1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50:
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73:
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80: import ;
81: import ;
82: import ;
83: import ;
84:
85:
86:
104: public class StyleSheet extends StyleContext
105: {
106:
107:
112: class CSSStyleSheetParserCallback
113: implements CSSParserCallback
114: {
115:
118: private CSSStyle[] styles;
119:
120:
123: private int precedence;
124:
125:
132: CSSStyleSheetParserCallback(int prec)
133: {
134: precedence = prec;
135: }
136:
137:
142: public void startStatement(Selector[] sel)
143: {
144: styles = new CSSStyle[sel.length];
145: for (int i = 0; i < sel.length; i++)
146: styles[i] = new CSSStyle(precedence, sel[i]);
147: }
148:
149:
152: public void endStatement()
153: {
154: for (int i = 0; i < styles.length; i++)
155: css.add(styles[i]);
156: styles = null;
157: }
158:
159:
165: public void declaration(String property, String value)
166: {
167: CSS.Attribute cssAtt = CSS.getAttribute(property);
168: Object val = CSS.getValue(cssAtt, value);
169: for (int i = 0; i < styles.length; i++)
170: {
171: CSSStyle style = styles[i];
172: CSS.addInternal(style, cssAtt, value);
173: if (cssAtt != null)
174: style.addAttribute(cssAtt, val);
175: }
176: }
177:
178: }
179:
180:
183: private class CSSStyle
184: extends SimpleAttributeSet
185: implements Style, Comparable<CSSStyle>
186: {
187:
188: static final int PREC_UA = 0;
189: static final int PREC_NORM = 100000;
190: static final int PREC_AUTHOR_NORMAL = 200000;
191: static final int PREC_AUTHOR_IMPORTANT = 300000;
192: static final int PREC_USER_IMPORTANT = 400000;
193:
194:
197: private int precedence;
198:
199:
204: Selector selector;
205:
206: CSSStyle(int prec, Selector sel)
207: {
208: precedence = prec;
209: selector = sel;
210: }
211:
212: public String getName()
213: {
214:
215: return null;
216: }
217:
218: public void addChangeListener(ChangeListener listener)
219: {
220:
221: }
222:
223: public void removeChangeListener(ChangeListener listener)
224: {
225:
226: }
227:
228:
232: public int compareTo(CSSStyle other)
233: {
234: return other.precedence + other.selector.getSpecificity()
235: - precedence - selector.getSpecificity();
236: }
237:
238: }
239:
240:
241: URL base;
242:
243:
244: int baseFontSize;
245:
246:
249: private ArrayList<StyleSheet> linked;
250:
251:
255: ArrayList<CSSStyle> css = new ArrayList<CSSStyle>();
256:
257:
260: private HashMap<String,Style> resolvedStyles;
261:
262:
265: public StyleSheet()
266: {
267: super();
268: baseFontSize = 4;
269: resolvedStyles = new HashMap<String,Style>();
270: }
271:
272:
281: public Style getRule(HTML.Tag t, Element e)
282: {
283:
284:
285: ArrayList<Element> path = new ArrayList<Element>();
286: Element el;
287: AttributeSet atts;
288: for (el = e; el != null; el = el.getParentElement())
289: path.add(el);
290:
291:
292: StringBuilder selector = new StringBuilder();
293: int count = path.size();
294:
295: for (int i = count - 1; i > 0; i--)
296: {
297: el = path.get(i);
298: atts = el.getAttributes();
299: Object name = atts.getAttribute(StyleConstants.NameAttribute);
300: selector.append(name.toString());
301: if (atts.isDefined(HTML.Attribute.ID))
302: {
303: selector.append('#');
304: selector.append(atts.getAttribute(HTML.Attribute.ID));
305: }
306: if (atts.isDefined(HTML.Attribute.CLASS))
307: {
308: selector.append('.');
309: selector.append(atts.getAttribute(HTML.Attribute.CLASS));
310: }
311: if (atts.isDefined(HTML.Attribute.DYNAMIC_CLASS))
312: {
313: selector.append(':');
314: selector.append(atts.getAttribute(HTML.Attribute.DYNAMIC_CLASS));
315: }
316: if (atts.isDefined(HTML.Attribute.PSEUDO_CLASS))
317: {
318: selector.append(':');
319: selector.append(atts.getAttribute(HTML.Attribute.PSEUDO_CLASS));
320: }
321: selector.append(' ');
322: }
323: selector.append(t.toString());
324: el = path.get(0);
325: atts = el.getAttributes();
326:
327: if (el.isLeaf())
328: {
329: Object o = atts.getAttribute(t);
330: if (o instanceof AttributeSet)
331: atts = (AttributeSet) o;
332: else
333: atts = null;
334: }
335: if (atts != null)
336: {
337: if (atts.isDefined(HTML.Attribute.ID))
338: {
339: selector.append('#');
340: selector.append(atts.getAttribute(HTML.Attribute.ID));
341: }
342: if (atts.isDefined(HTML.Attribute.CLASS))
343: {
344: selector.append('.');
345: selector.append(atts.getAttribute(HTML.Attribute.CLASS));
346: }
347: if (atts.isDefined(HTML.Attribute.DYNAMIC_CLASS))
348: {
349: selector.append(':');
350: selector.append(atts.getAttribute(HTML.Attribute.DYNAMIC_CLASS));
351: }
352: if (atts.isDefined(HTML.Attribute.PSEUDO_CLASS))
353: {
354: selector.append(':');
355: selector.append(atts.getAttribute(HTML.Attribute.PSEUDO_CLASS));
356: }
357: }
358: return getResolvedStyle(selector.toString(), path, t);
359: }
360:
361:
372: private Style getResolvedStyle(String selector, List<Element> path, HTML.Tag tag)
373: {
374: Style style = resolvedStyles.get(selector);
375: if (style == null)
376: style = resolveStyle(selector, path, tag);
377: return style;
378: }
379:
380:
391: private Style resolveStyle(String selector, List<Element> path, HTML.Tag tag)
392: {
393: int count = path.size();
394: String[] tags = new String[count];
395: List<Map<String,String>> attributes =
396: new ArrayList<Map<String,String>>(count);
397: for (int i = 0; i < count; i++)
398: {
399: Element el = path.get(i);
400: AttributeSet atts = el.getAttributes();
401: if (i == 0 && el.isLeaf())
402: {
403: Object o = atts.getAttribute(tag);
404: if (o instanceof AttributeSet)
405: atts = (AttributeSet) o;
406: else
407: atts = null;
408: }
409: if (atts != null)
410: {
411: HTML.Tag t =
412: (HTML.Tag) atts.getAttribute(StyleConstants.NameAttribute);
413: if (t != null)
414: tags[i] = t.toString();
415: else
416: tags[i] = null;
417: attributes.add(attributeSetToMap(atts));
418: }
419: else
420: {
421: tags[i] = null;
422: attributes.add(null);
423: }
424: }
425: tags[0] = tag.toString();
426: return resolveStyle(selector, tags, attributes);
427: }
428:
429:
438: private Style resolveStyle(String selector, String[] tags,
439: List<Map<String,String>> attributes)
440: {
441:
442:
443: ArrayList<CSSStyle> styles = new ArrayList<CSSStyle>();
444: for (CSSStyle style : css)
445: {
446: if (style.selector.matches(tags, attributes))
447: styles.add(style);
448: }
449:
450:
451: if (linked != null)
452: {
453: for (int i = linked.size() - 1; i >= 0; i--)
454: {
455: StyleSheet ss = linked.get(i);
456: for (int j = ss.css.size() - 1; j >= 0; j--)
457: {
458: CSSStyle style = ss.css.get(j);
459: if (style.selector.matches(tags, attributes))
460: styles.add(style);
461: }
462: }
463: }
464:
465:
466: Collections.sort(styles);
467: Style[] styleArray = styles.toArray(new Style[styles.size()]);
468: Style resolved = new MultiStyle(selector, styleArray);
469: resolvedStyles.put(selector, resolved);
470: return resolved;
471: }
472:
473:
481: public Style getRule(String selector)
482: {
483: CSSStyle best = null;
484: for (Iterator<CSSStyle> i = css.iterator(); i.hasNext();)
485: {
486: CSSStyle style = i.next();
487: if (style.compareTo(best) < 0)
488: best = style;
489: }
490: return best;
491: }
492:
493:
499: public void addRule(String rule)
500: {
501: CSSStyleSheetParserCallback cb =
502: new CSSStyleSheetParserCallback(CSSStyle.PREC_AUTHOR_NORMAL);
503:
504: StringReader in = new StringReader(rule);
505: CSSParser parser = new CSSParser(in, cb);
506: try
507: {
508: parser.parse();
509: }
510: catch (IOException ex)
511: {
512:
513: }
514:
515:
516: resolvedStyles.clear();
517: }
518:
519:
526: public AttributeSet getDeclaration(String decl)
527: {
528: if (decl == null)
529: return SimpleAttributeSet.EMPTY;
530:
531: return null;
532: }
533:
534:
544: public void loadRules(Reader in, URL ref)
545: throws IOException
546: {
547: CSSStyleSheetParserCallback cb =
548: new CSSStyleSheetParserCallback(CSSStyle.PREC_UA);
549:
550: CSSParser parser = new CSSParser(in, cb);
551: parser.parse();
552: }
553:
554:
561: public AttributeSet getViewAttributes(View v)
562: {
563: return new ViewAttributeSet(v, this);
564: }
565:
566:
571: public void removeStyle(String nm)
572: {
573:
574: super.removeStyle(nm);
575: }
576:
577:
584: public void addStyleSheet(StyleSheet ss)
585: {
586: if (linked == null)
587: linked = new ArrayList<StyleSheet>();
588: linked.add(ss);
589: }
590:
591:
596: public void removeStyleSheet(StyleSheet ss)
597: {
598: if (linked != null)
599: {
600: linked.remove(ss);
601: }
602: }
603:
604:
609: public StyleSheet[] getStyleSheets()
610: {
611: StyleSheet[] linkedSS;
612: if (linked != null)
613: {
614: linkedSS = new StyleSheet[linked.size()];
615: linkedSS = linked.toArray(linkedSS);
616: }
617: else
618: {
619: linkedSS = null;
620: }
621: return linkedSS;
622: }
623:
624:
631: public void importStyleSheet(URL url)
632: {
633: try
634: {
635: InputStream in = url.openStream();
636: Reader r = new BufferedReader(new InputStreamReader(in));
637: CSSStyleSheetParserCallback cb =
638: new CSSStyleSheetParserCallback(CSSStyle.PREC_AUTHOR_NORMAL);
639: CSSParser parser = new CSSParser(r, cb);
640: parser.parse();
641: }
642: catch (IOException ex)
643: {
644:
645: }
646: }
647:
648:
655: public void setBase(URL base)
656: {
657: this.base = base;
658: }
659:
660:
665: public URL getBase()
666: {
667: return base;
668: }
669:
670:
677: public void addCSSAttribute(MutableAttributeSet attr, CSS.Attribute key,
678: String value)
679: {
680: Object val = CSS.getValue(key, value);
681: CSS.addInternal(attr, key, value);
682: attr.addAttribute(key, val);
683: }
684:
685:
696: public boolean addCSSAttributeFromHTML(MutableAttributeSet attr, CSS.Attribute key,
697: String value)
698: {
699:
700: attr.addAttribute(key, value);
701: return attr.containsAttribute(key, value);
702: }
703:
704:
710: public AttributeSet translateHTMLToCSS(AttributeSet htmlAttrSet)
711: {
712: AttributeSet cssAttr = htmlAttrSet.copyAttributes();
713:
714:
715: Object o = htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);
716: if (o != null)
717: cssAttr = addAttribute(cssAttr, CSS.Attribute.TEXT_ALIGN, o);
718:
719:
720: o = htmlAttrSet.getAttribute(HTML.Attribute.WIDTH);
721: if (o != null)
722: cssAttr = addAttribute(cssAttr, CSS.Attribute.WIDTH,
723: new Length(o.toString()));
724:
725:
726: o = htmlAttrSet.getAttribute(HTML.Attribute.HEIGHT);
727: if (o != null)
728: cssAttr = addAttribute(cssAttr, CSS.Attribute.HEIGHT,
729: new Length(o.toString()));
730:
731: o = htmlAttrSet.getAttribute(HTML.Attribute.NOWRAP);
732: if (o != null)
733: cssAttr = addAttribute(cssAttr, CSS.Attribute.WHITE_SPACE, "nowrap");
734:
735:
736: o = htmlAttrSet.getAttribute(HTML.Attribute.CELLSPACING);
737: if (o != null)
738: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_SPACING,
739: new Length(o.toString()));
740:
741:
742:
743: HTML.Tag tag = (HTML.Tag)
744: htmlAttrSet.getAttribute(StyleConstants.NameAttribute);
745: if ((tag == HTML.Tag.TD || tag == HTML.Tag.TH)
746: && htmlAttrSet instanceof Element)
747: {
748: Element el = (Element) htmlAttrSet;
749: AttributeSet tableAttrs = el.getParentElement().getParentElement()
750: .getAttributes();
751: o = tableAttrs.getAttribute(HTML.Attribute.CELLPADDING);
752: if (o != null)
753: {
754: Length l = new Length(o.toString());
755: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_BOTTOM, l);
756: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_LEFT, l);
757: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_RIGHT, l);
758: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_TOP, l);
759: }
760: o = tableAttrs.getAttribute(HTML.Attribute.BORDER);
761: cssAttr = translateBorder(cssAttr, o);
762: }
763:
764:
765: o = cssAttr.getAttribute(HTML.Attribute.BORDER);
766: cssAttr = translateBorder(cssAttr, o);
767:
768:
769: return cssAttr;
770: }
771:
772:
781: private AttributeSet translateBorder(AttributeSet cssAttr, Object o)
782: {
783: if (o != null)
784: {
785: BorderWidth l = new BorderWidth(o.toString());
786: if (l.getValue() > 0)
787: {
788: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_WIDTH, l);
789: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_STYLE,
790: "solid");
791: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_COLOR,
792: new CSSColor("black"));
793: }
794: }
795: return cssAttr;
796: }
797:
798:
809: public AttributeSet addAttribute(AttributeSet old, Object key,
810: Object value)
811: {
812:
813: return super.addAttribute(old, key, value);
814: }
815:
816:
825: public AttributeSet addAttributes(AttributeSet old, AttributeSet attr)
826: {
827:
828: return super.addAttributes(old, attr);
829: }
830:
831:
840: public AttributeSet removeAttribute(AttributeSet old, Object key)
841: {
842:
843: return super.removeAttribute(old, key);
844: }
845:
846:
855: public AttributeSet removeAttributes(AttributeSet old, AttributeSet attrs)
856: {
857:
858: return super.removeAttributes(old, attrs);
859: }
860:
861:
870: public AttributeSet removeAttributes(AttributeSet old, Enumeration<?> names)
871: {
872:
873: return super.removeAttributes(old, names);
874: }
875:
876:
883: protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)
884: {
885: return super.createSmallAttributeSet(a);
886: }
887:
888:
896: protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)
897: {
898: return super.createLargeAttributeSet(a);
899: }
900:
901:
907: public Font getFont(AttributeSet a)
908: {
909: int realSize = getFontSize(a);
910:
911:
912: Object valign = a.getAttribute(CSS.Attribute.VERTICAL_ALIGN);
913: if (valign != null)
914: {
915: String v = valign.toString();
916: if (v.contains("sup") || v.contains("sub"))
917: realSize -= 2;
918: }
919:
920:
921: String family = "SansSerif";
922:
923: int style = Font.PLAIN;
924: FontWeight weight = (FontWeight) a.getAttribute(CSS.Attribute.FONT_WEIGHT);
925: if (weight != null)
926: style |= weight.getValue();
927: FontStyle fStyle = (FontStyle) a.getAttribute(CSS.Attribute.FONT_STYLE);
928: if (fStyle != null)
929: style |= fStyle.getValue();
930: return new Font(family, style, realSize);
931: }
932:
933:
940: float getEMBase(AttributeSet atts)
941: {
942: Font font = getFont(atts);
943: FontRenderContext ctx = new FontRenderContext(null, false, false);
944: Rectangle2D bounds = font.getStringBounds("M", ctx);
945: return (float) bounds.getWidth();
946: }
947:
948:
955: float getEXBase(AttributeSet atts)
956: {
957: Font font = getFont(atts);
958: FontRenderContext ctx = new FontRenderContext(null, false, false);
959: Rectangle2D bounds = font.getStringBounds("x", ctx);
960: return (float) bounds.getHeight();
961: }
962:
963:
970: private int getFontSize(AttributeSet atts)
971: {
972: int size = 12;
973: if (atts.isDefined(CSS.Attribute.FONT_SIZE))
974: {
975: FontSize fs = (FontSize) atts.getAttribute(CSS.Attribute.FONT_SIZE);
976: if (fs.isRelative())
977: {
978: int parSize = 12;
979: AttributeSet resolver = atts.getResolveParent();
980: if (resolver != null)
981: parSize = getFontSize(resolver);
982: size = fs.getValue(parSize);
983: }
984: else
985: {
986: size = fs.getValue();
987: }
988: }
989: else
990: {
991: AttributeSet resolver = atts.getResolveParent();
992: if (resolver != null)
993: size = getFontSize(resolver);
994: }
995: return size;
996: }
997:
998:
1006: public Color getForeground(AttributeSet a)
1007: {
1008: CSSColor c = (CSSColor) a.getAttribute(CSS.Attribute.COLOR);
1009: Color color = null;
1010: if (c != null)
1011: color = c.getValue();
1012: return color;
1013: }
1014:
1015:
1023: public Color getBackground(AttributeSet a)
1024: {
1025: CSSColor c = (CSSColor) a.getAttribute(CSS.Attribute.BACKGROUND_COLOR);
1026: Color color = null;
1027: if (c != null)
1028: color = c.getValue();
1029: return color;
1030: }
1031:
1032:
1038: public BoxPainter getBoxPainter(AttributeSet a)
1039: {
1040: return new BoxPainter(a, this);
1041: }
1042:
1043:
1049: public ListPainter getListPainter(AttributeSet a)
1050: {
1051: return new ListPainter(a, this);
1052: }
1053:
1054:
1059: public void setBaseFontSize(int sz)
1060: {
1061: if (sz <= 7 && sz >= 1)
1062: baseFontSize = sz;
1063: }
1064:
1065:
1072: public void setBaseFontSize(String size)
1073: {
1074: size = size.trim();
1075: int temp = 0;
1076: try
1077: {
1078: if (size.length() == 2)
1079: {
1080: int i = new Integer(size.substring(1)).intValue();
1081: if (size.startsWith("+"))
1082: temp = baseFontSize + i;
1083: else if (size.startsWith("-"))
1084: temp = baseFontSize - i;
1085: }
1086: else if (size.length() == 1)
1087: temp = new Integer(size.substring(0)).intValue();
1088:
1089: if (temp <= 7 && temp >= 1)
1090: baseFontSize = temp;
1091: }
1092: catch (NumberFormatException nfe)
1093: {
1094:
1095: }
1096: }
1097:
1098:
1104: public static int getIndexOfSize(float pt)
1105: {
1106:
1107: return 0;
1108: }
1109:
1110:
1116: public float getPointSize(int index)
1117: {
1118:
1119: return 0;
1120: }
1121:
1122:
1128: public float getPointSize(String size)
1129: {
1130:
1131: return 0;
1132: }
1133:
1134:
1141: public Color stringToColor(String colorName)
1142: {
1143: return CSSColor.convertValue(colorName);
1144: }
1145:
1146:
1155: public static class BoxPainter extends Object implements Serializable
1156: {
1157:
1158:
1161: private float leftInset;
1162:
1163:
1166: private float rightInset;
1167:
1168:
1171: private float topInset;
1172:
1173:
1176: private float bottomInset;
1177:
1178:
1181: private Border border;
1182:
1183: private float leftPadding;
1184: private float rightPadding;
1185: private float topPadding;
1186: private float bottomPadding;
1187:
1188:
1191: private Color background;
1192:
1193:
1198: BoxPainter(AttributeSet as, StyleSheet ss)
1199: {
1200: float emBase = ss.getEMBase(as);
1201: float exBase = ss.getEXBase(as);
1202:
1203: Length l = (Length) as.getAttribute(CSS.Attribute.MARGIN_LEFT);
1204: if (l != null)
1205: {
1206: l.setFontBases(emBase, exBase);
1207: leftInset = l.getValue();
1208: }
1209: l = (Length) as.getAttribute(CSS.Attribute.MARGIN_RIGHT);
1210: if (l != null)
1211: {
1212: l.setFontBases(emBase, exBase);
1213: rightInset = l.getValue();
1214: }
1215: l = (Length) as.getAttribute(CSS.Attribute.MARGIN_TOP);
1216: if (l != null)
1217: {
1218: l.setFontBases(emBase, exBase);
1219: topInset = l.getValue();
1220: }
1221: l = (Length) as.getAttribute(CSS.Attribute.MARGIN_BOTTOM);
1222: if (l != null)
1223: {
1224: l.setFontBases(emBase, exBase);
1225: bottomInset = l.getValue();
1226: }
1227:
1228:
1229: l = (Length) as.getAttribute(CSS.Attribute.PADDING_LEFT);
1230: if (l != null)
1231: {
1232: l.setFontBases(emBase, exBase);
1233: leftPadding = l.getValue();
1234: }
1235: l = (Length) as.getAttribute(CSS.Attribute.PADDING_RIGHT);
1236: if (l != null)
1237: {
1238: l.setFontBases(emBase, exBase);
1239: rightPadding = l.getValue();
1240: }
1241: l = (Length) as.getAttribute(CSS.Attribute.PADDING_TOP);
1242: if (l != null)
1243: {
1244: l.setFontBases(emBase, exBase);
1245: topPadding = l.getValue();
1246: }
1247: l = (Length) as.getAttribute(CSS.Attribute.PADDING_BOTTOM);
1248: if (l != null)
1249: {
1250: l.setFontBases(emBase, exBase);
1251: bottomPadding = l.getValue();
1252: }
1253:
1254:
1255: border = new CSSBorder(as, ss);
1256:
1257:
1258: background = ss.getBackground(as);
1259:
1260: }
1261:
1262:
1263:
1274: public float getInset(int size, View v)
1275: {
1276: float inset;
1277: switch (size)
1278: {
1279: case View.TOP:
1280: inset = topInset;
1281: if (border != null)
1282: inset += border.getBorderInsets(null).top;
1283: inset += topPadding;
1284: break;
1285: case View.BOTTOM:
1286: inset = bottomInset;
1287: if (border != null)
1288: inset += border.getBorderInsets(null).bottom;
1289: inset += bottomPadding;
1290: break;
1291: case View.LEFT:
1292: inset = leftInset;
1293: if (border != null)
1294: inset += border.getBorderInsets(null).left;
1295: inset += leftPadding;
1296: break;
1297: case View.RIGHT:
1298: inset = rightInset;
1299: if (border != null)
1300: inset += border.getBorderInsets(null).right;
1301: inset += rightPadding;
1302: break;
1303: default:
1304: inset = 0.0F;
1305: }
1306: return inset;
1307: }
1308:
1309:
1320: public void paint(Graphics g, float x, float y, float w, float h, View v)
1321: {
1322: int inX = (int) (x + leftInset);
1323: int inY = (int) (y + topInset);
1324: int inW = (int) (w - leftInset - rightInset);
1325: int inH = (int) (h - topInset - bottomInset);
1326: if (background != null)
1327: {
1328: g.setColor(background);
1329: g.fillRect(inX, inY, inW, inH);
1330: }
1331: if (border != null)
1332: {
1333: border.paintBorder(null, g, inX, inY, inW, inH);
1334: }
1335: }
1336: }
1337:
1338:
1345: public static class ListPainter implements Serializable
1346: {
1347:
1348:
1351: private AttributeSet attributes;
1352:
1353:
1356: private StyleSheet styleSheet;
1357:
1358:
1361: private String type;
1362:
1363:
1368: ListPainter(AttributeSet as, StyleSheet ss)
1369: {
1370: attributes = as;
1371: styleSheet = ss;
1372: type = (String) as.getAttribute(CSS.Attribute.LIST_STYLE_TYPE);
1373: }
1374:
1375:
1378: private final Rectangle tmpRect = new Rectangle();
1379:
1380:
1391: public void paint(Graphics g, float x, float y, float w, float h, View v,
1392: int item)
1393: {
1394:
1395:
1396:
1397: View itemView = v.getView(item);
1398: AttributeSet viewAtts = itemView.getAttributes();
1399: Object tag = viewAtts.getAttribute(StyleConstants.NameAttribute);
1400:
1401:
1402: if (tag != null && tag == HTML.Tag.LI)
1403: {
1404: g.setColor(Color.BLACK);
1405: int centerX = (int) (x - 12);
1406: int centerY = -1;
1407:
1408:
1409: tmpRect.setBounds((int) x, (int) y, (int) w, (int) h);
1410: if (itemView.getViewCount() > 0)
1411: {
1412: View v1 = itemView.getView(0);
1413: if (v1 instanceof ParagraphView && v1.getViewCount() > 0)
1414: {
1415: Shape a1 = itemView.getChildAllocation(0, tmpRect);
1416: Rectangle r1 = a1 instanceof Rectangle ? (Rectangle) a1
1417: : a1.getBounds();
1418: ParagraphView par = (ParagraphView) v1;
1419: Shape a = par.getChildAllocation(0, r1);
1420: if (a != null)
1421: {
1422: Rectangle r = a instanceof Rectangle ? (Rectangle) a
1423: : a.getBounds();
1424: centerY = (int) (r.height / 2 + r.y);
1425: }
1426: }
1427: }
1428: if (centerY == -1)
1429: {
1430: centerY =(int) (h / 2 + y);
1431: }
1432: g.fillOval(centerX - 3, centerY - 3, 6, 6);
1433: }
1434: }
1435: }
1436:
1437:
1444: private Map<String,String> attributeSetToMap(AttributeSet atts)
1445: {
1446: HashMap<String,String> map = new HashMap<String,String>();
1447: Enumeration<?> keys = atts.getAttributeNames();
1448: while (keys.hasMoreElements())
1449: {
1450: Object key = keys.nextElement();
1451: Object value = atts.getAttribute(key);
1452: map.put(key.toString(), value.toString());
1453: }
1454: return map;
1455: }
1456: }