Java Code Examples for javax.swing.plaf.synth.SynthContext#getComponent()

The following examples show how to use javax.swing.plaf.synth.SynthContext#getComponent() . 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: NimbusIcon.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: SeaGlassSynthPainterImpl.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 3
Source File: SeaGlassToolTipUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 4
Source File: NimbusIcon.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example 5
Source File: NimbusIcon.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: NimbusIcon.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example 7
Source File: NimbusIcon.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: NimbusIcon.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: NimbusIcon.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example 10
Source File: NimbusIcon.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example 11
Source File: NimbusIcon.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: NimbusIcon.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example 13
Source File: NimbusIcon.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example 14
Source File: SeaGlassIcon.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 15
Source File: SynthPainterImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 16
Source File: SynthPainterImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 17
Source File: SynthPainterImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 18
Source File: MSynthPainter.java    From swift-k with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 19
Source File: SynthPainterImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 20
Source File: SynthPainterImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
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);
        }
    }
}