diff options
author | Roman Kennke <roman@kennke.org> | 2006-11-07 15:16:40 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-11-07 15:16:40 +0000 |
commit | 19b7da4d35e451e8d6c3b5682ff121b829d1a8da (patch) | |
tree | 9fa15ef1c16211f237551ce33a15629743bfaff0 /javax | |
parent | 4c6d0ec7ff1e6ff696e386ea0d3d261addf895f1 (diff) | |
download | classpath-19b7da4d35e451e8d6c3b5682ff121b829d1a8da.tar.gz |
2006-11-07 Roman Kennke <kennke@aicas.com>
* javax/swing/text/html/HTMLEditorKit.java
(HTMLFactory.create): Include ListView.
* javax/swing/text/html/ListView.java
(paint): Removed comment.
* javax/swing/text/html/StyleSheet.java
(CSSStyle.priority): New field.
(CSSStyle.CSSStyle(int)): New constructor with priority.
(CSSStyle.compareTo): New method. Used for sorting the styles.
(CSSStyleSheetParserCallback.declaration): Store the style
with the complete selector.
(ListPainter.attributes): Renamed as field.
(ListPainter.styleSheet): New field.
(ListPainter.type): New field.
(ListPainter.ListPainter): Pass StyleSheet to constructor.
(ListPainter.paint): Provide simplistic implementation.
(getListPainter): Pass StyleSheet to constructor.
(resolveStyle): Fixed CSS style resolving.
Diffstat (limited to 'javax')
-rw-r--r-- | javax/swing/text/html/HTMLEditorKit.java | 4 | ||||
-rw-r--r-- | javax/swing/text/html/ListView.java | 3 | ||||
-rw-r--r-- | javax/swing/text/html/StyleSheet.java | 106 |
3 files changed, 81 insertions, 32 deletions
diff --git a/javax/swing/text/html/HTMLEditorKit.java b/javax/swing/text/html/HTMLEditorKit.java index d4bfbbce5..db31b55e2 100644 --- a/javax/swing/text/html/HTMLEditorKit.java +++ b/javax/swing/text/html/HTMLEditorKit.java @@ -646,7 +646,6 @@ public class HTMLEditorKit else if (tag.equals(HTML.Tag.IMG)) view = new ImageView(element); - // FIXME: Uncomment when the views have been implemented else if (tag.equals(HTML.Tag.CONTENT)) view = new InlineView(element); else if (tag == HTML.Tag.HEAD) @@ -663,10 +662,11 @@ public class HTMLEditorKit || tag.equals(HTML.Tag.TEXTAREA)) view = new FormView(element); - /* else if (tag.equals(HTML.Tag.MENU) || tag.equals(HTML.Tag.DIR) || tag.equals(HTML.Tag.UL) || tag.equals(HTML.Tag.OL)) view = new ListView(element); + // FIXME: Uncomment when the views have been implemented + /* else if (tag.equals(HTML.Tag.OBJECT)) view = new ObjectView(element); else if (tag.equals(HTML.Tag.FRAMESET)) diff --git a/javax/swing/text/html/ListView.java b/javax/swing/text/html/ListView.java index c07d3598c..3e809bbd2 100644 --- a/javax/swing/text/html/ListView.java +++ b/javax/swing/text/html/ListView.java @@ -94,9 +94,6 @@ public class ListView public void paint(Graphics g, Shape allocation) { super.paint(g, allocation); - // FIXME: Why is this overridden? I think that painting would be done - // by the superclass and the stylesheet... Maybe find out when this - // stuff is implemented properly. } /** diff --git a/javax/swing/text/html/StyleSheet.java b/javax/swing/text/html/StyleSheet.java index 85b93510c..bb51f022e 100644 --- a/javax/swing/text/html/StyleSheet.java +++ b/javax/swing/text/html/StyleSheet.java @@ -55,9 +55,12 @@ import java.io.Serializable; import java.io.StringReader; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.StringTokenizer; import javax.swing.border.BevelBorder; @@ -89,7 +92,7 @@ import javax.swing.text.View; * * The rules are stored as named styles, and other information is stored to * translate the context of an element to a rule. - * + * * @author Lillian Angel (langel@redhat.com) */ public class StyleSheet extends StyleContext @@ -137,21 +140,16 @@ public class StyleSheet extends StyleContext */ public void declaration(String property, String value) { - for (int i = 0; i < selector.length; i++) + CSSStyle style = (CSSStyle) css.get(selector); + if (style == null) { - CSSStyle style = (CSSStyle) css.get(selector[i]); - if (style == null) - { - style = new CSSStyle(); - css.put(selector[i], style); - } - CSS.Attribute cssAtt = CSS.getAttribute(property); - Object val = CSS.getValue(cssAtt, value); - if (cssAtt != null) - style.addAttribute(cssAtt, val); - // else // For debugging only. - // System.err.println("no mapping for: " + property); + style = new CSSStyle(selector.length); + css.put(selector, style); } + CSS.Attribute cssAtt = CSS.getAttribute(property); + Object val = CSS.getValue(cssAtt, value); + if (cssAtt != null) + style.addAttribute(cssAtt, val); } } @@ -161,9 +159,19 @@ public class StyleSheet extends StyleContext */ private class CSSStyle extends SimpleAttributeSet - implements Style + implements Style, Comparable { + /** + * The priority of this style when matching CSS selectors. + */ + int priority; + + CSSStyle(int prio) + { + priority = prio; + } + public String getName() { // TODO: Implement this for correctness. @@ -179,6 +187,12 @@ public class StyleSheet extends StyleContext { // TODO: Implement this for correctness. } + + public int compareTo(Object o) + { + CSSStyle other = (CSSStyle) o; + return other.priority - priority; + } } @@ -374,14 +388,28 @@ public class StyleSheet extends StyleContext // the default.css. int count = tags.length; ArrayList styles = new ArrayList(); - for (int i = 0; i < count; i++) + Set selectors = css.keySet(); + for (Iterator i = selectors.iterator(); i.hasNext();) { - Style style = (Style) css.get(tags[i]); - if (style != null) - styles.add(style); - // FIXME: Handle ID and CLASS attributes. + String[] sel = (String[]) i.next(); + // All parts of the selector must match. + if (sel.length <= tags.length) + { + boolean match = true; + for (int j = sel.length - 1; j >= 0 && match; j--) + { + if (! tags[sel.length - 1 - j].equals(sel[j])) + match = false; + } + if (match) + styles.add(css.get(sel)); + } } + + // Sort selectors. + Collections.sort(styles); Style[] styleArray = new Style[styles.size()]; + styleArray = (Style[]) styles.toArray(styleArray); Style resolved = new MultiStyle(selector, (Style[]) styles.toArray(styleArray)); resolvedStyles.put(selector, resolved); @@ -816,7 +844,7 @@ public class StyleSheet extends StyleContext */ public ListPainter getListPainter(AttributeSet a) { - return new ListPainter(a); + return new ListPainter(a, this); } /** @@ -1063,18 +1091,30 @@ public class StyleSheet extends StyleContext /** * Attribute set for painter */ - AttributeSet as; - + private AttributeSet attributes; + + /** + * The associated style sheet. + */ + private StyleSheet styleSheet; + + /** + * The bullet type. + */ + private String type; + /** * Package-private constructor. * * @param as - AttributeSet for painter */ - ListPainter(AttributeSet as) + ListPainter(AttributeSet as, StyleSheet ss) { - this.as = as; + attributes = as; + styleSheet = ss; + type = (String) as.getAttribute(CSS.Attribute.LIST_STYLE_TYPE); } - + /** * Paints the CSS list decoration according to the attributes given. * @@ -1089,7 +1129,19 @@ public class StyleSheet extends StyleContext public void paint(Graphics g, float x, float y, float w, float h, View v, int item) { - // FIXME: Not implemented. + // FIXME: This is a very simplistic list rendering. We still need + // to implement different bullet types (see type field) and custom + // bullets via images. + View itemView = v.getView(item); + AttributeSet viewAtts = itemView.getAttributes(); + Object tag = viewAtts.getAttribute(StyleConstants.NameAttribute); + // Only paint something here when the child view is an LI tag + // and the calling view is some of the list tags then). + if (tag != null && tag == HTML.Tag.LI) + { + g.setColor(Color.BLACK); + g.fillOval((int) x - 15, (int) (h / 2 - 3 + y), 6, 6); + } } } |