This commit is contained in:
pablo rodriguez 2023-06-28 08:22:36 +02:00
parent 8ac9065af1
commit d71f78a00e
4 changed files with 189 additions and 138 deletions

View File

@ -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<Void, Integer> {
private List<Integer> progressList;
public ProcessTask() {
progressList = new ArrayList<>();
}
@Override
protected Void doInBackground() throws Exception {
runLongProcess();
return null;
}
@Override
protected void process(List<Integer> 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();
}
});
}
}

View File

@ -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){
}
}

View File

@ -114,14 +114,7 @@ public class demarre extends JFrame {
btnTutoriels.setIcon(new ImageIcon(demarre.class.getResource("/resources/gestionnaire.png"))); btnTutoriels.setIcon(new ImageIcon(demarre.class.getResource("/resources/gestionnaire.png")));
btnTutoriels.addActionListener(new ActionListener() { btnTutoriels.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { new gestionnaire();
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." );
} }
}); });
// btnTutoriels.setIcon(new ImageIcon(demarre.class.getResource("/resources/tutoriel.png"))); // btnTutoriels.setIcon(new ImageIcon(demarre.class.getResource("/resources/tutoriel.png")));

View File

@ -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<String> cYears;
private JComboBox<String> 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<String>();
cFormations = new JComboBox<String>();
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<String, String> 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;
// }
}