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

java.lang.Object
  extended by com.alee.extended.painter.AbstractPainter<E>
      extended by com.alee.extended.painter.AdaptivePainter<E>
All Implemented Interfaces:
Painter<E>
Direct Known Subclasses:
AdaptiveLabelPainter, AdaptivePanelPainter, AdaptivePopupMenuPainter, AdaptiveScrollBarButtonPainter, AdaptiveScrollBarPainter

public abstract class AdaptivePainter<E extends javax.swing.JComponent>
extends AbstractPainter<E>

Special painter made to adapts any kind of painters to fit custom painters within the specific UIs. To use it properly you should extend this class and implement UI painter interface methods. In general cases those methods might have no effect since general-type painters do not know anything about component specifics.

Author:
Mikle Garin

Field Summary
 
Fields inherited from class com.alee.extended.painter.AbstractPainter
listeners, margin, opaque, preferredSize
 
Constructor Summary
AdaptivePainter(Painter painter)
          Constructs new AdaptivePainter to adapt specified painter.
 
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.
 Painter getPainter()
          Returns adapted 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.
 void paint(java.awt.Graphics2D g2d, java.awt.Rectangle bounds, E c)
          Paints visual data onto the component graphics.
 void removePainterListener(PainterListener listener)
          Removes painter listener.
 void uninstall(E c)
          Called when painter is intalled into some component.
 
Methods inherited from class com.alee.extended.painter.AbstractPainter
p, repaint, repaint, repaint, revalidate, setMargin, setMargin, setMargin, setOpaque, setPreferredSize, updateAll, updateOpacity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdaptivePainter

public AdaptivePainter(Painter painter)
Constructs new AdaptivePainter to adapt specified painter.

Parameters:
painter - painter to adapt
Method Detail

getPainter

public Painter getPainter()
Returns adapted painter.

Returns:
adapted painter

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>
Overrides:
install in class AbstractPainter<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>
Overrides:
uninstall in class AbstractPainter<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>
Overrides:
isOpaque in class AbstractPainter<E extends javax.swing.JComponent>
Parameters:
c - component to process
Returns:
true if visual data provided by this painter is opaque, false otherwise

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>
Overrides:
getPreferredSize in class AbstractPainter<E extends javax.swing.JComponent>
Parameters:
c - component to process
Returns:
preferred size required for proper painting of 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>
Overrides:
getMargin in class AbstractPainter<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

addPainterListener

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

Specified by:
addPainterListener in interface Painter<E extends javax.swing.JComponent>
Overrides:
addPainterListener in class AbstractPainter<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>
Overrides:
removePainterListener in class AbstractPainter<E extends javax.swing.JComponent>
Parameters:
listener - painter listener to remove

paint

public void paint(java.awt.Graphics2D g2d,
                  java.awt.Rectangle bounds,
                  E c)
Paints visual data onto the component graphics. Provided graphics and component are taken directly from component UI paint method. Provided bounds are usually fake (zero location, component size) but in some cases it might be specified by componentUI.

Parameters:
g2d - component graphics
bounds - bounds for painter visual data
c - component to process