home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / JTextArea.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  6.1 KB  |  333 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Rectangle;
  9. import java.awt.event.InputEvent;
  10. import java.awt.event.KeyEvent;
  11. import java.io.IOException;
  12. import java.io.ObjectOutputStream;
  13. import javax.accessibility.AccessibleContext;
  14. import javax.swing.text.AttributeSet;
  15. import javax.swing.text.BadLocationException;
  16. import javax.swing.text.Document;
  17. import javax.swing.text.Element;
  18. import javax.swing.text.JTextComponent;
  19. import javax.swing.text.PlainDocument;
  20.  
  21. public class JTextArea extends JTextComponent {
  22.    private static final String uiClassID = "TextAreaUI";
  23.    private int rows;
  24.    private int columns;
  25.    private int columnWidth;
  26.    private int rowHeight;
  27.    private boolean wrap;
  28.    private boolean word;
  29.  
  30.    public JTextArea() {
  31.       this((Document)null, (String)null, 0, 0);
  32.    }
  33.  
  34.    public JTextArea(String var1) {
  35.       this((Document)null, var1, 0, 0);
  36.    }
  37.  
  38.    public JTextArea(int var1, int var2) {
  39.       this((Document)null, (String)null, var1, var2);
  40.    }
  41.  
  42.    public JTextArea(String var1, int var2, int var3) {
  43.       this((Document)null, var1, var2, var3);
  44.    }
  45.  
  46.    public JTextArea(Document var1) {
  47.       this(var1, (String)null, 0, 0);
  48.    }
  49.  
  50.    public JTextArea(Document var1, String var2, int var3, int var4) {
  51.       this.rows = var3;
  52.       this.columns = var4;
  53.       this.wrap = false;
  54.       if (var1 == null) {
  55.          var1 = this.createDefaultModel();
  56.       }
  57.  
  58.       ((JTextComponent)this).setDocument(var1);
  59.       if (var2 != null) {
  60.          ((JTextComponent)this).setText(var2);
  61.       }
  62.  
  63.       if (var3 < 0) {
  64.          throw new IllegalArgumentException("rows: " + var3);
  65.       } else if (var4 < 0) {
  66.          throw new IllegalArgumentException("columns: " + var3);
  67.       }
  68.    }
  69.  
  70.    public String getUIClassID() {
  71.       return "TextAreaUI";
  72.    }
  73.  
  74.    protected Document createDefaultModel() {
  75.       return new PlainDocument();
  76.    }
  77.  
  78.    public void setTabSize(int var1) {
  79.       Document var2 = ((JTextComponent)this).getDocument();
  80.       if (var2 != null) {
  81.          int var3 = this.getTabSize();
  82.          var2.putProperty("tabSize", new Integer(var1));
  83.          ((JComponent)this).firePropertyChange("tabSize", var3, var1);
  84.       }
  85.  
  86.    }
  87.  
  88.    public int getTabSize() {
  89.       int var1 = 8;
  90.       Document var2 = ((JTextComponent)this).getDocument();
  91.       if (var2 != null) {
  92.          Integer var3 = (Integer)var2.getProperty("tabSize");
  93.          if (var3 != null) {
  94.             var1 = var3;
  95.          }
  96.       }
  97.  
  98.       return var1;
  99.    }
  100.  
  101.    public void setLineWrap(boolean var1) {
  102.       boolean var2 = this.wrap;
  103.       this.wrap = var1;
  104.       ((JComponent)this).firePropertyChange("lineWrap", var2, var1);
  105.    }
  106.  
  107.    public boolean getLineWrap() {
  108.       return this.wrap;
  109.    }
  110.  
  111.    public void setWrapStyleWord(boolean var1) {
  112.       boolean var2 = this.word;
  113.       this.word = var1;
  114.       ((JComponent)this).firePropertyChange("wrapStyleWord", var2, var1);
  115.    }
  116.  
  117.    public boolean getWrapStyleWord() {
  118.       return this.word;
  119.    }
  120.  
  121.    public int getLineOfOffset(int var1) throws BadLocationException {
  122.       Document var2 = ((JTextComponent)this).getDocument();
  123.       if (var1 < 0) {
  124.          throw new BadLocationException("Can't translate offset to line", -1);
  125.       } else if (var1 > var2.getLength()) {
  126.          throw new BadLocationException("Can't translate offset to line", var2.getLength() + 1);
  127.       } else {
  128.          Element var3 = ((JTextComponent)this).getDocument().getDefaultRootElement();
  129.          return var3.getElementIndex(var1);
  130.       }
  131.    }
  132.  
  133.    public int getLineCount() {
  134.       Element var1 = ((JTextComponent)this).getDocument().getDefaultRootElement();
  135.       int var2 = var1.getElementCount();
  136.       Element var3 = var1.getElement(var2 - 1);
  137.       return var3.getEndOffset() - var3.getStartOffset() > 1 ? var2 : var2 - 1;
  138.    }
  139.  
  140.    public int getLineStartOffset(int var1) throws BadLocationException {
  141.       Element var2 = ((JTextComponent)this).getDocument().getDefaultRootElement();
  142.       if (var1 < 0) {
  143.          throw new BadLocationException("Negative line", -1);
  144.       } else if (var1 >= var2.getElementCount()) {
  145.          throw new BadLocationException("No such line", ((JTextComponent)this).getDocument().getLength() + 1);
  146.       } else {
  147.          Element var3 = var2.getElement(var1);
  148.          return var3.getStartOffset();
  149.       }
  150.    }
  151.  
  152.    public int getLineEndOffset(int var1) throws BadLocationException {
  153.       Element var2 = ((JTextComponent)this).getDocument().getDefaultRootElement();
  154.       if (var1 < 0) {
  155.          throw new BadLocationException("Negative line", -1);
  156.       } else if (var1 >= var2.getElementCount()) {
  157.          throw new BadLocationException("No such line", ((JTextComponent)this).getDocument().getLength() + 1);
  158.       } else {
  159.          Element var3 = var2.getElement(var1);
  160.          return var3.getEndOffset();
  161.       }
  162.    }
  163.  
  164.    public void insert(String var1, int var2) {
  165.       Document var3 = ((JTextComponent)this).getDocument();
  166.       if (var3 != null) {
  167.          try {
  168.             var3.insertString(var2, var1, (AttributeSet)null);
  169.          } catch (BadLocationException var5) {
  170.             throw new IllegalArgumentException(((Throwable)var5).getMessage());
  171.          }
  172.       }
  173.  
  174.    }
  175.  
  176.    public void append(String var1) {
  177.       Document var2 = ((JTextComponent)this).getDocument();
  178.       if (var2 != null) {
  179.          try {
  180.             var2.insertString(var2.getLength(), var1, (AttributeSet)null);
  181.          } catch (BadLocationException var4) {
  182.          }
  183.       }
  184.  
  185.    }
  186.  
  187.    public void replaceRange(String var1, int var2, int var3) {
  188.       if (var3 < var2) {
  189.          throw new IllegalArgumentException("end before start");
  190.       } else {
  191.          Document var4 = ((JTextComponent)this).getDocument();
  192.          if (var4 != null) {
  193.             try {
  194.                var4.remove(var2, var3 - var2);
  195.                var4.insertString(var2, var1, (AttributeSet)null);
  196.             } catch (BadLocationException var6) {
  197.                throw new IllegalArgumentException(((Throwable)var6).getMessage());
  198.             }
  199.          }
  200.  
  201.       }
  202.    }
  203.  
  204.    public boolean isManagingFocus() {
  205.       return true;
  206.    }
  207.  
  208.    protected void processKeyEvent(KeyEvent var1) {
  209.       super.processKeyEvent(var1);
  210.       if (this.isManagingFocus() && (var1.getKeyCode() == 9 || var1.getKeyChar() == '\t')) {
  211.          ((InputEvent)var1).consume();
  212.       }
  213.  
  214.    }
  215.  
  216.    public int getRows() {
  217.       return this.rows;
  218.    }
  219.  
  220.    public void setRows(int var1) {
  221.       int var2 = this.rows;
  222.       if (var1 < 0) {
  223.          throw new IllegalArgumentException("rows less than zero.");
  224.       } else {
  225.          if (var1 != var2) {
  226.             this.rows = var1;
  227.             ((Container)this).invalidate();
  228.          }
  229.  
  230.       }
  231.    }
  232.  
  233.    protected int getRowHeight() {
  234.       if (this.rowHeight == 0) {
  235.          FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
  236.          this.rowHeight = var1.getHeight();
  237.       }
  238.  
  239.       return this.rowHeight;
  240.    }
  241.  
  242.    public int getColumns() {
  243.       return this.columns;
  244.    }
  245.  
  246.    public void setColumns(int var1) {
  247.       int var2 = this.columns;
  248.       if (var1 < 0) {
  249.          throw new IllegalArgumentException("columns less than zero.");
  250.       } else {
  251.          if (var1 != var2) {
  252.             this.columns = var1;
  253.             ((Container)this).invalidate();
  254.          }
  255.  
  256.       }
  257.    }
  258.  
  259.    protected int getColumnWidth() {
  260.       if (this.columnWidth == 0) {
  261.          FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
  262.          this.columnWidth = var1.charWidth('m');
  263.       }
  264.  
  265.       return this.columnWidth;
  266.    }
  267.  
  268.    public Dimension getPreferredSize() {
  269.       Dimension var1 = super.getPreferredSize();
  270.       var1 = var1 == null ? new Dimension(400, 400) : var1;
  271.       if (this.columns != 0) {
  272.          var1.width = Math.max(var1.width, this.columns * this.getColumnWidth());
  273.       }
  274.  
  275.       if (this.rows != 0) {
  276.          var1.height = Math.max(var1.height, this.rows * this.getRowHeight());
  277.       }
  278.  
  279.       return var1;
  280.    }
  281.  
  282.    public void setFont(Font var1) {
  283.       super.setFont(var1);
  284.       this.rowHeight = 0;
  285.       this.columnWidth = 0;
  286.    }
  287.  
  288.    protected String paramString() {
  289.       String var1 = this.wrap ? "true" : "false";
  290.       String var2 = this.word ? "true" : "false";
  291.       return super.paramString() + ",colums=" + this.columns + ",columWidth=" + this.columnWidth + ",rows=" + this.rows + ",rowHeight=" + this.rowHeight + ",word=" + var2 + ",wrap=" + var1;
  292.    }
  293.  
  294.    public boolean getScrollableTracksViewportWidth() {
  295.       return this.wrap ? true : super.getScrollableTracksViewportWidth();
  296.    }
  297.  
  298.    public Dimension getPreferredScrollableViewportSize() {
  299.       Dimension var1 = super.getPreferredScrollableViewportSize();
  300.       var1 = var1 == null ? new Dimension(400, 400) : var1;
  301.       var1.width = this.columns == 0 ? var1.width : this.columns * this.getColumnWidth();
  302.       var1.height = this.rows == 0 ? var1.height : this.rows * this.getRowHeight();
  303.       return var1;
  304.    }
  305.  
  306.    public int getScrollableUnitIncrement(Rectangle var1, int var2, int var3) {
  307.       switch (var2) {
  308.          case 0:
  309.             return this.getColumnWidth();
  310.          case 1:
  311.             return this.getRowHeight();
  312.          default:
  313.             throw new IllegalArgumentException("Invalid orientation: " + var2);
  314.       }
  315.    }
  316.  
  317.    private void writeObject(ObjectOutputStream var1) throws IOException {
  318.       var1.defaultWriteObject();
  319.       if (super.ui != null && this.getUIClassID().equals("TextAreaUI")) {
  320.          super.ui.installUI(this);
  321.       }
  322.  
  323.    }
  324.  
  325.    public AccessibleContext getAccessibleContext() {
  326.       if (super.accessibleContext == null) {
  327.          super.accessibleContext = new AccessibleJTextArea(this);
  328.       }
  329.  
  330.       return super.accessibleContext;
  331.    }
  332. }
  333.