aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/swing/text/View.java
diff options
context:
space:
mode:
authorMark Wielaard <mark@gcc.gnu.org>2006-03-10 21:46:48 +0000
committerMark Wielaard <mark@gcc.gnu.org>2006-03-10 21:46:48 +0000
commit8aa540d2f783474d1d2e06f16744bf67b9c1facc (patch)
treeea38c56431c5d4528fb54254c3f8e50f517bede3 /libjava/classpath/javax/swing/text/View.java
parent27079765d00123f8e53d0e1ef7f9d46559266e6d (diff)
downloadgcc-8aa540d2f783474d1d2e06f16744bf67b9c1facc.zip
gcc-8aa540d2f783474d1d2e06f16744bf67b9c1facc.tar.gz
gcc-8aa540d2f783474d1d2e06f16744bf67b9c1facc.tar.bz2
Imported GNU Classpath 0.90
Imported GNU Classpath 0.90 * scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore. * gnu/classpath/jdwp/VMFrame.java (SIZE): New constant. * java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5. * java/lang/Math.java: New override file. * java/lang/Character.java: Merged from Classpath. (start, end): Now 'int's. (canonicalName): New field. (CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants. (UnicodeBlock): Added argument. (of): New overload. (forName): New method. Updated unicode blocks. (sets): Updated. * sources.am: Regenerated. * Makefile.in: Likewise. From-SVN: r111942
Diffstat (limited to 'libjava/classpath/javax/swing/text/View.java')
-rw-r--r--libjava/classpath/javax/swing/text/View.java136
1 files changed, 122 insertions, 14 deletions
diff --git a/libjava/classpath/javax/swing/text/View.java b/libjava/classpath/javax/swing/text/View.java
index b835842..2feaf29 100644
--- a/libjava/classpath/javax/swing/text/View.java
+++ b/libjava/classpath/javax/swing/text/View.java
@@ -44,6 +44,7 @@ import java.awt.Rectangle;
import java.awt.Shape;
import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
public abstract class View implements SwingConstants
@@ -72,8 +73,29 @@ public abstract class View implements SwingConstants
public abstract void paint(Graphics g, Shape s);
+ /**
+ * Sets the parent for this view. This is the first method that is beeing
+ * called on a view to setup the view hierarchy. This is also the last method
+ * beeing called when the view is disconnected from the view hierarchy, in
+ * this case <code>parent</code> is null.
+ *
+ * If <code>parent</code> is <code>null</code>, a call to this method also
+ * calls <code>setParent</code> on the children, thus disconnecting them from
+ * the view hierarchy. That means that super must be called when this method
+ * is overridden.
+ *
+ * @param parent the parent to set, <code>null</code> when this view is
+ * beeing disconnected from the view hierarchy
+ */
public void setParent(View parent)
{
+ if (parent == null)
+ {
+ int numChildren = getViewCount();
+ for (int i = 0; i < numChildren; i++)
+ getView(i).setParent(null);
+ }
+
this.parent = parent;
}
@@ -101,27 +123,65 @@ public abstract class View implements SwingConstants
return elt;
}
+ /**
+ * Returns the preferred span along the specified axis. Normally the view is
+ * rendered with the span returned here if that is possible.
+ *
+ * @param axis the axis
+ *
+ * @return the preferred span along the specified axis
+ */
public abstract float getPreferredSpan(int axis);
+ /**
+ * Returns the resize weight of this view. A value of <code>0</code> or less
+ * means this view is not resizeable. Positive values make the view
+ * resizeable. The default implementation returns <code>0</code>
+ * unconditionally.
+ *
+ * @param axis the axis
+ *
+ * @return the resizability of this view along the specified axis
+ */
public int getResizeWeight(int axis)
{
return 0;
}
+ /**
+ * Returns the maximum span along the specified axis. The default
+ * implementation will forward to
+ * {@link #getPreferredSpan(int)} unless {@link #getResizeWeight(int)}
+ * returns a value > 0, in which case this returns {@link Integer#MIN_VALUE}.
+ *
+ * @param axis the axis
+ *
+ * @return the maximum span along the specified axis
+ */
public float getMaximumSpan(int axis)
{
+ float max = Integer.MAX_VALUE;
if (getResizeWeight(axis) <= 0)
- return getPreferredSpan(axis);
-
- return Integer.MAX_VALUE;
+ max = getPreferredSpan(axis);
+ return max;
}
+ /**
+ * Returns the minimum span along the specified axis. The default
+ * implementation will forward to
+ * {@link #getPreferredSpan(int)} unless {@link #getResizeWeight(int)}
+ * returns a value > 0, in which case this returns <code>0</code>.
+ *
+ * @param axis the axis
+ *
+ * @return the minimum span along the specified axis
+ */
public float getMinimumSpan(int axis)
{
+ float min = 0;
if (getResizeWeight(axis) <= 0)
- return getPreferredSpan(axis);
-
- return Integer.MAX_VALUE;
+ min = getPreferredSpan(axis);
+ return min;
}
public void setSize(float width, float height)
@@ -129,6 +189,20 @@ public abstract class View implements SwingConstants
// The default implementation does nothing.
}
+ /**
+ * Returns the alignment of this view along the baseline of the parent view.
+ * An alignment of <code>0.0</code> will align this view with the left edge
+ * along the baseline, an alignment of <code>0.5</code> will align it
+ * centered to the baseline, an alignment of <code>1.0</code> will align
+ * the right edge along the baseline.
+ *
+ * The default implementation returns 0.5 unconditionally.
+ *
+ * @param axis the axis
+ *
+ * @return the alignment of this view along the parents baseline for the
+ * specified axis
+ */
public float getAlignment(int axis)
{
return 0.5f;
@@ -160,6 +234,15 @@ public abstract class View implements SwingConstants
return parent != null ? parent.getViewFactory() : null;
}
+ /**
+ * Replaces a couple of child views with new child views. If
+ * <code>length == 0</code> then this is a simple insertion, if
+ * <code>views == null</code> this only removes some child views.
+ *
+ * @param offset the offset at which to replace
+ * @param length the number of child views to be removed
+ * @param views the new views to be inserted, may be <code>null</code>
+ */
public void replace(int offset, int length, View[] views)
{
// Default implementation does nothing.
@@ -392,6 +475,10 @@ public abstract class View implements SwingConstants
* of the change to the model. This calles {@link #forwardUpdateToView}
* for each View that must be forwarded to.
*
+ * If <code>ec</code> is not <code>null</code> (this means there have been
+ * structural changes to the element that this view is responsible for) this
+ * method should recognize this and don't notify newly added child views.
+ *
* @param ec the ElementChange describing the element changes (may be
* <code>null</code> if there were no changes)
* @param ev the DocumentEvent describing the changes to the model
@@ -404,10 +491,31 @@ public abstract class View implements SwingConstants
DocumentEvent ev, Shape shape, ViewFactory vf)
{
int count = getViewCount();
- for (int i = 0; i < count; i++)
+ if (count > 0)
{
- View child = getView(i);
- forwardUpdateToView(child, ev, shape, vf);
+ int startOffset = ev.getOffset();
+ int endOffset = startOffset + ev.getLength();
+ int startIndex = getViewIndex(startOffset, Position.Bias.Backward);
+ int endIndex = getViewIndex(endOffset, Position.Bias.Forward);
+ int index = -1;
+ int addLength = -1;
+ if (ec != null)
+ {
+ index = ec.getIndex();
+ addLength = ec.getChildrenAdded().length;
+ }
+
+ if (startIndex >= 0 && endIndex >= 0)
+ {
+ for (int i = startIndex; i <= endIndex; i++)
+ {
+ // Skip newly added child views.
+ if (index >= 0 && i >= index && i < (index+addLength))
+ continue;
+ View child = getView(i);
+ forwardUpdateToView(child, ev, shape, vf);
+ }
+ }
}
}
@@ -503,9 +611,9 @@ public abstract class View implements SwingConstants
if (b2 != Position.Bias.Forward && b2 != Position.Bias.Backward)
throw new IllegalArgumentException
("b2 must be either Position.Bias.Forward or Position.Bias.Backward");
- Shape s1 = modelToView(p1, a, b1);
- Shape s2 = modelToView(p2, a, b2);
- return s1.getBounds().union(s2.getBounds());
+ Rectangle s1 = (Rectangle) modelToView(p1, a, b1);
+ Rectangle s2 = (Rectangle) modelToView(p2, a, b2);
+ return SwingUtilities.computeUnion(s1.x, s1.y, s1.width, s1.height, s2);
}
/**
@@ -570,7 +678,7 @@ public abstract class View implements SwingConstants
* Dumps the complete View hierarchy. This method can be used for debugging
* purposes.
*/
- void dump()
+ protected void dump()
{
// Climb up the hierarchy to the parent.
View parent = getParent();
@@ -590,7 +698,7 @@ public abstract class View implements SwingConstants
{
for (int i = 0; i < indent; ++i)
System.out.print('.');
- System.out.println(this);
+ System.out.println(this + "(" + getStartOffset() + "," + getEndOffset() + ": " + getElement());
int count = getViewCount();
for (int i = 0; i < count; ++i)