Java 8 ButtonModel - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ButtonModel class.

This code example shows how to use the following methods:setSelected
    /** 
     * Adds a button model 
     * @param model The button model to add 
     */ 
    public final void addButtonModel(ButtonModel model) {
        if (model != null && !buttonModels.contains(model)) {
            buttonModels.add(model);
            model.setSelected(isSelected());
        } 
    } 
 
    /** 
     * Removes a button model 
     * @param model The button model to remove 
     */ 
    public final void removeButtonModel(ButtonModel model) {
        if (model != null && buttonModels.contains(model)) {
            buttonModels.remove(model);
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:isArmed, isEnabled, isPressed, isSelected, setPressed
		/* 
		 * (non-Javadoc) 
		 */ 
		public boolean isArmed() 
		{ 
			return delegate.isArmed();
		} 
 
		/* 
		 * (non-Javadoc) 
		 */ 
		public boolean isEnabled() 
		{ 
			return delegate.isEnabled();
		} 
 
		/** 
		 * Determines whether the selection state is set to be partially selected. 
		 * 
		 * @return <code>true</code> if the selection is set as partially selected or 

5
CodeRank
This code example shows how to use the following methods:setArmed, setEnabled, setPressed, setRollover, setSelected
			if (!component.isEnabled())
				return; 
			boolean isInside = this.trackableUI.isInside(e);
			// boolean isInsideChanged = (this.isMouseInside != isInside); 
			this.isMouseInside = isInside;
			this.model.setRollover(this.isMouseInside);
			this.model.setPressed(false);
			this.model.setArmed(false);
			this.model.setSelected(false);
			this.model.setEnabled(component.isEnabled());
		} finally { 
			this.stateTransitionTracker.onModelStateChanged();
		} 
	} 
 
	/* 
	 * (non-Javadoc) 
	 *  
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) 
	 */ 
5
CodeRank
This code example shows how to use the following methods:isArmed, isEnabled
        // source with the destination, and thus transparent pixels in the 
        // destination, remain transparent. 
        graphics.setComposite(AlphaComposite.SrcAtop);
 
        // set the mask color based on the button models state. 
        if (!model.isEnabled()) {
            graphics.setColor(DISABLED_BUTTON_MASK_COLOR);
        } else if (model.isArmed()) {
            graphics.setColor(PRESSED_BUTTON_MASK_COLOR);
        } else { 
            graphics.setColor(new Color(0, 0, 0, 0));
        } 
 
        // fill a rectangle with the mask color. 
        graphics.fillRect(0, 0, iconRect.width, iconRect.height);
 
        graphics.dispose();
        g.drawImage(image, iconRect.x, iconRect.y, null);
    } 
 
5
CodeRank
This code example shows how to use the following methods:isArmed, isEnabled, isPressed, isSelected
	private static final long serialVersionUID = -7415345504361964833L;
 
	public void paintIcon(Component c, Graphics g, int x, int y) {
		JMenuItem b = (JMenuItem) c;
		ButtonModel model = b.getModel();
		boolean isSelected = model.isSelected();
		boolean isEnabled = model.isEnabled();
		boolean isPressed = model.isPressed();
		boolean isArmed = model.isArmed();
		 
		g.translate(x, y);
		if (isEnabled) {
			if (isPressed || isArmed) {
				drawCircles(g, new ColorUIResource(250, 250, 250), new ColorUIResource(162, 188, 241), new ColorUIResource(206, 220, 245));
			} else { 
				drawCircles(g, new ColorUIResource(150, 150, 150), new ColorUIResource(230, 230, 230), new ColorUIResource(190, 190, 190));
			} 
		} else { 
			drawCircles(g, new ColorUIResource(160, 160, 160), new ColorUIResource(210, 210, 210), new ColorUIResource(190, 190, 190));
		} 

5
CodeRank
This code example shows how to use the following methods:isArmed, isSelected
 
		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 

4
CodeRank
This code example shows how to use the following methods:isSelected
			addBorderState(BorderEdge.WEST.value());
		} 
		if (north.isSelected()) {
			addBorderState(BorderEdge.NORTH.value());
		} 
		if (east.isSelected()) {
			addBorderState(BorderEdge.EAST.value());
		} 
		if (south.isSelected()) {
			addBorderState(BorderEdge.SOUTH.value());
		} 
	} 
	 
    private byte translateEdgeToState(BorderEdge t) {
    	 
		state = BorderEdge.NONE.value();
    	if (t == BorderEdge.WEST) {
    		state = BorderEdge.WEST.value();
    	} else { 
    		if (t == BorderState.BorderEdge.NORTH) {
3
CodeRank
This code example shows how to use the following methods:addActionListener, setSelected
    protected ButtonModel model;
 
    public ToggleButtonListener(ActionW action, boolean selected) {
        super(action);
        model = new ToggleButtonModel();
        model.setSelected(selected);
        model.addActionListener(this);
    } 
 
    @Override 
    public void enableAction(boolean enabled) {
        model.setEnabled(enabled);
    } 
 
    @Override 
    public String toString() {
        return action.getTitle(); 
    } 
 
    @Override 
4
CodeRank
This code example shows how to use the following methods:isSelected
 
        /** 
         * Draws the check mark if {@link ButtonModel#isSelected} returns true. 
         */ 
        private void drawCheckMarkIfNecessary(Graphics2D graphics, ButtonModel model) {
            if (model.isSelected()) {
                drawCheckMark(graphics, model);
            } 
        } 
 
        /** 
         * Draws the check in the check box using the appropriate color based on the 
         * {@link ButtonModel#isPressed} state. Note that part of the check will be drawn outside 
         * it's bounds. Because this icon is actually being drawn inside a larger component (a 
         * {@link javax.swing.JCheckBox}), this shouldn't be an issue. 
         */ 
        private void drawCheckMark(Graphics2D graphics, ButtonModel model) {
            int x1 = CHECK_BOX_SIZE / 4;
            int y1 = CHECK_BOX_SIZE / 3;
            int x2 = x1 + CHECK_BOX_SIZE / 6;
3
CodeRank
This code example shows how to use the following methods:isArmed, isPressed, isRollover
 
		String text = layout(b, g.getFontMetrics(), b.getWidth(), b.getHeight());
 
		clearTextShiftOffset(); 
 
		if (model.isArmed() && model.isPressed()) {
			paintButtonPressed(g, b);
		} else if (b.isRolloverEnabled() && model.isRollover()) {
			paintButtonPressed(g, b);
		} 
 
		if (b.getIcon() != null) {
			paintIcon(g, c, iconRect);
		} 
 
		if (b.isFocusPainted() && b.isFocusOwner()) {
			paintFocus(g, b, viewRect, textRect, iconRect);
			if (iconRect != null && iconRect.width > 0 && iconRect.height > 0) {
				if (b.getIcon() != null) {
					paintIcon(g, c, iconRect);
4
CodeRank
See Code Examples for Java 8 ButtonModel Methods: