home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / text / StyledEditorKit$StyledTextAction.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  2.8 KB  |  70 lines

  1. package com.sun.java.swing.text;
  2.  
  3. import com.sun.java.swing.JEditorPane;
  4. import java.awt.event.ActionEvent;
  5. import java.util.EventObject;
  6.  
  7. public abstract class StyledEditorKit$StyledTextAction extends TextAction {
  8.    public StyledEditorKit$StyledTextAction(String var1) {
  9.       super(var1);
  10.    }
  11.  
  12.    protected final JEditorPane getEditor(ActionEvent var1) {
  13.       if (var1 != null) {
  14.          Object var2 = ((EventObject)var1).getSource();
  15.          if (var2 instanceof JEditorPane) {
  16.             return (JEditorPane)var2;
  17.          }
  18.  
  19.          JTextComponent var3 = ((TextAction)this).getFocusedComponent();
  20.          if (var3 instanceof JEditorPane) {
  21.             return (JEditorPane)var3;
  22.          }
  23.       }
  24.  
  25.       throw new IllegalArgumentException("target must be JEditorPane");
  26.    }
  27.  
  28.    protected final StyledDocument getStyledDocument(JEditorPane var1) {
  29.       Document var2 = ((JTextComponent)var1).getDocument();
  30.       if (var2 instanceof StyledDocument) {
  31.          return (StyledDocument)var2;
  32.       } else {
  33.          throw new IllegalArgumentException("document must be StyledDocument");
  34.       }
  35.    }
  36.  
  37.    protected final StyledEditorKit getStyledEditorKit(JEditorPane var1) {
  38.       EditorKit var2 = var1.getEditorKit();
  39.       if (var2 instanceof StyledEditorKit) {
  40.          return (StyledEditorKit)var2;
  41.       } else {
  42.          throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
  43.       }
  44.    }
  45.  
  46.    protected final void setCharacterAttributes(JEditorPane var1, AttributeSet var2, boolean var3) {
  47.       int var4 = ((JTextComponent)var1).getSelectionStart();
  48.       int var5 = ((JTextComponent)var1).getSelectionEnd();
  49.       if (var4 != var5) {
  50.          StyledDocument var8 = this.getStyledDocument(var1);
  51.          var8.setCharacterAttributes(var4, var5 - var4, var2, var3);
  52.       } else {
  53.          StyledEditorKit var6 = this.getStyledEditorKit(var1);
  54.          MutableAttributeSet var7 = var6.getInputAttributes();
  55.          if (var3) {
  56.             var7.removeAttributes(var7);
  57.          }
  58.  
  59.          var7.addAttributes(var2);
  60.       }
  61.    }
  62.  
  63.    protected final void setParagraphAttributes(JEditorPane var1, AttributeSet var2, boolean var3) {
  64.       int var4 = ((JTextComponent)var1).getSelectionStart();
  65.       int var5 = ((JTextComponent)var1).getSelectionEnd();
  66.       StyledDocument var6 = this.getStyledDocument(var1);
  67.       var6.setParagraphAttributes(var4, var5 - var4, var2, var3);
  68.    }
  69. }
  70.