diff options
author | Roman Kennke <roman@kennke.org> | 2006-02-21 13:56:15 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-02-21 13:56:15 +0000 |
commit | 5a1955ce950c4f0aa7dd9ea9dbcd441806befda6 (patch) | |
tree | 3d66c8dfbf3c99bddff9f211bcc30790e17d4fb3 | |
parent | 99b056ec56c15f6a11348ec21e57e4fdaa6be266 (diff) | |
download | classpath-5a1955ce950c4f0aa7dd9ea9dbcd441806befda6.tar.gz |
2006-02-21 Roman Kennke <kennke@aicas.com>
* javax/swing/text/AbstractDocument.java
(AbstractElement.getAttribute): Use getResolveParent() to fetch
the resolving parent.
(AbstractElement.getResolveParent): Fixed to handle possible null
parent.
* javax/swing/text/BoxView.java
(childReqs): New field.
(paint): Added debugging code (commented out).
(getPreferredSpan): Rewritten to use new update* methods.
(getMaximumSpan): Rewritten to return Integer.MAX_VALUE
for the minor axis and preferredSpan for the major axis.
(getMinimumSpan): Rewritten to use new update* methods.
(baselineRequirements): Rewritten to avoid creation of
unnecessary SizeRequirements objects.
(baselineLayout): Rewritten to use new update* methods.
(calculateMajorAxisRequirements): Rewritten to avoid creation of
unnecessary SizeRequirements objects.
(calculateMinorAxisRequirements): Rewritten to avoid creation of
unnecessary SizeRequirements objects.
(layout): Some robustness fixes for the layout. Turned AssertionErrors
into warnings.
(layoutMajorAxis): Rewritten to use new update* methods.
(layoutMinorAxis): Rewritten to use new update* methods.
(getChildRequirements): Replaced by the update* methods.
(getAlignment): Use update* methods.
(updateChildRequirements): New methods. Updates the child requirements
if necessary.
(updateRequirements): New methods. Updates the BoxView requirements
if necessary.
* javax/swing/text/DefaultStyledDocument.java
(ElementBuffer.insert): Added warning for illegal replacement operation.
* javax/swing/text/FlowView.java
(layoutRow): When offset doesn't change, return -1.
(LogicalView): Now subclasses BoxView.
(loadChildren): Let the CompositeView.setParent() load the children
of the logicalView.
(calculateMinorRequirements): New overridden method.
* javax/swing/text/GlyphView.java
(DefaultGlyphPainter.paint): Fixed typo.
(startOffset): Made field private.
(endOffset): Made field private.
(paint): Call getStartOffset() and getEndOffset() instead of the
element methods.
(isStrikeThrough): Fixed typo.
(breakView): Use Utilities.getBreakLocation() to determine best
break location.
(changedUpdate): Call preferencedChange on this instead of parent.
(removeUpdate): Call preferencedChange on this instead of parent.
* javax/swing/text/ParagraphView.java
(Row.getAlignment): For Y_AXIS, call super.
(getAlignment): Likewise.
* javax/swing/text/Utilities.java
(getBreakLocation): Set Segment object directly on the BreakIterator.
* javax/swing/text/html/HTML.java
(Attribute): Made class non-serializable and final as specified.
(Attribute(String)): Made constructor private.
(Attribute.compareTo): Removed.
(Attribute.equals): Removed.
(Attribute.hashCode): Removed.
(Tag): Made class non-comparable and non-serializable as specified.
(Tag.compareTo): Removed.
(Tag.equals): Removed.
(Tag.hashCode): Removed.
* javax/swing/text/html/HTMLDocument.java
(HTMLReader.blockOpen): Add tag as name attribute to element.
* javax/swing/text/html/HTMLEditorKit.java
(HTMLFactory.create): Create NullView for <head> tags, removed unused
fallback.
* javax/swing/text/html/InlineView.java
(setPropertiesFromAttributes): Call super.
* javax/swing/text/html/NullView.java: New class.
-rw-r--r-- | ChangeLog | 74 | ||||
-rw-r--r-- | javax/swing/text/AbstractDocument.java | 12 | ||||
-rw-r--r-- | javax/swing/text/BoxView.java | 286 | ||||
-rw-r--r-- | javax/swing/text/ComponentView.java | 3 | ||||
-rw-r--r-- | javax/swing/text/DefaultStyledDocument.java | 17 | ||||
-rw-r--r-- | javax/swing/text/FlowView.java | 184 | ||||
-rw-r--r-- | javax/swing/text/GlyphView.java | 31 | ||||
-rw-r--r-- | javax/swing/text/ParagraphView.java | 19 | ||||
-rw-r--r-- | javax/swing/text/Utilities.java | 8 | ||||
-rw-r--r-- | javax/swing/text/html/HTML.java | 79 | ||||
-rw-r--r-- | javax/swing/text/html/HTMLDocument.java | 10 | ||||
-rw-r--r-- | javax/swing/text/html/HTMLEditorKit.java | 28 | ||||
-rw-r--r-- | javax/swing/text/html/InlineView.java | 1 | ||||
-rw-r--r-- | javax/swing/text/html/NullView.java | 102 |
14 files changed, 475 insertions, 379 deletions
@@ -1,5 +1,79 @@ 2006-02-21 Roman Kennke <kennke@aicas.com> + * javax/swing/text/AbstractDocument.java + (AbstractElement.getAttribute): Use getResolveParent() to fetch + the resolving parent. + (AbstractElement.getResolveParent): Fixed to handle possible null + parent. + * javax/swing/text/BoxView.java + (childReqs): New field. + (paint): Added debugging code (commented out). + (getPreferredSpan): Rewritten to use new update* methods. + (getMaximumSpan): Rewritten to return Integer.MAX_VALUE + for the minor axis and preferredSpan for the major axis. + (getMinimumSpan): Rewritten to use new update* methods. + (baselineRequirements): Rewritten to avoid creation of + unnecessary SizeRequirements objects. + (baselineLayout): Rewritten to use new update* methods. + (calculateMajorAxisRequirements): Rewritten to avoid creation of + unnecessary SizeRequirements objects. + (calculateMinorAxisRequirements): Rewritten to avoid creation of + unnecessary SizeRequirements objects. + (layout): Some robustness fixes for the layout. Turned AssertionErrors + into warnings. + (layoutMajorAxis): Rewritten to use new update* methods. + (layoutMinorAxis): Rewritten to use new update* methods. + (getChildRequirements): Replaced by the update* methods. + (getAlignment): Use update* methods. + (updateChildRequirements): New methods. Updates the child requirements + if necessary. + (updateRequirements): New methods. Updates the BoxView requirements + if necessary. + * javax/swing/text/DefaultStyledDocument.java + (ElementBuffer.insert): Added warning for illegal replacement operation. + * javax/swing/text/FlowView.java + (layoutRow): When offset doesn't change, return -1. + (LogicalView): Now subclasses BoxView. + (loadChildren): Let the CompositeView.setParent() load the children + of the logicalView. + (calculateMinorRequirements): New overridden method. + * javax/swing/text/GlyphView.java + (DefaultGlyphPainter.paint): Fixed typo. + (startOffset): Made field private. + (endOffset): Made field private. + (paint): Call getStartOffset() and getEndOffset() instead of the + element methods. + (isStrikeThrough): Fixed typo. + (breakView): Use Utilities.getBreakLocation() to determine best + break location. + (changedUpdate): Call preferencedChange on this instead of parent. + (removeUpdate): Call preferencedChange on this instead of parent. + * javax/swing/text/ParagraphView.java + (Row.getAlignment): For Y_AXIS, call super. + (getAlignment): Likewise. + * javax/swing/text/Utilities.java + (getBreakLocation): Set Segment object directly on the BreakIterator. + * javax/swing/text/html/HTML.java + (Attribute): Made class non-serializable and final as specified. + (Attribute(String)): Made constructor private. + (Attribute.compareTo): Removed. + (Attribute.equals): Removed. + (Attribute.hashCode): Removed. + (Tag): Made class non-comparable and non-serializable as specified. + (Tag.compareTo): Removed. + (Tag.equals): Removed. + (Tag.hashCode): Removed. + * javax/swing/text/html/HTMLDocument.java + (HTMLReader.blockOpen): Add tag as name attribute to element. + * javax/swing/text/html/HTMLEditorKit.java + (HTMLFactory.create): Create NullView for <head> tags, removed unused + fallback. + * javax/swing/text/html/InlineView.java + (setPropertiesFromAttributes): Call super. + * javax/swing/text/html/NullView.java: New class. + +2006-02-21 Roman Kennke <kennke@aicas.com> + PR classpath/26368 * javax/swing/text/GapContent.java (GapContentPosition): Made class private. diff --git a/javax/swing/text/AbstractDocument.java b/javax/swing/text/AbstractDocument.java index 0568249e4..06040a756 100644 --- a/javax/swing/text/AbstractDocument.java +++ b/javax/swing/text/AbstractDocument.java @@ -1345,11 +1345,11 @@ public abstract class AbstractDocument implements Document, Serializable public Object getAttribute(Object key) { Object result = attributes.getAttribute(key); - if (result == null && element_parent != null) + if (result == null) { - AttributeSet parentSet = element_parent.getAttributes(); - if (parentSet != null) - result = parentSet.getAttribute(key); + AttributeSet resParent = getResolveParent(); + if (resParent != null) + result = resParent.getAttribute(key); } return result; } @@ -1386,9 +1386,7 @@ public abstract class AbstractDocument implements Document, Serializable */ public AttributeSet getResolveParent() { - if (attributes.getResolveParent() != null) - return attributes.getResolveParent(); - return element_parent.getAttributes(); + return attributes.getResolveParent(); } /** diff --git a/javax/swing/text/BoxView.java b/javax/swing/text/BoxView.java index c54335403..b5907dcbb 100644 --- a/javax/swing/text/BoxView.java +++ b/javax/swing/text/BoxView.java @@ -87,6 +87,11 @@ public class BoxView private int[] span = new int[2]; /** + * The SizeRequirements of the child views along the X_AXIS and Y_AXIS. + */ + private SizeRequirements[][] childReqs = new SizeRequirements[2][]; + + /** * Creates a new <code>BoxView</code> for the given * <code>Element</code> and axis. Valid values for the axis are * {@link View#X_AXIS} and {@link View#Y_AXIS}. @@ -274,6 +279,9 @@ public class BoxView public void paint(Graphics g, Shape a) { Rectangle inside = getInsideAllocation(a); + // TODO: Used for debugging. + //g.drawRect(inside.x, inside.y, inside.width, inside.height); + Rectangle copy = new Rectangle(inside); int count = getViewCount(); for (int i = 0; i < count; ++i) @@ -296,24 +304,14 @@ public class BoxView */ public float getPreferredSpan(int axis) { - if (!isLayoutValid(axis)) - { - if (axis == myAxis) - requirements[axis] = calculateMajorAxisRequirements(axis, - requirements[axis]); - else - requirements[axis] = calculateMinorAxisRequirements(axis, - requirements[axis]); - } + updateRequirements(axis); return requirements[axis].preferred; } /** * Returns the maximum span of this view along the specified axis. - * This calculates the maximum span using - * {@link #calculateMajorAxisRequirements} or - * {@link #calculateMinorAxisRequirements} (depending on the axis) and - * returns the resulting maximum span. + * This returns <code>Integer.MAX_VALUE</code> for the minor axis + * and the preferred span for the major axis. * * @param axis the axis * @@ -321,16 +319,12 @@ public class BoxView */ public float getMaximumSpan(int axis) { - if (!isLayoutValid(axis)) - { - if (axis == myAxis) - requirements[axis] = calculateMajorAxisRequirements(axis, - requirements[axis]); - else - requirements[axis] = calculateMinorAxisRequirements(axis, - requirements[axis]); - } - return requirements[axis].maximum; + float max; + if (axis == myAxis) + max = getPreferredSpan(axis); + else + max = Integer.MAX_VALUE; + return max; } /** @@ -346,15 +340,7 @@ public class BoxView */ public float getMinimumSpan(int axis) { - if (!isLayoutValid(axis)) - { - if (axis == myAxis) - requirements[axis] = calculateMajorAxisRequirements(axis, - requirements[axis]); - else - requirements[axis] = calculateMinorAxisRequirements(axis, - requirements[axis]); - } + updateRequirements(axis); return requirements[axis].minimum; } @@ -373,8 +359,45 @@ public class BoxView protected SizeRequirements baselineRequirements(int axis, SizeRequirements sr) { - SizeRequirements[] childReqs = getChildRequirements(axis); - return SizeRequirements.getAlignedSizeRequirements(childReqs); + updateChildRequirements(axis); + + SizeRequirements res = sr; + if (res == null) + res = new SizeRequirements(); + + float minLeft = 0; + float minRight = 0; + float prefLeft = 0; + float prefRight = 0; + float maxLeft = 0; + float maxRight = 0; + for (int i = 0; i < childReqs[axis].length; i++) + { + float myMinLeft = childReqs[axis][i].minimum * childReqs[axis][i].alignment; + float myMinRight = childReqs[axis][i].minimum - myMinLeft; + minLeft = Math.max(myMinLeft, minLeft); + minRight = Math.max(myMinRight, minRight); + float myPrefLeft = childReqs[axis][i].preferred * childReqs[axis][i].alignment; + float myPrefRight = childReqs[axis][i].preferred - myPrefLeft; + prefLeft = Math.max(myPrefLeft, prefLeft); + prefRight = Math.max(myPrefRight, prefRight); + float myMaxLeft = childReqs[axis][i].maximum * childReqs[axis][i].alignment; + float myMaxRight = childReqs[axis][i].maximum - myMaxLeft; + maxLeft = Math.max(myMaxLeft, maxLeft); + maxRight = Math.max(myMaxRight, maxRight); + } + int minSize = (int) (minLeft + minRight); + int prefSize = (int) (prefLeft + prefRight); + int maxSize = (int) (maxLeft + maxRight); + float align = prefLeft / (prefRight + prefLeft); + if (Float.isNaN(align)) + align = 0; + + res.alignment = align; + res.maximum = maxSize; + res.preferred = prefSize; + res.minimum = minSize; + return res; } /** @@ -389,12 +412,13 @@ public class BoxView protected void baselineLayout(int span, int axis, int[] offsets, int[] spans) { - SizeRequirements[] childReqs = getChildRequirements(axis); + updateChildRequirements(axis); + updateRequirements(axis); + // Calculate the spans and offsets using the SizeRequirements uility // methods. SizeRequirements.calculateAlignedPositions(span, requirements[axis], - childReqs, offsets, spans); - layoutValid[axis] = true; + childReqs[axis], offsets, spans); } /** @@ -411,8 +435,34 @@ public class BoxView protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements sr) { - SizeRequirements[] childReqs = getChildRequirements(axis); - return SizeRequirements.getTiledSizeRequirements(childReqs); + updateChildRequirements(axis); + + SizeRequirements result = sr; + if (result == null) + result = new SizeRequirements(); + + long minimum = 0; + long preferred = 0; + long maximum = 0; + for (int i = 0; i < children.length; i++) + { + minimum += childReqs[axis][i].minimum; + preferred += childReqs[axis][i].preferred; + maximum += childReqs[axis][i].maximum; + } + // Overflow check. + if (minimum > Integer.MAX_VALUE) + minimum = Integer.MAX_VALUE; + if (preferred > Integer.MAX_VALUE) + preferred = Integer.MAX_VALUE; + if (maximum > Integer.MAX_VALUE) + maximum = Integer.MAX_VALUE; + + result.minimum = (int) minimum; + result.preferred = (int) preferred; + result.maximum = (int) maximum; + result.alignment = 0.5F; + return result; } /** @@ -428,10 +478,47 @@ public class BoxView * the specified axis */ protected SizeRequirements calculateMinorAxisRequirements(int axis, - SizeRequirements sr) + SizeRequirements sr) { - SizeRequirements[] childReqs = getChildRequirements(axis); - return SizeRequirements.getAlignedSizeRequirements(childReqs); + updateChildRequirements(axis); + + SizeRequirements res = sr; + if (res == null) + res = new SizeRequirements(); + + float minLeft = 0; + float minRight = 0; + float prefLeft = 0; + float prefRight = 0; + float maxLeft = 0; + float maxRight = 0; + for (int i = 0; i < childReqs[axis].length; i++) + { + float myMinLeft = childReqs[axis][i].minimum * childReqs[axis][i].alignment; + float myMinRight = childReqs[axis][i].minimum - myMinLeft; + minLeft = Math.max(myMinLeft, minLeft); + minRight = Math.max(myMinRight, minRight); + float myPrefLeft = childReqs[axis][i].preferred * childReqs[axis][i].alignment; + float myPrefRight = childReqs[axis][i].preferred - myPrefLeft; + prefLeft = Math.max(myPrefLeft, prefLeft); + prefRight = Math.max(myPrefRight, prefRight); + float myMaxLeft = childReqs[axis][i].maximum * childReqs[axis][i].alignment; + float myMaxRight = childReqs[axis][i].maximum - myMaxLeft; + maxLeft = Math.max(myMaxLeft, maxLeft); + maxRight = Math.max(myMaxRight, maxRight); + } + int minSize = (int) (minLeft + minRight); + int prefSize = (int) (prefLeft + prefRight); + int maxSize = (int) (maxLeft + maxRight); + float align = prefLeft / (prefRight + prefLeft); + if (Float.isNaN(align)) + align = 0; + + res.alignment = align; + res.maximum = maxSize; + res.preferred = prefSize; + res.minimum = minSize; + return res; } @@ -559,11 +646,10 @@ public class BoxView int minorAxis = myAxis == X_AXIS ? Y_AXIS : X_AXIS; if ((! isLayoutValid(minorAxis)) || newSpan[minorAxis] != span[minorAxis]) { - requirements[minorAxis] = calculateMinorAxisRequirements(minorAxis, - requirements[minorAxis]); - layoutMinorAxis(newSpan[minorAxis], minorAxis, offsets[minorAxis], + layoutValid[minorAxis] = false; + span[minorAxis] = newSpan[minorAxis]; + layoutMinorAxis(span[minorAxis], minorAxis, offsets[minorAxis], spans[minorAxis]); - span[myAxis] = newSpan[myAxis]; // Update the child view's sizes. for (int i = 0; i < count; ++i) @@ -577,11 +663,10 @@ public class BoxView // Update major axis as appropriate. if ((! isLayoutValid(myAxis)) || newSpan[myAxis] != span[myAxis]) { - requirements[myAxis] = calculateMajorAxisRequirements(myAxis, - requirements[myAxis]); - layoutMajorAxis(newSpan[myAxis], myAxis, offsets[myAxis], - spans[myAxis]); + layoutValid[myAxis] = false; span[myAxis] = newSpan[myAxis]; + layoutMajorAxis(span[myAxis], myAxis, offsets[myAxis], + spans[myAxis]); // Update the child view's sizes. for (int i = 0; i < count; ++i) @@ -591,11 +676,10 @@ public class BoxView layoutValid[myAxis] = true; } - - assert layoutValid[myAxis] == true - : "Major axis layout must be valid after layout"; - assert layoutValid[minorAxis] == true - : "Minor axis layout must be valid after layout"; + if (layoutValid[myAxis] == false) + System.err.println("WARNING: Major axis layout must be valid after layout"); + if (layoutValid[minorAxis] == false) + System.err.println("Minor axis layout must be valid after layout"); } /** @@ -610,12 +694,15 @@ public class BoxView protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) { - SizeRequirements[] childReqs = getChildRequirements(axis); + updateChildRequirements(axis); + updateRequirements(axis); + // Calculate the spans and offsets using the SizeRequirements uility // methods. - SizeRequirements.calculateTiledPositions(targetSpan, null, childReqs, + SizeRequirements.calculateTiledPositions(targetSpan, requirements[axis], + childReqs[axis], offsets, spans); - layoutValid[axis] = true; + } /** @@ -630,12 +717,14 @@ public class BoxView protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) { - SizeRequirements[] childReqs = getChildRequirements(axis); + updateChildRequirements(axis); + updateRequirements(axis); + // Calculate the spans and offsets using the SizeRequirements uility // methods. SizeRequirements.calculateAlignedPositions(targetSpan, requirements[axis], - childReqs, offsets, spans); - layoutValid[axis] = true; + childReqs[axis], offsets, + spans); } /** @@ -683,29 +772,6 @@ public class BoxView } /** - * Returns the size requirements of this view's children for the major - * axis. - * - * @return the size requirements of this view's children for the major - * axis - */ - private SizeRequirements[] getChildRequirements(int axis) - { - // Allocate SizeRequirements for each child view. - int count = getViewCount(); - SizeRequirements[] childReqs = new SizeRequirements[count]; - for (int i = 0; i < count; ++i) - { - View view = getView(i); - childReqs[i] = new SizeRequirements((int) view.getMinimumSpan(axis), - (int) view.getPreferredSpan(axis), - (int) view.getMaximumSpan(axis), - view.getAlignment(axis)); - } - return childReqs; - } - - /** * Returns the span for the child view with the given index for the specified * axis. * @@ -758,9 +824,7 @@ public class BoxView align = 0.5F; else { - if (! isLayoutValid(axis)) - requirements[axis] = calculateMinorAxisRequirements(axis, - requirements[axis]); + updateRequirements(axis); align = requirements[axis].alignment; } return align; @@ -773,7 +837,7 @@ public class BoxView * @param height indicates that the preferred height of the child changed. * @param child the child View. */ - public void preferenceChanged (View child, boolean width, boolean height) + public void preferenceChanged(View child, boolean width, boolean height) { if (width) layoutValid[X_AXIS] = false; @@ -860,4 +924,50 @@ public class BoxView // FIXME: What to do here? return super.flipEastAndWestAtEnds(position, bias); } + + /** + * Updates the child requirements along the specified axis. The requirements + * are only updated if the layout for the specified axis is marked as + * invalid. + * + * @param axis the axis to be updated + */ + private void updateChildRequirements(int axis) + { + if (! isLayoutValid(axis)) + { + int numChildren = getViewCount(); + if (childReqs[axis] == null || childReqs[axis].length != numChildren) + childReqs[axis] = new SizeRequirements[numChildren]; + for (int i = 0; i < numChildren; ++i) + { + View child = getView(i); + childReqs[axis][i] = + new SizeRequirements((int) child.getMinimumSpan(axis), + (int) child.getPreferredSpan(axis), + (int) child.getMaximumSpan(axis), + child.getAlignment(axis)); + } + } + } + + /** + * Updates the view's cached requirements along the specified axis if + * necessary. The requirements are only updated if the layout for the + * specified axis is marked as invalid. + * + * @param axis the axis + */ + private void updateRequirements(int axis) + { + if (! layoutValid[axis]) + { + if (axis == myAxis) + requirements[axis] = calculateMajorAxisRequirements(axis, + requirements[axis]); + else + requirements[axis] = calculateMinorAxisRequirements(axis, + requirements[axis]); + } + } } diff --git a/javax/swing/text/ComponentView.java b/javax/swing/text/ComponentView.java index 2846f8b53..a7d237ab7 100644 --- a/javax/swing/text/ComponentView.java +++ b/javax/swing/text/ComponentView.java @@ -228,8 +228,9 @@ public class ComponentView extends View * * @param p the parent view to set */ - void setParentImpl(View p) + private void setParentImpl(View p) { + super.setParent(p); if (p != null) { Component c = getComponent(); diff --git a/javax/swing/text/DefaultStyledDocument.java b/javax/swing/text/DefaultStyledDocument.java index 9e893ae41..06c56b56b 100644 --- a/javax/swing/text/DefaultStyledDocument.java +++ b/javax/swing/text/DefaultStyledDocument.java @@ -729,9 +729,20 @@ public class DefaultStyledDocument extends AbstractDocument implements // first place. if (removed.length > 0 || added.length > 0) { - e.replace(curr.index, removed.length, added); - ElementEdit ee = new ElementEdit(e, curr.index, removed, added); - ev.addEdit(ee); + if (curr.index + removed.length <= e.getElementCount()) + { + e.replace(curr.index, removed.length, added); + ElementEdit ee = new ElementEdit(e, curr.index, removed, added); + ev.addEdit(ee); + } + else + { + System.err.println("WARNING: Tried to replace elements "); + System.err.print("beyond boundaries: elementCount: "); + System.err.println(e.getElementCount()); + System.err.print("index: " + curr.index); + System.err.println(", removed.length: " + removed.length); + } } } } diff --git a/javax/swing/text/FlowView.java b/javax/swing/text/FlowView.java index 6d97a0351..219ab8ebe 100644 --- a/javax/swing/text/FlowView.java +++ b/javax/swing/text/FlowView.java @@ -38,13 +38,10 @@ exception statement from your version. */ package javax.swing.text; -import java.awt.Container; -import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; -import java.util.Iterator; -import java.util.Vector; +import javax.swing.SizeRequirements; import javax.swing.event.DocumentEvent; /** @@ -215,7 +212,7 @@ public abstract class FlowView extends BoxView int rowViewCount = row.getViewCount(); offset = row.getView(rowViewCount - 1).getEndOffset(); } - return offset; + return offset != pos ? offset : -1; } /** @@ -317,149 +314,14 @@ public abstract class FlowView extends BoxView * visual representation, this is handled by the physical view implemented * in the <code>FlowView</code>. */ - class LogicalView extends View + class LogicalView extends BoxView { /** - * The child views of this logical view. - */ - Vector children; - - /** * Creates a new LogicalView instance. */ - LogicalView(Element el) - { - super(el); - children = new Vector(); - } - - /** - * Returns the container that holds this view. The logical view returns - * the enclosing FlowView's container here. - * - * @return the container that holds this view - */ - public Container getContainer() - { - return FlowView.this.getContainer(); - } - - /** - * Returns the number of child views of this logical view. - * - * @return the number of child views of this logical view - */ - public int getViewCount() - { - return children.size(); - } - - /** - * Returns the child view at the specified index. - * - * @param index the index - * - * @return the child view at the specified index - */ - public View getView(int index) - { - return (View) children.get(index); - } - - /** - * Replaces some child views with other child views. - * - * @param offset the offset at which to replace child views - * @param length the number of children to remove - * @param views the views to be inserted - */ - public void replace(int offset, int length, View[] views) - { - if (length > 0) - { - for (int count = 0; count < length; ++count) - children.remove(offset); - } - - int endOffset = offset + views.length; - for (int i = offset; i < endOffset; ++i) - { - children.add(i, views[i - offset]); - // Set the parent of the child views to the flow view itself so - // it has something to resolve. - views[i - offset].setParent(FlowView.this); - } - } - - /** - * Returns the index of the child view that contains the specified - * position in the document model. - * - * @param pos the position for which we are searching the child view - * @param b the bias - * - * @return the index of the child view that contains the specified - * position in the document model - */ - public int getViewIndex(int pos, Position.Bias b) + LogicalView(Element el, int axis) { - int index = -1; - int i = 0; - for (Iterator it = children.iterator(); it.hasNext(); i++) - { - View child = (View) it.next(); - if (pos >= child.getStartOffset() && pos < child.getEndOffset()) - { - index = i; - break; - } - } - return index; - } - - /** - * Throws an AssertionError because it must never be called. LogicalView - * only serves as a holder for child views and has no visual - * representation. - */ - public float getPreferredSpan(int axis) - { - throw new AssertionError("This method must not be called in " - + "LogicalView."); - } - - /** - * Throws an AssertionError because it must never be called. LogicalView - * only serves as a holder for child views and has no visual - * representation. - */ - public Shape modelToView(int pos, Shape a, Position.Bias b) - throws BadLocationException - { - throw new AssertionError("This method must not be called in " - + "LogicalView."); - } - - /** - * Throws an AssertionError because it must never be called. LogicalView - * only serves as a holder for child views and has no visual - * representation. - */ - public void paint(Graphics g, Shape s) - { - throw new AssertionError("This method must not be called in " - + "LogicalView."); - } - - /** - * Throws an AssertionError because it must never be called. LogicalView - * only serves as a holder for child views and has no visual - * representation. - */ - public int viewToModel(float x, float y, Shape a, Position.Bias[] b) - { - throw new AssertionError("This method must not be called in " - + "LogicalView."); + super(el, axis); } } @@ -581,16 +443,8 @@ public abstract class FlowView extends BoxView { if (layoutPool == null) { - layoutPool = new LogicalView(getElement()); + layoutPool = new LogicalView(getElement(), getAxis()); layoutPool.setParent(this); - Element el = getElement(); - int count = el.getElementCount(); - for (int i = 0; i < count; ++i) - { - Element childEl = el.getElement(i); - View childView = vf.create(childEl); - layoutPool.append(childView); - } } } @@ -719,4 +573,30 @@ public abstract class FlowView extends BoxView } return result; } + + /** + * Calculates the size requirements of this <code>BoxView</code> along + * its minor axis, that is the axis opposite to the axis specified in the + * constructor. + * + * This is overridden and forwards the request to the logical view. + * + * @param axis the axis that is examined + * @param r the <code>SizeRequirements</code> object to hold the result, + * if <code>null</code>, a new one is created + * + * @return the size requirements for this <code>BoxView</code> along + * the specified axis + */ + protected SizeRequirements calculateMinorAxisRequirements(int axis, + SizeRequirements r) + { + // We need to call super here so that the alignment is properly + // calculated. + SizeRequirements res = super.calculateMinorAxisRequirements(axis, r); + res.minimum = (int) layoutPool.getMinimumSpan(axis); + res.preferred = (int) layoutPool.getPreferredSpan(axis); + res.maximum = (int) layoutPool.getMaximumSpan(axis); + return res; + } } diff --git a/javax/swing/text/GlyphView.java b/javax/swing/text/GlyphView.java index 9a25f947c..d505274c9 100644 --- a/javax/swing/text/GlyphView.java +++ b/javax/swing/text/GlyphView.java @@ -311,7 +311,7 @@ public class GlyphView extends View implements TabableView, Cloneable Utilities.drawTabbedText(txt, bounds.x, bounds.y + ascent, g, tabEx, txt.offset); - if (view.isStikeThrough()) + if (view.isStrikeThrough()) { int strikeHeight = (int) (getAscent(view) / 2); g.drawLine(bounds.x, bounds.y + strikeHeight, bounds.height + width, @@ -474,12 +474,12 @@ public class GlyphView extends View implements TabableView, Cloneable /** * The start offset within the document for this view. */ - int startOffset; + private int startOffset; /** * The end offset within the document for this view. */ - int endOffset; + private int endOffset; /** * Creates a new <code>GlyphView</code> for the given <code>Element</code>. @@ -538,8 +538,7 @@ public class GlyphView extends View implements TabableView, Cloneable { Element el = getElement(); checkPainter(); - getGlyphPainter().paint(this, g, a, el.getStartOffset(), - el.getEndOffset()); + getGlyphPainter().paint(this, g, a, getStartOffset(), getEndOffset()); } @@ -568,6 +567,7 @@ public class GlyphView extends View implements TabableView, Cloneable } else span = painter.getHeight(this); + return span; } @@ -796,7 +796,7 @@ public class GlyphView extends View implements TabableView, Cloneable * * @return whether the text should be rendered strike-through or not */ - public boolean isStikeThrough() + public boolean isStrikeThrough() { Element el = getElement(); AttributeSet atts = el.getAttributes(); @@ -890,13 +890,15 @@ public class GlyphView extends View implements TabableView, Cloneable checkPainter(); GlyphPainter painter = getGlyphPainter(); - int breakLocation = painter.getBoundedPosition(this, p0, pos, len); + // Try to find a suitable line break. BreakIterator lineBreaker = BreakIterator.getLineInstance(); Segment txt = new Segment(); try { - getDocument().getText(getStartOffset(), getEndOffset(), txt); + int start = getStartOffset(); + int length = getEndOffset() - start; + getDocument().getText(start, length, txt); } catch (BadLocationException ex) { @@ -905,11 +907,10 @@ public class GlyphView extends View implements TabableView, Cloneable err.initCause(ex); throw err; } - lineBreaker.setText(txt); - int goodBreakLocation = lineBreaker.previous(); - if (goodBreakLocation != BreakIterator.DONE) - breakLocation = goodBreakLocation; - + int breakLocation = + Utilities.getBreakLocation(txt, getContainer().getFontMetrics(getFont()), + (int) pos, (int) (pos + len), + getTabExpander(), p0); View brokenView = createFragment(p0, breakLocation); return brokenView; } @@ -970,7 +971,7 @@ public class GlyphView extends View implements TabableView, Cloneable */ public void changedUpdate(DocumentEvent e, Shape a, ViewFactory vf) { - getParent().preferenceChanged(this, true, true); + preferenceChanged(this, true, true); } /** @@ -1000,7 +1001,7 @@ public class GlyphView extends View implements TabableView, Cloneable */ public void removeUpdate(DocumentEvent e, Shape a, ViewFactory vf) { - getParent().preferenceChanged(this, true, false); + preferenceChanged(this, true, false); } /** diff --git a/javax/swing/text/ParagraphView.java b/javax/swing/text/ParagraphView.java index 874041f9a..15bed7818 100644 --- a/javax/swing/text/ParagraphView.java +++ b/javax/swing/text/ParagraphView.java @@ -66,9 +66,14 @@ public class ParagraphView extends FlowView implements TabExpander public float getAlignment(int axis) { - // FIXME: This is very likely not 100% correct. Work this out. - return 0.0F; + float align; + if (axis == X_AXIS) + align = 0.0F; // TODO: Implement according to justification + else + align = super.getAlignment(axis); + return align; } + protected void loadChildren(ViewFactory vf) { // Do nothing here. The children are added while layouting. @@ -133,17 +138,18 @@ public class ParagraphView extends FlowView implements TabExpander */ public float getAlignment(int axis) { + float align; if (axis == X_AXIS) - return 0.0F; + align = super.getAlignment(axis); else if (getViewCount() > 0) { - float prefHeight = getPreferredSpan(Y_AXIS); float firstRowHeight = getView(0).getPreferredSpan(Y_AXIS); - return (firstRowHeight / 2.F) / prefHeight; + align = (firstRowHeight / 2.F) / prefHeight; } else - return 0.0F; + align = 0.0F; + return align; } /** @@ -414,5 +420,4 @@ public class ParagraphView extends FlowView implements TabExpander // This method is not used. return 0; } - } diff --git a/javax/swing/text/Utilities.java b/javax/swing/text/Utilities.java index 439f3f82c..2372aee8b 100644 --- a/javax/swing/text/Utilities.java +++ b/javax/swing/text/Utilities.java @@ -41,12 +41,8 @@ package javax.swing.text; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Point; -import java.awt.Rectangle; import java.text.BreakIterator; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; - /** * A set of utilities to deal with text. This is used by several other classes * inside this package. @@ -516,8 +512,8 @@ public class Utilities { int mark = Utilities.getTabbedTextOffset(s, metrics, x0, x, e, startOffset); BreakIterator breaker = BreakIterator.getWordInstance(); - breaker.setText(s.toString()); - + breaker.setText(s); + // If mark is equal to the end of the string, just use that position if (mark == s.count) return mark; diff --git a/javax/swing/text/html/HTML.java b/javax/swing/text/html/HTML.java index 0b758d2b8..2b521cd22 100644 --- a/javax/swing/text/html/HTML.java +++ b/javax/swing/text/html/HTML.java @@ -57,8 +57,7 @@ public class HTML /** * Represents a HTML attribute. */ - public static class Attribute - implements Serializable + public static final class Attribute { /** * The action attribute @@ -464,47 +463,18 @@ public class HTML * The width attribute */ public static final Attribute WIDTH = new Attribute("width"); - private final String name; - - /** - * Creates the attribute with the given name. - */ - protected Attribute(String a_name) - { - name = a_name; - } - - /** - * Calls compareTo on the tag names (Strings) - */ - public int compareTo(Object other) - { - return name.compareTo(((Attribute) other).name); - } /** - * The attributes are equal if the names are equal - * (ignoring case) + * The attribute name. */ - public boolean equals(Object other) - { - if (other == this) - return true; - - if (!(other instanceof Attribute)) - return false; - - Attribute that = (Attribute) other; - - return that.name.equalsIgnoreCase(name); - } + private final String name; /** - * Returns the hash code which corresponds to the string for this tag. + * Creates the attribute with the given name. */ - public int hashCode() + private Attribute(String a_name) { - return name == null ? 0 : name.hashCode(); + name = a_name; } /** @@ -559,7 +529,6 @@ public class HTML * Represents a HTML tag. */ public static class Tag - implements Comparable, Serializable { /** * The <a> tag @@ -1047,42 +1016,6 @@ public class HTML } /** - * Calls compareTo on the tag names (Strings) - */ - public int compareTo(Object other) - { - return name.compareTo(((Tag) other).name); - } - - /** - * The tags are equal if the names are equal (ignoring case). - */ - public boolean equals(Object other) - { - if (other == this) - { - return true; - } - - if (!(other instanceof Tag)) - { - return false; - } - - Tag that = (Tag) other; - - return that.name.equalsIgnoreCase(name); - } - - /** - * Returns the hash code which corresponds to the string for this tag. - */ - public int hashCode() - { - return name == null ? 0 : name.hashCode(); - } - - /** * Returns the tag name. The names of the built-in tags are always * returned in lowercase. */ diff --git a/javax/swing/text/html/HTMLDocument.java b/javax/swing/text/html/HTMLDocument.java index e208edddc..062fdd5fe 100644 --- a/javax/swing/text/html/HTMLDocument.java +++ b/javax/swing/text/html/HTMLDocument.java @@ -475,7 +475,7 @@ public class HTMLDocument extends DefaultStyledDocument { public BlockElement (Element parent, AttributeSet a) { - super (parent, a); + super(parent, a); } /** @@ -1286,13 +1286,15 @@ public class HTMLDocument extends DefaultStyledDocument { printBuffer(); DefaultStyledDocument.ElementSpec element; - attr.addAttribute(StyleConstants.NameAttribute, t); - element = new DefaultStyledDocument.ElementSpec(attr, + AttributeContext ctx = getAttributeContext(); + AttributeSet copy = attr.copyAttributes(); + copy = ctx.addAttribute(copy, StyleConstants.NameAttribute, t); + element = new DefaultStyledDocument.ElementSpec(copy, DefaultStyledDocument.ElementSpec.StartTagType); parseBuffer.addElement(element); printBuffer(); } - + /** * Instructs the parse buffer to close the block element associated with * the given HTML.Tag diff --git a/javax/swing/text/html/HTMLEditorKit.java b/javax/swing/text/html/HTMLEditorKit.java index 59c207858..8bfd69e98 100644 --- a/javax/swing/text/html/HTMLEditorKit.java +++ b/javax/swing/text/html/HTMLEditorKit.java @@ -56,17 +56,11 @@ import javax.accessibility.AccessibleContext; import javax.swing.Action; import javax.swing.JEditorPane; -import javax.swing.text.AbstractDocument; import javax.swing.text.BadLocationException; -import javax.swing.text.BoxView; -import javax.swing.text.ComponentView; import javax.swing.text.Document; import javax.swing.text.EditorKit; import javax.swing.text.Element; -import javax.swing.text.IconView; -import javax.swing.text.LabelView; import javax.swing.text.MutableAttributeSet; -import javax.swing.text.ParagraphView; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; import javax.swing.text.StyledEditorKit; @@ -532,8 +526,8 @@ public class HTMLEditorKit public View create(Element element) { View view = null; - Object attr = element.getAttributes().getAttribute( - StyleConstants.NameAttribute); + Object attr = + element.getAttributes().getAttribute(StyleConstants.NameAttribute); if (attr instanceof HTML.Tag) { HTML.Tag tag = (HTML.Tag) attr; @@ -555,6 +549,9 @@ public class HTMLEditorKit // FIXME: Uncomment when the views have been implemented else if (tag.equals(HTML.Tag.CONTENT)) view = new InlineView(element); + else if (tag == HTML.Tag.HEAD) + view = new NullView(element); + /* else if (tag.equals(HTML.Tag.MENU) || tag.equals(HTML.Tag.DIR) || tag.equals(HTML.Tag.UL) || tag.equals(HTML.Tag.OL)) @@ -577,21 +574,6 @@ public class HTMLEditorKit else if (tag.equals(HTML.Tag.FRAME)) view = new FrameView(element); */ } - - if (view == null) - { - String name = element.getName(); - if (name.equals(AbstractDocument.ContentElementName)) - view = new LabelView(element); - else if (name.equals(AbstractDocument.ParagraphElementName)) - view = new ParagraphView(element); - else if (name.equals(AbstractDocument.SectionElementName)) - view = new BoxView(element, View.Y_AXIS); - else if (name.equals(StyleConstants.ComponentElementName)) - view = new ComponentView(element); - else if (name.equals(StyleConstants.IconElementName)) - view = new IconView(element); - } return view; } } diff --git a/javax/swing/text/html/InlineView.java b/javax/swing/text/html/InlineView.java index 7e2b9a0a9..77ec86e82 100644 --- a/javax/swing/text/html/InlineView.java +++ b/javax/swing/text/html/InlineView.java @@ -146,6 +146,7 @@ public class InlineView protected void setPropertiesFromAttributes() { // FIXME: Implement this. + super.setPropertiesFromAttributes(); } /** diff --git a/javax/swing/text/html/NullView.java b/javax/swing/text/html/NullView.java new file mode 100644 index 000000000..4b66c5ad8 --- /dev/null +++ b/javax/swing/text/html/NullView.java @@ -0,0 +1,102 @@ +/* NullView.java -- A dummy view that renders nothing + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.text.html; + +import java.awt.Graphics; +import java.awt.Shape; + +import javax.swing.text.BadLocationException; +import javax.swing.text.Element; +import javax.swing.text.View; +import javax.swing.text.Position.Bias; + +/** + * A dummy view that renders nothing. This is used for invisible HTML elements + * like <head>. + * + * @author Roman Kennke (kennke@aicas.com) + */ +public class NullView + extends View +{ + + /** + * Creates a new NullView. + * + * @param elem the element + */ + public NullView(Element elem) + { + super(elem); + } + + /** + * Does nothing. + */ + public void paint(Graphics g, Shape s) + { + // Nothing to do here. + } + + /** + * Returns zero for both directions. + */ + public float getPreferredSpan(int axis) + { + return 0; + } + + /** + * Returns the allocation of this view, which should be empty anyway. + */ + public Shape modelToView(int pos, Shape a, Bias b) + throws BadLocationException + { + return a; + } + + /** + * Returns the start offset of the element. + */ + public int viewToModel(float x, float y, Shape a, Bias[] b) + { + return getElement().getStartOffset(); + } + +} |