3 import javajs.awt.Component;
7 public abstract class AbstractButton extends JComponent implements SC {
18 protected AbstractButton(String type) {
24 public void setSelected(boolean selected) {
25 this.selected = selected;
29 * SwingController.setSelected(this);
37 public boolean isSelected() {
42 public void addItemListener(Object listener) {
43 itemListener = listener;
47 public Object getIcon() {
52 public void setIcon(Object icon) {
53 this.icon = (String) icon;
57 public void init(String text, Object icon, String actionCommand, SC popupMenu) {
59 this.icon = (String) icon;
60 this.actionCommand = actionCommand;
61 this.popupMenu = popupMenu;
65 * SwingController.initMenuItem(this);
72 public SC getTopPopupMenu() {
73 // note that JMenu.getPopupMenu refers to ITSELF, not the main one)
78 public void add(SC item) {
79 addComponent((Component) item);
83 public void insert(SC subMenu, int index) {
84 // JMenu, JPopupMenu only, but implemented here as well
86 insertComponent((Component) subMenu, index);
90 public Object getPopupMenu() {
95 protected String getMenuHTML() {
96 String label = (this.icon != null ? this.icon
97 : this.text != null ? this.text
99 String s = (label == null ? "" : "<li><a>" + label + "</a>"
100 + htmlMenuOpener("ul"));
101 int n = getComponentCount();
103 for(int i = 0; i < n; i++)
104 s += getComponent(i).toHTML();
110 protected String htmlMenuOpener(String type) {
111 return "<" + type + " id=\"" + this.id + "\"" + (this.enabled ? "" : getHtmlDisabled()) + ">";
114 protected String getHtmlDisabled() {
115 return " disabled=\"disabled\"";