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
|
/**
*
*/
package com.complex.ui;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
/**
* @author Sébastien Serpaud
*
*/
public class TestActions {
/**
*
*/
private static final long serialVersionUID = 18862990943464100L;
private DemoAction action[];
/**
*
*/
@SuppressWarnings("serial")
public TestActions() {
action = new DemoAction[6];
action[0] = new DemoAction("Plot Magnitude", 'M',
createImageIcon("com/complex/lib/icons/magnitude.ico"));
action[1] = new DemoAction("Plot Magnitude in dB", 'B',
createImageIcon("com/complex/lib/icons/db.ico"));
action[2] = new DemoAction("Plot Phase", 'P',
createImageIcon("com/complex/lib/icons/phase.ico"));
action[3] = new DemoAction("Plot Phase in degree", 'D',
createImageIcon("com/complex/lib/icons/phasedegree.ico"));
action[4] = new DemoAction("Plot Real Part", 'R',
createImageIcon("com/complex/lib/icons/re.ico"));
action[5] = new DemoAction("Plot Imaginary Part", 'I',
createImageIcon("com/complex/lib/icons/im.ico"));
}
public void initMenu(JMenu menu) {
for (int i = 0; i < action.length; i++)
menu.add(action[i]);
}
public void initToolBar(JToolBar toolBar) {
for (int i = 0; i < action.length; i++)
toolBar.add(action[i]);
}
private ImageIcon createImageIcon(String path) {
java.net.URL imgURL = this.getClass().getClassLoader().getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println(this.getClass().getName() + " : fichier non trouve : " + path);
return null;
}
}
private class DemoAction extends AbstractAction {
/**
*
*/
private static final long serialVersionUID = -8785245616631770805L;
public DemoAction(String text, char shortcutKey, ImageIcon icon) {
super(text, icon);
putValue(SHORT_DESCRIPTION, text);
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(shortcutKey,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
public void actionPerformed(ActionEvent a) {
String name = (String) getValue(NAME);
System.out.println(name);
}
}
} |
Partager