Package javax.swing

Examples of javax.swing.ButtonModel


   * @param newModel
   *            The new action model for this button.
   * @see #getActionModel()
   */
  public void setActionModel(ActionButtonModel newModel) {
    ButtonModel oldModel = getActionModel();

    if (oldModel != null) {
      oldModel.removeChangeListener(this.actionHandler);
      oldModel.removeActionListener(this.actionHandler);
    }

    actionModel = newModel;

    if (newModel != null) {
View Full Code Here


   * Programmatically perform an action "click". This does the same thing as
   * if the user had pressed and released the action area of the button.
   */
  public void doActionClick() {
    Dimension size = getSize();
    ButtonModel actionModel = this.getActionModel();
    actionModel.setArmed(true);
    actionModel.setPressed(true);
    paintImmediately(new Rectangle(0, 0, size.width, size.height));
    try {
      Thread.sleep(100);
    } catch (InterruptedException ie) {
    }
    actionModel.setPressed(false);
    actionModel.setArmed(false);
  }
View Full Code Here

    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    AbstractButton button = (AbstractButton) source;
    ButtonModel model = button.getModel();

    if (button.isSelected()) {

      drawButton(button, g2, Color.LIGHT_GRAY.brighter(), Color.GRAY.brighter(), Color.LIGHT_GRAY, 5);

    }

    Color messageBackground = normalize(UIManager.getColor(IContentDesign.COLOR_MESSAGE_BACKGROUND));
    Color instructionForeground = normalize(UIManager.getColor(IContentDesign.COLOR_INSTRUCTION_FOREGROUND));

    if (model.isArmed()) {

      drawButton(button, g2, messageBackground, instructionForeground, instructionForeground, 3);

    } else if (model.isRollover()) {

      drawButton(button, g2, messageBackground, instructionForeground, instructionForeground, 6);

    }
    g2.dispose();
View Full Code Here

  private static Rectangle textRect = new Rectangle();
  private static Rectangle iconRect = new Rectangle();

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

    String text = layout(b, SwingUtilities2.getFontMetrics(b, g), b
        .getWidth(), b.getHeight());

    clearTextShiftOffset();

    if (!model.isEnabled()) {
      g.setColor(JLAFConstants.LIGHT_GRAY);
      g.fillRoundRect(0, 0, c.getWidth()-1, c.getHeight()-1, 10, 7);
      g.setColor(JLAFConstants.DARK_GRAY);
      g.drawRoundRect(0, 0, c.getWidth()-1, c.getHeight()-1, 9, 5);
    } else if (model.isArmed() && model.isPressed()) {
//      g.setColor(JLAFConstants.INVISIBLE);
//      g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 10, 7);
      g.setColor(JLAFConstants.DARK_GRAY);
      g.drawRoundRect(0, 0, c.getWidth()-1, c.getHeight()-1, 9, 5);
    } else if (model.isRollover() || model.isArmed()) {
//      g.setColor(JLAFConstants.INVISIBLE);
//      g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 10, 7);
      g.setColor(JLAFConstants.LIGHT_GRAY);
      g.drawRoundRect(0, 0, c.getWidth()-1, c.getHeight()-1, 9, 5);
    } else {
View Full Code Here

    }
  }

  protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
    int mnemIndex = b.getDisplayedMnemonicIndex();

    /* Draw the Text */
    if (model.isEnabled()) {
      if (model.isArmed() && model.isPressed()) {
        g.setColor(JLAFConstants.BLACK);
      } else if (model.isRollover()) {
        g.setColor(JLAFConstants.DARK_GRAY);
      } else {
        g.setColor(JLAFConstants.DARK_GRAY);
      }
    } else {
View Full Code Here

      return 13;
    }
   
    public void paintIcon(Component c, Graphics g, int x, int y) {
      g.translate(x, y);
      ButtonModel model = ((JCheckBox)c).getModel();
      int controlSize = getControlSize();
     
      Graphics2D g2d = (Graphics2D)g;
     
      if (model.isEnabled()) {
        if (model.isPressed() && model.isArmed()) {
          g2d.setColor(JLAFConstants.DARK_GRAY);
          g2d.draw(border);
          g2d.setColor(JLAFConstants.GRAY);
          g2d.setClip(border);
          g2d.fillRect(1, 1, controlSize-1, controlSize-1);
          g2d.setClip(null);
          g2d.setColor(JLAFConstants.BLACK);
        } else if(model.isRollover()) {
          g2d.setColor(JLAFConstants.LIGHT_GRAY);
          g2d.draw(border);
          g2d.setClip(border);
          g2d.fillRect(1, 1, controlSize-1, controlSize-1);
          g2d.setClip(null);
          g2d.setColor(JLAFConstants.BLACK);
        } else {
          g2d.setColor(JLAFConstants.BLACK);
          g2d.draw(border);
          g2d.setColor(c.getForeground());
        }
      } else {
        g2d.setColor(JLAFConstants.GRAY);
        g2d.draw(border);
        g2d.setColor(JLAFConstants.GRAY);
      }
     
      if (model.isSelected()) {
        drawCheck(g2d, 3, 5);
      }
      g.translate(-x, -y);
    }
View Full Code Here

    private static final int controlSize = 13;
   
   
    public void paintIcon(Component c, Graphics g, int x, int y) {
      JRadioButton rb = (JRadioButton)c;
      ButtonModel model = rb.getModel();
     
      g.translate(x, y);
     
     
      if (model.isEnabled()) {
        if(model.isRollover()) {
          g.setColor(JLAFConstants.DARK_GRAY);
        } else {
          g.setColor(JLAFConstants.LIGHT_GRAY);
        }
      } else {
        g.setColor(JLAFConstants.LIGHT_GRAY);
      }
     
     
      // fill interior
      g.fillRect(2, 1, 8, 3);
      g.fillRect(1, 4, 10, 4);
      g.fillRect(2, 8, 8, 3);
     
     
      // draw Dark Circle (start at top, go clockwise)
      if(model.isEnabled()) {
        g.setColor(JLAFConstants.BLACK);
      } else {
        g.setColor(JLAFConstants.DARK_GRAY);
      }
      g.drawLine( 4, 07, 0);
      g.drawLine( 8, 19, 1);
      g.drawLine(10, 2, 10, 3);
      g.drawLine(11, 4, 11, 7);
      g.drawLine(10, 8, 10, 9);
      g.drawLine( 9,108,10);
      g.drawLine( 7,114,11);
      g.drawLine( 3,102,10);
      g.drawLine( 1, 91, 8);
      g.drawLine( 0, 70, 4);
      g.drawLine( 1, 31, 2);
      g.drawLine( 2, 13, 1);
     
      // selected dot
      if (model.isSelected()) {
        if(model.isEnabled()) {
          g.setColor(JLAFConstants.BLACK);
        } else {
          g.setColor(JLAFConstants.DARK_GRAY);
        }
        g.fillRect( 4, 44, 4);
View Full Code Here

  static private final int xOff = 4;
 
  private static class MenuArrowIcon implements Icon, UIResource, Serializable {
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      JMenuItem b = (JMenuItem) c;
      ButtonModel model = b.getModel();
     
      g.translate( x, y );
     
      if ( !model.isEnabled() ) {
        g.setColor(JLAFConstants.GRAY);
      } else {
        if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) {
          g.setColor(JLAFConstants.WHITE);
        } else {
          g.setColor( b.getForeground() );
        }
      }
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.