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