3 import swingjs.api.DOMNode;
6 public abstract class JSToggleButtonUI extends JSButtonUI {
8 private boolean isDomChecked;
10 boolean verifyButtonClick(boolean isRelease) {
11 // state should change upon mouse release
13 // Yes, we could do this with an HTML5 click event, but I want to try this...
15 // cannot use node.getAttribute here because that returns "null" in FF
16 boolean checked = ((Boolean) DOMNode.getAttr(domBtn, "checked") == true);
17 // System.out.println(c.getName() + this.id + " JSTogglebutton verify checked=" + checked + " isReleased=" + isRelease + " isDomChecked=" + isDomChecked);
18 if (isRelease && isDomChecked == checked)
20 isDomChecked = checked;
25 // private static final Object BASIC_TOGGLE_BUTTON_UI_KEY = new Object();
27 // // ********************************
29 // // ********************************
30 // public static ComponentUI createUI(JComponent b) {
31 // AppContext appContext = AppContext.getAppContext();
32 // BasicToggleButtonUI toggleButtonUI =
33 // (BasicToggleButtonUI) appContext.get(BASIC_TOGGLE_BUTTON_UI_KEY);
34 // if (toggleButtonUI == null) {
35 // toggleButtonUI = new BasicToggleButtonUI();
36 // appContext.put(BASIC_TOGGLE_BUTTON_UI_KEY, toggleButtonUI);
38 // return toggleButtonUI;
42 protected String getPropertyPrefix() {
43 return "ToggleButton.";
47 // // ********************************
49 // // ********************************
50 // public void paint(Graphics g, JComponent c) {
51 // AbstractButton b = (AbstractButton) c;
52 // ButtonModel model = b.getModel();
54 // Dimension size = b.getSize();
55 // FontMetrics fm = g.getFontMetrics();
57 // Insets i = c.getInsets();
59 // Rectangle viewRect = new Rectangle(size);
61 // viewRect.x += i.left;
62 // viewRect.y += i.top;
63 // viewRect.width -= (i.right + viewRect.x);
64 // viewRect.height -= (i.bottom + viewRect.y);
66 // Rectangle iconRect = new Rectangle();
67 // Rectangle textRect = new Rectangle();
69 // Font f = c.getFont();
72 // // layout the text and icon
73 // String text = SwingUtilities.layoutCompoundLabel(
74 // c, fm, b.getText(), b.getIcon(),
75 // b.getVerticalAlignment(), b.getHorizontalAlignment(),
76 // b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
77 // viewRect, iconRect, textRect,
78 // b.getText() == null ? 0 : b.getIconTextGap());
80 // g.setColor(b.getBackground());
82 // if (model.isArmed() && model.isPressed() || model.isSelected()) {
83 // paintButtonPressed(g,b);
87 // if(b.getIcon() != null) {
88 // paintIcon(g, b, iconRect);
92 // if(text != null && !text.equals("")) {
93 // View v = (View) c.getClientProperty(BasicHTML.propertyKey);
95 // v.paint(g, textRect);
97 // paintText(g, b, textRect, text);
101 // // draw the dashed focus line.
102 // if (b.isFocusPainted() && b.hasFocus()) {
103 // paintFocus(g, b, viewRect, textRect, iconRect);
107 // protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {
108 // ButtonModel model = b.getModel();
111 // if(!model.isEnabled()) {
112 // if(model.isSelected()) {
113 // icon = (Icon) b.getDisabledSelectedIcon();
115 // icon = (Icon) b.getDisabledIcon();
117 // } else if(model.isPressed() && model.isArmed()) {
118 // icon = (Icon) b.getPressedIcon();
119 // if(icon == null) {
120 // // Use selected icon
121 // icon = (Icon) b.getSelectedIcon();
123 // } else if(model.isSelected()) {
124 // if(b.isRolloverEnabled() && model.isRollover()) {
125 // icon = (Icon) b.getRolloverSelectedIcon();
126 // if (icon == null) {
127 // icon = (Icon) b.getSelectedIcon();
130 // icon = (Icon) b.getSelectedIcon();
132 // } else if(b.isRolloverEnabled() && model.isRollover()) {
133 // icon = (Icon) b.getRolloverIcon();
136 // if(icon == null) {
137 // icon = (Icon) b.getIcon();
140 // icon.paintIcon(b, g, iconRect.x, iconRect.y);
144 // * Overriden so that the text will not be rendered as shifted for
145 // * Toggle buttons and subclasses.
147 // protected int getTextShiftOffset() {