Transférer les fichiers vers 'src/Test'

This commit is contained in:
Romain BESSON 2022-12-03 15:27:11 +01:00
parent fd6b0e8bad
commit 53481c883b
4 changed files with 117 additions and 44 deletions

View File

@ -31,7 +31,7 @@ public class AdminView extends JPanel {
settings.setPositionX(0); settings.setPositionX(0);
settings.setPositionY(0); settings.setPositionY(0);
JButton studList = new JButton("Voir la liste des etudiants"); CustomJButton studList = new CustomJButton("Voir la liste des etudiants");
studList.setActionCommand("pv::GetStudList"); studList.setActionCommand("pv::GetStudList");
studList.addActionListener(this.listener); studList.addActionListener(this.listener);
this.add(studList, settings); this.add(studList, settings);
@ -40,7 +40,7 @@ public class AdminView extends JPanel {
this.add(new JLabel(" "), settings); this.add(new JLabel(" "), settings);
settings.setPositionY(2); settings.setPositionY(2);
JButton moveStudGrup = new JButton("Changer le groupe d'un etudiant"); CustomJButton moveStudGrup = new CustomJButton("Changer le groupe d'un etudiant");
moveStudGrup.addActionListener(this.listener); moveStudGrup.addActionListener(this.listener);
moveStudGrup.setActionCommand("av::MoveStudGrup"); moveStudGrup.setActionCommand("av::MoveStudGrup");
this.add(moveStudGrup, settings); this.add(moveStudGrup, settings);
@ -49,7 +49,7 @@ public class AdminView extends JPanel {
this.add(new JLabel(" "), settings); this.add(new JLabel(" "), settings);
settings.setPositionY(4); settings.setPositionY(4);
JButton addStudGrup = new JButton("Ajouter un etudiant dans un groupe"); CustomJButton addStudGrup = new CustomJButton("Ajouter un etudiant dans un groupe");
addStudGrup.addActionListener(this.listener); addStudGrup.addActionListener(this.listener);
addStudGrup.setActionCommand("av::AddStudGrup"); addStudGrup.setActionCommand("av::AddStudGrup");
this.add(addStudGrup, settings); this.add(addStudGrup, settings);

View File

@ -0,0 +1,33 @@
package Test;
import javax.swing.JButton;
import java.awt.*;
public class CustomJButton extends JButton {
private final Font font = new Font("Arial", Font.PLAIN, 15);
private final Color defaultColor = Color.GRAY;
private final int radius = 20;
public CustomJButton(String text, Color c) {
super(text);
this.setBackground(c);
init();
}
public CustomJButton(String text) {
super(text);
this.setBackground(defaultColor);
init();
}
private void init() {
this.setFont(font);
this.setFocusPainted(false);
//this.setContentAreaFilled(false);
this.setBorderPainted(false);
this.setBorder(new RoundedBorder(radius));
}
}

View File

@ -8,7 +8,9 @@ public class MainMenu extends JFrame {
private final static Dimension MINIMUM_SIZE = new Dimension(960, 600); private final static Dimension MINIMUM_SIZE = new Dimension(960, 600);
private final CardLayout cards = new CardLayout(), adminCards = new CardLayout(), profCards = new CardLayout(), studentCards = new CardLayout(); private final CardLayout cards = new CardLayout(), adminCards = new CardLayout(), profCards = new CardLayout(), studentCards = new CardLayout();
private final JPanel adminPanel = new JPanel(), profPanel = new JPanel(), studentPanel = new JPanel(); private final JPanel adminPanel = new JPanel(), profPanel = new JPanel(), studentPanel = new JPanel();
private final Color blue = new Color(53, 242, 242); private final Color adminColor = new Color(255, 2, 2);
private final Color profColor = new Color(182, 2, 189);
private final Color studentColor = new Color(53, 242, 242);
private JMenuBar menuBar; private JMenuBar menuBar;
private Controller listener; private Controller listener;
private AdminView av; private AdminView av;
@ -17,10 +19,10 @@ public class MainMenu extends JFrame {
private JTable table; private JTable table;
private int cardIndex = 0; private int cardIndex = 0;
private String[] viewName = {"Administrateur", "Professeur", "Etudiant"}; private String[] viewName = {"Administrateur", "Professeur", "Etudiant"};
private final JButton[] buttonTab = { private final CustomJButton[] buttonTab = {
new JButton(viewName[0]), new CustomJButton(viewName[0]),
new JButton(viewName[1]), new CustomJButton(viewName[1]),
new JButton(viewName[2]) new CustomJButton(viewName[2])
}; };
@ -46,6 +48,7 @@ public class MainMenu extends JFrame {
this.setLayout(cards); this.setLayout(cards);
this.add(firstCard()); this.add(firstCard());
this.add(adminPanel); this.add(adminPanel);
this.add(profPanel); this.add(profPanel);
this.add(studentPanel); this.add(studentPanel);
@ -55,20 +58,26 @@ public class MainMenu extends JFrame {
private void createJMenuBar() { private void createJMenuBar() {
JMenu menu = new JMenu("Menu"), file = new JMenu("File"), edit = new JMenu("Edit"), view = new JMenu("View"); JMenu menu = new JMenu("Menu"), file = new JMenu("File"), edit = new JMenu("Edit"), view = new JMenu("Affichage");
JMenuItem adminMenuItem = new JMenuItem("Vu "+viewName[0]); JMenuItem adminMenuItem = new JMenuItem("Vue "+viewName[0]);
adminMenuItem.addActionListener((event) -> changeView(1)); adminMenuItem.addActionListener((event) -> changeView(1));
JMenuItem profMenuItem = new JMenuItem("Vu "+viewName[1]); JMenuItem profMenuItem = new JMenuItem("Vue "+viewName[1]);
profMenuItem.addActionListener((event) -> changeView(2)); profMenuItem.addActionListener((event) -> changeView(2));
JMenuItem studentMenuItem = new JMenuItem("Vu "+viewName[2]); JMenuItem studentMenuItem = new JMenuItem("Vue "+viewName[2]);
studentMenuItem.addActionListener((event) -> changeView(3)); studentMenuItem.addActionListener((event) -> changeView(3));
JMenuItem mainMenuItem = new JMenuItem("Retourner au menu principal"); JMenuItem mainMenuItem = new JMenuItem("Retourner au menu principal");
mainMenuItem.addActionListener(this::backtoMainMenu); mainMenuItem.addActionListener(this::backtoMainMenu);
JMenuItem fullScreenMenuItem = new JMenuItem("Plein écran");
fullScreenMenuItem.addActionListener(this::setFullScreen);
JMenuItem notFullScreenMenuItem = new JMenuItem("Fenêtré");
notFullScreenMenuItem.addActionListener(this::unsetFullScreen);
JMenuItem quitMenuItem = new JMenuItem("Quitter"); JMenuItem quitMenuItem = new JMenuItem("Quitter");
quitMenuItem.addActionListener((event) -> System.exit(0)); quitMenuItem.addActionListener((event) -> System.exit(0));
@ -80,7 +89,9 @@ public class MainMenu extends JFrame {
file.add(new JMenuItem("Ca c'est juste du style")); file.add(new JMenuItem("Ca c'est juste du style"));
edit.add(new JMenuItem("Ca aussi c'est du style")); edit.add(new JMenuItem("Ca aussi c'est du style"));
view.add(new JMenuItem("Encore du style"));
view.add(fullScreenMenuItem);
view.add(notFullScreenMenuItem);
menuBar.add(menu); menuBar.add(menu);
menuBar.add(file); menuBar.add(file);
@ -91,18 +102,47 @@ public class MainMenu extends JFrame {
} }
private void setFullScreen(ActionEvent e) {
this.setVisible(false);
this.setExtendedState(MAXIMIZED_BOTH);
this.setUndecorated(true);
this.setVisible(true);
}
private void unsetFullScreen(ActionEvent e) {
this.setVisible(false);
this.setSize(MINIMUM_SIZE);
this.setUndecorated(false);
this.setVisible(true);
}
private void backtoMainMenu(ActionEvent e) { private void backtoMainMenu(ActionEvent e) {
this.setJMenuBar(null); this.setJMenuBar(null);
cards.first(this.getContentPane()); cards.first(this.getContentPane());
} }
private JPanel cardWithTable(JPanel sidePanel) { private JPanel cardWithTable(JPanel sidePanel, String origin) {
JPanel panel = new JPanel(); JPanel panel = new JPanel();
JScrollPane scrollPane = new JScrollPane(); JScrollPane scrollPane = new JScrollPane();
panel.setLayout(new GridLayout(1, 2)); panel.setLayout(new GridLayout(1, 2));
if (origin.equals(viewName[0])){
sidePanel.setBackground(adminColor);
System.out.println("admin");
} else if (origin.equals(viewName[1])) {
sidePanel.setBackground(profColor);
System.out.println("prof");
} else {
sidePanel.setBackground(studentColor);
System.out.println("student");
}
panel.add(sidePanel); panel.add(sidePanel);
panel.add(this.table); panel.add(this.table);
panel.add(scrollPane); panel.add(scrollPane);
@ -116,28 +156,28 @@ public class MainMenu extends JFrame {
table = this.listener.initTable(); table = this.listener.initTable();
if (index == 1) { if (index == 1) {
cardIndex = index; this.cardIndex = index;
this.setTitle(viewName[0]); this.setTitle(this.viewName[0]);
adminPanel.setLayout(adminCards); this.adminPanel.setLayout(this.adminCards);
adminPanel.add(cardWithTable(adminView())); this.adminPanel.add(cardWithTable(adminView(), viewName[0]));
adminCards.next(adminPanel); this.adminCards.next(this.adminPanel);
menuBar.setBackground(Color.RED); this.menuBar.setBackground(this.adminColor);
} else if (index == 2) { } else if (index == 2) {
cardIndex = index; this.cardIndex = index;
this.setTitle(viewName[1]); this.setTitle(this.viewName[1]);
profPanel.setLayout(profCards); this.profPanel.setLayout(this.profCards);
profPanel.add(cardWithTable(profView())); this.profPanel.add(cardWithTable(profView(), viewName[1]));
profCards.next(profPanel); this.profCards.next(this.profPanel);
menuBar.setBackground(Color.MAGENTA); this.menuBar.setBackground(this.profColor);
} else if (index == 3){ } else if (index == 3){
cardIndex = index; this.cardIndex = index;
this.setTitle(viewName[2]); this.setTitle(this.viewName[2]);
studentPanel.setLayout(studentCards); this.studentPanel.setLayout(this.studentCards);
studentPanel.add(cardWithTable(studentView())); this.studentPanel.add(cardWithTable(studentView(), viewName[2]));
studentCards.next(studentPanel); this.studentCards.next(this.studentPanel);
menuBar.setBackground(this.blue); this.menuBar.setBackground(this.studentColor);
} }
travelThroughCards(index); travelThroughCards(index);
} }
@ -146,15 +186,15 @@ public class MainMenu extends JFrame {
public void updateTable(JTable table) { public void updateTable(JTable table) {
if (cardIndex == 1) { if (cardIndex == 1) {
this.table = table; this.table = table;
adminPanel.add(cardWithTable(adminView())); adminPanel.add(cardWithTable(adminView(), viewName[0]));
adminCards.next(adminPanel); adminCards.next(adminPanel);
} else if (cardIndex == 2) { } else if (cardIndex == 2) {
this.table = table; this.table = table;
profPanel.add(cardWithTable(profView())); profPanel.add(cardWithTable(profView(), viewName[1]));
profCards.next(profPanel); profCards.next(profPanel);
} else { } else {
this.table = table; this.table = table;
studentPanel.add(cardWithTable(profView())); studentPanel.add(cardWithTable(profView(), viewName[2]));
studentCards.next(studentPanel); studentCards.next(studentPanel);
} }
} }
@ -222,25 +262,25 @@ public class MainMenu extends JFrame {
if (origin.getText().equals(viewName[0])) { if (origin.getText().equals(viewName[0])) {
this.setTitle(viewName[0]); this.setTitle(viewName[0]);
menuBar.setBackground(Color.RED); menuBar.setBackground(this.adminColor);
adminPanel.setLayout(adminCards); adminPanel.setLayout(adminCards);
adminPanel.add(cardWithTable(adminView())); adminPanel.add(cardWithTable(adminView(), viewName[0]));
adminCards.next(adminPanel); adminCards.next(adminPanel);
cardIndex = 1; cardIndex = 1;
} else if (origin.getText().equals(viewName[1])) { } else if (origin.getText().equals(viewName[1])) {
this.setTitle(viewName[1]); this.setTitle(viewName[1]);
menuBar.setBackground(Color.MAGENTA); menuBar.setBackground(this.profColor);
profPanel.setLayout(profCards); profPanel.setLayout(profCards);
profPanel.add(cardWithTable(profView())); profPanel.add(cardWithTable(profView(), viewName[1]));
profCards.next(profPanel); profCards.next(profPanel);
cardIndex = 2; cardIndex = 2;
} else { } else {
this.setTitle(viewName[2]); this.setTitle(viewName[2]);
menuBar.setBackground(this.blue); menuBar.setBackground(this.studentColor);
studentPanel.setLayout(studentCards); studentPanel.setLayout(studentCards);
studentPanel.add(cardWithTable(studentView())); studentPanel.add(cardWithTable(studentView(), viewName[2]));
studentCards.next(studentPanel); studentCards.next(studentPanel);
cardIndex = 3; cardIndex = 3;
} }

View File

@ -50,7 +50,7 @@ public class ProfView extends JPanel {
settings.setPositionY(6); settings.setPositionY(6);
settings.setPositionY(0); settings.setPositionY(0);
JButton studList = new JButton("Voir la liste des etudiants"); CustomJButton studList = new CustomJButton("Voir la liste des etudiants");
studList.setActionCommand("pv::GetStudList"); studList.setActionCommand("pv::GetStudList");
studList.addActionListener(this.listener); studList.addActionListener(this.listener);
this.add(studList, settings); this.add(studList, settings);
@ -77,7 +77,7 @@ public class ProfView extends JPanel {
settings.setPositionY(3); settings.setPositionY(3);
settings.setPadding(new Insets(0, 0, 0, 0)); settings.setPadding(new Insets(0, 0, 0, 0));
settings.setAnchor(GridBagConstraints.EAST); settings.setAnchor(GridBagConstraints.EAST);
JButton confirm = new JButton("Rechercher"); CustomJButton confirm = new CustomJButton("Rechercher");
confirm.setActionCommand("pv::GetListFiltered"); confirm.setActionCommand("pv::GetListFiltered");
confirm.addActionListener(this.listener); confirm.addActionListener(this.listener);
this.add(confirm, settings); this.add(confirm, settings);
@ -106,7 +106,7 @@ public class ProfView extends JPanel {
settings.setPositionY(6); settings.setPositionY(6);
settings.setPadding(new Insets(0, 0, 0, 0)); settings.setPadding(new Insets(0, 0, 0, 0));
settings.setAnchor(GridBagConstraints.EAST); settings.setAnchor(GridBagConstraints.EAST);
JButton searchTLetters = new JButton("Rechercher"); CustomJButton searchTLetters = new CustomJButton("Rechercher");
searchTLetters.addActionListener(this.listener); searchTLetters.addActionListener(this.listener);
searchTLetters.setActionCommand("pv::SearchStudentPer3Letters"); searchTLetters.setActionCommand("pv::SearchStudentPer3Letters");
this.add(searchTLetters, settings); this.add(searchTLetters, settings);