Search in sources :

Example 1 with Painter

use of javax.swing.Painter in project jdk8u_jdk by JetBrains.

the class SynthPainterImpl method paintBackground.

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);
        }
    }
}
Also used : Painter(javax.swing.Painter) SynthPainter(javax.swing.plaf.synth.SynthPainter)

Example 2 with Painter

use of javax.swing.Painter in project jdk8u_jdk by JetBrains.

the class TableScrollPaneCorner method paintComponent.

/**
     * Paint the component using the Nimbus Table Header Background Painter
     */
@Override
protected void paintComponent(Graphics g) {
    Painter painter = (Painter) UIManager.get("TableHeader:\"TableHeader.renderer\"[Enabled].backgroundPainter");
    if (painter != null) {
        if (g instanceof Graphics2D) {
            painter.paint((Graphics2D) g, this, getWidth() + 1, getHeight());
        } else {
            // paint using image to not Graphics2D to support
            // Java 1.1 printing API
            BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = (Graphics2D) img.getGraphics();
            painter.paint(g2, this, getWidth() + 1, getHeight());
            g2.dispose();
            g.drawImage(img, 0, 0, null);
            img = null;
        }
    }
}
Also used : Painter(javax.swing.Painter) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 3 with Painter

use of javax.swing.Painter in project jdk8u_jdk by JetBrains.

the class NimbusStyle method getForegroundPainter.

/**
     * Gets the appropriate foreground Painter, if there is one, for the state
     * specified in the given SynthContext. This method does appropriate
     * fallback searching, as described in #get.
     *
     * @param ctx The SynthContext. Must not be null.
     * @return The foreground painter associated for the given state, or null if
     * none could be found.
     */
public Painter getForegroundPainter(SynthContext ctx) {
    Values v = getValues(ctx);
    int xstate = getExtendedState(ctx, v);
    Painter p = null;
    // check the cache
    tmpKey.init("foregroundPainter$$instance", xstate);
    p = (Painter) v.cache.get(tmpKey);
    if (p != null)
        return p;
    // not in cache, so lookup and store in cache
    RuntimeState s = null;
    int[] lastIndex = new int[] { -1 };
    while ((s = getNextState(v.states, lastIndex, xstate)) != null) {
        if (s.foregroundPainter != null) {
            p = s.foregroundPainter;
            break;
        }
    }
    if (p == null)
        p = (Painter) get(ctx, "foregroundPainter");
    if (p != null) {
        v.cache.put(new CacheKey("foregroundPainter$$instance", xstate), p);
    }
    return p;
}
Also used : Painter(javax.swing.Painter) SynthPainter(javax.swing.plaf.synth.SynthPainter)

Example 4 with Painter

use of javax.swing.Painter in project jdk8u_jdk by JetBrains.

the class NimbusStyle method getBorderPainter.

/**
     * Gets the appropriate border Painter, if there is one, for the state
     * specified in the given SynthContext. This method does appropriate
     * fallback searching, as described in #get.
     *
     * @param ctx The SynthContext. Must not be null.
     * @return The border painter associated for the given state, or null if
     * none could be found.
     */
public Painter getBorderPainter(SynthContext ctx) {
    Values v = getValues(ctx);
    int xstate = getExtendedState(ctx, v);
    Painter p = null;
    // check the cache
    tmpKey.init("borderPainter$$instance", xstate);
    p = (Painter) v.cache.get(tmpKey);
    if (p != null)
        return p;
    // not in cache, so lookup and store in cache
    RuntimeState s = null;
    int[] lastIndex = new int[] { -1 };
    while ((s = getNextState(v.states, lastIndex, xstate)) != null) {
        if (s.borderPainter != null) {
            p = s.borderPainter;
            break;
        }
    }
    if (p == null)
        p = (Painter) get(ctx, "borderPainter");
    if (p != null) {
        v.cache.put(new CacheKey("borderPainter$$instance", xstate), p);
    }
    return p;
}
Also used : Painter(javax.swing.Painter) SynthPainter(javax.swing.plaf.synth.SynthPainter)

Example 5 with Painter

use of javax.swing.Painter in project jdk8u_jdk by JetBrains.

the class NimbusStyle method getBackgroundPainter.

/**
     * Gets the appropriate background Painter, if there is one, for the state
     * specified in the given SynthContext. This method does appropriate
     * fallback searching, as described in #get.
     *
     * @param ctx The SynthContext. Must not be null.
     * @return The background painter associated for the given state, or null if
     * none could be found.
     */
public Painter getBackgroundPainter(SynthContext ctx) {
    Values v = getValues(ctx);
    int xstate = getExtendedState(ctx, v);
    Painter p = null;
    // check the cache
    tmpKey.init("backgroundPainter$$instance", xstate);
    p = (Painter) v.cache.get(tmpKey);
    if (p != null)
        return p;
    // not in cache, so lookup and store in cache
    RuntimeState s = null;
    int[] lastIndex = new int[] { -1 };
    while ((s = getNextState(v.states, lastIndex, xstate)) != null) {
        if (s.backgroundPainter != null) {
            p = s.backgroundPainter;
            break;
        }
    }
    if (p == null)
        p = (Painter) get(ctx, "backgroundPainter");
    if (p != null) {
        v.cache.put(new CacheKey("backgroundPainter$$instance", xstate), p);
    }
    return p;
}
Also used : Painter(javax.swing.Painter) SynthPainter(javax.swing.plaf.synth.SynthPainter)

Aggregations

Painter (javax.swing.Painter)7 SynthPainter (javax.swing.plaf.synth.SynthPainter)4 BufferedImage (java.awt.image.BufferedImage)2 Graphics2D (java.awt.Graphics2D)1 UIResource (javax.swing.plaf.UIResource)1