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