JAL-1807 Bob's first commit -- Applet loaded; needs image
[jalview.git] / src / javajs / swing / JMenuItem.java
1 package javajs.swing;
2
3 public class JMenuItem extends AbstractButton {
4
5   public final int btnType;
6   
7   public static final int TYPE_SEPARATOR = 0;
8   public static final int TYPE_BUTTON = 1;
9   public static final int TYPE_CHECKBOX = 2;
10   public static final int TYPE_RADIO = 3;
11   public static final int TYPE_MENU = 4;
12
13
14   public JMenuItem(String text) {
15     super("btn");
16     setText(text);
17     btnType = (text == null ? 0 : 1);
18   }
19
20   public JMenuItem(String type, int i) {
21     super(type);
22     btnType = i;
23   }
24
25   @Override
26   public String toHTML() {
27     return htmlMenuOpener("li")
28         + (text == null ? "" : "<a>" + htmlLabel() + "</a>") + "</li>";
29   }
30
31   @Override
32   protected String getHtmlDisabled() {
33     return " class=\"ui-state-disabled\"";  
34   }
35
36   private String htmlLabel() {
37     return (btnType == TYPE_BUTTON ? text 
38         : "<label><input id=\"" + id + "-" + (btnType == TYPE_RADIO ? "r" : "c") 
39         + "b\" type=\""
40         + (btnType == TYPE_RADIO ? "radio\" name=\"" + htmlName : "checkbox")
41         + "\" " + (selected ? "checked" : "") + " />" 
42         + text + "</label>");
43   }
44
45
46 }