This commit is contained in:
pro.boooooo 2023-01-15 20:08:18 +01:00
parent b7cd8d1d37
commit 068f0f3b50
38 changed files with 1113 additions and 2062 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,37 +1,37 @@
package JsonInspector; package JsonInspector;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
public class ArrayObjectListener implements MouseListener { public class ArrayObjectListener implements MouseListener {
private final Line line; private final Line line;
private final Frame frame; private final Frame frame;
public ArrayObjectListener(Line line, Frame frame) { public ArrayObjectListener(Line line, Frame frame) {
this.line = line; this.line = line;
this.frame = frame; this.frame = frame;
} }
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (line.isShow()) { if (line.isShow()) {
line.retreat(); line.retreat();
} else { } else {
line.unfold(); line.unfold();
} }
frame.repaintFile(); frame.repaintFile();
} }
@Override @Override
public void mousePressed(MouseEvent e) {} public void mousePressed(MouseEvent e) {}
@Override @Override
public void mouseReleased(MouseEvent e) {} public void mouseReleased(MouseEvent e) {}
@Override @Override
public void mouseEntered(MouseEvent e) {} public void mouseEntered(MouseEvent e) {}
@Override @Override
public void mouseExited(MouseEvent e) {} public void mouseExited(MouseEvent e) {}
} }

View File

@ -1,117 +0,0 @@
package Console;
import java.net.URL;
import java.io.InputStream;
import java.io.IOException;
/**
* [Bilal]
* Afficher le code JSON dans la console une fois formatter
*/
public class DisplayConsole {
private URL jsonFile;
public DisplayConsole(URL jsonFile) {
this.jsonFile = jsonFile;
if (this.Display() == null) {
System.out.println("[!] Probleme lors du formatage de : " + this.jsonFile.getFile());
} else {
System.out.println(this.Display());
}
}
private String Display() {
try {
InputStream jsonReader = this.jsonFile.openStream();
StringBuilder containerJsonFormatted = new StringBuilder();
int indentLevel = 0;
boolean currentlyInRecord = false;
int cursor = jsonReader.read();
while (cursor != -1) {
char c = (char) cursor;
switch (c) {
case '{': {
containerJsonFormatted.append(c);
if (!currentlyInRecord) {
containerJsonFormatted.append("\n");
indentLevel++;
this.addIndentation(containerJsonFormatted, indentLevel);
}
break;
}
case '[': {
containerJsonFormatted.append(c);
if (!currentlyInRecord) {
containerJsonFormatted.append("\n");
indentLevel++;
this.addIndentation(containerJsonFormatted, indentLevel);
}
break;
}
case '"': {
currentlyInRecord = !currentlyInRecord;
containerJsonFormatted.append(c);
break;
}
case ':': {
containerJsonFormatted.append(c).append(" ");
break;
}
case ',': {
containerJsonFormatted.append(c);
if (!currentlyInRecord) {
containerJsonFormatted.append("\n");
this.addIndentation(containerJsonFormatted, indentLevel);
}
break;
}
case ']': {
if (!currentlyInRecord) {
containerJsonFormatted.append("\n");
indentLevel--;
this.addIndentation(containerJsonFormatted, indentLevel);
}
containerJsonFormatted.append(c);
break;
}
case '}': {
if (!currentlyInRecord) {
containerJsonFormatted.append("\n");
indentLevel--;
this.addIndentation(containerJsonFormatted, indentLevel);
}
containerJsonFormatted.append(c);
break;
}
default: {
containerJsonFormatted.append(c);
break;
}
}
cursor = jsonReader.read();
}
jsonReader.close();
return containerJsonFormatted.toString();
} catch (IOException e) {
System.out.println("[!] Fichier " + this.jsonFile.getFile() + " n'existe pas");
return null;
}
}
private void addIndentation(StringBuilder sb, int indentLevel) {
for (int i = 0; i < indentLevel; i++) {
sb.append("\t");
}
}
}

View File

@ -1,24 +0,0 @@
import java.io.File;
import Console.DisplayConsole;
import Graphics.GraphicsCore;
/**
* [Bilal et Romain]
* Programme pour afficher un code json dans le teminal ou sur une JFrame (avec
* les options tel que: la coloration syntaxique, repli de tableau etc...)
*/
public class Core {
public static void main(String[] args) {
if (args.length == 1) {
try {
new DisplayConsole(new File(args[0]).toURI().toURL());
} catch (Exception e) {
System.out.println(e);
}
} else if (args.length == 0) {
new GraphicsCore();
} else {
System.out.println("[!] Utilisation: ./jsonFormatter <path>");
}
}
}

View File

@ -1,155 +1,155 @@
package JsonInspector; package JsonInspector;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
public class Frame extends JFrame { 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 showTab = true;
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);
this.setMinimumSize(MINIMUM_FRAME_SIZE); this.setMinimumSize(MINIMUM_FRAME_SIZE);
this.setLayout(cards); this.setLayout(cards);
this.add(firstCard()); this.add(firstCard());
//this.add(secondCard()); //this.add(secondCard());
cards.first(this.getContentPane()); cards.first(this.getContentPane());
} }
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("file:C:\\Users\\Elève\\Desktop\\temp\\jason.json", 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();
panel.setLayout(layout); panel.setLayout(layout);
gbc.insets = new Insets(10, 10, 10, 10); gbc.insets = new Insets(10, 10, 10, 10);
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = 0; gbc.gridy = 0;
JLabel label = new JLabel("URL :"); JLabel label = new JLabel("URL :");
label.setForeground(Parameters.DEFAULT_TEXT_COLOR); label.setForeground(Parameters.DEFAULT_TEXT_COLOR);
panel.add(label, gbc); panel.add(label, gbc);
gbc.gridx = 1; gbc.gridx = 1;
panel.add(textField, gbc); panel.add(textField, gbc);
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = 1; gbc.gridy = 1;
gbc.gridwidth = 2; gbc.gridwidth = 2;
panel.add(button, gbc); panel.add(button, gbc);
panel.setBackground(Parameters.IHM_COLOR); panel.setBackground(Parameters.IHM_COLOR);
return panel; return panel;
} }
private JPanel secondCard() { private JPanel secondCard() {
file = new GraphicFile(this, tree); file = new GraphicFile(this, tree);
return initSecondCard(file); return initSecondCard(file);
} }
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 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());
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));
southPanel.add(unfoldButton); southPanel.add(unfoldButton);
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(new JButton("convertir en PHP"));
mainPanel.add(file); mainPanel.add(file);
mainPanel.add(southPanel, BorderLayout.SOUTH); mainPanel.add(southPanel, BorderLayout.SOUTH);
mainPanel.add(scroll); mainPanel.add(scroll);
scroll.setViewportView(file); scroll.setViewportView(file);
return mainPanel; return mainPanel;
} }
private void unfoldAction() { private void unfoldAction() {
file.showAll(); file.showAll();
repaintFile(); repaintFile();
} }
private void retreatAction() { private void retreatAction() {
file.retreatAll(); file.retreatAll();
repaintFile(); repaintFile();
} }
public void repaintFile() { public void repaintFile() {
file = new GraphicFile(this, file.getLines()); file = new GraphicFile(this, file.getLines());
this.remove(secondCard); this.remove(secondCard);
secondCard = secondCard(file); secondCard = secondCard(file);
this.add(secondCard); this.add(secondCard);
cards.last(this.getContentPane()); cards.last(this.getContentPane());
} }
private void validationAction(JTextField field) { private void validationAction(JTextField field) {
try { try {
URL url = new URL(field.getText()); URL url = new URL(field.getText());
String file = Main.getJsonInOneLine(url); String file = Main.getJsonInOneLine(url);
if (file.length() <= 2) { if (file.length() <= 2) {
throw new FileNotFoundException(); throw new FileNotFoundException();
} }
tree = new Tree(file); tree = new Tree(file);
secondCard = secondCard(); secondCard = secondCard();
this.add(secondCard); this.add(secondCard);
cards.last(this.getContentPane()); cards.last(this.getContentPane());
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
JOptionPane.showMessageDialog(this, "URL invalide", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, "URL invalide", "Error", JOptionPane.ERROR_MESSAGE);
} catch (JsonSyntaxException j) { } catch (JsonSyntaxException j) {
JOptionPane.showMessageDialog(this, "Erreur de syntax dans le fichier", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, "Erreur de syntax dans le fichier", "Error", JOptionPane.ERROR_MESSAGE);
} catch (FileNotFoundException f) { } catch (FileNotFoundException f) {
JOptionPane.showMessageDialog(this, "Impossible trouver le fichier", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, "Impossible trouver le fichier", "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());
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,89 +0,0 @@
package Graphics;
import java.io.InputStream;
import java.io.IOException;
import java.util.HashMap;
import javax.swing.JLabel;
import javax.swing.JPanel;
import Graphics.Type.*;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.util.List;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Color;
import java.net.URL;
/**
* [Romain]
* Pour gerer l'affichage graphique du code JSON
*/
public class GraphicFile extends JPanel {
/**
* @param url Le chemin vers le fichier JSON
*/
public GraphicFile(URL url) {
super();
try {
System.out.println("[+] Lecture de " + url);
this.setLayout(new FlowLayout(FlowLayout.LEFT));
this.setLocation(500, 500);
InputStream jsonReader = url.openStream();
Traitable fileTraited = new Traitable(jsonReader);
jsonReader.close();
HashMap<String, Type<?>> allVariables = fileTraited.getVariableMap();
JPanel core = new JPanel(new GridBagLayout());
GridBagConstraints settings = new GridBagConstraints();
settings.gridx = 0;
settings.gridy = 0;
settings.anchor = GridBagConstraints.WEST;
core.add(new JLabel("{"), settings);
int rows = 1;
settings.gridy = 1;
settings.gridx = 2;
for (String key : allVariables.keySet()) {
JPanel fusion = new JPanel(new GridLayout(1, 1));
settings.gridy = rows;
JLabel name = new JLabel("\"" + key + "\": ");
name.setForeground(new Color(163, 90, 0));
fusion.add(name);
if (allVariables.get(key).getClass().getName() != "Graphics.Type.Array") {
JLabel value = new JLabel(allVariables.get(key).display());
value.setForeground(allVariables.get(key).getColor());
fusion.add(value);
} else {
JPanel speForArray = new JPanel();
speForArray.add(new JLabel("[ "));
for (int i = 0; i <= allVariables.get(key).listGet().size() - 1; i++) {
JLabel tmp = new JLabel(String.valueOf(allVariables.get(key).listGet().get(i).display()));
tmp.setForeground(allVariables.get(key).listGet().get(i).getColor());
speForArray.add(tmp);
}
speForArray.add(new JLabel(" ]"));
fusion.add(speForArray);
}
core.add(fusion, settings);
rows++;
}
settings.gridx = 0;
settings.gridy = rows;
core.add(new JLabel("}"), settings);
this.add(core);
this.setVisible(true);
} catch (IOException e) {
System.out.println("[!] Fichier " + url.getFile() + " n'existe pas");
}
}
}

View File

@ -1,172 +0,0 @@
package Graphics;
import java.io.File;
import java.net.MalformedURLException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import javax.swing.JFileChooser;
import java.net.URL;
import java.awt.Dimension;
import java.awt.CardLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.BorderLayout;
import javax.swing.filechooser.FileSystemView;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
* [Romain]
* Faire le pont entre la selection du fichier JSON et l'affichage
* graphique du code JSON
*/
public class GraphicsCore extends JFrame {
private final Dimension DEFAULT_FRAME_SIZE = new Dimension(800, 600);
private final Dimension MINIMUM_FRAME_SIZE = new Dimension(600, 500);
private final CardLayout cards;
private JLabel textField;
private URL url;
public GraphicsCore() {
super("Inspecteur JSON - Romain & Bilal");
this.url = null;
this.textField = new JLabel("Clique ici pour choisir le chemin du fichier JSON ->");
this.cards = new CardLayout();
this.init();
this.add(firstCard());
cards.last(this.getContentPane());
this.setVisible(true);
}
/**
* Initalisation des parametres de la Frame par defaut.
*/
private void init() {
this.setSize(DEFAULT_FRAME_SIZE);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setMinimumSize(MINIMUM_FRAME_SIZE);
this.setLayout(cards);
this.add(firstCard());
cards.first(this.getContentPane());
}
/**
* Creation de la fenetre ou l'on nous demande de chemin absolut du fichier JSON
*
* @return Le JPanel de la premiere card du CardLayout
*/
private JPanel firstCard() {
GridBagLayout layout = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
this.textField = new JLabel("Clique ici pour choisir le chemin du fichier JSON ->");
JButton button = new JButton("Valider");
button.addActionListener((event) -> validationAction(this.textField.getText()));
JButton selectedFile = new JButton("...");
selectedFile.addActionListener((event) -> getPathOf());
JPanel panel = new JPanel();
panel.setLayout(layout);
gbc.insets = new Insets(10, 10, 10, 10);
gbc.gridx = 0;
gbc.gridy = 0;
panel.add(new JLabel("URL :"), gbc);
gbc.gridx = 1;
panel.add(this.textField, gbc);
gbc.gridx = 2;
panel.add(selectedFile, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
panel.add(button, gbc);
return panel;
}
/**
* Creation de la fenetre ou sera afficher le code du fichier JSON
*
* @return Le JPanel contenant le rendu de Traitable
* @see Graphics.Traitable
*/
private JPanel secondCard() {
GraphicFile file = new GraphicFile(this.url);
JPanel mainPanel = new JPanel(), southPanel = new JPanel();
JButton backButton = new JButton("Retour");
backButton.addActionListener((event) -> backAction(mainPanel));
JScrollPane scroll = new JScrollPane();
mainPanel.setLayout(new BorderLayout());
southPanel.add(backButton);
southPanel.add(new JButton("Tout déplier"));
southPanel.add(new JButton("convertir en PHP"));
mainPanel.add(file, BorderLayout.CENTER);
mainPanel.add(southPanel, BorderLayout.SOUTH);
mainPanel.add(scroll);
scroll.setViewportView(file);
return mainPanel;
}
/**
* Permet de la fenetre ou l'on nous demande de chemin absolut du fichier JSON
*
* @param field Le chemin absolue du fichier JSON
*/
private void validationAction(String field) {
try {
this.url = new File(field).toURI().toURL();
this.add(secondCard());
cards.last(this.getContentPane());
} catch (MalformedURLException e) {
JOptionPane.showMessageDialog(this, "Invalid URL", "Error", JOptionPane.ERROR_MESSAGE);
}
}
/**
* Retourner dans la selection du fichier JSON
*
* @param panel Le JPanel ou l'on demande a l'utilisateur de choisir le fichier
* JSON
*/
private void backAction(JPanel panel) {
this.remove(panel);
cards.first(this.getContentPane());
}
/**
* Selection du fichier JSON
*/
private void getPathOf() {
JFileChooser jc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
jc.setDialogTitle("Choissez le fichier json: ");
jc.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichier JSON", "json");
jc.setFileFilter(filter);
int res = jc.showOpenDialog(this);
if (res == JFileChooser.APPROVE_OPTION) {
if (jc.getSelectedFile().isFile()) {
this.textField.setText(jc.getSelectedFile().getAbsolutePath());
this.revalidate();
}
}
}
}

View File

@ -1,221 +0,0 @@
package Graphics;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.LinkedList;
import Graphics.Type.*;
import java.io.IOException;
import java.io.InputStream;
/**
* [Bilal]
* Classe qui sert a stocke les valeurs contenue dans le JSON dans une liste.
*/
public class Traitable {
private final HashMap<String, String> contentRaw;
private final HashMap<String, Type<?>> content;
private final InputStream file;
public Traitable(InputStream file) {
this.contentRaw = new LinkedHashMap<>();
this.content = new LinkedHashMap<>();
this.file = file;
this.Run();
}
/**
* Lancement automatique une fois que Traitable est instantie
*
* @see Graphics.GraphicFile
*/
private void Run() {
System.out.println("[+] Preparation...");
try {
try {
StringBuilder allJson = new StringBuilder();
StringBuilder tmp = new StringBuilder();
int i = 0;
for (int cursor = this.file.read(); cursor != -1; cursor = this.file.read()) {
char c = (char) cursor;
allJson.append(c);
}
allJson = this.ajustementVirguleEnd(allJson.toString());
while (i < allJson.length()) {
if (allJson.charAt(i) == '"') {
while (allJson.charAt(i) != ',') {
if (allJson.charAt(i) == '[') {
while (allJson.charAt(i) != ']') {
tmp.append(allJson.charAt(i));
i++;
}
} else if (allJson.charAt(i) == '{') {
while (allJson.charAt(i) != '}') {
tmp.append(allJson.charAt(i));
i++;
}
} else {
tmp.append(allJson.charAt(i));
i++;
}
}
String[] varInfo = this.getInfoOfRecord(tmp);
this.saveValue(varInfo[0], varInfo[1]);
tmp.setLength(0);
i++;
}
i++;
}
} catch (StringIndexOutOfBoundsException ignore) {
}
} catch (IOException e) {
System.out.println("[!] Probleme lors de la lecture du fichier");
}
}
/**
* Enregistre dans la HashMap la valeur
*
* @param name Le nom de l'entree
* @param value La valeur de l'entree
*
* @see Graphics.Type.Type
* @see java.util.HashMap
*/
private void saveValue(String name, String value) {
String typeOfValue = this.getType(value);
switch (typeOfValue) {
case "string": {
this.content.put(name, new Chaine(String.valueOf(value)));
break;
}
case "int": {
this.content.put(name, new Entier(Integer.valueOf(value)));
break;
}
case "double": {
this.content.put(name, new Flottant(Double.valueOf(value)));
break;
}
case "boolean": {
this.content.put(name, new Bool(Boolean.valueOf(value)));
break;
}
case "array": {
this.content.put(name, new Array(value));
break;
}
}
}
/**
* Sert a detecter le type d'une valeur
*
* @param value La chaine a evolue pour determiner son type
* @return Le type
*/
private String getType(String value) {
if (value.contains("{")) {
return "object";
} else if (value.contains("[")) {
return "array";
} else if (value.contains("true") || value.contains("false")) {
return "boolean";
} else if (value.contains(".")) {
return "double";
} else if (value.contains("null")) {
return "null";
} else if (value.contains("\"")) {
return "string";
} else {
return "int";
}
}
/**
* Recuperer le nom et la valeur divise sous forme de tableau
*
* @param sb La phrase a separer
* @return Un tableau { 0 = nom, 1 = value }
*/
private String[] getInfoOfRecord(StringBuilder sb) {
String[] info = sb.toString().split(":");
info[0] = this.removeSpeChar(info[0]);
info[1] = this.removeFirstSpaceIfThere(info[1]);
return info;
}
/**
* Retourne une valeur JSON qui, si elle contient un espace au debut, le
* supprime
*
* @param str La valeur JSON
* @return La valeur JSON sans l'espace au debut si il y en a un
*/
private String removeFirstSpaceIfThere(String str) {
if (str.length() > 0 && str.charAt(0) == ' ') {
str = str.substring(1);
}
return str;
}
/**
* Sert a retirer le charactere guillemet
*
* @param str La phrase a soustraire le symbole guillemet
* @return Retourner une chaine sans le charactere guillemet
*/
private String removeSpeChar(String str) {
StringBuilder tmp = new StringBuilder();
for (int i = 0; i <= str.length() - 1; i++) {
if (str.charAt(i) != '"') {
tmp.append(str.charAt(i));
}
}
return tmp.toString();
}
/**
* Sert a rajouter une virgule a l'avant dernier charactre du fichier (pour ne
* pas skipper la derniere cle valeur)
*
* @param str Le fichier json en une ligne
* @return Le fichier avec la fameuse virgule
*/
private StringBuilder ajustementVirguleEnd(String str) {
int longueur = str.length();
char avantDernierCaractere = str.charAt(longueur - 2);
String nouvelleChaine = str.substring(0, longueur - 2) + avantDernierCaractere + ","
+ str.substring(longueur - 1);
return new StringBuilder(nouvelleChaine);
}
/**
* Recuperer le jeu de cles valeurs dans GrahicFile
*
* @see Graphics.GraphicFile
* @return Le jeu de cles valeurs
*/
public HashMap<String, Type<?>> getVariableMap() {
return this.content;
}
}

View File

@ -1,114 +0,0 @@
package Graphics.Type;
import java.awt.Color;
import Graphics.Type.*;
import java.util.LinkedList;
import java.util.List;
/**
* Representation d'un tableau d'object
*/
public class Array implements Type<List<Type<?>>> {
private String valueRaw;
private List<Type<?>> value;
private Color color;
public Array(String valueRaw) {
this.valueRaw = valueRaw.substring(1, valueRaw.length() - 1);
this.value = new LinkedList<>();
this.Run();
}
public void Run() {
String[] spliced = this.valueRaw.split(",");
List<Type<?>> list = new LinkedList<>();
for (int i = 0; i <= spliced.length - 1; i++) {
switch (this.getType(spliced[i])) {
case "string": {
list.add(new Chaine(String.valueOf(spliced[i])));
break;
}
case "int": {
list.add(new Entier(Integer.valueOf(spliced[i])));
break;
}
case "double": {
list.add(new Flottant(Double.valueOf(spliced[i])));
break;
}
case "boolean": {
list.add(new Bool(Boolean.valueOf(spliced[i])));
break;
}
}
}
this.value = list;
}
public String getType(String value) {
if (value.contains("{")) {
return "object";
} else if (value.contains("[")) {
return "array";
} else if (value.contains("\"")) {
return "string";
} else if (value.contains("true") || value.contains("false")) {
return "boolean";
} else if (value.contains(".")) {
return "double";
} else if (value.contains("null")) {
return "null";
} else {
return "int";
}
}
public String getValueRaw() {
return this.valueRaw;
}
@Override
public List<Type<?>> listGet() {
return this.value;
}
@Override
public Color getColor() {
return this.color;
}
@Override
public String display() {
StringBuilder str = new StringBuilder();
str.append("[ ");
for (int i = 0; i <= this.value.size() - 1; i++) {
str.append(this.value.get(i).display() + ", ");
}
str.deleteCharAt(str.length() - 1);
str.deleteCharAt(str.length() - 1);
str.append(" ]");
return str.toString();
}
@Override
public String getType() {
return "array";
}
@Override
public List<Type<?>> getValue() {
return this.value;
}
}

View File

@ -1,47 +0,0 @@
package Graphics.Type;
import java.awt.Color;
import java.util.List;
/**
* Representation du type boolean
*/
public class Bool implements Type<Boolean> {
private Boolean value;
private Color color;
public Bool(Boolean value) {
this.value = value;
if (value) {
this.color = Color.GREEN;
} else {
this.color = Color.RED;
}
}
@Override
public List<Type<?>> listGet() {
return null;
}
@Override
public Color getColor() {
return this.color;
}
@Override
public String display() {
return String.valueOf(value);
}
@Override
public String getType() {
return "boolean";
}
@Override
public Boolean getValue() {
return this.value;
}
}

View File

@ -1,43 +0,0 @@
package Graphics.Type;
import java.awt.Color;
import java.util.List;
/**
* Representation du type string
*/
public class Chaine implements Type<String> {
private String value;
private Color color;
public Chaine(String value) {
this.value = value;
this.color = Color.PINK;
}
@Override
public List<Type<?>> listGet() {
return null;
}
@Override
public Color getColor() {
return this.color;
}
@Override
public String display() {
return String.valueOf(value);
}
@Override
public String getType() {
return "string";
}
@Override
public String getValue() {
return this.value;
}
}

View File

@ -1,43 +0,0 @@
package Graphics.Type;
import java.awt.Color;
import java.util.List;
/**
* Representation du type int
*/
public class Entier implements Type<Integer> {
public Integer value;
private Color color;
public Entier(Integer value) {
this.value = value;
this.color = Color.BLUE;
}
@Override
public List<Type<?>> listGet() {
return null;
}
@Override
public Color getColor() {
return this.color;
}
@Override
public String display() {
return String.valueOf(value);
}
@Override
public String getType() {
return "int";
}
@Override
public Integer getValue() {
return this.value;
}
}

View File

@ -1,43 +0,0 @@
package Graphics.Type;
import java.awt.Color;
import java.util.List;
/**
* Representation du type double
*/
public class Flottant implements Type<Double> {
private Double value;
private Color color;
public Flottant(Double value) {
this.value = value;
this.color = Color.BLUE;
}
@Override
public List<Type<?>> listGet() {
return null;
}
@Override
public Color getColor() {
return this.color;
}
@Override
public String display() {
return String.valueOf(value);
}
@Override
public String getType() {
return "double";
}
@Override
public Double getValue() {
return this.value;
}
}

View File

@ -1,36 +0,0 @@
package Graphics.Type;
import java.awt.Color;
import java.util.List;
public interface Type<T> {
/**
* Retourner le type de la variable
*
* @return le type en string
*/
public String getType();
/**
*
* @return
*/
public T getValue();
/**
* Recuperer la couleur de syntaxe d'un type
*/
public Color getColor();
/**
* Afficher la valeur / toutes les valeurs
*/
public String display();
/**
* UNIQUEMENT POUR Graphics.Type.Chaine
*
* @return La liste contenant les valeurs du tableau
*/
public List<Type<?>> listGet();
}

View File

@ -1,9 +1,9 @@
package JsonInspector; package JsonInspector;
public class JsonSyntaxException extends Throwable { public class JsonSyntaxException extends Throwable {
private static final String MESSAGE = "Syntax error in JSON file"; private static final String MESSAGE = "Syntax error in JSON file";
public JsonSyntaxException() { public JsonSyntaxException() {
super(MESSAGE); super(MESSAGE);
} }
} }

View File

@ -1,92 +1,92 @@
package JsonInspector; package JsonInspector;
import java.awt.*; import java.awt.*;
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;
private final Node node; private final Node node;
private MyJLabel lastElement; private MyJLabel lastElement;
private boolean closingElement = false; private boolean closingElement = false;
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;
} }
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));
this.node = node; this.node = node;
this.depth = depth; this.depth = depth;
} }
public Line(Node node, String str, Color color, int depth) { public Line(Node node, String str, Color color, int depth) {
super(); super();
this.add(new MyJLabel(str, color)); this.add(new MyJLabel(str, color));
this.node = node; this.node = node;
this.depth = depth; this.depth = depth;
} }
public void add(String string) { public void add(String string) {
lastElement = new MyJLabel(string); lastElement = new MyJLabel(string);
this.add(lastElement); this.add(lastElement);
} }
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;
} }
public void unfold() { public void unfold() {
show = true; show = true;
} }
public void retreat() { public void retreat() {
show = false; show = false;
} }
public void setClosingElement() { public void setClosingElement() {
closingElement = true; closingElement = true;
} }
public boolean isClosingElement() { public boolean isClosingElement() {
return closingElement; return closingElement;
} }
public void removeClosingLabel() { public void removeClosingLabel() {
try { try {
if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) { if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) {
this.remove(lastElement); this.remove(lastElement);
} }
} catch (NullPointerException e) { } catch (NullPointerException e) {
//System.out.println("La ligne est vide"); //System.out.println("La ligne est vide");
} }
} }
} }

View File

@ -1,18 +1,18 @@
package JsonInspector; package JsonInspector;
import javax.swing.*; import javax.swing.*;
import java.awt.*; 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);
} }
} }

View File

@ -1,24 +1,24 @@
package JsonInspector; package JsonInspector;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
public class MyJPanel extends JPanel { public class MyJPanel extends JPanel {
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);
} }
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) { public MyJPanel(boolean isTransparent) {
super(); super();
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
this.setOpaque(isTransparent); this.setOpaque(isTransparent);
} }
} }

View File

@ -1,115 +1,115 @@
package JsonInspector; package JsonInspector;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
public class Node { public class Node {
private final ArrayList<Value> values = new ArrayList<>(); private final ArrayList<Value> values = new ArrayList<>();
private final String name; private final String name;
private final Type type; private final Type type;
public Node(String name, Type type) { public Node(String name, Type type) {
this.type = type; this.type = type;
if (type == Type.ELEMENT) { if (type == Type.ELEMENT) {
this.name = ""; this.name = "";
} else { } else {
this.name = name; this.name = name;
} }
} }
private void findType(String value) { private void findType(String value) {
if (value.charAt(0) == '"' && value.charAt(value.length()-1) == '"') { if (value.charAt(0) == '"' && value.charAt(value.length()-1) == '"') {
values.add(new Value<String>(Tree.cleanOpeningExpression(value))); values.add(new Value<String>(Tree.cleanOpeningExpression(value)));
return; return;
} }
try { try {
values.add(new Value<Integer>(Integer.parseInt(value))); values.add(new Value<Integer>(Integer.parseInt(value)));
} catch (NumberFormatException nfeInt) { } catch (NumberFormatException nfeInt) {
try { try {
values.add(new Value<Double>(Double.parseDouble(value))); values.add(new Value<Double>(Double.parseDouble(value)));
} catch (NumberFormatException nfeDouble) { } catch (NumberFormatException nfeDouble) {
values.add(new Value<Other>(new Other(value))); values.add(new Value<Other>(new Other(value)));
} }
} }
} }
public <T> void add(T value) { public <T> void add(T value) {
if (value != null) { if (value != null) {
if (value.getClass().equals(Node.class)) { if (value.getClass().equals(Node.class)) {
values.add(new Value<T>(value)); values.add(new Value<T>(value));
} else { } else {
findType((String) value); findType((String) value);
} }
} }
} }
public Type getType() { public Type getType() {
return type; return type;
} }
public String getName() { public String getName() {
return name; return name;
} }
public Value get(int index) { public Value get(int index) {
return values.get(index); return values.get(index);
} }
public int getSize() { public int getSize() {
return values.size(); return values.size();
} }
public boolean isObject() { public boolean isObject() {
return type == Type.OBJECT; return type == Type.OBJECT;
} }
public boolean isArray() { public boolean isArray() {
return type == Type.ARRAY; return type == Type.ARRAY;
} }
public boolean isElement() { public boolean isElement() {
return type == Type.ELEMENT; return type == Type.ELEMENT;
} }
public boolean isPair() { public boolean isPair() {
return type == Type.PAIR; return type == Type.PAIR;
} }
public boolean isArrayObjectElement() { public boolean isArrayObjectElement() {
boolean array = type == Type.ARRAY; boolean array = type == Type.ARRAY;
boolean object = type == Type.OBJECT; boolean object = type == Type.OBJECT;
boolean element = type == Type.ELEMENT; boolean element = type == Type.ELEMENT;
if (array || object || element) { if (array || object || element) {
return true; return true;
} }
return false; return false;
} }
@Override @Override
public String toString() { public String toString() {
String string = name + " : "; String string = name + " : ";
for (int i = 0; i < values.size(); i++) { for (int i = 0; i < values.size(); i++) {
string += values.get(i) + ", "; string += values.get(i) + ", ";
} }
return string; return string;
} }
} }

View File

@ -1,16 +1,16 @@
package JsonInspector; package JsonInspector;
public class Other { public class Other {
String value; String value;
public Other(String value) { public Other(String value) {
this.value = value; this.value = value;
} }
@Override @Override
public String toString() { public String toString() {
return value; return value;
} }
} }

View File

@ -1,20 +1,20 @@
package JsonInspector; package JsonInspector;
import java.awt.*; import java.awt.*;
public class Parameters { public class Parameters {
public static final Font FILE_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 18); public static final Font FILE_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 18);
public static final String IHM_INDENTATION = " "; public static final String IHM_INDENTATION = " ";
public static final String CONSOLE_INDENTATION = " "; public static final String CONSOLE_INDENTATION = " ";
public static final String ARRAY_CLOSING = "...]"; public static final String ARRAY_CLOSING = "...]";
public static final String OBJECT_ELEMENT_CLOSING = "...}"; public static final String OBJECT_ELEMENT_CLOSING = "...}";
public static final Color IHM_COLOR = new Color(70, 70, 70); public static final Color IHM_COLOR = new Color(70, 70, 70);
public static final Color KEY_COLOR = new Color(70, 189, 204); public static final Color KEY_COLOR = new Color(70, 189, 204);
public static final Color OTHER_COLOR = new Color(7, 103, 183); public static final Color OTHER_COLOR = new Color(7, 103, 183);
public static final Color STRING_COLOR = new Color(203, 109, 80); public static final Color STRING_COLOR = new Color(203, 109, 80);
public static final Color NUMBER_COLOR = new Color(133, 192, 95); public static final Color NUMBER_COLOR = new Color(133, 192, 95);
public static final Color MOUSE_OVER_COLOR = new Color(60, 60, 60); public static final Color MOUSE_OVER_COLOR = new Color(60, 60, 60);
public static final Color DEFAULT_TEXT_COLOR = new Color(220, 220, 220); public static final Color DEFAULT_TEXT_COLOR = new Color(220, 220, 220);
public static final Color BACKGROUND_COLOR = new Color(45, 45, 45); public static final Color BACKGROUND_COLOR = new Color(45, 45, 45);
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
package JsonInspector; package JsonInspector;
public enum Type { public enum Type {
OBJECT, ELEMENT, ARRAY, PAIR, NULL OBJECT, ELEMENT, ARRAY, PAIR, NULL
} }

View File

@ -1,44 +1,44 @@
package JsonInspector; package JsonInspector;
public class Value <T> { public class Value <T> {
private T value; private T value;
public Value(T value) { public Value(T value) {
this.value = value; this.value = value;
} }
public T getValue() { public T getValue() {
return value; return value;
} }
public boolean isObjectOrArray() { public boolean isObjectOrArray() {
if (value.getClass().equals(Node.class)) { if (value.getClass().equals(Node.class)) {
Node node = (Node) value; Node node = (Node) value;
if (node.getType() == Type.OBJECT || node.getType() == Type.ARRAY) { if (node.getType() == Type.OBJECT || node.getType() == Type.ARRAY) {
return true; return true;
} else { } else {
return false; return false;
} }
} else { } else {
return false; return false;
} }
} }
public boolean isNode() { public boolean isNode() {
return value.getClass().equals(Node.class); return value.getClass().equals(Node.class);
} }
public boolean isString () { public boolean isString () {
return value.getClass().equals(String.class); return value.getClass().equals(String.class);
} }
public boolean isNumber() { public boolean isNumber() {
return value.getClass().equals(Integer.class) || value.getClass().equals(Double.class); return value.getClass().equals(Integer.class) || value.getClass().equals(Double.class);
} }
} }

View File

@ -1 +1 @@
{"couple": [true, "Onde"], "age": 19, "nationalite": "Franco-Algerienne", "enVie": true, "poid": 1.7} {"couple": [true, "Onde", ["F", 3]], "age": 19, "nationalite": "Franco-Algerienne", "enVie": true, "poid": 1.7}