Transférer les fichiers vers 'src/fr/sae/JSonInspector/Graphics'
This commit is contained in:
parent
d38211b431
commit
77cb91dc32
@ -1,9 +1,9 @@
|
|||||||
package fr.sae.JSonInspector.Graphics;
|
package JsonInspector.Graphics;
|
||||||
|
|
||||||
import fr.sae.JSonInspector.Exception.JsonSyntaxException;
|
import JsonInspector.Exception.JsonSyntaxException;
|
||||||
import fr.sae.JSonInspector.Main;
|
import JsonInspector.Main;
|
||||||
import fr.sae.JSonInspector.Settings.Parameters;
|
import JsonInspector.Settings.Parameters;
|
||||||
import fr.sae.JSonInspector.Storage.Tree;
|
import JsonInspector.Storage.Tree;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -15,17 +15,19 @@ public class Frame extends JFrame {
|
|||||||
private static final Dimension DEFAULT_FRAME_SIZE = new Dimension(800, 600);
|
private static final Dimension DEFAULT_FRAME_SIZE = new Dimension(800, 600);
|
||||||
private static final Dimension MINIMUM_FRAME_SIZE = new Dimension(600, 500);
|
private static final Dimension MINIMUM_FRAME_SIZE = new Dimension(600, 500);
|
||||||
private final CardLayout cards = new CardLayout();
|
private final CardLayout cards = new CardLayout();
|
||||||
private boolean showTab = true;
|
private boolean php = false;
|
||||||
private JPanel secondCard;
|
private JPanel secondCard;
|
||||||
private GraphicFile file;
|
private GraphicFile file;
|
||||||
private Tree tree;
|
private Tree tree;
|
||||||
|
|
||||||
|
|
||||||
public Frame() {
|
public Frame() {
|
||||||
super("Inspecteur JSON");
|
super("Inspecteur JSON");
|
||||||
init();
|
init();
|
||||||
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);
|
||||||
@ -36,10 +38,15 @@ public class Frame extends JFrame {
|
|||||||
cards.first(this.getContentPane());
|
cards.first(this.getContentPane());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Créer le premier panel où l'on entre l'URL du fichier
|
||||||
|
* @return le panel créé
|
||||||
|
*/
|
||||||
private JPanel firstCard() {
|
private JPanel firstCard() {
|
||||||
GridBagLayout layout = new GridBagLayout();
|
GridBagLayout layout = new GridBagLayout();
|
||||||
GridBagConstraints gbc = new GridBagConstraints();
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
JTextField textField = new JTextField("file:C:\\Users\\Elève\\Desktop\\temp\\jason.json", 30);
|
JTextField textField = new JTextField(30);
|
||||||
JButton button = new JButton("Valider");
|
JButton button = new JButton("Valider");
|
||||||
button.addActionListener((event) -> validationAction(textField));
|
button.addActionListener((event) -> validationAction(textField));
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
@ -64,24 +71,42 @@ public class Frame extends JFrame {
|
|||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Créer le deuxième panel où l'on voit le fichier
|
||||||
|
* @return le panel créé
|
||||||
|
*/
|
||||||
private JPanel secondCard() {
|
private JPanel secondCard() {
|
||||||
file = new GraphicFile(this, tree);
|
file = new GraphicFile(this, tree, php);
|
||||||
return initSecondCard(file);
|
return initSecondCard(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Créer le deuxième panel où l'on voit le fichier
|
||||||
|
* @return le panel créé
|
||||||
|
*/
|
||||||
private JPanel secondCard(GraphicFile file) {
|
private JPanel secondCard(GraphicFile file) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
return initSecondCard(file);
|
return initSecondCard(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private JPanel initSecondCard(GraphicFile file) {
|
private JPanel initSecondCard(GraphicFile file) {
|
||||||
JButton unfoldButton = new JButton("Tout déplier");
|
JButton unfoldButton = new JButton("Tout déplier");
|
||||||
JButton retreatButton = new JButton("Tout replier");
|
JButton retreatButton = new JButton("Tout replier");
|
||||||
|
JButton convertButton = 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();
|
||||||
JScrollPane scroll = new JScrollPane();
|
JScrollPane scroll = new JScrollPane();
|
||||||
mainPanel.setLayout(new BorderLayout());
|
mainPanel.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
if (php) {
|
||||||
|
convertButton.setText("Convertir en JSON");
|
||||||
|
} else {
|
||||||
|
convertButton.setText("Convertir en PHP");
|
||||||
|
}
|
||||||
|
|
||||||
southPanel.setBackground(Parameters.IHM_COLOR);
|
southPanel.setBackground(Parameters.IHM_COLOR);
|
||||||
southPanel.add(backButton);
|
southPanel.add(backButton);
|
||||||
backButton.addActionListener((event) -> backAction(mainPanel));
|
backButton.addActionListener((event) -> backAction(mainPanel));
|
||||||
@ -89,7 +114,8 @@ public class Frame extends JFrame {
|
|||||||
unfoldButton.addActionListener((event) -> unfoldAction());
|
unfoldButton.addActionListener((event) -> unfoldAction());
|
||||||
southPanel.add(retreatButton);
|
southPanel.add(retreatButton);
|
||||||
retreatButton.addActionListener((event) -> retreatAction());
|
retreatButton.addActionListener((event) -> retreatAction());
|
||||||
southPanel.add(new JButton("convertir en PHP"));
|
southPanel.add(convertButton);
|
||||||
|
convertButton.addActionListener((event) -> convertAction());
|
||||||
|
|
||||||
mainPanel.add(file);
|
mainPanel.add(file);
|
||||||
mainPanel.add(southPanel, BorderLayout.SOUTH);
|
mainPanel.add(southPanel, BorderLayout.SOUTH);
|
||||||
@ -99,16 +125,42 @@ public class Frame extends JFrame {
|
|||||||
return mainPanel;
|
return mainPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Passe de la version PHP du fichier à la version JSON et vice-versa
|
||||||
|
*/
|
||||||
|
private void convertAction() {
|
||||||
|
if (!php) {
|
||||||
|
php = true;
|
||||||
|
} else {
|
||||||
|
php = false;
|
||||||
|
}
|
||||||
|
file = new GraphicFile(this, tree, php);
|
||||||
|
repaintFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Déplit l'élément cliqué
|
||||||
|
*/
|
||||||
private void unfoldAction() {
|
private void unfoldAction() {
|
||||||
file.showAll();
|
file.showAll();
|
||||||
repaintFile();
|
repaintFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replit l'élément cliqué
|
||||||
|
*/
|
||||||
private void retreatAction() {
|
private void retreatAction() {
|
||||||
file.retreatAll();
|
file.retreatAll();
|
||||||
repaintFile();
|
repaintFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Met à jour le fichier
|
||||||
|
*/
|
||||||
public void repaintFile() {
|
public void repaintFile() {
|
||||||
file = new GraphicFile(this, file.getLines());
|
file = new GraphicFile(this, file.getLines());
|
||||||
this.remove(secondCard);
|
this.remove(secondCard);
|
||||||
@ -117,6 +169,11 @@ public class Frame extends JFrame {
|
|||||||
cards.last(this.getContentPane());
|
cards.last(this.getContentPane());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Passe du premier panel au second
|
||||||
|
* @param field le champ contenant l'URL
|
||||||
|
*/
|
||||||
private void validationAction(JTextField field) {
|
private void validationAction(JTextField field) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(field.getText());
|
URL url = new URL(field.getText());
|
||||||
@ -142,6 +199,11 @@ public class Frame extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Passe du second panel au premier
|
||||||
|
* @param panel
|
||||||
|
*/
|
||||||
private void backAction(JPanel panel) {
|
private void backAction(JPanel panel) {
|
||||||
this.remove(panel);
|
this.remove(panel);
|
||||||
cards.first(this.getContentPane());
|
cards.first(this.getContentPane());
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package fr.sae.JSonInspector.Graphics;
|
package JsonInspector.Graphics;
|
||||||
|
|
||||||
import fr.sae.JSonInspector.Settings.Parameters;
|
import JsonInspector.Settings.Parameters;
|
||||||
import fr.sae.JSonInspector.Storage.Node;
|
import JsonInspector.Storage.Node;
|
||||||
import fr.sae.JSonInspector.Storage.Tree;
|
import JsonInspector.Storage.Tree;
|
||||||
import fr.sae.JSonInspector.Storage.Type;
|
import JsonInspector.Storage.Type;
|
||||||
import fr.sae.JSonInspector.Storage.Value;
|
import JsonInspector.Storage.Value;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -14,20 +14,23 @@ 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;
|
private final ArrayList<Line> lines;
|
||||||
|
private boolean php = false;
|
||||||
private Node firstNode;
|
private Node firstNode;
|
||||||
|
|
||||||
public GraphicFile(Frame frame, Tree tree) {
|
|
||||||
|
public GraphicFile(Frame frame, Tree tree, boolean php) {
|
||||||
super();
|
super();
|
||||||
|
this.php = php;
|
||||||
firstNode = tree.getFirstNode();
|
firstNode = tree.getFirstNode();
|
||||||
init();
|
init();
|
||||||
lines = new ArrayList<>();
|
lines = new ArrayList<>();
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
createFileRecursive(firstNode, 0, false);
|
createFileRecursive(firstNode, 0, false);
|
||||||
// displayAllLines();
|
|
||||||
displayLines();
|
displayLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public GraphicFile(Frame frame, ArrayList<Line> lines) {
|
public GraphicFile(Frame frame, ArrayList<Line> lines) {
|
||||||
super();
|
super();
|
||||||
init();
|
init();
|
||||||
@ -37,6 +40,9 @@ public class GraphicFile extends JPanel {
|
|||||||
displayLines();
|
displayLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialise l'objet (permet de ne pas répéter de code dans les constructeurs)
|
||||||
|
*/
|
||||||
private void init() {
|
private void init() {
|
||||||
this.setBackground(Parameters.BACKGROUND_COLOR);
|
this.setBackground(Parameters.BACKGROUND_COLOR);
|
||||||
this.setLayout(new FlowLayout(FlowLayout.LEFT));
|
this.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||||
@ -46,6 +52,13 @@ public class GraphicFile extends JPanel {
|
|||||||
this.add(alignementPanel);
|
this.add(alignementPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parcours de manière récursive l'arbre pour créer les lignes
|
||||||
|
* @param node le noeud à afficher
|
||||||
|
* @param depth la profondeur dans l'arbre
|
||||||
|
* @param virgule détermine si une virgule doit être affichée à la fin
|
||||||
|
*/
|
||||||
private void createFileRecursive(Node node, int depth, boolean virgule) {
|
private void createFileRecursive(Node node, int depth, boolean virgule) {
|
||||||
String indentation = "";
|
String indentation = "";
|
||||||
|
|
||||||
@ -64,11 +77,24 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Créé une ligne de type 'PAIR'
|
||||||
|
* @param node le noeud a afficher
|
||||||
|
* @param depth la profondeur dans l'arbre
|
||||||
|
* @param indentation l'indentation du père
|
||||||
|
* @param virgule détermine si une virgule doit être affichée à la fin
|
||||||
|
*/
|
||||||
private void createPair(Node node, int depth, String indentation, boolean virgule) {
|
private void createPair(Node node, int depth, String indentation, boolean virgule) {
|
||||||
Line line = new Line(node, depth);
|
Line line = new Line(node, depth);
|
||||||
line.add(indentation);
|
line.add(indentation);
|
||||||
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
||||||
|
if (!php) {
|
||||||
line.add(": ");
|
line.add(": ");
|
||||||
|
} else {
|
||||||
|
line.add(" => ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (node.getSize() != 0) {
|
if (node.getSize() != 0) {
|
||||||
createValue(line, node.get(0));
|
createValue(line, node.get(0));
|
||||||
@ -83,6 +109,14 @@ public class GraphicFile extends JPanel {
|
|||||||
lines.add(line);
|
lines.add(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Créé une ligne de type 'OBJECT' ou 'ELEMENT'
|
||||||
|
* @param node le noeud a afficher
|
||||||
|
* @param depth la profondeur dans l'arbre
|
||||||
|
* @param indentation l'indentation du père
|
||||||
|
* @param virgule détermine si une virgule doit être affichée à la fin
|
||||||
|
*/
|
||||||
private void createObjectElement(Node node, int depth, String indentation, boolean virgule) {
|
private void createObjectElement(Node node, int depth, String indentation, boolean virgule) {
|
||||||
Line line = new Line(node, depth);
|
Line line = new Line(node, depth);
|
||||||
line.add(indentation);
|
line.add(indentation);
|
||||||
@ -92,17 +126,37 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.getType() == Type.ELEMENT) {
|
if (node.getType() == Type.ELEMENT) {
|
||||||
|
if (!php) {
|
||||||
line.add("{");
|
line.add("{");
|
||||||
|
} else {
|
||||||
|
line.add("(");
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
||||||
|
if (!php) {
|
||||||
line.add(": {");
|
line.add(": {");
|
||||||
|
} else {
|
||||||
|
line.add(" => (");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.getSize() == 0) {
|
if (node.getSize() == 0) {
|
||||||
if (virgule) {
|
if (virgule) {
|
||||||
|
if (!php) {
|
||||||
line.add(" },");
|
line.add(" },");
|
||||||
} else {
|
} else {
|
||||||
|
line.add(" ),");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (!php) {
|
||||||
line.add(" }");
|
line.add(" }");
|
||||||
|
} else {
|
||||||
|
line.add(" )");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
|
|
||||||
@ -110,7 +164,14 @@ public class GraphicFile extends JPanel {
|
|||||||
line.addMouseListener(new ArrayObjectListener(line, frame));
|
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;
|
||||||
|
|
||||||
|
if (!php) {
|
||||||
|
endLine = new Line(node, indentation + "}", depth);
|
||||||
|
} else {
|
||||||
|
endLine = new Line(node, indentation + ")", depth);
|
||||||
|
}
|
||||||
|
|
||||||
endLine.setClosingElement();
|
endLine.setClosingElement();
|
||||||
|
|
||||||
if (virgule) {
|
if (virgule) {
|
||||||
@ -121,6 +182,14 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Créé une ligne de type 'ARRAY'
|
||||||
|
* @param node le noeud a afficher
|
||||||
|
* @param depth la profondeur dans l'arbre
|
||||||
|
* @param indentation l'indentation du père
|
||||||
|
* @param virgule détermine si une virgule doit être affichée à la fin
|
||||||
|
*/
|
||||||
private void createArray(Node node, int depth, String indentation, boolean virgule) {
|
private void createArray(Node node, int depth, String indentation, boolean virgule) {
|
||||||
Line line = new Line(node, depth);
|
Line line = new Line(node, depth);
|
||||||
line.add(indentation);
|
line.add(indentation);
|
||||||
@ -130,13 +199,27 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
||||||
|
if (!php) {
|
||||||
line.add(": [");
|
line.add(": [");
|
||||||
|
} else {
|
||||||
|
line.add(" => (");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (node.getSize() == 0) {
|
if (node.getSize() == 0) {
|
||||||
if (virgule) {
|
if (virgule) {
|
||||||
|
if (!php) {
|
||||||
line.add(" ],");
|
line.add(" ],");
|
||||||
} else {
|
} else {
|
||||||
|
line.add(" ),");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (!php) {
|
||||||
line.add(" ]");
|
line.add(" ]");
|
||||||
|
} else {
|
||||||
|
line.add(" )");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
} else {
|
} else {
|
||||||
@ -161,7 +244,12 @@ public class GraphicFile extends JPanel {
|
|||||||
lines.add(valueLine);
|
lines.add(valueLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
Line endLine = new Line(node, indentation + "]", depth);
|
Line endLine;
|
||||||
|
if (!php) {
|
||||||
|
endLine = new Line(node, indentation + "]", depth);
|
||||||
|
} else {
|
||||||
|
endLine = new Line(node, indentation + ")", depth);
|
||||||
|
}
|
||||||
endLine.setClosingElement();
|
endLine.setClosingElement();
|
||||||
|
|
||||||
if (virgule) {
|
if (virgule) {
|
||||||
@ -172,6 +260,12 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affiche la valeur d'un noeud
|
||||||
|
* @param line la ligne sur laquelle afficher la valeur
|
||||||
|
* @param value la valeur à afficher
|
||||||
|
*/
|
||||||
private void createValue(Line line, Value value) {
|
private void createValue(Line line, Value value) {
|
||||||
if (value.isNumber()) {
|
if (value.isNumber()) {
|
||||||
line.add("" + value.getValue(), Parameters.NUMBER_COLOR);
|
line.add("" + value.getValue(), Parameters.NUMBER_COLOR);
|
||||||
@ -182,6 +276,12 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appelle les fils d'un noeud père
|
||||||
|
* @param node le noeud père
|
||||||
|
* @param depth la profondeur dans l'arbre
|
||||||
|
*/
|
||||||
private void callNextNodes(Node node, int depth) {
|
private void callNextNodes(Node node, int depth) {
|
||||||
boolean virgule;
|
boolean virgule;
|
||||||
|
|
||||||
@ -196,6 +296,10 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affiche les lignes dans l'ordre en prenant compte de leur statut de visibilité
|
||||||
|
*/
|
||||||
private void displayLines() {
|
private void displayLines() {
|
||||||
boolean inArrayObject = false, array, object;
|
boolean inArrayObject = false, array, object;
|
||||||
Node openedArrayObject = lines.get(0).getNode();
|
Node openedArrayObject = lines.get(0).getNode();
|
||||||
@ -206,8 +310,7 @@ public class GraphicFile extends JPanel {
|
|||||||
array = lines.get(i).getNode().isArray();
|
array = lines.get(i).getNode().isArray();
|
||||||
object = lines.get(i).getNode().isObject();
|
object = lines.get(i).getNode().isObject();
|
||||||
|
|
||||||
// Vérifie si le noeud est du type ARRAY ou du type OBJECT et s'il doit être
|
// Vérifie si le noeud est du type ARRAY ou du type OBJECT et s'il doit être affiché
|
||||||
// affiché
|
|
||||||
if ((array || object) && !lines.get(i).isShow()) {
|
if ((array || object) && !lines.get(i).isShow()) {
|
||||||
inArrayObject = true;
|
inArrayObject = true;
|
||||||
openedArrayObject = lines.get(i).getNode();
|
openedArrayObject = lines.get(i).getNode();
|
||||||
@ -229,6 +332,11 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affiche une ligne normalement
|
||||||
|
* @param index le numéro de la ligne
|
||||||
|
*/
|
||||||
private void displayOneLine(int index) {
|
private void displayOneLine(int index) {
|
||||||
gbc.gridy = index;
|
gbc.gridy = index;
|
||||||
|
|
||||||
@ -236,6 +344,12 @@ public class GraphicFile extends JPanel {
|
|||||||
alignementPanel.add(lines.get(index), gbc);
|
alignementPanel.add(lines.get(index), gbc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affiche un ligne cacher
|
||||||
|
* @param index le numéro de la ligne
|
||||||
|
* @param endOfLine le texte à afficher en fin de ligne
|
||||||
|
*/
|
||||||
private void displayOneHidedLine(int index, String endOfLine) {
|
private void displayOneHidedLine(int index, String endOfLine) {
|
||||||
gbc.gridy = index;
|
gbc.gridy = index;
|
||||||
|
|
||||||
@ -244,6 +358,10 @@ public class GraphicFile extends JPanel {
|
|||||||
alignementPanel.add(lines.get(index), gbc);
|
alignementPanel.add(lines.get(index), gbc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change tous les statuts de visibilités à vrai
|
||||||
|
*/
|
||||||
public void showAll() {
|
public void showAll() {
|
||||||
for (Line line : lines) {
|
for (Line line : lines) {
|
||||||
if (!line.isShow()) {
|
if (!line.isShow()) {
|
||||||
@ -253,6 +371,10 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change tous les statuts de visibilité à faux pour les éléments que l'on peut cacher
|
||||||
|
*/
|
||||||
public void retreatAll() {
|
public void retreatAll() {
|
||||||
for (Line line : lines) {
|
for (Line line : lines) {
|
||||||
if (line.getNode().isArrayObjectElement()) {
|
if (line.getNode().isArrayObjectElement()) {
|
||||||
@ -263,12 +385,21 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enlève tous les caractères fermants
|
||||||
|
*/
|
||||||
private void removeAllClosingLabel() {
|
private void removeAllClosingLabel() {
|
||||||
for(Line line : lines) {
|
for(Line line : lines) {
|
||||||
line.removeClosingLabel();
|
line.removeClosingLabel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return la liste des lignes du fichier
|
||||||
|
*/
|
||||||
public ArrayList<Line> getLines() {
|
public ArrayList<Line> getLines() {
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package fr.sae.JSonInspector.Graphics;
|
package JsonInspector.Graphics;
|
||||||
|
|
||||||
import fr.sae.JSonInspector.Graphics.MyJLabel;
|
import JsonInspector.Storage.Node;
|
||||||
import fr.sae.JSonInspector.Graphics.MyJPanel;
|
|
||||||
import fr.sae.JSonInspector.Storage.Node;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Représente une ligne dans l'IHM
|
||||||
|
*/
|
||||||
public class Line extends MyJPanel {
|
public class Line extends MyJPanel {
|
||||||
private boolean show = true;
|
private boolean show = true;
|
||||||
private final int depth;
|
private final int depth;
|
||||||
@ -13,12 +14,25 @@ public class Line extends MyJPanel {
|
|||||||
private MyJLabel lastElement;
|
private MyJLabel lastElement;
|
||||||
private boolean closingElement = false;
|
private boolean closingElement = false;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param node le noeud représenté par cette ligne
|
||||||
|
* @param depth la profondeur dans l'arbre
|
||||||
|
*/
|
||||||
public Line(Node node, int depth) {
|
public Line(Node node, int depth) {
|
||||||
super();
|
super();
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param node le noeud représenté par cette ligne
|
||||||
|
* @param str le texte à afficher sur la ligne
|
||||||
|
* @param depth profondeur dans l'arbre
|
||||||
|
*/
|
||||||
public Line(Node node, String str, int depth) {
|
public Line(Node node, String str, int depth) {
|
||||||
super();
|
super();
|
||||||
this.add(new MyJLabel(str));
|
this.add(new MyJLabel(str));
|
||||||
@ -26,51 +40,79 @@ public class Line extends MyJPanel {
|
|||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Line(Node node, String str, Color color, int depth) {
|
|
||||||
super();
|
|
||||||
this.add(new MyJLabel(str, color));
|
|
||||||
this.node = node;
|
|
||||||
this.depth = depth;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute du texte sur la ligne
|
||||||
|
* @param string le texte à ajouter
|
||||||
|
*/
|
||||||
public void add(String string) {
|
public void add(String string) {
|
||||||
lastElement = new MyJLabel(string);
|
lastElement = new MyJLabel(string);
|
||||||
this.add(lastElement);
|
this.add(lastElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute du texte sur la ligne
|
||||||
|
* @param string le texte à ajouter
|
||||||
|
* @param color la couleur du texte
|
||||||
|
*/
|
||||||
public void add(String string, Color color) {
|
public void add(String string, Color color) {
|
||||||
lastElement = new MyJLabel(string, color);
|
lastElement = new MyJLabel(string, color);
|
||||||
this.add(lastElement);
|
this.add(lastElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Node getNode() {
|
public Node getNode() {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getDepth() {
|
public int getDepth() {
|
||||||
return depth;
|
return depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isShow() {
|
public boolean isShow() {
|
||||||
return show;
|
return show;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change le statut de visibilité de la ligne à 'vrai'
|
||||||
|
*/
|
||||||
public void unfold() {
|
public void unfold() {
|
||||||
show = true;
|
show = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change le statut de visibilité de la ligne à 'faux'
|
||||||
|
*/
|
||||||
public void retreat() {
|
public void retreat() {
|
||||||
show = false;
|
show = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définit si la ligne représente la fin d'un noeud
|
||||||
|
*/
|
||||||
public void setClosingElement() {
|
public void setClosingElement() {
|
||||||
closingElement = true;
|
closingElement = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test si la ligne représente la fin d'un noeud
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public boolean isClosingElement() {
|
public boolean isClosingElement() {
|
||||||
return closingElement;
|
return closingElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enlève le dernier élément de la ligne
|
||||||
|
*/
|
||||||
public void removeClosingLabel() {
|
public void removeClosingLabel() {
|
||||||
try {
|
try {
|
||||||
if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) {
|
if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) {
|
||||||
|
@ -1,20 +1,27 @@
|
|||||||
package fr.sae.JSonInspector.Graphics;
|
package JsonInspector.Graphics;
|
||||||
|
|
||||||
import fr.sae.JSonInspector.Settings.Parameters;
|
import JsonInspector.Settings.Parameters;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class MyJLabel extends JLabel {
|
public class MyJLabel extends JLabel {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param text le texte à afficher
|
||||||
|
* @param color la couleur du texte
|
||||||
|
*/
|
||||||
public MyJLabel(String text, Color color) {
|
public MyJLabel(String text, Color color) {
|
||||||
super(text);
|
super(text);
|
||||||
// this.setFont(Parameters.FILE_FONT);
|
|
||||||
this.setForeground(color);
|
this.setForeground(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param text le texte à afficher
|
||||||
|
*/
|
||||||
public MyJLabel(String text) {
|
public MyJLabel(String text) {
|
||||||
super(text);
|
super(text);
|
||||||
// this.setFont(Parameters.FILE_FONT);
|
|
||||||
this.setForeground(Parameters.DEFAULT_TEXT_COLOR);
|
this.setForeground(Parameters.DEFAULT_TEXT_COLOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,27 @@
|
|||||||
package fr.sae.JSonInspector.Graphics;
|
package JsonInspector.Graphics;
|
||||||
|
|
||||||
import fr.sae.JSonInspector.Settings.Parameters;
|
import JsonInspector.Settings.Parameters;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class MyJPanel extends JPanel {
|
public class MyJPanel extends JPanel {
|
||||||
|
/**
|
||||||
|
* Construit un JPanel qui aligne tous ses éléments sur la gauche
|
||||||
|
* @param color la couleur de fond du panel
|
||||||
|
*/
|
||||||
public MyJPanel(Color color) {
|
public MyJPanel(Color color) {
|
||||||
super();
|
super();
|
||||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||||
this.setBackground(color);
|
this.setBackground(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construit un JPanel qui aligne tous ses éléments sur la gauche
|
||||||
|
*/
|
||||||
public MyJPanel() {
|
public MyJPanel() {
|
||||||
super();
|
super();
|
||||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||||
this.setBackground(Parameters.BACKGROUND_COLOR);
|
this.setBackground(Parameters.BACKGROUND_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyJPanel(boolean isTransparent) {
|
|
||||||
super();
|
|
||||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
|
||||||
this.setOpaque(isTransparent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user