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