javax.swing.plaf.synth.SynthGraphicsUtils Java Examples

The following examples show how to use javax.swing.plaf.synth.SynthGraphicsUtils. 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 File: bug8081411.java    From openjdk-jdk9 with 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 File: SeaGlassButtonUI.java    From seaglass with 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 File: ToolbarContainer.java    From netbeans with 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 File: bug8081411.java    From openjdk-jdk9 with 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 File: SeaGlassMenuItemLayoutHelper.java    From seaglass with Apache License 2.0 4 votes vote down vote up
public SynthGraphicsUtils getGraphicsUtils() {
    return gu;
}
 
Example #6
Source File: SeaGlassMenuItemLayoutHelper.java    From seaglass with Apache License 2.0 4 votes vote down vote up
public SynthGraphicsUtils getAccGraphicsUtils() {
    return accGu;
}
 
Example #7
Source File: SeaGlassInternalFrameTitlePane.java    From seaglass with 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 File: SeaGlassTitlePane.java    From seaglass with 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 File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
@Override public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
  return style.getGraphicsUtils(context);
}
 
Example #10
Source File: SeaGlassStyleWrapper.java    From seaglass with 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 File: SeaGlassStyle.java    From seaglass with 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;
}