summaryrefslogtreecommitdiff
path: root/javax
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-11-15 11:03:00 +0000
committerRoman Kennke <roman@kennke.org>2006-11-15 11:03:00 +0000
commitd75e6f110b4e554532133d265beffd0ff211fd38 (patch)
tree5676f5ed9ce12b5e790d693e0a073ff0af368d4e /javax
parente54f60215b005f0a1957afe55e0dc8bc5c3518e6 (diff)
downloadclasspath-d75e6f110b4e554532133d265beffd0ff211fd38.tar.gz
2006-11-15 Roman Kennke <kennke@aicas.com>
* javax/swing/text/html/CSS.java (Attribute.BORDER_SPACING): New field for the CSS border-spacing attribute. * javax/swing/text/html/StyleSheet.java (BoxPainter.bottomPadding): New field. (BoxPainter.leftPadding): New field. (BoxPainter.rightPadding): New field. (BoxPainter.topPadding): New field. (BoxPainter.BoxPainter): Fetch the MARGIN and PADDING* attributes too. (BoxPainter.getInset): Recognize and include the padding. (translateHTMLToCSS): Added mapping for CELLPADDING and CELLSPACING. javax/swing/text/html/TableView.java (RowView.calculateMajorAxisRequirements): Adjust req's for cellSpacing. (RowView.layoutMajorAxis): Adjust multi-column span for cellSpacing. (cellSpacing): New field. (columnRequirements): Made package private to avoid accessor method. (calculateMinorAxisRequirements): Include cellSpacing. (calculateMajorAxisRequirements): Overridden to include cellSpacing. (layoutMajorAxis): Likewise. (layoutColumns): Respect cellSpacing. (setParent): Overridden to fetch the CSS attributes when view gets connected. (setPropertiesFromAttributes): New method. Fetches the cell spacing from the CSS attributes.
Diffstat (limited to 'javax')
-rw-r--r--javax/swing/text/html/CSS.java7
-rw-r--r--javax/swing/text/html/StyleSheet.java58
-rw-r--r--javax/swing/text/html/TableView.java89
3 files changed, 144 insertions, 10 deletions
diff --git a/javax/swing/text/html/CSS.java b/javax/swing/text/html/CSS.java
index 6461dca9a..2068076e2 100644
--- a/javax/swing/text/html/CSS.java
+++ b/javax/swing/text/html/CSS.java
@@ -415,6 +415,8 @@ public class CSS implements Serializable
new Attribute("border-left-color", false, null);
static final Attribute BORDER_RIGHT_COLOR =
new Attribute("border-right-color", false, null);
+ static final Attribute BORDER_SPACING =
+ new Attribute("border-spacing", false, null);
/**
* The attribute string.
@@ -516,7 +518,10 @@ public class CSS implements Serializable
else if (att == Attribute.MARGIN || att == Attribute.MARGIN_BOTTOM
|| att == Attribute.MARGIN_LEFT || att == Attribute.MARGIN_RIGHT
|| att == Attribute.MARGIN_TOP || att == Attribute.WIDTH
- || att == Attribute.HEIGHT)
+ || att == Attribute.HEIGHT
+ || att == Attribute.PADDING || att == Attribute.PADDING_BOTTOM
+ || att == Attribute.PADDING_LEFT || att == Attribute.PADDING_RIGHT
+ || att == Attribute.PADDING_TOP)
o = new Length(v);
else if (att == Attribute.BORDER_WIDTH || att == Attribute.BORDER_TOP_WIDTH
|| att == Attribute.BORDER_LEFT_WIDTH
diff --git a/javax/swing/text/html/StyleSheet.java b/javax/swing/text/html/StyleSheet.java
index 450682f68..72cf7044f 100644
--- a/javax/swing/text/html/StyleSheet.java
+++ b/javax/swing/text/html/StyleSheet.java
@@ -709,6 +709,27 @@ public class StyleSheet extends StyleContext
if (o != null)
cssAttr = addAttribute(cssAttr, CSS.Attribute.WHITE_SPACE, "nowrap");
+ // Map cellspacing attr of tables to CSS border-spacing.
+ o = htmlAttrSet.getAttribute(HTML.Attribute.CELLSPACING);
+ if (o != null)
+ cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_SPACING,
+ new Length(o.toString()));
+
+ // For table cells and headers, fetch the cellpadding value from the
+ // parent table and set it as CSS padding attribute.
+ HTML.Tag tag = (HTML.Tag)
+ htmlAttrSet.getAttribute(StyleConstants.NameAttribute);
+ if ((tag == HTML.Tag.TD || tag == HTML.Tag.TH)
+ && htmlAttrSet instanceof Element)
+ {
+ Element el = (Element) htmlAttrSet;
+ AttributeSet tableAttrs = el.getParentElement().getParentElement()
+ .getAttributes();
+ o = tableAttrs.getAttribute(HTML.Attribute.CELLPADDING);
+ if (o != null)
+ cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING,
+ new Length(o.toString()));
+ }
// TODO: Add more mappings.
return cssAttr;
}
@@ -1036,6 +1057,11 @@ public class StyleSheet extends StyleContext
*/
private Border border;
+ private float leftPadding;
+ private float rightPadding;
+ private float topPadding;
+ private float bottomPadding;
+
/**
* The background color.
*/
@@ -1048,7 +1074,13 @@ public class StyleSheet extends StyleContext
*/
BoxPainter(AttributeSet as, StyleSheet ss)
{
- Length l = (Length) as.getAttribute(CSS.Attribute.MARGIN_LEFT);
+ // Fetch margins.
+ Length l = (Length) as.getAttribute(CSS.Attribute.MARGIN);
+ if (l != null)
+ {
+ topInset = bottomInset = leftInset = rightInset = l.getValue();
+ }
+ l = (Length) as.getAttribute(CSS.Attribute.MARGIN_LEFT);
if (l != null)
leftInset = l.getValue();
l = (Length) as.getAttribute(CSS.Attribute.MARGIN_RIGHT);
@@ -1061,6 +1093,26 @@ public class StyleSheet extends StyleContext
if (l != null)
bottomInset = l.getValue();
+ // Fetch padding.
+ l = (Length) as.getAttribute(CSS.Attribute.PADDING);
+ if (l != null)
+ {
+ leftPadding = rightPadding = topPadding = bottomPadding =
+ l.getValue();
+ }
+ l = (Length) as.getAttribute(CSS.Attribute.PADDING_LEFT);
+ if (l != null)
+ leftPadding = l.getValue();
+ l = (Length) as.getAttribute(CSS.Attribute.PADDING_RIGHT);
+ if (l != null)
+ rightPadding = l.getValue();
+ l = (Length) as.getAttribute(CSS.Attribute.PADDING_TOP);
+ if (l != null)
+ topPadding = l.getValue();
+ l = (Length) as.getAttribute(CSS.Attribute.PADDING_BOTTOM);
+ if (l != null)
+ bottomPadding = l.getValue();
+
// Determine border.
border = new CSSBorder(as);
@@ -1090,21 +1142,25 @@ public class StyleSheet extends StyleContext
inset = topInset;
if (border != null)
inset += border.getBorderInsets(null).top;
+ inset += topPadding;
break;
case View.BOTTOM:
inset = bottomInset;
if (border != null)
inset += border.getBorderInsets(null).bottom;
+ inset += bottomPadding;
break;
case View.LEFT:
inset = leftInset;
if (border != null)
inset += border.getBorderInsets(null).left;
+ inset += leftPadding;
break;
case View.RIGHT:
inset = rightInset;
if (border != null)
inset += border.getBorderInsets(null).right;
+ inset += rightPadding;
break;
default:
inset = 0.0F;
diff --git a/javax/swing/text/html/TableView.java b/javax/swing/text/html/TableView.java
index 1e99042b5..fb62c1b1a 100644
--- a/javax/swing/text/html/TableView.java
+++ b/javax/swing/text/html/TableView.java
@@ -117,9 +117,10 @@ class TableView
{
if (r == null)
r = new SizeRequirements();
- r.minimum = totalColumnRequirements.minimum;
- r.preferred = totalColumnRequirements.preferred;
- r.maximum = totalColumnRequirements.maximum;
+ int adjust = (columnRequirements.length + 1) * cellSpacing;
+ r.minimum = totalColumnRequirements.minimum + adjust;
+ r.preferred = totalColumnRequirements.preferred + adjust;
+ r.maximum = totalColumnRequirements.maximum + adjust;
r.alignment = 0.0F;
return r;
}
@@ -143,6 +144,8 @@ class TableView
for (int j = 0; j < cv.colSpan; j++, realColumn++)
{
spans[i] += columnSpans[realColumn];
+ if (j < cv.colSpan - 1)
+ spans[i] += cellSpacing;
}
}
}
@@ -211,8 +214,10 @@ class TableView
/**
* The column requirements.
+ *
+ * Package private to avoid accessor methods.
*/
- private SizeRequirements[] columnRequirements;
+ SizeRequirements[] columnRequirements;
/**
* The overall requirements across all columns.
@@ -246,6 +251,13 @@ class TableView
private boolean gridValid;
/**
+ * Additional space that is added _between_ table cells.
+ *
+ * This is package private to avoid accessor methods.
+ */
+ int cellSpacing;
+
+ /**
* Creates a new HTML table view for the specified element.
*
* @param el the element for the table view
@@ -346,6 +358,11 @@ class TableView
r.minimum = width;
}
+ // Adjust requirements when we have cell spacing.
+ int adjust = (columnRequirements.length + 1) * cellSpacing;
+ r.minimum += adjust;
+ r.preferred += adjust;
+
// Apply the alignment.
Object o = atts.getAttribute(CSS.Attribute.TEXT_ALIGN);
r.alignment = 0.0F;
@@ -360,6 +377,8 @@ class TableView
r.alignment = 1.0F;
}
+ // Make it not resize in the horizontal direction.
+ r.maximum = r.preferred;
return r;
}
@@ -561,7 +580,9 @@ class TableView
}
// Try to adjust the spans so that we fill the targetSpan.
- long diff = targetSpan - sumPref;
+ // For adjustments we have to use the targetSpan minus the cumulated
+ // cell spacings.
+ long diff = targetSpan - (n + 1) * cellSpacing - sumPref;
float factor = 0.0F;
int[] diffs = null;
if (diff != 0)
@@ -598,7 +619,7 @@ class TableView
}
// Actually perform adjustments.
- int totalOffs = 0;
+ int totalOffs = cellSpacing;
for (int i = 0; i < n; i++)
{
columnOffsets[i] = totalOffs;
@@ -608,8 +629,8 @@ class TableView
columnSpans[i] += Math.round(adjust);
}
// Avoid overflow here.
- totalOffs = (int) Math.min((long) totalOffs + (long) columnSpans[i],
- Integer.MAX_VALUE);
+ totalOffs = (int) Math.min((long) totalOffs + (long) columnSpans[i]
+ + (long) cellSpacing, Integer.MAX_VALUE);
}
}
@@ -672,4 +693,56 @@ class TableView
span = super.getMaximumSpan(axis);
return span;
}
+
+ /**
+ * Overridden to fetch the CSS attributes when view gets connected.
+ */
+ public void setParent(View parent)
+ {
+ super.setParent(parent);
+ if (parent != null)
+ setPropertiesFromAttributes();
+ }
+
+ /**
+ * Fetches CSS and HTML layout attributes.
+ */
+ private void setPropertiesFromAttributes()
+ {
+ // Fetch and parse cell spacing.
+ Object o = getAttributes().getAttribute(CSS.Attribute.BORDER_SPACING);
+ if (o != null && o instanceof Length)
+ {
+ Length l = (Length) o;
+ cellSpacing = (int) l.getValue();
+ }
+ }
+
+ /**
+ * Overridden to adjust for cellSpacing.
+ */
+ protected SizeRequirements calculateMajorAxisRequirements(int axis,
+ SizeRequirements r)
+ {
+ r = super.calculateMajorAxisRequirements(axis, r);
+ int adjust = (getViewCount() + 1) * cellSpacing;
+ r.minimum += adjust;
+ r.preferred += adjust;
+ r.maximum += adjust;
+ return r;
+ }
+
+ /**
+ * Overridden to adjust for cellSpacing.
+ */
+ protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets,
+ int spans[])
+ {
+ int adjust = (getViewCount() + 1) * cellSpacing;
+ super.layoutMajorAxis(targetSpan - adjust, axis, offsets, spans);
+ for (int i = 0; i < offsets.length; i++)
+ {
+ offsets[i] += (i + 1) * cellSpacing;
+ }
+ }
}