1:
37:
38:
39: package ;
40:
41:
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48:
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58:
59: import ;
60: import ;
61:
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79:
80:
82: import ;
83: import ;
84:
85:
88: public class HTMLEditorKit
89: extends StyledEditorKit
90: implements Serializable, Cloneable, Accessible
91: {
92:
93:
97: public static class LinkController
98: extends MouseAdapter
99: implements MouseMotionListener, Serializable
100: {
101:
102:
105: private Element lastAnchorElement;
106:
107:
110: public LinkController()
111: {
112: super();
113: }
114:
115:
122: public void mouseClicked(MouseEvent e)
123: {
124: JEditorPane editor = (JEditorPane) e.getSource();
125: if (! editor.isEditable() && SwingUtilities.isLeftMouseButton(e))
126: {
127: Point loc = e.getPoint();
128: int pos = editor.viewToModel(loc);
129: if (pos >= 0)
130: activateLink(pos, editor, e.getX(), e.getY());
131: }
132: }
133:
134:
139: public void mouseDragged(MouseEvent e)
140: {
141:
142: }
143:
144:
149: public void mouseMoved(MouseEvent e)
150: {
151: JEditorPane editor = (JEditorPane) e.getSource();
152: HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit();
153: if (! editor.isEditable())
154: {
155: Document doc = editor.getDocument();
156: if (doc instanceof HTMLDocument)
157: {
158: Cursor newCursor = kit.getDefaultCursor();
159: HTMLDocument htmlDoc = (HTMLDocument) doc;
160: Point loc = e.getPoint();
161: int pos = editor.viewToModel(loc);
162: Element el = htmlDoc.getCharacterElement(pos);
163: if (pos < el.getStartOffset() || pos >= el.getEndOffset())
164: el = null;
165: if (el != null)
166: {
167: AttributeSet aAtts = (AttributeSet)
168: el.getAttributes().getAttribute(HTML.Tag.A);
169: if (aAtts != null)
170: {
171: if (el != lastAnchorElement)
172: {
173: if (lastAnchorElement != null)
174: htmlDoc.updateSpecialClass(lastAnchorElement,
175: HTML.Attribute.DYNAMIC_CLASS,
176: null);
177: lastAnchorElement = el;
178: htmlDoc.updateSpecialClass(el,
179: HTML.Attribute.DYNAMIC_CLASS,
180: "hover");
181: }
182: newCursor = kit.getLinkCursor();
183: }
184: else
185: {
186: if (lastAnchorElement != null)
187: htmlDoc.updateSpecialClass(lastAnchorElement,
188: HTML.Attribute.DYNAMIC_CLASS,
189: null);
190: lastAnchorElement = null;
191: }
192: }
193: else
194: {
195: if (lastAnchorElement != null)
196: htmlDoc.updateSpecialClass(lastAnchorElement,
197: HTML.Attribute.DYNAMIC_CLASS,
198: null);
199: lastAnchorElement = null;
200: }
201: if (editor.getCursor() != newCursor)
202: {
203: editor.setCursor(newCursor);
204: }
205: }
206: }
207: }
208:
209:
216: protected void activateLink(int pos, JEditorPane editor)
217: {
218: activateLink(pos, editor);
219: }
220:
221: private void activateLink(int pos, JEditorPane editor, int x, int y)
222: {
223:
224:
225: Document doc = editor.getDocument();
226: if (doc instanceof HTMLDocument)
227: {
228: HTMLDocument htmlDoc = (HTMLDocument) doc;
229: Element el = htmlDoc.getCharacterElement(pos);
230: AttributeSet atts = el.getAttributes();
231: AttributeSet anchorAtts =
232: (AttributeSet) atts.getAttribute(HTML.Tag.A);
233: String href = null;
234: if (anchorAtts != null)
235: {
236: href = (String) anchorAtts.getAttribute(HTML.Attribute.HREF);
237: htmlDoc.updateSpecialClass(el, HTML.Attribute.PSEUDO_CLASS,
238: "visited");
239: }
240: else
241: {
242:
243: }
244: HyperlinkEvent event = null;
245: if (href != null)
246: event = createHyperlinkEvent(editor, htmlDoc, href,
247: anchorAtts, el);
248: if (event != null)
249: editor.fireHyperlinkUpdate(event);
250: }
251:
252: }
253:
254:
267: private HyperlinkEvent createHyperlinkEvent(JEditorPane editor,
268: HTMLDocument doc,
269: String href,
270: AttributeSet anchor,
271: Element el)
272: {
273: URL url;
274: try
275: {
276: URL base = doc.getBase();
277: url = new URL(base, href);
278:
279: }
280: catch (MalformedURLException ex)
281: {
282: url = null;
283: }
284: HyperlinkEvent ev;
285: if (doc.isFrameDocument())
286: {
287: String target = null;
288: if (anchor != null)
289: target = (String) anchor.getAttribute(HTML.Attribute.TARGET);
290: if (target == null || target.equals(""))
291: target = doc.getBaseTarget();
292: if (target == null || target.equals(""))
293: target = "_self";
294: ev = new HTMLFrameHyperlinkEvent(editor,
295: HyperlinkEvent.EventType.ACTIVATED,
296: url, href, el, target);
297: }
298: else
299: {
300: ev = new HyperlinkEvent(editor, HyperlinkEvent.EventType.ACTIVATED,
301: url, href, el);
302: }
303: return ev;
304: }
305: }
306:
307:
315: public static class InsertHTMLTextAction
316: extends HTMLTextAction
317: {
318:
319:
322: protected HTML.Tag addTag;
323:
324:
328: protected HTML.Tag alternateAddTag;
329:
330:
333: protected HTML.Tag alternateParentTag;
334:
335:
338: protected String html;
339:
340:
343: protected HTML.Tag parentTag;
344:
345:
353: public InsertHTMLTextAction(String name, String html,
354: HTML.Tag parentTag, HTML.Tag addTag)
355: {
356: this(name, html, parentTag, addTag, null, null);
357: }
358:
359:
369: public InsertHTMLTextAction(String name, String html, HTML.Tag parentTag,
370: HTML.Tag addTag, HTML.Tag alternateParentTag,
371: HTML.Tag alternateAddTag)
372: {
373: super(name);
374:
375:
376: this.html = html;
377: this.parentTag = parentTag;
378: this.addTag = addTag;
379: this.alternateParentTag = alternateParentTag;
380: this.alternateAddTag = alternateAddTag;
381: }
382:
383:
403: protected void insertHTML(JEditorPane editor, HTMLDocument doc, int offset,
404: String html, int popDepth, int pushDepth,
405: HTML.Tag addTag)
406: {
407: try
408: {
409: super.getHTMLEditorKit(editor).insertHTML(doc, offset, html,
410: popDepth, pushDepth, addTag);
411: }
412: catch (IOException e)
413: {
414: throw (RuntimeException) new RuntimeException("Parser is null.").initCause(e);
415: }
416: catch (BadLocationException ex)
417: {
418: throw (RuntimeException) new RuntimeException("BadLocationException: "
419: + offset).initCause(ex);
420: }
421: }
422:
423:
443: protected void insertAtBoundary(JEditorPane editor,
444: HTMLDocument doc, int offset,
445: Element insertElement,
446: String html, HTML.Tag parentTag,
447: HTML.Tag addTag)
448: {
449: insertAtBoundry(editor, doc, offset, insertElement,
450: html, parentTag, addTag);
451: }
452:
453:
470: protected void insertAtBoundry(JEditorPane editor,
471: HTMLDocument doc,
472: int offset, Element insertElement,
473: String html, HTML.Tag parentTag,
474: HTML.Tag addTag)
475: {
476: Element parent = insertElement;
477: Element el;
478:
479: if (offset > 0 || insertElement == null)
480: {
481: el = doc.getDefaultRootElement();
482: while (el != null && el.getStartOffset() != offset
483: && ! el.isLeaf())
484: el = el.getElement(el.getElementIndex(offset));
485: parent = el != null ? el.getParentElement() : null;
486: }
487: if (parent != null)
488: {
489: int pops = 0;
490: int pushes = 0;
491: if (offset == 0 && insertElement != null)
492: {
493: el = parent;
494: while (el != null && ! el.isLeaf())
495: {
496: el = el.getElement(el.getElementIndex(offset));
497: pops++;
498: }
499: }
500: else
501: {
502: el = parent;
503: offset--;
504: while (el != null && ! el.isLeaf())
505: {
506: el = el.getElement(el.getElementIndex(offset));
507: pops++;
508: }
509: el = parent;
510: offset++;
511: while (el != null && el != insertElement)
512: {
513: el = el.getElement(el.getElementIndex(offset));
514: pushes++;
515: }
516: }
517: pops = Math.max(0, pops - 1);
518: insertHTML(editor, doc, offset, html, pops, pushes, addTag);
519: }
520: }
521:
522:
527: public void actionPerformed(ActionEvent ae)
528: {
529: JEditorPane source = getEditor(ae);
530: if (source != null)
531: {
532: HTMLDocument d = getHTMLDocument(source);
533: int offset = source.getSelectionStart();
534: int length = d.getLength();
535: boolean inserted = true;
536: if (! tryInsert(source, d, offset, parentTag, addTag))
537: {
538: inserted = tryInsert(source, d, offset, alternateParentTag,
539: alternateAddTag);
540: }
541: if (inserted)
542: adjustSelection(source, d, offset, length);
543: }
544: }
545:
546:
558: private boolean tryInsert(JEditorPane pane, HTMLDocument doc, int offset,
559: HTML.Tag tag, HTML.Tag addTag)
560: {
561: boolean inserted = false;
562: Element el = findElementMatchingTag(doc, offset, tag);
563: if (el != null && el.getStartOffset() == offset)
564: {
565: insertAtBoundary(pane, doc, offset, el, html, tag, addTag);
566: inserted = true;
567: }
568: else if (offset > 0)
569: {
570: int depth = elementCountToTag(doc, offset - 1, tag);
571: if (depth != -1)
572: {
573: insertHTML(pane, doc, offset, html, depth, 0, addTag);
574: inserted = true;
575: }
576: }
577: return inserted;
578: }
579:
580:
588: private void adjustSelection(JEditorPane pane, HTMLDocument doc,
589: int offset, int oldLen)
590: {
591: int newLen = doc.getLength();
592: if (newLen != oldLen && offset < newLen)
593: {
594: if (offset > 0)
595: {
596: String text;
597: try
598: {
599: text = doc.getText(offset - 1, 1);
600: }
601: catch (BadLocationException ex)
602: {
603: text = null;
604: }
605: if (text != null && text.length() > 0
606: && text.charAt(0) == '\n')
607: {
608: pane.select(offset, offset);
609: }
610: else
611: {
612: pane.select(offset + 1, offset + 1);
613: }
614: }
615: else
616: {
617: pane.select(1, 1);
618: }
619: }
620: }
621: }
622:
623:
626: public abstract static class HTMLTextAction
627: extends StyledEditorKit.StyledTextAction
628: {
629:
630:
633: public HTMLTextAction(String name)
634: {
635: super(name);
636: }
637:
638:
644: protected HTMLDocument getHTMLDocument(JEditorPane e)
645: {
646: Document d = e.getDocument();
647: if (d instanceof HTMLDocument)
648: return (HTMLDocument) d;
649: throw new IllegalArgumentException("Document is not a HTMLDocument.");
650: }
651:
652:
658: protected HTMLEditorKit getHTMLEditorKit(JEditorPane e)
659: {
660: EditorKit d = e.getEditorKit();
661: if (d instanceof HTMLEditorKit)
662: return (HTMLEditorKit) d;
663: throw new IllegalArgumentException("EditorKit is not a HTMLEditorKit.");
664: }
665:
666:
674: protected Element[] getElementsAt(HTMLDocument doc,
675: int offset)
676: {
677: return getElementsAt(doc.getDefaultRootElement(), offset, 0);
678: }
679:
680:
683: private Element[] getElementsAt(Element root, int offset, int depth)
684: {
685: Element[] elements = null;
686: if (root != null)
687: {
688: if (root.isLeaf())
689: {
690: elements = new Element[depth + 1];
691: elements[depth] = root;
692: return elements;
693: }
694: elements = getElementsAt(root.getElement(root.getElementIndex(offset)),
695: offset, depth + 1);
696: elements[depth] = root;
697: }
698: return elements;
699: }
700:
701:
715: protected int elementCountToTag(HTMLDocument doc,
716: int offset, HTML.Tag tag)
717: {
718: Element root = doc.getDefaultRootElement();
719: int num = -1;
720: Element next = root.getElement(root.getElementIndex(offset));
721:
722: while (!next.isLeaf())
723: {
724: num++;
725: if (next.getAttributes().
726: getAttribute(StyleConstants.NameAttribute).equals(tag))
727: return num;
728: next = next.getElement(next.getElementIndex(offset));
729: }
730: return num;
731: }
732:
733:
742: protected Element findElementMatchingTag(HTMLDocument doc,
743: int offset, HTML.Tag tag)
744: {
745: Element element = doc.getDefaultRootElement();
746: Element tagElement = null;
747:
748: while (element != null)
749: {
750: Object otag = element.getAttributes().getAttribute(
751: StyleConstants.NameAttribute);
752: if (otag instanceof HTML.Tag && otag.equals(tag))
753: tagElement = element;
754: element = element.getElement(element.getElementIndex(offset));
755: }
756:
757: return tagElement;
758: }
759: }
760:
761:
765: public static class HTMLFactory
766: implements ViewFactory
767: {
768:
769:
772: public HTMLFactory()
773: {
774:
775: }
776:
777:
786: public View create(Element element)
787: {
788: View view = null;
789: Object attr =
790: element.getAttributes().getAttribute(StyleConstants.NameAttribute);
791: if (attr instanceof HTML.Tag)
792: {
793: HTML.Tag tag = (HTML.Tag) attr;
794:
795: if (tag == HTML.Tag.IMPLIED || tag == HTML.Tag.P
796: || tag == HTML.Tag.H1 || tag == HTML.Tag.H2
797: || tag == HTML.Tag.H3 || tag == HTML.Tag.H4
798: || tag == HTML.Tag.H5 || tag == HTML.Tag.H6
799: || tag == HTML.Tag.DT)
800: view = new ParagraphView(element);
801: else if (tag == HTML.Tag.LI || tag == HTML.Tag.DL
802: || tag == HTML.Tag.DD || tag == HTML.Tag.BODY
803: || tag == HTML.Tag.HTML || tag == HTML.Tag.CENTER
804: || tag == HTML.Tag.DIV
805: || tag == HTML.Tag.BLOCKQUOTE
806: || tag == HTML.Tag.PRE
807: || tag == HTML.Tag.FORM
808:
809:
810: || tag == HTML.Tag.TD || tag == HTML.Tag.TH)
811: view = new BlockView(element, View.Y_AXIS);
812: else if (tag == HTML.Tag.TR)
813:
814:
815: view = new BlockView(element, View.X_AXIS);
816: else if (tag == HTML.Tag.IMG)
817: view = new ImageView(element);
818:
819: else if (tag == HTML.Tag.CONTENT)
820: view = new InlineView(element);
821: else if (tag == HTML.Tag.HEAD)
822: view = new NullView(element);
823: else if (tag == HTML.Tag.TABLE)
824: view = new javax.swing.text.html.TableView(element);
825: else if (tag == HTML.Tag.HR)
826: view = new HRuleView(element);
827: else if (tag == HTML.Tag.BR)
828: view = new BRView(element);
829: else if (tag == HTML.Tag.INPUT || tag == HTML.Tag.SELECT
830: || tag == HTML.Tag.TEXTAREA)
831: view = new FormView(element);
832:
833: else if (tag == HTML.Tag.MENU || tag == HTML.Tag.DIR
834: || tag == HTML.Tag.UL || tag == HTML.Tag.OL)
835: view = new ListView(element);
836: else if (tag == HTML.Tag.FRAMESET)
837: view = new FrameSetView(element);
838: else if (tag == HTML.Tag.FRAME)
839: view = new FrameView(element);
840: else if (tag == HTML.Tag.OBJECT)
841: view = new ObjectView(element);
842: }
843: if (view == null)
844: {
845: view = new NullView(element);
846: }
847: return view;
848: }
849: }
850:
851:
854: public abstract static class Parser
855: {
856:
866: public abstract void parse(Reader reader, ParserCallback callback,
867: boolean ignoreCharSet) throws IOException;
868: }
869:
870:
875: public static class ParserCallback
876: {
877:
882: public static final Object IMPLIED = "_implied_";
883:
884:
887: public ParserCallback()
888: {
889:
890: }
891:
892:
895: public void flush() throws BadLocationException
896: {
897:
898: }
899:
900:
905: public void handleComment(char[] comment, int position)
906: {
907:
908: }
909:
910:
916: public void handleEndOfLineString(String end_of_line)
917: {
918:
919: }
920:
921:
928: public void handleEndTag(HTML.Tag tag, int position)
929: {
930:
931: }
932:
933:
939: public void handleError(String message, int position)
940: {
941:
942: }
943:
944:
951: public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet attributes,
952: int position)
953: {
954:
955: }
956:
957:
964: public void handleStartTag(HTML.Tag tag, MutableAttributeSet attributes,
965: int position)
966: {
967:
968: }
969:
970:
975: public void handleText(char[] text, int position)
976: {
977:
978: }
979: }
980:
981:
984: private static final long serialVersionUID = 8751997116710384592L;
985:
986:
989: public static final String DEFAULT_CSS = "default.css";
990:
991:
994: public static final String BOLD_ACTION = "html-bold-action";
995:
996:
999: public static final String ITALIC_ACTION = "html-italic-action";
1000:
1001:
1005: public static final String COLOR_ACTION = "html-color-action";
1006:
1007:
1010: public static final String FONT_CHANGE_BIGGER = "html-font-bigger";
1011:
1012:
1015: public static final String FONT_CHANGE_SMALLER = "html-font-smaller";
1016:
1017:
1020: public static final String IMG_ALIGN_BOTTOM = "html-image-align-bottom";
1021:
1022:
1025: public static final String IMG_ALIGN_MIDDLE = "html-image-align-middle";
1026:
1027:
1030: public static final String IMG_ALIGN_TOP = "html-image-align-top";
1031:
1032:
1035: public static final String IMG_BORDER = "html-image-border";
1036:
1037:
1040: public static final String LOGICAL_STYLE_ACTION = "html-logical-style-action";
1041:
1042:
1045: public static final String PARA_INDENT_LEFT = "html-para-indent-left";
1046:
1047:
1050: public static final String PARA_INDENT_RIGHT = "html-para-indent-right";
1051:
1052:
1055: private static final Action[] defaultActions =
1056: {
1057: new InsertHTMLTextAction("InsertTable",
1058: "<table border=1><tr><td></td></tr></table>",
1059: HTML.Tag.BODY, HTML.Tag.TABLE),
1060: new InsertHTMLTextAction("InsertTableRow",
1061: "<table border=1><tr><td></td></tr></table>",
1062: HTML.Tag.TABLE, HTML.Tag.TR,
1063: HTML.Tag.BODY, HTML.Tag.TABLE),
1064: new InsertHTMLTextAction("InsertTableCell",
1065: "<table border=1><tr><td></td></tr></table>",
1066: HTML.Tag.TR, HTML.Tag.TD,
1067: HTML.Tag.BODY, HTML.Tag.TABLE),
1068: new InsertHTMLTextAction("InsertUnorderedList",
1069: "<ul><li></li></ul>",
1070: HTML.Tag.BODY, HTML.Tag.UL),
1071: new InsertHTMLTextAction("InsertUnorderedListItem",
1072: "<ul><li></li></ul>",
1073: HTML.Tag.UL, HTML.Tag.LI,
1074: HTML.Tag.BODY, HTML.Tag.UL),
1075: new InsertHTMLTextAction("InsertOrderedList",
1076: "<ol><li></li></ol>",
1077: HTML.Tag.BODY, HTML.Tag.OL),
1078: new InsertHTMLTextAction("InsertOrderedListItem",
1079: "<ol><li></li></ol>",
1080: HTML.Tag.OL, HTML.Tag.LI,
1081: HTML.Tag.BODY, HTML.Tag.OL),
1082: new InsertHTMLTextAction("InsertPre",
1083: "<pre></pre>", HTML.Tag.BODY, HTML.Tag.PRE)
1084:
1085: };
1086:
1087:
1090: private StyleSheet styleSheet;
1091:
1092:
1095: HTMLFactory viewFactory;
1096:
1097:
1100: Cursor linkCursor;
1101:
1102:
1105: Cursor defaultCursor;
1106:
1107:
1110: Parser parser;
1111:
1112:
1115: private LinkController linkController;
1116:
1117:
1118: String contentType = "text/html";
1119:
1120:
1121: MutableAttributeSet inputAttributes;
1122:
1123:
1124: JEditorPane editorPane;
1125:
1126:
1132: private boolean autoFormSubmission;
1133:
1134:
1137: public HTMLEditorKit()
1138: {
1139: linkController = new LinkController();
1140: autoFormSubmission = true;
1141: }
1142:
1143:
1149: public ViewFactory getViewFactory()
1150: {
1151: if (viewFactory == null)
1152: viewFactory = new HTMLFactory();
1153: return viewFactory;
1154: }
1155:
1156:
1161: public Document createDefaultDocument()
1162: {
1163:
1164: StyleSheet styleSheet = getStyleSheet();
1165: StyleSheet ss = new StyleSheet();
1166: ss.addStyleSheet(styleSheet);
1167:
1168: HTMLDocument document = new HTMLDocument(ss);
1169: document.setParser(getParser());
1170: document.setAsynchronousLoadPriority(4);
1171: document.setTokenThreshold(100);
1172: return document;
1173: }
1174:
1175:
1181: protected Parser getParser()
1182: {
1183: if (parser == null)
1184: {
1185: parser = new GnuParserDelegator(HTML_401F.getInstance());
1186: }
1187: return parser;
1188: }
1189:
1190:
1206: public void insertHTML(HTMLDocument doc, int offset, String html,
1207: int popDepth, int pushDepth, HTML.Tag insertTag)
1208: throws BadLocationException, IOException
1209: {
1210: Parser parser = getParser();
1211: if (offset < 0 || offset > doc.getLength())
1212: throw new BadLocationException("Bad location", offset);
1213: if (parser == null)
1214: throw new IOException("Parser is null.");
1215:
1216: ParserCallback pc = doc.getReader(offset, popDepth, pushDepth, insertTag);
1217:
1218:
1219:
1220:
1221: parser.parse(new StringReader(html), pc, false);
1222: pc.flush();
1223: }
1224:
1225:
1238: public void read(Reader in, Document doc, int pos) throws IOException,
1239: BadLocationException
1240: {
1241: if (doc instanceof HTMLDocument)
1242: {
1243: Parser parser = getParser();
1244: if (pos < 0 || pos > doc.getLength())
1245: throw new BadLocationException("Bad location", pos);
1246: if (parser == null)
1247: throw new IOException("Parser is null.");
1248:
1249: HTMLDocument hd = ((HTMLDocument) doc);
1250: if (editorPane != null)
1251: hd.setBase(editorPane.getPage());
1252: ParserCallback pc = hd.getReader(pos);
1253:
1254:
1255:
1256:
1257: parser.parse(in, pc, false);
1258: pc.flush();
1259: }
1260: else
1261:
1262:
1263: super.read(in, doc, pos);
1264: }
1265:
1266:
1278: public void write(Writer out, Document doc, int pos, int len)
1279: throws IOException, BadLocationException
1280: {
1281: if (doc instanceof HTMLDocument)
1282: {
1283: HTMLWriter writer = new HTMLWriter(out, (HTMLDocument) doc, pos, len);
1284: writer.write();
1285: }
1286: else if (doc instanceof StyledDocument)
1287: {
1288: MinimalHTMLWriter writer = new MinimalHTMLWriter(out,
1289: (StyledDocument) doc,
1290: pos, len);
1291: writer.write();
1292: }
1293: else
1294: super.write(out, doc, pos, len);
1295: }
1296:
1297:
1303: public String getContentType()
1304: {
1305: return contentType;
1306: }
1307:
1308:
1313: public Object clone()
1314: {
1315:
1316: HTMLEditorKit copy = (HTMLEditorKit) super.clone();
1317: copy.linkController = new LinkController();
1318: return copy;
1319: }
1320:
1321:
1329: protected void createInputAttributes(Element element,
1330: MutableAttributeSet set)
1331: {
1332: set.removeAttributes(set);
1333: set.addAttributes(element.getAttributes());
1334:
1335: }
1336:
1337:
1342: public void install(JEditorPane c)
1343: {
1344: super.install(c);
1345: c.addMouseListener(linkController);
1346: c.addMouseMotionListener(linkController);
1347: editorPane = c;
1348: }
1349:
1350:
1356: public void deinstall(JEditorPane c)
1357: {
1358: super.deinstall(c);
1359: c.removeMouseListener(linkController);
1360: c.removeMouseMotionListener(linkController);
1361: editorPane = null;
1362: }
1363:
1364:
1369: public AccessibleContext getAccessibleContext()
1370: {
1371:
1372:
1373:
1374: return null;
1375: }
1376:
1377:
1384: public Action[] getActions()
1385: {
1386: return TextAction.augmentList(super.getActions(), defaultActions);
1387: }
1388:
1389:
1394: public Cursor getDefaultCursor()
1395: {
1396: if (defaultCursor == null)
1397: defaultCursor = Cursor.getDefaultCursor();
1398: return defaultCursor;
1399: }
1400:
1401:
1406: public Cursor getLinkCursor()
1407: {
1408: if (linkCursor == null)
1409: linkCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
1410: return linkCursor;
1411: }
1412:
1413:
1418: public void setLinkCursor(Cursor cursor)
1419: {
1420: linkCursor = cursor;
1421: }
1422:
1423:
1428: public void setDefaultCursor(Cursor cursor)
1429: {
1430: defaultCursor = cursor;
1431: }
1432:
1433:
1438: public MutableAttributeSet getInputAttributes()
1439: {
1440: return inputAttributes;
1441: }
1442:
1443:
1450: public StyleSheet getStyleSheet()
1451: {
1452: if (styleSheet == null)
1453: {
1454: try
1455: {
1456: styleSheet = new StyleSheet();
1457: Class c = HTMLEditorKit.class;
1458: InputStream in = c.getResourceAsStream(DEFAULT_CSS);
1459: InputStreamReader r = new InputStreamReader(in);
1460: styleSheet.loadRules(r, null);
1461: r.close();
1462: }
1463: catch (IOException ex)
1464: {
1465:
1466: }
1467: }
1468: return styleSheet;
1469: }
1470:
1471:
1480: public void setStyleSheet(StyleSheet s)
1481: {
1482: styleSheet = s;
1483: }
1484:
1485:
1501: public boolean isAutoFormSubmission()
1502: {
1503: return autoFormSubmission;
1504: }
1505:
1506:
1516: public void setAutoFormSubmission(boolean auto)
1517: {
1518: autoFormSubmission = auto;
1519: }
1520: }