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/24 09:25:40 UTC
svn commit: r569277 - in
/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html:
HTMLDocument.java ImageView.java
Author: apetrenko
Date: Fri Aug 24 00:25:39 2007
New Revision: 569277
URL: http://svn.apache.org/viewvc?rev=569277&view=rev
Log:
Patch for HARMONY-4575 "[classlib][swing][html] Images in links are not working properly"
Modified:
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTMLDocument.java
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/HTMLDocument.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTMLDocument.java?rev=569277&r1=569276&r2=569277&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTMLDocument.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTMLDocument.java Fri Aug 24 00:25:39 2007
@@ -95,6 +95,9 @@
}
public class HTMLReader extends HTMLEditorKit.ParserCallback {
+
+ private boolean anchorReferenceEncountered = false;
+
public class TagAction {
public void start(final Tag tag, final MutableAttributeSet attr) {
}
@@ -362,6 +365,7 @@
class AnchorAction extends CharacterAction {
public void start(final Tag tag, final MutableAttributeSet attr) {
+ anchorReferenceEncountered = attr.isDefined(HTML.Attribute.HREF);
super.start(tag, attr);
openedBlocks.add(Tag.A);
}
@@ -371,6 +375,7 @@
// been removed
super.end(tag);
openedBlocks.remove(Tag.A);
+ anchorReferenceEncountered = false;
}
}
@@ -432,6 +437,20 @@
}
}
+ class ImageAction extends SpecialAction {
+
+ @Override
+ public void start(Tag tag, MutableAttributeSet attr) {
+
+ if (anchorReferenceEncountered) {
+
+ attr.addAttributes(charAttr.copyAttributes());
+ }
+
+ super.start(tag, attr);
+ }
+ }
+
class BaseAction extends TagAction {
public void start(final Tag tag, final MutableAttributeSet attr) {
checkInsertTag(tag);
@@ -975,7 +994,7 @@
tagActionMap.put(Tag.HTML, blockAction);
tagActionMap.put(Tag.I, advancedCharacterAction);
tagActionMap.put(Tag.IFRAME, hiddenAction);
- tagActionMap.put(Tag.IMG, specialAction);
+ tagActionMap.put(Tag.IMG, new ImageAction());
tagActionMap.put(Tag.INPUT, formAction);
tagActionMap.put(Tag.INS, characterAction);
tagActionMap.put(Tag.ISINDEX, new IsindexAction());
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?rev=569277&r1=569276&r2=569277&view=diff
==============================================================================
--- 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 Fri Aug 24 00:25:39 2007
@@ -42,10 +42,12 @@
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.Position.Bias;
+import javax.swing.text.html.CSS.ColorProperty;
import org.apache.harmony.x.swing.text.html.HTMLIconFactory;
public class ImageView extends View {
+
private AttributeSet attrs;
private BackgroundImageLoader loader;
@@ -58,11 +60,18 @@
private int border;
private int vSpace;
private int hSpace;
+
+ /** Not-found-property marker: Any negative number */
+ private final int INT_PROPERTY_NOT_FOUND = -1;
public ImageView(final Element element) {
super(element);
if (element != null) { // Fix for HARMONY-1747, for compatibility with RI
setPropertiesFromAttributes();
+ if (element.getAttributes().getAttribute(HTML.Tag.A) != null) {
+ setAnchorViewAttributes();
+ }
+ adjustBordersAndSpaces();
}
}
@@ -148,12 +157,14 @@
}
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 (border > 0) {
+ 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()) {
@@ -265,6 +276,10 @@
color = getStyleSheet().getForeground(getAttributes());
}
+ /**
+ * Converts attribute value to number, correctly interprets by this view
+ * (i.e. null->negative number)
+ */
private int getIntProperty(AttributeSet source, HTML.Attribute attr) {
String result = (String) source.getAttribute(attr);
// Null verification is added for possibly improved performance:
@@ -274,10 +289,10 @@
try {
return Integer.parseInt(result);
} catch (NumberFormatException nfe) {
- // Ignored, return 0, according to RI's result
+ // Ignored, according to RI's result
}
}
- return 0;
+ return INT_PROPERTY_NOT_FOUND;
}
private void createImage(final int desiredWidth, final int desiredHeight) {
@@ -303,5 +318,33 @@
}
}
};
+ }
+
+ /**
+ * The method sets the 1px border (if the border is absent) and sets the
+ * color stated for <a> tag
+ */
+ private void setAnchorViewAttributes() {
+ if (border < 0) {
+ border = 1;
+ }
+ color = ((ColorProperty) getStyleSheet().getRule("a").getAttribute(
+ CSS.Attribute.COLOR)).getColor();
+ }
+
+ /**
+ * Sets negative properties to zero ones (negative property can either
+ * directly stated or returned by getIntProperty method)
+ */
+ private void adjustBordersAndSpaces() {
+ if (vSpace < 0) {
+ vSpace = 0;
+ }
+ if (hSpace < 0) {
+ hSpace = 0;
+ }
+ if (border < 0) {
+ border = 0;
+ }
}
}