From d71f78a00e5f21f964eeec5f50655291a2bb2c4a Mon Sep 17 00:00:00 2001 From: pablo rodriguez <58742538+1-pablo-rodriguez@users.noreply.github.com> Date: Wed, 28 Jun 2023 08:22:36 +0200 Subject: [PATCH] maj --- src/baseUFRHG/ProgressBarExample.java | 106 --------------- src/baseUFRHG/createEvaluation.java | 24 ---- src/baseUFRHG/demarre.java | 9 +- src/baseUFRHG/gestionnaire.java | 188 ++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 138 deletions(-) delete mode 100644 src/baseUFRHG/ProgressBarExample.java delete mode 100644 src/baseUFRHG/createEvaluation.java create mode 100644 src/baseUFRHG/gestionnaire.java diff --git a/src/baseUFRHG/ProgressBarExample.java b/src/baseUFRHG/ProgressBarExample.java deleted file mode 100644 index f138b26..0000000 --- a/src/baseUFRHG/ProgressBarExample.java +++ /dev/null @@ -1,106 +0,0 @@ -package baseUFRHG; - -import java.awt.FlowLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.JProgressBar; -import javax.swing.SwingUtilities; -import javax.swing.SwingWorker; - -public class ProgressBarExample extends JFrame { - - /** - * - */ - private static final long serialVersionUID = 1L; - private JButton startButton; - private JProgressBar progressBar; - private ProcessTask processTask; - - public ProgressBarExample() { - setTitle("Exemple de ProgressBar"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setLayout(new FlowLayout()); - - startButton = new JButton("Démarrer"); - progressBar = new JProgressBar(0, 100); - progressBar.setStringPainted(true); - - startButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - startButton.setEnabled(false); - processTask = new ProcessTask(); - processTask.execute(); - } - }); - - add(startButton); - add(progressBar); - - pack(); - setVisible(true); - } - - private class ProcessTask extends SwingWorker { - - private List progressList; - - public ProcessTask() { - progressList = new ArrayList<>(); - } - - @Override - protected Void doInBackground() throws Exception { - runLongProcess(); - return null; - } - - @Override - protected void process(List chunks) { - int value = chunks.get(chunks.size() - 1); - progressBar.setValue(value); - } - - @Override - protected void done() { - startButton.setEnabled(true); - progressBar.setValue(0); - JOptionPane.showMessageDialog(ProgressBarExample.this, "Le processus est terminé !"); - } - - private void runLongProcess() { - for (int i = 0; i <= 100; i++) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - progressList.add(i); - publishProgress(); - } - } - - private void publishProgress() { - int lastIndex = progressList.size() - 1; - Integer[] chunks = new Integer[]{progressList.get(lastIndex)}; - publish(chunks); - } - } - - public static void main(String[] args) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - new ProgressBarExample(); - } - }); - } - -} diff --git a/src/baseUFRHG/createEvaluation.java b/src/baseUFRHG/createEvaluation.java deleted file mode 100644 index dd8e8b4..0000000 --- a/src/baseUFRHG/createEvaluation.java +++ /dev/null @@ -1,24 +0,0 @@ -package baseUFRHG; - -/** - * Cette class permet de créer le noeud évaluation. - * @author pabr6 - * - */ -public class createEvaluation { - - noeud analyseCalc; - - public noeud getAnalyseCalc() { - return analyseCalc; - } - - public void setAnalyseCalc(noeud evaluation) { - this.analyseCalc = evaluation; - } - - public createEvaluation(noeud rootContent, noeud rootStyles, noeud rootMeta, noeud graphics, String filenameFichier){ - - } - -} diff --git a/src/baseUFRHG/demarre.java b/src/baseUFRHG/demarre.java index d2a2475..4b611a7 100644 --- a/src/baseUFRHG/demarre.java +++ b/src/baseUFRHG/demarre.java @@ -114,14 +114,7 @@ public class demarre extends JFrame { btnTutoriels.setIcon(new ImageIcon(demarre.class.getResource("/resources/gestionnaire.png"))); btnTutoriels.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - try { - String url = "https://www.youtube.com/channel/UCG3tJWp_oZvOumH5kWUJ55g"; - java.awt.Desktop.getDesktop().browse(java.net.URI.create(url)); - } - catch (java.io.IOException e1) { - System.out.println(e1.getMessage()); - } - System.out.println( "Affiche les tutoriels." ); + new gestionnaire(); } }); // btnTutoriels.setIcon(new ImageIcon(demarre.class.getResource("/resources/tutoriel.png"))); diff --git a/src/baseUFRHG/gestionnaire.java b/src/baseUFRHG/gestionnaire.java new file mode 100644 index 0000000..c7355f9 --- /dev/null +++ b/src/baseUFRHG/gestionnaire.java @@ -0,0 +1,188 @@ +package baseUFRHG; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Map; + +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.border.EmptyBorder; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; + +public class gestionnaire extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + noeud nBase = null; + + private JPanel contentPane; + private JFrame frame; + + private JComboBox cYears; + private JComboBox cFormations; + private JTable table; + private JScrollPane scrollPane_1; + + /** + * Create the frame. + */ + public gestionnaire() { + getContentPane().setLayout(null); + + + + initialize(); + } + + + + private void initialize() { + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setBounds(100, 100, 1200, 651); + frame.setTitle("Gestionnaire Base des inscriptions des étudiants"); + frame.setLocationRelativeTo(null); // Centre la fenêtre à l'écran + + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + + frame.setContentPane(contentPane); + + + + nBase = recupeBases.recupeLaBase(); + cYears = new JComboBox(); + cFormations = new JComboBox(); + table = new JTable(); + table.setCellSelectionEnabled(true); + table.setColumnSelectionAllowed(true); + + + for(noeud nChild : nBase.getChildren()) { + cYears.addItem(nChild.getName()); + for(noeud nFormation : nChild.getChildren()) { + cFormations.addItem(nFormation.getName()); + } + } + cYears.setBounds(10, 25, 157, 22); + cYears.setVisible(true); + cFormations.setBounds(210, 25, 307, 22); + cFormations.setVisible(true); + + // Ajout d'un ActionListener à la JComboBox + cFormations.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + majTable(); + } + }); + + + + + + + table.setBounds(38, 136, 496, 199); +// scrollPane.add(table); + + + contentPane.setLayout(null); + contentPane.add(cYears); + contentPane.add(cFormations); +// contentPane.add(table); + + scrollPane_1 = new JScrollPane(); + scrollPane_1.setBounds(10, 71, 908, 515); + scrollPane_1.setVisible(true); + + contentPane.add(scrollPane_1); + scrollPane_1.setViewportView(table); + + + majTable(); + + frame.setVisible(true); + } + + + private void majTable() { + noeud nYears = nBase.getChild(cYears.getSelectedItem().toString()); + + if(nYears!=null) { + noeud nFormation = nYears.getChild(cFormations.getSelectedItem().toString()); + + String[] head = new String[31] ; + String[][] data = new String[nFormation.getChildren().size()][31] ; + + int indexRow = 0; + for(noeud nStudent : nFormation.getChildren()) { + int indexCol = 0; + head = new String[nStudent.getAttributes().size()]; + for (Map.Entry entry : nStudent.getAttributes().entrySet()) { + if(indexRow==0) { + String key = entry.getKey(); + head[indexCol] = key; + }else { + String value = entry.getValue(); + data[indexRow][indexCol] = value; + } + indexCol++; + } + indexRow++; + } + + + TableColumnModel columnModel = table.getColumnModel(); + for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) { + // Obtention de la colonne à l'index donné + TableColumn column = columnModel.getColumn(columnIndex); + column.setHeaderValue(head[columnIndex]); + // Ajustement de la largeur préférée de la colonne + column.setWidth(300); + } + + + + table.setModel(new DefaultTableModel(data, head)); + table.revalidate(); + table.repaint(); + + } + + + } + + + +// private static int getMaxColumnWidth(JTable table, int columnIndex) { +// int maxWidth = 200; +//// TableColumn column = table.getColumnModel().getColumn(columnIndex); +// // Obtention du modèle de rendu de cellules par défaut +// DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer(); +// +// if(cellRenderer!=null) { +// for (int row = 0; row < table.getRowCount(); row++) { +// Component cellComponent = cellRenderer.getTableCellRendererComponent(table, +// table.getValueAt(row, columnIndex), +// false, false, row, columnIndex); +// +// maxWidth = Math.max(maxWidth, cellComponent.getPreferredSize().width); +// } +// } +// +// +// return maxWidth; +// } + + + + +}