de.javasoft.plaf.synthetica.painter
Class SyntheticaBasicIconPainter

java.lang.Object
  extended by sun.swing.plaf.synth.SynthIcon
      extended by de.javasoft.plaf.synthetica.painter.SyntheticaBasicIconPainter
All Implemented Interfaces:
javax.swing.Icon, javax.swing.plaf.UIResource

public class SyntheticaBasicIconPainter
extends sun.swing.plaf.synth.SynthIcon

A basic class to paint Java2D icons.

Version:
1.11, 21.09.2011

Nested Class Summary
static class Cacheable.ScaleType
           
 
Constructor Summary
SyntheticaBasicIconPainter()
          Constructor for 16x16 pixel icon.
SyntheticaBasicIconPainter(javax.swing.plaf.synth.SynthContext sc, int width, int height)
          Constructor.
 
Method Summary
protected  java.awt.geom.Rectangle2D.Float calc2DBounds(java.awt.Graphics2D g2, float w, float h)
          Calculates outer shape bounds in respect of the stroke width.
protected  java.awt.Paint createLinearGradientPaint(float startX, float startY, float endX, float endY, float[] fractions, java.awt.Color[] colors)
          Convenient method to create a LinearGradientPaint for Java 1.5 and Java 6.
protected  java.awt.BasicStroke createStroke(javax.swing.plaf.synth.SynthContext sc)
          Creates the stroke used for Java2D painting.
 int getCacheHash(javax.swing.plaf.synth.SynthContext sc, int w, int h, int meta, java.lang.String id)
          Returns a cache hash value which is used by SyntheticaSoftCache.
 java.awt.Insets getCacheScaleInsets(javax.swing.plaf.synth.SynthContext sc, java.lang.String id)
          Returns the insets in case of 9 square scaling is used.
 Cacheable.ScaleType getCacheScaleType(java.lang.String id)
          Returns the scaling type which will be used for scaling.
 int getIconHeight()
           
 int getIconHeight(javax.swing.plaf.synth.SynthContext sc)
           
 int getIconWidth()
           
 int getIconWidth(javax.swing.plaf.synth.SynthContext sc)
           
protected  float getScale()
          Returns the current scale factor.
protected  java.awt.Color getSyntheticaBackgroundColor(javax.swing.JComponent c)
          Helper method to create the Synthetica background color with alpha value provided by client properties "Synthetica.background" and "Synthetica.background.alpha".
 void paint2D(javax.swing.plaf.synth.SynthContext sc, java.awt.Graphics2D g2, float x, float y, float w, float h)
          Paint non-scaled icon with Java2D.
 void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
           
 void paintIcon(javax.swing.plaf.synth.SynthContext sc, java.awt.Graphics g, int x, int y, int w, int h)
           
protected static java.awt.Shape subtractStroke(java.awt.Graphics2D g2, java.awt.Shape s)
          Helper method to subtract the stroke from the given shape.
 
Methods inherited from class sun.swing.plaf.synth.SynthIcon
getIconHeight, getIconWidth, paintIcon
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyntheticaBasicIconPainter

public SyntheticaBasicIconPainter()
Constructor for 16x16 pixel icon.


SyntheticaBasicIconPainter

public SyntheticaBasicIconPainter(javax.swing.plaf.synth.SynthContext sc,
                                  int width,
                                  int height)
Constructor.

Parameters:
sc - SynthContext - can be null.
width - The icon width.
height - The icon height.
Method Detail

getScale

protected float getScale()
Returns the current scale factor.


createStroke

protected java.awt.BasicStroke createStroke(javax.swing.plaf.synth.SynthContext sc)
Creates the stroke used for Java2D painting.


getIconHeight

public int getIconHeight()
Specified by:
getIconHeight in interface javax.swing.Icon

getIconWidth

public int getIconWidth()
Specified by:
getIconWidth in interface javax.swing.Icon

paintIcon

public void paintIcon(java.awt.Component c,
                      java.awt.Graphics g,
                      int x,
                      int y)
Specified by:
paintIcon in interface javax.swing.Icon

paintIcon

public void paintIcon(javax.swing.plaf.synth.SynthContext sc,
                      java.awt.Graphics g,
                      int x,
                      int y,
                      int w,
                      int h)

paint2D

public void paint2D(javax.swing.plaf.synth.SynthContext sc,
                    java.awt.Graphics2D g2,
                    float x,
                    float y,
                    float w,
                    float h)
Paint non-scaled icon with Java2D. Default implementation does nothing. Override and implement painting code. Width and height returns original values minus 1 which is useful because the stroke line width is 1 in most cases. If a custom stroke is used the helper method calc2DBounds(Graphics2D, float, float) can be used to calculate x,y,w,h in respect of the stroke line width.

Parameters:
sc - SynthContext - can be null.
g2 - Graphics.
x - Original non-scaled X-position. If paint2D(SynthContext, Graphics2D, float, float, float, float) isn't overridden the X-position can be ignored because point of origin is translated to X,Y by the default implementation.
y - Original non-scaled Y-position. If paint2D(SynthContext, Graphics2D, float, float, float, float) isn't overridden the Y-position can be ignored because point of origin is translated to X,Y by the default implementation.
w - Non-scaled width-1.
h - Non-scaled height-1.
See Also:
calc2DBounds(Graphics2D, float, float)

calc2DBounds

protected java.awt.geom.Rectangle2D.Float calc2DBounds(java.awt.Graphics2D g2,
                                                       float w,
                                                       float h)
Calculates outer shape bounds in respect of the stroke width.

Parameters:
w - Non-scaled width-1.
h - Non-scaled height-1.

subtractStroke

protected static java.awt.Shape subtractStroke(java.awt.Graphics2D g2,
                                               java.awt.Shape s)
Helper method to subtract the stroke from the given shape.

Parameters:
g2 - Graphics.
s - The shape.
Returns:
The shape without stroke.

getSyntheticaBackgroundColor

protected java.awt.Color getSyntheticaBackgroundColor(javax.swing.JComponent c)
Helper method to create the Synthetica background color with alpha value provided by client properties "Synthetica.background" and "Synthetica.background.alpha". If background client property isn't set null will be returned.

Parameters:
c - The relevant JComponent.
Returns:
The background color including alpha value or null

createLinearGradientPaint

protected java.awt.Paint createLinearGradientPaint(float startX,
                                                   float startY,
                                                   float endX,
                                                   float endY,
                                                   float[] fractions,
                                                   java.awt.Color[] colors)
Convenient method to create a LinearGradientPaint for Java 1.5 and Java 6.

See Also:
SyntheticaLookAndFeel.createLinearGradientPaint(float, float, float, float, float[], Color[])

getCacheHash

public int getCacheHash(javax.swing.plaf.synth.SynthContext sc,
                        int w,
                        int h,
                        int meta,
                        java.lang.String id)
Returns a cache hash value which is used by SyntheticaSoftCache. The hash value has to represent every single paint attribute which is used by the painter class which implements the Cacheable interface.

Parameters:
sc - The synth context
w - The paint width
h - The paint height
meta - A context related meta value
id - Usually the relevant painter method name
Returns:
The hash value or -1 for non-cacheable

getCacheScaleType

public Cacheable.ScaleType getCacheScaleType(java.lang.String id)
Returns the scaling type which will be used for scaling.

Parameters:
id - Usually the relevant painter method name
Returns:
The scaling type

getCacheScaleInsets

public java.awt.Insets getCacheScaleInsets(javax.swing.plaf.synth.SynthContext sc,
                                           java.lang.String id)
Returns the insets in case of 9 square scaling is used.

Parameters:
sc - The synth context
id - Usually the relevant painter method name
Returns:
The image insets used for 9 square scaling

getIconWidth

public int getIconWidth(javax.swing.plaf.synth.SynthContext sc)
Specified by:
getIconWidth in class sun.swing.plaf.synth.SynthIcon

getIconHeight

public int getIconHeight(javax.swing.plaf.synth.SynthContext sc)
Specified by:
getIconHeight in class sun.swing.plaf.synth.SynthIcon


Copyright © 2004-2011 Jyloo Software. All Rights Reserved.