Java Code Examples for javax.swing.ButtonModel

The following examples show how to use javax.swing.ButtonModel. These examples are extracted from open source projects. 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 Project: FlatLaf   Source File: FlatToggleButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
@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 );
}
 
Example 2
Source Project: FlatLaf   Source File: FlatButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
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 );
}
 
Example 3
Source Project: xdm   Source File: XDMMenuUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source Project: xdm   Source File: XDMButtonUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
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) {
	}
}
 
Example 5
Source Project: netbeans   Source File: EditMediator.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 6
Source Project: niftyeditor   Source File: FileChooserEditor.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 7
Source Project: seaglass   Source File: SeaGlassButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source Project: netbeans   Source File: MnemonicsTest.java    License: Apache License 2.0 6 votes vote down vote up
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());
    }
}
 
Example 9
Source Project: netbeans   Source File: ProfilerPopup.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 10
Source Project: seaglass   Source File: SeaGlassGraphicsUtils.java    License: Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 11
Source Project: beautyeye   Source File: BECheckBoxMenuItemUI.java    License: Apache License 2.0 6 votes vote down vote up
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);
    	}
 
Example 12
Source Project: netbeans   Source File: PathUiSupport.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 13
Source Project: netbeans   Source File: PathUiSupport.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 14
Source Project: littleluck   Source File: LuckButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 15
Source Project: visualvm   Source File: ProfilerPopup.java    License: GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 16
Source Project: RipplePower   Source File: RPCButton.java    License: Apache License 2.0 6 votes vote down vote up
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);
			}
		}
	});
}
 
Example 17
Source Project: FlatLaf   Source File: FlatMenuUI.java    License: Apache License 2.0 5 votes vote down vote up
@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 );
}
 
Example 18
Source Project: ghidra   Source File: MenuItemManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
	if (action != null) {
		action.removePropertyChangeListener(this);
	}

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

	action = null;
}
 
Example 19
Source Project: littleluck   Source File: LuckCheckboxIcon.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 20
Source Project: netbeans   Source File: SelectorPanel.java    License: Apache License 2.0 5 votes vote down vote up
public GeneralPlatformInstall getInstaller () {
    SelectorPanel c = getComponent ();
    ButtonModel bm = c.group.getSelection();
    if (bm != null) {            
        return c.installersByButtonModels.get(bm);
    }
    return null;
}
 
Example 21
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);
}
 
Example 22
@Override
public void setSelected(ButtonModel model, boolean selected) {
    if (selected) {
        super.setSelected(model, selected);
    } else {
        clearSelection();
    }
}
 
Example 23
Source Project: RipplePower   Source File: RPPopMenuItem.java    License: Apache License 2.0 5 votes vote down vote up
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));
			}
		}
	});
}
 
Example 24
Source Project: beautyeye   Source File: BEMenuUI.java    License: Apache License 2.0 5 votes vote down vote up
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();
	}
}
 
Example 25
Source Project: netbeans   Source File: FlatSlidingButtonUI.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 26
Source Project: beautyeye   Source File: __UI__.java    License: Apache License 2.0 5 votes vote down vote up
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);
		}
	}
}
 
Example 27
Source Project: consulo   Source File: CheckBox.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 28
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()]);
}
 
Example 29
Source Project: stendhal   Source File: StyledButtonUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 30
Source Project: beautyeye   Source File: BERadioButtonMenuItemUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 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);
    	}
    }