类javax.swing.plaf.synth.SynthGraphicsUtils源码实例Demo

下面列出了怎么用javax.swing.plaf.synth.SynthGraphicsUtils的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-jdk9   文件: bug8081411.java
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!");
    }
}
 
源代码2 项目: seaglass   文件: SeaGlassButtonUI.java
/**
 * @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;
}
 
源代码3 项目: netbeans   文件: ToolbarContainer.java
/** 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);
}
 
源代码4 项目: openjdk-jdk9   文件: bug8081411.java
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);
    }
 
源代码5 项目: seaglass   文件: SeaGlassMenuItemLayoutHelper.java
public SynthGraphicsUtils getGraphicsUtils() {
    return gu;
}
 
源代码6 项目: seaglass   文件: SeaGlassMenuItemLayoutHelper.java
public SynthGraphicsUtils getAccGraphicsUtils() {
    return accGu;
}
 
源代码7 项目: seaglass   文件: SeaGlassInternalFrameTitlePane.java
/**
 * @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);
}
 
源代码8 项目: seaglass   文件: SeaGlassTitlePane.java
/**
 * @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);
}
 
源代码9 项目: java-swing-tips   文件: MainPanel.java
@Override public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
  return style.getGraphicsUtils(context);
}
 
源代码10 项目: seaglass   文件: SeaGlassStyleWrapper.java
/**
 * Returns the <code>SynthGraphicUtils</code> for the specified context.
 *
 * @param  context SynthContext identifying requester
 *
 * @return SynthGraphicsUtils
 */
public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
    return SEAGLASS_GRAPHICS;
}
 
源代码11 项目: seaglass   文件: SeaGlassStyle.java
/**
 * Returns the <code>SynthGraphicUtils</code> for the specified context.
 *
 * @param  context SynthContext identifying requester
 *
 * @return SynthGraphicsUtils
 */
public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
    return SEAGLASS_GRAPHICS;
}
 
 类所在包
 类方法
 同包方法