Methods Summary |
---|
protected java.awt.Component | createComponent()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.
AttributeSet attr = getElement().getAttributes();
Component comp = StyleConstants.getComponent(attr);
return comp;
|
public float | getAlignment(int axis)Determines the desired alignment for this view along an
axis. This is implemented to give the alignment of the
embedded component.
if (c != null) {
switch (axis) {
case View.X_AXIS:
return c.getAlignmentX();
case View.Y_AXIS:
return c.getAlignmentY();
}
}
return super.getAlignment(axis);
|
public final java.awt.Component | getComponent()Fetch the component associated with the view.
return createdC;
|
public float | getMaximumSpan(int axis)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.
if ((axis != X_AXIS) && (axis != Y_AXIS)) {
throw new IllegalArgumentException("Invalid axis: " + axis);
}
if (c != null) {
Dimension size = c.getMaximumSize();
if (axis == View.X_AXIS) {
return size.width;
} else {
return size.height;
}
}
return 0;
|
public float | getMinimumSpan(int axis)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.
if ((axis != X_AXIS) && (axis != Y_AXIS)) {
throw new IllegalArgumentException("Invalid axis: " + axis);
}
if (c != null) {
Dimension size = c.getMinimumSize();
if (axis == View.X_AXIS) {
return size.width;
} else {
return size.height;
}
}
return 0;
|
public float | getPreferredSpan(int axis)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.
if ((axis != X_AXIS) && (axis != Y_AXIS)) {
throw new IllegalArgumentException("Invalid axis: " + axis);
}
if (c != null) {
Dimension size = c.getPreferredSize();
if (axis == View.X_AXIS) {
return size.width;
} else {
return size.height;
}
}
return 0;
|
public java.awt.Shape | modelToView(int pos, java.awt.Shape a, javax.swing.text.Position$Bias b)Provides a mapping from the coordinate space of the model to
that of the view.
int p0 = getStartOffset();
int p1 = getEndOffset();
if ((pos >= p0) && (pos <= p1)) {
Rectangle r = a.getBounds();
if (pos == p1) {
r.x += r.width;
}
r.width = 0;
return r;
}
throw new BadLocationException(pos + " not in range " + p0 + "," + p1, pos);
|
public void | paint(java.awt.Graphics g, java.awt.Shape a)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.
if (c != null) {
Rectangle alloc = (a instanceof Rectangle) ?
(Rectangle) a : a.getBounds();
c.setBounds(alloc.x, alloc.y, alloc.width, alloc.height);
}
|
void | setComponentParent()Set the parent of the embedded component
with assurance that it is thread-safe.
View p = getParent();
if (p != null) {
Container parent = getContainer();
if (parent != null) {
if (c == null) {
// try to build a component
Component comp = createComponent();
if (comp != null) {
createdC = comp;
c = new Invalidator(comp);
}
}
if (c != null) {
if (c.getParent() == null) {
// components associated with the View tree are added
// to the hosting container with the View as a constraint.
parent.add(c, this);
}
}
}
} else {
if (c != null) {
Container parent = c.getParent();
if (parent != null) {
// remove the component from its hosting container
parent.remove(c);
}
}
}
|
public void | setParent(javax.swing.text.View p)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).
super.setParent(p);
if (SwingUtilities.isEventDispatchThread()) {
setComponentParent();
} else {
Runnable callSetComponentParent = new Runnable() {
public void run() {
Document doc = getDocument();
try {
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readLock();
}
setComponentParent();
Container host = getContainer();
if (host != null) {
preferenceChanged(null, true, true);
host.repaint();
}
} finally {
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readUnlock();
}
}
}
};
SwingUtilities.invokeLater(callSetComponentParent);
}
|
public int | viewToModel(float x, float y, java.awt.Shape a, javax.swing.text.Position$Bias[] bias)Provides a mapping from the view coordinate space to the logical
coordinate space of the model.
Rectangle alloc = (Rectangle) a;
if (x < alloc.x + (alloc.width / 2)) {
bias[0] = Position.Bias.Forward;
return getStartOffset();
}
bias[0] = Position.Bias.Backward;
return getEndOffset();
|