private static void paintAndCheckIcon(Icon icon, SynthContext synthContext, int width, int height) { BufferedImage buffImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = buffImage.createGraphics(); g.setColor(Color.RED); g.fillRect(0, 0, width, height); SynthGraphicsUtils.paintIcon(icon, synthContext, g, 0, 0, width, height); g.dispose(); Color iconCenterColor = new Color(buffImage.getRGB(width / 2, height / 2)); if (!TEST_COLOR.equals(iconCenterColor)) { throw new RuntimeException("Icon is painted incorrectly!"); } }
/** * @see javax.swing.plaf.basic.BasicButtonUI#getPreferredSize(javax.swing.JComponent) */ public Dimension getPreferredSize(JComponent c) { if (c.getComponentCount() > 0 && c.getLayout() != null) { return null; } AbstractButton b = (AbstractButton) c; SeaGlassContext ss = getContext(c); SynthStyle style2 = ss.getStyle(); SynthGraphicsUtils graphicsUtils = style2.getGraphicsUtils(ss); Dimension size = graphicsUtils.getPreferredSize(ss, style2.getFont(ss), b.getText(), getSizingIcon(b), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), b.getIconTextGap(), b.getDisplayedMnemonicIndex()); ss.dispose(); // Make height odd. size.height &= ~1; return size; }
/** Paint bumps to specific Graphics. */ @Override public void paint (Graphics g) { Icon icon = UIManager.getIcon("ToolBar.handleIcon"); Region region = Region.TOOL_BAR; SynthStyleFactory sf = SynthLookAndFeel.getStyleFactory(); SynthStyle style = sf.getStyle(toolbar, region); SynthContext context = new SynthContext(toolbar, region, style, SynthConstants.DEFAULT); SynthGraphicsUtils sgu = context.getStyle().getGraphicsUtils(context); sgu.paintText(context, g, null, icon, SwingConstants.LEADING, SwingConstants.LEADING, 0, 0, 0, -1, 0); }
private static void testSynthIcon() { if (!checkAndSetNimbusLookAndFeel()) { return; } JMenuItem menu = new JMenuItem(); Icon subMenuIcon = UIManager.getIcon("Menu.arrowIcon"); if (!(subMenuIcon instanceof SynthIcon)) { throw new RuntimeException("Icon is not a SynthIcon!"); } Region region = SynthLookAndFeel.getRegion(menu); SynthStyle style = SynthLookAndFeel.getStyle(menu, region); SynthContext synthContext = new SynthContext(menu, region, style, SynthConstants.ENABLED); int width = SynthGraphicsUtils.getIconWidth(subMenuIcon, synthContext); int height = SynthGraphicsUtils.getIconHeight(subMenuIcon, synthContext); paintAndCheckIcon(subMenuIcon, synthContext, width, height); int newWidth = width * 17; int newHeight = height * 37; Icon centeredIcon = new CenteredSynthIcon((SynthIcon) subMenuIcon, newWidth, newHeight); paintAndCheckIcon(centeredIcon, synthContext, newWidth, newHeight); }
public SynthGraphicsUtils getGraphicsUtils() { return gu; }
public SynthGraphicsUtils getAccGraphicsUtils() { return accGu; }
/** * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container) */ public Dimension minimumLayoutSize(Container c) { SeaGlassContext context = getContext(SeaGlassInternalFrameTitlePane.this); int width = 8; int height = 0; int buttonCount = 0; Dimension pref; if (frame.isClosable()) { pref = closeButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); buttonCount++; } if (frame.isMaximizable()) { pref = maxButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); buttonCount++; } if (frame.isIconifiable()) { pref = iconButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); buttonCount++; } pref = menuButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); FontMetrics fm = SeaGlassInternalFrameTitlePane.this.getFontMetrics(getFont()); SynthGraphicsUtils graphicsUtils = context.getStyle().getGraphicsUtils(context); String frameTitle = frame.getTitle(); int title_w = frameTitle != null ? graphicsUtils.computeStringWidth(context, fm.getFont(), fm, frameTitle) : 0; int title_length = frameTitle != null ? frameTitle.length() : 0; // Leave room for three characters in the title. if (title_length > 3) { int subtitle_w = graphicsUtils.computeStringWidth(context, fm.getFont(), fm, frameTitle.substring(0, 3) + "..."); width += (title_w < subtitle_w) ? title_w : subtitle_w; } else { width += title_w; } height = Math.max(fm.getHeight() + 2, height); width += titleSpacing + titleSpacing; Insets insets = getInsets(); height += insets.top + insets.bottom; width += insets.left + insets.right; context.dispose(); return new Dimension(width, height); }
/** * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container) */ public Dimension minimumLayoutSize(Container c) { SeaGlassContext context = getContext(SeaGlassTitlePane.this); int width = 10; int height = FrameAndRootPainter.TITLE_BAR_HEIGHT; int buttonCount = 0; Dimension pref; if (isParentClosable()) { pref = closeButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); buttonCount++; } if (isParentMaximizable()) { pref = maxButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); buttonCount++; } if (isParentIconifiable()) { pref = iconButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); buttonCount++; } pref = menuButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); FontMetrics fm = getFontMetrics(getFont()); SynthGraphicsUtils graphicsUtils = context.getStyle().getGraphicsUtils(context); String frameTitle = getTitle(); int title_w = frameTitle != null ? graphicsUtils.computeStringWidth(context, fm.getFont(), fm, frameTitle) : 0; int title_length = frameTitle != null ? frameTitle.length() : 0; // Leave room for three characters in the title. if (title_length > 3) { int subtitle_w = graphicsUtils.computeStringWidth(context, fm.getFont(), fm, frameTitle.substring(0, 3) + "..."); width += (title_w < subtitle_w) ? title_w : subtitle_w; } else { width += title_w; } height = Math.max(fm.getHeight(), height); width += titleSpacing + titleSpacing; Insets insets = getInsets(); height += insets.top + insets.bottom; width += insets.left + insets.right; context.dispose(); return new Dimension(width, height); }
/** * Returns the <code>SynthGraphicUtils</code> for the specified context. * * @param context SynthContext identifying requester * * @return SynthGraphicsUtils */ public SynthGraphicsUtils getGraphicsUtils(SynthContext context) { return SEAGLASS_GRAPHICS; }