javax.swing.AbstractButton#putClientProperty ( )源码实例Demo

下面列出了javax.swing.AbstractButton#putClientProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: AbstractToolbarFactory.java
private void configureToolbarButton (AbstractButton item, String containerCtx, String action, ActionProvider provider, Map ctx) {
        item.setFocusable(false);
        item.setName(action);
        item.putClientProperty (KEY_ACTION, action);
        item.setToolTipText(
            provider.getDisplayName(action, containerCtx));
//        item.setToolTipText(provider.getDescription(action, containerCtx));
        int state = ctx == null ? ActionProvider.STATE_VISIBLE :
            provider.getState (action, containerCtx, ctx);
        boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0;
        item.setEnabled(enabled);
        boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
        item.setVisible (visible);
        boolean toggled = (state & ActionProvider.STATE_SELECTED) != 0;
        item.setSelected(toggled);
//        item.setMnemonic(provider.getMnemonic(action, containerCtx));
//        item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
        item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
    }
 
源代码2 项目: netbeans   文件: Mnemonics.java
/**
 * Wrapper for AbstractButton.setMnemonic and JLabel.setDisplayedMnemonic
 * @param item AbstractButton/JLabel
 * @param mnem Mnemonic char to set, latin [a-z,A-Z], digit [0-9], or any VK_ code
 */
private static void setMnemonic(Object item, int mnem) {
    if (isAquaLF()) {
        // there shall be no mnemonics on macosx.
        //#55864
        return;
    }

    if ((mnem >= 'a') && (mnem <= 'z')) {
        mnem = mnem + ('A' - 'a');
    }

    if (item instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) item;
        b.putClientProperty(PROP_MNEMONIC, mnem);
        b.setMnemonic(mnem);
    } else {
        ((JLabel) item).setDisplayedMnemonic(mnem);
    }
}
 
源代码3 项目: pumpernickel   文件: MockComponent.java
/**
 * Temporarily massage this component so it is visible, enabled, unselected,
 * unfocused, etc.
 */
private void storeState(JComponent c) {
	if (c instanceof AbstractButton) {
		AbstractButton b = (AbstractButton) c;
		b.putClientProperty(WAS_SELECTED, new Boolean(b.isSelected()));
		b.putClientProperty(WAS_FOCUS_PAINTED, new Boolean(b.isSelected()));
		b.setSelected(false);
		b.setFocusPainted(false);
	}
	if (c.isEnabled() == false) {
		c.putClientProperty(WAS_ENABLED, new Boolean(c.isEnabled()));
		c.setEnabled(true);
	}
	if (c.isVisible() == false) {
		c.putClientProperty(WAS_VISIBLE, new Boolean(c.isVisible()));
		c.setVisible(true);
	}
	for (int a = 0; a < c.getComponentCount(); a++) {
		if (c.getComponent(a) instanceof JComponent) {
			storeState((JComponent) c.getComponent(a));
		}
	}
}
 
源代码4 项目: pumpernickel   文件: QButtonUI.java
@Override
public void uninstallUI(JComponent c) {
	super.uninstallUI(c);
	AbstractButton button = (AbstractButton) c;
	ButtonInfo i = getButtonInfo(button, false);
	button.getModel().removeChangeListener(i.buttonStateListener);
	if (i != null) {
		button.removePropertyChangeListener(PROPERTY_BOOLEAN_BUTTON_STATE,
				i.booleanStateListener);
		button.removePropertyChangeListener(PROPERTY_HORIZONTAL_POSITION,
				i.refreshBorderListener);
		button.removePropertyChangeListener(PROPERTY_VERTICAL_POSITION,
				i.refreshBorderListener);
		button.removePropertyChangeListener(PROPERTY_STROKE_PAINTED,
				i.refreshBorderListener);
		button.removePropertyChangeListener(PROPERTY_IS_CIRCLE,
				i.refreshBorderListener);
	}
	button.removeKeyListener(focusArrowListener);
	button.putClientProperty(PROPERTY_BUTTON_INFO, null);
	buttons.remove(button);
}
 
源代码5 项目: FlatLaf   文件: FlatFileChooserUI.java
private void patchUI( JFileChooser fc ) {
	// turn top-right buttons into toolbar buttons
	Component topPanel = fc.getComponent( 0 );
	if( (topPanel instanceof JPanel) &&
		(((JPanel)topPanel).getLayout() instanceof BorderLayout) )
	{
		Component topButtonPanel = ((JPanel)topPanel).getComponent( 0 );
		if( (topButtonPanel instanceof JPanel) &&
			(((JPanel)topButtonPanel).getLayout() instanceof BoxLayout) )
		{
			Insets margin = UIManager.getInsets( "Button.margin" );
			Component[] comps = ((JPanel)topButtonPanel).getComponents();
			for( int i = comps.length - 1; i >= 0; i-- ) {
				Component c = comps[i];
				if( c instanceof JButton || c instanceof JToggleButton ) {
					AbstractButton b = (AbstractButton)c;
					b.putClientProperty( FlatClientProperties.BUTTON_TYPE,
						FlatClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON );
					b.setMargin( margin );
					b.setFocusable( false );
				} else if( c instanceof Box.Filler )
					((JPanel)topButtonPanel).remove( i );
			}
		}
	}

	// increase maximum row count of directory combo box popup list
	try {
		Component directoryComboBox =  ((JPanel)topPanel).getComponent( 2 );
		if( directoryComboBox instanceof JComboBox ) {
			int maximumRowCount = UIManager.getInt( "ComboBox.maximumRowCount" );
			if( maximumRowCount > 0 )
				((JComboBox<?>)directoryComboBox).setMaximumRowCount( maximumRowCount );
		}
	} catch( ArrayIndexOutOfBoundsException ex ) {
		// ignore
	}
}
 
源代码6 项目: netbeans   文件: Mnemonics.java
/**
 * Wrapper for the
 * <code>AbstractButton.setMnemonicIndex</code> or
 * <code>JLabel.setDisplayedMnemonicIndex</code> method.
 * @param item AbstractButton/JLabel or subclasses
 * @param index Index of the Character to underline under JDK1.4
 * @param latinCode Latin Character Keycode to underline under JDK1.3
 */
private static void setMnemonicIndex(Object item, int index) {
    if (item instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) item;
        b.putClientProperty(PROP_DISPLAYED_MNEMONIC_INDEX, index);
        b.removePropertyChangeListener(PROP_DISPLAYED_MNEMONIC_INDEX, MNEMONIC_INDEX_LISTENER);
        b.setDisplayedMnemonicIndex(index);
        b.addPropertyChangeListener(PROP_DISPLAYED_MNEMONIC_INDEX, MNEMONIC_INDEX_LISTENER);
    } else if (item instanceof JLabel) {
        ((JLabel) item).setDisplayedMnemonicIndex(index);
    }
}
 
源代码7 项目: netbeans   文件: Mnemonics.java
/**
 * Wrapper for AbstractButton/JLabel.setText
 * @param item AbstractButton/JLabel
 * @param text the text to set
 */
private static void setText(Object item, String text) {
    if (item instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) item;
        b.putClientProperty(PROP_TEXT, text);
        b.setText(text);
    } else {
        ((JLabel) item).setText(text);
    }
}
 
源代码8 项目: pumpernickel   文件: NavigationButtons.java
public static void formatPrev(AbstractButton button) {
	button.setIcon(createIcon(false, .75f));
	button.setRolloverIcon(createIcon(false, .85f));
	button.setSelectedIcon(createIcon(false, 1f));
	button.setDisabledIcon(createIcon(false, .3f));
	button.setUI(new BevelButtonUI());
	button.setContentAreaFilled(true);
	button.putClientProperty("JButton.segmentPosition", "first");
	button.setBorderPainted(true);
}
 
源代码9 项目: pumpernickel   文件: NavigationButtons.java
public static void formatNext(AbstractButton button) {
	button.setIcon(createIcon(true, .75f));
	button.setRolloverIcon(createIcon(true, .85f));
	button.setSelectedIcon(createIcon(true, 1f));
	button.setDisabledIcon(createIcon(true, .3f));
	button.setUI(new BevelButtonUI());
	button.setContentAreaFilled(true);
	button.putClientProperty("JButton.segmentPosition", "last");
	button.setBorderPainted(true);
}
 
源代码10 项目: pumpernickel   文件: MockComponent.java
/** 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));
		}
	}
}
 
源代码11 项目: snap-desktop   文件: ToolButtonFactory.java
private static void configure(AbstractButton button) {

        RolloverButtonEventListener l = new RolloverButtonEventListener();
        button.addMouseListener(l);
        button.addItemListener(l);

        if (button.getAction() != null) {
            if (button.getIcon() != null) {
                button.putClientProperty("hideActionText", Boolean.TRUE);
            }
            Object largeIcon = button.getAction().getValue("_largeIcon");
            if (largeIcon instanceof Icon) {
                button.setIcon((Icon) largeIcon);
            }
        }

        Icon icon = button.getIcon();
        int minWidth = BUTTON_MIN_SIZE;
        int minHeight = BUTTON_MIN_SIZE;
        if (icon != null) {
            button.setText(null);
            minWidth = Math.max(icon.getIconWidth(), BUTTON_MIN_SIZE);
            minHeight = Math.max(icon.getIconHeight(), BUTTON_MIN_SIZE);
            if (icon instanceof ImageIcon) {
                button.setRolloverIcon(createRolloverIcon((ImageIcon) icon));
            }
        } else {
            button.setText("[?]");
        }
        final int space = 3;
        Dimension prefSize = new Dimension(minWidth + space, minHeight + space);
        Dimension minSize = new Dimension(minWidth, minHeight);
        Dimension maxSize = new Dimension(minWidth + space, minHeight + space);
        button.setPreferredSize(prefSize);
        button.setMaximumSize(maxSize);
        button.setMinimumSize(minSize);

    }
 
源代码12 项目: pumpernickel   文件: QButtonUI.java
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;
}
 
源代码13 项目: Zettelkasten   文件: Tools.java
public static AbstractButton makeTexturedToolBarButton(AbstractButton button, String segmentPosition) {
    if (null == segmentPosition || segmentPosition.isEmpty() || segmentPosition.equals(SEGMENT_POSITION_ONLY)) {
        button.putClientProperty("JButton.buttonType", "textured");
    } else {
        button.putClientProperty("JButton.buttonType", "segmentedTextured");
        button.putClientProperty("JButton.segmentPosition", segmentPosition);
    }
    button.setText(null);
    button.setBorderPainted(true);
    button.setPreferredSize(Constants.seaGlassButtonDimension);
    return button;
}
 
源代码14 项目: netbeans   文件: Actions.java
/** Connects buttons to action. If the action supplies value for "iconBase"
 * key from getValue(String) with a path to icons, the methods set*Icon
 * will be called on the
 * button with loaded icons using the iconBase. E.g. if the value for "iconBase"
 * is "com/mycompany/myIcon.gif" then the following images are tried
 * <ul>
 *  <li>setIcon with "com/mycompany/myIcon.gif"</li>
 *  <li>setPressedIcon with "com/mycompany/myIcon_pressed.gif"</li>
 *  <li>setDisabledIcon with "com/mycompany/myIcon_disabled.gif"</li>
 *  <li>setRolloverIcon with "com/mycompany/myIcon_rollover.gif"</li>
 *  <li>setSelectedIcon with "com/mycompany/myIcon_selected.gif"</li>
 *  <li>setRolloverSelectedIcon with "com/mycompany/myIcon_rolloverSelected.gif"</li>
 *  <li>setDisabledSelectedIcon with "com/mycompany/myIcon_disabledSelected.gif"</li>
 * </ul>
 * SystemAction has special support for iconBase - please check
 * {@link SystemAction#iconResource} for more details.
 * You can supply an alternative implementation
 * for this method by implementing method
 * {@link ButtonActionConnector#connect(AbstractButton, Action)} and
 * registering an instance of {@link ButtonActionConnector} in the
 * default lookup.
 * @param button the button
 * @param action the action
 * @since 3.29
 * @since 7.32 for set*SelectedIcon
 */
public static void connect(AbstractButton button, Action action) {
    for (ButtonActionConnector bac : buttonActionConnectors()) {
        if (bac.connect(button, action)) {
            return;
        }
    }
    Bridge b;
    if (action instanceof BooleanStateAction) {
        b = new BooleanButtonBridge(button, (BooleanStateAction)action);
    } else if (action.getValue(Actions.ACTION_VALUE_TOGGLE) != null) {
        b = new BooleanButtonBridge(button, action);
    } else {
        b = new ButtonBridge(button, action);
    }
    b.prepare();
    button.putClientProperty(DynamicMenuContent.HIDE_WHEN_DISABLED, action.getValue(DynamicMenuContent.HIDE_WHEN_DISABLED));
}
 
源代码15 项目: netbeans   文件: TransparentToolBar.java
public void mouseEntered(MouseEvent e) {
    AbstractButton b = (AbstractButton) e.getSource();
    b.putClientProperty(PROP_HOVERED, Boolean.TRUE);
    refresh(b);
}
 
源代码16 项目: netbeans   文件: TransparentToolBar.java
public void mouseExited(MouseEvent e) {
    AbstractButton b = (AbstractButton) e.getSource();
    b.putClientProperty(PROP_HOVERED, Boolean.FALSE);
    refresh(b);
}
 
源代码17 项目: visualvm   文件: TransparentToolBar.java
public void mouseEntered(MouseEvent e) {
    AbstractButton b = (AbstractButton) e.getSource();
    b.putClientProperty(PROP_HOVERED, Boolean.TRUE);
    refresh(b);
}
 
源代码18 项目: visualvm   文件: TransparentToolBar.java
public void mouseExited(MouseEvent e) {
    AbstractButton b = (AbstractButton) e.getSource();
    b.putClientProperty(PROP_HOVERED, Boolean.FALSE);
    refresh(b);
}
 
源代码19 项目: visualvm   文件: TransparentToolBar.java
public void mouseEntered(MouseEvent e) {
    AbstractButton b = (AbstractButton) e.getSource();
    b.putClientProperty(PROP_HOVERED, Boolean.TRUE);
    refresh(b);
}
 
源代码20 项目: visualvm   文件: TransparentToolBar.java
public void mouseExited(MouseEvent e) {
    AbstractButton b = (AbstractButton) e.getSource();
    b.putClientProperty(PROP_HOVERED, Boolean.FALSE);
    refresh(b);
}