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

  1. package javax.swing.text.html;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.io.IOException;
  5. import javax.swing.JEditorPane;
  6. import javax.swing.text.BadLocationException;
  7. import javax.swing.text.DefaultStyledDocument;
  8. import javax.swing.text.Element;
  9. import javax.swing.text.JTextComponent;
  10. import javax.swing.text.StyledEditorKit;
  11.  
  12. public class HTMLEditorKit$InsertHTMLTextAction extends HTMLEditorKit.HTMLTextAction {
  13.    protected String html;
  14.    protected HTML.Tag parentTag;
  15.    protected HTML.Tag addTag;
  16.    protected HTML.Tag alternateParentTag;
  17.    protected HTML.Tag alternateAddTag;
  18.  
  19.    public HTMLEditorKit$InsertHTMLTextAction(String var1, String var2, HTML.Tag var3, HTML.Tag var4) {
  20.       this(var1, var2, var3, var4, (HTML.Tag)null, (HTML.Tag)null);
  21.    }
  22.  
  23.    public HTMLEditorKit$InsertHTMLTextAction(String var1, String var2, HTML.Tag var3, HTML.Tag var4, HTML.Tag var5, HTML.Tag var6) {
  24.       super(var1);
  25.       this.html = var2;
  26.       this.parentTag = var3;
  27.       this.addTag = var4;
  28.       this.alternateParentTag = var5;
  29.       this.alternateAddTag = var6;
  30.    }
  31.  
  32.    public void actionPerformed(ActionEvent var1) {
  33.       JEditorPane var2 = ((StyledEditorKit.StyledTextAction)this).getEditor(var1);
  34.       if (var2 != null) {
  35.          HTMLDocument var3 = ((HTMLEditorKit.HTMLTextAction)this).getHTMLDocument(var2);
  36.          int var4 = ((JTextComponent)var2).getSelectionStart();
  37.          Element var5 = ((HTMLEditorKit.HTMLTextAction)this).findElementMatchingTag(var3, var4, this.parentTag);
  38.          if (var5 != null && var5.getStartOffset() == var4) {
  39.             this.insertAtBoundry(var2, var3, var4, var5, this.html, this.parentTag, this.addTag);
  40.          } else {
  41.             int var6 = ((HTMLEditorKit.HTMLTextAction)this).elementCountToTag(var3, var4 - 1, this.parentTag);
  42.             if (var6 != -1) {
  43.                this.insertHTML(var2, var3, var4, this.html, var6, 0, this.addTag);
  44.             } else if (this.alternateParentTag != null) {
  45.                var6 = ((HTMLEditorKit.HTMLTextAction)this).elementCountToTag(var3, var4 - 1, this.alternateParentTag);
  46.                if (var6 != -1) {
  47.                   this.insertHTML(var2, var3, var4, this.html, var6, 0, this.alternateAddTag);
  48.                }
  49.             }
  50.          }
  51.       }
  52.  
  53.    }
  54.  
  55.    protected void insertAtBoundry(JEditorPane var1, HTMLDocument var2, int var3, Element var4, String var5, HTML.Tag var6, HTML.Tag var7) {
  56.       Element var8;
  57.       for(var8 = ((DefaultStyledDocument)var2).getDefaultRootElement(); var8 != null && var8.getStartOffset() != var3 && !var8.isLeaf(); var8 = var8.getElement(var8.getElementIndex(var3))) {
  58.       }
  59.  
  60.       if (var8 != null) {
  61.          Element var14;
  62.          Element var9 = var14 = var8.getParentElement();
  63.          int var10 = 0;
  64.          --var3;
  65.  
  66.          while(var14 != null && !var14.isLeaf()) {
  67.             var14 = var14.getElement(var14.getElementIndex(var3));
  68.             ++var10;
  69.          }
  70.  
  71.          var10 = Math.max(0, var10 - 1);
  72.          int var11 = 0;
  73.          var8 = var9;
  74.          ++var3;
  75.  
  76.          while(var8 != null && var8 != var4) {
  77.             var8 = var8.getElement(var8.getElementIndex(var3));
  78.             ++var11;
  79.          }
  80.  
  81.          this.insertHTML(var1, var2, var3, var5, var10, var11, var7);
  82.       }
  83.  
  84.    }
  85.  
  86.    protected void insertHTML(JEditorPane var1, HTMLDocument var2, int var3, String var4, int var5, int var6, HTML.Tag var7) {
  87.       try {
  88.          ((HTMLEditorKit.HTMLTextAction)this).getHTMLEditorKit(var1).insertHTML(var2, var3, var4, var5, var6, var7);
  89.       } catch (IOException var9) {
  90.          throw new RuntimeException("Unable to insert: " + var9);
  91.       } catch (BadLocationException var10) {
  92.          throw new RuntimeException("Unable to insert: " + var10);
  93.       }
  94.    }
  95. }
  96.