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
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(Object o)
233: {
234: CSSStyle other = (CSSStyle) o;
235: return other.precedence + other.selector.getSpecificity()
236: - precedence - selector.getSpecificity();
237: }
238:
239: }
240:
241:
242: URL base;
243:
244:
245: int baseFontSize;
246:
247:
250: private ArrayList linked;
251:
252:
256: ArrayList css = new ArrayList();
257:
258:
261: private HashMap resolvedStyles;
262:
263:
266: public StyleSheet()
267: {
268: super();
269: baseFontSize = 4;
270: resolvedStyles = new HashMap();
271: }
272:
273:
282: public Style getRule(HTML.Tag t, Element e)
283: {
284:
285:
286: ArrayList path = new ArrayList();
287: Element el;
288: AttributeSet atts;
289: for (el = e; el != null; el = el.getParentElement())
290: path.add(el);
291:
292:
293: StringBuilder selector = new StringBuilder();
294: int count = path.size();
295:
296: for (int i = count - 1; i > 0; i--)
297: {
298: el = (Element) path.get(i);
299: atts = el.getAttributes();
300: Object name = atts.getAttribute(StyleConstants.NameAttribute);
301: selector.append(name.toString());
302: if (atts.isDefined(HTML.Attribute.ID))
303: {
304: selector.append('#');
305: selector.append(atts.getAttribute(HTML.Attribute.ID));
306: }
307: if (atts.isDefined(HTML.Attribute.CLASS))
308: {
309: selector.append('.');
310: selector.append(atts.getAttribute(HTML.Attribute.CLASS));
311: }
312: if (atts.isDefined(HTML.Attribute.DYNAMIC_CLASS))
313: {
314: selector.append(':');
315: selector.append(atts.getAttribute(HTML.Attribute.DYNAMIC_CLASS));
316: }
317: if (atts.isDefined(HTML.Attribute.PSEUDO_CLASS))
318: {
319: selector.append(':');
320: selector.append(atts.getAttribute(HTML.Attribute.PSEUDO_CLASS));
321: }
322: selector.append(' ');
323: }
324: selector.append(t.toString());
325: el = (Element) path.get(0);
326: atts = el.getAttributes();
327:
328: if (el.isLeaf())
329: {
330: Object o = atts.getAttribute(t);
331: if (o instanceof AttributeSet)
332: atts = (AttributeSet) o;
333: else
334: atts = null;
335: }
336: if (atts != null)
337: {
338: if (atts.isDefined(HTML.Attribute.ID))
339: {
340: selector.append('#');
341: selector.append(atts.getAttribute(HTML.Attribute.ID));
342: }
343: if (atts.isDefined(HTML.Attribute.CLASS))
344: {
345: selector.append('.');
346: selector.append(atts.getAttribute(HTML.Attribute.CLASS));
347: }
348: if (atts.isDefined(HTML.Attribute.DYNAMIC_CLASS))
349: {
350: selector.append(':');
351: selector.append(atts.getAttribute(HTML.Attribute.DYNAMIC_CLASS));
352: }
353: if (atts.isDefined(HTML.Attribute.PSEUDO_CLASS))
354: {
355: selector.append(':');
356: selector.append(atts.getAttribute(HTML.Attribute.PSEUDO_CLASS));
357: }
358: }
359: return getResolvedStyle(selector.toString(), path, t);
360: }
361:
362:
373: private Style getResolvedStyle(String selector, List path, HTML.Tag tag)
374: {
375: Style style = (Style) resolvedStyles.get(selector);
376: if (style == null)
377: style = resolveStyle(selector, path, tag);
378: return style;
379: }
380:
381:
392: private Style resolveStyle(String selector, List path, HTML.Tag tag)
393: {
394: int count = path.size();
395: String[] tags = new String[count];
396: Map[] attributes = new Map[count];
397: for (int i = 0; i < count; i++)
398: {
399: Element el = (Element) 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[i] = attributeSetToMap(atts);
418: }
419: else
420: {
421: tags[i] = null;
422: attributes[i] = 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, Map[] attributes)
439: {
440:
441:
442: int count = tags.length;
443: ArrayList styles = new ArrayList();
444: for (Iterator i = css.iterator(); i.hasNext();)
445: {
446: CSSStyle style = (CSSStyle) i.next();
447: if (style.selector.matches(tags, attributes))
448: styles.add(style);
449: }
450:
451:
452: if (linked != null)
453: {
454: for (int i = linked.size() - 1; i >= 0; i--)
455: {
456: StyleSheet ss = (StyleSheet) linked.get(i);
457: for (int j = ss.css.size() - 1; j >= 0; j--)
458: {
459: CSSStyle style = (CSSStyle) ss.css.get(j);
460: if (style.selector.matches(tags, attributes))
461: styles.add(style);
462: }
463: }
464: }
465:
466:
467: Collections.sort(styles);
468: Style[] styleArray = new Style[styles.size()];
469: styleArray = (Style[]) styles.toArray(styleArray);
470: Style resolved = new MultiStyle(selector,
471: (Style[]) styles.toArray(styleArray));
472: resolvedStyles.put(selector, resolved);
473: return resolved;
474: }
475:
476:
484: public Style getRule(String selector)
485: {
486: CSSStyle best = null;
487: for (Iterator i = css.iterator(); i.hasNext();)
488: {
489: CSSStyle style = (CSSStyle) i.next();
490: if (style.compareTo(best) < 0)
491: best = style;
492: }
493: return best;
494: }
495:
496:
502: public void addRule(String rule)
503: {
504: CSSStyleSheetParserCallback cb =
505: new CSSStyleSheetParserCallback(CSSStyle.PREC_AUTHOR_NORMAL);
506:
507: StringReader in = new StringReader(rule);
508: CSSParser parser = new CSSParser(in, cb);
509: try
510: {
511: parser.parse();
512: }
513: catch (IOException ex)
514: {
515:
516: }
517:
518:
519: resolvedStyles.clear();
520: }
521:
522:
529: public AttributeSet getDeclaration(String decl)
530: {
531: if (decl == null)
532: return SimpleAttributeSet.EMPTY;
533:
534: return null;
535: }
536:
537:
547: public void loadRules(Reader in, URL ref)
548: throws IOException
549: {
550: CSSStyleSheetParserCallback cb =
551: new CSSStyleSheetParserCallback(CSSStyle.PREC_UA);
552:
553: CSSParser parser = new CSSParser(in, cb);
554: parser.parse();
555: }
556:
557:
564: public AttributeSet getViewAttributes(View v)
565: {
566: return new ViewAttributeSet(v, this);
567: }
568:
569:
574: public void removeStyle(String nm)
575: {
576:
577: super.removeStyle(nm);
578: }
579:
580:
587: public void addStyleSheet(StyleSheet ss)
588: {
589: if (linked == null)
590: linked = new ArrayList();
591: linked.add(ss);
592: }
593:
594:
599: public void removeStyleSheet(StyleSheet ss)
600: {
601: if (linked != null)
602: {
603: linked.remove(ss);
604: }
605: }
606:
607:
612: public StyleSheet[] getStyleSheets()
613: {
614: StyleSheet[] linkedSS;
615: if (linked != null)
616: {
617: linkedSS = new StyleSheet[linked.size()];
618: linkedSS = (StyleSheet[]) linked.toArray(linkedSS);
619: }
620: else
621: {
622: linkedSS = null;
623: }
624: return linkedSS;
625: }
626:
627:
634: public void importStyleSheet(URL url)
635: {
636: try
637: {
638: InputStream in = url.openStream();
639: Reader r = new BufferedReader(new InputStreamReader(in));
640: CSSStyleSheetParserCallback cb =
641: new CSSStyleSheetParserCallback(CSSStyle.PREC_AUTHOR_NORMAL);
642: CSSParser parser = new CSSParser(r, cb);
643: parser.parse();
644: }
645: catch (IOException ex)
646: {
647:
648: }
649: }
650:
651:
658: public void setBase(URL base)
659: {
660: this.base = base;
661: }
662:
663:
668: public URL getBase()
669: {
670: return base;
671: }
672:
673:
680: public void addCSSAttribute(MutableAttributeSet attr, CSS.Attribute key,
681: String value)
682: {
683: Object val = CSS.getValue(key, value);
684: CSS.addInternal(attr, key, value);
685: attr.addAttribute(key, val);
686: }
687:
688:
699: public boolean addCSSAttributeFromHTML(MutableAttributeSet attr, CSS.Attribute key,
700: String value)
701: {
702:
703: attr.addAttribute(key, value);
704: return attr.containsAttribute(key, value);
705: }
706:
707:
713: public AttributeSet translateHTMLToCSS(AttributeSet htmlAttrSet)
714: {
715: AttributeSet cssAttr = htmlAttrSet.copyAttributes();
716:
717:
718: Object o = htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);
719: if (o != null)
720: cssAttr = addAttribute(cssAttr, CSS.Attribute.TEXT_ALIGN, o);
721:
722:
723: o = htmlAttrSet.getAttribute(HTML.Attribute.WIDTH);
724: if (o != null)
725: cssAttr = addAttribute(cssAttr, CSS.Attribute.WIDTH,
726: new Length(o.toString()));
727:
728:
729: o = htmlAttrSet.getAttribute(HTML.Attribute.HEIGHT);
730: if (o != null)
731: cssAttr = addAttribute(cssAttr, CSS.Attribute.HEIGHT,
732: new Length(o.toString()));
733:
734: o = htmlAttrSet.getAttribute(HTML.Attribute.NOWRAP);
735: if (o != null)
736: cssAttr = addAttribute(cssAttr, CSS.Attribute.WHITE_SPACE, "nowrap");
737:
738:
739: o = htmlAttrSet.getAttribute(HTML.Attribute.CELLSPACING);
740: if (o != null)
741: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_SPACING,
742: new Length(o.toString()));
743:
744:
745:
746: HTML.Tag tag = (HTML.Tag)
747: htmlAttrSet.getAttribute(StyleConstants.NameAttribute);
748: if ((tag == HTML.Tag.TD || tag == HTML.Tag.TH)
749: && htmlAttrSet instanceof Element)
750: {
751: Element el = (Element) htmlAttrSet;
752: AttributeSet tableAttrs = el.getParentElement().getParentElement()
753: .getAttributes();
754: o = tableAttrs.getAttribute(HTML.Attribute.CELLPADDING);
755: if (o != null)
756: {
757: Length l = new Length(o.toString());
758: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_BOTTOM, l);
759: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_LEFT, l);
760: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_RIGHT, l);
761: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_TOP, l);
762: }
763: o = tableAttrs.getAttribute(HTML.Attribute.BORDER);
764: cssAttr = translateBorder(cssAttr, o);
765: }
766:
767:
768: o = cssAttr.getAttribute(HTML.Attribute.BORDER);
769: cssAttr = translateBorder(cssAttr, o);
770:
771:
772: return cssAttr;
773: }
774:
775:
784: private AttributeSet translateBorder(AttributeSet cssAttr, Object o)
785: {
786: if (o != null)
787: {
788: BorderWidth l = new BorderWidth(o.toString());
789: if (l.getValue() > 0)
790: {
791: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_WIDTH, l);
792: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_STYLE,
793: "solid");
794: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_COLOR,
795: new CSSColor("black"));
796: }
797: }
798: return cssAttr;
799: }
800:
801:
812: public AttributeSet addAttribute(AttributeSet old, Object key,
813: Object value)
814: {
815:
816: return super.addAttribute(old, key, value);
817: }
818:
819:
828: public AttributeSet addAttributes(AttributeSet old, AttributeSet attr)
829: {
830:
831: return super.addAttributes(old, attr);
832: }
833:
834:
843: public AttributeSet removeAttribute(AttributeSet old, Object key)
844: {
845:
846: return super.removeAttribute(old, key);
847: }
848:
849:
858: public AttributeSet removeAttributes(AttributeSet old, AttributeSet attrs)
859: {
860:
861: return super.removeAttributes(old, attrs);
862: }
863:
864:
873: public AttributeSet removeAttributes(AttributeSet old, Enumeration<?> names)
874: {
875:
876: return super.removeAttributes(old, names);
877: }
878:
879:
886: protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)
887: {
888: return super.createSmallAttributeSet(a);
889: }
890:
891:
899: protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)
900: {
901: return super.createLargeAttributeSet(a);
902: }
903:
904:
910: public Font getFont(AttributeSet a)
911: {
912: int realSize = getFontSize(a);
913:
914:
915: Object valign = a.getAttribute(CSS.Attribute.VERTICAL_ALIGN);
916: if (valign != null)
917: {
918: String v = valign.toString();
919: if (v.contains("sup") || v.contains("sub"))
920: realSize -= 2;
921: }
922:
923:
924: String family = "SansSerif";
925:
926: int style = Font.PLAIN;
927: FontWeight weight = (FontWeight) a.getAttribute(CSS.Attribute.FONT_WEIGHT);
928: if (weight != null)
929: style |= weight.getValue();
930: FontStyle fStyle = (FontStyle) a.getAttribute(CSS.Attribute.FONT_STYLE);
931: if (fStyle != null)
932: style |= fStyle.getValue();
933: return new Font(family, style, realSize);
934: }
935:
936:
943: float getEMBase(AttributeSet atts)
944: {
945: Font font = getFont(atts);
946: FontRenderContext ctx = new FontRenderContext(null, false, false);
947: Rectangle2D bounds = font.getStringBounds("M", ctx);
948: return (float) bounds.getWidth();
949: }
950:
951:
958: float getEXBase(AttributeSet atts)
959: {
960: Font font = getFont(atts);
961: FontRenderContext ctx = new FontRenderContext(null, false, false);
962: Rectangle2D bounds = font.getStringBounds("x", ctx);
963: return (float) bounds.getHeight();
964: }
965:
966:
973: private int getFontSize(AttributeSet atts)
974: {
975: int size = 12;
976: if (atts.isDefined(CSS.Attribute.FONT_SIZE))
977: {
978: FontSize fs = (FontSize) atts.getAttribute(CSS.Attribute.FONT_SIZE);
979: if (fs.isRelative())
980: {
981: int parSize = 12;
982: AttributeSet resolver = atts.getResolveParent();
983: if (resolver != null)
984: parSize = getFontSize(resolver);
985: size = fs.getValue(parSize);
986: }
987: else
988: {
989: size = fs.getValue();
990: }
991: }
992: else
993: {
994: AttributeSet resolver = atts.getResolveParent();
995: if (resolver != null)
996: size = getFontSize(resolver);
997: }
998: return size;
999: }
1000:
1001:
1009: public Color getForeground(AttributeSet a)
1010: {
1011: CSSColor c = (CSSColor) a.getAttribute(CSS.Attribute.COLOR);
1012: Color color = null;
1013: if (c != null)
1014: color = c.getValue();
1015: return color;
1016: }
1017:
1018:
1026: public Color getBackground(AttributeSet a)
1027: {
1028: CSSColor c = (CSSColor) a.getAttribute(CSS.Attribute.BACKGROUND_COLOR);
1029: Color color = null;
1030: if (c != null)
1031: color = c.getValue();
1032: return color;
1033: }
1034:
1035:
1041: public BoxPainter getBoxPainter(AttributeSet a)
1042: {
1043: return new BoxPainter(a, this);
1044: }
1045:
1046:
1052: public ListPainter getListPainter(AttributeSet a)
1053: {
1054: return new ListPainter(a, this);
1055: }
1056:
1057:
1062: public void setBaseFontSize(int sz)
1063: {
1064: if (sz <= 7 && sz >= 1)
1065: baseFontSize = sz;
1066: }
1067:
1068:
1075: public void setBaseFontSize(String size)
1076: {
1077: size.trim();
1078: int temp = 0;
1079: try
1080: {
1081: if (size.length() == 2)
1082: {
1083: int i = new Integer(size.substring(1)).intValue();
1084: if (size.startsWith("+"))
1085: temp = baseFontSize + i;
1086: else if (size.startsWith("-"))
1087: temp = baseFontSize - i;
1088: }
1089: else if (size.length() == 1)
1090: temp = new Integer(size.substring(0)).intValue();
1091:
1092: if (temp <= 7 && temp >= 1)
1093: baseFontSize = temp;
1094: }
1095: catch (NumberFormatException nfe)
1096: {
1097:
1098: }
1099: }
1100:
1101:
1107: public static int getIndexOfSize(float pt)
1108: {
1109:
1110: return 0;
1111: }
1112:
1113:
1119: public float getPointSize(int index)
1120: {
1121:
1122: return 0;
1123: }
1124:
1125:
1131: public float getPointSize(String size)
1132: {
1133:
1134: return 0;
1135: }
1136:
1137:
1144: public Color stringToColor(String colorName)
1145: {
1146: return CSSColor.convertValue(colorName);
1147: }
1148:
1149:
1158: public static class BoxPainter extends Object implements Serializable
1159: {
1160:
1161:
1164: private float leftInset;
1165:
1166:
1169: private float rightInset;
1170:
1171:
1174: private float topInset;
1175:
1176:
1179: private float bottomInset;
1180:
1181:
1184: private Border border;
1185:
1186: private float leftPadding;
1187: private float rightPadding;
1188: private float topPadding;
1189: private float bottomPadding;
1190:
1191:
1194: private Color background;
1195:
1196:
1201: BoxPainter(AttributeSet as, StyleSheet ss)
1202: {
1203: float emBase = ss.getEMBase(as);
1204: float exBase = ss.getEXBase(as);
1205:
1206: Length l = (Length) as.getAttribute(CSS.Attribute.MARGIN_LEFT);
1207: if (l != null)
1208: {
1209: l.setFontBases(emBase, exBase);
1210: leftInset = l.getValue();
1211: }
1212: l = (Length) as.getAttribute(CSS.Attribute.MARGIN_RIGHT);
1213: if (l != null)
1214: {
1215: l.setFontBases(emBase, exBase);
1216: rightInset = l.getValue();
1217: }
1218: l = (Length) as.getAttribute(CSS.Attribute.MARGIN_TOP);
1219: if (l != null)
1220: {
1221: l.setFontBases(emBase, exBase);
1222: topInset = l.getValue();
1223: }
1224: l = (Length) as.getAttribute(CSS.Attribute.MARGIN_BOTTOM);
1225: if (l != null)
1226: {
1227: l.setFontBases(emBase, exBase);
1228: bottomInset = l.getValue();
1229: }
1230:
1231:
1232: l = (Length) as.getAttribute(CSS.Attribute.PADDING_LEFT);
1233: if (l != null)
1234: {
1235: l.setFontBases(emBase, exBase);
1236: leftPadding = l.getValue();
1237: }
1238: l = (Length) as.getAttribute(CSS.Attribute.PADDING_RIGHT);
1239: if (l != null)
1240: {
1241: l.setFontBases(emBase, exBase);
1242: rightPadding = l.getValue();
1243: }
1244: l = (Length) as.getAttribute(CSS.Attribute.PADDING_TOP);
1245: if (l != null)
1246: {
1247: l.setFontBases(emBase, exBase);
1248: topPadding = l.getValue();
1249: }
1250: l = (Length) as.getAttribute(CSS.Attribute.PADDING_BOTTOM);
1251: if (l != null)
1252: {
1253: l.setFontBases(emBase, exBase);
1254: bottomPadding = l.getValue();
1255: }
1256:
1257:
1258: border = new CSSBorder(as, ss);
1259:
1260:
1261: background = ss.getBackground(as);
1262:
1263: }
1264:
1265:
1266:
1277: public float getInset(int size, View v)
1278: {
1279: float inset;
1280: switch (size)
1281: {
1282: case View.TOP:
1283: inset = topInset;
1284: if (border != null)
1285: inset += border.getBorderInsets(null).top;
1286: inset += topPadding;
1287: break;
1288: case View.BOTTOM:
1289: inset = bottomInset;
1290: if (border != null)
1291: inset += border.getBorderInsets(null).bottom;
1292: inset += bottomPadding;
1293: break;
1294: case View.LEFT:
1295: inset = leftInset;
1296: if (border != null)
1297: inset += border.getBorderInsets(null).left;
1298: inset += leftPadding;
1299: break;
1300: case View.RIGHT:
1301: inset = rightInset;
1302: if (border != null)
1303: inset += border.getBorderInsets(null).right;
1304: inset += rightPadding;
1305: break;
1306: default:
1307: inset = 0.0F;
1308: }
1309: return inset;
1310: }
1311:
1312:
1323: public void paint(Graphics g, float x, float y, float w, float h, View v)
1324: {
1325: int inX = (int) (x + leftInset);
1326: int inY = (int) (y + topInset);
1327: int inW = (int) (w - leftInset - rightInset);
1328: int inH = (int) (h - topInset - bottomInset);
1329: if (background != null)
1330: {
1331: g.setColor(background);
1332: g.fillRect(inX, inY, inW, inH);
1333: }
1334: if (border != null)
1335: {
1336: border.paintBorder(null, g, inX, inY, inW, inH);
1337: }
1338: }
1339: }
1340:
1341:
1348: public static class ListPainter implements Serializable
1349: {
1350:
1351:
1354: private AttributeSet attributes;
1355:
1356:
1359: private StyleSheet styleSheet;
1360:
1361:
1364: private String type;
1365:
1366:
1371: ListPainter(AttributeSet as, StyleSheet ss)
1372: {
1373: attributes = as;
1374: styleSheet = ss;
1375: type = (String) as.getAttribute(CSS.Attribute.LIST_STYLE_TYPE);
1376: }
1377:
1378:
1381: private final Rectangle tmpRect = new Rectangle();
1382:
1383:
1394: public void paint(Graphics g, float x, float y, float w, float h, View v,
1395: int item)
1396: {
1397:
1398:
1399:
1400: View itemView = v.getView(item);
1401: AttributeSet viewAtts = itemView.getAttributes();
1402: Object tag = viewAtts.getAttribute(StyleConstants.NameAttribute);
1403:
1404:
1405: if (tag != null && tag == HTML.Tag.LI)
1406: {
1407: g.setColor(Color.BLACK);
1408: int centerX = (int) (x - 12);
1409: int centerY = -1;
1410:
1411:
1412: tmpRect.setBounds((int) x, (int) y, (int) w, (int) h);
1413: if (itemView.getViewCount() > 0)
1414: {
1415: View v1 = itemView.getView(0);
1416: if (v1 instanceof ParagraphView && v1.getViewCount() > 0)
1417: {
1418: Shape a1 = itemView.getChildAllocation(0, tmpRect);
1419: Rectangle r1 = a1 instanceof Rectangle ? (Rectangle) a1
1420: : a1.getBounds();
1421: ParagraphView par = (ParagraphView) v1;
1422: Shape a = par.getChildAllocation(0, r1);
1423: if (a != null)
1424: {
1425: Rectangle r = a instanceof Rectangle ? (Rectangle) a
1426: : a.getBounds();
1427: centerY = (int) (r.height / 2 + r.y);
1428: }
1429: }
1430: }
1431: if (centerY == -1)
1432: {
1433: centerY =(int) (h / 2 + y);
1434: }
1435: g.fillOval(centerX - 3, centerY - 3, 6, 6);
1436: }
1437: }
1438: }
1439:
1440:
1447: private Map attributeSetToMap(AttributeSet atts)
1448: {
1449: HashMap map = new HashMap();
1450: Enumeration keys = atts.getAttributeNames();
1451: while (keys.hasMoreElements())
1452: {
1453: Object key = keys.nextElement();
1454: Object value = atts.getAttribute(key);
1455: map.put(key.toString(), value.toString());
1456: }
1457: return map;
1458: }
1459: }