org.pbjar.jxlayer.plaf.ext
Class TransformUI

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.pbjar.jxlayer.plaf.ext.MouseEventUI<JComponent>
                  extended by org.pbjar.jxlayer.plaf.ext.TransformUI
All Implemented Interfaces:
Serializable

public class TransformUI
extends MouseEventUI<JComponent>

This class provides for all necessary functionality when using transformations in a LayerUI.

Some implementation details:

Known limitations:

  1. In Java versions before Java 6u10, this implementation employs a custom TransformUI.TransformRepaintManager in order to have descendant's repaint requests propagated up to the JXLayer ancestor. This TransformUI.TransformRepaintManager will work well with and without other TransformUI.TransformRepaintManager that are either subclasses of the WrappedRepaintManager or SwingX's ForwardingRepaintManager. Other TransformUI.TransformRepaintManagers may cause conflicts.

    In Java versions 6u10 or higher, an attempt will be made to use the new RepaintManager delegate facility that has been designed for JavaFX.

  2. Transformations will be applied on the whole of the content of the JXLayer. The result is that Borders and other content within JXLayer's insets will generally either be invisible, or will be rendered in a very undesirable way. If you want a Border to be transformed together with JXLayer's view, that border should be set on the view instead. On the other hand, if you want the Border not to be transformed, that border must be set on JXLayer's parent.

Note: A TransformUI instance cannot be shared and can be set to a single JXLayer instance only.

Author:
Piet Blok
See Also:
Serialized Form

Nested Class Summary
protected static class TransformUI.TransformRepaintManager
          A delegate RepaintManager that can be set on the view of a JXLayer in Java versions starting with Java 6u10.
 
Constructor Summary
TransformUI()
          Construct a TransformUI with a DefaultTransformModel.
TransformUI(TransformModel model)
          Construct a TransformUI with a specified model.
 
Method Summary
 void addRenderingHint(RenderingHints.Key key, Object value)
          Add one rendering hint to the currently active rendering hints.
 void addRenderingHints(Map<RenderingHints.Key,Object> hints)
          Add new rendering hints to the currently active rendering hints;
 TransformModel getModel()
          Get the TransformModel.
 AffineTransform getPreferredTransform(Dimension size, org.jdesktop.jxlayer.JXLayer<JComponent> layer)
          Get a preferred AffineTransform.
protected  Map<RenderingHints.Key,Object> getRenderingHints(org.jdesktop.jxlayer.JXLayer<JComponent> layer)
          Get the rendering hints.
protected  AffineTransform getTransform(org.jdesktop.jxlayer.JXLayer<JComponent> layer)
          Get the AffineTransform customized for the layer argument.
 void installUI(JComponent component)
          Overridden to replace the LayoutManager, to add some listeners and to ensure that an appropriate TransformUI.TransformRepaintManager is installed.
 void paint(Graphics g, JComponent component)
           This implementation does the following: A BufferedImage is created the size of the clip bounds of the argument graphics object.
protected  void paintLayer(Graphics2D g2, org.jdesktop.jxlayer.JXLayer<JComponent> layer)
          If the view of the JXLayer is (partly) obscured by its parent (this is the case when the size of the view (in component space) is larger than the size of the JXLayer), the obscured parts will not be painted by the super implementation.
static void prepareForJTextComponent()
          JTextComponent and its descendants have some caret position problems when used inside a transformed JXLayer.
 void setEnabled(boolean enabled)
          Overridden to also trigger JComponent.revalidate() and Component.repaint().
 void setModel(TransformModel transformModel)
          Set a new TransformModel.
 void setRenderingHints(Map<RenderingHints.Key,Object> hints)
          Replace the currently active rendering hints with new hints.
 Rectangle transform(Rectangle rect, org.jdesktop.jxlayer.JXLayer<JComponent> layer)
          Primarily intended for use by TransformUI.TransformRepaintManager.
 void uninstallUI(JComponent c)
          Overridden to restore the original LayoutManager and remove some listeners.
 void updateUI(org.jdesktop.jxlayer.JXLayer<JComponent> layer)
          Mark TransformUI as dirty if the LookAndFeel was changed.
 
Methods inherited from class org.pbjar.jxlayer.plaf.ext.MouseEventUI
eventDispatched, getInstalledLayer, getLayerEventMask, processMouseWheelEvent
 
Methods inherited from class org.jdesktop.jxlayer.plaf.AbstractLayerUI
configureGraphics, eventDispatched, getClip, getComposite, getRenderingHints, getTransform, handlePropertyChangeEvent, isDirty, paintLayer, processFocusEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, setDirty
 
Methods inherited from class org.jdesktop.jxlayer.plaf.LayerUI
addPropertyChangeListener, addPropertyChangeListener, contains, firePropertyChange, getPreferredScrollableViewportSize, getPropertyChangeListeners, getPropertyChangeListeners, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, removePropertyChangeListener, removePropertyChangeListener, updateUI
 
Methods inherited from class javax.swing.plaf.ComponentUI
createUI, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransformUI

public TransformUI()
Construct a TransformUI with a DefaultTransformModel.


TransformUI

public TransformUI(TransformModel model)
Construct a TransformUI with a specified model.

Parameters:
model - the model
Method Detail

prepareForJTextComponent

public static void prepareForJTextComponent()
JTextComponent and its descendants have some caret position problems when used inside a transformed JXLayer. When you plan to use JTextComponent(s) inside the hierarchy of a transformed JXLayer, call this method in an early stage, before instantiating any JTextComponent .

It executes the following method:

 System.setProperty("i18n", Boolean.TRUE.toString());
 
As a result, a GlyphView.GlyphPainter will be selected that uses floating point instead of fixed point calculations.


addRenderingHint

public void addRenderingHint(RenderingHints.Key key,
                             Object value)
Add one rendering hint to the currently active rendering hints.

Parameters:
key - the key
value - the value

addRenderingHints

public void addRenderingHints(Map<RenderingHints.Key,Object> hints)
Add new rendering hints to the currently active rendering hints;

Parameters:
hints - the new rendering hints

getModel

public final TransformModel getModel()
Get the TransformModel.

Returns:
the TransformModel
See Also:
setModel(TransformModel)

getPreferredTransform

public AffineTransform getPreferredTransform(Dimension size,
                                             org.jdesktop.jxlayer.JXLayer<JComponent> layer)
Get a preferred AffineTransform. This method will typically be invoked by programs that calculate a preferred size.

The size argument will be used to compute anchor values for some types of transformations. If the size argument is null a value of (0,0) is used for the anchor.

In enabled state this method is delegated to the TransformModel that has been set. Otherwise null will be returned.

Parameters:
size - a Dimension instance to be used for an anchor or null
layer - the JXLayer.
Returns:
a AffineTransform instance or null

installUI

public void installUI(JComponent component)
Overridden to replace the LayoutManager, to add some listeners and to ensure that an appropriate TransformUI.TransformRepaintManager is installed.

Overrides:
installUI in class MouseEventUI<JComponent>
See Also:
uninstallUI(JComponent)

paint

public final void paint(Graphics g,
                        JComponent component)

This implementation does the following:

  1. A BufferedImage is created the size of the clip bounds of the argument graphics object.
  2. A Graphics object is obtained from the image.
  3. The image is filled with a background color.
  4. The image graphics is translated according to x and y of the clip bounds.
  5. The clip from the argument graphics object is set to the image graphics.
  6. AbstractLayerUI.configureGraphics(Graphics2D, JXLayer) is invoked with the image graphics as an argument.
  7. paintLayer(Graphics2D, JXLayer) is invoked with the image graphics as an argument.
  8. The image graphics is disposed.
  9. The image is drawn on the argument graphics object.

Overrides:
paint in class org.jdesktop.jxlayer.plaf.AbstractLayerUI<JComponent>

setEnabled

public void setEnabled(boolean enabled)
Overridden to also trigger JComponent.revalidate() and Component.repaint().


setModel

public final void setModel(TransformModel transformModel)
                    throws NullPointerException
Set a new TransformModel. The new model may not be null.

Parameters:
transformModel - the new model
Throws:
NullPointerException - if transformModel is null
See Also:
getModel()

setRenderingHints

public void setRenderingHints(Map<RenderingHints.Key,Object> hints)
Replace the currently active rendering hints with new hints.

Parameters:
hints - the new rendering hints or null to clear all rendering hints

transform

public final Rectangle transform(Rectangle rect,
                                 org.jdesktop.jxlayer.JXLayer<JComponent> layer)
Primarily intended for use by TransformUI.TransformRepaintManager.

Parameters:
rect - a rectangle
layer - the layer
Returns:
the argument rectangle if no AffineTransform is available, else a new rectangle

uninstallUI

public void uninstallUI(JComponent c)
Overridden to restore the original LayoutManager and remove some listeners.

Overrides:
uninstallUI in class MouseEventUI<JComponent>

updateUI

public void updateUI(org.jdesktop.jxlayer.JXLayer<JComponent> layer)
Mark TransformUI as dirty if the LookAndFeel was changed.

Parameters:
layer - the JXLayer this TransformUI is set to

getRenderingHints

protected Map<RenderingHints.Key,Object> getRenderingHints(org.jdesktop.jxlayer.JXLayer<JComponent> layer)
Get the rendering hints.

Returns:
the rendering hints
See Also:
setRenderingHints(Map), addRenderingHints(Map), addRenderingHint(java.awt.RenderingHints.Key, Object)

getTransform

protected final AffineTransform getTransform(org.jdesktop.jxlayer.JXLayer<JComponent> layer)
Get the AffineTransform customized for the layer argument.

In enabled state this method is delegated to the TransformModel that has been set. Otherwise null will be returned.


paintLayer

protected final void paintLayer(Graphics2D g2,
                                org.jdesktop.jxlayer.JXLayer<JComponent> layer)
If the view of the JXLayer is (partly) obscured by its parent (this is the case when the size of the view (in component space) is larger than the size of the JXLayer), the obscured parts will not be painted by the super implementation. Therefore, only under this condition, a special painting technique is executed:
  1. All descendants of the JXLayer are temporarily set to non double buffered.
  2. The graphics object is translated for the X and Y coordinates of the view.
  3. The view is painted.
  4. The original double buffered property is restored for all descendants.

In all other cases, the super method is invoked.

The g2 argument is a graphics object obtained from a BufferedImage.

See Also: