summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/javax/swing/text
diff options
context:
space:
mode:
authormark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2005-11-18 00:59:33 +0000
committermark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2005-11-18 00:59:33 +0000
commit15d27402f51cf831d82aa31271f5c01855b4f2cf (patch)
tree4c44aaa3ed1ee1b4f15732664c05cfc9214e1fa9 /libjava/classpath/javax/swing/text
parent820206ad46c6fc0131d5771ec1051267022e875d (diff)
downloadppe42-gcc-15d27402f51cf831d82aa31271f5c01855b4f2cf.tar.gz
ppe42-gcc-15d27402f51cf831d82aa31271f5c01855b4f2cf.zip
Imported GNU Classpath gcj-import-20051117.
* gnu/java/net/protocol/file/Connection.java: Removed, fully merged. * sources.am: Regenerated. * Makefile.in: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107153 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/javax/swing/text')
-rw-r--r--libjava/classpath/javax/swing/text/AbstractDocument.java28
-rw-r--r--libjava/classpath/javax/swing/text/BoxView.java33
-rw-r--r--libjava/classpath/javax/swing/text/ComponentView.java148
-rw-r--r--libjava/classpath/javax/swing/text/CompositeView.java68
-rw-r--r--libjava/classpath/javax/swing/text/DefaultCaret.java36
-rw-r--r--libjava/classpath/javax/swing/text/FlowView.java3
-rw-r--r--libjava/classpath/javax/swing/text/GlyphView.java3
-rw-r--r--libjava/classpath/javax/swing/text/IconView.java47
-rw-r--r--libjava/classpath/javax/swing/text/ParagraphView.java113
-rw-r--r--libjava/classpath/javax/swing/text/PlainDocument.java94
-rw-r--r--libjava/classpath/javax/swing/text/WrappedPlainView.java2
11 files changed, 443 insertions, 132 deletions
diff --git a/libjava/classpath/javax/swing/text/AbstractDocument.java b/libjava/classpath/javax/swing/text/AbstractDocument.java
index baf8608b888..a324425562e 100644
--- a/libjava/classpath/javax/swing/text/AbstractDocument.java
+++ b/libjava/classpath/javax/swing/text/AbstractDocument.java
@@ -672,20 +672,8 @@ public abstract class AbstractDocument implements Document, Serializable
new DefaultDocumentEvent(offset, length,
DocumentEvent.EventType.REMOVE);
- // Here we set up the parameters for an ElementChange, if one
- // needs to be added to the DocumentEvent later
- Element root = getDefaultRootElement();
- int start = root.getElementIndex(offset);
- int end = root.getElementIndex(offset + length);
-
- Element[] removed = new Element[end - start + 1];
- for (int i = start; i <= end; i++)
- removed[i - start] = root.getElement(i);
-
removeUpdate(event);
- Element[] added = new Element[1];
- added[0] = root.getElement(start);
boolean shouldFire = content.getString(offset, length).length() != 0;
writeLock();
@@ -694,17 +682,6 @@ public abstract class AbstractDocument implements Document, Serializable
postRemoveUpdate(event);
- GapContent.UndoRemove changes = null;
- if (content instanceof GapContent)
- changes = (GapContent.UndoRemove) temp;
-
- if (changes != null && !(start == end))
- {
- // We need to add an ElementChange to our DocumentEvent
- ElementEdit edit = new ElementEdit (root, start, removed, added);
- event.addEdit(edit);
- }
-
if (shouldFire)
fireRemoveUpdate(event);
}
@@ -2143,7 +2120,10 @@ public abstract class AbstractDocument implements Document, Serializable
*/
public String getName()
{
- return ContentElementName;
+ String name = super.getName();
+ if (name == null)
+ name = ContentElementName;
+ return name;
}
/**
diff --git a/libjava/classpath/javax/swing/text/BoxView.java b/libjava/classpath/javax/swing/text/BoxView.java
index f201045dbdb..5c9587dfe5d 100644
--- a/libjava/classpath/javax/swing/text/BoxView.java
+++ b/libjava/classpath/javax/swing/text/BoxView.java
@@ -476,7 +476,6 @@ public class BoxView
protected View getViewAtPoint(int x, int y, Rectangle r)
{
View result = null;
-
int count = getViewCount();
Rectangle copy = new Rectangle(r);
@@ -490,7 +489,9 @@ public class BoxView
break;
}
}
-
+
+ if (result == null && count > 0)
+ return getView(count - 1);
return result;
}
@@ -498,10 +499,12 @@ public class BoxView
* Computes the allocation for a child <code>View</code>. The parameter
* <code>a</code> stores the allocation of this <code>CompositeView</code>
* and is then adjusted to hold the allocation of the child view.
- *
- * @param index the index of the child <code>View</code>
- * @param a the allocation of this <code>CompositeView</code> before the
- * call, the allocation of the child on exit
+ *
+ * @param index
+ * the index of the child <code>View</code>
+ * @param a
+ * the allocation of this <code>CompositeView</code> before the
+ * call, the allocation of the child on exit
*/
protected void childAllocation(int index, Rectangle a)
{
@@ -737,4 +740,22 @@ public class BoxView
yLayoutValid = false;
super.preferenceChanged(child, width, height);
}
+
+ /**
+ * Maps the document model position <code>pos</code> to a Shape
+ * in the view coordinate space. This method overrides CompositeView's
+ * method to make sure the children are allocated properly before
+ * calling the super's behaviour.
+ */
+ public Shape modelToView(int pos, Shape a, Position.Bias bias)
+ throws BadLocationException
+ {
+ // Make sure everything is allocated properly and then call super
+ if (!isAllocationValid())
+ {
+ Rectangle bounds = a.getBounds();
+ setSize(bounds.width, bounds.height);
+ }
+ return super.modelToView(pos, a, bias);
+ }
}
diff --git a/libjava/classpath/javax/swing/text/ComponentView.java b/libjava/classpath/javax/swing/text/ComponentView.java
index 16112c8f4de..830dda3ecdc 100644
--- a/libjava/classpath/javax/swing/text/ComponentView.java
+++ b/libjava/classpath/javax/swing/text/ComponentView.java
@@ -38,10 +38,13 @@ exception statement from your version. */
package javax.swing.text;
import java.awt.Component;
+import java.awt.Container;
import java.awt.Graphics;
+import java.awt.Rectangle;
import java.awt.Shape;
import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
/**
* A {@link View} implementation that is able to render arbitrary
@@ -52,12 +55,17 @@ import javax.swing.SwingConstants;
* this <code>ComponentView</code>, so this view must not be shared between
* multiple <code>JTextComponent</code>s.
*
+ * @author Roman Kennke (kennke@aicas.com)
* @author original author unknown
- * @author Roman Kennke (roman@kennke.org)
*/
-// FIXME: This class is a complete stub and needs to be implemented properly.
public class ComponentView extends View
{
+
+ /**
+ * The component that is displayed by this view.
+ */
+ private Component comp;
+
/**
* Creates a new instance of <code>ComponentView</code> for the specified
* <code>Element</code>.
@@ -77,7 +85,7 @@ public class ComponentView extends View
*
* @return the component that is rendered
*/
- protected Component createComponent()
+ protected Component createComponent()
{
return StyleConstants.getComponent(getElement().getAttributes());
}
@@ -91,7 +99,14 @@ public class ComponentView extends View
*/
public float getAlignment(int axis)
{
- return 0;
+ float align;
+ if (axis == X_AXIS)
+ align = getComponent().getAlignmentX();
+ else if (axis == Y_AXIS)
+ align = getComponent().getAlignmentY();
+ else
+ throw new IllegalArgumentException();
+ return align;
}
/**
@@ -103,7 +118,9 @@ public class ComponentView extends View
*/
public final Component getComponent()
{
- return null;
+ if (comp == null)
+ comp = createComponent();
+ return comp;
}
/**
@@ -118,49 +135,115 @@ public class ComponentView extends View
*/
public float getMaximumSpan(int axis)
{
- return 0;
+ float span;
+ if (axis == X_AXIS)
+ span = getComponent().getMaximumSize().width;
+ else if (axis == Y_AXIS)
+ span = getComponent().getMaximumSize().height;
+ else
+ throw new IllegalArgumentException();
+ return span;
}
public float getMinimumSpan(int axis)
{
- // TODO: Implement this properly.
- return 0;
+ float span;
+ if (axis == X_AXIS)
+ span = getComponent().getMinimumSize().width;
+ else if (axis == Y_AXIS)
+ span = getComponent().getMinimumSize().height;
+ else
+ throw new IllegalArgumentException();
+ return span;
}
public float getPreferredSpan(int axis)
{
- // TODO: Implement this properly.
- return 0;
+ float span;
+ if (axis == X_AXIS)
+ span = getComponent().getPreferredSize().width;
+ else if (axis == Y_AXIS)
+ span = getComponent().getPreferredSize().height;
+ else
+ throw new IllegalArgumentException();
+ return span;
}
public Shape modelToView(int pos, Shape a, Position.Bias b)
throws BadLocationException
{
- // TODO: Implement this properly.
- return null;
+ Element el = getElement();
+ if (pos < el.getStartOffset() || pos >= el.getEndOffset())
+ throw new BadLocationException("Illegal offset for this view", pos);
+ Rectangle r = a.getBounds();
+ Component c = getComponent();
+ return new Rectangle(r.x, r.y, c.getWidth(), c.getHeight());
}
-
+
+ /**
+ * The real painting behavour is performed by normal component painting,
+ * triggered by the text component that hosts this view. This method does
+ * not paint by itself. However, it sets the size of the component according
+ * to the allocation that is passed here.
+ *
+ * @param g the graphics context
+ * @param a the allocation of the child
+ */
public void paint(Graphics g, Shape a)
{
- // TODO: Implement this properly.
+ Rectangle r = a.getBounds();
+ getComponent().setBounds(r.x, r.y, r.width, r.height);
}
-
- public void setParent(View p)
+
+ /**
+ * This sets up the component when the view is added to its parent, or
+ * cleans up the view when it is removed from its parent.
+ *
+ * When this view is added to a parent view, the component of this view
+ * is added to the container that hosts this view. When <code>p</code> is
+ * <code>null</code>, then the view is removed from it's parent and we have
+ * to also remove the component from it's parent container.
+ *
+ * @param p the parent view or <code>null</code> if this view is removed
+ * from it's parent
+ */
+ public void setParent(final View p)
{
- // TODO: Implement this properly.
+ if (SwingUtilities.isEventDispatchThread())
+ setParentImpl(p);
+ else
+ SwingUtilities.invokeLater
+ (new Runnable()
+ {
+ public void run()
+ {
+ setParentImpl(p);
+ }
+ });
}
-
- public void setSize(float width, float height)
+
+ /**
+ * The implementation of {@link #setParent}. This is package private to
+ * avoid a synthetic accessor method.
+ *
+ * @param p the parent view to set
+ */
+ void setParentImpl(View p)
{
- // TODO: Implement this properly.
+ if (p != null)
+ {
+ Component c = getComponent();
+ p.getContainer().add(c);
+ }
+ else
+ {
+ Component c = getComponent();
+ Container parent = c.getParent();
+ parent.remove(c);
+ comp = null;
+ }
}
- public int viewToModel(float x, float y, Shape a, Position.Bias[] bias)
- {
- // TODO: Implement this properly.
- return 0;
- }
-
/**
* Maps coordinates from the <code>View</code>'s space into a position
* in the document model.
@@ -173,10 +256,13 @@ public class ComponentView extends View
* @return the position in the document that corresponds to the screen
* coordinates <code>x, y</code>
*/
- public int viewToModel(float x, float y, Shape a, Position.Bias b)
+ public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
{
- // FIXME: Implement this properly.
- return 0;
+ // The element should only have one character position and it is clear
+ // that this position is the position that best matches the given screen
+ // coordinates, simply because this view has only this one position.
+ Element el = getElement();
+ return el.getStartOffset();
}
/**
@@ -205,7 +291,7 @@ public class ComponentView extends View
Position.Bias[] biasRet)
throws BadLocationException
{
- // TODO: Implement this properly.
- throw new AssertionError("Not implemented yet.");
+ // FIXME: Implement this method.
+ throw new AssertionError("Not yet implemented");
}
}
diff --git a/libjava/classpath/javax/swing/text/CompositeView.java b/libjava/classpath/javax/swing/text/CompositeView.java
index bc626a40696..e6c2e4cc2d8 100644
--- a/libjava/classpath/javax/swing/text/CompositeView.java
+++ b/libjava/classpath/javax/swing/text/CompositeView.java
@@ -264,50 +264,56 @@ public abstract class CompositeView
* Maps coordinates from the <code>View</code>'s space into a position
* in the document model.
*
- * @param x the x coordinate in the view space
- * @param y the y coordinate in the view space
+ * @param x the x coordinate in the view space, x >= 0
+ * @param y the y coordinate in the view space, y >= 0
* @param a the allocation of this <code>View</code>
* @param b the bias to use
*
* @return the position in the document that corresponds to the screen
- * coordinates <code>x, y</code>
+ * coordinates <code>x, y</code> >= 0
*/
public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
{
- Rectangle r = getInsideAllocation(a);
- View view = getViewAtPoint((int) x, (int) y, r);
- return view.viewToModel(x, y, a, b);
+ if (x >= 0 && y >= 0)
+ {
+ Rectangle r = getInsideAllocation(a);
+ View view = getViewAtPoint((int) x, (int) y, r);
+ return view.viewToModel(x, y, a, b);
+ }
+ return 0;
}
/**
* Returns the next model location that is visible in eiter north / south
- * direction or east / west direction. This is used to determine the
- * placement of the caret when navigating around the document with
- * the arrow keys.
- *
- * This is a convenience method for
- * {@link #getNextNorthSouthVisualPositionFrom} and
- * {@link #getNextEastWestVisualPositionFrom}.
- *
- * @param pos the model position to start search from
- * @param b the bias for <code>pos</code>
- * @param a the allocated region for this view
- * @param direction the direction from the current position, can be one of
- * the following:
- * <ul>
- * <li>{@link SwingConstants#WEST}</li>
- * <li>{@link SwingConstants#EAST}</li>
- * <li>{@link SwingConstants#NORTH}</li>
- * <li>{@link SwingConstants#SOUTH}</li>
- * </ul>
- * @param biasRet the bias of the return value gets stored here
- *
+ * direction or east / west direction. This is used to determine the placement
+ * of the caret when navigating around the document with the arrow keys. This
+ * is a convenience method for {@link #getNextNorthSouthVisualPositionFrom}
+ * and {@link #getNextEastWestVisualPositionFrom}.
+ *
+ * @param pos
+ * the model position to start search from
+ * @param b
+ * the bias for <code>pos</code>
+ * @param a
+ * the allocated region for this view
+ * @param direction
+ * the direction from the current position, can be one of the
+ * following:
+ * <ul>
+ * <li>{@link SwingConstants#WEST}</li>
+ * <li>{@link SwingConstants#EAST}</li>
+ * <li>{@link SwingConstants#NORTH}</li>
+ * <li>{@link SwingConstants#SOUTH}</li>
+ * </ul>
+ * @param biasRet
+ * the bias of the return value gets stored here
* @return the position inside the model that represents the next visual
* location
- *
- * @throws BadLocationException if <code>pos</code> is not a valid location
- * inside the document model
- * @throws IllegalArgumentException if <code>direction</code> is invalid
+ * @throws BadLocationException
+ * if <code>pos</code> is not a valid location inside the document
+ * model
+ * @throws IllegalArgumentException
+ * if <code>direction</code> is invalid
*/
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
int direction, Position.Bias[] biasRet)
diff --git a/libjava/classpath/javax/swing/text/DefaultCaret.java b/libjava/classpath/javax/swing/text/DefaultCaret.java
index 66e2f4723cf..3ebeceb947d 100644
--- a/libjava/classpath/javax/swing/text/DefaultCaret.java
+++ b/libjava/classpath/javax/swing/text/DefaultCaret.java
@@ -781,28 +781,34 @@ public class DefaultCaret extends Rectangle
*/
public void moveDot(int dot)
{
- this.dot = dot;
- handleHighlight();
- adjustVisibility(this);
- appear();
+ if (dot >= 0)
+ {
+ this.dot = dot;
+ handleHighlight();
+ adjustVisibility(this);
+ appear();
+ }
}
/**
* Sets the current position of this <code>Caret</code> within the
- * <code>Document</code>. This also sets the <code>mark</code> to the
- * new location.
- *
- * @param dot the new position to be set
- *
+ * <code>Document</code>. This also sets the <code>mark</code> to the new
+ * location.
+ *
+ * @param dot
+ * the new position to be set
* @see #moveDot(int)
*/
public void setDot(int dot)
{
- this.dot = dot;
- this.mark = dot;
- handleHighlight();
- adjustVisibility(this);
- appear();
+ if (dot >= 0)
+ {
+ this.mark = dot;
+ this.dot = dot;
+ handleHighlight();
+ adjustVisibility(this);
+ appear();
+ }
}
/**
@@ -878,7 +884,7 @@ public class DefaultCaret extends Rectangle
}
Rectangle area = null;
try
- {
+ {
area = getComponent().modelToView(getDot());
}
catch (BadLocationException ex)
diff --git a/libjava/classpath/javax/swing/text/FlowView.java b/libjava/classpath/javax/swing/text/FlowView.java
index fd6785b6f18..765f515a20d 100644
--- a/libjava/classpath/javax/swing/text/FlowView.java
+++ b/libjava/classpath/javax/swing/text/FlowView.java
@@ -601,6 +601,9 @@ public abstract class FlowView extends BoxView
*/
public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory vf)
{
+ // First we must send the insertUpdate to the logical view so it can
+ // be updated accordingly.
+ layoutPool.insertUpdate(changes, a, vf);
strategy.insertUpdate(this, changes, getInsideAllocation(a));
}
diff --git a/libjava/classpath/javax/swing/text/GlyphView.java b/libjava/classpath/javax/swing/text/GlyphView.java
index eb1fadd4f2d..d3dd75e624b 100644
--- a/libjava/classpath/javax/swing/text/GlyphView.java
+++ b/libjava/classpath/javax/swing/text/GlyphView.java
@@ -457,9 +457,6 @@ public class GlyphView extends View implements TabableView, Cloneable
Bias[] biasRet)
{
Rectangle b = a.getBounds();
- assert b.contains(x, y) : "The coordinates are expected to be within the "
- + "view's bounds: x=" + x + ", y=" + y
- + "a=" + a;
int pos = getBoundedPosition(v, v.getStartOffset(), b.x, x - b.x);
return pos;
}
diff --git a/libjava/classpath/javax/swing/text/IconView.java b/libjava/classpath/javax/swing/text/IconView.java
index 6dd0f7ad34a..86c27dd5fda 100644
--- a/libjava/classpath/javax/swing/text/IconView.java
+++ b/libjava/classpath/javax/swing/text/IconView.java
@@ -39,11 +39,25 @@ exception statement from your version. */
package javax.swing.text;
import java.awt.Graphics;
+import java.awt.Rectangle;
import java.awt.Shape;
+import javax.swing.Icon;
+import javax.swing.JTextPane;
import javax.swing.SwingConstants;
-// TODO: Implement this class.
+/**
+ * A View that can render an icon. This view is created by the
+ * {@link StyledEditorKit}'s view factory for all elements that have name
+ * {@link StyleConstants#IconElementName}. This is usually created by
+ * inserting an icon into <code>JTextPane</code> using
+ * {@link JTextPane#insertIcon(Icon)}
+ *
+ * The icon is determined using the attribute
+ * {@link StyleConstants#IconAttribute}, which's value must be an {@link Icon}.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
public class IconView
extends View
{
@@ -67,7 +81,9 @@ public class IconView
*/
public void paint(Graphics g, Shape a)
{
- // TODO: Implement me.
+ Icon icon = StyleConstants.getIcon(getElement().getAttributes());
+ Rectangle b = a.getBounds();
+ icon.paintIcon(getContainer(), g, b.x, b.y);
}
/**
@@ -80,8 +96,15 @@ public class IconView
*/
public float getPreferredSpan(int axis)
{
- // TODO: Implement me.
- return 0F;
+ Icon icon = StyleConstants.getIcon(getElement().getAttributes());
+ float span;
+ if (axis == X_AXIS)
+ span = icon.getIconWidth();
+ else if (axis == Y_AXIS)
+ span = icon.getIconHeight();
+ else
+ throw new IllegalArgumentException();
+ return span;
}
/**
@@ -106,8 +129,12 @@ public class IconView
public Shape modelToView(int pos, Shape a, Position.Bias b)
throws BadLocationException
{
- // Implement me.
- return null;
+ Element el = getElement();
+ if (pos < el.getStartOffset() || pos >= el.getEndOffset())
+ throw new BadLocationException("Illegal offset for this view", pos);
+ Rectangle r = a.getBounds();
+ Icon icon = StyleConstants.getIcon(el.getAttributes());
+ return new Rectangle(r.x, r.y, icon.getIconWidth(), icon.getIconHeight());
}
/**
@@ -124,8 +151,11 @@ public class IconView
*/
public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
{
- // FIXME: not implemented
- return 0;
+ // The element should only have one character position and it is clear
+ // that this position is the position that best matches the given screen
+ // coordinates, simply because this view has only this one position.
+ Element el = getElement();
+ return el.getStartOffset();
}
/**
@@ -157,4 +187,5 @@ public class IconView
// TODO: Implement this properly.
throw new AssertionError("Not implemented yet.");
}
+
}
diff --git a/libjava/classpath/javax/swing/text/ParagraphView.java b/libjava/classpath/javax/swing/text/ParagraphView.java
index 6fb121f949e..c4864503187 100644
--- a/libjava/classpath/javax/swing/text/ParagraphView.java
+++ b/libjava/classpath/javax/swing/text/ParagraphView.java
@@ -38,6 +38,10 @@ exception statement from your version. */
package javax.swing.text;
+import java.awt.Shape;
+
+import javax.swing.event.DocumentEvent;
+
/**
* A {@link FlowView} that flows it's children horizontally and boxes the rows
* vertically.
@@ -67,6 +71,26 @@ public class ParagraphView extends FlowView implements TabExpander
}
/**
+ * The indentation of the first line of the paragraph.
+ */
+ protected int firstLineIndent;
+
+ /**
+ * The justification of the paragraph.
+ */
+ private int justification;
+
+ /**
+ * The line spacing of this paragraph.
+ */
+ private float lineSpacing;
+
+ /**
+ * The TabSet of this paragraph.
+ */
+ private TabSet tabSet;
+
+ /**
* Creates a new <code>ParagraphView</code> for the given
* <code>Element</code>.
*
@@ -116,4 +140,93 @@ public class ParagraphView extends FlowView implements TabExpander
else
return 0.0F;
}
+
+ /**
+ * Receives notification when some attributes of the displayed element
+ * changes. This triggers a refresh of the cached attributes of this
+ * paragraph.
+ *
+ * @param ev the document event
+ * @param a the allocation of this view
+ * @param fv the view factory to use for creating new child views
+ */
+ public void changedUpdate(DocumentEvent ev, Shape a, ViewFactory fv)
+ {
+ setPropertiesFromAttributes();
+ }
+
+ /**
+ * Fetches the cached properties from the element's attributes.
+ */
+ protected void setPropertiesFromAttributes()
+ {
+ Element el = getElement();
+ AttributeSet atts = el.getAttributes();
+ setFirstLineIndent(StyleConstants.getFirstLineIndent(atts));
+ setLineSpacing(StyleConstants.getLineSpacing(atts));
+ setJustification(StyleConstants.getAlignment(atts));
+ tabSet = StyleConstants.getTabSet(atts);
+ }
+
+ /**
+ * Sets the indentation of the first line of the paragraph.
+ *
+ * @param i the indentation to set
+ */
+ protected void setFirstLineIndent(float i)
+ {
+ firstLineIndent = (int) i;
+ }
+
+ /**
+ * Sets the justification of the paragraph.
+ *
+ * @param j the justification to set
+ */
+ protected void setJustification(int j)
+ {
+ justification = j;
+ }
+
+ /**
+ * Sets the line spacing for this paragraph.
+ *
+ * @param s the line spacing to set
+ */
+ protected void setLineSpacing(float s)
+ {
+ lineSpacing = s;
+ }
+
+ /**
+ * Returns the i-th view from the logical views, before breaking into rows.
+ *
+ * @param i the index of the logical view to return
+ *
+ * @return the i-th view from the logical views, before breaking into rows
+ */
+ protected View getLayoutView(int i)
+ {
+ return layoutPool.getView(i);
+ }
+
+ /**
+ * Returns the number of logical child views.
+ *
+ * @return the number of logical child views
+ */
+ protected int getLayoutViewCount()
+ {
+ return layoutPool.getViewCount();
+ }
+
+ /**
+ * Returns the TabSet used by this ParagraphView.
+ *
+ * @return the TabSet used by this ParagraphView
+ */
+ protected TabSet getTabSet()
+ {
+ return tabSet;
+ }
}
diff --git a/libjava/classpath/javax/swing/text/PlainDocument.java b/libjava/classpath/javax/swing/text/PlainDocument.java
index 9e600c4c908..0c00a06ff25 100644
--- a/libjava/classpath/javax/swing/text/PlainDocument.java
+++ b/libjava/classpath/javax/swing/text/PlainDocument.java
@@ -105,10 +105,65 @@ public class PlainDocument extends AbstractDocument
return root;
}
- protected void insertUpdate(DefaultDocumentEvent event, AttributeSet attributes)
+ protected void insertUpdate(DefaultDocumentEvent event,
+ AttributeSet attributes)
{
- reindex();
+ int offset = event.getOffset();
+ int end = offset + event.getLength();
+ int elementIndex = rootElement.getElementIndex(offset);
+ Element firstElement = rootElement.getElement(elementIndex);
+
+ // added and removed are Element arrays used to add an ElementEdit
+ // to the DocumentEvent if there were entire lines added or removed.
+ Element[] removed = new Element[1];
+ Element[] added;
+ try
+ {
+ String str = content.getString(0, content.length());
+ ArrayList elts = new ArrayList();
+ // Determine how many NEW lines were added by finding the newline
+ // characters within the newly inserted text
+ int j = firstElement.getStartOffset();
+ int i = str.indexOf('\n', offset);
+ while (i != -1 && i <= end)
+ {
+ // For each new line, create a new element
+ elts.add(createLeafElement(rootElement, SimpleAttributeSet.EMPTY,
+ j, i + 1));
+ j = i + 1;
+ if (j >= str.length())
+ break;
+ i = str.indexOf('\n', j);
+ }
+ // If there were new lines added we have to add an ElementEdit to
+ // the DocumentEvent and we have to call rootElement.replace to
+ // insert the new lines
+ if (elts.size() != 0)
+ {
+ // Set up the ElementEdit by filling the added and removed
+ // arrays with the proper Elements
+ added = new Element[elts.size()];
+ for (int k = 0; k < elts.size(); ++k)
+ added[k] = (Element) elts.get(k);
+ removed[0] = firstElement;
+
+ // Now create and add the ElementEdit
+ ElementEdit e = new ElementEdit(rootElement, elementIndex, removed,
+ added);
+ event.addEdit(e);
+
+ // And call replace to actually make the changes
+ ((BranchElement) rootElement).replace(elementIndex, 1, added);
+ }
+ }
+ catch (BadLocationException e)
+ {
+ // This shouldn't happen so we throw an AssertionError
+ AssertionError ae = new AssertionError();
+ ae.initCause(e);
+ throw ae;
+ }
super.insertUpdate(event, attributes);
}
@@ -116,24 +171,37 @@ public class PlainDocument extends AbstractDocument
{
super.removeUpdate(event);
+ // added and removed are Element arrays used to add an ElementEdit
+ // to the DocumentEvent if there were entire lines added or removed
+ // from the Document
+ Element[] added = new Element[1];
+ Element[] removed;
int p0 = event.getOffset();
- int len = event.getLength();
- int p1 = len + p0;
// check if we must collapse some elements
int i1 = rootElement.getElementIndex(p0);
- int i2 = rootElement.getElementIndex(p1);
+ int i2 = rootElement.getElementIndex(p0 + event.getLength());
if (i1 != i2)
{
- Element el1 = rootElement.getElement(i1);
- Element el2 = rootElement.getElement(i2);
- int start = el1.getStartOffset();
- int end = el2.getEndOffset();
- // collapse elements if the removal spans more than 1 line
- Element newEl = createLeafElement(rootElement,
+ // If there were lines removed then we have to add an ElementEdit
+ // to the DocumentEvent so we set it up now by filling the Element
+ // arrays "removed" and "added" appropriately
+ removed = new Element [i2 - i1 + 1];
+ for (int i = i1; i <= i2; i++)
+ removed[i-i1] = rootElement.getElement(i);
+
+ int start = rootElement.getElement(i1).getStartOffset();
+ int end = rootElement.getElement(i2).getEndOffset();
+ added[0] = createLeafElement(rootElement,
SimpleAttributeSet.EMPTY,
start, end);
- rootElement.replace(i1, i2 - i1 + 1, new Element[]{ newEl });
+
+ // Now create and add the ElementEdit
+ ElementEdit e = new ElementEdit(rootElement, i1, removed, added);
+ event.addEdit(e);
+
+ // collapse elements if the removal spans more than 1 line
+ rootElement.replace(i1, i2 - i1 + 1, added);
}
}
@@ -167,7 +235,7 @@ public class PlainDocument extends AbstractDocument
throws BadLocationException
{
String string = str;
- if (Boolean.TRUE.equals(getProperty("filterNewlines")))
+ if (str != null && Boolean.TRUE.equals(getProperty("filterNewlines")))
string = str.replaceAll("\n", " ");
super.insertString(offs, string, atts);
}
diff --git a/libjava/classpath/javax/swing/text/WrappedPlainView.java b/libjava/classpath/javax/swing/text/WrappedPlainView.java
index b90519046ae..b03399d0974 100644
--- a/libjava/classpath/javax/swing/text/WrappedPlainView.java
+++ b/libjava/classpath/javax/swing/text/WrappedPlainView.java
@@ -50,7 +50,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.text.Position.Bias;
/**
- * @author abalkiss
+ * @author Anthony Balkissoon abalkiss at redhat dot com
*
*/
public class WrappedPlainView extends BoxView implements TabExpander
OpenPOWER on IntegriCloud