javax.swing.plaf.synth.SynthContext#getComponent ( )源码实例Demo

下面列出了javax.swing.plaf.synth.SynthContext#getComponent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u-dev-jdk   文件: NimbusIcon.java
@Override
public int getIconHeight(SynthContext context) {
    if (context == null) {
        return height;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar){
        JToolBar toolbar = (JToolBar)c;
        if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
            //we only do the -1 hack for UIResource borders, assuming
            //that the border is probably going to be our border
            if (toolbar.getBorder() instanceof UIResource) {
                return c.getHeight() - 1;
            } else {
                return c.getHeight();
            }
        } else {
            return scale(context, width);
        }
    } else {
        return scale(context, height);
    }
}
 
源代码2 项目: openjdk-jdk9   文件: NimbusIcon.java
@Override
public int getIconHeight(SynthContext context) {
    if (context == null) {
        return height;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar){
        JToolBar toolbar = (JToolBar)c;
        if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
            //we only do the -1 hack for UIResource borders, assuming
            //that the border is probably going to be our border
            if (toolbar.getBorder() instanceof UIResource) {
                return c.getHeight() - 1;
            } else {
                return c.getHeight();
            }
        } else {
            return scale(context, width);
        }
    } else {
        return scale(context, height);
    }
}
 
源代码3 项目: openjdk-jdk8u   文件: NimbusIcon.java
/**
 * Scale a size based on the "JComponent.sizeVariant" client property of the
 * component that is using this icon
 *
 * @param context The synthContext to get the component from
 * @param size The size to scale
 * @return The scaled size or original if "JComponent.sizeVariant" is not
 *          set
 */
private int scale(SynthContext context, int size) {
    if (context == null || context.getComponent() == null){
        return size;
    }
    // The key "JComponent.sizeVariant" is used to match Apple's LAF
    String scaleKey = (String) context.getComponent().getClientProperty(
            "JComponent.sizeVariant");
    if (scaleKey != null) {
        if (NimbusStyle.LARGE_KEY.equals(scaleKey)) {
            size *= NimbusStyle.LARGE_SCALE;
        } else if (NimbusStyle.SMALL_KEY.equals(scaleKey)) {
            size *= NimbusStyle.SMALL_SCALE;
        } else if (NimbusStyle.MINI_KEY.equals(scaleKey)) {
            // mini is not quite as small for icons as full mini is
            // just too tiny
            size *= NimbusStyle.MINI_SCALE + 0.07;
        }
    }
    return size;
}
 
源代码4 项目: dragonwell8_jdk   文件: NimbusIcon.java
@Override
public int getIconWidth(SynthContext context) {
    if (context == null) {
        return width;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar && ((JToolBar)c).getOrientation() == JToolBar.VERTICAL) {
        //we only do the -1 hack for UIResource borders, assuming
        //that the border is probably going to be our border
        if (c.getBorder() instanceof UIResource) {
            return c.getWidth() - 1;
        } else {
            return c.getWidth();
        }
    } else {
        return scale(context, width);
    }
}
 
源代码5 项目: dragonwell8_jdk   文件: NimbusIcon.java
@Override
public int getIconHeight(SynthContext context) {
    if (context == null) {
        return height;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar){
        JToolBar toolbar = (JToolBar)c;
        if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
            //we only do the -1 hack for UIResource borders, assuming
            //that the border is probably going to be our border
            if (toolbar.getBorder() instanceof UIResource) {
                return c.getHeight() - 1;
            } else {
                return c.getHeight();
            }
        } else {
            return scale(context, width);
        }
    } else {
        return scale(context, height);
    }
}
 
源代码6 项目: openjdk-8-source   文件: NimbusIcon.java
/**
 * Scale a size based on the "JComponent.sizeVariant" client property of the
 * component that is using this icon
 *
 * @param context The synthContext to get the component from
 * @param size The size to scale
 * @return The scaled size or original if "JComponent.sizeVariant" is not
 *          set
 */
private int scale(SynthContext context, int size) {
    if (context == null || context.getComponent() == null){
        return size;
    }
    // The key "JComponent.sizeVariant" is used to match Apple's LAF
    String scaleKey = (String) context.getComponent().getClientProperty(
            "JComponent.sizeVariant");
    if (scaleKey != null) {
        if (NimbusStyle.LARGE_KEY.equals(scaleKey)) {
            size *= NimbusStyle.LARGE_SCALE;
        } else if (NimbusStyle.SMALL_KEY.equals(scaleKey)) {
            size *= NimbusStyle.SMALL_SCALE;
        } else if (NimbusStyle.MINI_KEY.equals(scaleKey)) {
            // mini is not quite as small for icons as full mini is
            // just too tiny
            size *= NimbusStyle.MINI_SCALE + 0.07;
        }
    }
    return size;
}
 
源代码7 项目: Bytecoder   文件: NimbusIcon.java
/**
 * Scale a size based on the "JComponent.sizeVariant" client property of the
 * component that is using this icon
 *
 * @param context The synthContext to get the component from
 * @param size The size to scale
 * @return The scaled size or original if "JComponent.sizeVariant" is not
 *          set
 */
private int scale(SynthContext context, int size) {
    if (context == null || context.getComponent() == null){
        return size;
    }
    // The key "JComponent.sizeVariant" is used to match Apple's LAF
    String scaleKey = (String) context.getComponent().getClientProperty(
            "JComponent.sizeVariant");
    if (scaleKey != null) {
        if (NimbusStyle.LARGE_KEY.equals(scaleKey)) {
            size *= NimbusStyle.LARGE_SCALE;
        } else if (NimbusStyle.SMALL_KEY.equals(scaleKey)) {
            size *= NimbusStyle.SMALL_SCALE;
        } else if (NimbusStyle.MINI_KEY.equals(scaleKey)) {
            // mini is not quite as small for icons as full mini is
            // just too tiny
            size *= NimbusStyle.MINI_SCALE + 0.07;
        }
    }
    return size;
}
 
源代码8 项目: Java8CN   文件: NimbusIcon.java
@Override
public int getIconWidth(SynthContext context) {
    if (context == null) {
        return width;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar && ((JToolBar)c).getOrientation() == JToolBar.VERTICAL) {
        //we only do the -1 hack for UIResource borders, assuming
        //that the border is probably going to be our border
        if (c.getBorder() instanceof UIResource) {
            return c.getWidth() - 1;
        } else {
            return c.getWidth();
        }
    } else {
        return scale(context, width);
    }
}
 
源代码9 项目: jdk8u60   文件: NimbusIcon.java
@Override
public int getIconHeight(SynthContext context) {
    if (context == null) {
        return height;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar){
        JToolBar toolbar = (JToolBar)c;
        if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
            //we only do the -1 hack for UIResource borders, assuming
            //that the border is probably going to be our border
            if (toolbar.getBorder() instanceof UIResource) {
                return c.getHeight() - 1;
            } else {
                return c.getHeight();
            }
        } else {
            return scale(context, width);
        }
    } else {
        return scale(context, height);
    }
}
 
源代码10 项目: jdk8u60   文件: NimbusIcon.java
/**
 * Scale a size based on the "JComponent.sizeVariant" client property of the
 * component that is using this icon
 *
 * @param context The synthContext to get the component from
 * @param size The size to scale
 * @return The scaled size or original if "JComponent.sizeVariant" is not
 *          set
 */
private int scale(SynthContext context, int size) {
    if (context == null || context.getComponent() == null){
        return size;
    }
    // The key "JComponent.sizeVariant" is used to match Apple's LAF
    String scaleKey = (String) context.getComponent().getClientProperty(
            "JComponent.sizeVariant");
    if (scaleKey != null) {
        if (NimbusStyle.LARGE_KEY.equals(scaleKey)) {
            size *= NimbusStyle.LARGE_SCALE;
        } else if (NimbusStyle.SMALL_KEY.equals(scaleKey)) {
            size *= NimbusStyle.SMALL_SCALE;
        } else if (NimbusStyle.MINI_KEY.equals(scaleKey)) {
            // mini is not quite as small for icons as full mini is
            // just too tiny
            size *= NimbusStyle.MINI_SCALE + 0.07;
        }
    }
    return size;
}
 
源代码11 项目: jdk8u-jdk   文件: NimbusIcon.java
@Override
public int getIconHeight(SynthContext context) {
    if (context == null) {
        return height;
    }
    JComponent c = context.getComponent();
    if (c instanceof JToolBar){
        JToolBar toolbar = (JToolBar)c;
        if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
            //we only do the -1 hack for UIResource borders, assuming
            //that the border is probably going to be our border
            if (toolbar.getBorder() instanceof UIResource) {
                return c.getHeight() - 1;
            } else {
                return c.getHeight();
            }
        } else {
            return scale(context, width);
        }
    } else {
        return scale(context, height);
    }
}
 
源代码12 项目: seaglass   文件: SeaGlassToolTipUI.java
/**
 * Paints the specified component.
 *
 * @param context
 *            context for the component being painted
 * @param g
 *            the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    JToolTip tip = (JToolTip) context.getComponent();

    Insets insets = tip.getInsets();
    View v = (View) tip.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        Rectangle paintTextR = new Rectangle(insets.left, insets.top, tip.getWidth() - (insets.left + insets.right), tip.getHeight()
                - (insets.top + insets.bottom));
        v.paint(g, paintTextR);
    } else {
        g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
        g.setFont(style.getFont(context));
        context.getStyle().getGraphicsUtils(context).paintText(context, g, tip.getTipText(), insets.left, insets.top, -1);
    }
}
 
源代码13 项目: seaglass   文件: SeaGlassSynthPainterImpl.java
/**
 * Paint the object's background.
 *
 * @param ctx       the SynthContext.
 * @param g         the Graphics context.
 * @param x         the x location corresponding to the upper-left
 *                  coordinate to paint.
 * @param y         the y location corresponding to the upper left
 *                  coordinate to paint.
 * @param w         the width to paint.
 * @param h         the height to paint.
 * @param transform the affine transform to apply, or {@code null} if none
 *                  is to be applied.
 */
private void paintBackground(SynthContext ctx, Graphics g, int x, int y, int w, int h, AffineTransform transform) {
    // if the background color of the component is 100% transparent
    // then we should not paint any background graphics. This is a solution
    // for there being no way of turning off Nimbus background painting as
    // basic components are all non-opaque by default.
    Component c  = ctx.getComponent();
    Color     bg = (c != null) ? c.getBackground() : null;

    if (bg == null || bg.getAlpha() > 0) {
        SeaGlassPainter backgroundPainter = style.getBackgroundPainter(ctx);

        if (backgroundPainter != null) {
            paint(backgroundPainter, ctx, g, x, y, w, h, transform);
        }
    }
}
 
源代码14 项目: jdk1.8-source-analysis   文件: SynthPainterImpl.java
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
                             int w, int h, AffineTransform transform) {
    // if the background color of the component is 100% transparent
    // then we should not paint any background graphics. This is a solution
    // for there being no way of turning off Nimbus background painting as
    // basic components are all non-opaque by default.
    Component c = ctx.getComponent();
    Color bg = (c != null) ? c.getBackground() : null;
    if (bg == null || bg.getAlpha() > 0){
        Painter backgroundPainter = style.getBackgroundPainter(ctx);
        if (backgroundPainter != null) {
            paint(backgroundPainter, ctx, g, x, y, w, h,transform);
        }
    }
}
 
源代码15 项目: dragonwell8_jdk   文件: SynthPainterImpl.java
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
                             int w, int h, AffineTransform transform) {
    // if the background color of the component is 100% transparent
    // then we should not paint any background graphics. This is a solution
    // for there being no way of turning off Nimbus background painting as
    // basic components are all non-opaque by default.
    Component c = ctx.getComponent();
    Color bg = (c != null) ? c.getBackground() : null;
    if (bg == null || bg.getAlpha() > 0){
        Painter backgroundPainter = style.getBackgroundPainter(ctx);
        if (backgroundPainter != null) {
            paint(backgroundPainter, ctx, g, x, y, w, h,transform);
        }
    }
}
 
源代码16 项目: seaglass   文件: SeaGlassIcon.java
/**
 * Returns the icon's height. This is a cover method for <code>
 * getIconHeight(null)</code>.
 *
 * @param  context the SynthContext describing the component/region, the
 *                 style, and the state.
 *
 * @return an int specifying the fixed height of the icon.
 */
@Override
public int getIconHeight(SynthContext context) {
    if (context == null) {
        return height;
    }

    JComponent c = context.getComponent();

    if (c instanceof JToolBar) {
        JToolBar toolbar = (JToolBar) c;

        if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {

            // we only do the -1 hack for UIResource borders, assuming
            // that the border is probably going to be our border
            if (toolbar.getBorder() instanceof UIResource) {
                return c.getHeight() - 1;
            } else {
                return c.getHeight();
            }
        } else {
            return scale(context, width);
        }
    } else {
        return scale(context, height);
    }
}
 
源代码17 项目: openjdk-jdk8u   文件: SynthPainterImpl.java
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
                             int w, int h, AffineTransform transform) {
    // if the background color of the component is 100% transparent
    // then we should not paint any background graphics. This is a solution
    // for there being no way of turning off Nimbus background painting as
    // basic components are all non-opaque by default.
    Component c = ctx.getComponent();
    Color bg = (c != null) ? c.getBackground() : null;
    if (bg == null || bg.getAlpha() > 0){
        Painter backgroundPainter = style.getBackgroundPainter(ctx);
        if (backgroundPainter != null) {
            paint(backgroundPainter, ctx, g, x, y, w, h,transform);
        }
    }
}
 
源代码18 项目: jdk8u60   文件: SynthPainterImpl.java
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
                             int w, int h, AffineTransform transform) {
    // if the background color of the component is 100% transparent
    // then we should not paint any background graphics. This is a solution
    // for there being no way of turning off Nimbus background painting as
    // basic components are all non-opaque by default.
    Component c = ctx.getComponent();
    Color bg = (c != null) ? c.getBackground() : null;
    if (bg == null || bg.getAlpha() > 0){
        Painter backgroundPainter = style.getBackgroundPainter(ctx);
        if (backgroundPainter != null) {
            paint(backgroundPainter, ctx, g, x, y, w, h,transform);
        }
    }
}
 
源代码19 项目: swift-k   文件: MSynthPainter.java
@Override
public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h,
        int tabIndex, int orientation) {
    JTabbedPane t = (JTabbedPane) context.getComponent();
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (t.getSelectedIndex() == tabIndex) {
        g.setColor(BG);
    }
    else {
        g.setColor(INACTIVE);
    }
    g.fillRoundRect(x, y, w - 2, h, 5, 5);
    g.fillRect(x, y + 5, w - 2, h - 3);
}
 
源代码20 项目: JDKSourceCode1.8   文件: SynthPainterImpl.java
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
                             int w, int h, AffineTransform transform) {
    // if the background color of the component is 100% transparent
    // then we should not paint any background graphics. This is a solution
    // for there being no way of turning off Nimbus background painting as
    // basic components are all non-opaque by default.
    Component c = ctx.getComponent();
    Color bg = (c != null) ? c.getBackground() : null;
    if (bg == null || bg.getAlpha() > 0){
        Painter backgroundPainter = style.getBackgroundPainter(ctx);
        if (backgroundPainter != null) {
            paint(backgroundPainter, ctx, g, x, y, w, h,transform);
        }
    }
}
 
 同类方法