javax.swing.text.html
Class CommentView

java.lang.Object
  extended byjavax.swing.text.View
      extended byjavax.swing.text.ComponentView
          extended byjavax.swing.text.html.EditableView
              extended byjavax.swing.text.html.HiddenTagView
                  extended byjavax.swing.text.html.CommentView
All Implemented Interfaces:
DocumentListener, EventListener, SwingConstants

class CommentView
extends HiddenTagView

CommentView subclasses HiddenTagView to contain a JTextArea showing a comment. When the textarea is edited the comment is reset. As this inherits from EditableView if the JTextComponent is not editable, the textarea will not be visible.

Author:
Scott Violet

Nested Class Summary
(package private) static class CommentView.CommentBorder
           
(package private) static class HiddenTagView.EndTagBorder
           
(package private) static class HiddenTagView.StartTagBorder
           
 
Nested classes inherited from class javax.swing.text.ComponentView
 
Field Summary
(package private) static Border CBorder
           
(package private) static int circleD
           
(package private) static int circleR
           
(package private) static int commentPadding
           
(package private) static int commentPaddingD
           
(package private) static Border EndBorder
           
(package private)  boolean isSettingAttributes
          Set to true when setting attributes.
(package private) static int padding
           
(package private) static Border StartBorder
           
(package private) static int tagSize
           
(package private) static Color UnknownTagBorderColor
           
(package private)  float yAlign
          Alignment along the y axis, based on the font of the textfield.
 
Fields inherited from class javax.swing.text.ComponentView
 
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
(package private) CommentView(Element e)
           
 
Method Summary
(package private)  void _setTextFromModel()
          This resets the text on the text component we created to match that of the AttributeSet for the Element we represent.
(package private)  void _updateModelFromText()
          This is subclassed to put the text on the Comment attribute of the Element's AttributeSet.
 void changedUpdate(DocumentEvent e)
          Gives notification that an attribute or set of attributes changed.
 void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Gives notification from the document that attributes were changed in a location that this view is responsible for.
protected  Component createComponent()
          Create the component that is associated with this view.
 float getAlignment(int axis)
          Determines the desired alignment for this view along an axis.
 float getMaximumSpan(int axis)
          Determines the maximum span for this view along an axis.
 float getMinimumSpan(int axis)
          Determines the minimum span for this view along an axis.
 float getPreferredSpan(int axis)
          Determines the preferred span for this view along an axis.
(package private)  String getRepresentedText()
           
(package private)  JTextComponent getTextComponent()
           
 void insertUpdate(DocumentEvent e)
          Gives notification that there was an insert into the document.
(package private)  boolean isEndTag()
           
 boolean isVisible()
          Returns a boolean that indicates whether the view is visible or not.
 void paint(Graphics g, Shape allocation)
          The real paint behavior occurs naturally from the association that the component has with its parent container (the same container hosting this view).
 void removeUpdate(DocumentEvent e)
          Gives notification that a portion of the document has been removed.
(package private)  void resetBorder()
           
 void setParent(View parent)
          Sets the parent for a child view.
(package private)  void setTextFromModel()
          This resets the text on the text component we created to match that of the AttributeSet for the Element we represent.
(package private)  void updateModelFromText()
          This copies the text from the text component we've created to the Element's AttributeSet we represent.
(package private)  void updateYAlign(Font font)
           
 
Methods inherited from class javax.swing.text.ComponentView
getComponent, modelToView, viewToModel
 
Methods inherited from class javax.swing.text.View
append, breakView, createFragment, forwardUpdate, forwardUpdateToView, getAttributes, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getNextVisualPositionFrom, getParent, getResizeWeight, getStartOffset, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, insertUpdate, modelToView, modelToView, preferenceChanged, remove, removeAll, removeUpdate, replace, setSize, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CBorder

static final Border CBorder

commentPadding

static final int commentPadding
See Also:
Constant Field Values

commentPaddingD

static final int commentPaddingD
See Also:
Constant Field Values

yAlign

float yAlign
Alignment along the y axis, based on the font of the textfield.


isSettingAttributes

boolean isSettingAttributes
Set to true when setting attributes.


circleR

static final int circleR
See Also:
Constant Field Values

circleD

static final int circleD
See Also:
Constant Field Values

tagSize

static final int tagSize
See Also:
Constant Field Values

padding

static final int padding
See Also:
Constant Field Values

UnknownTagBorderColor

static final Color UnknownTagBorderColor

StartBorder

static final Border StartBorder

EndBorder

static final Border EndBorder
Constructor Detail

CommentView

CommentView(Element e)
Method Detail

createComponent

protected Component createComponent()
Description copied from class: ComponentView
Create the component that is associated with this view. This will be called when it has been determined that a new component is needed. This would result from a call to setParent or as a result of being notified that attributes have changed.

Overrides:
createComponent in class HiddenTagView

resetBorder

void resetBorder()
Overrides:
resetBorder in class HiddenTagView

_updateModelFromText

void _updateModelFromText()
This is subclassed to put the text on the Comment attribute of the Element's AttributeSet.

Overrides:
_updateModelFromText in class HiddenTagView

getTextComponent

JTextComponent getTextComponent()
Overrides:
getTextComponent in class HiddenTagView

getRepresentedText

String getRepresentedText()
Overrides:
getRepresentedText in class HiddenTagView

getAlignment

public float getAlignment(int axis)
Description copied from class: ComponentView
Determines the desired alignment for this view along an axis. This is implemented to give the alignment of the embedded component.

Overrides:
getAlignment in class ComponentView
Parameters:
axis - may be either View.X_AXIS or View.Y_AXIS
Returns:
the desired alignment. This should be a value between 0.0 and 1.0 where 0 indicates alignment at the origin and 1.0 indicates alignment to the full span away from the origin. An alignment of 0.5 would be the center of the view.

getMinimumSpan

public float getMinimumSpan(int axis)
Description copied from class: ComponentView
Determines the minimum span for this view along an axis. This is implemented to return the value returned by Component.getMinimumSize along the axis of interest.

Overrides:
getMinimumSpan in class EditableView

getPreferredSpan

public float getPreferredSpan(int axis)
Description copied from class: ComponentView
Determines the preferred span for this view along an axis. This is implemented to return the value returned by Component.getPreferredSize along the axis of interest.

Overrides:
getPreferredSpan in class EditableView

getMaximumSpan

public float getMaximumSpan(int axis)
Description copied from class: ComponentView
Determines the maximum span for this view along an axis. This is implemented to return the value returned by Component.getMaximumSize along the axis of interest.

Overrides:
getMaximumSpan in class EditableView

insertUpdate

public void insertUpdate(DocumentEvent e)
Description copied from interface: DocumentListener
Gives notification that there was an insert into the document. The range given by the DocumentEvent bounds the freshly inserted region.

Specified by:
insertUpdate in interface DocumentListener
Parameters:
e - the document event

removeUpdate

public void removeUpdate(DocumentEvent e)
Description copied from interface: DocumentListener
Gives notification that a portion of the document has been removed. The range is given in terms of what the view last saw (that is, before updating sticky positions).

Specified by:
removeUpdate in interface DocumentListener
Parameters:
e - the document event

changedUpdate

public void changedUpdate(DocumentEvent e)
Description copied from interface: DocumentListener
Gives notification that an attribute or set of attributes changed.

Specified by:
changedUpdate in interface DocumentListener
Parameters:
e - the document event

changedUpdate

public void changedUpdate(DocumentEvent e,
                          Shape a,
                          ViewFactory f)
Description copied from class: View
Gives notification from the document that attributes were changed in a location that this view is responsible for. To reduce the burden to subclasses, this functionality is spread out into the following calls that subclasses can reimplement:
  1. updateChildren is called if there were any changes to the element this view is responsible for. If this view has child views that are represent the child elements, then this method should do whatever is necessary to make sure the child views correctly represent the model.
  2. forwardUpdate is called to forward the DocumentEvent to the appropriate child views.
  3. updateLayout is called to give the view a chance to either repair its layout, to reschedule layout, or do nothing.

Overrides:
changedUpdate in class View
Parameters:
e - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
See Also:
View.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

updateYAlign

void updateYAlign(Font font)

setTextFromModel

void setTextFromModel()
This resets the text on the text component we created to match that of the AttributeSet for the Element we represent.

If this is invoked on the event dispatching thread, this directly invokes _setTextFromModel, otherwise SwingUtilities.invokeLater is used to schedule execution of _setTextFromModel.


_setTextFromModel

void _setTextFromModel()
This resets the text on the text component we created to match that of the AttributeSet for the Element we represent.


updateModelFromText

void updateModelFromText()
This copies the text from the text component we've created to the Element's AttributeSet we represent.

If this is invoked on the event dispatching thread, this directly invokes _updateModelFromText, otherwise SwingUtilities.invokeLater is used to schedule execution of _updateModelFromText.


isEndTag

boolean isEndTag()

paint

public void paint(Graphics g,
                  Shape allocation)
Description copied from class: ComponentView
The real paint behavior occurs naturally from the association that the component has with its parent container (the same container hosting this view). This is implemented to do nothing.

Overrides:
paint in class ComponentView
Parameters:
g - the graphics context
allocation - the shape
See Also:
View.paint(java.awt.Graphics, java.awt.Shape)

setParent

public void setParent(View parent)
Description copied from class: ComponentView
Sets the parent for a child view. The parent calls this on the child to tell it who its parent is, giving the view access to things like the hosting Container. The superclass behavior is executed, followed by a call to createComponent if the parent view parameter is non-null and a component has not yet been created. The embedded components parent is then set to the value returned by getContainer. If the parent view parameter is null, this view is being cleaned up, thus the component is removed from its parent.

The changing of the component hierarchy will touch the component lock, which is the one thing that is not safe from the View hierarchy. Therefore, this functionality is executed immediately if on the event thread, or is queued on the event queue if called from another thread (notification of change from an asynchronous update).

Overrides:
setParent in class ComponentView
Parameters:
parent - the parent

isVisible

public boolean isVisible()
Description copied from class: View
Returns a boolean that indicates whether the view is visible or not. By default all views are visible.

Overrides:
isVisible in class View
Returns:
true if the Component is visible.