summaryrefslogtreecommitdiff
path: root/javax/swing/text
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-11-20 11:18:04 +0000
committerRoman Kennke <roman@kennke.org>2006-11-20 11:18:04 +0000
commitcae822ad6e80f552bbf44bd42d2d47d5bdfd759d (patch)
treefc86ebe5867387b8033242d8610e0ab97b3e8168 /javax/swing/text
parent306331a3743616637d2c42b7a830a9853f2c1488 (diff)
downloadclasspath-cae822ad6e80f552bbf44bd42d2d47d5bdfd759d.tar.gz
2006-11-20 Roman Kennke <kennke@aicas.com>
* javax/swing/text/BoxView.java (BoxView): Initialize with invalid req's. (forwardUpdate): Trigger repaint when children changed the major axis. (getResizeWeight): Return resizable when the pref differs from the min or the pref differs from the max size. (layoutMajorAxis): Actually sum up the preferred sizes. (paint): Made binary search more robust. (replace): Let arrays shrink when needed. (replaceLayoutArray): Let arrays shrink when needed. (setAxis): Trigger preferenceChanged. * javax/swing/text/CompositeView.java (getInsideAllocation): Call insets method to take account of overriding subclasses. * javax/swing/text/DefaultStyledDocument.java (ElementBuffer.finishEdit): Clear the stack and edits buffer. (ElementBuffer.insertUpdate): Only remove the found element, not all. * javax/swing/text/GlyphView.java (insertUpdate): Pass null in preferenceChanged. (removeUpdate): Pass null in preferenceChanged. (changedUpdate): Pass null in preferenceChanged. * javax/swing/text/Utilities.java (drawTabbedText): Avoid single calls to charWidth() and instead call charsWidth() on whole chunks. * javax/swing/text/html/HTMLDocument.java (BlockElement.getName): Fall back to super when necessary. (RunElement.getName): Fall back to super when necessary. (HTMLReader.MAX_THRESHOLD): New constant field. (HTMLReader.GROW_THRESHOLD): New constant field. (HTMLReader.theshold): New field. (HTMLReader.HTMLReader): Fetch threshold from document. (HTMLReader.addContent): Sucessivly grow the threshold. (createLeafElement): Don't create two elemens and don't set attribute. * javax/swing/text/html/TableView.java (RowView.replace): Invalidate grid. (gridValid): Made package private. (layoutMinorAxis): Mark all rows as invalid. (replace): Invalidate grid.
Diffstat (limited to 'javax/swing/text')
-rw-r--r--javax/swing/text/BoxView.java98
-rw-r--r--javax/swing/text/CompositeView.java8
-rw-r--r--javax/swing/text/DefaultStyledDocument.java17
-rw-r--r--javax/swing/text/GlyphView.java6
-rw-r--r--javax/swing/text/Utilities.java52
-rw-r--r--javax/swing/text/html/HTMLDocument.java28
-rw-r--r--javax/swing/text/html/TableView.java24
7 files changed, 144 insertions, 89 deletions
diff --git a/javax/swing/text/BoxView.java b/javax/swing/text/BoxView.java
index 902927980..72bc07e75 100644
--- a/javax/swing/text/BoxView.java
+++ b/javax/swing/text/BoxView.java
@@ -38,6 +38,7 @@ 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;
@@ -105,6 +106,8 @@ public class BoxView
myAxis = axis;
layoutValid[0] = false;
layoutValid[1] = false;
+ requirementsValid[X_AXIS] = false;
+ requirementsValid[Y_AXIS] = false;
span[0] = 0;
span[1] = 0;
requirements[0] = new SizeRequirements();
@@ -141,7 +144,10 @@ public class BoxView
*/
public void setAxis(int axis)
{
+ boolean changed = axis != myAxis;
myAxis = axis;
+ if (changed)
+ preferenceChanged(null, true, true);
}
/**
@@ -222,35 +228,20 @@ public class BoxView
*/
public void replace(int offset, int length, View[] views)
{
- int oldNumChildren = getViewCount();
-
// Actually perform the replace.
super.replace(offset, length, views);
// Resize and copy data for cache arrays.
int newItems = views != null ? views.length : 0;
- int delta = newItems - length;
- int src = offset + length;
- int numMove = oldNumChildren - src;
- int dst = src + delta;
- offsets[X_AXIS] = replaceLayoutArray(offsets[X_AXIS], offset,
- oldNumChildren, delta, src, dst,
- numMove);
- spans[X_AXIS] = replaceLayoutArray(spans[X_AXIS], offset,
- oldNumChildren, delta, src, dst,
- numMove);
- offsets[Y_AXIS] = replaceLayoutArray(offsets[Y_AXIS], offset,
- oldNumChildren, delta, src, dst,
- numMove);
- spans[Y_AXIS] = replaceLayoutArray(spans[Y_AXIS], offset,
- oldNumChildren, delta, src, dst,
- numMove);
-
- // Invalidate layout information.
- layoutValid[X_AXIS] = false;
- requirementsValid[X_AXIS] = false;
- layoutValid[Y_AXIS] = false;
- requirementsValid[Y_AXIS] = false;
+ int minor = 1 - myAxis;
+ offsets[myAxis] = replaceLayoutArray(offsets[myAxis], offset, newItems);
+ spans[myAxis] = replaceLayoutArray(spans[myAxis], offset, newItems);
+ layoutValid[myAxis] = false;
+ requirementsValid[myAxis] = false;
+ offsets[minor] = replaceLayoutArray(offsets[minor], offset, newItems);
+ spans[minor] = replaceLayoutArray(spans[minor], offset, newItems);
+ layoutValid[minor] = false;
+ requirementsValid[minor] = false;
}
/**
@@ -261,23 +252,14 @@ public class BoxView
*
* @return the replaced array
*/
- private int[] replaceLayoutArray(int[] oldArray, int offset, int numChildren,
- int delta, int src, int dst, int numMove)
+ private int[] replaceLayoutArray(int[] oldArray, int offset, int newItems)
{
- int[] newArray;
- if (numChildren + delta > oldArray.length)
- {
- int newLength = Math.max(2 * oldArray.length, numChildren + delta);
- newArray = new int[newLength];
- System.arraycopy(oldArray, 0, newArray, 0, offset);
- System.arraycopy(oldArray, src, newArray, dst, numMove);
- }
- else
- {
- newArray = oldArray;
- System.arraycopy(newArray, src, newArray, dst, numMove);
- }
+ int num = getViewCount();
+ int[] newArray = new int[num];
+ System.arraycopy(oldArray, 0, newArray, 0, offset);
+ System.arraycopy(oldArray, offset, newArray, offset + newItems,
+ num - newItems - offset);
return newArray;
}
@@ -341,12 +323,14 @@ public class BoxView
newMid = (up - low) / 2 + low;
mid = (newMid == mid) ? newMid - 1 : newMid;
}
- else
+ else if (isAfter(cX, cY, tmpRect))
{
low = mid;
newMid = (up - low) / 2 + low;
mid = (newMid == mid) ? newMid + 1 : newMid;
}
+ else
+ break;
if (mid >= 0 && mid < viewCount)
{
start = getView(mid);
@@ -864,7 +848,7 @@ public class BoxView
{
View child = getView(i);
spans[i] = (int) child.getPreferredSpan(axis);
- sumPref = spans[i];
+ sumPref += spans[i];
}
// Try to adjust the spans so that we fill the targetSpan.
@@ -1105,9 +1089,11 @@ public class BoxView
{
if (axis != X_AXIS && axis != Y_AXIS)
throw new IllegalArgumentException("Illegal axis argument");
- int weight = 1;
- if (axis == myAxis)
- weight = 0;
+ updateRequirements(axis);
+ int weight = 0;
+ if ((requirements[axis].preferred != requirements[axis].minimum)
+ || (requirements[axis].preferred != requirements[axis].maximum))
+ weight = 1;
return weight;
}
@@ -1134,8 +1120,30 @@ public class BoxView
protected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent e,
Shape a, ViewFactory vf)
{
- // FIXME: What to do here?
+ boolean wasValid = isLayoutValid(myAxis);
super.forwardUpdate(ec, e, a, vf);
+ // Trigger repaint when one of the children changed the major axis.
+ if (wasValid && ! isLayoutValid(myAxis))
+ {
+ Container c = getContainer();
+ if (a != null && c != null)
+ {
+ int pos = e.getOffset();
+ int index = getViewIndexAtPosition(pos);
+ Rectangle r = getInsideAllocation(a);
+ if (myAxis == X_AXIS)
+ {
+ r.x += offsets[myAxis][index];
+ r.width -= offsets[myAxis][index];
+ }
+ else
+ {
+ r.y += offsets[myAxis][index];
+ r.height -= offsets[myAxis][index];
+ }
+ c.repaint(r.x, r.y, r.width, r.height);
+ }
+ }
}
public int viewToModel(float x, float y, Shape a, Position.Bias[] bias)
diff --git a/javax/swing/text/CompositeView.java b/javax/swing/text/CompositeView.java
index ac81e544f..90458b6f2 100644
--- a/javax/swing/text/CompositeView.java
+++ b/javax/swing/text/CompositeView.java
@@ -534,10 +534,10 @@ public abstract class CompositeView
// a synchronized block in order to avoid multiple threads creating
// this instance simultanously.
Rectangle inside = insideAllocation;
- inside.x = alloc.x + left;
- inside.y = alloc.y + top;
- inside.width = alloc.width - left - right;
- inside.height = alloc.height - top - bottom;
+ inside.x = alloc.x + getLeftInset();
+ inside.y = alloc.y + getTopInset();
+ inside.width = alloc.width - getLeftInset() - getRightInset();
+ inside.height = alloc.height - getTopInset() - getBottomInset();
return inside;
}
diff --git a/javax/swing/text/DefaultStyledDocument.java b/javax/swing/text/DefaultStyledDocument.java
index e97ee1dc1..015b09ca0 100644
--- a/javax/swing/text/DefaultStyledDocument.java
+++ b/javax/swing/text/DefaultStyledDocument.java
@@ -1039,6 +1039,8 @@ public class DefaultStyledDocument extends AbstractDocument implements
ElementEdit ee = new ElementEdit(parent, index, removed, added);
ev.addEdit(ee);
}
+ edits.clear();
+ elementStack.clear();
}
/**
@@ -1086,7 +1088,7 @@ public class DefaultStyledDocument extends AbstractDocument implements
createFracture(data);
i = 0;
}
-
+
// Handle each ElementSpec individually.
for (; i < data.length; i++)
{
@@ -1121,14 +1123,13 @@ public class DefaultStyledDocument extends AbstractDocument implements
if (offset == 0 && fracturedParent != null
&& data[0].getType() == ElementSpec.EndTagType)
{
- for (int p = 0;
+ int p;
+ for (p = 0;
p < data.length && data[p].getType() == ElementSpec.EndTagType;
- p++)
- {
- Edit edit = insertPath[insertPath.length - p - 1];
- edit.index--;
- edit.removed.add(0, edit.e.getElement(edit.index));
- }
+ p++);
+ Edit edit = insertPath[insertPath.length - p - 1];
+ edit.index--;
+ edit.removed.add(0, edit.e.getElement(edit.index));
}
}
diff --git a/javax/swing/text/GlyphView.java b/javax/swing/text/GlyphView.java
index e2303bbc9..d5070a6a9 100644
--- a/javax/swing/text/GlyphView.java
+++ b/javax/swing/text/GlyphView.java
@@ -1046,7 +1046,7 @@ public class GlyphView extends View implements TabableView, Cloneable
*/
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory vf)
{
- preferenceChanged(this, true, true);
+ preferenceChanged(null, true, true);
}
/**
@@ -1061,7 +1061,7 @@ public class GlyphView extends View implements TabableView, Cloneable
*/
public void insertUpdate(DocumentEvent e, Shape a, ViewFactory vf)
{
- preferenceChanged(this, true, false);
+ preferenceChanged(null, true, false);
}
/**
@@ -1076,7 +1076,7 @@ public class GlyphView extends View implements TabableView, Cloneable
*/
public void removeUpdate(DocumentEvent e, Shape a, ViewFactory vf)
{
- preferenceChanged(this, true, false);
+ preferenceChanged(null, true, false);
}
/**
diff --git a/javax/swing/text/Utilities.java b/javax/swing/text/Utilities.java
index e1243f640..d49d806cf 100644
--- a/javax/swing/text/Utilities.java
+++ b/javax/swing/text/Utilities.java
@@ -89,12 +89,12 @@ public class Utilities
// The font metrics of the current selected font.
FontMetrics metrics = g.getFontMetrics();
+
int ascent = metrics.getAscent();
// The current x and y pixel coordinates.
int pixelX = x;
- int pixelWidth = 0;
int pos = s.offset;
int len = 0;
@@ -103,39 +103,43 @@ public class Utilities
for (int offset = s.offset; offset < end; ++offset)
{
char c = buffer[offset];
- if (c == '\t')
+ switch (c)
{
+ case '\t':
if (len > 0) {
g.drawChars(buffer, pos, len, pixelX, y);
- pixelX += pixelWidth;
- pixelWidth = 0;
+ pixelX += metrics.charsWidth(buffer, pos, len);
+ len = 0;
}
pos = offset+1;
- len = 0;
+ if (e != null)
+ pixelX = (int) e.nextTabStop((float) pixelX, startOffset + offset
+ - s.offset);
+ else
+ pixelX += metrics.charWidth(' ');
+ x = pixelX;
+ break;
+ case '\n':
+ case '\r':
+ if (len > 0) {
+ g.drawChars(buffer, pos, len, pixelX, y);
+ pixelX += metrics.charsWidth(buffer, pos, len);
+ len = 0;
+ }
+ x = pixelX;
+ break;
+ default:
+ len += 1;
}
-
- switch (c)
- {
- case '\t':
- // In case we have a tab, we just 'jump' over the tab.
- // When we have no tab expander we just use the width of ' '.
- if (e != null)
- pixelX = (int) e.nextTabStop(pixelX,
- startOffset + offset - s.offset);
- else
- pixelX += metrics.charWidth(' ');
- break;
- default:
- ++len;
- pixelWidth += metrics.charWidth(buffer[offset]);
- break;
- }
}
if (len > 0)
- g.drawChars(buffer, pos, len, pixelX, y);
+ {
+ g.drawChars(buffer, pos, len, pixelX, y);
+ pixelX += metrics.charsWidth(buffer, pos, len);
+ }
- return pixelX + pixelWidth;
+ return pixelX;
}
/**
diff --git a/javax/swing/text/html/HTMLDocument.java b/javax/swing/text/html/HTMLDocument.java
index 3ff40b437..c0eafbf54 100644
--- a/javax/swing/text/html/HTMLDocument.java
+++ b/javax/swing/text/html/HTMLDocument.java
@@ -184,8 +184,6 @@ public class HTMLDocument extends DefaultStyledDocument
protected Element createLeafElement(Element parent, AttributeSet a, int p0,
int p1)
{
- RunElement el = new RunElement(parent, a, p0, p1);
- el.addAttribute(StyleConstants.NameAttribute, HTML.Tag.CONTENT);
return new RunElement(parent, a, p0, p1);
}
@@ -454,6 +452,8 @@ public class HTMLDocument extends DefaultStyledDocument
String name = null;
if (tag != null)
name = tag.toString();
+ if (name == null)
+ name = super.getName();
return name;
}
}
@@ -490,6 +490,8 @@ public class HTMLDocument extends DefaultStyledDocument
String name = null;
if (tag != null)
name = tag.toString();
+ if (name == null)
+ name = super.getName();
return name;
}
@@ -511,7 +513,17 @@ public class HTMLDocument extends DefaultStyledDocument
* @author Anthony Balkissoon abalkiss at redhat dot com
*/
public class HTMLReader extends HTMLEditorKit.ParserCallback
- {
+ {
+ /**
+ * The maximum token threshold. We don't grow it larger than this.
+ */
+ private static final int MAX_THRESHOLD = 10000;
+
+ /**
+ * The threshold growth factor.
+ */
+ private static final int GROW_THRESHOLD = 5;
+
/**
* Holds the current character attribute set *
*/
@@ -604,6 +616,11 @@ public class HTMLDocument extends DefaultStyledDocument
*/
Document textAreaDocument;
+ /**
+ * The token threshold. This gets increased while loading.
+ */
+ private int threshold;
+
public class TagAction
{
/**
@@ -1156,6 +1173,7 @@ public class HTMLDocument extends DefaultStyledDocument
this.offset = offset;
this.popDepth = popDepth;
this.pushDepth = pushDepth;
+ threshold = getTokenThreshold();
initTags();
}
@@ -1610,8 +1628,10 @@ public class HTMLDocument extends DefaultStyledDocument
// Add the element to the buffer
parseBuffer.addElement(element);
- if (parseBuffer.size() > HTMLDocument.this.getTokenThreshold())
+ if (parseBuffer.size() > threshold)
{
+ if (threshold <= MAX_THRESHOLD)
+ threshold *= GROW_THRESHOLD;
try
{
flushImpl();
diff --git a/javax/swing/text/html/TableView.java b/javax/swing/text/html/TableView.java
index 0bdbccd44..376d640e7 100644
--- a/javax/swing/text/html/TableView.java
+++ b/javax/swing/text/html/TableView.java
@@ -78,6 +78,12 @@ class TableView
super(el, X_AXIS);
}
+ public void replace(int offset, int len, View[] views)
+ {
+ super.replace(offset, len, views);
+ gridValid = false;
+ }
+
/**
* Overridden to make rows not resizable along the Y axis.
*/
@@ -251,7 +257,7 @@ class TableView
/**
* Indicates if the grid setup is ok.
*/
- private boolean gridValid;
+ boolean gridValid;
/**
* Additional space that is added _between_ table cells.
@@ -393,6 +399,16 @@ class TableView
int[] spans)
{
updateGrid();
+
+ // Mark all rows as invalid.
+ int n = getViewCount();
+ for (int i = 0; i < n; i++)
+ {
+ View row = getView(i);
+ if (row instanceof RowView)
+ ((RowView) row).layoutChanged(axis);
+ }
+
layoutColumns(targetSpan);
super.layoutMinorAxis(targetSpan, axis, offsets, spans);
}
@@ -772,4 +788,10 @@ class TableView
{
super.changedUpdate(e, a, this);
}
+
+ public void replace(int offset, int len, View[] views)
+ {
+ super.replace(offset, len, views);
+ gridValid = false;
+ }
}