org.jdesktop.jxlayer.plaf.ext
Class SpotLightUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by org.jdesktop.jxlayer.plaf.LayerUI<V>
          extended by org.jdesktop.jxlayer.plaf.AbstractLayerUI<V>
              extended by org.jdesktop.jxlayer.plaf.AbstractBufferedLayerUI<javax.swing.JComponent>
                  extended by org.jdesktop.jxlayer.plaf.ext.SpotLightUI
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener

public class SpotLightUI
extends AbstractBufferedLayerUI<javax.swing.JComponent>

SpotLightUI paints the layer as is and then it paints translucent mask on the top.

Here you can see the example of overridden contains() method, which implements a custom mouseEvent filter;
A mouseEvent will be processed only if any of added shapes contain its coordinates

The mask is generated with help of the paintLayer();
The perfomance if very good because most of the time the cached image is used, and it is repainted only when the layer is resized or when setDirty(true) is called)

See Also:
paint(Graphics,JComponent), contains(JComponent,int,int), Serialized Form

Constructor Summary
SpotLightUI()
          Creates an instance of SpotLightUI
SpotLightUI(java.awt.Color overlayColor, int softClipWidth)
          Creates an instance of SpotLightUI with the specified width of the "soft border" and overlay color, which is usually translucent.
SpotLightUI(int softClipWidth)
          Creates an instance of SpotLightUI with the specified width of the "soft border"
 
Method Summary
 void addShape(java.awt.Shape shape)
          Adds the specified shape to the slip list.
 boolean contains(javax.swing.JComponent c, int x, int y)
          
 long getLayerEventMask()
          This UI delegate does not listen for any events
 java.awt.Color getOverlayColor()
          Returns the overlay color used for spotlight effect
 int getSoftClipWidth()
          Gets the width for the "soft border"
protected  boolean isIncrementalUpdate(JXLayer<? extends javax.swing.JComponent> l)
          We don't want to update the buffer of this painter for every component's repainting, so this method returns false and it makes the painting much faster
 boolean isShadowEnabled()
           
 void paint(java.awt.Graphics g, javax.swing.JComponent c)
          Paints the specified component. Subclasses should override this method and use the specified Graphics object to render the content of the component.

Note: It is rarely necessary to override this method, for custom painting override AbstractLayerUI.paintLayer(Graphics2D,JXLayer) instead

This method configures the passed Graphics with help of the AbstractLayerUI.configureGraphics(Graphics2D,JXLayer) method, then calls paintLayer(Graphics2D,JXLayer) and resets the "dirty bit" at the end.

This method paints the paitns the JXLayer to the BufferedImage and then paints this image to the passed Graphics.

protected  void paintLayer(java.awt.Graphics2D g2, JXLayer<? extends javax.swing.JComponent> l)
          Subclasses should implement this method and perform custom painting operations here.
 void reset()
          Resets this SpotLightUI.
 void setOverlayColor(java.awt.Color overlayColor)
          Sets the overlay color used for spotlight effect
 void setShadowEnabled(boolean enabled)
           
 void setSoftClipWidth(int softClipWidth)
          Sets the width for the "soft border"
 
Methods inherited from class org.jdesktop.jxlayer.plaf.AbstractBufferedLayerUI
applyLayerEffects, createBuffer, getBuffer, getLayer, getLayerEffects, installUI, isBufferContentValid, isBufferFormatValid, propertyChange, setBuffer, uninstallUI, updateUI
 
Methods inherited from class org.jdesktop.jxlayer.plaf.AbstractLayerUI
configureGraphics, eventDispatched, getClip, getComposite, getRenderingHints, getTransform, handlePropertyChangeEvent, isDirty, processFocusEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, setDirty
 
Methods inherited from class org.jdesktop.jxlayer.plaf.LayerUI
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, getPreferredScrollableViewportSize, getPropertyChangeListeners, getPropertyChangeListeners, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class javax.swing.plaf.ComponentUI
createUI, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpotLightUI

public SpotLightUI()
Creates an instance of SpotLightUI


SpotLightUI

public SpotLightUI(int softClipWidth)
Creates an instance of SpotLightUI with the specified width of the "soft border"

Parameters:
softClipWidth - the width of the "soft border"

SpotLightUI

public SpotLightUI(java.awt.Color overlayColor,
                   int softClipWidth)
Creates an instance of SpotLightUI with the specified width of the "soft border" and overlay color, which is usually translucent.

Parameters:
overlayColor - the overlay color
softClipWidth - the width of the "soft border"
Method Detail

getLayerEventMask

public long getLayerEventMask()
This UI delegate does not listen for any events

Overrides:
getLayerEventMask in class AbstractLayerUI<javax.swing.JComponent>
Returns:
0
See Also:
JXLayer.setLayerEventMask(long)

isShadowEnabled

public boolean isShadowEnabled()

setShadowEnabled

public void setShadowEnabled(boolean enabled)

getOverlayColor

public java.awt.Color getOverlayColor()
Returns the overlay color used for spotlight effect

Returns:
the overlay color used for spotlight effect

setOverlayColor

public void setOverlayColor(java.awt.Color overlayColor)
Sets the overlay color used for spotlight effect

Parameters:
overlayColor - the overlay color used for spotlight effect

getSoftClipWidth

public int getSoftClipWidth()
Gets the width for the "soft border"

Returns:
the width for the "soft border"

setSoftClipWidth

public void setSoftClipWidth(int softClipWidth)
Sets the width for the "soft border"

Parameters:
softClipWidth - the width for the "soft border"

reset

public void reset()
Resets this SpotLightUI.


addShape

public void addShape(java.awt.Shape shape)
Adds the specified shape to the slip list.

Parameters:
shape - Shape to add to the clip list.

isIncrementalUpdate

protected boolean isIncrementalUpdate(JXLayer<? extends javax.swing.JComponent> l)
We don't want to update the buffer of this painter for every component's repainting, so this method returns false and it makes the painting much faster

Overrides:
isIncrementalUpdate in class AbstractBufferedLayerUI<javax.swing.JComponent>
Parameters:
l - the JXLayer being painted
Returns:
false to disable the incremental update mode
See Also:
AbstractBufferedLayerUI.getBuffer()

paint

public void paint(java.awt.Graphics g,
                  javax.swing.JComponent c)
Paints the specified component. Subclasses should override this method and use the specified Graphics object to render the content of the component.

Note: It is rarely necessary to override this method, for custom painting override AbstractLayerUI.paintLayer(Graphics2D,JXLayer) instead

This method configures the passed Graphics with help of the AbstractLayerUI.configureGraphics(Graphics2D,JXLayer) method, then calls paintLayer(Graphics2D,JXLayer) and resets the "dirty bit" at the end.

This method paints the paitns the JXLayer to the BufferedImage and then paints this image to the passed Graphics.

It also manages the state of the existing cached image and applies the existing LayerEffects to the image.

Overrides:
paint in class AbstractBufferedLayerUI<javax.swing.JComponent>
Parameters:
g - the Graphics context in which to paint;
c - the component being painted; it can be safely cast to the JXLayer<V>
See Also:
AbstractLayerUI.paintLayer(Graphics2D,JXLayer), AbstractBufferedLayerUI.isBufferFormatValid(JXLayer), AbstractBufferedLayerUI.isBufferContentValid(JXLayer,Shape), AbstractBufferedLayerUI.getLayerEffects(JXLayer)

paintLayer

protected void paintLayer(java.awt.Graphics2D g2,
                          JXLayer<? extends javax.swing.JComponent> l)
Subclasses should implement this method and perform custom painting operations here.

The default implementation paints the passed JXLayer as is.

Overrides:
paintLayer in class AbstractLayerUI<javax.swing.JComponent>
Parameters:
g2 - the Graphics2D context in which to paint
l - the JXLayer being painted

contains

public boolean contains(javax.swing.JComponent c,
                        int x,
                        int y)

Overrides:
contains in class javax.swing.plaf.ComponentUI