summaryrefslogtreecommitdiff
path: root/javax/swing
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-12-06 19:36:08 +0000
committerRoman Kennke <roman@kennke.org>2006-12-06 19:36:08 +0000
commitd5425275a1d00836416906578b76ceba3d35ecae (patch)
treeadd3080a271ae50acdce6b5d555ff8f94270a95c /javax/swing
parent784d171e995d386c1aae2899a963d725ab7ded88 (diff)
downloadclasspath-d5425275a1d00836416906578b76ceba3d35ecae.tar.gz
2006-12-06 Roman Kennke <kennke@aicas.com>
* javax/swing/text/html/BlockView.java (getAlignment): Align blocks horizontally by the superclass. * javax/swing/text/html/HTMLEditorKit.java (HTMLFactory.create): Replace equals comparison by == for efficiency. Add mapping for misplaced tr, td and th tags. Include object mapping. * javax/swing/text/html/TableView.java (RowView.replace): Invalidate grid early. (gridValid): Initialize with false. (create): Only create RowView and CellView for correctly placed tags. Avoid unnecessary casts. (getAlignment): Removed. (replace): Invalidate grid early.
Diffstat (limited to 'javax/swing')
-rw-r--r--javax/swing/text/html/BlockView.java2
-rw-r--r--javax/swing/text/html/HTMLEditorKit.java59
-rw-r--r--javax/swing/text/html/TableView.java43
3 files changed, 49 insertions, 55 deletions
diff --git a/javax/swing/text/html/BlockView.java b/javax/swing/text/html/BlockView.java
index 1fc29cd68..b05c983e9 100644
--- a/javax/swing/text/html/BlockView.java
+++ b/javax/swing/text/html/BlockView.java
@@ -523,7 +523,7 @@ public class BlockView extends BoxView
public float getAlignment(int axis)
{
if (axis == X_AXIS)
- return 0.0F;
+ return super.getAlignment(axis);
if (axis == Y_AXIS)
{
if (getViewCount() == 0)
diff --git a/javax/swing/text/html/HTMLEditorKit.java b/javax/swing/text/html/HTMLEditorKit.java
index c15fcae99..0ede1c74e 100644
--- a/javax/swing/text/html/HTMLEditorKit.java
+++ b/javax/swing/text/html/HTMLEditorKit.java
@@ -792,48 +792,53 @@ public class HTMLEditorKit
{
HTML.Tag tag = (HTML.Tag) attr;
- if (tag.equals(HTML.Tag.IMPLIED) || tag.equals(HTML.Tag.P)
- || tag.equals(HTML.Tag.H1) || tag.equals(HTML.Tag.H2)
- || tag.equals(HTML.Tag.H3) || tag.equals(HTML.Tag.H4)
- || tag.equals(HTML.Tag.H5) || tag.equals(HTML.Tag.H6)
- || tag.equals(HTML.Tag.DT))
+ if (tag == HTML.Tag.IMPLIED || tag == HTML.Tag.P
+ || tag == HTML.Tag.H1 || tag == HTML.Tag.H2
+ || tag == HTML.Tag.H3 || tag == HTML.Tag.H4
+ || tag == HTML.Tag.H5 || tag == HTML.Tag.H6
+ || tag == HTML.Tag.DT)
view = new ParagraphView(element);
- else if (tag.equals(HTML.Tag.LI) || tag.equals(HTML.Tag.DL)
- || tag.equals(HTML.Tag.DD) || tag.equals(HTML.Tag.BODY)
- || tag.equals(HTML.Tag.HTML) || tag.equals(HTML.Tag.CENTER)
- || tag.equals(HTML.Tag.DIV)
- || tag.equals(HTML.Tag.BLOCKQUOTE)
- || tag.equals(HTML.Tag.PRE)
- || tag.equals(HTML.Tag.FORM))
+ else if (tag == HTML.Tag.LI || tag == HTML.Tag.DL
+ || tag == HTML.Tag.DD || tag == HTML.Tag.BODY
+ || tag == HTML.Tag.HTML || tag == HTML.Tag.CENTER
+ || tag == HTML.Tag.DIV
+ || tag == HTML.Tag.BLOCKQUOTE
+ || tag == HTML.Tag.PRE
+ || tag == HTML.Tag.FORM
+ // Misplaced TD and TH tags get mapped as vertical block.
+ // Note that correctly placed tags get mapped in TableView.
+ || tag == HTML.Tag.TD || tag == HTML.Tag.TH)
view = new BlockView(element, View.Y_AXIS);
- else if (tag.equals(HTML.Tag.IMG))
+ else if (tag == HTML.Tag.TR)
+ // Misplaced TR tags get mapped as horizontal blocks.
+ // Note that correctly placed tags get mapped in TableView.
+ view = new BlockView(element, View.X_AXIS);
+ else if (tag == HTML.Tag.IMG)
view = new ImageView(element);
- else if (tag.equals(HTML.Tag.CONTENT))
+ else if (tag == HTML.Tag.CONTENT)
view = new InlineView(element);
else if (tag == HTML.Tag.HEAD)
view = new NullView(element);
- else if (tag.equals(HTML.Tag.TABLE))
+ else if (tag == HTML.Tag.TABLE)
view = new javax.swing.text.html.TableView(element);
- else if (tag.equals(HTML.Tag.HR))
+ else if (tag == HTML.Tag.HR)
view = new HRuleView(element);
- else if (tag.equals(HTML.Tag.BR))
+ else if (tag == HTML.Tag.BR)
view = new BRView(element);
- else if (tag.equals(HTML.Tag.INPUT) || tag.equals(HTML.Tag.SELECT)
- || tag.equals(HTML.Tag.TEXTAREA))
+ else if (tag == HTML.Tag.INPUT || tag == HTML.Tag.SELECT
+ || tag == HTML.Tag.TEXTAREA)
view = new FormView(element);
- else if (tag.equals(HTML.Tag.MENU) || tag.equals(HTML.Tag.DIR)
- || tag.equals(HTML.Tag.UL) || tag.equals(HTML.Tag.OL))
+ else if (tag == HTML.Tag.MENU || tag == HTML.Tag.DIR
+ || tag == HTML.Tag.UL || tag == HTML.Tag.OL)
view = new ListView(element);
- else if (tag.equals(HTML.Tag.FRAMESET))
+ else if (tag == HTML.Tag.FRAMESET)
view = new FrameSetView(element);
- else if (tag.equals(HTML.Tag.FRAME))
+ else if (tag == HTML.Tag.FRAME)
view = new FrameView(element);
- // FIXME: Uncomment when the views have been implemented
- /*
- else if (tag.equals(HTML.Tag.OBJECT))
- view = new ObjectView(element); */
+ else if (tag == HTML.Tag.OBJECT)
+ view = new ObjectView(element);
}
if (view == null)
{
diff --git a/javax/swing/text/html/TableView.java b/javax/swing/text/html/TableView.java
index b4e9bad4f..0885e6372 100644
--- a/javax/swing/text/html/TableView.java
+++ b/javax/swing/text/html/TableView.java
@@ -92,8 +92,8 @@ class TableView
public void replace(int offset, int len, View[] views)
{
- super.replace(offset, len, views);
gridValid = false;
+ super.replace(offset, len, views);
}
/**
@@ -335,7 +335,7 @@ class TableView
/**
* Indicates if the grid setup is ok.
*/
- boolean gridValid;
+ boolean gridValid = false;
/**
* Additional space that is added _between_ table cells.
@@ -370,21 +370,20 @@ class TableView
View view = null;
AttributeSet atts = elem.getAttributes();
Object name = atts.getAttribute(StyleConstants.NameAttribute);
- if (name instanceof HTML.Tag)
- {
- HTML.Tag tag = (HTML.Tag) name;
- if (tag == HTML.Tag.TR)
- view = new RowView(elem);
- else if (tag == HTML.Tag.TD || tag == HTML.Tag.TH)
- view = new CellView(elem);
- else if (tag == HTML.Tag.CAPTION)
- view = new ParagraphView(elem);
- }
-
- // If we haven't mapped the element, then fall back to the standard
- // view factory.
- if (view == null)
+ AttributeSet pAtts = elem.getParentElement().getAttributes();
+ Object pName = pAtts.getAttribute(StyleConstants.NameAttribute);
+
+ if (name == HTML.Tag.TR && pName == HTML.Tag.TABLE)
+ view = new RowView(elem);
+ else if ((name == HTML.Tag.TD || name == HTML.Tag.TH)
+ && pName == HTML.Tag.TR)
+ view = new CellView(elem);
+ else if (name == HTML.Tag.CAPTION)
+ view = new ParagraphView(elem);
+ else
{
+ // If we haven't mapped the element, then fall back to the standard
+ // view factory.
View parent = getParent();
if (parent != null)
{
@@ -944,8 +943,8 @@ class TableView
public void replace(int offset, int len, View[] views)
{
- super.replace(offset, len, views);
gridValid = false;
+ super.replace(offset, len, views);
}
/**
@@ -967,14 +966,4 @@ class TableView
}
}
- /**
- * Overridden to place a table centered in the horizontal direction.
- */
- public float getAlignment(int axis)
- {
- if (axis == X_AXIS)
- return 0.5F;
- else
- return super.getAlignment(axis);
- }
}