home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / text / html / HTMLEditorKit.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  8.5 KB  |  205 lines

  1. package javax.swing.text.html;
  2.  
  3. import java.awt.Component;
  4. import java.awt.event.MouseListener;
  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.net.URL;
  13. import javax.swing.Action;
  14. import javax.swing.JEditorPane;
  15. import javax.swing.text.AbstractDocument;
  16. import javax.swing.text.BadLocationException;
  17. import javax.swing.text.Document;
  18. import javax.swing.text.Element;
  19. import javax.swing.text.MutableAttributeSet;
  20. import javax.swing.text.StyleConstants;
  21. import javax.swing.text.StyledDocument;
  22. import javax.swing.text.StyledEditorKit;
  23. import javax.swing.text.TextAction;
  24. import javax.swing.text.ViewFactory;
  25. import javax.swing.text.html.HTML.Attribute;
  26. import javax.swing.text.html.HTML.Tag;
  27.  
  28. public class HTMLEditorKit extends StyledEditorKit {
  29.    public static final String DEFAULT_CSS = "default.css";
  30.    private static StyleSheet defaultStyles = null;
  31.    private MouseListener linkHandler = new LinkController();
  32.    private static Parser defaultParser = null;
  33.    public static final String BOLD_ACTION = "html-bold-action";
  34.    public static final String ITALIC_ACTION = "html-italic-action";
  35.    public static final String PARA_INDENT_LEFT = "html-para-indent-left";
  36.    public static final String PARA_INDENT_RIGHT = "html-para-indent-right";
  37.    public static final String FONT_CHANGE_BIGGER = "html-font-bigger";
  38.    public static final String FONT_CHANGE_SMALLER = "html-font-smaller";
  39.    public static final String COLOR_ACTION = "html-color-action";
  40.    public static final String LOGICAL_STYLE_ACTION = "html-logical-style-action";
  41.    public static final String IMG_ALIGN_TOP = "html-image-align-top";
  42.    public static final String IMG_ALIGN_MIDDLE = "html-image-align-middle";
  43.    public static final String IMG_ALIGN_BOTTOM = "html-image-align-bottom";
  44.    public static final String IMG_BORDER = "html-image-border";
  45.    private static final String INSERT_TABLE_HTML = "<table border=1><tr><td></td></tr></table>";
  46.    private static final String INSERT_UL_HTML = "<ul><li></li></ul>";
  47.    private static final String INSERT_OL_HTML = "<ol><li></li></ol>";
  48.    private static final Action[] defaultActions;
  49.    // $FF: synthetic field
  50.    static Class class$javax$swing$text$html$HTMLEditorKit;
  51.  
  52.    static {
  53.       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)};
  54.    }
  55.  
  56.    // $FF: synthetic method
  57.    static Class class$(String var0) {
  58.       try {
  59.          return Class.forName(var0);
  60.       } catch (ClassNotFoundException var2) {
  61.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  62.       }
  63.    }
  64.  
  65.    public Object clone() {
  66.       return new HTMLEditorKit();
  67.    }
  68.  
  69.    public Document createDefaultDocument() {
  70.       StyleSheet var1 = this.getStyleSheet();
  71.       HTMLDocument var2 = new HTMLDocument(var1);
  72.       ((AbstractDocument)var2).setAsynchronousLoadPriority(4);
  73.       var2.setTokenThreshold(100);
  74.       return var2;
  75.    }
  76.  
  77.    protected void createInputAttributes(Element var1, MutableAttributeSet var2) {
  78.       var2.removeAttributes(var2);
  79.       var2.addAttributes(var1.getAttributes());
  80.       var2.removeAttribute(StyleConstants.ComposedTextAttribute);
  81.       Object var3 = var2.getAttribute(StyleConstants.NameAttribute);
  82.       if (var3 instanceof HTML.Tag) {
  83.          HTML.Tag var4 = (HTML.Tag)var3;
  84.          if (var4 == Tag.IMG) {
  85.             var2.removeAttribute(Attribute.SRC);
  86.             var2.removeAttribute(Attribute.HEIGHT);
  87.             var2.removeAttribute(Attribute.WIDTH);
  88.             var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  89.          } else if (var4 == Tag.HR) {
  90.             var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  91.          } else if (var4 == Tag.COMMENT) {
  92.             var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  93.             var2.removeAttribute(Attribute.COMMENT);
  94.          } else if (var4 instanceof HTML.UnknownTag) {
  95.             var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  96.             var2.removeAttribute(Attribute.ENDTAG);
  97.          }
  98.       }
  99.  
  100.    }
  101.  
  102.    public void deinstall(JEditorPane var1) {
  103.       ((Component)var1).removeMouseListener(this.linkHandler);
  104.       super.deinstall(var1);
  105.    }
  106.  
  107.    public Action[] getActions() {
  108.       return TextAction.augmentList(super.getActions(), defaultActions);
  109.    }
  110.  
  111.    public String getContentType() {
  112.       return "text/html";
  113.    }
  114.  
  115.    protected Parser getParser() {
  116.       if (defaultParser == null) {
  117.          try {
  118.             Class var1 = Class.forName("javax.swing.text.html.parser.ParserDelegator");
  119.             defaultParser = (Parser)var1.newInstance();
  120.          } catch (Throwable var2) {
  121.          }
  122.       }
  123.  
  124.       return defaultParser;
  125.    }
  126.  
  127.    public StyleSheet getStyleSheet() {
  128.       if (defaultStyles == null) {
  129.          defaultStyles = new StyleSheet();
  130.  
  131.          try {
  132.             InputStream var1 = (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("default.css");
  133.             BufferedReader var2 = new BufferedReader(new InputStreamReader(var1));
  134.             defaultStyles.loadRules(var2, (URL)null);
  135.             ((Reader)var2).close();
  136.          } catch (Throwable var3) {
  137.          }
  138.       }
  139.  
  140.       return defaultStyles;
  141.    }
  142.  
  143.    public ViewFactory getViewFactory() {
  144.       return new HTMLFactory();
  145.    }
  146.  
  147.    public void insertHTML(HTMLDocument var1, int var2, String var3, int var4, int var5, HTML.Tag var6) throws BadLocationException, IOException {
  148.       Parser var7 = this.getParser();
  149.       if (var7 == null) {
  150.          throw new IOException("Can't load parser");
  151.       } else if (var2 > ((AbstractDocument)var1).getLength()) {
  152.          throw new BadLocationException("Invalid location", var2);
  153.       } else {
  154.          ParserCallback var8 = var1.getReader(var2, var4, var5, var6);
  155.          Boolean var9 = (Boolean)((AbstractDocument)var1).getProperty("IgnoreCharsetDirective");
  156.          var7.parse(new StringReader(var3), var8, var9 == null ? false : var9);
  157.          var8.flush();
  158.       }
  159.    }
  160.  
  161.    public void install(JEditorPane var1) {
  162.       ((Component)var1).addMouseListener(this.linkHandler);
  163.       super.install(var1);
  164.    }
  165.  
  166.    public void read(Reader var1, Document var2, int var3) throws IOException, BadLocationException {
  167.       if (var2 instanceof HTMLDocument) {
  168.          HTMLDocument var4 = (HTMLDocument)var2;
  169.          Parser var5 = this.getParser();
  170.          if (var5 == null) {
  171.             throw new IOException("Can't load parser");
  172.          }
  173.  
  174.          if (var3 > var2.getLength()) {
  175.             throw new BadLocationException("Invalid location", var3);
  176.          }
  177.  
  178.          ParserCallback var6 = var4.getReader(var3);
  179.          Boolean var7 = (Boolean)var2.getProperty("IgnoreCharsetDirective");
  180.          var5.parse(var1, var6, var7 == null ? false : var7);
  181.          var6.flush();
  182.       } else {
  183.          super.read(var1, var2, var3);
  184.       }
  185.  
  186.    }
  187.  
  188.    public void setStyleSheet(StyleSheet var1) {
  189.       defaultStyles = var1;
  190.    }
  191.  
  192.    public void write(Writer var1, Document var2, int var3, int var4) throws IOException, BadLocationException {
  193.       if (var2 instanceof HTMLDocument) {
  194.          HTMLWriter var5 = new HTMLWriter(var1, (HTMLDocument)var2, var3, var4);
  195.          var5.write();
  196.       } else if (var2 instanceof StyledDocument) {
  197.          MinimalHTMLWriter var6 = new MinimalHTMLWriter(var1, (StyledDocument)var2, var3, var4);
  198.          var6.write();
  199.       } else {
  200.          super.write(var1, var2, var3, var4);
  201.       }
  202.  
  203.    }
  204. }
  205.