Package javax.swing

Examples of javax.swing.ButtonModel


            return this.component;
        }
       
        public GeneralPlatformInstall getInstaller () {
            SelectorPanel c = getComponent ();
            ButtonModel bm = c.group.getSelection();
            if (bm != null) {           
                return c.installersByButtonModels.get(bm);
            }
            return null;
        }
View Full Code Here


        }

        @Override
        public void paintIcon(Component c, Graphics g, int x, int y) {
            JCheckBox cb = (JCheckBox) c;
            ButtonModel model = cb.getModel();

            // TODO fix up for Nimbus LAF
            if (model.isEnabled()) {
                if (model.isPressed() && model.isArmed()) {
                    g.setColor(MetalLookAndFeel.getControlShadow());
                    g.fillRect(x, y, iconWidth - 1, iconHeight - 1);
                    drawPressed3DBorder(g, x, y, iconWidth, iconHeight);
                } else {
                    drawFlush3DBorder(g, x, y, iconWidth, iconHeight);
View Full Code Here

    }

    @Override
    public void paint(Graphics g, JComponent c) {
        AbstractButton b = (AbstractButton) c;
        ButtonModel model = b.getModel();

        FontMetrics fm = g.getFontMetrics();

        Insets i = c.getInsets();

        viewRect.x = i.left;
        viewRect.y = i.top;
        viewRect.width = b.getWidth() - (i.right + viewRect.x);
        viewRect.height = b.getHeight() - (i.bottom + viewRect.y);

        textRect.x = textRect.y = textRect.width = textRect.height = 0;
        iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;

        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());

        clearTextShiftOffset();

        // perform UI specific press action, e.g. Windows L&F shifts text
        if (model.isArmed() && model.isPressed()) {
            paintButtonPressed(g, b);
        }

        // Paint the Icon
        if (b.getIcon() != null) {
View Full Code Here

      setSize( d );
    }
   
    protected void setArmed( boolean b )
    {
      final ButtonModel  m = getModel();
      m.setArmed( b );
      repaint();
    }
View Full Code Here

    // to avoid lnf border painting
    // which is happening despite setting our own border
    public void paintComponent( Graphics g )
    {
      final Icon      icn;
      final ButtonModel  m;
   
      if( isEnabled() ) {
        m = getModel();
        if( m.isPressed() ) {
          icn = icnPressed;
        } else if( m.isArmed() ) {
          icn = icnOver;
        } else {
          icn = icnNormal;
        }
      } else {
View Full Code Here

      this.b    = b;
    }
   
    public void actionPerformed( ActionEvent e )
    {
      final ButtonModel bm = b.getModel();
      if( bm.isPressed() != onOff ) bm.setPressed( onOff );
      if( bm.isArmed()   != onOff ) bm.setArmed(   onOff );
    }
View Full Code Here

        return ui;
    }

    protected void paintText(Graphics g, JComponent com, Rectangle rect, String s) {
        XBayaLinkButton bn = (XBayaLinkButton) com;
        ButtonModel bnModel = bn.getModel();
        if (bnModel.isEnabled()) {
            if (bnModel.isPressed())
                bn.setForeground(bn.getActiveLinkColor());
            else if (bn.isLinkVisited())
                bn.setForeground(bn.getVisitedLinkColor());

            else
                bn.setForeground(bn.getLinkColor());
        } else {
            if (bn.getDisabledLinkColor() != null)
                bn.setForeground(bn.getDisabledLinkColor());
        }
        super.paintText(g, com, rect, s);
        int behaviour = bn.getLinkBehavior();
        boolean drawLine = false;
        if (behaviour == XBayaLinkButton.HOVER_UNDERLINE) {
            if (bnModel.isRollover())
                drawLine = true;
        } else if (behaviour == XBayaLinkButton.ALWAYS_UNDERLINE || behaviour == XBayaLinkButton.SYSTEM_DEFAULT)
            drawLine = true;
        if (!drawLine)
            return;
        FontMetrics fm = g.getFontMetrics();
        int x = rect.x + getTextShiftOffset();
        int y = (rect.y + fm.getAscent() + fm.getDescent() + getTextShiftOffset()) - 1;
        if (bnModel.isEnabled()) {
            g.setColor(bn.getForeground());
            g.drawLine(x, y, (x + rect.width) - 1, y);
        } else {
            g.setColor(bn.getBackground().brighter());
            g.drawLine(x, y, (x + rect.width) - 1, y);
View Full Code Here

    paintState(g, x, y);
    super.paintIcon(c, g, x, y);
  }

  private void paintState(Graphics g, int x, int y) {
    ButtonModel model = menuItem.getModel();
    //if (!model.isEnabled()) return;

    int w = getIconWidth();
    int h = getIconHeight();

    g.translate(x, y);
    if (model.isSelected() || model.isArmed() /* && model.isPressed()*/) {
      Color background = model.isArmed()
                ? UIManager.getColor("MenuItem.background")
                : UIManager.getColor("ScrollBar.track");
      Color upColor   = UIManager.getColor("controlLtHighlight");
      Color downColor   = UIManager.getColor("controlDkShadow");

      // Background
      g.setColor(background);
      g.fillRect(0, 0, w, h);
      // Top and left border
      g.setColor(model.isSelected() ? downColor : upColor);
      g.drawLine(0, 0, w-2, 0);
      g.drawLine(0, 0, 0, h-2);
      // Bottom and right border
      g.setColor(model.isSelected() ? upColor: downColor);
      g.drawLine(0, h-1, w-1, h-1);
      g.drawLine(w-1, 0, w-1, h-1);
    }
    g.translate(-x, -y);
    g.setColor(UIManager.getColor("textText"));
View Full Code Here

    }
  }


  private void paint3D(Graphics g) {
    ButtonModel buttonModel = getModel();
    if (buttonModel.isArmed() && buttonModel.isPressed() || buttonModel.isSelected())
      return;

    int width  = getWidth();
    int height = getHeight();
    if (getDirection() == EAST)
View Full Code Here

     * @return Icon or null if there is no icon for the button.
     */
    public static Icon getCurrentIcon(final AbstractButton button) {
        Icon icon = null;

        final ButtonModel model = button.getModel();
        if (model.isEnabled()) {
            if (model.isArmed()) {
                icon = button.getPressedIcon();
            } else if (model.isRollover()){
                icon = model.isSelected() ? button.getRolloverSelectedIcon()
                        : button.getRolloverIcon();
            } else if (model.isSelected()) {
                icon = button.getSelectedIcon();
            }
        } else {
            icon = model.isSelected() ? button.getDisabledSelectedIcon()
                    : button.getDisabledIcon();
        }
        if (icon == null) {
            icon = button.getIcon();
        }
View Full Code Here

TOP

Related Classes of javax.swing.ButtonModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.