Transférer les fichiers vers 'src/JsonInspector'
This commit is contained in:
@@ -2,40 +2,27 @@ 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 static final String DEFAULT_LINK = "https://gbfs.citibikenyc.com/gbfs/en/station_information.json";
|
||||
private final CardLayout cards = new CardLayout();
|
||||
private boolean showTab = true;
|
||||
private JPanel secondCard;
|
||||
private GraphicFile file;
|
||||
private Node node;
|
||||
private Tree tree;
|
||||
|
||||
|
||||
public Frame() {
|
||||
super("Inspecteur JSON");
|
||||
tree = new Tree("");
|
||||
init();
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
public Frame(Node node) {
|
||||
super("Inspecteur JSON");
|
||||
this.node = node;
|
||||
init();
|
||||
secondCard = secondCard();
|
||||
this.add(secondCard);
|
||||
cards.last(this.getContentPane());
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
this.setSize(DEFAULT_FRAME_SIZE);
|
||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
@@ -50,7 +37,7 @@ public class Frame extends JFrame {
|
||||
private JPanel firstCard() {
|
||||
GridBagLayout layout = new GridBagLayout();
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
JTextField textField = new JTextField(DEFAULT_LINK, 30);
|
||||
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();
|
||||
@@ -78,53 +65,31 @@ public class Frame extends JFrame {
|
||||
|
||||
private JPanel secondCard() {
|
||||
file = new GraphicFile(this, tree);
|
||||
JButton showButton = new JButton();
|
||||
JButton backButton = new JButton("Retour");
|
||||
JPanel mainPanel = new JPanel(), southPanel = new JPanel();
|
||||
JScrollPane scroll = new JScrollPane();
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
|
||||
if (showTab) {
|
||||
showButton.setText("Tout déplier");
|
||||
} else {
|
||||
showButton.setText("Tout replier");
|
||||
}
|
||||
|
||||
southPanel.setBackground(Parameters.IHM_COLOR);
|
||||
southPanel.add(backButton);
|
||||
backButton.addActionListener((event) -> backAction(mainPanel));
|
||||
southPanel.add(showButton);
|
||||
showButton.addActionListener((event) -> showAction());
|
||||
southPanel.add(new JButton("convertir en PHP"));
|
||||
|
||||
mainPanel.add(file);
|
||||
mainPanel.add(southPanel, BorderLayout.SOUTH);
|
||||
mainPanel.add(scroll);
|
||||
|
||||
scroll.setViewportView(file);
|
||||
return mainPanel;
|
||||
return initSecondCard(file);
|
||||
}
|
||||
|
||||
|
||||
private JPanel secondCard(GraphicFile file) {
|
||||
this.file = file;
|
||||
JButton showButton = new JButton();
|
||||
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());
|
||||
|
||||
if (showTab) {
|
||||
showButton.setText("Tout déplier");
|
||||
} else {
|
||||
showButton.setText("Tout replier");
|
||||
}
|
||||
|
||||
southPanel.setBackground(Parameters.IHM_COLOR);
|
||||
southPanel.add(backButton);
|
||||
backButton.addActionListener((event) -> backAction(mainPanel));
|
||||
southPanel.add(showButton);
|
||||
showButton.addActionListener((event) -> showAction());
|
||||
southPanel.add(unfoldButton);
|
||||
unfoldButton.addActionListener((event) -> unfoldAction());
|
||||
southPanel.add(retreatButton);
|
||||
retreatButton.addActionListener((event) -> retreatAction());
|
||||
southPanel.add(new JButton("convertir en PHP"));
|
||||
|
||||
mainPanel.add(file);
|
||||
@@ -136,15 +101,14 @@ public class Frame extends JFrame {
|
||||
}
|
||||
|
||||
|
||||
private void showAction() {
|
||||
if (showTab) {
|
||||
showTab = false;
|
||||
file.showAll();
|
||||
} else {
|
||||
showTab = true;
|
||||
file.retreatAll();
|
||||
}
|
||||
private void unfoldAction() {
|
||||
file.showAll();
|
||||
repaintFile();
|
||||
}
|
||||
|
||||
|
||||
private void retreatAction() {
|
||||
file.retreatAll();
|
||||
repaintFile();
|
||||
}
|
||||
|
||||
@@ -161,11 +125,25 @@ public class Frame extends JFrame {
|
||||
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, "Invalid URL", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user