Exemplo n.º 1
0
 public JToggleButton addToggleAction(IToggleAction action) {
   JToggleButton tglBtn = new JToggleButton();
   tglBtn.setAction(action);
   super.add(tglBtn);
   action.getToggleComponentHolder().addToggleableComponent(tglBtn);
   initialiseButton(action, tglBtn);
   return tglBtn;
 }
  private void configure() {
    fRotation = LEFT;

    fButtonDelegate =
        new JToggleButton() {
          public String getText() {
            return null;
          }

          public boolean isEnabled() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.isEnabled();
            }
            return super.isEnabled();
          }

          public boolean isSelected() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.isSelected();
            }
            return super.isSelected();
          }

          public boolean isFocusPainted() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.isFocusPainted();
            }
            return super.isFocusPainted();
          }

          public boolean isContentAreaFilled() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.isContentAreaFilled();
            }
            return super.isContentAreaFilled();
          }

          public boolean isBorderPainted() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.isBorderPainted();
            }
            return super.isBorderPainted();
          }

          public Border getBorder() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getBorder();
            }
            return super.getBorder();
          }

          public boolean isOpaque() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.isOpaque();
            }
            return super.isOpaque();
          }

          public Color getBackground() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getBackground();
            }
            return super.getBackground();
          }

          public Icon getIcon() {
            return null;
          }

          public Icon getPressedIcon() {
            return null;
          }

          public Icon getSelectedIcon() {
            return null;
          }

          public Icon getRolloverIcon() {
            return null;
          }

          public Icon getRolloverSelectedIcon() {
            return null;
          }

          public Icon getDisabledIcon() {
            return null;
          }
        };

    fLabelDelegate =
        new JLabel() {
          public String getText() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getText();
            }
            return super.getText();
          }

          public Color getForeground() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getForeground();
            }
            return super.getForeground();
          }

          public boolean isEnabled() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.isEnabled();
            }
            return super.isEnabled();
          }

          public int getIconTextGap() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getIconTextGap();
            }
            return super.getIconTextGap();
          }

          public int getVerticalAlignment() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getVerticalAlignment();
            }
            return super.getVerticalAlignment();
          }

          public int getVerticalTextPosition() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getVerticalTextPosition();
            }
            return super.getVerticalTextPosition();
          }

          public int getHorizontalAlignment() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getHorizontalAlignment();
            }
            return super.getHorizontalAlignment();
          }

          public int getHorizontalTextPosition() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getHorizontalTextPosition();
            }
            return super.getHorizontalTextPosition();
          }

          public Border getBorder() {
            return null;
          }

          public int getMnemonic() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getMnemonic();
            }
            return -1;
          }

          public int getDisplayedMnemonicIndex() {
            if (JVerticalToggleButton.this != null) {
              return JVerticalToggleButton.this.getDisplayedMnemonicIndex();
            }
            return super.getDisplayedMnemonicIndex();
          }

          private Insets insets = new Insets(0, 0, 0, 0);

          public Insets getInsets() {
            if (JVerticalToggleButton.this != null) {
              return super.getInsets();
            }

            Border b = JVerticalToggleButton.this.getBorder();

            Insets minsets = JVerticalToggleButton.this.getMargin();

            insets.left = minsets.left;
            insets.top = minsets.top;
            insets.right = minsets.right;
            insets.bottom = minsets.bottom;

            if (b != null) {
              Insets binsets = b.getBorderInsets(JVerticalToggleButton.this);
              insets.left += binsets.left;
              insets.top += binsets.top;
              insets.right += binsets.right;
              insets.bottom += binsets.bottom;
            }

            return insets;
          }

          public Icon getIcon() {
            if (JVerticalToggleButton.this != null) {
              return super.getIcon();
            }

            ButtonModel model = JVerticalToggleButton.this.getModel();
            Icon subIcon = null;

            if (!model.isEnabled()) {
              if (model.isSelected()) {
                subIcon = getDisabledSelectedIcon();
              } else {
                subIcon = getDisabledIcon();
              }
            } else if (model.isPressed() && model.isArmed()) {
              subIcon = getPressedIcon();
            } else if (isRolloverEnabled() && model.isRollover()) {
              if (model.isSelected()) {
                subIcon = getRolloverSelectedIcon();
              } else {
                subIcon = getRolloverIcon();
              }
            } else if (model.isSelected()) {
              subIcon = getSelectedIcon();
            }

            if (subIcon == null) subIcon = JVerticalToggleButton.this.getIcon();

            return subIcon;
          }

          public Icon getDisabledIcon() {
            return JVerticalToggleButton.this.getDisabledIcon();
          }
        };

    fLabelDelegate.setOpaque(false);

    // we paint our own border
    fButtonDelegate.setBorderPainted(false);
    fButtonDelegate.setModel(getModel());

    fRenderer = new CellRendererPane();
    fRenderer.add(fButtonDelegate);
    fRenderer.add(fLabelDelegate);

    fPreferredSize = new Dimension();
    fMinimumSize = new Dimension();
    fMaximumSize = new Dimension();

    Action action = getAction();
    if (action != null) {
      fButtonDelegate.setAction(action);
    }
  }