Here's some cleanup, that should make BeanShell & Co work again after
the HTML fixes.
2006-08-25 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/text/LabelView.java
(setPropertiesFromAttributes): Only set background when
the corresponding attribute is actually defined, otherwise
set to null, as the StyleConstants would return black.
* javax/swing/text/DefaultStyledDocument.java
(ElementBuffer.documentEvent): Removed obsolete field.
(ElementBuffer.change): Do prepareEdits() and finishEdits()
to correctly update the element structure.
(ElementBuffer.insertContentTag): Removed unused statement.
(ElementBuffer.recreateAfterFracture): Removed
unused obsolete method.
(setCharacterAttributes): Removed unused statement.
/Roman
Index: javax/swing/text/DefaultStyledDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v
retrieving revision 1.67
diff -u -1 -2 -r1.67 DefaultStyledDocument.java
--- javax/swing/text/DefaultStyledDocument.java 9 Aug 2006 15:06:39 -0000 1.67
+++ javax/swing/text/DefaultStyledDocument.java 25 Aug 2006 13:14:44 -0000
@@ -488,29 +488,24 @@
private int offset;
/** Holds the end offset for structural changes. */
private int endOffset;
/** Holds the length of structural changes. */
private int length;
/** Holds the position of the change. */
private int pos;
/**
- * The ElementChange that describes the latest changes.
- */
- private DefaultDocumentEvent documentEvent;
-
- /**
* The parent of the fracture.
*/
private Element fracturedParent;
/**
* The fractured child.
*/
private Element fracturedChild;
/**
* Indicates if a fracture has been created.
*/
@@ -826,31 +821,27 @@
* <code>DefaultDocumentEvent</code> to reflect the structural changes.
* The bulk work is delegated to [EMAIL PROTECTED] #changeUpdate()}.
*
* @param offset
* the start index of the interval to be changed
* @param length
* the length of the interval to be changed
* @param ev
* the <code>DefaultDocumentEvent</code> describing the change
*/
public void change(int offset, int length, DefaultDocumentEvent ev)
{
- if (length == 0)
- return;
- this.offset = offset;
- this.pos = offset;
- this.length = length;
- documentEvent = ev;
+ prepareEdit(offset, length);
changeUpdate();
+ finishEdit(ev);
}
/**
* Creates and returns a deep clone of the specified <code>clonee</code>
* with the specified parent as new parent.
*
* This method can only clone direct instances of [EMAIL PROTECTED] BranchElement}
* or [EMAIL PROTECTED] LeafElement}.
*
* @param parent the new parent
* @param clonee the element to be cloned
*
@@ -1249,26 +1240,24 @@
}
/**
* Inserts a content element into the document structure.
*
* @param tag -
* the element spec
*/
private void insertContentTag(ElementSpec tag, Edit edit)
{
int len = tag.getLength();
int dir = tag.getDirection();
- AttributeSet tagAtts = tag.getAttributes();
-
if (dir == ElementSpec.JoinNextDirection)
{
if (! edit.isFracture)
{
Element first = null;
if (insertPath != null)
{
for (int p = insertPath.length - 1; p >= 0; p--)
{
if (insertPath[p] == edit)
{
if (p != insertPath.length - 1)
@@ -1594,74 +1583,24 @@
child.getStartOffset(), pos);
ec.added.add(e);
e = createLeafElement(ec.e, child.getAttributes(),
pos, child.getEndOffset());
ec.added.add(e);
}
}
return splitEnd;
}
- /**
- * Recreates all the elements from the parent to the element on the top of
- * the stack, starting from startFrom with the starting offset of
- * startOffset.
- *
- * @param recreate -
- * the elements to recreate
- * @param parent -
- * the element to add the new elements to
- * @param startFrom -
- * where to start recreating from
- * @param startOffset -
- * the offset of the first element
- * @return the array of added elements
- */
- private Element[] recreateAfterFracture(Element[] recreate,
- BranchElement parent, int startFrom,
- int startOffset)
- {
- Element[] added = new Element[recreate.length - startFrom];
- int j = 0;
- for (int i = startFrom; i < recreate.length; i++)
- {
- Element curr = recreate[i];
- int len = curr.getEndOffset() - curr.getStartOffset();
- if (curr instanceof LeafElement)
- added[j] = createLeafElement(parent, curr.getAttributes(),
- startOffset, startOffset + len);
- else
- {
- BranchElement br =
- (BranchElement) createBranchElement(parent,
- curr.getAttributes());
- int bSize = curr.getElementCount();
- for (int k = 0; k < bSize; k++)
- {
- Element bCurr = curr.getElement(k);
- Element[] add = recreateAfterFracture(new Element[] { bCurr }, br, 0,
- startOffset);
- br.replace(0, 0, add);
-
- }
- added[j] = br;
- }
- startOffset += len;
- j++;
- }
-
- return added;
- }
}
/**
* An element type for sections. This is a simple BranchElement with a unique
* name.
*/
protected class SectionElement extends BranchElement
{
/**
* Creates a new SectionElement.
*/
@@ -1976,25 +1915,24 @@
// writeUnlock() should always be in try/finally block to make
// sure that locking happens in a balanced manner.
writeLock();
DefaultDocumentEvent ev = new DefaultDocumentEvent(offset,
length,
DocumentEvent.EventType.CHANGE);
// Modify the element structure so that the interval begins at an
// element
// start and ends at an element end.
buffer.change(offset, length, ev);
- Element root = getDefaultRootElement();
// Visit all paragraph elements within the specified interval
int end = offset + length;
Element curr;
for (int pos = offset; pos < end;)
{
// Get the CharacterElement at offset pos.
curr = getCharacterElement(pos);
if (pos == curr.getEndOffset())
break;
MutableAttributeSet a = (MutableAttributeSet) curr.getAttributes();
ev.addEdit(new AttributeUndoableEdit(curr, attributes, replace));
Index: javax/swing/text/LabelView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/LabelView.java,v
retrieving revision 1.6
diff -u -1 -2 -r1.6 LabelView.java
--- javax/swing/text/LabelView.java 25 Aug 2006 11:20:46 -0000 1.6
+++ javax/swing/text/LabelView.java 25 Aug 2006 13:14:45 -0000
@@ -106,40 +106,39 @@
super(element);
valid = false;
}
/**
* Loads the properties of this label view from the element's text
* attributes. This method is called from the constructor and the
* [EMAIL PROTECTED] #changedUpdate} method
*/
protected void setPropertiesFromAttributes()
{
AttributeSet atts = getAttributes();
- // We cannot use StyleConstants.getBackground() here, because that returns
- // BLACK as default (when background == null). What we need is the
- // background setting of the text component instead, which is what we get
- // when background == null anyway.
setStrikeThrough(StyleConstants.isStrikeThrough(atts));
setSubscript(StyleConstants.isSubscript(atts));
setSuperscript(StyleConstants.isSuperscript(atts));
setUnderline(StyleConstants.isUnderline(atts));
// Determine the font and colors.
Document d = getDocument();
if (d instanceof StyledDocument)
{
StyledDocument doc = (StyledDocument) d;
font = doc.getFont(atts);
- background = doc.getBackground(atts);
+ if (atts.isDefined(StyleConstants.Background))
+ background = doc.getBackground(atts);
+ else
+ background = null;
foreground = doc.getForeground(atts);
}
valid = true;
}
/**
* Receives notification when text attributes change in the chunk of
* text that this view is responsible for. This simply calls
* [EMAIL PROTECTED] #setPropertiesFromAttributes()}.
*
* @param e the document event
* @param a the allocation of this view