summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAudrius Meskauskas <audriusa@Bioinformatics.org>2006-07-08 19:46:44 +0000
committerAudrius Meskauskas <audriusa@Bioinformatics.org>2006-07-08 19:46:44 +0000
commit9ad3adece7759dfca5f82faa14ff0ee5b301ea4c (patch)
treed2d3a2449501c81209493a74273afd889b3d2755
parentc079413426b9f3aee12d1d965c63ae786f70b7f5 (diff)
downloadclasspath-9ad3adece7759dfca5f82faa14ff0ee5b301ea4c.tar.gz
2006-07-08 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* javax/swing/text/FlowView.java (FlowStrategy.layoutRow): Handle the forced break in the same way as exceeding the available row space. * javax/swing/text/html/HRuleView.java: Rewritten. * javax/swing/text/html/HTMLDocument.java (HTMLReader.addSpecialElement):Reserve two characters for the special elements. * examples/gnu/classpath/examples/swing/HtmlDemo.java (text): Extended the HTML example to parse.
-rw-r--r--ChangeLog12
-rw-r--r--examples/gnu/classpath/examples/swing/HtmlDemo.java8
-rw-r--r--javax/swing/text/FlowView.java61
-rw-r--r--javax/swing/text/html/HRuleView.java68
-rw-r--r--javax/swing/text/html/HTMLDocument.java16
5 files changed, 110 insertions, 55 deletions
diff --git a/ChangeLog b/ChangeLog
index 86f732675..9e5636115 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2006-07-08 Audrius Meskauskas <AudriusA@Bioinformatics.org>
+
+ * javax/swing/text/FlowView.java (FlowStrategy.layoutRow):
+ Handle the forced break in the same way as exceeding the
+ available row space.
+ * javax/swing/text/html/HRuleView.java: Rewritten.
+ * javax/swing/text/html/HTMLDocument.java
+ (HTMLReader.addSpecialElement):Reserve two characters for
+ the special elements.
+ * examples/gnu/classpath/examples/swing/HtmlDemo.java
+ (text): Extended the HTML example to parse.
+
2006-07-07 David Gilbert <david.gilbert@object-refinery.com>
* javax/swing/AbstractButton.java
diff --git a/examples/gnu/classpath/examples/swing/HtmlDemo.java b/examples/gnu/classpath/examples/swing/HtmlDemo.java
index 6ac626717..988b0bd0e 100644
--- a/examples/gnu/classpath/examples/swing/HtmlDemo.java
+++ b/examples/gnu/classpath/examples/swing/HtmlDemo.java
@@ -63,8 +63,12 @@ public class HtmlDemo extends JPanel
JTextPane html = new JTextPane();
- //JTextArea text = new JTextArea("<html><body><p><img src='' alt='alt txt'></p></body></html>");
- JTextArea text = new JTextArea("<html><body><p>nor<font color=red>ma</font>l<sup>sup</sup>normal<sub>sub</sub>normal</p></body></html>");
+ JTextArea text = new JTextArea("<html><body><p>" +
+ "123456789HR!<hr>987654321"+
+ "123456789BR!<br>987654321"+
+ "<font color=red>ma</font>"+
+ "<sup>sup</sup>normal<sub>sub</sub>normal</p><p>Table:"+
+ "<table><tr>a<td>b<td>c<tr>x<td>y<td>z</table></body></html>");
JPanel buttons;
diff --git a/javax/swing/text/FlowView.java b/javax/swing/text/FlowView.java
index e3052d57a..89fcc6fcd 100644
--- a/javax/swing/text/FlowView.java
+++ b/javax/swing/text/FlowView.java
@@ -159,20 +159,18 @@ public abstract class FlowView extends BoxView
}
/**
- * Lays out one row of the flow view. This is called by {@link #layout}
- * to fill one row with child views until the available span is exhausted.
- *
- * The default implementation fills the row by calling
- * {@link #createView(FlowView, int, int, int)} until the available space
- * is exhausted, a forced break is encountered or there are no more views
- * in the logical view. If the available space is exhausted,
- * {@link #adjustRow(FlowView, int, int, int)} is called to fit the row
- * into the available span.
- *
+ * Lays out one row of the flow view. This is called by {@link #layout} to
+ * fill one row with child views until the available span is exhausted. The
+ * default implementation fills the row by calling
+ * {@link #createView(FlowView, int, int, int)} until the available space is
+ * exhausted, a forced break is encountered or there are no more views in
+ * the logical view. If the available space is exhausted,
+ * {@link #adjustRow(FlowView, int, int, int)} is called to fit the row into
+ * the available span.
+ *
* @param fv the flow view for which we perform the layout
* @param rowIndex the index of the row
* @param pos the model position for the beginning of the row
- *
* @return the start position of the next row
*/
protected int layoutRow(FlowView fv, int rowIndex, int pos)
@@ -188,36 +186,39 @@ public abstract class FlowView extends BoxView
if (span == 0)
span = Integer.MAX_VALUE;
- while (span > 0)
+ Row: while (span > 0)
{
- if (logicalView.getViewIndex(offset, Position.Bias.Forward) == -1)
+ if (logicalView.getViewIndex(offset, Position.Bias.Forward) == - 1)
break;
View view = createView(fv, offset, span, rowIndex);
if (view == null)
break;
+
int viewSpan = (int) view.getPreferredSpan(axis);
- row.append(view);
int breakWeight = view.getBreakWeight(axis, x, span);
-
- offset += (view.getEndOffset() - view.getStartOffset());
- if (breakWeight >= View.ForcedBreakWeight)
- break;
+ row.append(view);
+ offset += (view.getEndOffset() - view.getStartOffset());
x += viewSpan;
span -= viewSpan;
+
+ // Break if the line if the view does not fit in this row or the
+ // line just must be broken.
+ if (span < 0 || breakWeight >= View.ForcedBreakWeight)
+ {
+ int flowStart = fv.getFlowStart(axis);
+ int flowSpan = fv.getFlowSpan(axis);
+ adjustRow(fv, rowIndex, flowSpan, flowStart);
+ int rowViewCount = row.getViewCount();
+ if (rowViewCount > 0)
+ offset = row.getView(rowViewCount - 1).getEndOffset();
+ else
+ offset = - 1;
+ break Row;
+ }
}
- if (span < 0)
- {
- int flowStart = fv.getFlowStart(axis);
- int flowSpan = fv.getFlowSpan(axis);
- adjustRow(fv, rowIndex, flowSpan, flowStart);
- int rowViewCount = row.getViewCount();
- if (rowViewCount > 0)
- offset = row.getView(rowViewCount - 1).getEndOffset();
- else
- offset = -1;
- }
- return offset != pos ? offset : -1;
+
+ return offset != pos ? offset : - 1;
}
/**
diff --git a/javax/swing/text/html/HRuleView.java b/javax/swing/text/html/HRuleView.java
index fc317798c..3bae5eb8e 100644
--- a/javax/swing/text/html/HRuleView.java
+++ b/javax/swing/text/html/HRuleView.java
@@ -59,9 +59,52 @@ class HRuleView extends InlineView
*/
View nullView;
+ /**
+ * The height of the horizontal dash area.
+ */
static int HEIGHT = 4;
/**
+ * The imaginary invisible view that stays after end of line after the
+ * breaking procedure. It occupies on character.
+ */
+ class Beginning extends NullView
+ {
+ /**
+ * The break offset that becomes the views start offset.
+ */
+ int breakOffset;
+
+ /**
+ * Return the end offset that is always one char after the break offset.
+ */
+ public int getEndOffset()
+ {
+ return breakOffset + 1;
+ }
+
+ /**
+ * Return the start offset that has been passed in a constructor.
+ */
+ public int getStartOffset()
+ {
+ return breakOffset;
+ }
+
+ /**
+ * Create the new instance of this view.
+ *
+ * @param element the element (inherited from the HR view)
+ * @param offset the position where the HR view has been broken
+ */
+ public Beginning(Element element, int offset)
+ {
+ super(element);
+ breakOffset = offset;
+ }
+ }
+
+ /**
* Creates the new HR view.
*/
public HRuleView(Element element)
@@ -76,7 +119,7 @@ class HRuleView extends InlineView
*/
public int getBreakWeight(int axis, float pos, float len)
{
- if (axis == X_AXIS)
+ if (axis == X_AXIS && ((getEndOffset() - getStartOffset()) > 1))
return ForcedBreakWeight;
else
return BadBreakWeight;
@@ -105,14 +148,17 @@ class HRuleView extends InlineView
}
/**
- * Always returns the null view, indicating that the dash must be painted
- * below the breaking point.
+ * Break the view into this view and the invisible imaginary view that
+ * stays on the end of line that is broken by HR dash. The view is broken
+ * only if its length is longer than one (the two characters are expected
+ * in the initial length).
*/
public View breakView(int axis, int offset, float pos, float len)
{
- if (nullView == null)
- nullView = new NullView(getElement());
- return nullView;
+ if (getEndOffset() - getStartOffset() > 1)
+ return new Beginning(getElement(), offset);
+ else
+ return this;
}
/**
@@ -132,15 +178,7 @@ class HRuleView extends InlineView
else
return HEIGHT;
}
-
- /**
- * Returns the same values as {@link #getMaximumSpan(int)}
- */
- public float getMinimumSpan(int axis)
- {
- return getMaximumSpan(axis);
- }
-
+
/**
* Returns the same values as {@link #getMaximumSpan(int)}
*/
diff --git a/javax/swing/text/html/HTMLDocument.java b/javax/swing/text/html/HTMLDocument.java
index e714a857b..0eaf66fd8 100644
--- a/javax/swing/text/html/HTMLDocument.java
+++ b/javax/swing/text/html/HTMLDocument.java
@@ -1433,14 +1433,14 @@ public class HTMLDocument extends DefaultStyledDocument
// Migrate from the rather htmlAttributeSet to the faster, lighter and
// unchangeable alternative implementation.
AttributeSet copy = a.copyAttributes();
-
- // TODO: Figure out why we must always insert this single character
- // (otherwise the element does not appear). Either fix or add explaining
- // comment or at least report a normal bug.
- DefaultStyledDocument.ElementSpec spec;
- spec = new DefaultStyledDocument.ElementSpec(copy,
- DefaultStyledDocument.ElementSpec.ContentType,
- new char[] {' '}, 0, 1 );
+
+ // The two spaces are required because some special elements like HR
+ // must be broken. At least two characters are needed to break into the
+ // two parts.
+ DefaultStyledDocument.ElementSpec spec =
+ new DefaultStyledDocument.ElementSpec(copy,
+ DefaultStyledDocument.ElementSpec.ContentType,
+ new char[] {' ', ' '}, 0, 2 );
parseBuffer.add(spec);
}