From c662c089dbef5e27b8bc0132a8fbe6db0d75ebb9 Mon Sep 17 00:00:00 2001 From: besson Date: Sat, 14 Jan 2023 18:36:41 +0100 Subject: [PATCH] =?UTF-8?q?Transf=C3=A9rer=20les=20fichiers=20vers=20'src/?= =?UTF-8?q?JsonInspector'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JsonInspector/ArrayObjectListener.java | 1 - src/JsonInspector/Frame.java | 5 ++ src/JsonInspector/GraphicFile.java | 61 +++++++++++++++++----- src/JsonInspector/Line.java | 11 ++++ 4 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/JsonInspector/ArrayObjectListener.java b/src/JsonInspector/ArrayObjectListener.java index 57b485d..9d9ff12 100644 --- a/src/JsonInspector/ArrayObjectListener.java +++ b/src/JsonInspector/ArrayObjectListener.java @@ -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 { diff --git a/src/JsonInspector/Frame.java b/src/JsonInspector/Frame.java index 137ba92..ec9b4d3 100644 --- a/src/JsonInspector/Frame.java +++ b/src/JsonInspector/Frame.java @@ -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(); diff --git a/src/JsonInspector/GraphicFile.java b/src/JsonInspector/GraphicFile.java index 4e5a7f4..e00cabd 100644 --- a/src/JsonInspector/GraphicFile.java +++ b/src/JsonInspector/GraphicFile.java @@ -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 lines = new ArrayList<>(); + private ArrayList 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,13 +270,22 @@ public class GraphicFile extends JPanel { public void retreatAll() { for (Line line : lines) { - if (0 < line.getDepth() && 0 < line.getNode().getSize()) { - line.retreat(); + 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 getLines() { return lines; } @@ -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)); diff --git a/src/JsonInspector/Line.java b/src/JsonInspector/Line.java index 8f2f308..50d6f85 100644 --- a/src/JsonInspector/Line.java +++ b/src/JsonInspector/Line.java @@ -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("...}")) {