home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.text.html;
-
- import java.awt.event.ActionEvent;
- import java.io.IOException;
- import javax.swing.JEditorPane;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.DefaultStyledDocument;
- import javax.swing.text.Element;
- import javax.swing.text.JTextComponent;
- import javax.swing.text.StyledEditorKit;
-
- public class HTMLEditorKit$InsertHTMLTextAction extends HTMLEditorKit.HTMLTextAction {
- protected String html;
- protected HTML.Tag parentTag;
- protected HTML.Tag addTag;
- protected HTML.Tag alternateParentTag;
- protected HTML.Tag alternateAddTag;
-
- public HTMLEditorKit$InsertHTMLTextAction(String var1, String var2, HTML.Tag var3, HTML.Tag var4) {
- this(var1, var2, var3, var4, (HTML.Tag)null, (HTML.Tag)null);
- }
-
- public HTMLEditorKit$InsertHTMLTextAction(String var1, String var2, HTML.Tag var3, HTML.Tag var4, HTML.Tag var5, HTML.Tag var6) {
- super(var1);
- this.html = var2;
- this.parentTag = var3;
- this.addTag = var4;
- this.alternateParentTag = var5;
- this.alternateAddTag = var6;
- }
-
- public void actionPerformed(ActionEvent var1) {
- JEditorPane var2 = ((StyledEditorKit.StyledTextAction)this).getEditor(var1);
- if (var2 != null) {
- HTMLDocument var3 = ((HTMLEditorKit.HTMLTextAction)this).getHTMLDocument(var2);
- int var4 = ((JTextComponent)var2).getSelectionStart();
- Element var5 = ((HTMLEditorKit.HTMLTextAction)this).findElementMatchingTag(var3, var4, this.parentTag);
- if (var5 != null && var5.getStartOffset() == var4) {
- this.insertAtBoundry(var2, var3, var4, var5, this.html, this.parentTag, this.addTag);
- } else {
- int var6 = ((HTMLEditorKit.HTMLTextAction)this).elementCountToTag(var3, var4 - 1, this.parentTag);
- if (var6 != -1) {
- this.insertHTML(var2, var3, var4, this.html, var6, 0, this.addTag);
- } else if (this.alternateParentTag != null) {
- var6 = ((HTMLEditorKit.HTMLTextAction)this).elementCountToTag(var3, var4 - 1, this.alternateParentTag);
- if (var6 != -1) {
- this.insertHTML(var2, var3, var4, this.html, var6, 0, this.alternateAddTag);
- }
- }
- }
- }
-
- }
-
- protected void insertAtBoundry(JEditorPane var1, HTMLDocument var2, int var3, Element var4, String var5, HTML.Tag var6, HTML.Tag var7) {
- Element var8;
- for(var8 = ((DefaultStyledDocument)var2).getDefaultRootElement(); var8 != null && var8.getStartOffset() != var3 && !var8.isLeaf(); var8 = var8.getElement(var8.getElementIndex(var3))) {
- }
-
- if (var8 != null) {
- Element var14;
- Element var9 = var14 = var8.getParentElement();
- int var10 = 0;
- --var3;
-
- while(var14 != null && !var14.isLeaf()) {
- var14 = var14.getElement(var14.getElementIndex(var3));
- ++var10;
- }
-
- var10 = Math.max(0, var10 - 1);
- int var11 = 0;
- var8 = var9;
- ++var3;
-
- while(var8 != null && var8 != var4) {
- var8 = var8.getElement(var8.getElementIndex(var3));
- ++var11;
- }
-
- this.insertHTML(var1, var2, var3, var5, var10, var11, var7);
- }
-
- }
-
- protected void insertHTML(JEditorPane var1, HTMLDocument var2, int var3, String var4, int var5, int var6, HTML.Tag var7) {
- try {
- ((HTMLEditorKit.HTMLTextAction)this).getHTMLEditorKit(var1).insertHTML(var2, var3, var4, var5, var6, var7);
- } catch (IOException var9) {
- throw new RuntimeException("Unable to insert: " + var9);
- } catch (BadLocationException var10) {
- throw new RuntimeException("Unable to insert: " + var10);
- }
- }
- }
-