protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Icon icon = b.getIcon(); Icon tmpIcon = null; if (icon == null) { return; } Icon selectedIcon = null; /* the fallback icon should be based on the selected state */ if (model.isSelected()) { selectedIcon = (Icon) b.getSelectedIcon(); if (selectedIcon != null) { icon = selectedIcon; } } if (!model.isEnabled()) { if (model.isSelected()) { tmpIcon = (Icon) b.getDisabledSelectedIcon(); if (tmpIcon == null) { tmpIcon = selectedIcon; } } if (tmpIcon == null) { tmpIcon = (Icon) b.getDisabledIcon(); } } else if (model.isPressed() && model.isArmed()) { tmpIcon = (Icon) b.getPressedIcon(); if (tmpIcon != null) { // revert back to 0 offset clearTextShiftOffset(); } } else if (b.isRolloverEnabled() && model.isRollover()) { if (model.isSelected()) { tmpIcon = (Icon) b.getRolloverSelectedIcon(); if (tmpIcon == null) { tmpIcon = selectedIcon; } } if (tmpIcon == null) { tmpIcon = (Icon) b.getRolloverIcon(); } } if (tmpIcon != null) { icon = tmpIcon; } if (model.isPressed() && model.isArmed()) { icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset()); } else { icon.paintIcon(c, g, iconRect.x, iconRect.y); } }
@Override protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Icon icon = b.getIcon(); Icon tmpIcon = null; Icon shadowIcon = null; boolean borderHasPressedCue = borderHasPressedCue(b); if (icon == null) { return; } if (!model.isEnabled()) { if (model.isSelected()) { tmpIcon = (Icon) b.getDisabledSelectedIcon(); } else { tmpIcon = (Icon) b.getDisabledIcon(); } } else if (model.isPressed() && model.isArmed()) { tmpIcon = (Icon) b.getPressedIcon(); if (tmpIcon != null) { // revert back to 0 offset clearTextShiftOffset(); } else if (icon != null && icon instanceof ImageIcon && !borderHasPressedCue) { // Create an icon on the fly. // Note: This is only needed for borderless buttons, which // have no other way to provide feedback about the pressed // state. tmpIcon = new ImageIcon(HalfbrightFilter.createHalfbrightImage(((ImageIcon) icon).getImage())); shadowIcon = new ImageIcon(ShadowFilter.createShadowImage(((ImageIcon) icon).getImage())); } } else if (b.isRolloverEnabled() && model.isRollover()) { if (model.isSelected()) { tmpIcon = b.getRolloverSelectedIcon(); if (tmpIcon == null) { tmpIcon = b.getSelectedIcon(); } } else { tmpIcon = (Icon) b.getRolloverIcon(); } } else if (model.isSelected()) { tmpIcon = b.getSelectedIcon(); } if (tmpIcon != null) { icon = tmpIcon; } if (model.isPressed() && model.isArmed()) { if (shadowIcon != null) { shadowIcon.paintIcon( c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset() + 1); } icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset()); } else { icon.paintIcon(c, g, iconRect.x, iconRect.y); } }
/** Returns the current state of the passed in <code>AbstractButton</code>. */ private int getComponentState(JComponent c) { int state = ENABLED; if (!c.isEnabled()) { state = DISABLED; } AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (model.isPressed()) { if (model.isArmed()) { state = PRESSED; } else { state = MOUSE_OVER; } } if (model.isRollover()) { state |= MOUSE_OVER; } if (model.isSelected()) { state |= SELECTED; } if (c.isFocusOwner() && button.isFocusPainted()) { state |= FOCUSED; } if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) { state |= DEFAULT; } return state; }
@Override public void paint(Graphics g, JComponent c) { Graphics2D g2 = (Graphics2D) g; AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); initShape(b); // ContentArea g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (model.isArmed()) { g2.setColor(ac); g2.fill(shape); } else if (b.isRolloverEnabled() && model.isRollover()) { paintFocusAndRollover(g2, c, rc); } else if (b.hasFocus()) { paintFocusAndRollover(g2, c, fc); } else { g2.setColor(c.getBackground()); g2.fill(shape); } // Border g2.setPaint(c.getForeground()); g2.draw(shape); g2.setColor(c.getBackground()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); super.paint(g2, c); }
public void paintComponent(Graphics g) { if (m.isPressed()) { t = colorCount - 1; g.setColor(pressed[t]); g.fillRect(0, 0, getSize().width - 1, getSize().height - 1); g.setColor(border[t]); } else { g.setColor(rollOver[t]); g.fillRect(0, 0, getSize().width - 1, getSize().height - 1); g.setColor(border[t]); if (m.isRollover()) { if (t < colorCount - 1 && !fadeIn.isRunning()) { fadeOut.stop(); fadeIn.start(); } } else { if (t > 0 && !fadeOut.isRunning()) { fadeIn.stop(); fadeOut.start(); } } } super.paintComponent(g); }
protected void paintText(Graphics g, JComponent com, Rectangle rect, String s) { JButtonLinkA bn = (JButtonLinkA) com; ButtonModel bnModel = bn.getModel(); Color color = bn.getForeground(); Object obj = null; if (bnModel.isEnabled()) { if (bnModel.isPressed()) bn.setForeground(bn.getActiveLinkColor()); else if (bn.isLinkVisited()) bn.setForeground(bn.getVisitedLinkColor()); else bn.setForeground(bn.getLinkColor()); } else { if (bn.getDisabledLinkColor() != null) bn.setForeground(bn.getDisabledLinkColor()); } super.paintText(g, com, rect, s); int behaviour = bn.getLinkBehavior(); boolean drawLine = false; if (behaviour == JButtonLinkA.HOVER_UNDERLINE) { if (bnModel.isRollover()) drawLine = true; } else if (behaviour == JButtonLinkA.ALWAYS_UNDERLINE || behaviour == JButtonLinkA.SYSTEM_DEFAULT) drawLine = true; if (!drawLine) return; FontMetrics fm = g.getFontMetrics(); int x = rect.x + getTextShiftOffset(); int y = (rect.y + fm.getAscent() + fm.getDescent() + getTextShiftOffset()) - 1; if (bnModel.isEnabled()) { g.setColor(bn.getForeground()); g.drawLine(x, y, (x + rect.width) - 1, y); } else { g.setColor(bn.getBackground().brighter()); g.drawLine(x, y, (x + rect.width) - 1, y); } }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); if (model.isRollover() && !(model.isPressed() && !model.isArmed())) { super.paintBorder(c, g, x, y, w, h); } }
public void paintIcon(Graphics2D g, ButtonInfo info) { AbstractButton button = info.button; Icon icon = button.getIcon(); ButtonModel model = button.getModel(); if (model.isRollover() && button.getRolloverIcon() != null) icon = button.getRolloverIcon(); if (model.isPressed() && button.getPressedIcon() != null) icon = button.getPressedIcon(); if (model.isSelected() && button.getSelectedIcon() != null) icon = button.getSelectedIcon(); if (model.isRollover() && model.isSelected() && button.getRolloverSelectedIcon() != null) icon = button.getRolloverSelectedIcon(); if (isEnabled(button) == false && button.getDisabledIcon() != null) icon = button.getDisabledIcon(); if (isEnabled(button) == false && model.isSelected() && button.getDisabledIcon() != null) icon = button.getDisabledSelectedIcon(); if (icon != null) { g.setComposite(isEnabled(button) ? AlphaComposite.SrcOver : SRC_OVER_TRANSLUCENT); icon.paintIcon(button, g, info.iconRect.x, info.iconRect.y); } }
protected void paintComponent(Graphics maing) { ButtonModel buttonModel = getModel(); Graphics2D g = (Graphics2D) maing.create(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (buttonModel.isRollover()) { if (buttonModel.isPressed()) { g.drawImage(img3, 0, 0, getWidth(), getHeight(), null); } else g.drawImage(img2, 0, 0, getWidth(), getHeight(), null); } else g.drawImage(img1, 0, 0, getWidth(), getHeight(), null); if (Settings.drawTracers) { g.setColor(Color.CYAN); g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); } g.dispose(); super.paintComponent(maing); }
public void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); if (!model.isEnabled()) { if (!isDisabled) { changeToDisabledColors(c); } } else if (model.isRollover() || isMouseOver(b)) { if (!isRollover) { changeToRolloverColors(c); } } else if (isDisabled || isRollover) { changeToOriginalColors(c); } super.paint(g, c); }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (model.isEnabled()) { if ((model.isPressed() && model.isArmed()) || model.isSelected()) { Color frameColor = ColorHelper.darker(AbstractLookAndFeel.getToolbarBackgroundColor(), 30); g.setColor(frameColor); g.drawRect(x, y, w - 1, h - 1); Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f); g2D.setComposite(alpha); g.setColor(Color.black); g.fillRect(x + 1, y + 1, w - 2, h - 2); g2D.setComposite(composite); } else if (model.isRollover()) { Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor(); Color frameHiColor = ColorHelper.darker(frameColor, 5); Color frameLoColor = ColorHelper.darker(frameColor, 20); JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x, y, w, h); frameHiColor = Color.white; frameLoColor = ColorHelper.brighter(frameLoColor, 60); JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x + 1, y + 1, w - 2, h - 2); Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f); g2D.setComposite(alpha); g.setColor(Color.white); g.fillRect(x + 2, y + 2, w - 4, h - 4); g2D.setComposite(composite); g.setColor(AbstractLookAndFeel.getFocusColor()); g.drawLine(x + 1, y + 1, x + w - 1, y + 1); g.drawLine(x + 1, y + 2, x + w - 2, y + 2); } else if (model.isSelected()) { Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor(); Color frameHiColor = Color.white; Color frameLoColor = ColorHelper.darker(frameColor, 30); JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h); } } }
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) { ButtonModel model = b.getModel(); FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont()); int mnemIndex; if (JTattooUtilities.getJavaVersion() >= 1.4) { mnemIndex = b.getDisplayedMnemonicIndex(); } else { mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic()); } int offs = 0; if (model.isArmed() && model.isPressed()) { offs = 1; } Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); Color foreground = b.getForeground(); Color background = b.getBackground(); if (background instanceof ColorUIResource) { if (model.isPressed() && model.isArmed()) { foreground = AbstractLookAndFeel.getTheme().getSelectionForegroundColor(); } else if (model.isRollover()) { foreground = AbstractLookAndFeel.getTheme().getRolloverForegroundColor(); } } if (!model.isEnabled()) { foreground = AbstractLookAndFeel.getTheme().getDisabledForegroundColor(); } if (ColorHelper.getGrayValue(foreground) > 64) { g2D.setColor(Color.black); } else { g2D.setColor(Color.white); } JTattooUtilities.drawStringUnderlineCharAt( b, g, text, mnemIndex, textRect.x + offs + 1, textRect.y + offs + fm.getAscent() + 1); g2D.setComposite(composite); g2D.setColor(foreground); JTattooUtilities.drawStringUnderlineCharAt( b, g, text, mnemIndex, textRect.x + offs, textRect.y + offs + fm.getAscent()); }
/** * Returns the Icon to use for painting the button. The icon is chosen with respect to the current * state of the button. * * @param b button the icon is associated with * @return an 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; }
@Override protected void paintComponent(Graphics g) { ButtonModel buttonModel = getModel(); Graphics2D gd = (Graphics2D) g.create(); gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gd.setPaint( new GradientPaint(0, 0, Color.decode("#6dc550"), 0, getHeight(), Color.decode("#5fb544"))); if (buttonModel.isRollover()) { gd.setPaint( new GradientPaint( 0, 0, Color.decode("#5fb544"), 0, getHeight(), Color.decode("#6dc550"))); if (buttonModel.isPressed()) gd.setPaint( new GradientPaint( 0, 0, Color.decode("#1e7d00"), 0, getHeight(), Color.decode("#91e53c"))); else setForeground(Color.white); } gd.fillRect(0, 0, getWidth(), getHeight()); gd.dispose(); super.paintComponent(g); }
/** * If necessary paints the background of the component, then invokes <code>paint</code>. * * @param g Graphics to paint to * @param c JComponent painting on * @throws NullPointerException if <code>g</code> or <code>c</code> is null * @see javax.swing.plaf.ComponentUI#update * @see javax.swing.plaf.ComponentUI#paint * @since 1.5 */ public void update(Graphics g, JComponent c) { AbstractButton button = (AbstractButton) c; if ((c.getBackground() instanceof UIResource) && button.isContentAreaFilled() && c.isEnabled()) { ButtonModel model = button.getModel(); if (!MetalUtils.isToolBarButton(c)) { if (!model.isArmed() && !model.isPressed() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } else if (model.isRollover() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } super.update(g, c); }
private void paintOceanIcon(Component c, Graphics g, int x, int y) { ButtonModel model = ((JCheckBoxMenuItem) c).getModel(); g.translate(x, y); int w = getIconWidth(); int h = getIconHeight(); if (model.isEnabled()) { if (model.isPressed() && model.isArmed()) { g.setColor(MetalLookAndFeel.getControlShadow()); g.fillRect(0, 0, w, h); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.fillRect(0, 0, w, 2); g.fillRect(0, 2, 2, h - 2); g.fillRect(w - 1, 1, 1, h - 1); g.fillRect(1, h - 1, w - 2, 1); } else if (model.isRollover()) { MetalUtilsCustom.drawGradient(c, g, "CheckBox.gradient", 0, 0, w, h, true); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); g.setColor(MetalLookAndFeel.getPrimaryControl()); g.drawRect(1, 1, w - 3, h - 3); g.drawRect(2, 2, w - 5, h - 5); } else { MetalUtilsCustom.drawGradient(c, g, "CheckBox.gradient", 0, 0, w, h, true); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); } g.setColor(MetalLookAndFeel.getControlInfo()); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); } g.translate(-x, -y); if (model.isSelected()) { drawCheck(g, x, y); } }
protected void paintComponent(Graphics maing) { ButtonModel buttonModel = getModel(); Graphics2D g = (Graphics2D) maing.create(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); if (!isEnabled()) { g.drawImage(genButton(w, h, lockedTX), 0, 0, w, h, null); } else if (buttonModel.isRollover()) { if (buttonModel.isPressed()) { new MusPlay("click.mp3"); g.drawImage(genButton(w, h, pressedTX), 0, 0, w, h, null); } else g.drawImage(genButton(w, h, rolloverTX), 0, 0, w, h, null); } else g.drawImage(genButton(w, h, defaultTX), 0, 0, w, h, null); if (Settings.drawTracers) { g.setColor(Color.RED); g.drawRect(0, 0, w - 1, h - 1); } g.dispose(); super.paintComponent(maing); }
@Override public void paint(Graphics g, JComponent c) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (model.isRollover()) { paintBackground(g2d, button); paintRoundBorder(g2d, button); } g.translate(3, 5); g.setColor(Color.WHITE); g.drawLine(1, 0, 5, 4); g.drawLine(0, 0, 5, 5); g.drawLine(5, 4, 9, 0); g.drawLine(5, 5, 10, 0); g.setColor(look.colors().shadow()); g.drawLine(0, 1, 5, 6); g.drawLine(5, 6, 10, 1); }
protected void paintBackground(Graphics g, AbstractButton b) { if (!b.isContentAreaFilled() || (b.getParent() instanceof JMenuBar)) { return; } if (!(b.isBorderPainted() && (b.getBorder() instanceof UIResource))) { super.paintBackground(g, b); return; } int width = b.getWidth(); int height = b.getHeight(); ButtonModel model = b.getModel(); Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (((width < 64) || (height < 16)) && ((b.getText() == null) || b.getText().length() == 0)) { if (model.isSelected()) { Color color = ColorHelper.darker(b.getBackground(), 20); g2D.setColor(color); g2D.fillRect(0, 0, width - 1, height - 1); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRect(0, 0, width - 1, height - 1); } else { Color[] colors = null; if (b.getBackground() instanceof ColorUIResource) { if (!model.isEnabled()) { colors = AbstractLookAndFeel.getTheme().getDisabledColors(); } else if (b.isRolloverEnabled() && model.isRollover()) { colors = AbstractLookAndFeel.getTheme().getRolloverColors(); } else { colors = AbstractLookAndFeel.getTheme().getButtonColors(); } } else { colors = ColorHelper.createColorArr( ColorHelper.brighter(b.getBackground(), 20), ColorHelper.darker(b.getBackground(), 20), 20); } JTattooUtilities.fillHorGradient(g, colors, 0, 0, width - 1, height - 1); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRect(0, 0, width - 1, height - 1); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); g2D.setColor(Color.white); g2D.drawRect(1, 1, width - 3, height - 3); } } else if (model.isPressed() && model.isArmed()) { int d = height - 2; Color color = AbstractLookAndFeel.getTheme().getSelectionBackgroundColor(); g2D.setColor(color); g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d); g2D.setColor(ColorHelper.darker(color, 40)); g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d); } else if (model.isSelected()) { int d = height - 2; Color color = ColorHelper.darker(b.getBackground(), 20); g2D.setColor(color); g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d); } else { int d = height - 2; Color[] colors = null; if (b.getBackground() instanceof ColorUIResource) { if (!model.isEnabled()) { colors = AbstractLookAndFeel.getTheme().getDisabledColors(); } else if (b.isRolloverEnabled() && model.isRollover()) { colors = AbstractLookAndFeel.getTheme().getRolloverColors(); } else { colors = AbstractLookAndFeel.getTheme().getButtonColors(); } } else { colors = ColorHelper.createColorArr( ColorHelper.brighter(b.getBackground(), 20), ColorHelper.darker(b.getBackground(), 20), 20); } Shape savedClip = g.getClip(); Area clipArea = new Area(new RoundRectangle2D.Double(0, 0, width - 1, height - 1, d, d)); clipArea.intersect(new Area(savedClip)); g2D.setClip(clipArea); JTattooUtilities.fillHorGradient(g, colors, 0, 0, width, height); g2D.setClip(savedClip); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); g2D.setColor(Color.white); g2D.drawRoundRect(1, 1, width - 3, height - 3, d - 2, d - 2); } g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); g2D.setComposite(composite); }
@Override protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { JMenu menu = (JMenu) menuItem; ButtonModel buttonmodel = menu.getModel(); if (menu.isTopLevelMenu()) { this.selectionForeground = Colors.getBlack(); } else { this.selectionForeground = Colors.getWhite(); } int w = menu.getWidth(); int h = menu.getHeight(); Color oldColor = g.getColor(); if (!menu.isContentAreaFilled() || !menu.isOpaque()) { // do nothing } else { if (menu.isTopLevelMenu()) { if (buttonmodel.isSelected()) { CashedPainter.drawMenuBackground(menuItem, g, 0, 0, w, h); } else if (buttonmodel.isRollover() && buttonmodel.isEnabled()) { g.setColor(new ColorUIResource(252, 252, 252)); g.fillRect(1, 1, w - 2, h - 2); g.setColor(RapidLookTools.getColors().getToolbarButtonColors()[0]); g.drawLine(2, 0, w - 3, 0); g.drawLine(2, h - 1, w - 3, h - 1); g.drawLine(0, 2, 0, h - 3); g.drawLine(w - 1, 2, w - 1, h - 3); g.drawLine(1, 1, 1, 1); g.drawLine(w - 2, 1, w - 2, 1); g.drawLine(1, h - 2, 1, h - 2); g.drawLine(w - 2, h - 2, w - 2, h - 2); g.setColor(RapidLookTools.getColors().getToolbarButtonColors()[8]); g.drawLine(0, 1, 1, 0); g.drawLine(w - 1, 1, w - 2, 0); g.drawLine(1, h - 1, 0, h - 2); g.drawLine(w - 1, h - 2, w - 2, h - 1); g.setColor(RapidLookTools.getColors().getToolbarButtonColors()[7]); g.drawLine(1, 2, 2, 1); g.drawLine(w - 2, 2, w - 3, 1); g.setColor(RapidLookTools.getColors().getToolbarButtonColors()[6]); g.drawLine(2, h - 2, 1, h - 3); g.drawLine(w - 2, h - 3, w - 3, h - 2); g.setColor(new ColorUIResource(252, 252, 252)); g.drawLine(0, 0, 0, 0); g.drawLine(w - 1, 0, w - 1, 0); g.setColor(new ColorUIResource(232, 232, 232)); g.drawLine(0, h - 1, 0, h - 1); g.drawLine(w - 1, h - 1, w - 1, h - 1); } else { if (menuItem.getParent() instanceof JMenuBar) { ((MenuBarUI) ((JMenuBar) menuItem.getParent()).getUI()).update(g, menuItem); } } } else { if (!menuItem.getModel().isSelected()) { CashedPainter.drawMenuItemFading(menuItem, g); } else { RapidLookTools.drawMenuItemBackground(g, menuItem); } } } g.setColor(oldColor); }
/** * Paint xp button background. * * @param nomalColor the nomal color * @param g the g * @param c the c */ public static void paintXPButtonBackground(NormalColor nomalColor, Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; // BEXPStyle xp = BEXPStyle.getXP(); boolean toolbar = (b.getParent() instanceof JToolBar); // Part part = getXPButtonType(b); if (b.isContentAreaFilled()) // && xp != null) { ButtonModel model = b.getModel(); // Skin skin = xp.getSkin(b, part); // normal, rollover/activated/focus, pressed, disabled, default // State state = State.NORMAL; if (toolbar) { // if (model.isArmed() && model.isPressed()) // { // state = State.PRESSED; // } // else if (!model.isEnabled()) // { // state = State.DISABLED; // } // else if (model.isSelected() && model.isRollover()) // { // state = State.HOTCHECKED; // } // else if (model.isSelected()) // { // state = State.CHECKED; // } // else if (model.isRollover()) // { // state = State.HOT; // } } else { // if (model.isArmed() && model.isPressed() || model.isSelected()) // { // state = State.PRESSED; // } // else if (!model.isEnabled()) // { // state = State.DISABLED; // } // else if (model.isRollover() || model.isPressed()) // { // state = State.HOT; // } // else if (b instanceof JButton // && ((JButton) b).isDefaultButton()) // { // state = State.DEFAULTED; // } // else if (c.hasFocus()) // { // state = State.HOT; // } } Dimension d = c.getSize(); int dx = 0; int dy = 0; int dw = d.width; int dh = d.height; Border border = c.getBorder(); Insets insets; if (border != null) { // Note: The border may be compound, containing an outer // opaque border (supplied by the application), plus an // inner transparent margin border. We want to size the // background to fill the transparent part, but stay // inside the opaque part. insets = BEButtonUI.getOpaqueInsets(border, c); } else { insets = c.getInsets(); } if (insets != null) { dx += insets.left; dy += insets.top; dw -= (insets.left + insets.right); dh -= (insets.top + insets.bottom); } /** ************************* 以下代码由jb2011改造自WindowsButtonUI START ******************* */ if (toolbar) { // 此状态下JToggleButton和JButton使用各自的背景实现,2012-10-16前无论是不是JToggleButton都是使用该种实是不太合理的 if (model.isRollover() || model.isPressed()) { if (c instanceof JToggleButton) __Icon9Factory__.getInstance() .getToggleButtonIcon_RoverGreen() .draw((Graphics2D) g, dx, dy, dw, dh); else __Icon9Factory__.getInstance() .getButtonIcon_PressedOrange() .draw((Graphics2D) g, dx, dy, dw, dh); } else if (model.isSelected()) // state == State.CHECKED)//||state == State.HOTCHECKED) { __Icon9Factory__.getInstance() .getToggleButtonIcon_CheckedGreen() .draw((Graphics2D) g, dx, dy, dw, dh); } else { // TODO 其它状态下的按钮背景样式需要完善,要不然看起来太硬! // skin.paintSkin(g, dx, dy, dw, dh, state); } } else { try { // TODO 其它状态下的按钮背景样式需要完善,要不然看起来太硬! // if(state == State.PRESSED) if (model.isArmed() && model.isPressed() || model.isSelected()) __Icon9Factory__.getInstance() .getButtonIcon_PressedOrange() .draw((Graphics2D) g, dx, dy, dw, dh); // else if(state == State.DISABLED) else if (!model.isEnabled()) __Icon9Factory__.getInstance() .getButtonIcon_DisableGray() .draw((Graphics2D) g, dx, dy, dw, dh); else if (model.isRollover()) __Icon9Factory__.getInstance() .getButtonIcon_rover() .draw((Graphics2D) g, dx, dy, dw, dh); else { if (nomalColor == NormalColor.green) { __Icon9Factory__.getInstance() .getButtonIcon_NormalGreen() .draw((Graphics2D) g, dx, dy, dw, dh); } else if (nomalColor == NormalColor.red) { __Icon9Factory__.getInstance() .getButtonIcon_NormalRed() .draw((Graphics2D) g, dx, dy, dw, dh); } else if (nomalColor == NormalColor.blue) { __Icon9Factory__.getInstance() .getButtonIcon_NormalBlue() .draw((Graphics2D) g, dx, dy, dw, dh); } else if (nomalColor == NormalColor.lightBlue) { __Icon9Factory__.getInstance() .getButtonIcon_NormalLightBlue() .draw((Graphics2D) g, dx, dy, dw, dh); } // else if(nomalColor==NormalColor.red) // { // //红色按钮禁用状态时为更好地突出禁用状态,用深灰按钮 // if(state == State.DISABLED) // __Icon9Factory__.getInstance().getButtonIcon_NormalGray().draw((Graphics2D)g, // dx, dy, dw, dh); // else // __Icon9Factory__.getInstance().getButtonIcon_NormalRed().draw((Graphics2D)g, // dx, dy, dw, dh); // } else __Icon9Factory__.getInstance() .getButtonIcon_NormalGray() .draw((Graphics2D) g, dx, dy, dw, dh); } } catch (Exception e) { e.printStackTrace(); } } /** ************************* 以下代码由JS改造自WindowsButtonUI END ******************* */ } }
public void paintIcon(Component c, Graphics g, int x, int y) { if (!JTattooUtilities.isLeftToRight(c)) { x += GAP; } int w = getIconWidth() - GAP; int h = getIconHeight(); AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); Graphics2D g2D = (Graphics2D) g; if (button.isEnabled()) { if ((button.isRolloverEnabled() && model.isRollover())) { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getRolloverColors(), x + 1, y + 1, w - 1, h - 1); } else { if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getFocusColors(), x + 1, y + 1, w - 1, h - 1); } else { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getCheckBoxColors(), x + 1, y + 1, w - 1, h - 1); } } } else { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getDisabledColors(), x + 1, y + 1, w - 1, h - 1); } Color frameColor = ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6); Color loFrameColor = ColorHelper.darker(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 50); g.setColor(frameColor); g.drawRect(x, y, w, h); Composite savedComposite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f); g2D.setComposite(alpha); g.setColor(loFrameColor); g.drawLine(x + 1, y + 1, x + w - 1, y + 1); g.drawLine(x + 1, y + 1, x + 1, y + h - 1); g2D.setComposite(savedComposite); Icon checkIcon; Icon checkDisabledIcon; Icon checkInverseIcon; if (AbstractLookAndFeel.getTheme().isSmallFontSize()) { checkIcon = SMALL_CHECK_ICON; checkDisabledIcon = SMALL_CHECK_DISABLED_ICON; checkInverseIcon = SMALL_CHECK_INVERSE_ICON; } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) { checkIcon = MEDIUM_CHECK_ICON; checkDisabledIcon = MEDIUM_CHECK_DISABLED_ICON; checkInverseIcon = MEDIUM_CHECK_INVERSE_ICON; } else { checkIcon = LARGE_CHECK_ICON; checkDisabledIcon = LARGE_CHECK_DISABLED_ICON; checkInverseIcon = LARGE_CHECK_INVERSE_ICON; } int xi = x + ((w - checkIcon.getIconWidth()) / 2) + 1; int yi = y + ((h - checkIcon.getIconHeight()) / 2); int gv = ColorHelper.getGrayValue(AbstractLookAndFeel.getButtonForegroundColor()); if (model.isPressed() && model.isArmed()) { Color bc = gv > 128 ? AbstractLookAndFeel.getTheme().getSelectionForegroundColor() : AbstractLookAndFeel.getTheme().getSelectionBackgroundColor(); Color fc = gv > 128 ? ColorHelper.brighter(bc, 20) : ColorHelper.darker(bc, 40); g.setColor(fc); g.drawRect(x + 4, y + 4, w - 8, h - 8); g.setColor(bc); g.fillRect(x + 5, y + 5, w - 9, h - 9); } else if (model.isSelected()) { if (!model.isEnabled()) { checkDisabledIcon.paintIcon(c, g, xi + 1, yi); } else { if (gv > 128) { checkIcon.paintIcon(c, g, xi, yi); } else { checkInverseIcon.paintIcon(c, g, xi + 1, yi + 1); } } } }
@Override public boolean isRollover() { return other.isRollover(); }
public void paintIcon(Component c, Graphics g, int x, int y) { if (!JTattooUtilities.isLeftToRight(c)) { x += GAP; } int w = getIconWidth() - GAP; int h = getIconHeight(); Graphics2D g2D = (Graphics2D) g; AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); Color colors[]; if (button.isEnabled()) { if ((button.isRolloverEnabled() && model.isRollover()) || (model.isPressed() && model.isArmed())) { colors = AbstractLookAndFeel.getTheme().getRolloverColors(); } else { if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) { colors = AbstractLookAndFeel.getTheme().getFocusColors(); } else { colors = AbstractLookAndFeel.getTheme().getCheckBoxColors(); } } } else { colors = AbstractLookAndFeel.getTheme().getDisabledColors(); } Color frameColor = ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6); Shape savedClip = g.getClip(); Area clipArea = new Area(new Ellipse2D.Double(x, y, w + 1, h + 1)); if (savedClip != null) { clipArea.intersect(new Area(savedClip)); } g2D.setClip(clipArea); JTattooUtilities.fillHorGradient(g, colors, x, y, w, h); g2D.setClip(savedClip); Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(frameColor); g.drawOval(x, y, w, h); if (model.isSelected()) { if (model.isEnabled()) { Color fc = AbstractLookAndFeel.getForegroundColor(); if (ColorHelper.getGrayValue(colors[0]) < 128) { if (ColorHelper.getGrayValue(fc) < 128) { g2D.setColor(Color.white); } else { g2D.setColor(fc); } } else { if (ColorHelper.getGrayValue(fc) > 128) { g2D.setColor(Color.black); } else { g2D.setColor(fc); } } } else { g.setColor(AbstractLookAndFeel.getDisabledForegroundColor()); } if (AbstractLookAndFeel.getTheme().isSmallFontSize()) { g2D.fillOval(x + 4, y + 4, w - 7, h - 7); } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) { g2D.fillOval(x + 4, y + 4, w - 7, h - 7); } else { g2D.fillOval(x + 5, y + 5, w - 9, h - 9); } } g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); }
public void paint(final Graphics g, final JComponent c) { final AnchoredButton button = (AnchoredButton) c; final String text = button.getText(); final Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon(); if ((icon == null) && (text == null)) { return; } final FontMetrics fm = button.getFontMetrics(button.getFont()); ourViewInsets = c.getInsets(ourViewInsets); ourViewRect.x = ourViewInsets.left; ourViewRect.y = ourViewInsets.top; final ToolWindowAnchor anchor = button.getAnchor(); // Use inverted height & width if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) { ourViewRect.height = c.getWidth() - (ourViewInsets.left + ourViewInsets.right); ourViewRect.width = c.getHeight() - (ourViewInsets.top + ourViewInsets.bottom); } else { ourViewRect.height = c.getHeight() - (ourViewInsets.left + ourViewInsets.right); ourViewRect.width = c.getWidth() - (ourViewInsets.top + ourViewInsets.bottom); } ourIconRect.x = ourIconRect.y = ourIconRect.width = ourIconRect.height = 0; ourTextRect.x = ourTextRect.y = ourTextRect.width = ourTextRect.height = 0; final String clippedText = SwingUtilities.layoutCompoundLabel( c, fm, text, icon, button.getVerticalAlignment(), button.getHorizontalAlignment(), button.getVerticalTextPosition(), button.getHorizontalTextPosition(), ourViewRect, ourIconRect, ourTextRect, button.getText() == null ? 0 : button.getIconTextGap()); // Paint button's background final Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); final ButtonModel model = button.getModel(); final Color background = button.getBackground(); Color toBorder = model.isRollover() ? new Color(0, 0, 0, 50) : null; final boolean vertical = anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT; if (model.isArmed() && model.isPressed() || model.isSelected()) { g2.setColor(new Color(0, 0, 0, 30)); g2.fillRect(3, 3, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6); g2.setColor(new Color(0, 0, 0, 120)); g2.drawLine(2, 2, 3 + button.getWidth() - (vertical ? 7 : 6), 2); g2.drawLine(2, 3, 2, 3 + button.getHeight() - 7); g2.setColor(new Color(0, 0, 0, 40)); g2.drawRect(3, 3, button.getWidth() - (vertical ? 7 : 6), button.getHeight() - 7); g2.setColor(new Color(255, 255, 255, 110)); g2.drawLine( 3, button.getHeight() - 3, 3 + button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 3); g2.drawLine( 3 + button.getWidth() - (vertical ? 6 : 5), 2, 3 + button.getWidth() - (vertical ? 6 : 5), 3 + button.getHeight() - 7); toBorder = null; } if (toBorder != null) { g.setColor(toBorder); g.drawRect(2, 2, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6); } AffineTransform tr = null; if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) { tr = g2.getTransform(); if (ToolWindowAnchor.RIGHT == anchor) { if (icon != null) { // do not rotate icon icon.paintIcon(c, g2, ourIconRect.y, ourIconRect.x); } g2.rotate(Math.PI / 2); g2.translate(0, -c.getWidth()); } else { if (icon != null) { // do not rotate icon icon.paintIcon( c, g2, ourIconRect.y, c.getHeight() - ourIconRect.x - icon.getIconHeight()); } g2.rotate(-Math.PI / 2); g2.translate(-c.getHeight(), 0); } } else { if (icon != null) { icon.paintIcon(c, g2, ourIconRect.x, ourIconRect.y); } } // paint text if (text != null) { if (model.isEnabled()) { if (model.isArmed() && model.isPressed() || model.isSelected()) { g.setColor(background); } else { g.setColor(button.getForeground()); } } else { g.setColor(background.darker()); } /* Draw the Text */ if (model.isEnabled()) { /** * paint the text normally */ g.setColor(button.getForeground()); BasicGraphicsUtils.drawString( g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent()); } else { /** * paint the text disabled ** */ if (model.isSelected()) { g.setColor(c.getBackground()); } else { g.setColor(getDisabledTextColor()); } BasicGraphicsUtils.drawString( g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent()); } } if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) { g2.setTransform(tr); } }
private void paintOceanBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton) c; ButtonModel model = ((AbstractButton) c).getModel(); g.translate(x, y); if (MetalUtils.isToolBarButton(button)) { if (model.isEnabled()) { if (model.isPressed()) { g.setColor(MetalLookAndFeel.getWhite()); g.fillRect(1, h - 1, w - 1, 1); g.fillRect(w - 1, 1, 1, h - 1); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 2, h - 2); g.fillRect(1, 1, w - 3, 1); } else if (model.isSelected() || model.isRollover()) { g.setColor(MetalLookAndFeel.getWhite()); g.fillRect(1, h - 1, w - 1, 1); g.fillRect(w - 1, 1, 1, h - 1); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 2, h - 2); } else { g.setColor(MetalLookAndFeel.getWhite()); g.drawRect(1, 1, w - 2, h - 2); g.setColor(UIManager.getColor("Button.toolBarBorderBackground")); g.drawRect(0, 0, w - 2, h - 2); } } else { g.setColor(UIManager.getColor("Button.disabledToolBarBorderBackground")); g.drawRect(0, 0, w - 2, h - 2); } } else if (model.isEnabled()) { boolean pressed = model.isPressed(); boolean armed = model.isArmed(); if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); g.drawRect(1, 1, w - 3, h - 3); } else if (pressed) { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.fillRect(0, 0, w, 2); g.fillRect(0, 2, 2, h - 2); g.fillRect(w - 1, 1, 1, h - 1); g.fillRect(1, h - 1, w - 2, 1); } else if (model.isRollover() && button.getClientProperty(NO_BUTTON_ROLLOVER) == null) { g.setColor(MetalLookAndFeel.getPrimaryControl()); g.drawRect(0, 0, w - 1, h - 1); g.drawRect(2, 2, w - 5, h - 5); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(1, 1, w - 3, h - 3); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); } } else { g.setColor(MetalLookAndFeel.getInactiveControlTextColor()); g.drawRect(0, 0, w - 1, h - 1); if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) { g.drawRect(1, 1, w - 3, h - 3); } } }