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.set(i, attributeSetToMap(atts));
418: }
419: else
420: {
421: tags[i] = null;
422: }
423: }
424: tags[0] = tag.toString();
425: return resolveStyle(selector, tags, attributes);
426: }
427:
428:
437: private Style resolveStyle(String selector, String[] tags,
438: List<Map<String,String>> attributes)
439: {
440:
441:
442: ArrayList<CSSStyle> styles = new ArrayList<CSSStyle>();
443: for (CSSStyle style : css)
444: {
445: if (style.selector.matches(tags, attributes))
446: styles.add(style);
447: }
448:
449:
450: if (linked != null)
451: {
452: for (int i = linked.size() - 1; i >= 0; i--)
453: {
454: StyleSheet ss = linked.get(i);
455: for (int j = ss.css.size() - 1; j >= 0; j--)
456: {
457: CSSStyle style = ss.css.get(j);
458: if (style.selector.matches(tags, attributes))
459: styles.add(style);
460: }
461: }
462: }
463:
464:
465: Collections.sort(styles);
466: Style[] styleArray = styles.toArray(new Style[styles.size()]);
467: Style resolved = new MultiStyle(selector, styleArray);
468: resolvedStyles.put(selector, resolved);
469: return resolved;
470: }
471:
472:
480: public Style getRule(String selector)
481: {
482: CSSStyle best = null;
483: for (Iterator<CSSStyle> i = css.iterator(); i.hasNext();)
484: {
485: CSSStyle style = i.next();
486: if (style.compareTo(best) < 0)
487: best = style;
488: }
489: return best;
490: }
491:
492:
498: public void addRule(String rule)
499: {
500: CSSStyleSheetParserCallback cb =
501: new CSSStyleSheetParserCallback(CSSStyle.PREC_AUTHOR_NORMAL);
502:
503: StringReader in = new StringReader(rule);
504: CSSParser parser = new CSSParser(in, cb);
505: try
506: {
507: parser.parse();
508: }
509: catch (IOException ex)
510: {
511:
512: }
513:
514:
515: resolvedStyles.clear();
516: }
517:
518:
525: public AttributeSet getDeclaration(String decl)
526: {
527: if (decl == null)
528: return SimpleAttributeSet.EMPTY;
529:
530: return null;
531: }
532:
533:
543: public void loadRules(Reader in, URL ref)
544: throws IOException
545: {
546: CSSStyleSheetParserCallback cb =
547: new CSSStyleSheetParserCallback(CSSStyle.PREC_UA);
548:
549: CSSParser parser = new CSSParser(in, cb);
550: parser.parse();
551: }
552:
553:
560: public AttributeSet getViewAttributes(View v)
561: {
562: return new ViewAttributeSet(v, this);
563: }
564:
565:
570: public void removeStyle(String nm)
571: {
572:
573: super.removeStyle(nm);
574: }
575:
576:
583: public void addStyleSheet(StyleSheet ss)
584: {
585: if (linked == null)
586: linked = new ArrayList<StyleSheet>();
587: linked.add(ss);
588: }
589:
590:
595: public void removeStyleSheet(StyleSheet ss)
596: {
597: if (linked != null)
598: {
599: linked.remove(ss);
600: }
601: }
602:
603:
608: public StyleSheet[] getStyleSheets()
609: {
610: StyleSheet[] linkedSS;
611: if (linked != null)
612: {
613: linkedSS = new StyleSheet[linked.size()];
614: linkedSS = linked.toArray(linkedSS);
615: }
616: else
617: {
618: linkedSS = null;
619: }
620: return linkedSS;
621: }
622:
623:
630: public void importStyleSheet(URL url)
631: {
632: try
633: {
634: InputStream in = url.openStream();
635: Reader r = new BufferedReader(new InputStreamReader(in));
636: CSSStyleSheetParserCallback cb =
637: new CSSStyleSheetParserCallback(CSSStyle.PREC_AUTHOR_NORMAL);
638: CSSParser parser = new CSSParser(r, cb);
639: parser.parse();
640: }
641: catch (IOException ex)
642: {
643:
644: }
645: }
646:
647:
654: public void setBase(URL base)
655: {
656: this.base = base;
657: }
658:
659:
664: public URL getBase()
665: {
666: return base;
667: }
668:
669:
676: public void addCSSAttribute(MutableAttributeSet attr, CSS.Attribute key,
677: String value)
678: {
679: Object val = CSS.getValue(key, value);
680: CSS.addInternal(attr, key, value);
681: attr.addAttribute(key, val);
682: }
683:
684:
695: public boolean addCSSAttributeFromHTML(MutableAttributeSet attr, CSS.Attribute key,
696: String value)
697: {
698:
699: attr.addAttribute(key, value);
700: return attr.containsAttribute(key, value);
701: }
702:
703:
709: public AttributeSet translateHTMLToCSS(AttributeSet htmlAttrSet)
710: {
711: AttributeSet cssAttr = htmlAttrSet.copyAttributes();
712:
713:
714: Object o = htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);
715: if (o != null)
716: cssAttr = addAttribute(cssAttr, CSS.Attribute.TEXT_ALIGN, o);
717:
718:
719: o = htmlAttrSet.getAttribute(HTML.Attribute.WIDTH);
720: if (o != null)
721: cssAttr = addAttribute(cssAttr, CSS.Attribute.WIDTH,
722: new Length(o.toString()));
723:
724:
725: o = htmlAttrSet.getAttribute(HTML.Attribute.HEIGHT);
726: if (o != null)
727: cssAttr = addAttribute(cssAttr, CSS.Attribute.HEIGHT,
728: new Length(o.toString()));
729:
730: o = htmlAttrSet.getAttribute(HTML.Attribute.NOWRAP);
731: if (o != null)
732: cssAttr = addAttribute(cssAttr, CSS.Attribute.WHITE_SPACE, "nowrap");
733:
734:
735: o = htmlAttrSet.getAttribute(HTML.Attribute.CELLSPACING);
736: if (o != null)
737: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_SPACING,
738: new Length(o.toString()));
739:
740:
741:
742: HTML.Tag tag = (HTML.Tag)
743: htmlAttrSet.getAttribute(StyleConstants.NameAttribute);
744: if ((tag == HTML.Tag.TD || tag == HTML.Tag.TH)
745: && htmlAttrSet instanceof Element)
746: {
747: Element el = (Element) htmlAttrSet;
748: AttributeSet tableAttrs = el.getParentElement().getParentElement()
749: .getAttributes();
750: o = tableAttrs.getAttribute(HTML.Attribute.CELLPADDING);
751: if (o != null)
752: {
753: Length l = new Length(o.toString());
754: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_BOTTOM, l);
755: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_LEFT, l);
756: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_RIGHT, l);
757: cssAttr = addAttribute(cssAttr, CSS.Attribute.PADDING_TOP, l);
758: }
759: o = tableAttrs.getAttribute(HTML.Attribute.BORDER);
760: cssAttr = translateBorder(cssAttr, o);
761: }
762:
763:
764: o = cssAttr.getAttribute(HTML.Attribute.BORDER);
765: cssAttr = translateBorder(cssAttr, o);
766:
767:
768: return cssAttr;
769: }
770:
771:
780: private AttributeSet translateBorder(AttributeSet cssAttr, Object o)
781: {
782: if (o != null)
783: {
784: BorderWidth l = new BorderWidth(o.toString());
785: if (l.getValue() > 0)
786: {
787: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_WIDTH, l);
788: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_STYLE,
789: "solid");
790: cssAttr = addAttribute(cssAttr, CSS.Attribute.BORDER_COLOR,
791: new CSSColor("black"));
792: }
793: }
794: return cssAttr;
795: }
796:
797:
808: public AttributeSet addAttribute(AttributeSet old, Object key,
809: Object value)
810: {
811:
812: return super.addAttribute(old, key, value);
813: }
814:
815:
824: public AttributeSet addAttributes(AttributeSet old, AttributeSet attr)
825: {
826:
827: return super.addAttributes(old, attr);
828: }
829:
830:
839: public AttributeSet removeAttribute(AttributeSet old, Object key)
840: {
841:
842: return super.removeAttribute(old, key);
843: }
844:
845:
854: public AttributeSet removeAttributes(AttributeSet old, AttributeSet attrs)
855: {
856:
857: return super.removeAttributes(old, attrs);
858: }
859:
860:
869: public AttributeSet removeAttributes(AttributeSet old, Enumeration<?> names)
870: {
871:
872: return super.removeAttributes(old, names);
873: }
874:
875:
882: protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)
883: {
884: return super.createSmallAttributeSet(a);
885: }
886:
887:
895: protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)
896: {
897: return super.createLargeAttributeSet(a);
898: }
899:
900:
906: public Font getFont(AttributeSet a)
907: {
908: int realSize = getFontSize(a);
909:
910:
911: Object valign = a.getAttribute(CSS.Attribute.VERTICAL_ALIGN);
912: if (valign != null)
913: {
914: String v = valign.toString();
915: if (v.contains("sup") || v.contains("sub"))
916: realSize -= 2;
917: }
918:
919:
920: String family = "SansSerif";
921:
922: int style = Font.PLAIN;
923: FontWeight weight = (FontWeight) a.getAttribute(CSS.Attribute.FONT_WEIGHT);
924: if (weight != null)
925: style |= weight.getValue();
926: FontStyle fStyle = (FontStyle) a.getAttribute(CSS.Attribute.FONT_STYLE);
927: if (fStyle != null)
928: style |= fStyle.getValue();
929: return new Font(family, style, realSize);
930: }
931:
932:
939: float getEMBase(AttributeSet atts)
940: {
941: Font font = getFont(atts);
942: FontRenderContext ctx = new FontRenderContext(null, false, false);
943: Rectangle2D bounds = font.getStringBounds("M", ctx);
944: return (float) bounds.getWidth();
945: }
946:
947:
954: float getEXBase(AttributeSet atts)
955: {
956: Font font = getFont(atts);
957: FontRenderContext ctx = new FontRenderContext(null, false, false);
958: Rectangle2D bounds = font.getStringBounds("x", ctx);
959: return (float) bounds.getHeight();
960: }
961:
962:
969: private int getFontSize(AttributeSet atts)
970: {
971: int size = 12;
972: if (atts.isDefined(CSS.Attribute.FONT_SIZE))
973: {
974: FontSize fs = (FontSize) atts.getAttribute(CSS.Attribute.FONT_SIZE);
975: if (fs.isRelative())
976: {
977: int parSize = 12;
978: AttributeSet resolver = atts.getResolveParent();
979: if (resolver != null)
980: parSize = getFontSize(resolver);
981: size = fs.getValue(parSize);
982: }
983: else
984: {
985: size = fs.getValue();
986: }
987: }
988: else
989: {
990: AttributeSet resolver = atts.getResolveParent();
991: if (resolver != null)
992: size = getFontSize(resolver);
993: }
994: return size;
995: }
996:
997:
1005: public Color getForeground(AttributeSet a)
1006: {
1007: CSSColor c = (CSSColor) a.getAttribute(CSS.Attribute.COLOR);
1008: Color color = null;
1009: if (c != null)
1010: color = c.getValue();
1011: return color;
1012: }
1013:
1014:
1022: public Color getBackground(AttributeSet a)
1023: {
1024: CSSColor c = (CSSColor) a.getAttribute(CSS.Attribute.BACKGROUND_COLOR);
1025: Color color = null;
1026: if (c != null)
1027: color = c.getValue();
1028: return color;
1029: }
1030:
1031:
1037: public BoxPainter getBoxPainter(AttributeSet a)
1038: {
1039: return new BoxPainter(a, this);
1040: }
1041:
1042:
1048: public ListPainter getListPainter(AttributeSet a)
1049: {
1050: return new ListPainter(a, this);
1051: }
1052:
1053:
1058: public void setBaseFontSize(int sz)
1059: {
1060: if (sz <= 7 && sz >= 1)
1061: baseFontSize = sz;
1062: }
1063:
1064:
1071: public void setBaseFontSize(String size)
1072: {
1073: size = size.trim();
1074: int temp = 0;
1075: try
1076: {
1077: if (size.length() == 2)
1078: {
1079: int i = new Integer(size.substring(1)).intValue();
1080: if (size.startsWith("+"))
1081: temp = baseFontSize + i;
1082: else if (size.startsWith("-"))
1083: temp = baseFontSize - i;
1084: }
1085: else if (size.length() == 1)
1086: temp = new Integer(size.substring(0)).intValue();
1087:
1088: if (temp <= 7 && temp >= 1)
1089: baseFontSize = temp;
1090: }
1091: catch (NumberFormatException nfe)
1092: {
1093:
1094: }
1095: }
1096:
1097:
1103: public static int getIndexOfSize(float pt)
1104: {
1105:
1106: return 0;
1107: }
1108:
1109:
1115: public float getPointSize(int index)
1116: {
1117:
1118: return 0;
1119: }
1120:
1121:
1127: public float getPointSize(String size)
1128: {
1129:
1130: return 0;
1131: }
1132:
1133:
1140: public Color stringToColor(String colorName)
1141: {
1142: return CSSColor.convertValue(colorName);
1143: }
1144:
1145:
1154: public static class BoxPainter extends Object implements Serializable
1155: {
1156:
1157:
1160: private float leftInset;
1161:
1162:
1165: private float rightInset;
1166:
1167:
1170: private float topInset;
1171:
1172:
1175: private float bottomInset;
1176:
1177:
1180: private Border border;
1181:
1182: private float leftPadding;
1183: private float rightPadding;
1184: private float topPadding;
1185: private float bottomPadding;
1186:
1187:
1190: private Color background;
1191:
1192:
1197: BoxPainter(AttributeSet as, StyleSheet ss)
1198: {
1199: float emBase = ss.getEMBase(as);
1200: float exBase = ss.getEXBase(as);
1201:
1202: Length l = (Length) as.getAttribute(CSS.Attribute.MARGIN_LEFT);
1203: if (l != null)
1204: {
1205: l.setFontBases(emBase, exBase);
1206: leftInset = l.getValue();
1207: }
1208: l = (Length) as.getAttribute(CSS.Attribute.MARGIN_RIGHT);
1209: if (l != null)
1210: {
1211: l.setFontBases(emBase, exBase);
1212: rightInset = l.getValue();
1213: }
1214: l = (Length) as.getAttribute(CSS.Attribute.MARGIN_TOP);
1215: if (l != null)
1216: {
1217: l.setFontBases(emBase, exBase);
1218: topInset = l.getValue();
1219: }
1220: l = (Length) as.getAttribute(CSS.Attribute.MARGIN_BOTTOM);
1221: if (l != null)
1222: {
1223: l.setFontBases(emBase, exBase);
1224: bottomInset = l.getValue();
1225: }
1226:
1227:
1228: l = (Length) as.getAttribute(CSS.Attribute.PADDING_LEFT);
1229: if (l != null)
1230: {
1231: l.setFontBases(emBase, exBase);
1232: leftPadding = l.getValue();
1233: }
1234: l = (Length) as.getAttribute(CSS.Attribute.PADDING_RIGHT);
1235: if (l != null)
1236: {
1237: l.setFontBases(emBase, exBase);
1238: rightPadding = l.getValue();
1239: }
1240: l = (Length) as.getAttribute(CSS.Attribute.PADDING_TOP);
1241: if (l != null)
1242: {
1243: l.setFontBases(emBase, exBase);
1244: topPadding = l.getValue();
1245: }
1246: l = (Length) as.getAttribute(CSS.Attribute.PADDING_BOTTOM);
1247: if (l != null)
1248: {
1249: l.setFontBases(emBase, exBase);
1250: bottomPadding = l.getValue();
1251: }
1252:
1253:
1254: border = new CSSBorder(as, ss);
1255:
1256:
1257: background = ss.getBackground(as);
1258:
1259: }
1260:
1261:
1262:
1273: public float getInset(int size, View v)
1274: {
1275: float inset;
1276: switch (size)
1277: {
1278: case View.TOP:
1279: inset = topInset;
1280: if (border != null)
1281: inset += border.getBorderInsets(null).top;
1282: inset += topPadding;
1283: break;
1284: case View.BOTTOM:
1285: inset = bottomInset;
1286: if (border != null)
1287: inset += border.getBorderInsets(null).bottom;
1288: inset += bottomPadding;
1289: break;
1290: case View.LEFT:
1291: inset = leftInset;
1292: if (border != null)
1293: inset += border.getBorderInsets(null).left;
1294: inset += leftPadding;
1295: break;
1296: case View.RIGHT:
1297: inset = rightInset;
1298: if (border != null)
1299: inset += border.getBorderInsets(null).right;
1300: inset += rightPadding;
1301: break;
1302: default:
1303: inset = 0.0F;
1304: }
1305: return inset;
1306: }
1307:
1308:
1319: public void paint(Graphics g, float x, float y, float w, float h, View v)
1320: {
1321: int inX = (int) (x + leftInset);
1322: int inY = (int) (y + topInset);
1323: int inW = (int) (w - leftInset - rightInset);
1324: int inH = (int) (h - topInset - bottomInset);
1325: if (background != null)
1326: {
1327: g.setColor(background);
1328: g.fillRect(inX, inY, inW, inH);
1329: }
1330: if (border != null)
1331: {
1332: border.paintBorder(null, g, inX, inY, inW, inH);
1333: }
1334: }
1335: }
1336:
1337:
1344: public static class ListPainter implements Serializable
1345: {
1346:
1347:
1350: private AttributeSet attributes;
1351:
1352:
1355: private StyleSheet styleSheet;
1356:
1357:
1360: private String type;
1361:
1362:
1367: ListPainter(AttributeSet as, StyleSheet ss)
1368: {
1369: attributes = as;
1370: styleSheet = ss;
1371: type = (String) as.getAttribute(CSS.Attribute.LIST_STYLE_TYPE);
1372: }
1373:
1374:
1377: private final Rectangle tmpRect = new Rectangle();
1378:
1379:
1390: public void paint(Graphics g, float x, float y, float w, float h, View v,
1391: int item)
1392: {
1393:
1394:
1395:
1396: View itemView = v.getView(item);
1397: AttributeSet viewAtts = itemView.getAttributes();
1398: Object tag = viewAtts.getAttribute(StyleConstants.NameAttribute);
1399:
1400:
1401: if (tag != null && tag == HTML.Tag.LI)
1402: {
1403: g.setColor(Color.BLACK);
1404: int centerX = (int) (x - 12);
1405: int centerY = -1;
1406:
1407:
1408: tmpRect.setBounds((int) x, (int) y, (int) w, (int) h);
1409: if (itemView.getViewCount() > 0)
1410: {
1411: View v1 = itemView.getView(0);
1412: if (v1 instanceof ParagraphView && v1.getViewCount() > 0)
1413: {
1414: Shape a1 = itemView.getChildAllocation(0, tmpRect);
1415: Rectangle r1 = a1 instanceof Rectangle ? (Rectangle) a1
1416: : a1.getBounds();
1417: ParagraphView par = (ParagraphView) v1;
1418: Shape a = par.getChildAllocation(0, r1);
1419: if (a != null)
1420: {
1421: Rectangle r = a instanceof Rectangle ? (Rectangle) a
1422: : a.getBounds();
1423: centerY = (int) (r.height / 2 + r.y);
1424: }
1425: }
1426: }
1427: if (centerY == -1)
1428: {
1429: centerY =(int) (h / 2 + y);
1430: }
1431: g.fillOval(centerX - 3, centerY - 3, 6, 6);
1432: }
1433: }
1434: }
1435:
1436:
1443: private Map<String,String> attributeSetToMap(AttributeSet atts)
1444: {
1445: HashMap<String,String> map = new HashMap<String,String>();
1446: Enumeration<?> keys = atts.getAttributeNames();
1447: while (keys.hasMoreElements())
1448: {
1449: Object key = keys.nextElement();
1450: Object value = atts.getAttribute(key);
1451: map.put(key.toString(), value.toString());
1452: }
1453: return map;
1454: }
1455: }