diff --git a/Makefile b/Makefile index 11e1d06..6719aa1 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ JAVA = java JAVAC = javac JAVADOC = javadoc -OPTIONSDOCS = -d docs +OPTIONSDOCS = -d docs -noqualifier all OPTIONS = -d build -Xlint:unchecked -Xlint:deprecation EXT = .java @@ -17,8 +17,8 @@ ConsolePACKAGE = Console/ # POUR ALLER PLUS VITE (Core, package:Console, ) ALL = $(SRC)*$(EXT) $(SRC)$(ConsolePACKAGE)*$(EXT) $(SRC)$(GraphicsPACKAGE)*$(EXT) -# LE FICHIER JSON -JSON = toFormat.json +# LE FICHIER JSON (Pour mon test) +JSON = /home/bilal-linux/toFormat.json .PHONY: console graphics clean docs diff --git a/build/Console/DisplayConsole.class b/build/Console/DisplayConsole.class index 561333c..01f7aa5 100644 Binary files a/build/Console/DisplayConsole.class and b/build/Console/DisplayConsole.class differ diff --git a/build/Core.class b/build/Core.class index aad6669..06e49f4 100644 Binary files a/build/Core.class and b/build/Core.class differ diff --git a/build/Graphics/GraphicFile.class b/build/Graphics/GraphicFile.class index 25828c7..b78811e 100644 Binary files a/build/Graphics/GraphicFile.class and b/build/Graphics/GraphicFile.class differ diff --git a/build/Graphics/GraphicsCore.class b/build/Graphics/GraphicsCore.class index 4623192..1aa35a2 100644 Binary files a/build/Graphics/GraphicsCore.class and b/build/Graphics/GraphicsCore.class differ diff --git a/build/Graphics/ListNodes.class b/build/Graphics/ListNodes.class deleted file mode 100644 index 5f613ca..0000000 Binary files a/build/Graphics/ListNodes.class and /dev/null differ diff --git a/build/Graphics/Node.class b/build/Graphics/Node.class deleted file mode 100644 index 2a9840a..0000000 Binary files a/build/Graphics/Node.class and /dev/null differ diff --git a/build/Graphics/Traitable.class b/build/Graphics/Traitable.class new file mode 100644 index 0000000..218f4bb Binary files /dev/null and b/build/Graphics/Traitable.class differ diff --git a/src/Console/DisplayConsole.java b/src/Console/DisplayConsole.java index f8873c3..01d9d74 100644 --- a/src/Console/DisplayConsole.java +++ b/src/Console/DisplayConsole.java @@ -4,6 +4,11 @@ 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; diff --git a/src/Core.java b/src/Core.java index d3c163b..76358f9 100644 --- a/src/Core.java +++ b/src/Core.java @@ -2,11 +2,16 @@ 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()); + new DisplayConsole(new File(args[0]).toURI().toURL()); } catch (Exception e) { System.out.println(e); } diff --git a/src/Graphics/GraphicFile.java b/src/Graphics/GraphicFile.java index f358e2e..d41d00a 100644 --- a/src/Graphics/GraphicFile.java +++ b/src/Graphics/GraphicFile.java @@ -2,31 +2,37 @@ package Graphics; import java.io.InputStream; import java.io.IOException; +import java.util.HashMap; import javax.swing.JPanel; import java.awt.GridLayout; 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 GridLayout(100, 1)); InputStream jsonReader = url.openStream(); - // ICI le code + /** + * C'est ici que le hashmap est stocke + */ + Traitable fileTraited = new Traitable(jsonReader); + HashMap allVariables = fileTraited.getVariableMap(); jsonReader.close(); } catch (IOException e) { System.out.println("[!] Fichier " + url.getFile() + " n'existe pas"); } } - - public void addIndentation(StringBuilder sb, int indentLevel) { - for (int i = 0; i < indentLevel; i++) { - sb.append("\t"); - } - } } diff --git a/src/Graphics/GraphicsCore.java b/src/Graphics/GraphicsCore.java index c9b06b1..e6af82d 100644 --- a/src/Graphics/GraphicsCore.java +++ b/src/Graphics/GraphicsCore.java @@ -19,6 +19,12 @@ 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; private final Dimension MINIMUM_FRAME_SIZE; @@ -42,6 +48,9 @@ public class GraphicsCore extends JFrame { this.setVisible(true); } + /** + * Initalisation des parametres de la Frame par defaut. + */ private void init() { this.setSize(DEFAULT_FRAME_SIZE); this.setDefaultCloseOperation(EXIT_ON_CLOSE); @@ -51,6 +60,11 @@ public class GraphicsCore extends JFrame { 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(); @@ -83,6 +97,12 @@ public class GraphicsCore extends JFrame { 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); @@ -104,6 +124,11 @@ public class GraphicsCore extends JFrame { 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(); @@ -114,11 +139,20 @@ public class GraphicsCore extends JFrame { } } + /** + * 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 + */ public void getPathOf() { JFileChooser jc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory()); diff --git a/src/Graphics/ListNodes.java b/src/Graphics/ListNodes.java deleted file mode 100644 index 1d1cb3b..0000000 --- a/src/Graphics/ListNodes.java +++ /dev/null @@ -1,128 +0,0 @@ -package Graphics; - -import java.util.ArrayList; -import java.util.Objects; - -public class ListNodes { - private Node begin; - - public ListNodes() { - this.begin = null; - } - - public void add(String name, String value) { - try { - if (this.begin == null) { - this.begin = new Node(name, value); - this.begin.addNext(new Node(name, value)); - } else { - Node cpy = this.begin; - - while (cpy.getNext() != null) { - cpy = cpy.getNext(); - } - - cpy.addNext(new Node(name, value)); - - System.out.println( - "[+] Noeud " + - cpy.getName() + " -> " + cpy.getValue().toString() + " ajouté ! " + - "(" + cpy.detectType(cpy.getValue().toString()) + ")"); - } - } catch (NullPointerException ignore) { - } - } - - public void addChild(String name, ArrayList an) { - try { - ArrayList finalList = new ArrayList<>(); - - for (int i = 0; i <= an.size() - 1; i++) { - finalList.add(new Node(null, an.get(i))); - } - - if (this.begin == null) { - this.begin = new Node(name, finalList); - this.begin.addNextChild(new Node(name, finalList)); - } else { - getBegin(name, finalList); - int i = 0; - - for (; i <= an.size() - 1; i++) { - System.out.print(an.get(i) + ", "); - } - - System.out.println("} (taille: " + i + ")"); - } - - } catch (NullPointerException ignore) { - } - } - - private void getBegin(String name, ArrayList finalList) { - Node cpy = this.begin; - - while (cpy.getNext() != null) { - cpy = cpy.getNext(); - } - - cpy.addNextChild(new Node(name, finalList)); - - System.out.print("[+] Noeud " + name + " -> { "); - } - - public void addChild(String name, ArrayList names, ArrayList values) { - try { - ArrayList finalList = new ArrayList<>(); - - for (int i = 0; i <= names.size() - 1; i++) { - finalList.add(new Node(names.get(i), values.get(i))); - } - - if (this.begin == null) { - this.begin = new Node(name, finalList); - this.begin.addNextChild(new Node(name, finalList)); - } else { - getBegin(name, finalList); - int i = 0; - - for (; i <= values.size() - 1; i++) { - System.out.print(names.get(i) + ": " + values.get(i) + ", "); - } - - System.out.println("} (taille: " + i + ")"); - } - - } catch (NullPointerException ignore) { - } - } - - public void displayNodes() { - Node cpy = this.begin; - - while (cpy.getNext() != null) { - cpy = cpy.getNext(); - if (!Objects.equals(cpy.getName().length(), 0)) { - System.out.println(cpy.toString()); - } - } - } - - public boolean isExist(String name) { - Node cpy = this.begin; - - while (cpy.getNext() != null) { - cpy = cpy.getNext(); - - if (Objects.equals(name, cpy.getName())) { - return true; - } - } - - return false; - } - - public boolean isEmpty() { - return this.begin == null || this.begin.getNext() == null; - } -} diff --git a/src/Graphics/Node.java b/src/Graphics/Node.java deleted file mode 100644 index 4692f2b..0000000 --- a/src/Graphics/Node.java +++ /dev/null @@ -1,143 +0,0 @@ -package Graphics; - -import java.util.ArrayList; - -public class Node { - private Node next; - private final String name; - private Object value; - private final ArrayList childs; - - public Node() { - this.name = null; - this.next = null; - this.value = null; - this.childs = new ArrayList<>(); - } - - public Node(String name, ArrayList childs) { - this.name = name; - this.value = null; - this.next = null; - this.childs = childs; - } - - public Node(String name, String value) { - this.name = name; - this.value = value; - this.next = null; - this.childs = null; - } - - public void addNext(Node node) { - try { - switch (this.detectType((String) node.getValue())) { - case "int": { - node.setValue(Integer.valueOf(node.getValue().toString())); - break; - } - - case "boolean": { - node.setValue(Boolean.valueOf(node.getValue().toString())); - break; - } - - case "float": { - node.setValue(Float.valueOf(node.getValue().toString())); - break; - } - - case "char": { - node.setValue(node.getValue().toString().charAt(0)); - break; - } - - default: { - node.setValue(node.getValue().toString()); - break; - } - } - - this.next = node; - } catch (Exception e) { - System.err.println(e); - System.err.println("[!] Probleme lors de l'ajout du noeud : " + this.name + " vers " + node.getName()); - } - } - - public void addNextChild(Node node) { - try { - this.next = node; - } catch (Exception e) { - System.err.println(e); - System.err.println("[!] Probleme lors de l'ajout du noeud : " + this.name + " vers " + node.getName()); - } - } - - public boolean haveChild() { - return this.childs == null; - } - - public String detectType(String str) { - if (str == null) { - return "null"; - } - - if (str.matches("[0-9]+")) { - return "int"; - } else if (str.length() == 1) { - return "char"; - } else if (str.equals("true") || str.equals("false")) { - return "boolean"; - } else if (str.matches("[0-9]+\\.[0-9]+")) { - return "float"; - } else if (str.matches("[a-zA-Z]+")) { - return "string"; - } else if (str.matches("[a-zA-Z0-9]+")) { - return "hexadecimal"; - } else { - return "string"; - } - } - - public String getName() { - return this.name; - } - - public Object getValue() { - return this.value; - } - - public Node getNext() { - return this.next; - } - - public ArrayList getChilds() { - return this.childs; - } - - public void setValue(Object toSet) { - this.value = toSet; - } - - @Override - public String toString() { - if (this.childs == null) { - return "Node: " + this.name + " => " + this.value; - } else { - StringBuilder toReturn = new StringBuilder("Node: " + this.name + " => { "); - for (int i = 0; i <= this.childs.size() - 1; i++) { - if (this.childs.get(i).getName() != null) { - toReturn.append(this.childs.get(i).getName()).append(": ").append(this.childs.get(i).getValue()) - .append(", "); - } else { - toReturn.append(this.childs.get(i).getValue()).append(", "); - } - } - - toReturn.append("} "); - - return toReturn.toString(); - } - } -} diff --git a/src/Graphics/Traitable.java b/src/Graphics/Traitable.java new file mode 100644 index 0000000..76c9aeb --- /dev/null +++ b/src/Graphics/Traitable.java @@ -0,0 +1,156 @@ +package Graphics; + +import java.util.HashMap; +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 content; + private final InputStream file; + + public Traitable(InputStream file) { + this.content = new HashMap<>(); + 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); + } + + while (i < allJson.length()) { + if (allJson.charAt(i) == '"') { + while (allJson.charAt(i) != ',') { + tmp.append(allJson.charAt(i)); + i++; + } + + // System.out.println(this.getNomOfRecord(tmp)); + tmp.setLength(0); + } + + i++; + } + } catch (StringIndexOutOfBoundsException ignore) { + } + + } catch (IOException e) { + System.out.println("[!] Probleme lors de la lecture du fichier"); + } + } + + private String getNomOfRecord(StringBuilder sb) { + int i = 0; + StringBuilder name = new StringBuilder(); + + while (i < sb.length()) { + if (sb.charAt(i) == ':') { + return name.toString().replaceAll("\"", ""); + } + + name.append(sb.charAt(i)); + + i++; + } + + return null; + } + + // TODO: a finir (Bilal) + private Object getValueOfRecord(StringBuilder sb) { + // int i; + // int counter; + // StringBuilder value = new StringBuilder(); + // String type = ""; + + // /** + // * Tableau + // */ + // if (sb.indexOf("[") != -1) { + // type = "tableau"; + // } + + // /** + // * Chaine de characteres + // */ + // for (i = 0, counter = 0; i <= sb.length() - 1; i++) { + // if (sb.charAt(i) == '"') { + // counter++; + // } + // } + + // if (counter < 2 && sb.indexOf(".") != -1) { + // type = "float"; + // } + + // /* + // * Objet + // */ + // if (sb.indexOf("{") != -1) { + // type = "objet"; + // } + + // /* + // * Integer + // */ + // for (i = 0, counter = 0; i <= sb.length() - 1; i++) { + // if (sb.charAt(i) == '"') { + // counter++; + // } + // } + + // if (counter < 2) { + // type = "int"; + // } + + // /** + // * Flottant + // */ + // for (i = 0, counter = 0; i <= sb.length() - 1; i++) { + // if (sb.charAt(i) == '"') { + // counter++; + // } + // } + + // if (counter < 2 && sb.indexOf(".") != -1) { + // type = "float"; + // } + + return null; + } + + /** + * Ajouter le jeu de cle valeur dans la liste + * + * @param name Nom de la variable + * @param value Contenue de la variable + */ + private void addToList(String name, Object value) { + System.out.println("[+] => " + name + ": " + value); + this.content.put(name, value); + } + + public HashMap getVariableMap() { + return this.content; + } +} \ No newline at end of file diff --git a/toFormat.json b/toFormat.json index dd859bf..25ad443 100644 --- a/toFormat.json +++ b/toFormat.json @@ -1 +1 @@ -{"ecole":"I.U.T Senart-Fontainebleau","eleves":["Romain Besson","Bilal Boudjemline"],"classe":"BUT Informatique","matiere":{"mat1":"SCR", "mat2":"Java"}} \ No newline at end of file +{"prenom":"Bilal", "age": 19,} \ No newline at end of file