com.alee.extended.painter
Class AbstractPainter<E extends javax.swing.JComponent>

java.lang.Object
  extended by com.alee.extended.painter.AbstractPainter<E>
Type Parameters:
E - component type
All Implemented Interfaces:
Painter<E>
Direct Known Subclasses:
AdaptivePainter, AlphaLayerPainter, BorderPainter, ButtonPaintersExample.SeaGlassButtonPainter, ColorPainter, ComplexExample.ShadeBackgroundPainter, GenericCellEditorPainter, NinePatchIconPainter, NinePatchStatePainter, NPDecorationPainter, NPScrollBarButtonPainter, TexturePainter, WebBreadcrumbButtonPainter, WebBreadcrumbToggleButtonPainter, WebComponentPanel.WebSelectablePanelPainter, WebDecorationPainter, WebLabelPainter, WebPopupPainter, WebScrollBarButtonPainter, WebScrollBarPainter, WebStylePainter

public abstract class AbstractPainter<E extends javax.swing.JComponent>
extends java.lang.Object
implements Painter<E>

This abstract painter provides a few additional useful features atop of the Painter interface. Usually this class is extended by various painters instead of implementing Painter interface directly.

Author:
Mikle Garin
See Also:
Painter

Field Summary
protected  java.util.List<PainterListener> listeners
          Painter listeners.
protected  java.awt.Insets margin
          Visual data margin.
protected  java.lang.Boolean opaque
          Whether visual data is opaque or not.
protected  java.awt.Dimension preferredSize
          Visual data preferred size.
 
Constructor Summary
AbstractPainter()
           
 
Method Summary
 void addPainterListener(PainterListener listener)
          Adds new painter listener.
 java.awt.Insets getMargin(E c)
          Returns margin required for visual data provided by this painter.
 java.awt.Dimension getPreferredSize(E c)
          Returns preferred size required for proper painting of visual data provided by this painter.
 void install(E c)
          Called when painter is intalled into some component.
 java.lang.Boolean isOpaque(E c)
          Returns whether visual data provided by this painter is opaque or not.
protected  java.awt.Point p(int x, int y)
          Returns point for the specified coordinates.
 void removePainterListener(PainterListener listener)
          Removes painter listener.
 void repaint()
          Should be called when painter visual representation changes.
 void repaint(int x, int y, int width, int height)
          Should be called when part of painter visual representation changes.
 void repaint(java.awt.Rectangle bounds)
          Should be called when part of painter visual representation changes.
 void revalidate()
          Should be called when painter size or border changes.
 void setMargin(java.awt.Insets margin)
          Sets margin required for visual data provided by this painter.
 void setMargin(int margin)
          Sets margin required for visual data provided by this painter.
 void setMargin(int top, int left, int bottom, int right)
          Sets margin required for visual data provided by this painter.
 void setOpaque(java.lang.Boolean opaque)
          Sets whether visual data provided by this painter is opaque or not.
 void setPreferredSize(java.awt.Dimension preferredSize)
          Sets preferred size for visual data provided by this painter.
 void uninstall(E c)
          Called when painter is intalled into some component.
 void updateAll()
          Should be called when painter size, border and visual representation changes.
 void updateOpacity()
          Should be called when painter opacity changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.alee.extended.painter.Painter
paint
 

Field Detail

opaque

protected java.lang.Boolean opaque
Whether visual data is opaque or not.


preferredSize

protected java.awt.Dimension preferredSize
Visual data preferred size.


margin

protected java.awt.Insets margin
Visual data margin.


listeners

protected java.util.List<PainterListener> listeners
Painter listeners.

Constructor Detail

AbstractPainter

public AbstractPainter()
Method Detail

install

public void install(E c)
Called when painter is intalled into some component. You might want to use this method to add custom component listeners or modify component settings.

Specified by:
install in interface Painter<E extends javax.swing.JComponent>
Parameters:
c - component to process

uninstall

public void uninstall(E c)
Called when painter is intalled into some component. You might want to use this method to add custom component listeners or modify component settings.

Specified by:
uninstall in interface Painter<E extends javax.swing.JComponent>
Parameters:
c - component to process

isOpaque

public java.lang.Boolean isOpaque(E c)
Returns whether visual data provided by this painter is opaque or not. Returned value might affect component opacity depending on painter support inside that component UI. Simply return null if you don't want to change default component opacity.

Specified by:
isOpaque in interface Painter<E extends javax.swing.JComponent>
Parameters:
c - component to process
Returns:
true if visual data provided by this painter is opaque, false otherwise

setOpaque

public void setOpaque(java.lang.Boolean opaque)
Sets whether visual data provided by this painter is opaque or not.

Parameters:
opaque - whether visual data provided by this painter is opaque or not

getPreferredSize

public java.awt.Dimension getPreferredSize(E c)
Returns preferred size required for proper painting of visual data provided by this painter. This should not take into account any sizes not related to this painter settings (for example text size on button).

Specified by:
getPreferredSize in interface Painter<E extends javax.swing.JComponent>
Parameters:
c - component to process
Returns:
preferred size required for proper painting of visual data provided by this painter

setPreferredSize

public void setPreferredSize(java.awt.Dimension preferredSize)
Sets preferred size for visual data provided by this painter.

Parameters:
preferredSize - preferred size for visual data provided by this painter

getMargin

public java.awt.Insets getMargin(E c)
Returns margin required for visual data provided by this painter. This margin is usually added to component's margin when the final component border is calculated. You may pass null instead of zero margin - it will simply be ignored in that case.

Specified by:
getMargin in interface Painter<E extends javax.swing.JComponent>
Parameters:
c - component to process
Returns:
margin required for visual data provided by this painter or null for zero margin

setMargin

public void setMargin(java.awt.Insets margin)
Sets margin required for visual data provided by this painter.

Parameters:
margin - margin required for visual data provided by this painter

setMargin

public void setMargin(int top,
                      int left,
                      int bottom,
                      int right)
Sets margin required for visual data provided by this painter.

Parameters:
top - top margin required for visual data provided by this painter
left - left margin required for visual data provided by this painter
bottom - bottom margin required for visual data provided by this painter
right - right margin required for visual data provided by this painter

setMargin

public void setMargin(int margin)
Sets margin required for visual data provided by this painter.

Parameters:
margin - margin required for visual data provided by this painter

addPainterListener

public void addPainterListener(PainterListener listener)
Adds new painter listener.

Specified by:
addPainterListener in interface Painter<E extends javax.swing.JComponent>
Parameters:
listener - painter listener to add

removePainterListener

public void removePainterListener(PainterListener listener)
Removes painter listener.

Specified by:
removePainterListener in interface Painter<E extends javax.swing.JComponent>
Parameters:
listener - painter listener to remove

repaint

public void repaint()
Should be called when painter visual representation changes.


repaint

public void repaint(java.awt.Rectangle bounds)
Should be called when part of painter visual representation changes.

Parameters:
bounds - part bounds

repaint

public void repaint(int x,
                    int y,
                    int width,
                    int height)
Should be called when part of painter visual representation changes.

Parameters:
x - part bounds X coordinate
y - part bounds Y coordinate
width - part bounds width
height - part bounds height

revalidate

public void revalidate()
Should be called when painter size or border changes.


updateOpacity

public void updateOpacity()
Should be called when painter opacity changes.


updateAll

public void updateAll()
Should be called when painter size, border and visual representation changes. Calls both revalidate and update listener methods.


p

protected java.awt.Point p(int x,
                           int y)
Returns point for the specified coordinates. Might be useful for points generation in various cases

Parameters:
x - X coordinate
y - Y coordinate
Returns:
point for the specified coordinates