Search in sources :

Example 1 with ShadowRenderer

use of org.jdesktop.swingx.graphics.ShadowRenderer in project intellij-community by JetBrains.

the class ShadowBorderPainter method createShadow.

public static Shadow createShadow(Image source, int x, int y, boolean paintSource, int shadowSize) {
    source = ImageUtil.toBufferedImage(source);
    final float w = source.getWidth(null);
    final float h = source.getHeight(null);
    float ratio = w / h;
    float deltaX = shadowSize;
    float deltaY = shadowSize / ratio;
    final Image scaled = source.getScaledInstance((int) (w + deltaX), (int) (h + deltaY), Image.SCALE_SMOOTH);
    final BufferedImage s = GraphicsUtilities.createCompatibleTranslucentImage(scaled.getWidth(null), scaled.getHeight(null));
    final Graphics2D graphics = (Graphics2D) s.getGraphics();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.drawImage(scaled, 0, 0, null);
    final BufferedImage shadow = new ShadowRenderer(shadowSize, .25f, Gray.x00).createShadow(s);
    if (paintSource) {
        final Graphics imgG = shadow.getGraphics();
        final double d = shadowSize * 0.5;
        imgG.drawImage(source, (int) (shadowSize + d), (int) (shadowSize + d / ratio), null);
    }
    return new Shadow(shadow, x - shadowSize - 5, y - shadowSize + 2);
}
Also used : ShadowRenderer(org.jdesktop.swingx.graphics.ShadowRenderer) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

Example 2 with ShadowRenderer

use of org.jdesktop.swingx.graphics.ShadowRenderer in project intellij-community by JetBrains.

the class SheetController method initShadowImage.

private void initShadowImage() {
    final BufferedImage mySheetStencil = GraphicsUtilities.createCompatibleTranslucentImage(SHEET_WIDTH, SHEET_HEIGHT);
    Graphics2D g2 = mySheetStencil.createGraphics();
    g2.setColor(new JBColor(Gray._255, Gray._0));
    g2.fillRect(0, 0, SHEET_WIDTH, SHEET_HEIGHT);
    g2.dispose();
    ShadowRenderer renderer = new ShadowRenderer();
    renderer.setSize(SHADOW_BORDER);
    renderer.setOpacity(.80f);
    renderer.setColor(new JBColor(JBColor.BLACK, Gray._10));
    myShadowImage = renderer.createShadow(mySheetStencil);
}
Also used : ShadowRenderer(org.jdesktop.swingx.graphics.ShadowRenderer) JBColor(com.intellij.ui.JBColor) BufferedImage(java.awt.image.BufferedImage)

Aggregations

BufferedImage (java.awt.image.BufferedImage)2 ShadowRenderer (org.jdesktop.swingx.graphics.ShadowRenderer)2 JBColor (com.intellij.ui.JBColor)1