summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-12-01 20:34:06 +0000
committerRoman Kennke <roman@kennke.org>2006-12-01 20:34:06 +0000
commit7432498fe956f2720f9c51b845c7a9bcd8c38e1b (patch)
treee87295e3c4153e78fc0feac3c05912219313d7f9
parent5bce0abfef6817e4299bc0640baf46b5f873d530 (diff)
downloadclasspath-7432498fe956f2720f9c51b845c7a9bcd8c38e1b.tar.gz
2006-12-01 Roman Kennke <kennke@aicas.com>
* gnu/javax/swing/text/html/css/BorderStyle.java: New class for handling border styles. * gnu/javax/swing/text/html/css/BorderWidth.java (isValid): New method. * gnu/javax/swing/text/html/css/Length.java (isValid): New method. * javax/swing/text/html/CSS.java (addInternal): Added shorthand parsing for border, padding and margin. (parseBackgroundShorthand): Added API docs. (parsePaddingShorthand): New method. Handles padding shorthand values. (parseMarginShorthand): New method. Handles margin shorthand values. (parseBorderShorthand): New method. Handles border shorthand values. * javax/swing/text/html/StyleSheet.java (translateHTMLToCSS): Set specific padding attributes. (BoxPainter.BoxPainter): Don't handle PADDING and MARGIN here. These shorthands are now handled in CSS. (BoxPainter.paint): Exclude the outer margin.
-rw-r--r--ChangeLog26
-rw-r--r--gnu/javax/swing/text/html/css/BorderStyle.java64
-rw-r--r--gnu/javax/swing/text/html/css/BorderWidth.java12
-rw-r--r--gnu/javax/swing/text/html/css/Length.java49
-rw-r--r--javax/swing/text/html/CSS.java173
-rw-r--r--javax/swing/text/html/StyleSheet.java33
6 files changed, 336 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index c454872e1..5054a7dc2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,28 @@
-2006-11-30 Roman Kennke <kennke@aicas.com>
+2006-12-01 Roman Kennke <kennke@aicas.com>
+
+ * gnu/javax/swing/text/html/css/BorderStyle.java: New class for
+ handling border styles.
+ * gnu/javax/swing/text/html/css/BorderWidth.java
+ (isValid): New method.
+ * gnu/javax/swing/text/html/css/Length.java
+ (isValid): New method.
+ * javax/swing/text/html/CSS.java
+ (addInternal): Added shorthand parsing for border, padding and
+ margin.
+ (parseBackgroundShorthand): Added API docs.
+ (parsePaddingShorthand): New method. Handles padding shorthand
+ values.
+ (parseMarginShorthand): New method. Handles margin shorthand
+ values.
+ (parseBorderShorthand): New method. Handles border shorthand
+ values.
+ * javax/swing/text/html/StyleSheet.java
+ (translateHTMLToCSS): Set specific padding attributes.
+ (BoxPainter.BoxPainter): Don't handle PADDING and MARGIN here.
+ These shorthands are now handled in CSS.
+ (BoxPainter.paint): Exclude the outer margin.
+
+2006-12-01 Roman Kennke <kennke@aicas.com>
* gnu/javax/swing/text/html/css/Length.java
(emBase): New field.
diff --git a/gnu/javax/swing/text/html/css/BorderStyle.java b/gnu/javax/swing/text/html/css/BorderStyle.java
new file mode 100644
index 000000000..d75beea52
--- /dev/null
+++ b/gnu/javax/swing/text/html/css/BorderStyle.java
@@ -0,0 +1,64 @@
+/* BorderStyle.java -- Utility for dealing with border styles
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.swing.text.html.css;
+
+/**
+ * Utility class for handling border styles.
+ */
+public class BorderStyle
+{
+
+ /**
+ * Determines if a given value makes up a valid border style value.
+ *
+ * @param value the value to check
+ *
+ * @return <code>true</code> when this is a valid border style,
+ * <code>false</code> otherwise
+ */
+ public static boolean isValidStyle(String value)
+ {
+ return value.equals("none") || value.equals("hidden")
+ || value.equals("dotted") || value.equals("dashed")
+ || value.equals("solid") || value.equals("double")
+ || value.equals("groove") || value.equals("ridge")
+ || value.equals("inset") || value.equals("outset");
+
+ }
+}
diff --git a/gnu/javax/swing/text/html/css/BorderWidth.java b/gnu/javax/swing/text/html/css/BorderWidth.java
index b717020e3..ae64c2110 100644
--- a/gnu/javax/swing/text/html/css/BorderWidth.java
+++ b/gnu/javax/swing/text/html/css/BorderWidth.java
@@ -63,4 +63,16 @@ public class BorderWidth
floatValue = 3.F;
}
+ /**
+ * Checks if the specified value makes up a valid border-width value.
+ *
+ * @param value the value to check
+ *
+ * @return <code>true</code> if the value is a valid border-width
+ */
+ public static boolean isValid(String value)
+ {
+ return value.equals("thin") || value.equals("medium")
+ || value.equals("thick") || Length.isValid(value);
+ }
}
diff --git a/gnu/javax/swing/text/html/css/Length.java b/gnu/javax/swing/text/html/css/Length.java
index 06e1ce1ac..06fa36e3d 100644
--- a/gnu/javax/swing/text/html/css/Length.java
+++ b/gnu/javax/swing/text/html/css/Length.java
@@ -231,4 +231,53 @@ public class Length
{
return isPercentage;
}
+
+ /**
+ * Checks if the specified value makes up a valid length value.
+ *
+ * @param value the value to check
+ *
+ * @return <code>true</code> if the value is a valid length
+ */
+ public static boolean isValid(String value)
+ {
+ boolean isValid = true;
+ int px = value.indexOf("px");
+ int em = value.indexOf("em");
+ int ex = value.indexOf("ex");
+ int pc = value.indexOf('%');
+ try
+ {
+ if (px != -1)
+ {
+ Integer.parseInt(value.substring(0, px));
+ }
+ else if (em != -1)
+ {
+ Integer.parseInt(value.substring(0, em));
+ }
+ else if (ex != -1)
+ {
+ Integer.parseInt(value.substring(0, ex));
+ }
+ else if (pc != -1)
+ {
+ Integer.parseInt(value.substring(0, ex));
+ }
+ else
+ {
+ Integer.parseInt(value);
+ }
+ }
+ catch (NumberFormatException nfe)
+ {
+ isValid = false;
+ }
+ return isValid;
+ }
+
+ public String toString()
+ {
+ return value;
+ }
}
diff --git a/javax/swing/text/html/CSS.java b/javax/swing/text/html/CSS.java
index c82b6c537..0d1eeb762 100644
--- a/javax/swing/text/html/CSS.java
+++ b/javax/swing/text/html/CSS.java
@@ -37,6 +37,7 @@ exception statement from your version. */
package javax.swing.text.html;
+import gnu.javax.swing.text.html.css.BorderStyle;
import gnu.javax.swing.text.html.css.BorderWidth;
import gnu.javax.swing.text.html.css.CSSColor;
import gnu.javax.swing.text.html.css.FontSize;
@@ -417,7 +418,7 @@ public class CSS implements Serializable
new Attribute("border-right-color", false, null);
static final Attribute BORDER_SPACING =
new Attribute("border-spacing", false, null);
-
+
/**
* The attribute string.
*/
@@ -537,8 +538,23 @@ public class CSS implements Serializable
{
if (a == Attribute.BACKGROUND)
parseBackgroundShorthand(atts, v);
+ else if (a == Attribute.PADDING)
+ parsePaddingShorthand(atts, v);
+ else if (a == Attribute.MARGIN)
+ parseMarginShorthand(atts, v);
+ else if (a == Attribute.BORDER || a == Attribute.BORDER_LEFT
+ || a == Attribute.BORDER_RIGHT || a == Attribute.BORDER_TOP
+ || a == Attribute.BORDER_BOTTOM)
+ parseBorderShorthand(atts, v, a);
}
+ /**
+ * Parses the background shorthand and translates it to more specific
+ * background attributes.
+ *
+ * @param atts the attributes
+ * @param v the value
+ */
private static void parseBackgroundShorthand(MutableAttributeSet atts,
String v)
{
@@ -551,4 +567,159 @@ public class CSS implements Serializable
new CSSColor(token));
}
}
+
+ /**
+ * Parses the padding shorthand and translates to the specific padding
+ * values.
+ *
+ * @param atts the attributes
+ * @param v the actual value
+ */
+ private static void parsePaddingShorthand(MutableAttributeSet atts, String v)
+ {
+ StringTokenizer tokens = new StringTokenizer(v, " ");
+ int numTokens = tokens.countTokens();
+ if (numTokens == 1)
+ {
+ Length l = new Length(tokens.nextToken());
+ atts.addAttribute(Attribute.PADDING_BOTTOM, l);
+ atts.addAttribute(Attribute.PADDING_LEFT, l);
+ atts.addAttribute(Attribute.PADDING_RIGHT, l);
+ atts.addAttribute(Attribute.PADDING_TOP, l);
+ }
+ else if (numTokens == 2)
+ {
+ Length l1 = new Length(tokens.nextToken());
+ Length l2 = new Length(tokens.nextToken());
+ atts.addAttribute(Attribute.PADDING_BOTTOM, l1);
+ atts.addAttribute(Attribute.PADDING_TOP, l1);
+ atts.addAttribute(Attribute.PADDING_LEFT, l2);
+ atts.addAttribute(Attribute.PADDING_RIGHT, l2);
+ }
+ else if (numTokens == 3)
+ {
+ Length l1 = new Length(tokens.nextToken());
+ Length l2 = new Length(tokens.nextToken());
+ Length l3 = new Length(tokens.nextToken());
+ atts.addAttribute(Attribute.PADDING_TOP, l1);
+ atts.addAttribute(Attribute.PADDING_LEFT, l2);
+ atts.addAttribute(Attribute.PADDING_RIGHT, l2);
+ atts.addAttribute(Attribute.PADDING_BOTTOM, l3);
+ }
+ else
+ {
+ Length l1 = new Length(tokens.nextToken());
+ Length l2 = new Length(tokens.nextToken());
+ Length l3 = new Length(tokens.nextToken());
+ Length l4 = new Length(tokens.nextToken());
+ atts.addAttribute(Attribute.PADDING_TOP, l1);
+ atts.addAttribute(Attribute.PADDING_RIGHT, l2);
+ atts.addAttribute(Attribute.PADDING_BOTTOM, l3);
+ atts.addAttribute(Attribute.PADDING_LEFT, l4);
+ }
+ }
+
+ /**
+ * Parses the margin shorthand and translates to the specific margin
+ * values.
+ *
+ * @param atts the attributes
+ * @param v the actual value
+ */
+ private static void parseMarginShorthand(MutableAttributeSet atts, String v)
+ {
+ StringTokenizer tokens = new StringTokenizer(v, " ");
+ int numTokens = tokens.countTokens();
+ if (numTokens == 1)
+ {
+ Length l = new Length(tokens.nextToken());
+ System.err.println("margin: " + l);
+ atts.addAttribute(Attribute.MARGIN_BOTTOM, l);
+ atts.addAttribute(Attribute.MARGIN_LEFT, l);
+ atts.addAttribute(Attribute.MARGIN_RIGHT, l);
+ atts.addAttribute(Attribute.MARGIN_TOP, l);
+ }
+ else if (numTokens == 2)
+ {
+ Length l1 = new Length(tokens.nextToken());
+ Length l2 = new Length(tokens.nextToken());
+ atts.addAttribute(Attribute.MARGIN_BOTTOM, l1);
+ atts.addAttribute(Attribute.MARGIN_TOP, l1);
+ atts.addAttribute(Attribute.MARGIN_LEFT, l2);
+ atts.addAttribute(Attribute.MARGIN_RIGHT, l2);
+ }
+ else if (numTokens == 3)
+ {
+ Length l1 = new Length(tokens.nextToken());
+ Length l2 = new Length(tokens.nextToken());
+ Length l3 = new Length(tokens.nextToken());
+ atts.addAttribute(Attribute.MARGIN_TOP, l1);
+ atts.addAttribute(Attribute.MARGIN_LEFT, l2);
+ atts.addAttribute(Attribute.MARGIN_RIGHT, l2);
+ atts.addAttribute(Attribute.MARGIN_BOTTOM, l3);
+ }
+ else
+ {
+ Length l1 = new Length(tokens.nextToken());
+ Length l2 = new Length(tokens.nextToken());
+ Length l3 = new Length(tokens.nextToken());
+ Length l4 = new Length(tokens.nextToken());
+ atts.addAttribute(Attribute.MARGIN_TOP, l1);
+ atts.addAttribute(Attribute.MARGIN_RIGHT, l2);
+ atts.addAttribute(Attribute.MARGIN_BOTTOM, l3);
+ atts.addAttribute(Attribute.MARGIN_LEFT, l4);
+ }
+ }
+
+ /**
+ * Parses the CSS border shorthand attribute and translates it to the
+ * more specific border attributes.
+ *
+ * @param atts the attribute
+ * @param value the value
+ */
+ private static void parseBorderShorthand(MutableAttributeSet atts,
+ String value, Attribute cssAtt)
+ {
+ StringTokenizer tokens = new StringTokenizer(value, " ");
+ while (tokens.hasMoreTokens())
+ {
+ String token = tokens.nextToken();
+ if (BorderStyle.isValidStyle(token))
+ {
+ if (cssAtt == Attribute.BORDER_LEFT || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_LEFT_STYLE, token);
+ if (cssAtt == Attribute.BORDER_RIGHT || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_RIGHT_STYLE, token);
+ if (cssAtt == Attribute.BORDER_BOTTOM || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_BOTTOM_STYLE, token);
+ if (cssAtt == Attribute.BORDER_TOP || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_TOP_STYLE, token);
+ }
+ else if (BorderWidth.isValid(token))
+ {
+ BorderWidth w = new BorderWidth(token);
+ if (cssAtt == Attribute.BORDER_LEFT || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_LEFT_WIDTH, w);
+ if (cssAtt == Attribute.BORDER_RIGHT || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_RIGHT_WIDTH, w);
+ if (cssAtt == Attribute.BORDER_BOTTOM || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_BOTTOM_WIDTH, w);
+ if (cssAtt == Attribute.BORDER_TOP || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_TOP_WIDTH, w);
+ }
+ else if (CSSColor.isValidColor(token))
+ {
+ CSSColor c = new CSSColor(token);
+ if (cssAtt == Attribute.BORDER_LEFT || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_LEFT_COLOR, c);
+ if (cssAtt == Attribute.BORDER_RIGHT || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_RIGHT_COLOR, c);
+ if (cssAtt == Attribute.BORDER_BOTTOM || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_BOTTOM_COLOR, c);
+ if (cssAtt == Attribute.BORDER_TOP || cssAtt == Attribute.BORDER)
+ atts.addAttribute(Attribute.BORDER_TOP_COLOR, c);
+ }
+ }
+ }
}
diff --git a/javax/swing/text/html/StyleSheet.java b/javax/swing/text/html/StyleSheet.java
index 1f3d14b5e..eadd325f2 100644
--- a/javax/swing/text/html/StyleSheet.java
+++ b/javax/swing/text/html/StyleSheet.java
@@ -743,8 +743,13 @@ public class StyleSheet extends StyleContext
.getAttributes();
o = tableAttrs.getAttribute(HTML.Attribute.CELLPADDING);
if (o != null)
- cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING,
- new Length(o.toString()));
+ {
+ Length l = new Length(o.toString());
+ cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_BOTTOM, l);
+ cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_LEFT, l);
+ cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_RIGHT, l);
+ cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_TOP, l);
+ }
}
// TODO: Add more mappings.
return cssAttr;
@@ -1155,13 +1160,7 @@ public class StyleSheet extends StyleContext
float emBase = ss.getEMBase(as);
float exBase = ss.getEXBase(as);
// Fetch margins.
- Length l = (Length) as.getAttribute(CSS.Attribute.MARGIN);
- if (l != null)
- {
- l.setFontBases(emBase, exBase);
- topInset = bottomInset = leftInset = rightInset = l.getValue();
- }
- l = (Length) as.getAttribute(CSS.Attribute.MARGIN_LEFT);
+ Length l = (Length) as.getAttribute(CSS.Attribute.MARGIN_LEFT);
if (l != null)
{
l.setFontBases(emBase, exBase);
@@ -1187,13 +1186,6 @@ public class StyleSheet extends StyleContext
}
// Fetch padding.
- l = (Length) as.getAttribute(CSS.Attribute.PADDING);
- if (l != null)
- {
- l.setFontBases(emBase, exBase);
- leftPadding = rightPadding = topPadding = bottomPadding =
- l.getValue();
- }
l = (Length) as.getAttribute(CSS.Attribute.PADDING_LEFT);
if (l != null)
{
@@ -1287,15 +1279,18 @@ public class StyleSheet extends StyleContext
*/
public void paint(Graphics g, float x, float y, float w, float h, View v)
{
-
+ int inX = (int) (x + leftInset);
+ int inY = (int) (y + topInset);
+ int inW = (int) (w - leftInset - rightInset);
+ int inH = (int) (h - topInset - bottomInset);
if (background != null)
{
g.setColor(background);
- g.fillRect((int) x, (int) y, (int) w, (int) h);
+ g.fillRect(inX, inY, inW, inH);
}
if (border != null)
{
- border.paintBorder(null, g, (int) x, (int) y, (int) w, (int) h);
+ border.paintBorder(null, g, inX, inY, inW, inH);
}
}
}