IconViewpublic class IconView extends View Icon decorator that implements the view interface. The
entire element is used to represent the icon. This acts
as a gateway from the display-only View implementations to
interactive lightweight icons (that is, it allows icons
to be embedded into the View hierarchy. The parent of the icon
is the container that is handed out by the associated view
factory. |
Fields Summary |
---|
private Icon | c |
Constructors Summary |
---|
public IconView(Element elem)Creates a new icon view that represents an element.
super(elem);
AttributeSet attr = elem.getAttributes();
c = StyleConstants.getIcon(attr);
|
Methods Summary |
---|
public float | getAlignment(int axis)Determines the desired alignment for this view along an
axis. This is implemented to give the alignment to the
bottom of the icon along the y axis, and the default
along the x axis.
switch (axis) {
case View.Y_AXIS:
return 1;
default:
return super.getAlignment(axis);
}
| public float | getPreferredSpan(int axis)Determines the preferred span for this view along an
axis.
switch (axis) {
case View.X_AXIS:
return c.getIconWidth();
case View.Y_AXIS:
return c.getIconHeight();
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
| public java.awt.Shape | modelToView(int pos, java.awt.Shape a, javax.swing.text.Position$Bias b)Provides a mapping from the document model coordinate space
to the coordinate space of the view mapped to it.
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)Paints the icon.
The real paint behavior occurs naturally from the association
that the icon has with its parent container (the same
container hosting this view), so this simply allows us to
position the icon properly relative to the view. Since
the coordinate system for the view is simply the parent
containers, positioning the child icon is easy.
Rectangle alloc = a.getBounds();
c.paintIcon(getContainer(), g, alloc.x, alloc.y);
| 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();
|
|