JAL-1807 Bob
[jalviewjs.git] / site / j2s / swingjs / plaf / JSToggleButtonUI.java
1 package swingjs.plaf;
2
3 import swingjs.api.DOMNode;
4
5
6 public abstract class JSToggleButtonUI extends JSButtonUI {
7
8         private boolean isDomChecked;
9
10         boolean verifyButtonClick(boolean isRelease) {
11                 // state should change upon mouse release
12
13                 // Yes, we could do this with an HTML5 click event, but I want to try this...
14
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)
19                         return false;
20                 isDomChecked = checked;
21                 return true;
22         }
23
24         
25 //  private static final Object BASIC_TOGGLE_BUTTON_UI_KEY = new Object();
26
27 //  // ********************************
28 //  //          Create PLAF
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);
37 //      }
38 //      return toggleButtonUI;
39 //  }
40 //
41         @Override
42   protected String getPropertyPrefix() {
43       return "ToggleButton.";
44   }
45
46
47 //  // ********************************
48 //  //          Paint Methods
49 //  // ********************************
50 //  public void paint(Graphics g, JComponent c) {
51 //      AbstractButton b = (AbstractButton) c;
52 //      ButtonModel model = b.getModel();
53 //
54 //      Dimension size = b.getSize();
55 //      FontMetrics fm = g.getFontMetrics();
56 //
57 //      Insets i = c.getInsets();
58 //
59 //      Rectangle viewRect = new Rectangle(size);
60 //
61 //      viewRect.x += i.left;
62 //      viewRect.y += i.top;
63 //      viewRect.width -= (i.right + viewRect.x);
64 //      viewRect.height -= (i.bottom + viewRect.y);
65 //
66 //      Rectangle iconRect = new Rectangle();
67 //      Rectangle textRect = new Rectangle();
68 //
69 //      Font f = c.getFont();
70 //      g.setFont(f);
71 //
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());
79 //
80 //      g.setColor(b.getBackground());
81 //
82 //      if (model.isArmed() && model.isPressed() || model.isSelected()) {
83 //          paintButtonPressed(g,b);
84 //      }
85 //
86 //      // Paint the Icon
87 //      if(b.getIcon() != null) {
88 //          paintIcon(g, b, iconRect);
89 //      }
90 //
91 //      // Draw the Text
92 //      if(text != null && !text.equals("")) {
93 //          View v = (View) c.getClientProperty(BasicHTML.propertyKey);
94 //          if (v != null) {
95 //             v.paint(g, textRect);
96 //          } else {
97 //             paintText(g, b, textRect, text);
98 //          }
99 //      }
100 //
101 //      // draw the dashed focus line.
102 //      if (b.isFocusPainted() && b.hasFocus()) {
103 //          paintFocus(g, b, viewRect, textRect, iconRect);
104 //      }
105 //  }
106
107 //  protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {
108 //      ButtonModel model = b.getModel();
109 //      Icon icon = null;
110 //
111 //      if(!model.isEnabled()) {
112 //          if(model.isSelected()) {
113 //             icon = (Icon) b.getDisabledSelectedIcon();
114 //          } else {
115 //             icon = (Icon) b.getDisabledIcon();
116 //          }
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();
122 //          }
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();
128 //              }
129 //          } else {
130 //              icon = (Icon) b.getSelectedIcon();
131 //          }
132 //      } else if(b.isRolloverEnabled() && model.isRollover()) {
133 //          icon = (Icon) b.getRolloverIcon();
134 //      }
135 //
136 //      if(icon == null) {
137 //          icon = (Icon) b.getIcon();
138 //      }
139 //
140 //      icon.paintIcon(b, g, iconRect.x, iconRect.y);
141 //  }
142 //
143 //  /**
144 //   * Overriden so that the text will not be rendered as shifted for
145 //   * Toggle buttons and subclasses.
146 //   */
147 //  protected int getTextShiftOffset() {
148 //      return 0;
149 //  }
150 //
151 //
152 }