Mise à jour de 'src/JsonInspector/Frame.java'

This commit is contained in:
Romain BESSON 2023-01-11 13:52:24 +01:00
parent bec8c0fa06
commit 0ccdd70536

View File

@ -1,99 +1,101 @@
import javax.swing.*;
import java.awt.*;
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 Node node;
public Frame() {
super("Inspecteur JSON");
init();
this.setVisible(true);
}
public Frame(Node node) {
super("Inspecteur JSON");
this.node = node;
init();
this.add(secondCard());
cards.last(this.getContentPane());
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(DEFAULT_LINK, 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.gridy = 1;
panel.add(button, gbc);
panel.setBackground(Parameters.IHM_COLOR);
return panel;
}
private JPanel secondCard() {
JPanel mainPanel = new JPanel(), southPanel = new JPanel();
JButton backButton = new JButton("Retour");
backButton.addActionListener((event) -> backAction(mainPanel));
GraphicFile file = new GraphicFile(new Tree(""));
JScrollPane scroll = new JScrollPane();
mainPanel.setLayout(new BorderLayout());
southPanel.setBackground(Parameters.IHM_COLOR);
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;
}
private void validationAction(JTextField field) {
try {
URL url = new URL(field.getText());
this.add(secondCard());
cards.last(this.getContentPane());
} catch (MalformedURLException e) {
JOptionPane.showMessageDialog(this, "Invalid URL", "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.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 Node node;
public Frame() {
super("Inspecteur JSON");
init();
this.setVisible(true);
}
public Frame(Node node) {
super("Inspecteur JSON");
this.node = node;
init();
this.add(secondCard());
cards.last(this.getContentPane());
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(DEFAULT_LINK, 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.gridy = 1;
panel.add(button, gbc);
panel.setBackground(Parameters.IHM_COLOR);
return panel;
}
private JPanel secondCard() {
JPanel mainPanel = new JPanel(), southPanel = new JPanel();
JButton backButton = new JButton("Retour");
backButton.addActionListener((event) -> backAction(mainPanel));
GraphicFile file = new GraphicFile(new Tree(""));
JScrollPane scroll = new JScrollPane();
mainPanel.setLayout(new BorderLayout());
southPanel.setBackground(Parameters.IHM_COLOR);
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;
}
private void validationAction(JTextField field) {
try {
URL url = new URL(field.getText());
this.add(secondCard());
cards.last(this.getContentPane());
} catch (MalformedURLException e) {
JOptionPane.showMessageDialog(this, "Invalid URL", "Error", JOptionPane.ERROR_MESSAGE);
}
}
private void backAction(JPanel panel) {
this.remove(panel);
cards.first(this.getContentPane());
}
}