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