Java Code Examples for javax.swing.plaf.synth.SynthGraphicsUtils

The following examples show how to use javax.swing.plaf.synth.SynthGraphicsUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: openjdk-jdk9   Source File: bug8081411.java    License: GNU General Public License v2.0 6 votes vote down vote up
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!");
    }
}
 
Example 2
Source Project: seaglass   Source File: SeaGlassButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 3
Source Project: netbeans   Source File: ToolbarContainer.java    License: Apache License 2.0 5 votes vote down vote up
/** 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);
}
 
Example 4
Source Project: openjdk-jdk9   Source File: bug8081411.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
    }
 
Example 5
Source Project: seaglass   Source File: SeaGlassMenuItemLayoutHelper.java    License: Apache License 2.0 4 votes vote down vote up
public SynthGraphicsUtils getGraphicsUtils() {
    return gu;
}
 
Example 6
Source Project: seaglass   Source File: SeaGlassMenuItemLayoutHelper.java    License: Apache License 2.0 4 votes vote down vote up
public SynthGraphicsUtils getAccGraphicsUtils() {
    return accGu;
}
 
Example 7
Source Project: seaglass   Source File: SeaGlassInternalFrameTitlePane.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @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);
}
 
Example 8
Source Project: seaglass   Source File: SeaGlassTitlePane.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @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);
}
 
Example 9
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 4 votes vote down vote up
@Override public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
  return style.getGraphicsUtils(context);
}
 
Example 10
Source Project: seaglass   Source File: SeaGlassStyleWrapper.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns the <code>SynthGraphicUtils</code> for the specified context.
 *
 * @param  context SynthContext identifying requester
 *
 * @return SynthGraphicsUtils
 */
public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
    return SEAGLASS_GRAPHICS;
}
 
Example 11
Source Project: seaglass   Source File: SeaGlassStyle.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns the <code>SynthGraphicUtils</code> for the specified context.
 *
 * @param  context SynthContext identifying requester
 *
 * @return SynthGraphicsUtils
 */
public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
    return SEAGLASS_GRAPHICS;
}