Java Code Examples for javax.swing.AbstractButton#getClientProperty()

The following examples show how to use javax.swing.AbstractButton#getClientProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractToolbarFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void update (String containerCtx) {
//        System.err.println("ToolbarFactory update " + containerCtx);
        JToolBar tb = (JToolBar) mappings.get(munge(containerCtx));
        synchronized (tb.getTreeLock()) {
    //        System.err.println("Toolbar to update: " + tb);
            ActionProvider provider = getEngine().getActionProvider();
            if (tb != null) {
                Component[] c = tb.getComponents();
                for (int i=0; i < c.length; i++) {
                    if (c[i] instanceof AbstractButton) {
                        AbstractButton b = (AbstractButton) c[i];
                        String action = (String) b.getClientProperty (KEY_ACTION);
                        configureToolbarButton (b, containerCtx, action, provider,
                            getEngine().getContextProvider().getContext());
                    }
                }

            } else {
                System.err.println("Asked to update non existent toolbar " + containerCtx);
            }
        }
    }
 
Example 2
Source File: QButtonUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect,
		String text) {
	// this hack helps us render a button in a different enabled state
	// than what it really is:
	ButtonState.Boolean state = (ButtonState.Boolean) b
			.getClientProperty(PROPERTY_BOOLEAN_BUTTON_STATE);
	if (state != null && state.isEnabled() != b.isEnabled()) {
		scratchButton.setText(b.getText());
		scratchButton.setDisplayedMnemonicIndex(b
				.getDisplayedMnemonicIndex());
		scratchButton.setForeground(b.getForeground());
		scratchButton.setFont(b.getFont());
		scratchButton.setBackground(b.getBackground());
		scratchButton.setEnabled(state.isEnabled());
		super.paintText(g, scratchButton, textRect, text);
		return;
	}
	super.paintText(g, b, textRect, text);
}
 
Example 3
Source File: LuckButtonUI.java    From littleluck with Apache License 2.0 6 votes vote down vote up
/**
 * check if use the default button style.
 *
 * @param b
 * @return default style return true, otherwise return false.
 */
private boolean checkIsPaintBg(AbstractButton b)
{
    if (!b.isContentAreaFilled())
    {
        return false;
    }
    
    Object isPaintBg = b.getClientProperty(LuckButtonUIBundle.IS_PAINTBG);

    if (b.getIcon() != null && isPaintBg == null)
    {
        return false;
    }

    return true;
}
 
Example 4
Source File: Mnemonics.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    AbstractButton b = (AbstractButton) evt.getSource();
    if (b.getDisplayedMnemonicIndex() == -1) {
        Integer mnemonic = (Integer) b.getClientProperty(PROP_MNEMONIC);
        Integer index = (Integer) b.getClientProperty(PROP_DISPLAYED_MNEMONIC_INDEX);
        if (mnemonic != null && index != null && Utilities.compareObjects(b.getText(), b.getClientProperty(PROP_TEXT))) {
            b.setMnemonic(mnemonic);
            b.setDisplayedMnemonicIndex(index);
        }
    }
}
 
Example 5
Source File: MockComponent.java    From pumpernickel with MIT License 5 votes vote down vote up
/** Restore this component back to its original goodness. */
private void restoreState(JComponent c) {
	if (c instanceof AbstractButton) {
		AbstractButton b = (AbstractButton) c;
		if (b.getClientProperty(WAS_SELECTED) != null) {
			b.setSelected(((Boolean) b.getClientProperty(WAS_SELECTED))
					.booleanValue());
			b.putClientProperty(WAS_SELECTED, null);
		}
		if (b.getClientProperty(WAS_FOCUS_PAINTED) != null) {
			b.setFocusPainted(((Boolean) b
					.getClientProperty(WAS_FOCUS_PAINTED)).booleanValue());
			b.putClientProperty(WAS_FOCUS_PAINTED, null);
		}
	}
	if (c.getClientProperty(WAS_ENABLED) != null) {
		c.setEnabled(((Boolean) c.getClientProperty(WAS_ENABLED))
				.booleanValue());
		c.putClientProperty(WAS_ENABLED, null);
	}
	if (c.getClientProperty(WAS_VISIBLE) != null) {
		c.setVisible(((Boolean) c.getClientProperty(WAS_VISIBLE))
				.booleanValue());
		c.putClientProperty(WAS_VISIBLE, null);
	}
	for (int a = 0; a < c.getComponentCount(); a++) {
		if (c.getComponent(a) instanceof JComponent) {
			restoreState((JComponent) c.getComponent(a));
		}
	}
}
 
Example 6
Source File: QButtonUI.java    From pumpernickel with MIT License 5 votes vote down vote up
protected ButtonInfo getButtonInfo(AbstractButton b, boolean createIfMissing) {
	ButtonInfo i = (ButtonInfo) b.getClientProperty(PROPERTY_BUTTON_INFO);
	if (i == null && createIfMissing) {
		i = new ButtonInfo(b);
		b.putClientProperty(PROPERTY_BUTTON_INFO, i);
	}
	return i;
}
 
Example 7
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * Update the style of the button.
 *
 * @param b the button.
 */
public void updateStyle(AbstractButton b) {
    SeaGlassContext context  = getContext(b, SynthConstants.ENABLED);
    SynthStyle      oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);
    if (style != oldStyle) {
        if (b.getMargin() == null || (b.getMargin() instanceof UIResource)) {
            Insets margin = (Insets) style.get(context, getPropertyPrefix() + "margin");

            if (margin == null) {
                // Some places assume margins are non-null.
                margin = SeaGlassLookAndFeel.EMPTY_UIRESOURCE_INSETS;
            }

            b.setMargin(margin);
        }

        Object value = style.get(context, getPropertyPrefix() + "iconTextGap");

        if (value != null) {
            LookAndFeel.installProperty(b, "iconTextGap", value);
        }

        value = style.get(context, getPropertyPrefix() + "contentAreaFilled");
        LookAndFeel.installProperty(b, "contentAreaFilled", value != null ? value : Boolean.TRUE);

        value = b.getClientProperty(APPLE_PREFIX + "buttonType");
        if (value != null) {
            if ("segmented".equals(value)) {
                b.setMargin(SeaGlassLookAndFeel.EMPTY_UIRESOURCE_INSETS);
            }
        }

        if (oldStyle != null) {
            uninstallKeyboardActions(b);
            installKeyboardActions(b);
        }
    }

    context.dispose();
}
 
Example 8
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * @see javax.swing.plaf.basic.BasicButtonUI#getBaseline(javax.swing.JComponent,
 *      int, int)
 */
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }

    if (width < 0 || height < 0) {
        throw new IllegalArgumentException("Width and height must be >= 0");
    }

    AbstractButton b    = (AbstractButton) c;
    String         text = b.getText();

    if (text == null || "".equals(text)) {
        return -1;
    }

    Insets    i        = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();

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

    // layout the text and icon
    SeaGlassContext context = getContext(b);
    FontMetrics     fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));

    context.getStyle().getGraphicsUtils(context).layoutText(context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(),
                                                            b.getVerticalAlignment(), b.getHorizontalTextPosition(),
                                                            b.getVerticalTextPosition(), viewRect, iconRect, textRect,
                                                            b.getIconTextGap());
    View view     = (View) b.getClientProperty(BasicHTML.propertyKey);
    int  baseline;

    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    } else {
        baseline = textRect.y + fm.getAscent();
    }

    context.dispose();
    return baseline;
}
 
Example 9
Source File: ButtonCluster.java    From pumpernickel with MIT License 2 votes vote down vote up
/**
 * Returns the <code>ButtonCluster</code> associated with a button, or
 * <code>null</code> if this button is not part of a cluster.
 */
public static ButtonCluster getCluster(AbstractButton button) {
	return (ButtonCluster) button.getClientProperty(CLUSTER_KEY);
}