Transférer les fichiers vers 'src/JsonInspector'

This commit is contained in:
Romain BESSON 2023-01-14 18:36:41 +01:00
parent d0ba68531d
commit c662c089db
4 changed files with 64 additions and 14 deletions

View File

@ -15,7 +15,6 @@ public class ArrayObjectListener implements MouseListener {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("Clique");
if (line.isShow()) {
line.retreat();
} else {

View File

@ -16,6 +16,7 @@ public class Frame extends JFrame {
private Node node;
private Tree tree;
public Frame() {
super("Inspecteur JSON");
tree = new Tree("");
@ -23,6 +24,7 @@ public class Frame extends JFrame {
this.setVisible(true);
}
public Frame(Node node) {
super("Inspecteur JSON");
this.node = node;
@ -33,6 +35,7 @@ public class Frame extends JFrame {
this.setVisible(true);
}
private void init() {
this.setSize(DEFAULT_FRAME_SIZE);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
@ -43,6 +46,7 @@ public class Frame extends JFrame {
cards.first(this.getContentPane());
}
private JPanel firstCard() {
GridBagLayout layout = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
@ -71,6 +75,7 @@ public class Frame extends JFrame {
return panel;
}
private JPanel secondCard() {
file = new GraphicFile(this, tree);
JButton showButton = new JButton();

View File

@ -8,7 +8,7 @@ public class GraphicFile extends JPanel {
private final GridBagConstraints gbc = new GridBagConstraints();
private final JPanel alignementPanel = new JPanel();
private final Frame frame;
private ArrayList<Line> lines = new ArrayList<>();
private ArrayList<Line> lines;
private Node firstNode;
@ -16,9 +16,11 @@ public class GraphicFile extends JPanel {
super();
//firstNode = tree.getFirstNode();
init();
lines = new ArrayList<>();
this.frame = frame;
firstNode = createTree();
createFileRecursive(firstNode, 0, false);
//displayAllLines();
displayLines();
}
@ -28,6 +30,7 @@ public class GraphicFile extends JPanel {
init();
this.frame = frame;
this.lines = lines;
//displayAllLines();
displayLines();
}
@ -49,13 +52,13 @@ public class GraphicFile extends JPanel {
indentation += Parameters.IHM_INDENTATION;
}
if (node.getType() == Type.OBJECT || node.getType() == Type.ELEMENT) {
if (node.isObject() || node.isElement()) {
createObjectElement(node, depth, indentation, virgule);
} else if (node.getType() == Type.ARRAY) {
} else if (node.isArray()) {
createArray(node, depth, indentation, virgule);
} else if (node.getType() == Type.PAIR) {
} else if (node.isPair()) {
createPair(node, depth, indentation, virgule);
}
}
@ -109,6 +112,7 @@ public class GraphicFile extends JPanel {
lines.add(line);
callNextNodes(node, depth);
Line endLine = new Line(node, indentation + "}", depth);
endLine.setClosingElement();
if (virgule) {
endLine.add(",");
@ -142,7 +146,7 @@ public class GraphicFile extends JPanel {
lines.add(line);
for (int i = 0; i < node.getSize(); i++) {
Line valueLine = new Line(node, depth + 1);
Line valueLine = new Line(new Node("", Type.NULL), depth + 1);
if (node.get(i).isNode()) {
callNextNodes(node, depth);
@ -160,6 +164,7 @@ public class GraphicFile extends JPanel {
}
Line endLine = new Line(node, indentation + "]", depth);
endLine.setClosingElement();
if (virgule) {
endLine.add(",");
@ -196,21 +201,29 @@ public class GraphicFile extends JPanel {
}
private void displayAllLines() {
for (int i = 0; i < lines.size(); i++) {
displayOneLine(i);
}
}
private void displayLines() {
boolean inArrayObject = false, array, object;
Line openedArrayObject = lines.get(0);
Node openedArrayObject = lines.get(0).getNode();
removeAllClosingLabel();
for (int i = 0; i < lines.size(); i++) {
if (!inArrayObject) {
array = lines.get(i).getNode().getType() == Type.ARRAY;
object = lines.get(i).getNode().getType() == Type.OBJECT;
array = lines.get(i).getNode().isArray();
object = lines.get(i).getNode().isObject();
// Vérifie si le noeud est du type ARRAY ou du type OBJECT et s'il doit être affiché
if ((array || object) && !lines.get(i).isShow()) {
inArrayObject = true;
openedArrayObject = lines.get(i);
openedArrayObject = lines.get(i).getNode();
if (openedArrayObject.getNode().getType() == Type.ARRAY) {
if (openedArrayObject.isArray()) {
displayOneHidedLine(i, "...]");
} else {
displayOneHidedLine(i, "...}");
@ -221,7 +234,7 @@ public class GraphicFile extends JPanel {
displayOneLine(i);
}
} else if (lines.get(i).getNode().equals(openedArrayObject.getNode())) {
} else if (lines.get(i).getNode().equals(openedArrayObject)) {
inArrayObject = false;
}
}
@ -257,11 +270,20 @@ public class GraphicFile extends JPanel {
public void retreatAll() {
for (Line line : lines) {
if (0 < line.getDepth() && 0 < line.getNode().getSize()) {
if (line.getNode().isArrayObjectElement()) {
if (0 < line.getDepth() && 0 < line.getNode().getSize() && !line.isClosingElement()) {
line.retreat();
}
}
}
}
private void removeAllClosingLabel() {
for(Line line : lines) {
line.removeClosingLabel();
}
}
public ArrayList<Line> getLines() {
@ -278,7 +300,11 @@ public class GraphicFile extends JPanel {
Node e = new Node("e", Type.ARRAY);
Node key = new Node("key", Type.PAIR);
Node key2 = new Node("key2", Type.PAIR);
Node key3 = new Node("key3", Type.PAIR);
Node key4 = new Node("key4", Type.PAIR);
Node object = new Node("object", Type.OBJECT);
Node object2 = new Node("object2", Type.OBJECT);
Node array = new Node("array", Type.ARRAY);
Integer number = 12;
String value1 = "EmployeeDetails.Employe", value2 = "E12012", value3 = "35", value4 = "string";
@ -295,7 +321,16 @@ public class GraphicFile extends JPanel {
beginning.add(key);
beginning.add(key2);
beginning.add(object);
beginning.add(object2);
object2.add(key3);
object2.add(key4);
beginning.add(array);
key2.add(value4);
key3.add(0.8);
key4.add(false);
array.add("str");
array.add(1790);
System.out.println(Tree.printTree(beginning, 0));

View File

@ -7,6 +7,7 @@ public class Line extends MyJPanel {
private final int depth;
private final Node node;
private MyJLabel lastElement;
private boolean closingElement = false;
public Line(Node node, int depth) {
@ -69,6 +70,16 @@ public class Line extends MyJPanel {
}
public void setClosingElement() {
closingElement = true;
}
public boolean isClosingElement() {
return closingElement;
}
public void removeClosingLabel() {
try {
if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) {