summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog33
-rw-r--r--gnu/javax/swing/text/html/css/Length.java90
-rw-r--r--javax/swing/text/BoxView.java8
-rw-r--r--javax/swing/text/GlyphView.java2
-rw-r--r--javax/swing/text/ParagraphView.java30
-rw-r--r--javax/swing/text/html/CSS.java5
-rw-r--r--javax/swing/text/html/ParagraphView.java47
-rw-r--r--javax/swing/text/html/StyleSheet.java48
8 files changed, 245 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index f8291ca44..4c0262949 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2006-08-31 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/text/BoxView.java
+ (getWidth): Return the width with insets added, not with one
+ added and one removed.
+ (getHeight): Return the height with insets added, not with one
+ added and one removed.
+ * javax/swing/text/GlyphView.java
+ (DefaultGlyphPainter.viewToModel): Need to add the start offset.
+ * javax/swing/text/ParagraphView.java
+ (Row.getAlignment): Adjust alignment with respect to
+ the justification attribute.
+ (Row.getLeftInset): Overridden to adjust for firstLineIndent
+ attribute.
+ * javax/swing/text/html/CSS.java
+ (getValue): Convert length values.
+ * javax/swing/text/html/Paragraph.java
+ (painter): New field.
+ (paint): Implemented to delegate painting to the BoxPainter too.
+ (setPropertiesFromAttributes): Implemented to load attributes
+ from CSS.
+ * javax/swing/text/html/StyleSheet.java
+ (BoxPainter.as): Removed field.
+ (BoxPainter.leftInset): New field.
+ (BoxPainter.bottomInset): New field.
+ (BoxPainter.rightInset): New field.
+ (BoxPainter.topInset): New field.
+ (BoxPainter.BoxPainter): Implemented to load the insets from
+ CSS.
+ (BoxPainter.getInset): Implemented.
+ * gnu/javax/swing/text/html/Length.java: New class.
+ Converts CSS length units to usable values.
+
2006-08-31 Andreas Tobler <a.tobler@schweiz.ch>
* configure.ac: Add check for gethostbyname_r.
diff --git a/gnu/javax/swing/text/html/css/Length.java b/gnu/javax/swing/text/html/css/Length.java
new file mode 100644
index 000000000..7091fbae7
--- /dev/null
+++ b/gnu/javax/swing/text/html/css/Length.java
@@ -0,0 +1,90 @@
+/* Length.java -- Converts CSS length values
+ 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;
+
+/**
+ * Converts CSS length values to usable length values.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class Length
+{
+
+ /**
+ * The original value.
+ */
+ private String value;
+
+ /**
+ * The converted value.
+ */
+ private float floatValue;
+
+ /**
+ * Creates a new length converter instance.
+ *
+ * @param val the CSS value
+ */
+ public Length(String val)
+ {
+ value = val;
+ int i = value.indexOf("px");
+ floatValue = 0.0F;
+ if (i != -1)
+ {
+ String sub = value.substring(0, i);
+ floatValue = Float.parseFloat(sub);
+ }
+ else
+ {
+ // TODO: Implement other length options.
+ floatValue = Float.parseFloat(value);
+ }
+ }
+
+ /**
+ * Returns the value converted to pixels.
+ *
+ * @return the value converted to pixels
+ */
+ public float getValue()
+ {
+ return floatValue;
+ }
+}
diff --git a/javax/swing/text/BoxView.java b/javax/swing/text/BoxView.java
index dc1cdfda8..962d06219 100644
--- a/javax/swing/text/BoxView.java
+++ b/javax/swing/text/BoxView.java
@@ -910,7 +910,9 @@ public class BoxView
*/
public int getWidth()
{
- return span[X_AXIS] + getLeftInset() - getRightInset();
+ // The RI returns the following here, however, I'd think that is a bug.
+ // return span[X_AXIS] + getLeftInset() - getRightInset();
+ return span[X_AXIS] + getLeftInset() + getRightInset();
}
/**
@@ -920,7 +922,9 @@ public class BoxView
*/
public int getHeight()
{
- return span[Y_AXIS] + getTopInset() - getBottomInset();
+ // The RI returns the following here, however, I'd think that is a bug.
+ // return span[Y_AXIS] + getTopInset() - getBottomInset();
+ return span[Y_AXIS] + getTopInset() + getBottomInset();
}
/**
diff --git a/javax/swing/text/GlyphView.java b/javax/swing/text/GlyphView.java
index 749d533ad..385f50bf6 100644
--- a/javax/swing/text/GlyphView.java
+++ b/javax/swing/text/GlyphView.java
@@ -455,7 +455,7 @@ public class GlyphView extends View implements TabableView, Cloneable
{
Rectangle b = a.getBounds();
int pos = getBoundedPosition(v, v.getStartOffset(), b.x, x - b.x);
- return pos;
+ return pos + v.getStartOffset();
}
}
diff --git a/javax/swing/text/ParagraphView.java b/javax/swing/text/ParagraphView.java
index d2ce1e1ae..b0b4b246e 100644
--- a/javax/swing/text/ParagraphView.java
+++ b/javax/swing/text/ParagraphView.java
@@ -65,11 +65,39 @@ public class ParagraphView extends FlowView implements TabExpander
super(el, X_AXIS);
}
+ /**
+ * Overridden to adjust when we are the first line, and firstLineIndent
+ * is not 0.
+ */
+ public short getLeftInset()
+ {
+ short leftInset = super.getLeftInset();
+ View parent = getParent();
+ if (parent != null)
+ {
+ if (parent.getView(0) == this)
+ leftInset += firstLineIndent;
+ }
+ return leftInset;
+ }
+
public float getAlignment(int axis)
{
float align;
if (axis == X_AXIS)
- align = 0.0F; // TODO: Implement according to justification
+ switch (justification)
+ {
+ case StyleConstants.ALIGN_RIGHT:
+ align = 1.0F;
+ break;
+ case StyleConstants.ALIGN_CENTER:
+ case StyleConstants.ALIGN_JUSTIFIED:
+ align = 0.5F;
+ break;
+ case StyleConstants.ALIGN_LEFT:
+ default:
+ align = 0.0F;
+ }
else
align = super.getAlignment(axis);
return align;
diff --git a/javax/swing/text/html/CSS.java b/javax/swing/text/html/CSS.java
index b11ed7b3f..20a2debbc 100644
--- a/javax/swing/text/html/CSS.java
+++ b/javax/swing/text/html/CSS.java
@@ -41,6 +41,7 @@ import gnu.javax.swing.text.html.css.CSSColor;
import gnu.javax.swing.text.html.css.FontSize;
import gnu.javax.swing.text.html.css.FontStyle;
import gnu.javax.swing.text.html.css.FontWeight;
+import gnu.javax.swing.text.html.css.Length;
import java.io.Serializable;
import java.util.HashMap;
@@ -485,6 +486,10 @@ public class CSS implements Serializable
o = new FontStyle(v);
else if (att == Attribute.COLOR || att == Attribute.BACKGROUND_COLOR)
o = new CSSColor(v);
+ else if (att == Attribute.MARGIN || att == Attribute.MARGIN_BOTTOM
+ || att == Attribute.MARGIN_LEFT || att == Attribute.MARGIN_RIGHT
+ || att == Attribute.MARGIN_TOP)
+ o = new Length(v);
else
o = v;
return o;
diff --git a/javax/swing/text/html/ParagraphView.java b/javax/swing/text/html/ParagraphView.java
index 043265db7..951f70b60 100644
--- a/javax/swing/text/html/ParagraphView.java
+++ b/javax/swing/text/html/ParagraphView.java
@@ -39,12 +39,14 @@ exception statement from your version. */
package javax.swing.text.html;
import java.awt.Graphics;
+import java.awt.Rectangle;
import java.awt.Shape;
import javax.swing.SizeRequirements;
import javax.swing.text.AttributeSet;
import javax.swing.text.Document;
import javax.swing.text.Element;
+import javax.swing.text.StyleConstants;
import javax.swing.text.View;
/**
@@ -55,7 +57,7 @@ import javax.swing.text.View;
* @author Roman Kennke (kennke@aicas.com)
*/
public class ParagraphView
- extends javax.swing.text.ParagraphView
+ extends javax.swing.text.ParagraphView
{
/**
@@ -64,6 +66,11 @@ public class ParagraphView
private AttributeSet attributes;
/**
+ * The stylesheet's box painter.
+ */
+ private StyleSheet.BoxPainter painter;
+
+ /**
* Creates a new ParagraphView for the specified element.
*
* @param element the element
@@ -106,7 +113,32 @@ public class ParagraphView
*/
protected void setPropertiesFromAttributes()
{
- // FIXME: Implement this.
+ super.setPropertiesFromAttributes();
+
+ // Fetch CSS attributes.
+ AttributeSet atts = getAttributes();
+ Object o = atts.getAttribute(CSS.Attribute.TEXT_ALIGN);
+ if (o != null)
+ {
+ String align = o.toString();
+ if (align.equals("left"))
+ setJustification(StyleConstants.ALIGN_LEFT);
+ else if (align.equals("right"))
+ setJustification(StyleConstants.ALIGN_RIGHT);
+ else if (align.equals("center"))
+ setJustification(StyleConstants.ALIGN_CENTER);
+ else if (align.equals("justify"))
+ setJustification(StyleConstants.ALIGN_JUSTIFIED);
+ }
+
+ // Fetch StyleSheet's box painter.
+ painter = getStyleSheet().getBoxPainter(atts);
+ setInsets((short) painter.getInset(TOP, this),
+ (short) painter.getInset(LEFT, this),
+ (short) painter.getInset(BOTTOM, this),
+ (short) painter.getInset(RIGHT, this));
+
+ // TODO: Handle CSS width and height attributes somehow.
}
/**
@@ -155,15 +187,20 @@ public class ParagraphView
}
/**
- * Paints this view. This delegates to the superclass after the coordinates
- * have been updated for tab calculations.
+ * Paints this view. This paints the box using the stylesheet's
+ * box painter for this view and delegates to the super class paint()
+ * afterwards.
*
* @param g the graphics object
* @param a the current allocation of this view
*/
public void paint(Graphics g, Shape a)
{
- // FIXME: Implement the above specified behaviour.
+ if (a != null)
+ {
+ Rectangle r = a instanceof Rectangle ? (Rectangle) a : a.getBounds();
+ painter.paint(g, r.x, r.y, r.width, r.height, this);
+ }
super.paint(g, a);
}
diff --git a/javax/swing/text/html/StyleSheet.java b/javax/swing/text/html/StyleSheet.java
index 5ae737d68..c21fc064a 100644
--- a/javax/swing/text/html/StyleSheet.java
+++ b/javax/swing/text/html/StyleSheet.java
@@ -45,6 +45,7 @@ import gnu.javax.swing.text.html.css.CSSParserCallback;
import gnu.javax.swing.text.html.css.FontSize;
import gnu.javax.swing.text.html.css.FontStyle;
import gnu.javax.swing.text.html.css.FontWeight;
+import gnu.javax.swing.text.html.css.Length;
import java.awt.Color;
import java.awt.Font;
@@ -905,12 +906,12 @@ public class StyleSheet extends StyleContext
*/
public static class BoxPainter extends Object implements Serializable
{
-
- /**
- * Attribute set for painter
- */
- AttributeSet as;
-
+
+ private float leftInset;
+ private float rightInset;
+ private float topInset;
+ private float bottomInset;
+
/**
* Package-private constructor.
*
@@ -918,9 +919,21 @@ public class StyleSheet extends StyleContext
*/
BoxPainter(AttributeSet as)
{
- this.as = as;
+ Length l = (Length) as.getAttribute(CSS.Attribute.MARGIN_LEFT);
+ if (l != null)
+ leftInset = l.getValue();
+ l = (Length) as.getAttribute(CSS.Attribute.MARGIN_RIGHT);
+ if (l != null)
+ rightInset = l.getValue();
+ l = (Length) as.getAttribute(CSS.Attribute.MARGIN_TOP);
+ if (l != null)
+ topInset = l.getValue();
+ l = (Length) as.getAttribute(CSS.Attribute.MARGIN_BOTTOM);
+ if (l != null)
+ bottomInset = l.getValue();
}
+
/**
* Gets the inset needed on a given side to account for the margin, border
* and padding.
@@ -934,8 +947,25 @@ public class StyleSheet extends StyleContext
*/
public float getInset(int size, View v)
{
- // FIXME: Not implemented.
- return 0;
+ float inset;
+ switch (size)
+ {
+ case View.TOP:
+ inset = topInset;
+ break;
+ case View.BOTTOM:
+ inset = bottomInset;
+ break;
+ case View.LEFT:
+ inset = leftInset;
+ break;
+ case View.RIGHT:
+ inset = rightInset;
+ break;
+ default:
+ inset = 0.0F;
+ }
+ return inset;
}
/**