Transférer les fichiers vers 'src/JsonInspector'
This commit is contained in:
parent
9828f30743
commit
700a9511b4
38
src/JsonInspector/ArrayObjectListener.java
Normal file
38
src/JsonInspector/ArrayObjectListener.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package JsonInspector;
|
||||||
|
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
|
||||||
|
public class ArrayObjectListener implements MouseListener {
|
||||||
|
private final Line line;
|
||||||
|
private final Frame frame;
|
||||||
|
|
||||||
|
|
||||||
|
public ArrayObjectListener(Line line, Frame frame) {
|
||||||
|
this.line = line;
|
||||||
|
this.frame = frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
System.out.println("Clique");
|
||||||
|
if (line.isShow()) {
|
||||||
|
line.retreat();
|
||||||
|
} else {
|
||||||
|
line.unfold();
|
||||||
|
}
|
||||||
|
frame.repaintFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {}
|
||||||
|
}
|
@ -11,6 +11,7 @@ public class Frame extends JFrame {
|
|||||||
private static final String DEFAULT_LINK = "https://gbfs.citibikenyc.com/gbfs/en/station_information.json";
|
private static final String DEFAULT_LINK = "https://gbfs.citibikenyc.com/gbfs/en/station_information.json";
|
||||||
private final CardLayout cards = new CardLayout();
|
private final CardLayout cards = new CardLayout();
|
||||||
private boolean showTab = true;
|
private boolean showTab = true;
|
||||||
|
private JPanel secondCard;
|
||||||
private GraphicFile file;
|
private GraphicFile file;
|
||||||
private Node node;
|
private Node node;
|
||||||
private Tree tree;
|
private Tree tree;
|
||||||
@ -26,7 +27,8 @@ public class Frame extends JFrame {
|
|||||||
super("Inspecteur JSON");
|
super("Inspecteur JSON");
|
||||||
this.node = node;
|
this.node = node;
|
||||||
init();
|
init();
|
||||||
this.add(secondCard());
|
secondCard = secondCard();
|
||||||
|
this.add(secondCard);
|
||||||
cards.last(this.getContentPane());
|
cards.last(this.getContentPane());
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
@ -60,7 +62,9 @@ public class Frame extends JFrame {
|
|||||||
gbc.gridx = 1;
|
gbc.gridx = 1;
|
||||||
panel.add(textField, gbc);
|
panel.add(textField, gbc);
|
||||||
|
|
||||||
|
gbc.gridx = 0;
|
||||||
gbc.gridy = 1;
|
gbc.gridy = 1;
|
||||||
|
gbc.gridwidth = 2;
|
||||||
panel.add(button, gbc);
|
panel.add(button, gbc);
|
||||||
|
|
||||||
panel.setBackground(Parameters.IHM_COLOR);
|
panel.setBackground(Parameters.IHM_COLOR);
|
||||||
@ -68,7 +72,7 @@ public class Frame extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JPanel secondCard() {
|
private JPanel secondCard() {
|
||||||
file = new GraphicFile(tree, showTab);
|
file = new GraphicFile(this, tree);
|
||||||
JButton showButton = new JButton();
|
JButton showButton = new JButton();
|
||||||
JButton backButton = new JButton("Retour");
|
JButton backButton = new JButton("Retour");
|
||||||
JPanel mainPanel = new JPanel(), southPanel = new JPanel();
|
JPanel mainPanel = new JPanel(), southPanel = new JPanel();
|
||||||
@ -85,7 +89,7 @@ public class Frame extends JFrame {
|
|||||||
southPanel.add(backButton);
|
southPanel.add(backButton);
|
||||||
backButton.addActionListener((event) -> backAction(mainPanel));
|
backButton.addActionListener((event) -> backAction(mainPanel));
|
||||||
southPanel.add(showButton);
|
southPanel.add(showButton);
|
||||||
showButton.addActionListener((event) -> showAction(mainPanel));
|
showButton.addActionListener((event) -> showAction());
|
||||||
southPanel.add(new JButton("convertir en PHP"));
|
southPanel.add(new JButton("convertir en PHP"));
|
||||||
|
|
||||||
mainPanel.add(file);
|
mainPanel.add(file);
|
||||||
@ -97,20 +101,54 @@ public class Frame extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void showAction(JPanel panel) {
|
private JPanel secondCard(GraphicFile file) {
|
||||||
|
this.file = file;
|
||||||
|
JButton showButton = new JButton();
|
||||||
|
JButton backButton = new JButton("Retour");
|
||||||
|
JPanel mainPanel = new JPanel(), southPanel = new JPanel();
|
||||||
|
JScrollPane scroll = new JScrollPane();
|
||||||
|
mainPanel.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
if (showTab) {
|
||||||
|
showButton.setText("Tout déplier");
|
||||||
|
} else {
|
||||||
|
showButton.setText("Tout replier");
|
||||||
|
}
|
||||||
|
|
||||||
|
southPanel.setBackground(Parameters.IHM_COLOR);
|
||||||
|
southPanel.add(backButton);
|
||||||
|
backButton.addActionListener((event) -> backAction(mainPanel));
|
||||||
|
southPanel.add(showButton);
|
||||||
|
showButton.addActionListener((event) -> showAction());
|
||||||
|
southPanel.add(new JButton("convertir en PHP"));
|
||||||
|
|
||||||
|
mainPanel.add(file);
|
||||||
|
mainPanel.add(southPanel, BorderLayout.SOUTH);
|
||||||
|
mainPanel.add(scroll);
|
||||||
|
|
||||||
|
scroll.setViewportView(file);
|
||||||
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void showAction() {
|
||||||
if (showTab) {
|
if (showTab) {
|
||||||
showTab = false;
|
showTab = false;
|
||||||
repaintFile(panel);
|
file.showAll();
|
||||||
} else {
|
} else {
|
||||||
showTab = true;
|
showTab = true;
|
||||||
repaintFile(panel);
|
file.retreatAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repaintFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void repaintFile(JPanel panel) {
|
public void repaintFile() {
|
||||||
this.remove(panel);
|
file = new GraphicFile(this, file.getLines());
|
||||||
this.add(secondCard());
|
this.remove(secondCard);
|
||||||
|
secondCard = secondCard(file);
|
||||||
|
this.add(secondCard);
|
||||||
cards.last(this.getContentPane());
|
cards.last(this.getContentPane());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,13 +156,15 @@ public class Frame extends JFrame {
|
|||||||
private void validationAction(JTextField field) {
|
private void validationAction(JTextField field) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(field.getText());
|
URL url = new URL(field.getText());
|
||||||
this.add(secondCard());
|
secondCard = secondCard();
|
||||||
|
this.add(secondCard);
|
||||||
cards.last(this.getContentPane());
|
cards.last(this.getContentPane());
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
JOptionPane.showMessageDialog(this, "Invalid URL", "Error", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this, "Invalid URL", "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void backAction(JPanel panel) {
|
private void backAction(JPanel panel) {
|
||||||
this.remove(panel);
|
this.remove(panel);
|
||||||
cards.first(this.getContentPane());
|
cards.first(this.getContentPane());
|
||||||
|
@ -6,28 +6,39 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class GraphicFile extends JPanel {
|
public class GraphicFile extends JPanel {
|
||||||
private final GridBagConstraints gbc = new GridBagConstraints();
|
private final GridBagConstraints gbc = new GridBagConstraints();
|
||||||
private final ArrayList<Line> lines = new ArrayList<>();
|
|
||||||
private final JPanel alignementPanel = new JPanel();
|
private final JPanel alignementPanel = new JPanel();
|
||||||
private final Node firstNode;
|
private final Frame frame;
|
||||||
|
private ArrayList<Line> lines = new ArrayList<>();
|
||||||
|
private Node firstNode;
|
||||||
|
|
||||||
|
|
||||||
public GraphicFile(Tree tree, boolean hided) {
|
public GraphicFile(Frame frame, Tree tree) {
|
||||||
super();
|
super();
|
||||||
//firstNode = tree.getFirstNode();
|
//firstNode = tree.getFirstNode();
|
||||||
this.setBackground(Parameters.BACKGROUND_COLOR);
|
init();
|
||||||
this.setLayout(new FlowLayout(FlowLayout.LEFT));
|
this.frame = frame;
|
||||||
firstNode = createTree();
|
firstNode = createTree();
|
||||||
createFileRecursive(firstNode, 0, false);
|
createFileRecursive(firstNode, 0, false);
|
||||||
|
displayLines();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public GraphicFile(Frame frame, ArrayList<Line> lines) {
|
||||||
|
super();
|
||||||
|
init();
|
||||||
|
this.frame = frame;
|
||||||
|
this.lines = lines;
|
||||||
|
displayLines();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
this.setBackground(Parameters.BACKGROUND_COLOR);
|
||||||
|
this.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||||
gbc.fill = GridBagConstraints.BOTH;
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
gbc.anchor = GridBagConstraints.WEST;
|
gbc.anchor = GridBagConstraints.WEST;
|
||||||
alignementPanel.setLayout(new GridBagLayout());
|
alignementPanel.setLayout(new GridBagLayout());
|
||||||
this.add(alignementPanel);
|
this.add(alignementPanel);
|
||||||
|
|
||||||
if (hided) {
|
|
||||||
displayHidedLines();
|
|
||||||
} else {
|
|
||||||
displayAllLines();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -74,6 +85,10 @@ public class GraphicFile extends JPanel {
|
|||||||
Line line = new Line(node, depth);
|
Line line = new Line(node, depth);
|
||||||
line.add(indentation);
|
line.add(indentation);
|
||||||
|
|
||||||
|
if (0 < depth && 0 < node.getSize()) {
|
||||||
|
line.retreat();
|
||||||
|
}
|
||||||
|
|
||||||
if (node.getType() == Type.ELEMENT) {
|
if (node.getType() == Type.ELEMENT) {
|
||||||
line.add("{");
|
line.add("{");
|
||||||
} else {
|
} else {
|
||||||
@ -90,6 +105,7 @@ public class GraphicFile extends JPanel {
|
|||||||
lines.add(line);
|
lines.add(line);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
line.addMouseListener(new ArrayObjectListener(line, frame));
|
||||||
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);
|
||||||
@ -107,6 +123,10 @@ public class GraphicFile extends JPanel {
|
|||||||
Line line = new Line(node, depth);
|
Line line = new Line(node, depth);
|
||||||
line.add(indentation);
|
line.add(indentation);
|
||||||
|
|
||||||
|
if (0 < depth && 0 < node.getSize()) {
|
||||||
|
line.retreat();
|
||||||
|
}
|
||||||
|
|
||||||
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
||||||
line.add(": [");
|
line.add(": [");
|
||||||
|
|
||||||
@ -118,6 +138,7 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
} else {
|
} else {
|
||||||
|
line.addMouseListener(new ArrayObjectListener(line, frame));
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
|
|
||||||
for (int i = 0; i < node.getSize(); i++) {
|
for (int i = 0; i < node.getSize(); i++) {
|
||||||
@ -175,25 +196,18 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void displayAllLines() {
|
private void displayLines() {
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
boolean inArrayObject = false, array, object;
|
||||||
displayOneLine(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void displayHidedLines() {
|
|
||||||
boolean inArray = false, array, object;
|
|
||||||
Line openedArrayObject = lines.get(0);
|
Line openedArrayObject = lines.get(0);
|
||||||
|
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
if (!inArray) {
|
if (!inArrayObject) {
|
||||||
array = lines.get(i).getNode().getType() == Type.ARRAY;
|
array = lines.get(i).getNode().getType() == Type.ARRAY;
|
||||||
object = lines.get(i).getNode().getType() == Type.OBJECT;
|
object = lines.get(i).getNode().getType() == Type.OBJECT;
|
||||||
|
|
||||||
// Vérifie si le noeud est du type ARRAY ou du type OBJECT
|
// Vérifie si le noeud est du type ARRAY ou du type OBJECT et s'il doit être affiché
|
||||||
if ((array || object) && 0 < lines.get(i).getDepth()) {
|
if ((array || object) && !lines.get(i).isShow()) {
|
||||||
inArray = true;
|
inArrayObject = true;
|
||||||
openedArrayObject = lines.get(i);
|
openedArrayObject = lines.get(i);
|
||||||
|
|
||||||
if (openedArrayObject.getNode().getType() == Type.ARRAY) {
|
if (openedArrayObject.getNode().getType() == Type.ARRAY) {
|
||||||
@ -208,7 +222,7 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (lines.get(i).getNode().equals(openedArrayObject.getNode())) {
|
} else if (lines.get(i).getNode().equals(openedArrayObject.getNode())) {
|
||||||
inArray = false;
|
inArrayObject = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,6 +245,30 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void showAll() {
|
||||||
|
for (Line line : lines) {
|
||||||
|
if (!line.isShow()) {
|
||||||
|
line.removeClosingLabel();
|
||||||
|
}
|
||||||
|
line.unfold();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void retreatAll() {
|
||||||
|
for (Line line : lines) {
|
||||||
|
if (0 < line.getDepth() && 0 < line.getNode().getSize()) {
|
||||||
|
line.retreat();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ArrayList<Line> getLines() {
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private Node createTree() {
|
private Node createTree() {
|
||||||
Node beginning = new Node("", Type.ELEMENT);
|
Node beginning = new Node("", Type.ELEMENT);
|
||||||
Node d = new Node("d", Type.OBJECT);
|
Node d = new Node("d", Type.OBJECT);
|
||||||
@ -249,6 +287,7 @@ public class GraphicFile extends JPanel {
|
|||||||
d.add(result);
|
d.add(result);
|
||||||
result.add(metadata);
|
result.add(metadata);
|
||||||
metadata.add(type);
|
metadata.add(type);
|
||||||
|
result.add(true);
|
||||||
result.add(value1);
|
result.add(value1);
|
||||||
result.add(value2);
|
result.add(value2);
|
||||||
result.add(value3);
|
result.add(value3);
|
||||||
|
@ -3,10 +3,10 @@ package JsonInspector;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class Line extends MyJPanel {
|
public class Line extends MyJPanel {
|
||||||
//Le nœud qui est représenté par cet objet Line
|
private boolean show = true;
|
||||||
public boolean show = true;
|
private final int depth;
|
||||||
private int depth;
|
private final Node node;
|
||||||
private Node node;
|
private MyJLabel lastElement;
|
||||||
|
|
||||||
|
|
||||||
public Line(Node node, int depth) {
|
public Line(Node node, int depth) {
|
||||||
@ -33,12 +33,14 @@ public class Line extends MyJPanel {
|
|||||||
|
|
||||||
|
|
||||||
public void add(String string) {
|
public void add(String string) {
|
||||||
this.add(new MyJLabel(string));
|
lastElement = new MyJLabel(string);
|
||||||
|
this.add(lastElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void add(String string, Color color) {
|
public void add(String string, Color color) {
|
||||||
this.add(new MyJLabel(string, color));
|
lastElement = new MyJLabel(string, color);
|
||||||
|
this.add(lastElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -50,4 +52,30 @@ public class Line extends MyJPanel {
|
|||||||
public int getDepth() {
|
public int getDepth() {
|
||||||
return depth;
|
return depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isShow() {
|
||||||
|
return show;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void unfold() {
|
||||||
|
show = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void retreat() {
|
||||||
|
show = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void removeClosingLabel() {
|
||||||
|
try {
|
||||||
|
if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) {
|
||||||
|
this.remove(lastElement);
|
||||||
|
}
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
//System.out.println("La ligne est vide");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,13 @@ import java.awt.*;
|
|||||||
public class MyJLabel extends JLabel {
|
public class MyJLabel extends JLabel {
|
||||||
public MyJLabel(String text, Color color) {
|
public MyJLabel(String text, Color color) {
|
||||||
super(text);
|
super(text);
|
||||||
this.setFont(Parameters.FILE_FONT);
|
//this.setFont(Parameters.FILE_FONT);
|
||||||
this.setForeground(color);
|
this.setForeground(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyJLabel(String text) {
|
public MyJLabel(String text) {
|
||||||
super(text);
|
super(text);
|
||||||
this.setFont(Parameters.FILE_FONT);
|
//this.setFont(Parameters.FILE_FONT);
|
||||||
this.setForeground(Parameters.DEFAULT_TEXT_COLOR);
|
this.setForeground(Parameters.DEFAULT_TEXT_COLOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user