From da69910269b111eeb6723f795be77a71a6121a64 Mon Sep 17 00:00:00 2001 From: besson Date: Sat, 3 Dec 2022 16:12:37 +0100 Subject: [PATCH] =?UTF-8?q?Transf=C3=A9rer=20les=20fichiers=20vers=20'src/?= =?UTF-8?q?Test'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Test/Controller.java | 150 ++++++++++++++++++++---------------- src/Test/CustomJButton.java | 4 +- src/Test/RoundedBorder.java | 29 +++++++ 3 files changed, 116 insertions(+), 67 deletions(-) create mode 100644 src/Test/RoundedBorder.java diff --git a/src/Test/Controller.java b/src/Test/Controller.java index 9d4ed7d..7e3b9a8 100644 --- a/src/Test/Controller.java +++ b/src/Test/Controller.java @@ -127,9 +127,6 @@ public class Controller implements ActionListener, ListSelectionListener { this.currentJTableUse = liste; this.parent.updateTable(liste); - - //forModal.add(liste); - //BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, this.parent, forModal); } /** @@ -545,75 +542,99 @@ public class Controller implements ActionListener, ListSelectionListener { value = tm.getValueAt(cell[0], i); if(Objects.equals(value, "[DEPLACER]")) { - JPanel forModal = new JPanel(new GridBagLayout()); - BLayout settings = new BLayout(); - - this.tmpStud = new ArrayList<>(); - this.tmpStud.add((String) tm.getValueAt(cell[0], 0)); - this.tmpStud.add((String) tm.getValueAt(cell[0], 1)); - - settings.setPositionX(0); - settings.setPositionY(0); - JLabel intro = new JLabel( - "Deplacer " + tm.getValueAt(cell[0], 0) + " " + - tm.getValueAt(cell[0], 1) + - " dans le groupe : " - ); - forModal.add(intro, settings); - - settings.setPositionX(1); - settings.setPositionY(0); - forModal.add(new JLabel(" "), settings); - - settings.setPositionX(2); - settings.setPositionY(0); - forModal.add(new JLabel(" "), settings); - - settings.setPositionX(3); - settings.setPositionY(0); - - this.list = new JComboBox<>(); - - for(Groupe groupe : this.g) { - this.list.addItem(groupe.getName()); - } - - forModal.add(list, settings); - - settings.setPositionX(4); - settings.setPositionY(0); - forModal.add(new JLabel(" "), settings); - - settings.setPositionX(5); - settings.setPositionY(0); - forModal.add(new JLabel(" "), settings); - - settings.setPositionX(6); - settings.setPositionY(0); - JButton moveBtn = new JButton("Deplacer"); - moveBtn.setActionCommand("crtll::ActionAddAndMoveGrup"); - moveBtn.addActionListener(this); - forModal.add(moveBtn, settings); - - DisplayModal( - "Deplacer l'eleve : " - + tm.getValueAt(cell[0], 0) + " " + tm.getValueAt(cell[0], 1), - 500, - 250, - this.av.getX(), - this.av.getY(), - forModal - ); + addMoveStudent(tm, cell, "[DEPLACER]"); } if(Objects.equals(value, "[AJOUTER]")) { - System.out.println("Ajout"); + addMoveStudent(tm, cell, "[AJOUTER]"); } } } } } + + private void addMoveStudent(TableModel tm, int[] cell, String action){ + String[] stringSetAdd = { + "Ajouter ", + "Ajouter", + "Nouveau groupe de l'eleve : " + }; + String[] stringSetMove = { + "Deplacer ", + "Deplacer", + "Deplacer l'eleve : " + }; + String[] stringSet; + + if (action == "[AJOUTER]"){ + stringSet = stringSetAdd; + } else { + stringSet = stringSetMove; + } + + JPanel forModal = new JPanel(new GridBagLayout()); + BLayout settings = new BLayout(); + + this.tmpStud = new ArrayList<>(); + this.tmpStud.add((String) tm.getValueAt(cell[0], 0)); + this.tmpStud.add((String) tm.getValueAt(cell[0], 1)); + + settings.setPositionX(0); + settings.setPositionY(0); + JLabel intro = new JLabel( + stringSet[0] + tm.getValueAt(cell[0], 0) + " " + + tm.getValueAt(cell[0], 1) + + " dans le groupe : " + ); + forModal.add(intro, settings); + + settings.setPositionX(1); + settings.setPositionY(0); + forModal.add(new JLabel(" "), settings); + + settings.setPositionX(2); + settings.setPositionY(0); + forModal.add(new JLabel(" "), settings); + + settings.setPositionX(3); + settings.setPositionY(0); + + this.list = new JComboBox<>(); + + for(Groupe groupe : this.g) { + this.list.addItem(groupe.getName()); + } + + forModal.add(list, settings); + + settings.setPositionX(4); + settings.setPositionY(0); + forModal.add(new JLabel(" "), settings); + + settings.setPositionX(5); + settings.setPositionY(0); + forModal.add(new JLabel(" "), settings); + + settings.setPositionX(6); + settings.setPositionY(0); + JButton moveBtn = new JButton(stringSet[1]); + moveBtn.setActionCommand("crtll::ActionAddAndMoveGrup"); + moveBtn.addActionListener(this); + forModal.add(moveBtn, settings); + + DisplayModal( + stringSet[2] + + tm.getValueAt(cell[0], 0) + " " + tm.getValueAt(cell[0], 1), + 500, + 250, + this.av.getX(), + this.av.getY(), + forModal + ); + this.parent.updateTable(this.initTable()); + } + public JTable initTable() { Object[][] data = new Object[this.e.size()][3]; String[] title = { @@ -625,8 +646,7 @@ public class Controller implements ActionListener, ListSelectionListener { Object[] info = { this.e.get(i).getNom(), this.e.get(i).getPrenom(), - String.valueOf(this.e.get(i).getGroupe()), - "[DEPLACER]" + String.valueOf(this.e.get(i).getGroupe()) }; data[i] = info; } diff --git a/src/Test/CustomJButton.java b/src/Test/CustomJButton.java index cc83c05..67a2cf3 100644 --- a/src/Test/CustomJButton.java +++ b/src/Test/CustomJButton.java @@ -26,8 +26,8 @@ public class CustomJButton extends JButton { private void init() { this.setFont(font); this.setFocusPainted(false); - //this.setContentAreaFilled(false); - this.setBorderPainted(false); + this.setContentAreaFilled(false); + //this.setBorderPainted(false); this.setBorder(new RoundedBorder(radius)); } } diff --git a/src/Test/RoundedBorder.java b/src/Test/RoundedBorder.java new file mode 100644 index 0000000..1e04680 --- /dev/null +++ b/src/Test/RoundedBorder.java @@ -0,0 +1,29 @@ +package Test; + +import javax.swing.border.Border; +import java.awt.*; + +public class RoundedBorder implements Border { + + private int radius; + + + RoundedBorder(int radius) { + this.radius = radius; + } + + + public Insets getBorderInsets(Component c) { + return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius); + } + + + public boolean isBorderOpaque() { + return true; + } + + + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + g.drawRoundRect(x, y, width-1, height-1, radius, radius); + } +}