Mise à jour de 'src/JsonInspector/GraphicFile.java'
This commit is contained in:
parent
0ccdd70536
commit
2db0e6e3f2
@ -1,142 +1,144 @@
|
|||||||
import javax.swing.*;
|
package JsonInspector;
|
||||||
import java.awt.*;
|
|
||||||
import java.net.URL;
|
import javax.swing.*;
|
||||||
import java.util.ArrayList;
|
import java.awt.*;
|
||||||
|
import java.net.URL;
|
||||||
public class GraphicFile extends JPanel {
|
import java.util.ArrayList;
|
||||||
private Node firstNode;
|
|
||||||
private ArrayList<Line> lines = new ArrayList<>();
|
public class GraphicFile extends JPanel {
|
||||||
private int index = 0;
|
private Node firstNode;
|
||||||
|
private ArrayList<Line> lines = new ArrayList<>();
|
||||||
public GraphicFile(Tree tree) {
|
private int index = 0;
|
||||||
super();
|
|
||||||
//firstNode = tree.getFirstNode();
|
public GraphicFile(Tree tree) {
|
||||||
this.setBackground(Parameters.BACKGROUND_COLOR);
|
super();
|
||||||
firstNode = createTree();
|
//firstNode = tree.getFirstNode();
|
||||||
createFileRecursive(firstNode, 0, false);
|
this.setBackground(Parameters.BACKGROUND_COLOR);
|
||||||
displayLines();
|
firstNode = createTree();
|
||||||
}
|
createFileRecursive(firstNode, 0, false);
|
||||||
|
displayLines();
|
||||||
|
}
|
||||||
private void createFileRecursive(Node node, int depth, boolean inList) {
|
|
||||||
String indentation = "";
|
|
||||||
|
private void createFileRecursive(Node node, int depth, boolean inList) {
|
||||||
for (int i = 0; i < depth; i++) {
|
String indentation = "";
|
||||||
indentation += Parameters.INDENTATION;
|
|
||||||
}
|
for (int i = 0; i < depth; i++) {
|
||||||
|
indentation += Parameters.INDENTATION;
|
||||||
if (node.getType() == Type.OBJECT) {
|
}
|
||||||
createObject(node, depth, indentation);
|
|
||||||
|
if (node.getType() == Type.OBJECT) {
|
||||||
} else if (node.getType() == Type.ARRAY) {
|
createObject(node, depth, indentation);
|
||||||
createArray(node, depth, indentation);
|
|
||||||
|
} else if (node.getType() == Type.ARRAY) {
|
||||||
} else if (node.getType() == Type.PAIR) {
|
createArray(node, depth, indentation);
|
||||||
createPair(node, indentation, inList);
|
|
||||||
}
|
} else if (node.getType() == Type.PAIR) {
|
||||||
}
|
createPair(node, indentation, inList);
|
||||||
|
}
|
||||||
|
}
|
||||||
private void createPair(Node node, String indentation, boolean virgule) {
|
|
||||||
Line line = new Line(node);
|
|
||||||
line.add(indentation);
|
private void createPair(Node node, String indentation, boolean virgule) {
|
||||||
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
Line line = new Line(node);
|
||||||
line.add(": ");
|
line.add(indentation);
|
||||||
line.add("\"" + node.getValues().get(0) + "\"", Parameters.VALUE_COLOR);
|
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
||||||
if (virgule) {
|
line.add(": ");
|
||||||
line.add(",");
|
line.add("\"" + node.getValues().get(0) + "\"", Parameters.VALUE_COLOR);
|
||||||
}
|
if (virgule) {
|
||||||
|
line.add(",");
|
||||||
lines.add(line);
|
}
|
||||||
}
|
|
||||||
|
lines.add(line);
|
||||||
|
}
|
||||||
private void createObject(Node node, int depth, String indentation) {
|
|
||||||
boolean virgule;
|
|
||||||
Line line = new Line(node);
|
private void createObject(Node node, int depth, String indentation) {
|
||||||
line.add(indentation);
|
boolean virgule;
|
||||||
|
Line line = new Line(node);
|
||||||
if (node.getName().equals("")) {
|
line.add(indentation);
|
||||||
line.add("{");
|
|
||||||
} else {
|
if (node.getName().equals("")) {
|
||||||
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
line.add("{");
|
||||||
line.add(": {");
|
} else {
|
||||||
}
|
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
||||||
|
line.add(": {");
|
||||||
lines.add(line);
|
}
|
||||||
callNextNodes(node, depth);
|
|
||||||
lines.add(new Line(node, indentation + "}"));
|
lines.add(line);
|
||||||
}
|
callNextNodes(node, depth);
|
||||||
|
lines.add(new Line(node, indentation + "}"));
|
||||||
|
}
|
||||||
private void createArray(Node node, int depth, String indentation) {
|
|
||||||
Line line = new Line(node);
|
|
||||||
line.add(indentation);
|
private void createArray(Node node, int depth, String indentation) {
|
||||||
|
Line line = new Line(node);
|
||||||
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
line.add(indentation);
|
||||||
line.add(": [");
|
|
||||||
|
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
||||||
lines.add(line);
|
line.add(": [");
|
||||||
callNextNodes(node, depth);
|
|
||||||
lines.add(new Line(node, indentation + "]"));
|
lines.add(line);
|
||||||
}
|
callNextNodes(node, depth);
|
||||||
|
lines.add(new Line(node, indentation + "]"));
|
||||||
|
}
|
||||||
private void callNextNodes(Node node, int depth) {
|
|
||||||
boolean virgule;
|
|
||||||
|
private void callNextNodes(Node node, int depth) {
|
||||||
for (int i = 0; i < node.getNodes().size(); i++) {
|
boolean virgule;
|
||||||
// si l'élément afficher est le dernier à son niveau "virgule" est faux
|
|
||||||
// donc il n'y aura pas de virgule en fin ligne
|
for (int i = 0; i < node.getNodes().size(); i++) {
|
||||||
virgule = !(i == node.getNodes().size() - 1);
|
// si l'élément afficher est le dernier à son niveau "virgule" est faux
|
||||||
createFileRecursive(node.getNodes().get(i), depth + 1, virgule);
|
// donc il n'y aura pas de virgule en fin ligne
|
||||||
}
|
virgule = !(i == node.getNodes().size() - 1);
|
||||||
}
|
createFileRecursive(node.getNodes().get(i), depth + 1, virgule);
|
||||||
|
}
|
||||||
|
}
|
||||||
private void displayLines() {
|
|
||||||
this.setLayout(new GridLayout(30, 1));
|
|
||||||
MyJPanel tempPanel;
|
private void displayLines() {
|
||||||
MyJLabel label;
|
this.setLayout(new GridLayout(30, 1));
|
||||||
|
MyJPanel tempPanel;
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
MyJLabel label;
|
||||||
tempPanel = new MyJPanel();
|
|
||||||
label = new MyJLabel("" + (i + 1));
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
label.setBackground(Parameters.IHM_COLOR);
|
tempPanel = new MyJPanel();
|
||||||
tempPanel.add(label);
|
label = new MyJLabel("" + (i + 1));
|
||||||
tempPanel.add(lines.get(i));
|
label.setBackground(Parameters.IHM_COLOR);
|
||||||
this.add(tempPanel);
|
tempPanel.add(label);
|
||||||
//System.out.println(lines.get(i).index);
|
tempPanel.add(lines.get(i));
|
||||||
}
|
this.add(tempPanel);
|
||||||
System.out.println();
|
//System.out.println(lines.get(i).index);
|
||||||
System.out.println(lines.size() + " ligne(s)");
|
}
|
||||||
}
|
System.out.println();
|
||||||
|
System.out.println(lines.size() + " ligne(s)");
|
||||||
|
}
|
||||||
private Node createTree() {
|
|
||||||
Node beginning = new Node("", Type.OBJECT);
|
|
||||||
Node d = new Node("d", Type.OBJECT);
|
private Node createTree() {
|
||||||
Node result = new Node("result", Type.ARRAY);
|
Node beginning = new Node("", Type.OBJECT);
|
||||||
Node inter = new Node("", Type.OBJECT);
|
Node d = new Node("d", Type.OBJECT);
|
||||||
Node metadata = new Node("metadata", Type.OBJECT);
|
Node result = new Node("result", Type.ARRAY);
|
||||||
Node userID = new Node("UserId", Type.PAIR);
|
Node inter = new Node("", Type.OBJECT);
|
||||||
Node roleCode = new Node("RoleCode", Type.PAIR);
|
Node metadata = new Node("metadata", Type.OBJECT);
|
||||||
Node type = new Node("type", Type.PAIR);
|
Node userID = new Node("UserId", Type.PAIR);
|
||||||
String value1 = "EmployeeDetails.Employe", value2 = "E12012", value3 = "35";
|
Node roleCode = new Node("RoleCode", Type.PAIR);
|
||||||
|
Node type = new Node("type", Type.PAIR);
|
||||||
beginning.addNode(d);
|
String value1 = "EmployeeDetails.Employe", value2 = "E12012", value3 = "35";
|
||||||
d.addNode(result);
|
|
||||||
result.addNode(inter);
|
beginning.addNode(d);
|
||||||
inter.addNode(metadata);
|
d.addNode(result);
|
||||||
inter.addNode(userID);
|
result.addNode(inter);
|
||||||
inter.addNode(roleCode);
|
inter.addNode(metadata);
|
||||||
metadata.addNode(type);
|
inter.addNode(userID);
|
||||||
type.addValue(value1);
|
inter.addNode(roleCode);
|
||||||
userID.addValue(value2);
|
metadata.addNode(type);
|
||||||
roleCode.addValue(value3);
|
type.addValue(value1);
|
||||||
|
userID.addValue(value2);
|
||||||
System.out.println(Tree.printTree(beginning, 0));
|
roleCode.addValue(value3);
|
||||||
|
|
||||||
return beginning;
|
System.out.println(Tree.printTree(beginning, 0));
|
||||||
}
|
|
||||||
}
|
return beginning;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user