You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ap...@apache.org on 2007/08/08 15:40:49 UTC
svn commit: r563878 -
/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java
Author: apetrenko
Date: Wed Aug 8 06:40:48 2007
New Revision: 563878
URL: http://svn.apache.org/viewvc?view=rev&rev=563878
Log:
Patch for HARMONY-4610 "[classlib][swing][html]Border and spacing attributes processing are unimplemented"
Modified:
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java?view=diff&rev=563878&r1=563877&r2=563878
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java Wed Aug 8 06:40:48 2007
@@ -58,6 +58,10 @@
private boolean synchronous = true;
private Color color;
+
+ private int border;
+ private int vSpace;
+ private int hSpace;
public ImageView(final Element element) {
super(element);
@@ -97,23 +101,24 @@
FontMetrics metrics = null;
if (alt != null) {
Font font = getStyleSheet().getFont(getAttributes());
- metrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
+ metrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
}
-
- return axis == X_AXIS
- ? getNoImageIcon().getIconWidth()
- + (metrics != null ? metrics.stringWidth(alt) : 0)
- : Math.max(getNoImageIcon().getIconHeight(),
- (metrics != null ? metrics.getHeight() : 0));
+
+ return axis == X_AXIS ? getNoImageIcon().getIconWidth()
+ + 2 * border + 2 * hSpace
+ + ((metrics == null) ? 0 : metrics.stringWidth(alt))
+ : ((metrics == null) ? getNoImageIcon().getIconHeight()
+ : Math.max(getNoImageIcon().getIconHeight(),metrics.getHeight())
+ + 2 * border + 2 * vSpace);
}
if (!loader.isReady()) {
- return axis == X_AXIS ? getLoadingImageIcon().getIconWidth()
- : getLoadingImageIcon().getIconHeight();
+ return axis == X_AXIS ? getLoadingImageIcon().getIconWidth()+ 2 * border + 2 * hSpace
+ : getLoadingImageIcon().getIconHeight() + 2 * border + 2 * vSpace;
}
if (axis == X_AXIS) {
- return loader.getWidth();
+ return loader.getWidth() + 2 * border + 2 * hSpace;
}
- return loader.getHeight();
+ return loader.getHeight() + 2 * border + 2 * vSpace;
}
public String getToolTipText(final float x, final float y,
@@ -126,9 +131,13 @@
.getAttribute(HTML.Attribute.ALT);
}
- public void paint(final Graphics g, final Shape shape) {
+public void paint(final Graphics g, final Shape shape) {
+
Rectangle rc = shape.getBounds();
-
+ rc.setSize(rc.width - 2*(hSpace + border), rc.height - 2*(vSpace + border));
+
+
+
// TODO change layered highlight painting code
JTextComponent tc = (JTextComponent)getContainer();
Highlighter hl = tc.getHighlighter();
@@ -138,11 +147,20 @@
getEndOffset(),
shape, tc, this);
}
+
+ Color oldColor = g.getColor();
+ g.setColor(color);
+ g.fillRect(rc.x + hSpace, rc.y + vSpace, rc.width + 2 * border,
+ rc.height + 2 * border);
+ g.setColor(oldColor);
+ g.fillRect(rc.x + hSpace + border, rc.y + vSpace + border, rc.width,
+ rc.height);
if (loader.isError()) {
- getNoImageIcon().paintIcon(null, g, rc.x, rc.y);
- Color oldColor = g.getColor();
+
g.setColor(color);
+
+ getNoImageIcon().paintIcon(null, g, rc.x + hSpace + border, rc.y+vSpace + border);
String alt = getAltText();
if (alt != null) {
@@ -151,12 +169,12 @@
Font font = getStyleSheet().getFont(getAttributes());
g.setFont(font);
FontMetrics metrics = g.getFontMetrics();
- g.drawString(alt, rc.x + getNoImageIcon().getIconWidth(),
- rc.y + metrics.getAscent());
-
+ g.drawString(alt, rc.x + hSpace + border
+ + getNoImageIcon().getIconWidth(), rc.y + vSpace + border+ metrics.getAscent());
+
g.setFont(oldFont);
}
- g.drawRect(rc.x, rc.y, rc.width - 1, rc.height - 1);
+
g.setColor(oldColor);
return;
}
@@ -168,7 +186,7 @@
}
}
- g.drawImage(getImage(), rc.x, rc.y, rc.width, rc.height, loader);
+ g.drawImage(getImage(), rc.x + hSpace + border, rc.y + vSpace + border, rc.width, rc.height, loader);
}
public Shape modelToView(final int pos, final Shape shape, final Bias bias)
@@ -217,8 +235,15 @@
protected void setPropertiesFromAttributes() {
attrs = getStyleSheet().getViewAttributes(this);
- src = (String)getElement().getAttributes()
- .getAttribute(HTML.Attribute.SRC);
+ AttributeSet elAttrs = getElement().getAttributes();
+
+ src = (String) elAttrs.getAttribute(HTML.Attribute.SRC);
+
+ border = getIntProperty(elAttrs,HTML.Attribute.BORDER);
+
+ hSpace = getIntProperty(elAttrs,HTML.Attribute.HSPACE);
+
+ vSpace = getIntProperty(elAttrs,HTML.Attribute.VSPACE);
Object size = getAttributes().getAttribute(CSS.Attribute.WIDTH);
int desiredWidth = -1;
@@ -234,6 +259,21 @@
createImage(desiredWidth, desiredHeight);
color = getStyleSheet().getForeground(getAttributes());
+ }
+
+ private int getIntProperty(AttributeSet source, HTML.Attribute attr) {
+ String result = (String) source.getAttribute(attr);
+ // Null verification is added for possibly improved performance:
+ // throwing and
+ // catching an exception is slower than null verification
+ if (result != null) {
+ try {
+ return Integer.parseInt(result);
+ } catch (NumberFormatException nfe) {
+ // Ignored, return 0, according to RI's result
+ }
+ }
+ return 0;
}
private void createImage(final int desiredWidth, final int desiredHeight) {