private static int getButtonBaselineResizeBehavior(AbstractButton button) { if (button.getClientProperty("html") != null) { return BRB_OTHER; } switch (button.getVerticalAlignment()) { case AbstractButton.TOP: return BRB_CONSTANT_ASCENT; case AbstractButton.BOTTOM: return BRB_CONSTANT_DESCENT; case AbstractButton.CENTER: return BRB_CENTER_OFFSET; } return BRB_OTHER; }
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); } } }
public static Dimension getPreferredSize(AbstractButton b) { String style = (String) b.getClientProperty("Quaqua.Button.style"); if (style == null) { style = "push"; } if (style.equals("help")) { Icon helpIcon = UIManager.getIcon("Button.helpIcon"); Insets insets = b.getInsets(); return new Dimension( helpIcon.getIconWidth() + insets.left + insets.right, helpIcon.getIconHeight() + insets.top + insets.bottom); } if (b.getComponentCount() > 0) { return null; } int textIconGap = Methods.invokeGetter(b, "getIconTextGap", 4); Icon icon = (Icon) b.getIcon(); String text = b.getText(); Font font = b.getFont(); FontMetrics fm = b.getFontMetrics(font); viewR.x = viewR.y = 0; viewR.width = Short.MAX_VALUE; viewR.height = Short.MAX_VALUE; iconR.x = iconR.y = iconR.width = iconR.height = 0; textR.x = textR.y = textR.width = textR.height = 0; SwingUtilities.layoutCompoundLabel( (JComponent) b, fm, text, icon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewR, iconR, textR, (text == null ? 0 : textIconGap)); /* The preferred size of the button is the size of * the text and icon rectangles plus the buttons insets. */ Rectangle r = iconR.union(textR); // if (b.isBorderPainted()) { Insets insets = b.getInsets(); r.width += insets.left + insets.right; r.height += insets.top + insets.bottom; // } if (!QuaquaUtilities.isSmallSizeVariant(b) && style.equals("push") && b.getIcon() == null && b.getText() != null) { r.width = Math.max(r.width, UIManager.getInt("Button.minimumWidth")); } return r.getSize(); }