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
|
public class PanelExtractionLog extends JPanel implements ActionListener {
private List <PanelSearchFileExtraction> listChamps; // Liste des JPanel à insérer
private JPanel panelListFiles; // panel dans lequel on insere
private Dialog dialog;
/**
* Create the panel.
*/
public PanelExtractionLog (Dialog dialog) {
super ();
this.dialog = dialog;
this.listChamps = (List <PanelSearchFileExtraction>) new ArrayList <PanelSearchFileExtraction> ();
listChamps.add (new PanelSearchFileExtraction (listChamps.size (),
dialog));
listChamps.add (new PanelSearchFileExtraction (listChamps.size (),
dialog));
listChamps.add (new PanelSearchFileExtraction (listChamps.size (),
dialog));
GridBagLayout gridBagLayout = new GridBagLayout ();
gridBagLayout.columnWidths = new int[] { 76, 315, 53, 0 };
gridBagLayout.rowHeights = new int[] { 0, 242, 22, 0 };
gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0,
Double.MIN_VALUE };
gridBagLayout.rowWeights = new double[] { 0.0, 1.0, 0.0,
Double.MIN_VALUE };
setLayout (gridBagLayout);
JButton btnAjouter = new JButton ("Ajouter");
btnAjouter.setMargin (new Insets (3, 7, 3, 7));
btnAjouter.setIcon (new ImageIcon ("images/add.png"));
GridBagConstraints gbc_btnAjouter = new GridBagConstraints ();
gbc_btnAjouter.fill = GridBagConstraints.HORIZONTAL;
gbc_btnAjouter.insets = new Insets (0, 0, 5, 5);
gbc_btnAjouter.gridx = 0;
gbc_btnAjouter.gridy = 0;
btnAjouter.setActionCommand ("Add");
btnAjouter.addActionListener (this);
add (btnAjouter, gbc_btnAjouter);
JButton btnRetirer = new JButton ("Retirer");
btnRetirer.setMargin (new Insets (3, 7, 3, 7));
btnRetirer.setIcon (new ImageIcon ("images/delete_2-16.png"));
GridBagConstraints gbc_btnRetirer = new GridBagConstraints ();
gbc_btnRetirer.anchor = GridBagConstraints.WEST;
gbc_btnRetirer.insets = new Insets (0, 0, 5, 5);
gbc_btnRetirer.gridx = 1;
gbc_btnRetirer.gridy = 0;
btnRetirer.setActionCommand ("Remove");
btnRetirer.addActionListener (this);
add (btnRetirer, gbc_btnRetirer);
panelListFiles = new JPanel ();
GridBagConstraints gbc_panelListFiles = new GridBagConstraints ();
gbc_panelListFiles.gridwidth = 3;
gbc_panelListFiles.insets = new Insets (0, 0, 5, 5);
gbc_panelListFiles.fill = GridBagConstraints.BOTH;
gbc_panelListFiles.gridx = 0;
gbc_panelListFiles.gridy = 1;
add (panelListFiles, gbc_panelListFiles);
GridBagLayout gbl_panelListFiles = new GridBagLayout ();
gbl_panelListFiles.columnWidths = new int[] { 0, 0 };
gbl_panelListFiles.rowHeights = new int[] { 0, 0 };
gbl_panelListFiles.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
gbl_panelListFiles.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
panelListFiles.setLayout (gbl_panelListFiles);
{
/*
* Insertion dans le JPanel de la liste préchargée
*/
for (int i = 0; i < listChamps.size (); ++i) {
GridBagConstraints gbc_pan = new GridBagConstraints ();
gbc_pan.gridwidth = 1;
gbc_pan.fill = GridBagConstraints.HORIZONTAL;
gbc_pan.anchor = GridBagConstraints.NORTH;
gbc_pan.gridx = 0;
gbc_pan.gridy = i;
panelListFiles.add (listChamps.get (i), gbc_pan);
}
}
/*
* Suite du code...
*/
} // constructeur
/*
* (non-Javadoc)
* @see
* java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed (ActionEvent e) {
String action = e.getActionCommand ();
if (action == "Remove") {
int indice = listChamps.size () - 1;
System.out.println (listChamps.size ());
panelListFiles.remove (indice);
listChamps.remove (indice);
} // action "Remove"
else if (action == "Add") {
int taille = listChamps.size ();
System.out.println (taille);
listChamps.add (new PanelSearchFileExtraction (taille, dialog));
GridBagConstraints gbc_pan = new GridBagConstraints ();
gbc_pan.gridwidth = 1;
gbc_pan.fill = GridBagConstraints.HORIZONTAL;
gbc_pan.anchor = GridBagConstraints.NORTH;
gbc_pan.gridx = 0;
gbc_pan.gridy = taille;
panelListFiles.add (listChamps.get (taille), gbc_pan);
} // action "Add"
revalidate ();
repaint ();
} // actionPerformed ()
} |
Partager