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); } }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (MetalLookAndFeel.usingOcean()) { paintOceanBorder(c, g, x, y, w, h); return; } AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (model.isEnabled()) { boolean isPressed = model.isPressed() && model.isArmed(); boolean isDefault = (button instanceof JButton && ((JButton) button).isDefaultButton()); if (isPressed && isDefault) { MetalUtils.drawDefaultButtonPressedBorder(g, x, y, w, h); } else if (isPressed) { MetalUtils.drawPressed3DBorder(g, x, y, w, h); } else if (isDefault) { MetalUtils.drawDefaultButtonBorder(g, x, y, w, h, false); } else { MetalUtils.drawButtonBorder(g, x, y, w, h, false); } } else { // disabled state MetalUtils.drawDisabledBorder(g, x, y, w - 1, h - 1); } }
/** 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; }
private void updateLook(JButton button) { ButtonModel model = button.getModel(); boolean enabled = model.isEnabled(); if (!enabled) { setLookNormal(button); return; } boolean pressed = model.isPressed(); boolean selected = model.isSelected(); if (pressed || selected) { setLookLowered(button); return; } if ((button == arrow) && popupVisible) { setLookLowered(button); return; } if (rollOver) { setLookRaised(button); return; } if (arrow.getModel().isSelected()) { setLookRaised(button); return; } setLookNormal(button); }
/** * Method which renders the text of the current button. * * <p> * * @param g Graphics context * @param b Current button to render * @param textRect Bounding rectangle to render the text. * @param text String to render * @since 1.4 */ @Override protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) { ButtonModel model = b.getModel(); FontMetrics fm = g.getFontMetrics(); int mnemonicIndex = Methods.invokeGetter(b, "getDisplayedMnemonicIndex", -1); boolean borderHasPressedCue = borderHasPressedCue(b); /* Draw the Text */ if (model.isPressed() && model.isArmed() && !borderHasPressedCue) { g.setColor(new Color(0xa0000000, true)); QuaquaUtilities.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset() + 1); } if (model.isEnabled()) { /** * paint the text normally */ g.setColor(b.getForeground()); } else { Color c = UIManager.getColor(getPropertyPrefix() + "disabledForeground"); g.setColor((c != null) ? c : b.getForeground()); } QuaquaUtilities.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset()); }
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); } }
@Override @SuppressWarnings("unchecked") public void paintIcon(final Component c, final Graphics g, final int x, final int y) { JCheckBox cb = (JCheckBox) c; javax.swing.ButtonModel model = cb.getModel(); if (ThemeManager.isLookAndFeelNimbus()) { icon.paintIcon(c, g, x, y); if (c.hasFocus()) { nimbusFocusBorder.paintBorder(g, x, y, iconWidth, iconHeight); } drawIndeterminateNimbusLine(g, x, y); } else { if (model.isEnabled()) { if (model.isPressed() && model.isArmed()) { g.setColor(MetalLookAndFeel.getControlShadow()); g.fillRect(x, y, iconWidth - 1, iconHeight - 1); drawPressed3DBorder(g, x, y, iconWidth, iconHeight); } else { drawFlush3DBorder(g, x, y, iconWidth, iconHeight); } g.setColor(MetalLookAndFeel.getControlInfo()); } else { g.setColor(MetalLookAndFeel.getControlShadow()); g.drawRect(x, y, iconWidth - 1, iconHeight - 1); } drawIndeterminateLine(g, x, y); } }
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); }
public void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); String text = layout(b, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight()); clearTextShiftOffset(); // perform UI specific press action, e.g. Windows L&F shifts text if (model.isArmed() && model.isPressed()) { paintButtonPressed(g, b); } // Paint the Icon if (b.getIcon() != null) { paintIcon(g, c, iconRect); } if (text != null && !text.equals("")) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, textRect); } else { paintText(g, b, textRect, text); } } if (b.isFocusPainted() && b.hasFocus()) { // paint UI specific focus paintFocus(g, b, viewRect, textRect, iconRect); } }
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(Component c, Graphics g, int x, int y) { ButtonModel model = ((AbstractButton) c).getModel(); if (model.isPressed() && model.isArmed()) { pressed.paintIcon(c, g, x, y); } else { super.paintIcon(c, g, x, y); } }
/** Returns the amount to shift the text/icon when painting. */ private int getTextShiftOffset(SynthContext state) { AbstractButton button = (AbstractButton) state.getComponent(); ButtonModel model = button.getModel(); if (model.isArmed() && model.isPressed() && button.getPressedIcon() == null) { return state.getStyle().getInt(state, getPropertyPrefix() + "textShiftOffset", 0); } return 0; }
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()); }
@Override public void mousePressed(MouseEvent e) { Object o = e.getSource(); if (o instanceof TableCellEditor) { actionPerformed(null); } else if (o instanceof JButton) { // DEBUG: view button click -> control key down + edit button(same cell) press -> remain // selection color ButtonModel m = ((JButton) e.getComponent()).getModel(); if (m.isPressed() && table.isRowSelected(table.getEditingRow()) && e.isControlDown()) { setBackground(table.getBackground()); } } }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor(); Color frameHiColor = ColorHelper.brighter(frameColor, 10); Color frameLoColor = ColorHelper.darker(frameColor, 30); JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x, y, w, h); if ((model.isPressed() && model.isArmed()) || model.isSelected()) { JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h); } else { JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h); JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x + 1, y + 1, w - 2, h - 2); } }
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 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); } } }
/** * 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; }
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); } }
@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); }
/** * Paint the component. * * @param g The graphics context for painting * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) */ protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; fRenderer.paintComponent(g2, fButtonDelegate, this, 0, 0, getWidth(), getHeight(), true); ButtonModel model = getModel(); boolean doOffset = model.isPressed() && model.isArmed(); int offsetAmount = UIManager.getInt("Button.textShiftOffset"); double degrees = Math.toRadians(-90); if (fRotation == LEFT) { int h = getHeight(); g2.translate(0, h); g2.rotate(degrees); if (doOffset) { g2.translate(-offsetAmount, offsetAmount); } fRenderer.paintComponent(g2, fLabelDelegate, this, 0, 0, getHeight(), getWidth(), true); if (doOffset) { g2.translate(offsetAmount, -offsetAmount); } g2.rotate(-degrees); g2.translate(0, -h); } else { int w = getWidth(); g2.translate(w, 0); g2.rotate(-degrees); if (doOffset) { g2.translate(offsetAmount, -offsetAmount); } fRenderer.paintComponent(g2, fLabelDelegate, this, 0, 0, getHeight(), getWidth(), true); if (doOffset) { g2.translate(-offsetAmount, offsetAmount); } g2.rotate(degrees); g2.translate(-w, 0); } }
/** * 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); }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (MetalLookAndFeel.usingOcean()) { if (model.isArmed() || !button.isEnabled()) { super.paintBorder(c, g, x, y, w, h); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); } return; } if (!c.isEnabled()) { MetalUtils.drawDisabledBorder(g, x, y, w - 1, h - 1); } else { if (model.isPressed() && model.isArmed()) { MetalUtils.drawPressed3DBorder(g, x, y, w, h); } else if (model.isSelected()) { MetalUtils.drawDark3DBorder(g, x, y, w, h); } else { MetalUtils.drawFlush3DBorder(g, x, y, w, h); } } }
/** * 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 ******************* */ } }
@Override public boolean isPressed() { return other.isPressed(); }
/** * This method is not being used to paint menu item since 6.0 This code left for compatibility * only. Do not use or override it, this will not cause any visible effect. */ public static void paintMenuItem( Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { JMenuItem b = (JMenuItem) c; ButtonModel model = b.getModel(); Dimension size = b.getSize(); Insets i = c.getInsets(); Rectangle viewRect = new Rectangle(size); viewRect.x += i.left; viewRect.y += i.top; viewRect.width -= (i.right + viewRect.x); viewRect.height -= (i.bottom + viewRect.y); Rectangle iconRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle acceleratorRect = new Rectangle(); Rectangle checkRect = new Rectangle(); Rectangle arrowRect = new Rectangle(); Font holdf = g.getFont(); Font f = c.getFont(); g.setFont(f); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f); FontMetrics fmAccel = SwingUtilities2.getFontMetrics(c, g, UIManager.getFont("MenuItem.acceleratorFont")); if (c.isOpaque()) { if (model.isArmed() || (c instanceof JMenu && model.isSelected())) { g.setColor(background); } else { g.setColor(c.getBackground()); } g.fillRect(0, 0, size.width, size.height); } // get Accelerator text KeyStroke accelerator = b.getAccelerator(); String acceleratorText = ""; if (accelerator != null) { int modifiers = accelerator.getModifiers(); if (modifiers > 0) { acceleratorText = KeyEvent.getKeyModifiersText(modifiers); acceleratorText += "+"; } acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode()); } // layout the text and icon String text = layoutMenuItem( c, fm, b.getText(), fmAccel, acceleratorText, b.getIcon(), checkIcon, arrowIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, acceleratorRect, checkRect, arrowRect, b.getText() == null ? 0 : defaultTextIconGap, defaultTextIconGap); // Paint the Check Color holdc = g.getColor(); if (checkIcon != null) { if (model.isArmed() || (c instanceof JMenu && model.isSelected())) g.setColor(foreground); checkIcon.paintIcon(c, g, checkRect.x, checkRect.y); g.setColor(holdc); } // Paint the Icon if (b.getIcon() != null) { Icon icon; if (!model.isEnabled()) { icon = (Icon) b.getDisabledIcon(); } else if (model.isPressed() && model.isArmed()) { icon = (Icon) b.getPressedIcon(); if (icon == null) { // Use default icon icon = (Icon) b.getIcon(); } } else { icon = (Icon) b.getIcon(); } if (icon != null) { icon.paintIcon(c, g, iconRect.x, iconRect.y); } } // Draw the Text if (text != null && !text.equals("")) { // Once BasicHTML becomes public, use BasicHTML.propertyKey // instead of the hardcoded string below! View v = (View) c.getClientProperty("html"); if (v != null) { v.paint(g, textRect); } else { int mnemIndex = b.getDisplayedMnemonicIndex(); if (!model.isEnabled()) { // *** paint the text disabled g.setColor(b.getBackground().brighter()); SwingUtilities2.drawStringUnderlineCharAt( b, g, text, mnemIndex, textRect.x, textRect.y + fmAccel.getAscent()); g.setColor(b.getBackground().darker()); SwingUtilities2.drawStringUnderlineCharAt( b, g, text, mnemIndex, textRect.x - 1, textRect.y + fmAccel.getAscent() - 1); } else { // *** paint the text normally if (model.isArmed() || (c instanceof JMenu && model.isSelected())) { g.setColor(foreground); } else { g.setColor(b.getForeground()); } SwingUtilities2.drawStringUnderlineCharAt( b, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent()); } } } // Draw the Accelerator Text if (acceleratorText != null && !acceleratorText.equals("")) { // Get the maxAccWidth from the parent to calculate the offset. int accOffset = 0; Container parent = b.getParent(); if (parent != null && parent instanceof JComponent) { JComponent p = (JComponent) parent; Integer maxValueInt = (Integer) p.getClientProperty(MotifGraphicsUtils.MAX_ACC_WIDTH); int maxValue = maxValueInt != null ? maxValueInt.intValue() : acceleratorRect.width; // Calculate the offset, with which the accelerator texts will be drawn with. accOffset = maxValue - acceleratorRect.width; } g.setFont(UIManager.getFont("MenuItem.acceleratorFont")); if (!model.isEnabled()) { // *** paint the acceleratorText disabled g.setColor(b.getBackground().brighter()); SwingUtilities2.drawString( c, g, acceleratorText, acceleratorRect.x - accOffset, acceleratorRect.y + fm.getAscent()); g.setColor(b.getBackground().darker()); SwingUtilities2.drawString( c, g, acceleratorText, acceleratorRect.x - accOffset - 1, acceleratorRect.y + fm.getAscent() - 1); } else { // *** paint the acceleratorText normally if (model.isArmed() || (c instanceof JMenu && model.isSelected())) { g.setColor(foreground); } else { g.setColor(b.getForeground()); } SwingUtilities2.drawString( c, g, acceleratorText, acceleratorRect.x - accOffset, acceleratorRect.y + fmAccel.getAscent()); } } // Paint the Arrow if (arrowIcon != null) { if (model.isArmed() || (c instanceof JMenu && model.isSelected())) g.setColor(foreground); if (!(b.getParent() instanceof JMenuBar)) arrowIcon.paintIcon(c, g, arrowRect.x, arrowRect.y); } g.setColor(holdc); g.setFont(holdf); }
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); } }