Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / swingjs / plaf / JSToggleButtonUI.java
index c73b557..b05453b 100644 (file)
-package swingjs.plaf;\r
-\r
-import swingjs.api.DOMNode;\r
-\r
-\r
-public abstract class JSToggleButtonUI extends JSButtonUI {\r
-\r
-       private boolean isDomChecked;\r
-\r
-       boolean verifyButtonClick(boolean isRelease) {\r
-               // state should change upon mouse release\r
-\r
-               // Yes, we could do this with an HTML5 click event, but I want to try this...\r
-\r
-               // cannot use node.getAttribute here because that returns "null" in FF\r
-               boolean checked = ((Boolean) DOMNode.getAttr(domBtn, "checked") == true);\r
-               //   System.out.println(c.getName() + this.id + " JSTogglebutton verify checked=" + checked + " isReleased=" + isRelease + " isDomChecked=" + isDomChecked);\r
-               if (isRelease && isDomChecked == checked)\r
-                       return false;\r
-               isDomChecked = checked;\r
-               return true;\r
-       }\r
-\r
-       \r
-//  private static final Object BASIC_TOGGLE_BUTTON_UI_KEY = new Object();\r
-\r
-//  // ********************************\r
-//  //          Create PLAF\r
-//  // ********************************\r
-//  public static ComponentUI createUI(JComponent b) {\r
-//      AppContext appContext = AppContext.getAppContext();\r
-//      BasicToggleButtonUI toggleButtonUI = \r
-//              (BasicToggleButtonUI) appContext.get(BASIC_TOGGLE_BUTTON_UI_KEY);\r
-//      if (toggleButtonUI == null) {\r
-//          toggleButtonUI = new BasicToggleButtonUI();\r
-//          appContext.put(BASIC_TOGGLE_BUTTON_UI_KEY, toggleButtonUI);\r
-//      }\r
-//      return toggleButtonUI;\r
-//  }\r
-//\r
-       @Override\r
-  protected String getPropertyPrefix() {\r
-      return "ToggleButton.";\r
-  }\r
-\r
-\r
-//  // ********************************\r
-//  //          Paint Methods\r
-//  // ********************************\r
-//  public void paint(Graphics g, JComponent c) {\r
-//      AbstractButton b = (AbstractButton) c;\r
-//      ButtonModel model = b.getModel();\r
-//\r
-//      Dimension size = b.getSize();\r
-//      FontMetrics fm = g.getFontMetrics();\r
-//\r
-//      Insets i = c.getInsets();\r
-//\r
-//      Rectangle viewRect = new Rectangle(size);\r
-//\r
-//      viewRect.x += i.left;\r
-//      viewRect.y += i.top;\r
-//      viewRect.width -= (i.right + viewRect.x);\r
-//      viewRect.height -= (i.bottom + viewRect.y);\r
-//\r
-//      Rectangle iconRect = new Rectangle();\r
-//      Rectangle textRect = new Rectangle();\r
-//\r
-//      Font f = c.getFont();\r
-//      g.setFont(f);\r
-//\r
-//      // layout the text and icon\r
-//      String text = SwingUtilities.layoutCompoundLabel(\r
-//          c, fm, b.getText(), b.getIcon(),\r
-//          b.getVerticalAlignment(), b.getHorizontalAlignment(),\r
-//          b.getVerticalTextPosition(), b.getHorizontalTextPosition(),\r
-//          viewRect, iconRect, textRect,\r
-//          b.getText() == null ? 0 : b.getIconTextGap());\r
-//\r
-//      g.setColor(b.getBackground());\r
-//\r
-//      if (model.isArmed() && model.isPressed() || model.isSelected()) {\r
-//          paintButtonPressed(g,b);\r
-//      }\r
-//\r
-//      // Paint the Icon\r
-//      if(b.getIcon() != null) {\r
-//          paintIcon(g, b, iconRect);\r
-//      }\r
-//\r
-//      // Draw the Text\r
-//      if(text != null && !text.equals("")) {\r
-//          View v = (View) c.getClientProperty(BasicHTML.propertyKey);\r
-//          if (v != null) {\r
-//             v.paint(g, textRect);\r
-//          } else {\r
-//             paintText(g, b, textRect, text);\r
-//          }\r
-//      }\r
-//\r
-//      // draw the dashed focus line.\r
-//      if (b.isFocusPainted() && b.hasFocus()) {\r
-//          paintFocus(g, b, viewRect, textRect, iconRect);\r
-//      }\r
-//  }\r
-\r
-//  protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {\r
-//      ButtonModel model = b.getModel();\r
-//      Icon icon = null;\r
-//\r
-//      if(!model.isEnabled()) {\r
-//          if(model.isSelected()) {\r
-//             icon = (Icon) b.getDisabledSelectedIcon();\r
-//          } else {\r
-//             icon = (Icon) b.getDisabledIcon();\r
-//          }\r
-//      } else if(model.isPressed() && model.isArmed()) {\r
-//          icon = (Icon) b.getPressedIcon();\r
-//          if(icon == null) {\r
-//              // Use selected icon\r
-//              icon = (Icon) b.getSelectedIcon();\r
-//          }\r
-//      } else if(model.isSelected()) {\r
-//          if(b.isRolloverEnabled() && model.isRollover()) {\r
-//              icon = (Icon) b.getRolloverSelectedIcon();\r
-//              if (icon == null) {\r
-//                  icon = (Icon) b.getSelectedIcon();\r
-//              }\r
-//          } else {\r
-//              icon = (Icon) b.getSelectedIcon();\r
-//          }\r
-//      } else if(b.isRolloverEnabled() && model.isRollover()) {\r
-//          icon = (Icon) b.getRolloverIcon();\r
-//      }\r
-//\r
-//      if(icon == null) {\r
-//          icon = (Icon) b.getIcon();\r
-//      }\r
-//\r
-//      icon.paintIcon(b, g, iconRect.x, iconRect.y);\r
-//  }\r
-//\r
-//  /**\r
-//   * Overriden so that the text will not be rendered as shifted for\r
-//   * Toggle buttons and subclasses.\r
-//   */\r
-//  protected int getTextShiftOffset() {\r
-//      return 0;\r
-//  }\r
-//\r
-//\r
-}\r
+package swingjs.plaf;
+
+import swingjs.api.DOMNode;
+
+
+public abstract class JSToggleButtonUI extends JSButtonUI {
+
+       private boolean isDomChecked;
+
+       boolean verifyButtonClick(boolean isRelease) {
+               // state should change upon mouse release
+
+               // Yes, we could do this with an HTML5 click event, but I want to try this...
+
+               // cannot use node.getAttribute here because that returns "null" in FF
+               boolean checked = ((Boolean) DOMNode.getAttr(domBtn, "checked") == true);
+               //   System.out.println(c.getName() + this.id + " JSTogglebutton verify checked=" + checked + " isReleased=" + isRelease + " isDomChecked=" + isDomChecked);
+               if (isRelease && isDomChecked == checked)
+                       return false;
+               isDomChecked = checked;
+               return true;
+       }
+
+       
+//  private static final Object BASIC_TOGGLE_BUTTON_UI_KEY = new Object();
+
+//  // ********************************
+//  //          Create PLAF
+//  // ********************************
+//  public static ComponentUI createUI(JComponent b) {
+//      AppContext appContext = AppContext.getAppContext();
+//      BasicToggleButtonUI toggleButtonUI = 
+//              (BasicToggleButtonUI) appContext.get(BASIC_TOGGLE_BUTTON_UI_KEY);
+//      if (toggleButtonUI == null) {
+//          toggleButtonUI = new BasicToggleButtonUI();
+//          appContext.put(BASIC_TOGGLE_BUTTON_UI_KEY, toggleButtonUI);
+//      }
+//      return toggleButtonUI;
+//  }
+//
+       @Override
+  protected String getPropertyPrefix() {
+      return "ToggleButton.";
+  }
+
+
+//  // ********************************
+//  //          Paint Methods
+//  // ********************************
+//  public void paint(Graphics g, JComponent c) {
+//      AbstractButton b = (AbstractButton) c;
+//      ButtonModel model = b.getModel();
+//
+//      Dimension size = b.getSize();
+//      FontMetrics fm = g.getFontMetrics();
+//
+//      Insets i = c.getInsets();
+//
+//      Rectangle viewRect = new Rectangle(size);
+//
+//      viewRect.x += i.left;
+//      viewRect.y += i.top;
+//      viewRect.width -= (i.right + viewRect.x);
+//      viewRect.height -= (i.bottom + viewRect.y);
+//
+//      Rectangle iconRect = new Rectangle();
+//      Rectangle textRect = new Rectangle();
+//
+//      Font f = c.getFont();
+//      g.setFont(f);
+//
+//      // layout the text and icon
+//      String text = SwingUtilities.layoutCompoundLabel(
+//          c, fm, b.getText(), b.getIcon(),
+//          b.getVerticalAlignment(), b.getHorizontalAlignment(),
+//          b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
+//          viewRect, iconRect, textRect,
+//          b.getText() == null ? 0 : b.getIconTextGap());
+//
+//      g.setColor(b.getBackground());
+//
+//      if (model.isArmed() && model.isPressed() || model.isSelected()) {
+//          paintButtonPressed(g,b);
+//      }
+//
+//      // Paint the Icon
+//      if(b.getIcon() != null) {
+//          paintIcon(g, b, iconRect);
+//      }
+//
+//      // Draw the Text
+//      if(text != null && !text.equals("")) {
+//          View v = (View) c.getClientProperty(BasicHTML.propertyKey);
+//          if (v != null) {
+//             v.paint(g, textRect);
+//          } else {
+//             paintText(g, b, textRect, text);
+//          }
+//      }
+//
+//      // draw the dashed focus line.
+//      if (b.isFocusPainted() && b.hasFocus()) {
+//          paintFocus(g, b, viewRect, textRect, iconRect);
+//      }
+//  }
+
+//  protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {
+//      ButtonModel model = b.getModel();
+//      Icon icon = null;
+//
+//      if(!model.isEnabled()) {
+//          if(model.isSelected()) {
+//             icon = (Icon) b.getDisabledSelectedIcon();
+//          } else {
+//             icon = (Icon) b.getDisabledIcon();
+//          }
+//      } else if(model.isPressed() && model.isArmed()) {
+//          icon = (Icon) b.getPressedIcon();
+//          if(icon == null) {
+//              // Use selected icon
+//              icon = (Icon) b.getSelectedIcon();
+//          }
+//      } else if(model.isSelected()) {
+//          if(b.isRolloverEnabled() && model.isRollover()) {
+//              icon = (Icon) b.getRolloverSelectedIcon();
+//              if (icon == null) {
+//                  icon = (Icon) b.getSelectedIcon();
+//              }
+//          } else {
+//              icon = (Icon) b.getSelectedIcon();
+//          }
+//      } else if(b.isRolloverEnabled() && model.isRollover()) {
+//          icon = (Icon) b.getRolloverIcon();
+//      }
+//
+//      if(icon == null) {
+//          icon = (Icon) b.getIcon();
+//      }
+//
+//      icon.paintIcon(b, g, iconRect.x, iconRect.y);
+//  }
+//
+//  /**
+//   * Overriden so that the text will not be rendered as shifted for
+//   * Toggle buttons and subclasses.
+//   */
+//  protected int getTextShiftOffset() {
+//      return 0;
+//  }
+//
+//
+}