类javax.swing.ButtonModel源码实例Demo

下面列出了怎么用javax.swing.ButtonModel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: FlatLaf   文件: FlatToggleButtonUI.java
@Override
protected Color getBackground( JComponent c ) {
	ButtonModel model = ((AbstractButton)c).getModel();

	if( model.isSelected() ) {
		// in toolbar use same colors for disabled and enabled because
		// we assume that toolbar icon is shown disabled
		boolean toolBarButton = isToolBarButton( c );
		return buttonStateColor( c,
			toolBarButton ? toolbarSelectedBackground : selectedBackground,
			toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
			null, null,
			toolBarButton ? toolbarPressedBackground : pressedBackground );
	}

	return super.getBackground( c );
}
 
源代码2 项目: FlatLaf   文件: FlatButtonUI.java
protected Color getBackground( JComponent c ) {
	if( !c.isEnabled() )
		return disabledBackground;

	// toolbar button
	if( isToolBarButton( c ) ) {
		ButtonModel model = ((AbstractButton)c).getModel();
		if( model.isPressed() )
			return toolbarPressedBackground;
		if( model.isRollover() )
			return toolbarHoverBackground;

		// use background of toolbar
		return c.getParent().getBackground();
	}

	boolean def = isDefaultButton( c );
	return buttonStateColor( c,
		getBackgroundBase( c, def ),
		null,
		isCustomBackground( c.getBackground() ) ? null : (def ? defaultFocusedBackground : focusedBackground),
		def ? defaultHoverBackground : hoverBackground,
		def ? defaultPressedBackground : pressedBackground );
}
 
源代码3 项目: xdm   文件: XDMMenuUI.java
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
	ButtonModel model = menuItem.getModel();
	Color oldColor = g.getColor();
	if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
		paintButtonPressed(g, menuItem);
	} else {
		g.setColor(this.colorBg);
		// g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
		// g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());//(0,
		// 0, gap + 1, menuItem.getHeight());
		// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
		// if (menuItem.getIcon() != null) {
		// int gap = menuItem.getIcon().getIconWidth() + 2;
		// g.setColor(this.darkColor);
		// g.drawLine(gap, 0, gap, menuItem.getHeight());
		// g.setColor(this.lightColor);
		// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
		// }
	}
	g.setColor(oldColor);
}
 
源代码4 项目: xdm   文件: XDMButtonUI.java
public void paint(Graphics g, JComponent c) {
	try {
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
		
		AbstractButton b = (AbstractButton) c;
		ButtonModel bm = b.getModel();
		if (bm.isRollover()) {
			paintButtonRollOver(g2, b);
		} else {
			paintButtonNormal(g2, b);
		}
		super.paint(g2, c);
	} catch (Exception e) {
	}
}
 
源代码5 项目: netbeans   文件: EditMediator.java
public static void register(Project project,
                            AntProjectHelper helper,
                            ReferenceHelper refHelper,
                            ListComponent list,
                            ButtonModel addJar,
                            ButtonModel addLibrary, 
                            ButtonModel addAntArtifact,
                            ButtonModel remove, 
                            ButtonModel moveUp,
                            ButtonModel moveDown, 
                            ButtonModel edit,
                            Document libPath,
                            ClassPathUiSupport.Callback callback) {    
    register(project, helper, refHelper, list, addJar, addLibrary, 
            addAntArtifact, remove, moveUp, moveDown, edit, false, libPath,
            callback);
}
 
源代码6 项目: niftyeditor   文件: FileChooserEditor.java
public String traslateFile() {
    File selected = jFileChooser1.getSelectedFile();
    ButtonModel selection = group.getSelection(); 
    if(selection.equals(absolute.getModel())){
       editedValue= selected.getAbsolutePath();
    }else if (selection.equals(copy.getModel())){
        
        try { 
            File dest = new File(this.copyText.getText()+"//"+selected.getName());
            FileUtils.copyFile(selected, dest);
            editedValue = assets.toURI().relativize(dest.toURI()).getPath();
        } catch (IOException ex) {
            Logger.getLogger(FileChooserEditor.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }else{
          editedValue= createReletive(selected);
    }
    return editedValue;
}
 
源代码7 项目: seaglass   文件: SeaGlassButtonUI.java
/**
 * Returns the Icon to use in painting the button.
 *
 * @param  b the button.
 *
 * @return the icon.
 */
protected Icon getIcon(AbstractButton b) {
    Icon        icon  = b.getIcon();
    ButtonModel model = b.getModel();

    if (!model.isEnabled()) {
        icon = getSynthDisabledIcon(b, icon);
    } else if (model.isPressed() && model.isArmed()) {
        icon = getPressedIcon(b, getSelectedIcon(b, icon));
    } else if (b.isRolloverEnabled() && model.isRollover()) {
        icon = getRolloverIcon(b, getSelectedIcon(b, icon));
    } else if (model.isSelected()) {
        icon = getSelectedIcon(b, icon);
    } else {
        icon = getEnabledIcon(b, icon);
    }

    if (icon == null) {
        return getDefaultIcon(b);
    }

    return icon;
}
 
源代码8 项目: netbeans   文件: MnemonicsTest.java
public void testSetLocalizedTextWithModel() throws Exception {
    ButtonModel m = new DefaultButtonModel();
    JButton b = new JButton();
    Mnemonics.setLocalizedText(b, "Hello &There");
    assertEquals("Hello There", b.getText());
    if( Mnemonics.isAquaLF() ) {
        assertEquals(0, b.getMnemonic());
        assertEquals(-1, b.getDisplayedMnemonicIndex());
    } else {
        assertEquals('T', b.getMnemonic());
        assertEquals(6, b.getDisplayedMnemonicIndex());
    }
    b.setModel(m);
    assertEquals("Hello There", b.getText());
    if( Mnemonics.isAquaLF() ) {
        assertEquals(0, b.getMnemonic());
        assertEquals(-1, b.getDisplayedMnemonicIndex());
    } else {
        assertEquals('T', b.getMnemonic());
        assertEquals(6, b.getDisplayedMnemonicIndex());
    }
}
 
源代码9 项目: netbeans   文件: ProfilerPopup.java
public Component getDefaultComponent(Container aContainer) {
    Component c = getFirstComponent(aContainer);
    
    if (c instanceof AbstractButton) {
        ButtonModel bm = ((AbstractButton)c).getModel();
        if (bm instanceof DefaultButtonModel) {
            ButtonGroup bg = ((DefaultButtonModel)bm).getGroup();
            Enumeration<AbstractButton> en = bg == null ? null : bg.getElements();
            while (en != null && en.hasMoreElements()) {
                AbstractButton ab = en.nextElement();
                if (ab.isSelected()) return ab;
            }
        }
    }
    
    return c;
}
 
源代码10 项目: seaglass   文件: SeaGlassGraphicsUtils.java
static void paintIcon(Graphics g, SeaGlassMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (lh.getIcon() != null) {
        Icon icon;
        JMenuItem mi = lh.getMenuItem();
        ButtonModel model = mi.getModel();
        if (!model.isEnabled()) {
            icon = mi.getDisabledIcon();
        } else if (model.isPressed() && model.isArmed()) {
            icon = mi.getPressedIcon();
            if (icon == null) {
                // Use default icon
                icon = mi.getIcon();
            }
        } else {
            icon = mi.getIcon();
        }

        if (icon != null) {
            Rectangle iconRect = lr.getIconRect();
            SynthIcon.paintIcon(icon, lh.getContext(), g, iconRect.x,
                    iconRect.y, iconRect.width, iconRect.height);
        }
    }
}
 
源代码11 项目: beautyeye   文件: BECheckBoxMenuItemUI.java
public void paintIcon(Component c, Graphics g, int x, int y) 
    	{
    		AbstractButton b = (AbstractButton) c;
    		ButtonModel model = b.getModel();
    		
    		Image selectedImg = __IconFactory__.getInstance().getCheckboxMenuItemSelectedNormalIcon().getImage();
    		boolean isSelected = model.isSelected();
//    		boolean isArmed = model.isArmed();
    		if (isSelected) 
    		{
//    			if(isArmed)
//    				selectedImg = __IconFactory__.getInstance().getCheckboxMenuItemSelectedRoverIcon().getImage();
    		}
    		else
    			selectedImg = __IconFactory__.getInstance().getCheckboxMenuItemNoneIcon().getImage();

    		g.drawImage(selectedImg
    				, x+(usedForVista?5:-4)//* 注意:当用于windows平台专用主类且处于Vista及更高版win时要做不一样的处理哦
    				, y - 3
    				, null);
    	}
 
源代码12 项目: netbeans   文件: PathUiSupport.java
public static void register(PhpProject project, JList<BasePathSupport.Item> list, ButtonModel addFolder,
        ButtonModel remove, ButtonModel moveUp, ButtonModel moveDown,
        FileChooserDirectoryHandler directoryHandler) {

    EditMediator em = new EditMediator(project, list, addFolder, remove, moveUp, moveDown, directoryHandler);

    // Register the listener on all buttons
    addFolder.addActionListener(em);
    remove.addActionListener(em);
    moveUp.addActionListener(em);
    moveDown.addActionListener(em);
    // On list selection
    em.selectionModel.addListSelectionListener(em);
    // Set the initial state of the buttons
    em.valueChanged(null);
}
 
源代码13 项目: netbeans   文件: PathUiSupport.java
public static void register(JList<BasePathSupport.Item> list, ButtonModel addFolder,
        ButtonModel remove, ButtonModel moveUp, ButtonModel moveDown,
        FileChooserDirectoryHandler directoryHandler) {

    EditMediator em = new EditMediator(list, addFolder, remove, moveUp, moveDown, directoryHandler);

    // Register the listener on all buttons
    addFolder.addActionListener(em);
    remove.addActionListener(em);
    moveUp.addActionListener(em);
    moveDown.addActionListener(em);
    // On list selection
    em.selectionModel.addListSelectionListener(em);
    // Set the initial state of the buttons
    em.valueChanged(null);
}
 
源代码14 项目: littleluck   文件: LuckButtonUI.java
public void paint(Graphics g, JComponent c)
{
    AbstractButton b = (AbstractButton) c;

    ButtonModel model = b.getModel();

    paintBg(g, (AbstractButton) c);

    // 设置组件偏移,以达到视觉上的按下和弹起效果
    // Set the component offsets to achieve visual depress and bounce
    if(model.isPressed() && model.isArmed() && b.getIcon() == null)
    {
        g.translate(2, 1);
    }

    super.paint(g, c);

    if(model.isPressed() && model.isArmed() && b.getIcon() == null)
    {
        g.translate(-2, -1);
    }
}
 
源代码15 项目: visualvm   文件: ProfilerPopup.java
public Component getDefaultComponent(Container aContainer) {
    Component c = getFirstComponent(aContainer);
    
    if (c instanceof AbstractButton) {
        ButtonModel bm = ((AbstractButton)c).getModel();
        if (bm instanceof DefaultButtonModel) {
            ButtonGroup bg = ((DefaultButtonModel)bm).getGroup();
            Enumeration<AbstractButton> en = bg == null ? null : bg.getElements();
            while (en != null && en.hasMoreElements()) {
                AbstractButton ab = en.nextElement();
                if (ab.isSelected()) return ab;
            }
        }
    }
    
    return c;
}
 
源代码16 项目: RipplePower   文件: RPCButton.java
private void initImage() {
	setForeground(LColor.black);
	setBackground(LColor.white);
	setContentAreaFilled(true);
	setFocusPainted(false);
	Border line = BorderFactory.createLineBorder(new LColor(80, 80, 80));
	Border empty = new EmptyBorder(4, 4, 4, 4);
	CompoundBorder border = new CompoundBorder(line, empty);
	setBorder(border);

	getModel().addChangeListener(new ChangeListener() {
		@Override
		public void stateChanged(ChangeEvent e) {
			ButtonModel model = (ButtonModel) e.getSource();
			if (model.isRollover()) {
				setBackground(LColor.lightSkyBlue);
			} else if (model.isArmed() || model.isPressed()) {
				setBackground(LColor.lightSkyBlue);
			} else if (model.isSelected()) {
				setBackground(LColor.white);
			} else {
				setBackground(LColor.white);
			}
		}
	});
}
 
源代码17 项目: FlatLaf   文件: FlatMenuUI.java
@Override
protected void paintBackground( Graphics g, Color selectionBackground ) {
	ButtonModel model = menuItem.getModel();
	if( model.isRollover() && !model.isArmed() && !model.isSelected() &&
		model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() )
	{
		g.setColor( deriveBackground( hoverBackground ) );
		g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() );
	} else
		super.paintBackground( g, selectionBackground );
}
 
源代码18 项目: ghidra   文件: MenuItemManager.java
@Override
public void dispose() {
	if (action != null) {
		action.removePropertyChangeListener(this);
	}

	if (menuItem != null) {
		ButtonModel buttonModel = menuItem.getModel();
		buttonModel.removeChangeListener(buttonModelChangeListener);
		menuItem = null;
	}

	action = null;
}
 
源代码19 项目: littleluck   文件: LuckCheckboxIcon.java
public void paintIcon(Component c, Graphics g, int x, int y)
{
    AbstractButton btn = (AbstractButton) c;

    ButtonModel model = btn.getModel();

    Image image = getPreImg(c, model);

    if (image != null)
    {
        g.drawImage(image, x, y, getIconWidth(), getIconHeight(), null);
    }
}
 
源代码20 项目: netbeans   文件: SelectorPanel.java
public GeneralPlatformInstall getInstaller () {
    SelectorPanel c = getComponent ();
    ButtonModel bm = c.group.getSelection();
    if (bm != null) {            
        return c.installersByButtonModels.get(bm);
    }
    return null;
}
 
源代码21 项目: rapidminer-studio   文件: RapidLookTools.java
public static void drawMenuItemBackground(Graphics g, JMenuItem menuItem) {
	Color oldColor = g.getColor();
	ButtonModel model = menuItem.getModel();
	int w = menuItem.getWidth();
	int h = menuItem.getHeight();

	if (model.isArmed() || model.isSelected() && menuItem instanceof JMenu) {
		g.setColor(Colors.MENU_ITEM_BACKGROUND_SELECTED);
		g.fillRect(0, 0, w, h);
	} else if (!(menuItem instanceof JMenu && ((JMenu) menuItem).isTopLevelMenu())) {
		drawMenuItemFading(menuItem, g);
	}
	g.setColor(oldColor);
}
 
源代码22 项目: jpexs-decompiler   文件: NoneSelectedButtonGroup.java
@Override
public void setSelected(ButtonModel model, boolean selected) {
    if (selected) {
        super.setSelected(model, selected);
    } else {
        clearSelection();
    }
}
 
源代码23 项目: RipplePower   文件: RPPopMenuItem.java
public RPPopMenuItem(String name) {
	super(name);
	setForeground(new LColor(255, 255, 255));
	setBackground(new LColor(18, 18, 18));
	setContentAreaFilled(true);
	setFocusPainted(false);
	Border line = BorderFactory.createLineBorder(new LColor(80, 80, 80));
	Border empty = new EmptyBorder(4, 4, 4, 4);
	CompoundBorder border = new CompoundBorder(line, empty);
	setBorder(border);

	getModel().addChangeListener(new ChangeListener() {
		@Override
		public void stateChanged(ChangeEvent e) {
			ButtonModel model = (ButtonModel) e.getSource();
			if (model.isRollover()) {
				setBackground(new LColor(120, 20, 20));
			} else if (model.isArmed() || model.isPressed()) {
				setBackground(new LColor(0, 0, 0));
			} else if (model.isSelected()) {
				setBackground(new LColor(0, 0, 0));
			} else {
				setBackground(new LColor(18, 18, 18));
			}
		}
	});
}
 
源代码24 项目: beautyeye   文件: BEMenuUI.java
public void mouseExited(MouseEvent evt) {
	super.mouseExited(evt);

	JMenu menu = (JMenu)evt.getSource();
	ButtonModel model = menu.getModel();
	if (menu.isRolloverEnabled()) {
		model.setRollover(false);
		menuItem.repaint();
	}
}
 
源代码25 项目: netbeans   文件: FlatSlidingButtonUI.java
@Override
protected void paintButtonPressed(Graphics g, AbstractButton b) {
    if (((SlidingButton) b).isBlinkState()) {
        // background already painted
        return;
    }

    ButtonModel bm = b.getModel();
    g.setColor(bm.isPressed() || bm.isArmed() || bm.isSelected() ? selectedBackground : hoverBackground);
    g.fillRect(0, 0, b.getWidth(), b.getHeight());
}
 
源代码26 项目: beautyeye   文件: __UI__.java
public void paintIcon(Component c, Graphics g, int x, int y) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();

	//选中时
	if(model.isSelected())
	{
		//处于禁用状态
		if(!model.isEnabled())
			g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_disable().getImage(), x, y, null);
		else
		{
			//处于被按住状态
			if(model.isPressed())
				g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_pressed().getImage(), x, y, null);
			else
				g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_normal().getImage(), x, y, null);
		}
	}
	//未选中时
	else
	{
		//处于禁用状态
		if(!model.isEnabled())
			g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_unchecked_disable().getImage(), x, y, null);
		else
		{
			//处于被按住状态
			if(model.isPressed())
				g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_unchecked_pressed().getImage(), x, y, null);
			else
				g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_unchecked_normal().getImage(), x, y, null);
		}
	}
}
 
源代码27 项目: consulo   文件: CheckBox.java
public CheckBox(@Nonnull String label,
                @Nonnull InspectionProfileEntry owner,
                @NonNls String property) {
    super(label, getPropertyValue(owner, property));
    final ButtonModel model = getModel();
    final SingleCheckboxChangeListener listener =
            new SingleCheckboxChangeListener(owner, property, model);
    model.addChangeListener(listener);
}
 
源代码28 项目: snap-desktop   文件: TransferMaskDialog.java
private static Product[] getSelectedProducts(Map<Product, ButtonModel> buttonMap) {
    List<Product> selectedProducts = new ArrayList<Product>(buttonMap.size());
    for (Map.Entry<Product, ButtonModel> entry : buttonMap.entrySet()) {
        Product product = entry.getKey();
        ButtonModel buttonModel = entry.getValue();
        if (buttonModel.isSelected()) {
            selectedProducts.add(product);
        }
    }
    return selectedProducts.toArray(new Product[selectedProducts.size()]);
}
 
源代码29 项目: stendhal   文件: StyledButtonUI.java
@Override
public void paint(Graphics graphics, JComponent button) {
	paintBackground(graphics, button);

	// Restore normal look after pressing ends, if needed
	if (button instanceof AbstractButton) {
		ButtonModel model = ((AbstractButton) button).getModel();
		if (!model.isPressed()) {
			// Try to avoid switching borders if the button has none or custom
			// borders
			if (button.getBorder().equals(style.getBorderDown())) {
				button.setBorder(style.getBorder());
			}
		}
		if (model.isRollover()) {
			hilite(graphics, button);
		}

		if (button instanceof JButton) {
			if (((JButton) button).isDefaultButton()) {
				Insets insets = button.getInsets();
				graphics.setColor(style.getShadowColor());
				int width = button.getWidth() - insets.right - insets.left - 3;
				int height = button.getHeight() - insets.top - insets.bottom - 3;
				graphics.drawRect(insets.left + 1, insets.right + 1, width, height);
			}
		}
	}

	super.paint(graphics, button);
}
 
源代码30 项目: beautyeye   文件: BERadioButtonMenuItemUI.java
/**
     * Draws the background of the menu item.
     * 
     * @param g the paint graphics
     * @param menuItem menu item to be painted
     * @param bgColor selection background color
     * @since 1.4
     */
    protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) 
    {
    	ButtonModel model = menuItem.getModel();
    	Color oldColor = g.getColor();
    	int menuWidth = menuItem.getWidth();
    	int menuHeight = menuItem.getHeight();

    	if(menuItem.isOpaque()) 
    	{
    		if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) 
    		{
    			g.setColor(bgColor);
    			g.fillRect(0,0, menuWidth, menuHeight);
    		} 
    		else 
    		{
    			g.setColor(menuItem.getBackground());
    			g.fillRect(0,0, menuWidth, menuHeight);
    		}
    		g.setColor(oldColor);
    	}
    	else if (model.isArmed() || (menuItem instanceof JMenu &&
    			model.isSelected())) 
    	{
//    		g.setColor(bgColor);
//    		g.fillRect(0,0, menuWidth, menuHeight);
//    		g.setColor(oldColor);
    		
    		//由jb2011改用NinePatch图来填充
			__Icon9Factory__.getInstance().getBgIcon_ItemSelected()
				.draw((Graphics2D)g, 0, 0, menuWidth, menuHeight);
    	}
    }
 
 类所在包
 同包方法