1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
package pSignature;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileFilter;
import pSignature.pInclude.DlgConcepteur;
import pSignature.pInclude.ReadFile;
import pSignature.pInclude.WriteFile;
public class fSignature extends JFrame {
private static JLabel lblTgi;
private static JLabel lblNom;
private static JLabel lblPrenom;
private static JComboBox cbBoxSelectionnerApprobateur;
private static JLabel lblSelectionnerApprobateur;
private static JButton btnConcepteur;
private static JButton btnSupprimer;
private static JFormattedTextField txtfldindice;
private static JLabel lblIndice;
private static JFormattedTextField txtfldreference;
private static JLabel lblRfrence;
private static JFormattedTextField txtfldArticleLogiciel;
private static JLabel lblArticleLogiciel;
private static JButton btnAjouter;
private static JLabel lblSelectionnerUnFichier;
private static JLabel lblSignaturelectronique;
private static JButton btnQuitter;
private static JButton btnValider;
private JScrollPane scrollPane;
private JScrollBar ascenseur;
private static JList lstSelectionnerUnFichier;
private static DefaultListModel model;
private static Vector<String> data = new Vector<String>();
// on va chercher la liste de fichiers pour initialiser la JList
Iterable<String> fichiers = getFiles(null);
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(
new Runnable() {
public void run() {
try {
fSignature frame = new fSignature();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public fSignature() {
getContentPane().setFont(new Font("Calibri", Font.PLAIN, 12));
setTitle("Signature électronique");
setFont(new Font("Calibri", Font.PLAIN, 12));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 400);
getContentPane().setLayout(new BorderLayout());
getContentPane().setLayout(null);
/*
http://www.developpez.net/forums/d1526606/java/interfaces-graphiques-java/awt-swing/probleme-scrollpane-jlist-vector/#post8285071
*/
final fSignature lstSelectionnerUnFichier = new fSignature(fichiers);
lstSelectionnerUnFichier.setFont(new Font("Calibri", Font.PLAIN, 12));
lstSelectionnerUnFichier.setBounds(40, 80, 150, 50);
getContentPane().add(lstSelectionnerUnFichier);
btnValider = new JButton("Valider");
btnValider.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
validation(e);
}
});
btnValider.setFont(new Font("Calibri", Font.PLAIN, 12));
btnValider.setToolTipText("Cliquer pour Valider votre signature");
btnValider.setBounds(40, 328, 89, 23);
getContentPane().add(btnValider);
btnQuitter = new JButton("Quitter");
btnQuitter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//quitter l'application
System.exit(0);
}
});
btnQuitter.setToolTipText("Cliquer pour Quitter l'application");
btnQuitter.setFont(new Font("Calibri", Font.PLAIN, 12));
btnQuitter.setBounds(180, 328, 89, 23);
getContentPane().add(btnQuitter);
lblSignaturelectronique = new JLabel("Signature électronique");
lblSignaturelectronique.setLabelFor(lblSignaturelectronique);
lblSignaturelectronique.setHorizontalAlignment(SwingConstants.CENTER);
lblSignaturelectronique.setFont(new Font("Calibri", Font.BOLD, 16));
lblSignaturelectronique.setToolTipText("Signature électronique");
lblSignaturelectronique.setHorizontalAlignment(JLabel.CENTER);
lblSignaturelectronique.setVerticalAlignment(JLabel.TOP);
getContentPane().add(lblSignaturelectronique);
lblSelectionnerUnFichier = new JLabel("Sélectionner un fichier :");
lblSelectionnerUnFichier .setLabelFor(lstSelectionnerUnFichier);
lblSelectionnerUnFichier .setFont(new Font("Calibri", Font.PLAIN, 12));
lblSelectionnerUnFichier .setBounds(40, 50, 130, 16);
getContentPane().add(lblSelectionnerUnFichier );
btnAjouter = new JButton("Ajouter");
btnAjouter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//ajouter un approbateur dans la liste
for(String fichier : getFiles(lstSelectionnerUnFichier)) {
lstSelectionnerUnFichier.ajouterElement(fichier);
}
}
});
btnAjouter.setBounds(200, 77, 89, 23);
getContentPane().add(btnAjouter);
lblArticleLogiciel = new JLabel("Article Logiciel :");
lblArticleLogiciel.setFont(new Font("Calibri", Font.PLAIN, 12));
lblArticleLogiciel.setBounds(40, 141, 86, 16);
getContentPane().add(lblArticleLogiciel);
txtfldArticleLogiciel = new JFormattedTextField();
/*try{
MaskFormatter indice = new MaskFormatter("UU");
//Vous pouvez ensuite le passer é votre zone de texte
txtfldArticleLogiciel = new JFormattedTextField(indice);
} catch(ParseException e) {
e.printStackTrace();
}*/
txtfldArticleLogiciel.setToolTipText("8 chiffres et 2 lettres");
txtfldArticleLogiciel.setFont(new Font("Calibri", Font.PLAIN, 12));
txtfldArticleLogiciel.setBounds(125, 141, 100, 20);
txtfldArticleLogiciel.setText("");
getContentPane().add(txtfldArticleLogiciel);
lblRfrence = new JLabel("Référence :");
lblRfrence.setFont(new Font("Calibri", Font.PLAIN, 12));
lblRfrence.setBounds(40, 165, 61, 16);
getContentPane().add(lblRfrence);
txtfldreference = new JFormattedTextField();
txtfldreference.setToolTipText("");
txtfldreference.setFont(new Font("Calibri", Font.PLAIN, 12));
txtfldreference.setBounds(125, 168, 65, 20);
txtfldreference.setText("");
getContentPane().add(txtfldreference);
lblIndice = new JLabel("Indice :");
lblIndice.setFont(new Font("Calibri", Font.PLAIN, 12));
lblIndice.setBounds(200, 165, 40, 16);
getContentPane().add(lblIndice);
txtfldindice = new JFormattedTextField();
/*try{
MaskFormatter indice = new MaskFormatter("UU");
//Vous pouvez ensuite le passer é votre zone de texte
txtfldindice = new JFormattedTextField(indice);
} catch(ParseException e) {
e.printStackTrace();
}*/
txtfldindice.setToolTipText("");
txtfldindice.setFont(new Font("Calibri", Font.PLAIN, 12));
txtfldindice.setBounds(250, 168, 65, 20);
txtfldindice.setText("");
getContentPane().add(txtfldindice);
btnSupprimer = new JButton("Supprimer");
btnSupprimer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
lstSelectionnerUnFichier.deleteSelectedElement();
}
public void valueChanged(ListSelectionEvent e) {
if ( !e.getValueIsAdjusting() ) {
ListSelectionModel source = ((ListSelectionModel)e.getSource());
btnSupprimer.setEnabled(source.getMinSelectionIndex()>=0 && source.getMaxSelectionIndex()==source.getMinSelectionIndex());
}
}
});
btnSupprimer.setBounds(200, 107, 89, 23);
getContentPane().add(btnSupprimer);
//concepteur
btnConcepteur = new JButton("Concepteur...");
btnConcepteur.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
DlgConcepteur.Concepteur();
}
});
btnConcepteur.setBounds(40, 189, 101, 23);
getContentPane().add(btnConcepteur);
lblTgi = new JLabel("TGI");
lblTgi.setFont(new Font("Calibri", Font.PLAIN, 12));
lblTgi.setBounds(200, 189, 100, 16);
lblTgi.setText("TGI");
getContentPane().add(lblTgi);
lblNom = new JLabel("Nom");
lblNom.setFont(new Font("Calibri", Font.PLAIN, 12));
lblNom.setBounds(250, 189, 100, 16);
lblNom.setText("Nom");
getContentPane().add(lblNom);
lblPrenom = new JLabel("Prénom");
lblPrenom.setFont(new Font("Calibri", Font.PLAIN, 12));
lblPrenom.setBounds(300, 189, 100, 16);
lblPrenom.setText("Prénom");
getContentPane().add(lblPrenom);
//approbateur
lblSelectionnerApprobateur = new JLabel("Sélectionner un approbateur :");
lblSelectionnerApprobateur.setFont(new Font("Calibri", Font.PLAIN, 12));
lblSelectionnerApprobateur.setBounds(40, 220, 163, 16);
getContentPane().add(lblSelectionnerApprobateur);
cbBoxSelectionnerApprobateur = new JComboBox();
cbBoxSelectionnerApprobateur.setFont(new Font("Times New Roman", Font.PLAIN, 14));
cbBoxSelectionnerApprobateur.setBounds(210, 220, 200, 16);
cbBoxSelectionnerApprobateur.setEditable(false); // ne Permet pas de saisir du texte
getContentPane().add(cbBoxSelectionnerApprobateur);
//récupérer la liste des approbateurs
cbBoxSelectionnerApprobateur.addItem("");
ReadFile.lireFichier(cbBoxSelectionnerApprobateur, "monfichier");
}
public fSignature(Iterable<String> fichiers) { // cette méthode marche pour toutes List (dont les Vector), et autre Collection
model = new DefaultListModel(); // je créé le modèle
for(String fichier : fichiers) { // j'ajoute mes éléments au modèle
model.addElement(fichier);
}
lstSelectionnerUnFichier = new JList(model); // je créé la JList à partir du modèle
add( lstSelectionnerUnFichier );
}
public void deleteSelectedElement() {
if ( !lstSelectionnerUnFichier.isSelectionEmpty() ) {
int index = lstSelectionnerUnFichier.getSelectedIndex();
model.remove(index);
}
}
public void ajouterElement(String file) {
model.addElement(file);
}
public void addSelectionListener(ListSelectionListener listener) {
lstSelectionnerUnFichier.getSelectionModel().addListSelectionListener(listener);
}
public static void modifierValeur(String tgi, String nom, String prenom) {
lblTgi.setText(tgi);
lblNom.setText(nom);
lblPrenom.setText(prenom);;
}
public static void creerFichierText() {
//créer un fichier.txt
WriteFile.ecrireFichier (
"fichier_FPGA",
lstSelectionnerUnFichier.getSelectedValue(),
txtfldArticleLogiciel.getText(),
txtfldreference.getText(),
txtfldindice.getText(),
lblTgi.getText(),
lblNom.getText(),
lblPrenom.getText(),
cbBoxSelectionnerApprobateur.getSelectedItem()
);
}
public static void validation(ActionEvent e) {
if (btnValider == e.getSource()) {
//vérifier que tous les champs soient remplis
JOptionPane message = new JOptionPane();
if (lstSelectionnerUnFichier.getSelectedValue() == null) {
message.showMessageDialog(null, "Veuillez sélectionner un fichier !", "Attention", JOptionPane.WARNING_MESSAGE);
} else if (txtfldArticleLogiciel.getText().isEmpty()) {
message.showMessageDialog(null, "Veuillez remplir le champs Article logiciel !", "Attention", JOptionPane.WARNING_MESSAGE);
} else if (txtfldreference.getText().isEmpty()) {
message.showMessageDialog(null, "Veuillez remplir le champs Référence !", "Attention", JOptionPane.WARNING_MESSAGE);
} else if (txtfldindice.getText().isEmpty()) {
message.showMessageDialog(null, "Veuillez remplir le champs Indice !", "Attention", JOptionPane.WARNING_MESSAGE);
} else if (lblTgi.getText() == "TGI" ||
lblNom.getText() == "Nom" ||
lblPrenom.getText() == "Prénom"
) {
message.showMessageDialog(null, "Veuillez saisir vos informations en cliquant sur le bonton 'Concepteur...' !", "Attention", JOptionPane.WARNING_MESSAGE);
} else if (cbBoxSelectionnerApprobateur.getSelectedItem() == "") {
message.showMessageDialog(null, "Veuillez sélectionner un approbateur !", "Attention", JOptionPane.WARNING_MESSAGE);
} else {
creerFichierText();
}
}
}
/**
* Récupère les noms des fichiers contenus dans un dossier sélectionné par JFileChooser
* @param parent
* @return
*/
private static Iterable<String> getFiles(Component parent) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setDialogTitle("Choisir dossier...");
fileChooser.showOpenDialog(parent);
File file = fileChooser.getSelectedFile();
if ( file!=null ) {
File[] files = file.listFiles();
ArrayList<String> names = new ArrayList<String>(files.length);
for(File f : files) {
names.add(f.getName());
}
return names;
}
else {
return Collections.emptyList();
}
}
} |
Partager