Some more fixes for table layout, and some minor fixes for CSS. These
allowed me to make this beautiful screenshot:
http://kennke.org/~roman/japi.png
Which is kinda nice, because the japi pages do quite a couple of table
and CSS 'tricks'. Note however that you won't be able to view this right
now due to a nasty bug in the html parser code (which I worked around
locally but can't commit).
2006-11-14 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/text/html/ImageView.java
(getPreferredSpan): Use CSS length values.
* javax/swing/text/html/TableView.java
(CellView.calculateMajorAxisRequirements): Overridden to
set the maximum reqs to maximum.
(RowView.getMaximumSize): For the X_AXIS, set the maximum
span to maximum.
(RowView.getMinimumSpan): Overridden. For the X_AXIS, return
the total column reqs.
(RowView.getPreferredSpan): Overridden. For the X_AXIS, return
the total column reqs.
* gnu/javax/swing/text/html/css/CSSColor.java
(convertValue): Catch NumberFormatExceptions for more
robustness.
* gnu/javax/swing/text/html/css/FontSize.java
(mapPixels): Actually map px values. Catch NFE for more
robustness.
/Roman
Index: javax/swing/text/html/TableView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/TableView.java,v
retrieving revision 1.5
diff -u -1 -5 -r1.5 TableView.java
--- javax/swing/text/html/TableView.java 11 Nov 2006 11:02:07 -0000 1.5
+++ javax/swing/text/html/TableView.java 14 Nov 2006 20:53:05 -0000
@@ -72,31 +72,51 @@
*/
RowView(Element el)
{
super(el, X_AXIS);
}
/**
* Overridden to make rows not resizable along the Y axis.
*/
public float getMaximumSpan(int axis)
{
float span;
if (axis == Y_AXIS)
span = super.getPreferredSpan(axis);
else
- span = super.getMaximumSpan(axis);
+ span = Integer.MAX_VALUE;
+ return span;
+ }
+
+ public float getMinimumSpan(int axis)
+ {
+ float span;
+ if (axis == X_AXIS)
+ span = totalColumnRequirements.minimum;
+ else
+ span = super.getMinimumSpan(axis);
+ return span;
+ }
+
+ public float getPreferredSpan(int axis)
+ {
+ float span;
+ if (axis == X_AXIS)
+ span = totalColumnRequirements.preferred;
+ else
+ span = super.getPreferredSpan(axis);
return span;
}
/**
* Calculates the overall size requirements for the row along the
* major axis. This will be the sum of the column requirements.
*/
protected SizeRequirements calculateMajorAxisRequirements(int axis,
SizeRequirements r)
{
if (r == null)
r = new SizeRequirements();
r.minimum = totalColumnRequirements.minimum;
r.preferred = totalColumnRequirements.preferred;
r.maximum = totalColumnRequirements.maximum;
@@ -139,30 +159,38 @@
/**
* The number of columns that this view spans.
*/
int colSpan;
/**
* Creates a new CellView for the specified element.
*
* @param el the element for which to create the colspan
*/
CellView(Element el)
{
super(el, Y_AXIS);
}
+ protected SizeRequirements calculateMajorAxisRequirements(int axis,
+ SizeRequirements r)
+ {
+ r = super.calculateMajorAxisRequirements(axis, r);
+ r.maximum = Integer.MAX_VALUE;
+ return r;
+ }
+
/**
* Overridden to fetch the columnSpan attibute.
*/
protected void setPropertiesFromAttributes()
{
super.setPropertiesFromAttributes();
colSpan = 1;
AttributeSet atts = getAttributes();
Object o = atts.getAttribute(HTML.Attribute.COLSPAN);
if (o != null)
{
try
{
colSpan = Integer.parseInt(o.toString());
}
Index: javax/swing/text/html/ImageView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/ImageView.java,v
retrieving revision 1.2
diff -u -1 -5 -r1.2 ImageView.java
--- javax/swing/text/html/ImageView.java 2 Nov 2006 14:04:33 -0000 1.2
+++ javax/swing/text/html/ImageView.java 14 Nov 2006 20:53:05 -0000
@@ -1,19 +1,20 @@
package javax.swing.text.html;
import gnu.javax.swing.text.html.CombinedAttributes;
import gnu.javax.swing.text.html.ImageViewIconFactory;
+import gnu.javax.swing.text.html.css.Length;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Rectangle;
import java.awt.Shape;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Element;
@@ -233,43 +234,43 @@
* loaded, the image size is returned. If there are no attributes, and the
* image is not loaded, zero is returned.
*
* @param axis -
* either X_AXIS or Y_AXIS
* @return either width of height of the image, depending on the axis.
*/
public float getPreferredSpan(int axis)
{
AttributeSet attrs = getAttributes();
Image image = getImage();
if (axis == View.X_AXIS)
{
- Object w = attrs.getAttribute(Attribute.WIDTH);
- if (w != null)
- return Integer.parseInt(w.toString());
+ Object w = attrs.getAttribute(CSS.Attribute.WIDTH);
+ if (w instanceof Length)
+ return ((Length) w).getValue();
else if (image != null)
return image.getWidth(getContainer());
else
return getNoImageIcon().getIconWidth();
}
else if (axis == View.Y_AXIS)
{
- Object w = attrs.getAttribute(Attribute.HEIGHT);
- if (w != null)
- return Integer.parseInt(w.toString());
+ Object w = attrs.getAttribute(CSS.Attribute.HEIGHT);
+ if (w instanceof Length)
+ return ((Length) w).getValue();
else if (image != null)
return image.getHeight(getContainer());
else
return getNoImageIcon().getIconHeight();
}
else
throw new IllegalArgumentException("axis " + axis);
}
/**
* Get the associated style sheet from the document.
*
* @return the associated style sheet.
*/
protected StyleSheet getStyleSheet()
@@ -427,18 +428,17 @@
throws BadLocationException
{
return area;
}
/**
* Starts loading the image asynchronuosly. If the image must be loaded
* synchronuosly instead, the [EMAIL PROTECTED] #setLoadsSynchronously} must be
* called before calling this method. The passed parameters are not used.
*/
public void setSize(float width, float height)
{
if (imageIcon == null)
reloadImage(false);
}
-
}
Index: gnu/javax/swing/text/html/css/CSSColor.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/swing/text/html/css/CSSColor.java,v
retrieving revision 1.2
diff -u -1 -5 -r1.2 CSSColor.java
--- gnu/javax/swing/text/html/css/CSSColor.java 11 Nov 2006 11:02:08 -0000 1.2
+++ gnu/javax/swing/text/html/css/CSSColor.java 14 Nov 2006 20:53:05 -0000
@@ -98,33 +98,40 @@
/**
* Converts a CSS color value to an AWT color.
*
* @param value the CSS color value
*
* @return the converted color value
*/
public static Color convertValue(String value)
{
Color color;
String val1 = value.toLowerCase();
if (val1.charAt(0) != '#')
val1 = (String) COLOR_MAP.get(val1);
if (val1 != null)
{
- String hexVal = val1.substring(1);
- int rgb = Integer.parseInt(hexVal, 16);
- color = new Color(rgb);
+ String hexVal = val1.substring(1).trim();
+ try
+ {
+ int rgb = Integer.parseInt(hexVal, 16);
+ color = new Color(rgb);
+ }
+ catch (NumberFormatException ex)
+ {
+ color = Color.BLACK;
+ }
}
else
color = null;
return color;
}
/**
* Returns the converted color.
*
* @return the converted color
*/
public Color getValue()
{
return color;
}
Index: gnu/javax/swing/text/html/css/FontSize.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/swing/text/html/css/FontSize.java,v
retrieving revision 1.1
diff -u -1 -5 -r1.1 FontSize.java
--- gnu/javax/swing/text/html/css/FontSize.java 24 Aug 2006 16:03:33 -0000 1.1
+++ gnu/javax/swing/text/html/css/FontSize.java 14 Nov 2006 20:53:05 -0000
@@ -99,34 +99,43 @@
private int mapPoints()
{
int end = value.indexOf("pt");
String number = value.substring(0, end);
int intVal = Integer.parseInt(number);
return intVal;
}
/**
* Maps pixel values ('XXXpx').
*
* @return the real font size
*/
private int mapPixels()
{
- int end = value.indexOf("pt");
+ int end = value.indexOf("px");
+ if (end == -1)
+ end = value.length();
String number = value.substring(0, end);
- int intVal = Integer.parseInt(number);
- return intVal;
+ try
+ {
+ int intVal = Integer.parseInt(number);
+ return intVal;
+ }
+ catch (NumberFormatException ex)
+ {
+ return DEFAULT_FONT_SIZE;
+ }
}
/**
* Maps absolute font-size values.
*
* @return the real value
*/
private int mapAbsolute()
{
int index;
if (value.equals("xx-small") || value.equals("x-small"))
index = 0;
else if (value.equals("small"))
index = 1;
else if (value.equals("medium"))