Package javax.swing

Examples of javax.swing.ButtonModel


    static void paint(SeaGlassContext context, SeaGlassContext accContext, Graphics g, Icon checkIcon, Icon arrowIcon,
        boolean useCheckAndArrow, String acceleratorDelimiter, int defaultTextIconGap) {
        JComponent c = context.getComponent();
        JMenuItem b = (JMenuItem) c;
        ButtonModel model = b.getModel();
        Insets i = b.getInsets();

        resetRects();

        viewRect.setBounds(0, 0, b.getWidth(), b.getHeight());

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

        SynthStyle style = context.getStyle();
        Font f = style.getFont(context);
        g.setFont(f);
        FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
        FontMetrics accFM = SwingUtilities2.getFontMetrics(c, g, accContext.getStyle().getFont(accContext));

        // get Accelerator text
        KeyStroke accelerator = b.getAccelerator();
        String acceleratorText = "";
        if (accelerator != null) {
            int modifiers = accelerator.getModifiers();
            if (modifiers > 0) {
                acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
                acceleratorText += acceleratorDelimiter;
            }

            int keyCode = accelerator.getKeyCode();
            if (keyCode != 0) {
                acceleratorText += KeyEvent.getKeyText(keyCode);
            } else {
                acceleratorText += accelerator.getKeyChar();
            }
        }

        // layoutl the text and icon
        String text = layoutMenuItem(context, fm, accContext, b.getText(), accFM, acceleratorText, b.getIcon(), checkIcon, arrowIcon, b
            .getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect,
            iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, b.getText() == null ? 0 : defaultTextIconGap,
            defaultTextIconGap, useCheckAndArrow);

        // Paint the Check
        if (checkIcon != null && useCheckAndArrow) {
            SeaGlassIcon.paintIcon(checkIcon, context, g, checkIconRect.x, checkIconRect.y, checkIconRect.width, checkIconRect.height);
        }

        // Paint the Icon
        if (b.getIcon() != null) {
            Icon icon;
            if (!model.isEnabled()) {
                icon = (Icon) b.getDisabledIcon();
            } else if (model.isPressed() && model.isArmed()) {
                icon = (Icon) b.getPressedIcon();
                if (icon == null) {
                    // Use default icon
                    icon = (Icon) b.getIcon();
                }
View Full Code Here


    }
  }

  public String getValue()
  {
    ButtonModel selection = buttonGroup.getSelection();
    return selection == null ? null : selection.getActionCommand();
  }
View Full Code Here

    isGroupSelectionFollowFocus = groupSelectionFollowFocus;
  }

  private static ButtonGroup getButtonGroup( AbstractButton button )
  {
    ButtonModel model = button.getModel();
    if( model instanceof DefaultButtonModel )
    {
      return ( ( DefaultButtonModel )model ).getGroup();
    }
    return null;
View Full Code Here

        public ArrayList<Boolean> states = new ArrayList<Boolean>();

        public void stateChanged(ChangeEvent e) {
            events.add(e);
            ButtonModel model = (ButtonModel) e.getSource();
            states.add(Boolean.valueOf(model.isPressed()));
            states.add(Boolean.valueOf(model.isArmed()));
        }
View Full Code Here

    public void setEditable(boolean editable) {
      if (this.editable != editable) {
        this.editable = editable;
        // Invoke setModel so we set the model to be the correct sort of model
        if (editable) {
          ButtonModel model = getModel();
          if (model instanceof ReadOnlyButtonModel) {
            this.setModel(((ReadOnlyButtonModel)model).getOriginalModel());
          }
        }
        else {
          ButtonModel model = getModel();
          if (!(model instanceof ReadOnlyButtonModel)) {
            this.setModel(new ReadOnlyButtonModel(this, model));
          }
        }
        this.firePropertyChange("editable", !editable, editable);
View Full Code Here

    public void setEditable(boolean editable) {
      if (this.editable != editable) {
        this.editable = editable;
        // Invoke setModel so we set the model to be the correct sort of model
        if (editable) {
          ButtonModel model = getModel();
          if (model instanceof ReadOnlyButtonModel) {
            this.setModel(((ReadOnlyButtonModel)model).getOriginalModel());
          }
        }
        else {
          ButtonModel model = getModel();
          if (!(model instanceof ReadOnlyButtonModel)) {
            this.setModel(new ReadOnlyButtonModel(this, model));
          }
        }
        this.firePropertyChange("editable", !editable, editable);
View Full Code Here

    public class TableJButtonUI extends WindowsButtonUI {

        @Override
        protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
            AbstractButton b = (AbstractButton) c;                          
            ButtonModel model = b.getModel();
            Icon icon = b.getIcon();
            Icon tmpIcon = null;

        if(icon == null) {
            return;
        }

          if(!model.isEnabled()) {
            if(model.isSelected()) {
              tmpIcon = (Icon) b.getDisabledSelectedIcon();
            } else {
              tmpIcon = (Icon) b.getDisabledIcon();
            }
          } else if(model.isPressed() && model.isArmed()) {
            tmpIcon = (Icon) b.getPressedIcon();
            if(tmpIcon != null) {
              // revert back to 0 offset
              clearTextShiftOffset();
            }
          } else if(b.isRolloverEnabled() && model.isRollover()) {
            if(model.isSelected()) {
              tmpIcon = (Icon) b.getRolloverSelectedIcon();
            } else {
              tmpIcon = (Icon) b.getRolloverIcon();
            }
          } else if(model.isSelected()) {
            tmpIcon = (Icon) b.getSelectedIcon();
          }

          if(tmpIcon != null) {
            icon = tmpIcon;
          }
          else {
            // TF:Mar 11, 2010:Changed this to create the transparent icon only if necessary
              int width = icon.getIconWidth();
              int height = icon.getIconHeight();
              BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
              icon.paintIcon(c, buf.createGraphics(),0,0);
              /*
               * for transparent icon
               */
              //PM:25/4/08 move code to common method
              UIutils.transparentImage(buf, UIutils.Gray2);
              icon = new ImageIcon(buf);
          }

          if(model.isPressed() && model.isArmed()) {
            icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(),
                iconRect.y + getTextShiftOffset());
            } else {
                icon.paintIcon(c, g, iconRect.x, iconRect.y);
            }
View Full Code Here

    public void setEditable(boolean editable) {
      if (this.editable != editable) {
        this.editable = editable;
        // Invoke setModel so we set the model to be the correct sort of model
        if (editable) {
          ButtonModel model = getModel();
          if (model instanceof ReadOnlyButtonModel) {
            this.setModel(((ReadOnlyButtonModel)model).getOriginalModel());
          }
        }
        else {
          ButtonModel model = getModel();
          if (!(model instanceof ReadOnlyButtonModel)) {
            this.setModel(new ReadOnlyButtonModel(this, model));
          }
        }
        this.firePropertyChange("editable", !editable, editable);
View Full Code Here

    public void setEditable(boolean editable) {
      if (this.editable != editable) {
        this.editable = editable;
        // Invoke setModel so we set the model to be the correct sort of model
        if (editable) {
          ButtonModel model = getModel();
          if (model instanceof ReadOnlyButtonModel) {
            this.setModel(((ReadOnlyButtonModel)model).getOriginalModel());
          }
        }
        else {
          ButtonModel model = getModel();
          if (!(model instanceof ReadOnlyButtonModel)) {
            this.setModel(new ReadOnlyButtonModel(this, model));
          }
        }
        this.firePropertyChange("editable", !editable, editable);
View Full Code Here

    public class TableJButtonUI extends WindowsButtonUI {

        @Override
        protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
            AbstractButton b = (AbstractButton) c;                          
            ButtonModel model = b.getModel();
            Icon icon = b.getIcon();
            Icon tmpIcon = null;

        if(icon == null) {
            return;
        }

          if(!model.isEnabled()) {
            if(model.isSelected()) {
              tmpIcon = (Icon) b.getDisabledSelectedIcon();
            } else {
              tmpIcon = (Icon) b.getDisabledIcon();
            }
          } else if(model.isPressed() && model.isArmed()) {
            tmpIcon = (Icon) b.getPressedIcon();
            if(tmpIcon != null) {
              // revert back to 0 offset
              clearTextShiftOffset();
            }
          } else if(b.isRolloverEnabled() && model.isRollover()) {
            if(model.isSelected()) {
              tmpIcon = (Icon) b.getRolloverSelectedIcon();
            } else {
              tmpIcon = (Icon) b.getRolloverIcon();
            }
          } else if(model.isSelected()) {
            tmpIcon = (Icon) b.getSelectedIcon();
          }

          if(tmpIcon != null) {
            icon = tmpIcon;
          }
          else {
            // TF:Mar 11, 2010:Changed this to create the transparent icon only if necessary
              int width = icon.getIconWidth();
              int height = icon.getIconHeight();
              BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
              icon.paintIcon(c, buf.createGraphics(),0,0);
              /*
               * for transparent icon
               */
              //PM:25/4/08 move code to common method
              UIutils.transparentImage(buf, UIutils.Gray2);
              icon = new ImageIcon(buf);
          }

          if(model.isPressed() && model.isArmed()) {
            icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(),
                iconRect.y + getTextShiftOffset());
            } else {
                icon.paintIcon(c, g, iconRect.x, iconRect.y);
            }
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.