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;
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) {
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) {}
}
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) {
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) {}
}

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;
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;
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());
}
}

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;
public class JsonSyntaxException extends Throwable {
private static final String MESSAGE = "Syntax error in JSON file";
public JsonSyntaxException() {
super(MESSAGE);
}
}
package JsonInspector;
public class JsonSyntaxException extends Throwable {
private static final String MESSAGE = "Syntax error in JSON file";
public JsonSyntaxException() {
super(MESSAGE);
}
}

View File

@ -1,92 +1,92 @@
package JsonInspector;
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;
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");
}
}
}

View File

@ -1,18 +1,18 @@
package JsonInspector;
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;
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);
}
}

View File

@ -1,24 +1,24 @@
package JsonInspector;
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;
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);
}
}

View File

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

View File

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

View File

@ -1,20 +1,20 @@
package JsonInspector;
import java.awt.*;
public class Parameters {
public static final Font FILE_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 18);
public static final String IHM_INDENTATION = " ";
public static final String CONSOLE_INDENTATION = " ";
public static final String ARRAY_CLOSING = "...]";
public static final String OBJECT_ELEMENT_CLOSING = "...}";
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 OTHER_COLOR = new Color(7, 103, 183);
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 MOUSE_OVER_COLOR = new Color(60, 60, 60);
public static final Color DEFAULT_TEXT_COLOR = new Color(220, 220, 220);
public static final Color BACKGROUND_COLOR = new Color(45, 45, 45);
}
package JsonInspector;
import java.awt.*;
public class Parameters {
public static final Font FILE_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 18);
public static final String IHM_INDENTATION = " ";
public static final String CONSOLE_INDENTATION = " ";
public static final String ARRAY_CLOSING = "...]";
public static final String OBJECT_ELEMENT_CLOSING = "...}";
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 OTHER_COLOR = new Color(7, 103, 183);
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 MOUSE_OVER_COLOR = new Color(60, 60, 60);
public static final Color DEFAULT_TEXT_COLOR = new Color(220, 220, 220);
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;
public enum Type {
OBJECT, ELEMENT, ARRAY, PAIR, NULL
}
package JsonInspector;
public enum Type {
OBJECT, ELEMENT, ARRAY, PAIR, NULL
}

View File

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