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 @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
System.out.println("Clique");
if (line.isShow()) { if (line.isShow()) {
line.retreat(); line.retreat();
} else { } else {

View File

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

View File

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

View File

@ -7,6 +7,7 @@ public class Line extends MyJPanel {
private final int depth; private final int depth;
private final Node node; private final Node node;
private MyJLabel lastElement; private MyJLabel lastElement;
private boolean closingElement = false;
public Line(Node node, int depth) { 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() { public void removeClosingLabel() {
try { try {
if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) { if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) {