public Rectangle getVisualBounds(JComponent c, int type, int width, int height) { Rectangle bounds = new Rectangle(0, 0, width, height); if (type == VisuallyLayoutable.CLIP_BOUNDS) { return bounds; } AbstractButton b = (AbstractButton) c; if (type == VisuallyLayoutable.COMPONENT_BOUNDS && b.getBorder() != null && b.isBorderPainted()) { Border border = b.getBorder(); if (border instanceof BackgroundBorder) { border = ((BackgroundBorder) border).getBackgroundBorder(); if (border instanceof VisualMargin) { InsetsUtil.subtractInto(((VisualMargin) border).getVisualMargin(c), bounds); } else if (border instanceof QuaquaButtonBorder) { InsetsUtil.subtractInto(((QuaquaButtonBorder) border).getVisualMargin(c), bounds); } } return bounds; } String text = b.getText(); boolean isEmpty = (text == null || text.length() == 0); if (isEmpty) { text = " "; } Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon(); if ((icon == null) && (text == null)) { return null; } FontMetrics fm = c.getFontMetrics(c.getFont()); Insets insets = c.getInsets(viewInsets); viewR.x = insets.left; viewR.y = insets.top; viewR.width = width - (insets.left + insets.right); viewR.height = height - (insets.top + insets.bottom); iconR.x = iconR.y = iconR.width = iconR.height = 0; textR.x = textR.y = textR.width = textR.height = 0; String clippedText = layoutCL(b, fm, text, icon, viewR, iconR, textR); Rectangle textBounds = Fonts.getPerceivedBounds(text, c.getFont(), c); if (isEmpty) { textBounds.width = 0; } int ascent = fm.getAscent(); textR.x += textBounds.x; textR.width = textBounds.width; textR.y += ascent + textBounds.y; textR.height -= fm.getHeight() - textBounds.height; bounds.setBounds(textR); return bounds; }
@Override public Dimension getMinimumSize(JComponent c) { AbstractButton b = (AbstractButton) c; String style = (String) c.getClientProperty("Quaqua.Button.style"); if (style == null) { style = "push"; } if (style.equals("help")) { return getPreferredSize(c); } Dimension d = super.getMinimumSize(c); if (isFixedHeight(c)) { Dimension p = getPreferredSize(c); if (d != null && p != null) { d.height = Math.max(d.height, p.height); } } if (!QuaquaUtilities.isSmallSizeVariant(c) && style.equals("push") // && b.getIcon() == null && b.getText() != null) { if (d != null) { d.width = Math.max(d.width, UIManager.getInt("Button.minimumWidth")); } } return d; }
private boolean isFixedHeight(JComponent c) { Border b = c.getBorder(); if (b != null && b instanceof BackgroundBorder) { b = ((BackgroundBorder) b).getBackgroundBorder(); if (b != null && b instanceof QuaquaButtonBorder) { return ((QuaquaButtonBorder) b).isFixedHeight(c); } } return false; }
@Override public Dimension getMaximumSize(JComponent c) { String style = (String) c.getClientProperty("Quaqua.Button.style"); if (style != null && style.equals("help")) { return getPreferredSize(c); } Dimension d = super.getMaximumSize(c); if (isFixedHeight(c)) { Dimension p = getPreferredSize(c); d.height = Math.max(d.height, p.height); } return d; }
@Override public void paint(Graphics g, JComponent c) { String style = (String) c.getClientProperty("Quaqua.Button.style"); if (style != null && style.equals("help")) { Insets insets = c.getInsets(); UIManager.getIcon("Button.helpIcon").paintIcon(c, g, insets.left, insets.top); return; } Object oldHints = QuaquaUtilities.beginGraphics((Graphics2D) g); if (((AbstractButton) c).isBorderPainted()) { Border b = c.getBorder(); if (b != null && b instanceof BackgroundBorder) { ((BackgroundBorder) b) .getBackgroundBorder() .paintBorder(c, g, 0, 0, c.getWidth(), c.getHeight()); } } super.paint(g, c); QuaquaUtilities.endGraphics((Graphics2D) g, oldHints); Debug.paint(g, c, this); }