home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / text / html / HTMLEditorKit.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  10.2 KB  |  275 lines

  1. package javax.swing.text.html;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Cursor;
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.io.InputStreamReader;
  9. import java.io.Reader;
  10. import java.io.StringReader;
  11. import java.io.Writer;
  12. import java.lang.reflect.Method;
  13. import java.net.URL;
  14. import javax.swing.Action;
  15. import javax.swing.JEditorPane;
  16. import javax.swing.text.AbstractDocument;
  17. import javax.swing.text.BadLocationException;
  18. import javax.swing.text.Document;
  19. import javax.swing.text.Element;
  20. import javax.swing.text.MutableAttributeSet;
  21. import javax.swing.text.Style;
  22. import javax.swing.text.StyleConstants;
  23. import javax.swing.text.StyledDocument;
  24. import javax.swing.text.StyledEditorKit;
  25. import javax.swing.text.TextAction;
  26. import javax.swing.text.ViewFactory;
  27. import javax.swing.text.html.HTML.Attribute;
  28. import javax.swing.text.html.HTML.Tag;
  29.  
  30. public class HTMLEditorKit extends StyledEditorKit {
  31.    public static final String DEFAULT_CSS = "default.css";
  32.    private static final Cursor MoveCursor = Cursor.getPredefinedCursor(12);
  33.    private static final Cursor DefaultCursor = Cursor.getPredefinedCursor(0);
  34.    private static final ViewFactory defaultFactory = new HTMLFactory();
  35.    MutableAttributeSet input;
  36.    private static StyleSheet defaultStyles = null;
  37.    private LinkController linkHandler = new LinkController();
  38.    private static Parser defaultParser = null;
  39.    private Cursor defaultCursor;
  40.    private Cursor linkCursor;
  41.    public static final String BOLD_ACTION = "html-bold-action";
  42.    public static final String ITALIC_ACTION = "html-italic-action";
  43.    public static final String PARA_INDENT_LEFT = "html-para-indent-left";
  44.    public static final String PARA_INDENT_RIGHT = "html-para-indent-right";
  45.    public static final String FONT_CHANGE_BIGGER = "html-font-bigger";
  46.    public static final String FONT_CHANGE_SMALLER = "html-font-smaller";
  47.    public static final String COLOR_ACTION = "html-color-action";
  48.    public static final String LOGICAL_STYLE_ACTION = "html-logical-style-action";
  49.    public static final String IMG_ALIGN_TOP = "html-image-align-top";
  50.    public static final String IMG_ALIGN_MIDDLE = "html-image-align-middle";
  51.    public static final String IMG_ALIGN_BOTTOM = "html-image-align-bottom";
  52.    public static final String IMG_BORDER = "html-image-border";
  53.    private static final String INSERT_TABLE_HTML = "<table border=1><tr><td></td></tr></table>";
  54.    private static final String INSERT_UL_HTML = "<ul><li></li></ul>";
  55.    private static final String INSERT_OL_HTML = "<ol><li></li></ol>";
  56.    private static final String INSERT_HR_HTML = "<hr>";
  57.    private static final String INSERT_PRE_HTML = "<pre></pre>";
  58.    private static final Action[] defaultActions;
  59.    // $FF: synthetic field
  60.    static Class class$javax$swing$text$html$HTMLEditorKit;
  61.    // $FF: synthetic field
  62.    static Class class$java$lang$String;
  63.  
  64.    public HTMLEditorKit() {
  65.       this.defaultCursor = DefaultCursor;
  66.       this.linkCursor = MoveCursor;
  67.    }
  68.  
  69.    public Object clone() {
  70.       return new HTMLEditorKit();
  71.    }
  72.  
  73.    public String getContentType() {
  74.       return "text/html";
  75.    }
  76.  
  77.    public ViewFactory getViewFactory() {
  78.       return defaultFactory;
  79.    }
  80.  
  81.    public Document createDefaultDocument() {
  82.       StyleSheet var1 = this.getStyleSheet();
  83.       StyleSheet var2 = new StyleSheet();
  84.       var2.addStyleSheet(var1);
  85.       HTMLDocument var3 = new HTMLDocument(var2);
  86.       var3.setParser(this.getParser());
  87.       ((AbstractDocument)var3).setAsynchronousLoadPriority(4);
  88.       var3.setTokenThreshold(100);
  89.       return var3;
  90.    }
  91.  
  92.    public void read(Reader var1, Document var2, int var3) throws IOException, BadLocationException {
  93.       if (var2 instanceof HTMLDocument) {
  94.          HTMLDocument var4 = (HTMLDocument)var2;
  95.          Parser var5 = this.getParser();
  96.          if (var5 == null) {
  97.             throw new IOException("Can't load parser");
  98.          }
  99.  
  100.          if (var3 > var2.getLength()) {
  101.             throw new BadLocationException("Invalid location", var3);
  102.          }
  103.  
  104.          ParserCallback var6 = var4.getReader(var3);
  105.          Boolean var7 = (Boolean)var2.getProperty("IgnoreCharsetDirective");
  106.          var5.parse(var1, var6, var7 == null ? false : var7);
  107.          var6.flush();
  108.       } else {
  109.          super.read(var1, var2, var3);
  110.       }
  111.  
  112.    }
  113.  
  114.    public void insertHTML(HTMLDocument var1, int var2, String var3, int var4, int var5, HTML.Tag var6) throws BadLocationException, IOException {
  115.       Parser var7 = this.getParser();
  116.       if (var7 == null) {
  117.          throw new IOException("Can't load parser");
  118.       } else if (var2 > ((AbstractDocument)var1).getLength()) {
  119.          throw new BadLocationException("Invalid location", var2);
  120.       } else {
  121.          ParserCallback var8 = var1.getReader(var2, var4, var5, var6);
  122.          Boolean var9 = (Boolean)((AbstractDocument)var1).getProperty("IgnoreCharsetDirective");
  123.          var7.parse(new StringReader(var3), var8, var9 == null ? false : var9);
  124.          var8.flush();
  125.       }
  126.    }
  127.  
  128.    public void write(Writer var1, Document var2, int var3, int var4) throws IOException, BadLocationException {
  129.       if (var2 instanceof HTMLDocument) {
  130.          HTMLWriter var5 = new HTMLWriter(var1, (HTMLDocument)var2, var3, var4);
  131.          var5.write();
  132.       } else if (var2 instanceof StyledDocument) {
  133.          MinimalHTMLWriter var6 = new MinimalHTMLWriter(var1, (StyledDocument)var2, var3, var4);
  134.          var6.write();
  135.       } else {
  136.          super.write(var1, var2, var3, var4);
  137.       }
  138.  
  139.    }
  140.  
  141.    public void install(JEditorPane var1) {
  142.       ((Component)var1).addMouseListener(this.linkHandler);
  143.       ((Component)var1).addMouseMotionListener(this.linkHandler);
  144.       super.install(var1);
  145.    }
  146.  
  147.    public void deinstall(JEditorPane var1) {
  148.       ((Component)var1).removeMouseListener(this.linkHandler);
  149.       ((Component)var1).removeMouseMotionListener(this.linkHandler);
  150.       super.deinstall(var1);
  151.    }
  152.  
  153.    public void setStyleSheet(StyleSheet var1) {
  154.       defaultStyles = var1;
  155.    }
  156.  
  157.    public StyleSheet getStyleSheet() {
  158.       if (defaultStyles == null) {
  159.          defaultStyles = new StyleSheet();
  160.  
  161.          try {
  162.             InputStream var1 = getResourceAsStream("default.css");
  163.             BufferedReader var2 = new BufferedReader(new InputStreamReader(var1));
  164.             defaultStyles.loadRules(var2, (URL)null);
  165.             ((Reader)var2).close();
  166.          } catch (Throwable var3) {
  167.          }
  168.       }
  169.  
  170.       return defaultStyles;
  171.    }
  172.  
  173.    static InputStream getResourceAsStream(String var0) {
  174.       try {
  175.          ClassLoader var2 = (class$javax$swing$text$html$HTMLEditorKit == null ? (class$javax$swing$text$html$HTMLEditorKit = class$("javax.swing.text.html.HTMLEditorKit")) : class$javax$swing$text$html$HTMLEditorKit).getClassLoader();
  176.          Class var1;
  177.          if (var2 != null) {
  178.             var1 = var2.loadClass("javax.swing.text.html.ResourceLoader");
  179.          } else {
  180.             var1 = Class.forName("javax.swing.text.html.ResourceLoader");
  181.          }
  182.  
  183.          Class[] var3 = new Class[]{class$java$lang$String == null ? (class$java$lang$String = class$("java.lang.String")) : class$java$lang$String};
  184.          Method var4 = var1.getMethod("getResourceAsStream", var3);
  185.          String[] var5 = new String[]{var0};
  186.          return (InputStream)var4.invoke((Object)null, var5);
  187.       } catch (Throwable var6) {
  188.          return (class$javax$swing$text$html$HTMLEditorKit == null ? (class$javax$swing$text$html$HTMLEditorKit = class$("javax.swing.text.html.HTMLEditorKit")) : class$javax$swing$text$html$HTMLEditorKit).getResourceAsStream(var0);
  189.       }
  190.    }
  191.  
  192.    public Action[] getActions() {
  193.       return TextAction.augmentList(super.getActions(), defaultActions);
  194.    }
  195.  
  196.    protected void createInputAttributes(Element var1, MutableAttributeSet var2) {
  197.       var2.removeAttributes(var2);
  198.       var2.addAttributes(var1.getAttributes());
  199.       var2.removeAttribute(StyleConstants.ComposedTextAttribute);
  200.       Object var3 = var2.getAttribute(StyleConstants.NameAttribute);
  201.       if (var3 instanceof HTML.Tag) {
  202.          HTML.Tag var4 = (HTML.Tag)var3;
  203.          if (var4 == Tag.IMG) {
  204.             var2.removeAttribute(Attribute.SRC);
  205.             var2.removeAttribute(Attribute.HEIGHT);
  206.             var2.removeAttribute(Attribute.WIDTH);
  207.             var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  208.          } else if (var4 != Tag.HR && var4 != Tag.BR) {
  209.             if (var4 == Tag.COMMENT) {
  210.                var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  211.                var2.removeAttribute(Attribute.COMMENT);
  212.             } else if (var4 == Tag.INPUT) {
  213.                var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  214.                var2.removeAttribute(Tag.INPUT);
  215.             } else if (var4 instanceof HTML.UnknownTag) {
  216.                var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  217.                var2.removeAttribute(Attribute.ENDTAG);
  218.             }
  219.          } else {
  220.             var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  221.          }
  222.       }
  223.  
  224.    }
  225.  
  226.    public MutableAttributeSet getInputAttributes() {
  227.       if (this.input == null) {
  228.          this.input = this.getStyleSheet().addStyle((String)null, (Style)null);
  229.       }
  230.  
  231.       return this.input;
  232.    }
  233.  
  234.    public void setDefaultCursor(Cursor var1) {
  235.       this.defaultCursor = var1;
  236.    }
  237.  
  238.    public Cursor getDefaultCursor() {
  239.       return this.defaultCursor;
  240.    }
  241.  
  242.    public void setLinkCursor(Cursor var1) {
  243.       this.linkCursor = var1;
  244.    }
  245.  
  246.    public Cursor getLinkCursor() {
  247.       return this.linkCursor;
  248.    }
  249.  
  250.    protected Parser getParser() {
  251.       if (defaultParser == null) {
  252.          try {
  253.             Class var1 = Class.forName("javax.swing.text.html.parser.ParserDelegator");
  254.             defaultParser = (Parser)var1.newInstance();
  255.          } catch (Throwable var2) {
  256.          }
  257.       }
  258.  
  259.       return defaultParser;
  260.    }
  261.  
  262.    // $FF: synthetic method
  263.    static Class class$(String var0) {
  264.       try {
  265.          return Class.forName(var0);
  266.       } catch (ClassNotFoundException var2) {
  267.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  268.       }
  269.    }
  270.  
  271.    static {
  272.       defaultActions = new Action[]{new InsertHTMLTextAction("InsertTable", "<table border=1><tr><td></td></tr></table>", Tag.BODY, Tag.TABLE), new InsertHTMLTextAction("InsertTableRow", "<table border=1><tr><td></td></tr></table>", Tag.TABLE, Tag.TR, Tag.BODY, Tag.TABLE), new InsertHTMLTextAction("InsertTableDataCell", "<table border=1><tr><td></td></tr></table>", Tag.TR, Tag.TD, Tag.BODY, Tag.TABLE), new InsertHTMLTextAction("InsertUnorderedList", "<ul><li></li></ul>", Tag.BODY, Tag.UL), new InsertHTMLTextAction("InsertUnorderedListItem", "<ul><li></li></ul>", Tag.UL, Tag.LI, Tag.BODY, Tag.UL), new InsertHTMLTextAction("InsertOrderedList", "<ol><li></li></ol>", Tag.BODY, Tag.OL), new InsertHTMLTextAction("InsertOrderedListItem", "<ol><li></li></ol>", Tag.OL, Tag.LI, Tag.BODY, Tag.OL), new InsertHRAction(), new InsertHTMLTextAction("InsertPre", "<pre></pre>", Tag.BODY, Tag.PRE), new NavigateLinkAction("next-link-action"), new NavigateLinkAction("previous-link-action"), new ActivateLinkAction("activate-link-action")};
  273.    }
  274. }
  275.