net.sourceforge.spedit.ui
Class WrapperView

java.lang.Object
  |
  +--javax.swing.text.View
        |
        +--net.sourceforge.spedit.ui.WrapperView
All Implemented Interfaces:
Stateable, Styleable, SwingConstants

public class WrapperView
extends View
implements Styleable, Stateable

The WrapperView class allows to wrap any view and add CSS-like display properties to it. This works very well with views such as ParagraphView or BoxView.

The XMLViewFactory of the core package always wrap created views in a WrapperView, so as long as you use the core classes you can assume assume safely that all the views are WrapperView instances (excepted the root view).


Inner classes inherited from class net.sourceforge.spedit.core.Styleable
Styleable.StyleSheet, Styleable.Utils
 
Field Summary
protected  boolean collapsed
           
protected  Font collapsedFont
           
protected  Element element
           
protected  boolean focused
           
protected  boolean hasToUpdate
           
protected  View nested
           
protected  String nestedName
           
protected  boolean refreshBounds
           
protected  boolean selected
           
protected  net.sourceforge.spedit.ui.StyleSheet styleSheet
           
protected  String title
           
protected  Rectangle2D viewBounds
           
 
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
 
Fields inherited from interface net.sourceforge.spedit.core.Stateable
FOCUSED, SELECTED, UNFOCUSED, UNSELECTED
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NORTH, NORTH_EAST, NORTH_WEST, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
WrapperView(Element e, String name)
           
WrapperView(Element e, String name, String title)
           
WrapperView(View v)
           
 
Method Summary
 void append(View v)
           
 View breakView(int axis, int offset, float pos, float len)
           
 void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)
           
 void collapse()
           
 View createFragment(int p0, int p1)
           
 void expand()
           
 float getAlignment(int axis)
           
 AttributeSet getAttributes()
           
 Rectangle2D getBounds()
          Returns the bounds of this view.
 int getBreakWeight(int axis, float pos, float len)
           
 Shape getChildAllocation(int index, Shape a)
           
 Container getContainer()
           
 Document getDocument()
           
 Element getElement()
           
 int getEndOffset()
           
 Graphics getGraphics()
           
 float getMaximumSpan(int axis)
           
 float getMinimumSpan(int axis)
           
 View getNestedView()
           
 int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
           
 View getParent()
           
 Styleable.StyleSheet getParentStyleSheet()
           
 float getPreferredSpan(int axis)
           
 int getResizeWeight(int axis)
           
 int getStartOffset()
           
 Styleable.StyleSheet getStyleSheet()
           
 View getView(int n)
           
 WrapperView getViewAt(float x, float y)
          Returns the view that is located at the given coordinates.
 int getViewCount()
           
 ViewFactory getViewFactory()
           
 int getViewIndex(int pos, Position.Bias b)
           
 void insert(int offs, View v)
           
 void insertUpdate(DocumentEvent e, Shape a, ViewFactory f)
           
 boolean isCollapsed()
           
 boolean isFocused()
           
 boolean isSelected()
           
 boolean isVisible()
           
 Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a)
           
 Shape modelToView(int pos, Shape a)
           
 Shape modelToView(int pos, Shape a, Position.Bias b)
           
 void paint(Graphics g, Shape s)
           
 void preferenceChanged(View child, boolean width, boolean height)
           
 void propagateMouseClicked(MouseEvent e)
          Propagates the given event to the nested view if it is a MouseListener instance.
 void propagateMouseEntered(MouseEvent e)
          Propagates the given event to the nested view if it is a MouseListener instance.
 void propagateMouseExited(MouseEvent e)
          Propagates the given event to the nested view if it is a MouseListener instance.
 void propagateMousePressed(MouseEvent e)
          Propagates the given event to the nested view if it is a MouseListener instance.
 void propagateMouseReleased(MouseEvent e)
          Propagates the given event to the nested view if it is a MouseListener instance.
 void remove(int i)
           
 void removeAll()
           
 void removeUpdate(DocumentEvent e, Shape a, ViewFactory f)
           
 void repaint()
           
 void replace(int offset, int length, View[] views)
           
 void setFocused(boolean focused)
           
 void setParent(View parent)
           
 void setSelected(boolean selected)
           
 void setSize(float width, float height)
           
 void setStyleSheet(Styleable.StyleSheet s)
           
 int viewToModel(float x, float y, Shape a)
           
 int viewToModel(float x, float y, Shape a, Position.Bias[] biasReturn)
           
 
Methods inherited from class javax.swing.text.View
forwardUpdate, forwardUpdateToView, updateChildren, updateLayout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nested

protected View nested

nestedName

protected String nestedName

title

protected String title

element

protected Element element

styleSheet

protected net.sourceforge.spedit.ui.StyleSheet styleSheet

focused

protected boolean focused

selected

protected boolean selected

collapsed

protected boolean collapsed

collapsedFont

protected Font collapsedFont

hasToUpdate

protected boolean hasToUpdate

viewBounds

protected Rectangle2D viewBounds

refreshBounds

protected boolean refreshBounds
Constructor Detail

WrapperView

public WrapperView(View v)

WrapperView

public WrapperView(Element e,
                   String name)

WrapperView

public WrapperView(Element e,
                   String name,
                   String title)
Method Detail

paint

public void paint(Graphics g,
                  Shape s)
Overrides:
paint in class View

repaint

public void repaint()

setFocused

public void setFocused(boolean focused)
Specified by:
setFocused in interface Stateable

isFocused

public boolean isFocused()
Specified by:
isFocused in interface Stateable

setSelected

public void setSelected(boolean selected)
Specified by:
setSelected in interface Stateable

isSelected

public boolean isSelected()
Specified by:
isSelected in interface Stateable

collapse

public void collapse()

expand

public void expand()

isCollapsed

public boolean isCollapsed()

getBounds

public Rectangle2D getBounds()
Returns the bounds of this view. The rectangle is mutable, so you should take care of not modifying it. Note: the returned reference can be null in case you call getBounds between a repaint request and the actual request or if the WrapperView has not been assigned a parent.
Returns:
The rectangle that corresponds to the View bounds.

getViewAt

public WrapperView getViewAt(float x,
                             float y)
Returns the view that is located at the given coordinates. These coordinates are relative to the current view upper-left corner, which has (0,0) coordinates.
Returns:
The given WrapperView instance if it exists, otherwise returns null if there is no view at this location.

propagateMouseClicked

public void propagateMouseClicked(MouseEvent e)

Propagates the given event to the nested view if it is a MouseListener instance. If it is not the case then the evenet is forwarded to the parent view, which has to be not null (of course) but also a WrapperView instance.

Note that this particular propagator intercepts the event in case the event occured on the "expander" icon if it has been set in the stylesheet.

Parameters:
e - The mouse event to be propagated.

propagateMousePressed

public void propagateMousePressed(MouseEvent e)

Propagates the given event to the nested view if it is a MouseListener instance. If it is not the case then the evenet is forwarded to the parent view, which has to be not null (of course) but also a WrapperView instance.

Parameters:
e - The mouse event to be propagated.

propagateMouseReleased

public void propagateMouseReleased(MouseEvent e)

Propagates the given event to the nested view if it is a MouseListener instance. If it is not the case then the evenet is forwarded to the parent view, which has to be not null (of course) but also a WrapperView instance.

Parameters:
e - The mouse event to be propagated.

propagateMouseEntered

public void propagateMouseEntered(MouseEvent e)

Propagates the given event to the nested view if it is a MouseListener instance. If it is not the case then the evenet is forwarded to the parent view, which has to be not null (of course) but also a WrapperView instance.

Parameters:
e - The mouse event to be propagated.

propagateMouseExited

public void propagateMouseExited(MouseEvent e)

Propagates the given event to the nested view if it is a MouseListener instance. If it is not the case then the evenet is forwarded to the parent view, which has to be not null (of course) but also a WrapperView instance.

Parameters:
e - The mouse event to be propagated.

viewToModel

public int viewToModel(float x,
                       float y,
                       Shape a)
Overrides:
viewToModel in class View

viewToModel

public int viewToModel(float x,
                       float y,
                       Shape a,
                       Position.Bias[] biasReturn)
Overrides:
viewToModel in class View

modelToView

public Shape modelToView(int p0,
                         Position.Bias b0,
                         int p1,
                         Position.Bias b1,
                         Shape a)
                  throws BadLocationException
Overrides:
modelToView in class View

modelToView

public Shape modelToView(int pos,
                         Shape a)
                  throws BadLocationException
Overrides:
modelToView in class View

modelToView

public Shape modelToView(int pos,
                         Shape a,
                         Position.Bias b)
                  throws BadLocationException
Overrides:
modelToView in class View

getPreferredSpan

public float getPreferredSpan(int axis)
Overrides:
getPreferredSpan in class View

getMinimumSpan

public float getMinimumSpan(int axis)
Overrides:
getMinimumSpan in class View

getMaximumSpan

public float getMaximumSpan(int axis)
Overrides:
getMaximumSpan in class View

setSize

public void setSize(float width,
                    float height)
Overrides:
setSize in class View

append

public void append(View v)
Overrides:
append in class View

getParent

public View getParent()
Overrides:
getParent in class View

getNestedView

public View getNestedView()

replace

public void replace(int offset,
                    int length,
                    View[] views)
Overrides:
replace in class View

setParent

public void setParent(View parent)
Overrides:
setParent in class View

remove

public void remove(int i)
Overrides:
remove in class View

removeAll

public void removeAll()
Overrides:
removeAll in class View

getViewIndex

public int getViewIndex(int pos,
                        Position.Bias b)
Overrides:
getViewIndex in class View

insert

public void insert(int offs,
                   View v)
Overrides:
insert in class View

getView

public View getView(int n)
Overrides:
getView in class View

getViewCount

public int getViewCount()
Overrides:
getViewCount in class View

getViewFactory

public ViewFactory getViewFactory()
Overrides:
getViewFactory in class View

breakView

public View breakView(int axis,
                      int offset,
                      float pos,
                      float len)
Overrides:
breakView in class View

createFragment

public View createFragment(int p0,
                           int p1)
Overrides:
createFragment in class View

changedUpdate

public void changedUpdate(DocumentEvent e,
                          Shape a,
                          ViewFactory f)
Overrides:
changedUpdate in class View

getAlignment

public float getAlignment(int axis)
Overrides:
getAlignment in class View

getAttributes

public AttributeSet getAttributes()
Overrides:
getAttributes in class View

getBreakWeight

public int getBreakWeight(int axis,
                          float pos,
                          float len)
Overrides:
getBreakWeight in class View

getChildAllocation

public Shape getChildAllocation(int index,
                                Shape a)
Overrides:
getChildAllocation in class View

getContainer

public Container getContainer()
Overrides:
getContainer in class View

getDocument

public Document getDocument()
Overrides:
getDocument in class View

getElement

public Element getElement()
Overrides:
getElement in class View

getEndOffset

public int getEndOffset()
Overrides:
getEndOffset in class View

getGraphics

public Graphics getGraphics()
Overrides:
getGraphics in class View

getNextVisualPositionFrom

public int getNextVisualPositionFrom(int pos,
                                     Position.Bias b,
                                     Shape a,
                                     int direction,
                                     Position.Bias[] biasRet)
                              throws BadLocationException
Overrides:
getNextVisualPositionFrom in class View

getResizeWeight

public int getResizeWeight(int axis)
Overrides:
getResizeWeight in class View

getStartOffset

public int getStartOffset()
Overrides:
getStartOffset in class View

insertUpdate

public void insertUpdate(DocumentEvent e,
                         Shape a,
                         ViewFactory f)
Overrides:
insertUpdate in class View

isVisible

public boolean isVisible()
Overrides:
isVisible in class View

preferenceChanged

public void preferenceChanged(View child,
                              boolean width,
                              boolean height)
Overrides:
preferenceChanged in class View

removeUpdate

public void removeUpdate(DocumentEvent e,
                         Shape a,
                         ViewFactory f)
Overrides:
removeUpdate in class View

getStyleSheet

public Styleable.StyleSheet getStyleSheet()
Specified by:
getStyleSheet in interface Styleable

setStyleSheet

public void setStyleSheet(Styleable.StyleSheet s)
Specified by:
setStyleSheet in interface Styleable

getParentStyleSheet

public Styleable.StyleSheet getParentStyleSheet()
Specified by:
getParentStyleSheet in interface Styleable