Transférer les fichiers vers 'src/fr/sae/JSonInspector/Graphics'
This commit is contained in:
parent
d38211b431
commit
77cb91dc32
@ -1,149 +1,211 @@
|
||||
package fr.sae.JSonInspector.Graphics;
|
||||
|
||||
import fr.sae.JSonInspector.Exception.JsonSyntaxException;
|
||||
import fr.sae.JSonInspector.Main;
|
||||
import fr.sae.JSonInspector.Settings.Parameters;
|
||||
import fr.sae.JSonInspector.Storage.Tree;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Frame extends JFrame {
|
||||
private static final Dimension DEFAULT_FRAME_SIZE = new Dimension(800, 600);
|
||||
private static final Dimension MINIMUM_FRAME_SIZE = new Dimension(600, 500);
|
||||
private final CardLayout cards = new CardLayout();
|
||||
private boolean showTab = true;
|
||||
private JPanel secondCard;
|
||||
private GraphicFile file;
|
||||
private Tree tree;
|
||||
|
||||
public Frame() {
|
||||
super("Inspecteur JSON");
|
||||
init();
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.setSize(DEFAULT_FRAME_SIZE);
|
||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
this.setMinimumSize(MINIMUM_FRAME_SIZE);
|
||||
this.setLayout(cards);
|
||||
this.add(firstCard());
|
||||
// this.add(secondCard());
|
||||
cards.first(this.getContentPane());
|
||||
}
|
||||
|
||||
private JPanel firstCard() {
|
||||
GridBagLayout layout = new GridBagLayout();
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
JTextField textField = new JTextField("file:C:\\Users\\Elève\\Desktop\\temp\\jason.json", 30);
|
||||
JButton button = new JButton("Valider");
|
||||
button.addActionListener((event) -> validationAction(textField));
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(layout);
|
||||
|
||||
gbc.insets = new Insets(10, 10, 10, 10);
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
JLabel label = new JLabel("URL :");
|
||||
label.setForeground(Parameters.DEFAULT_TEXT_COLOR);
|
||||
panel.add(label, gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
panel.add(textField, gbc);
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(button, gbc);
|
||||
|
||||
panel.setBackground(Parameters.IHM_COLOR);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private JPanel secondCard() {
|
||||
file = new GraphicFile(this, tree);
|
||||
return initSecondCard(file);
|
||||
}
|
||||
|
||||
private JPanel secondCard(GraphicFile file) {
|
||||
this.file = file;
|
||||
return initSecondCard(file);
|
||||
}
|
||||
|
||||
private JPanel initSecondCard(GraphicFile file) {
|
||||
JButton unfoldButton = new JButton("Tout déplier");
|
||||
JButton retreatButton = new JButton("Tout replier");
|
||||
JButton backButton = new JButton("Retour");
|
||||
JPanel mainPanel = new JPanel(), southPanel = new JPanel();
|
||||
JScrollPane scroll = new JScrollPane();
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
|
||||
southPanel.setBackground(Parameters.IHM_COLOR);
|
||||
southPanel.add(backButton);
|
||||
backButton.addActionListener((event) -> backAction(mainPanel));
|
||||
southPanel.add(unfoldButton);
|
||||
unfoldButton.addActionListener((event) -> unfoldAction());
|
||||
southPanel.add(retreatButton);
|
||||
retreatButton.addActionListener((event) -> retreatAction());
|
||||
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 unfoldAction() {
|
||||
file.showAll();
|
||||
repaintFile();
|
||||
}
|
||||
|
||||
private void retreatAction() {
|
||||
file.retreatAll();
|
||||
repaintFile();
|
||||
}
|
||||
|
||||
public void repaintFile() {
|
||||
file = new GraphicFile(this, file.getLines());
|
||||
this.remove(secondCard);
|
||||
secondCard = secondCard(file);
|
||||
this.add(secondCard);
|
||||
cards.last(this.getContentPane());
|
||||
}
|
||||
|
||||
private void validationAction(JTextField field) {
|
||||
try {
|
||||
URL url = new URL(field.getText());
|
||||
String file = Main.getJsonInOneLine(url);
|
||||
|
||||
if (file.length() <= 2) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
tree = new Tree(file);
|
||||
secondCard = secondCard();
|
||||
this.add(secondCard);
|
||||
cards.last(this.getContentPane());
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
JOptionPane.showMessageDialog(this, "URL invalide", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
} catch (JsonSyntaxException j) {
|
||||
JOptionPane.showMessageDialog(this, "Erreur de syntax dans le fichier", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
} catch (FileNotFoundException f) {
|
||||
JOptionPane.showMessageDialog(this, "Impossible trouver le fichier", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void backAction(JPanel panel) {
|
||||
this.remove(panel);
|
||||
cards.first(this.getContentPane());
|
||||
}
|
||||
}
|
||||
package JsonInspector.Graphics;
|
||||
|
||||
import JsonInspector.Exception.JsonSyntaxException;
|
||||
import JsonInspector.Main;
|
||||
import JsonInspector.Settings.Parameters;
|
||||
import JsonInspector.Storage.Tree;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Frame extends JFrame {
|
||||
private static final Dimension DEFAULT_FRAME_SIZE = new Dimension(800, 600);
|
||||
private static final Dimension MINIMUM_FRAME_SIZE = new Dimension(600, 500);
|
||||
private final CardLayout cards = new CardLayout();
|
||||
private boolean php = false;
|
||||
private JPanel secondCard;
|
||||
private GraphicFile file;
|
||||
private Tree tree;
|
||||
|
||||
|
||||
public Frame() {
|
||||
super("Inspecteur JSON");
|
||||
init();
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
this.setSize(DEFAULT_FRAME_SIZE);
|
||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
this.setMinimumSize(MINIMUM_FRAME_SIZE);
|
||||
this.setLayout(cards);
|
||||
this.add(firstCard());
|
||||
//this.add(secondCard());
|
||||
cards.first(this.getContentPane());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Créer le premier panel où l'on entre l'URL du fichier
|
||||
* @return le panel créé
|
||||
*/
|
||||
private JPanel firstCard() {
|
||||
GridBagLayout layout = new GridBagLayout();
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
JTextField textField = new JTextField(30);
|
||||
JButton button = new JButton("Valider");
|
||||
button.addActionListener((event) -> validationAction(textField));
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(layout);
|
||||
|
||||
gbc.insets = new Insets(10, 10, 10, 10);
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
JLabel label = new JLabel("URL :");
|
||||
label.setForeground(Parameters.DEFAULT_TEXT_COLOR);
|
||||
panel.add(label, gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
panel.add(textField, gbc);
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.gridwidth = 2;
|
||||
panel.add(button, gbc);
|
||||
|
||||
panel.setBackground(Parameters.IHM_COLOR);
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Créer le deuxième panel où l'on voit le fichier
|
||||
* @return le panel créé
|
||||
*/
|
||||
private JPanel secondCard() {
|
||||
file = new GraphicFile(this, tree, php);
|
||||
return initSecondCard(file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Créer le deuxième panel où l'on voit le fichier
|
||||
* @return le panel créé
|
||||
*/
|
||||
private JPanel secondCard(GraphicFile file) {
|
||||
this.file = file;
|
||||
return initSecondCard(file);
|
||||
}
|
||||
|
||||
|
||||
private JPanel initSecondCard(GraphicFile file) {
|
||||
JButton unfoldButton = new JButton("Tout déplier");
|
||||
JButton retreatButton = new JButton("Tout replier");
|
||||
JButton convertButton = new JButton();
|
||||
JButton backButton = new JButton("Retour");
|
||||
JPanel mainPanel = new JPanel(), southPanel = new JPanel();
|
||||
JScrollPane scroll = new JScrollPane();
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
|
||||
if (php) {
|
||||
convertButton.setText("Convertir en JSON");
|
||||
} else {
|
||||
convertButton.setText("Convertir en PHP");
|
||||
}
|
||||
|
||||
southPanel.setBackground(Parameters.IHM_COLOR);
|
||||
southPanel.add(backButton);
|
||||
backButton.addActionListener((event) -> backAction(mainPanel));
|
||||
southPanel.add(unfoldButton);
|
||||
unfoldButton.addActionListener((event) -> unfoldAction());
|
||||
southPanel.add(retreatButton);
|
||||
retreatButton.addActionListener((event) -> retreatAction());
|
||||
southPanel.add(convertButton);
|
||||
convertButton.addActionListener((event) -> convertAction());
|
||||
|
||||
mainPanel.add(file);
|
||||
mainPanel.add(southPanel, BorderLayout.SOUTH);
|
||||
mainPanel.add(scroll);
|
||||
|
||||
scroll.setViewportView(file);
|
||||
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() {
|
||||
file.showAll();
|
||||
repaintFile();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replit l'élément cliqué
|
||||
*/
|
||||
private void retreatAction() {
|
||||
file.retreatAll();
|
||||
repaintFile();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Met à jour le fichier
|
||||
*/
|
||||
public void repaintFile() {
|
||||
file = new GraphicFile(this, file.getLines());
|
||||
this.remove(secondCard);
|
||||
secondCard = secondCard(file);
|
||||
this.add(secondCard);
|
||||
cards.last(this.getContentPane());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Passe du premier panel au second
|
||||
* @param field le champ contenant l'URL
|
||||
*/
|
||||
private void validationAction(JTextField field) {
|
||||
try {
|
||||
URL url = new URL(field.getText());
|
||||
String file = Main.getJsonInOneLine(url);
|
||||
|
||||
if (file.length() <= 2) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
tree = new Tree(file);
|
||||
secondCard = secondCard();
|
||||
this.add(secondCard);
|
||||
cards.last(this.getContentPane());
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
JOptionPane.showMessageDialog(this, "URL invalide", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
} catch (JsonSyntaxException j) {
|
||||
JOptionPane.showMessageDialog(this, "Erreur de syntax dans le fichier", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
} catch (FileNotFoundException f) {
|
||||
JOptionPane.showMessageDialog(this, "Impossible trouver le fichier", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Passe du second panel au premier
|
||||
* @param panel
|
||||
*/
|
||||
private void backAction(JPanel panel) {
|
||||
this.remove(panel);
|
||||
cards.first(this.getContentPane());
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,83 +1,125 @@
|
||||
package fr.sae.JSonInspector.Graphics;
|
||||
|
||||
import fr.sae.JSonInspector.Graphics.MyJLabel;
|
||||
import fr.sae.JSonInspector.Graphics.MyJPanel;
|
||||
import fr.sae.JSonInspector.Storage.Node;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Line extends MyJPanel {
|
||||
private boolean show = true;
|
||||
private final int depth;
|
||||
private final Node node;
|
||||
private MyJLabel lastElement;
|
||||
private boolean closingElement = false;
|
||||
|
||||
public Line(Node node, int depth) {
|
||||
super();
|
||||
this.node = node;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public Line(Node node, String str, int depth) {
|
||||
super();
|
||||
this.add(new MyJLabel(str));
|
||||
this.node = node;
|
||||
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;
|
||||
}
|
||||
|
||||
public void add(String string) {
|
||||
lastElement = new MyJLabel(string);
|
||||
this.add(lastElement);
|
||||
}
|
||||
|
||||
public void add(String string, Color color) {
|
||||
lastElement = new MyJLabel(string, color);
|
||||
this.add(lastElement);
|
||||
}
|
||||
|
||||
public Node getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public boolean isShow() {
|
||||
return show;
|
||||
}
|
||||
|
||||
public void unfold() {
|
||||
show = true;
|
||||
}
|
||||
|
||||
public void retreat() {
|
||||
show = false;
|
||||
}
|
||||
|
||||
public void setClosingElement() {
|
||||
closingElement = true;
|
||||
}
|
||||
|
||||
public boolean isClosingElement() {
|
||||
return closingElement;
|
||||
}
|
||||
|
||||
public void removeClosingLabel() {
|
||||
try {
|
||||
if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) {
|
||||
this.remove(lastElement);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
// System.out.println("La ligne est vide");
|
||||
}
|
||||
}
|
||||
}
|
||||
package JsonInspector.Graphics;
|
||||
|
||||
import JsonInspector.Storage.Node;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Représente une ligne dans l'IHM
|
||||
*/
|
||||
public class Line extends MyJPanel {
|
||||
private boolean show = true;
|
||||
private final int depth;
|
||||
private final Node node;
|
||||
private MyJLabel lastElement;
|
||||
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) {
|
||||
super();
|
||||
this.node = node;
|
||||
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) {
|
||||
super();
|
||||
this.add(new MyJLabel(str));
|
||||
this.node = node;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ajoute du texte sur la ligne
|
||||
* @param string le texte à ajouter
|
||||
*/
|
||||
public void add(String string) {
|
||||
lastElement = new MyJLabel(string);
|
||||
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) {
|
||||
lastElement = new MyJLabel(string, color);
|
||||
this.add(lastElement);
|
||||
}
|
||||
|
||||
|
||||
public Node getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
|
||||
public boolean isShow() {
|
||||
return show;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change le statut de visibilité de la ligne à 'vrai'
|
||||
*/
|
||||
public void unfold() {
|
||||
show = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change le statut de visibilité de la ligne à 'faux'
|
||||
*/
|
||||
public void retreat() {
|
||||
show = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Définit si la ligne représente la fin d'un noeud
|
||||
*/
|
||||
public void setClosingElement() {
|
||||
closingElement = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test si la ligne représente la fin d'un noeud
|
||||
* @return
|
||||
*/
|
||||
public boolean isClosingElement() {
|
||||
return closingElement;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enlève le dernier élément de la ligne
|
||||
*/
|
||||
public void removeClosingLabel() {
|
||||
try {
|
||||
if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) {
|
||||
this.remove(lastElement);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
//System.out.println("La ligne est vide");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,27 @@
|
||||
package fr.sae.JSonInspector.Graphics;
|
||||
|
||||
import fr.sae.JSonInspector.Settings.Parameters;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MyJLabel extends JLabel {
|
||||
public MyJLabel(String text, Color color) {
|
||||
super(text);
|
||||
// this.setFont(Parameters.FILE_FONT);
|
||||
this.setForeground(color);
|
||||
}
|
||||
|
||||
public MyJLabel(String text) {
|
||||
super(text);
|
||||
// this.setFont(Parameters.FILE_FONT);
|
||||
this.setForeground(Parameters.DEFAULT_TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
package JsonInspector.Graphics;
|
||||
|
||||
import JsonInspector.Settings.Parameters;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MyJLabel extends JLabel {
|
||||
/**
|
||||
*
|
||||
* @param text le texte à afficher
|
||||
* @param color la couleur du texte
|
||||
*/
|
||||
public MyJLabel(String text, Color color) {
|
||||
super(text);
|
||||
this.setForeground(color);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param text le texte à afficher
|
||||
*/
|
||||
public MyJLabel(String text) {
|
||||
super(text);
|
||||
this.setForeground(Parameters.DEFAULT_TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,27 @@
|
||||
package fr.sae.JSonInspector.Graphics;
|
||||
|
||||
import fr.sae.JSonInspector.Settings.Parameters;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MyJPanel extends JPanel {
|
||||
public MyJPanel(Color color) {
|
||||
super();
|
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
this.setBackground(color);
|
||||
}
|
||||
|
||||
public MyJPanel() {
|
||||
super();
|
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
this.setBackground(Parameters.BACKGROUND_COLOR);
|
||||
}
|
||||
|
||||
public MyJPanel(boolean isTransparent) {
|
||||
super();
|
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
this.setOpaque(isTransparent);
|
||||
}
|
||||
}
|
||||
package JsonInspector.Graphics;
|
||||
|
||||
import JsonInspector.Settings.Parameters;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
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) {
|
||||
super();
|
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
this.setBackground(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construit un JPanel qui aligne tous ses éléments sur la gauche
|
||||
*/
|
||||
public MyJPanel() {
|
||||
super();
|
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
this.setBackground(Parameters.BACKGROUND_COLOR);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user