refactored windows

This commit is contained in:
2021-03-03 13:23:22 +01:00
parent 16df134cd4
commit bd48d32080
18 changed files with 144 additions and 339 deletions

View File

@@ -0,0 +1,89 @@
package lsystem.screen.main;
import lsystem.screen.Constants;
import javax.swing.*;
import java.awt.*;
public class MainFrame extends JFrame {
private static final long serialVersionUID = -7898079642230075807L;
private int nbTabs;
private int nbHelpWindow;
private JPanel basePanel;
private JTabbedPane tabs;
private JButton newGen;
private JButton help;
private int nbRules;
public MainFrame(){
nbRules = 1;
nbTabs = 0;
basePanel = new JPanel();
basePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
tabs = new JTabbedPane(SwingConstants.TOP);
JToolBar toolBar = new JToolBar();
newGen = new JButton("Nouvelle génération");
newGen.addActionListener(new Listener(this,null,"Tab",null));
toolBar.add(newGen);
help = new JButton("Aide");
help.addActionListener(new Listener(this,null,"Help",null));
toolBar.add(help);
this.setTitle("L-system interface");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(Constants.WIDTH, Constants.HEIGHT);
this.setLocationRelativeTo(null);
this.add(tabs);
this.add(toolBar, BorderLayout.NORTH);
this.setPreferredSize(new Dimension(640,600));
}
public void newHelp() {
if(nbHelpWindow>0){
JOptionPane.showMessageDialog(null, "Une fenêtre d'aide est déjà ouverte.");
}
else {
nbHelpWindow++;
JFrame aide = new JFrame();
aide.setTitle("Aide");
aide.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
aide.setSize(700,500);
aide.setLocationRelativeTo(null);
aide.setVisible(true);
JTextArea helpText = new JTextArea();
helpText.setText(Constants.HELP);
helpText.setEditable(false);
JScrollPane scrollbar = new JScrollPane(helpText);
scrollbar.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollbar.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
aide.add(scrollbar);
}
}
public void newTab() {
if(nbTabs>2)
JOptionPane.showMessageDialog(null, "Nombre maximal de générations atteintes");
else {
nbTabs++;
new Tab(nbTabs, nbRules, tabs);
}
}
public void closeTab() {
//TODO : Pour fermer un onglet, nécessite l'implémentation d'un button fermer grâce à la méthode newTab().
}
}