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
|
public class MainToolBar extends JToolBar implements ActionListener {
private static final long serialVersionUID = 1L;
private final String ADD_ACTION = "Add";
private final String DEL_ACTION = "Del";
private final String MOD_ACTION = "Mod";
private final String SAV_ACTION = "Sav";
private final String CAL_ACTION = "Cal";
private final String OPT_ACTION = "Opt";
private final Calendar calendar = new GregorianCalendar();
private final Date todayDate = new Date();
public MainToolBar(String MTBTitle, JTable maTable) {
calendar.setTime(todayDate);
this.setName(MTBTitle);
this.setFloatable(false);
addButtons(this);
}
protected JButton makeNavigationButton(Icon icon,
String actionCommand, String toolTipText, String altText, String modeIcon) {
// Create and initialize the button.
JButton button = new JButton();
button.setToolTipText(toolTipText);
button.setActionCommand(actionCommand);
button.addActionListener(this);
if (modeIcon.equals("Icon")) { // ImageIcon found
button.setIcon(icon);
} else { // no ImageIcon found
button.setText(altText);
System.err.println("Button image not found for:" + altText);
}
return button;
}
protected void addButtons(MainToolBar myBar) {
final String path = "U:/Java Workspaces/Icons/";
String modeIcon = "Icon";
File fichier1 = new File(path + "New.gif");
if (!fichier1.exists()) { modeIcon = "Text";}
File fichier2 = new File(path + "Delete.gif");
if (!fichier2.exists()) { modeIcon = "Text";}
File fichier3 = new File(path + "Modify.gif");
if (!fichier3.exists()) { modeIcon = "Text";}
File fichier4 = new File(path + "Save.gif");
if (!fichier4.exists()) { modeIcon = "Text";}
File fichier5 = new File(path + "Calculate.gif");
if (!fichier5.exists()) { modeIcon = "Text";}
File fichier6 = new File(path + "Option.gif");
if (!fichier6.exists()) { modeIcon = "Text";}
final Icon[] faces = { new ImageIcon(path + "New.gif"),
new ImageIcon(path + "Delete.gif"),
new ImageIcon(path + "Modify.gif"),
new ImageIcon(path + "Save.gif"),
new ImageIcon(path + "Calculate.gif"),
new ImageIcon(path + "Option.gif") };
JButton button = null;
// "ADD" Button
button = makeNavigationButton(faces[0], ADD_ACTION, "Add a new task",
"Add",modeIcon);
myBar.add(button);
// "MOD" Button
button = makeNavigationButton(faces[2], MOD_ACTION,
"Modify the selected task", "Modify",modeIcon);
myBar.add(button);
// "DEL" Button
button = makeNavigationButton(faces[1], DEL_ACTION,
"Delete the selected task", "Delete",modeIcon);
myBar.add(button);
// "Save" Button
button = makeNavigationButton(faces[3], SAV_ACTION,
"Save the task list", "Save",modeIcon);
myBar.add(button);
// "DEL" Button
button = makeNavigationButton(faces[4], CAL_ACTION,
"Calculate priority", "Calculate",modeIcon);
myBar.add(button);
// Ajout d'un séparateur
myBar.addSeparator();
// "OPT" Button
button = makeNavigationButton(faces[5], OPT_ACTION, "Manage options",
"Option",modeIcon);
myBar.add(button);
}
public void actionPerformed(ActionEvent actionRequested) {
// On a cliqué sur ADD
if (actionRequested.getActionCommand().equals(this.ADD_ACTION) )
{
TaskWindow panneau = new TaskWindow();
panneau.setCreda(calendar.get(Calendar.DATE) + "/" +
(calendar.get(Calendar.MONTH) + 1) + "/" +
calendar.get(Calendar.YEAR));
int reponse = JOptionPane.showConfirmDialog(null, panneau,
"Contact", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE);
if (reponse == JOptionPane.OK_OPTION)
System.out.println("Mettre à jour la table en créant une nouvelle ligne");
}
// On a cliqué sur MOD
else if (actionRequested.getActionCommand().equals(this.MOD_ACTION) )
{
System.out.println("Modifiation d'une ligne");
}
// On a cliqué sur DEL
else if (actionRequested.getActionCommand().equals(this.DEL_ACTION) )
{
System.out.println("suppression d'une ligne");
}
// On a cliqué sur CAL
else if (actionRequested.getActionCommand().equals(this.CAL_ACTION) )
{
System.out.println("Calcul de la liste");
}
// On a cliqué sur SAV
else if (actionRequested.getActionCommand().equals(this.SAV_ACTION) )
{
System.out.println("Sauvegarde de la liste");
}
// On a cliqué sur OPT
else if (actionRequested.getActionCommand().equals(this.OPT_ACTION) )
{
System.out.println("Gestion des options");
}
}
} |
Partager