home *** CD-ROM | disk | FTP | other *** search
- package javax.swing;
-
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Rectangle;
- import java.awt.event.InputEvent;
- import java.awt.event.KeyEvent;
- import java.io.IOException;
- import java.io.ObjectOutputStream;
- import javax.accessibility.AccessibleContext;
- import javax.swing.text.AttributeSet;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.Document;
- import javax.swing.text.Element;
- import javax.swing.text.JTextComponent;
- import javax.swing.text.PlainDocument;
-
- public class JTextArea extends JTextComponent {
- private static final String uiClassID = "TextAreaUI";
- private int rows;
- private int columns;
- private int columnWidth;
- private int rowHeight;
- private boolean wrap;
- private boolean word;
-
- public JTextArea() {
- this((Document)null, (String)null, 0, 0);
- }
-
- public JTextArea(int var1, int var2) {
- this((Document)null, (String)null, var1, var2);
- }
-
- public JTextArea(String var1) {
- this((Document)null, var1, 0, 0);
- }
-
- public JTextArea(String var1, int var2, int var3) {
- this((Document)null, var1, var2, var3);
- }
-
- public JTextArea(Document var1) {
- this(var1, (String)null, 0, 0);
- }
-
- public JTextArea(Document var1, String var2, int var3, int var4) {
- this.rows = var3;
- this.columns = var4;
- if (var1 == null) {
- var1 = this.createDefaultModel();
- }
-
- ((JTextComponent)this).setDocument(var1);
- if (var2 != null) {
- ((JTextComponent)this).setText(var2);
- }
-
- }
-
- public void append(String var1) {
- Document var2 = ((JTextComponent)this).getDocument();
- if (var2 != null) {
- try {
- var2.insertString(var2.getLength(), var1, (AttributeSet)null);
- } catch (BadLocationException var3) {
- }
- }
-
- }
-
- protected Document createDefaultModel() {
- return new PlainDocument();
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJTextArea(this);
- }
-
- return super.accessibleContext;
- }
-
- protected int getColumnWidth() {
- if (this.columnWidth == 0) {
- FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
- this.columnWidth = var1.charWidth('m');
- }
-
- return this.columnWidth;
- }
-
- public int getColumns() {
- return this.columns;
- }
-
- public int getLineCount() {
- Element var1 = ((JTextComponent)this).getDocument().getDefaultRootElement();
- int var2 = var1.getElementCount();
- Element var3 = var1.getElement(var2 - 1);
- return var3.getEndOffset() - var3.getStartOffset() > 1 ? var2 : var2 - 1;
- }
-
- public int getLineEndOffset(int var1) throws BadLocationException {
- Element var2 = ((JTextComponent)this).getDocument().getDefaultRootElement();
- if (var1 < 0) {
- throw new BadLocationException("Negative line", -1);
- } else if (var1 >= var2.getElementCount()) {
- throw new BadLocationException("No such line", ((JTextComponent)this).getDocument().getLength() + 1);
- } else {
- Element var3 = var2.getElement(var1);
- return var3.getEndOffset();
- }
- }
-
- public int getLineOfOffset(int var1) throws BadLocationException {
- Document var2 = ((JTextComponent)this).getDocument();
- if (var1 < 0) {
- throw new BadLocationException("Can't translate offset to line", -1);
- } else if (var1 > var2.getLength()) {
- throw new BadLocationException("Can't translate offset to line", var2.getLength() + 1);
- } else {
- Element var3 = ((JTextComponent)this).getDocument().getDefaultRootElement();
- return var3.getElementIndex(var1);
- }
- }
-
- public int getLineStartOffset(int var1) throws BadLocationException {
- Element var2 = ((JTextComponent)this).getDocument().getDefaultRootElement();
- if (var1 < 0) {
- throw new BadLocationException("Negative line", -1);
- } else if (var1 >= var2.getElementCount()) {
- throw new BadLocationException("No such line", ((JTextComponent)this).getDocument().getLength() + 1);
- } else {
- Element var3 = var2.getElement(var1);
- return var3.getStartOffset();
- }
- }
-
- public boolean getLineWrap() {
- return this.wrap;
- }
-
- public Dimension getPreferredScrollableViewportSize() {
- Dimension var1 = super.getPreferredScrollableViewportSize();
- var1 = var1 == null ? new Dimension(400, 400) : var1;
- var1.width = this.columns == 0 ? var1.width : this.columns * this.getColumnWidth();
- var1.height = this.rows == 0 ? var1.height : this.rows * this.getRowHeight();
- return var1;
- }
-
- public Dimension getPreferredSize() {
- Dimension var1 = super.getPreferredSize();
- var1 = var1 == null ? new Dimension(400, 400) : var1;
- if (this.columns != 0) {
- var1.width = Math.max(var1.width, this.columns * this.getColumnWidth());
- }
-
- if (this.rows != 0) {
- var1.height = Math.max(var1.height, this.rows * this.getRowHeight());
- }
-
- return var1;
- }
-
- protected int getRowHeight() {
- if (this.rowHeight == 0) {
- FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
- this.rowHeight = var1.getHeight();
- }
-
- return this.rowHeight;
- }
-
- public int getRows() {
- return this.rows;
- }
-
- public boolean getScrollableTracksViewportWidth() {
- return this.wrap ? true : super.getScrollableTracksViewportWidth();
- }
-
- public int getScrollableUnitIncrement(Rectangle var1, int var2, int var3) {
- switch (var2) {
- case 0:
- return this.getColumnWidth();
- case 1:
- return this.getRowHeight();
- default:
- throw new IllegalArgumentException("Invalid orientation: " + var2);
- }
- }
-
- public int getTabSize() {
- int var1 = 8;
- Document var2 = ((JTextComponent)this).getDocument();
- if (var2 != null) {
- Integer var3 = (Integer)var2.getProperty("tabSize");
- if (var3 != null) {
- var1 = var3;
- }
- }
-
- return var1;
- }
-
- public String getUIClassID() {
- return "TextAreaUI";
- }
-
- public boolean getWrapStyleWord() {
- return this.word;
- }
-
- public void insert(String var1, int var2) {
- Document var3 = ((JTextComponent)this).getDocument();
- if (var3 != null) {
- try {
- var3.insertString(var2, var1, (AttributeSet)null);
- } catch (BadLocationException var5) {
- throw new IllegalArgumentException(((Throwable)var5).getMessage());
- }
- }
-
- }
-
- public boolean isManagingFocus() {
- return true;
- }
-
- protected String paramString() {
- String var1 = this.wrap ? "true" : "false";
- String var2 = this.word ? "true" : "false";
- return super.paramString() + ",colums=" + this.columns + ",columWidth=" + this.columnWidth + ",rows=" + this.rows + ",rowHeight=" + this.rowHeight + ",word=" + var2 + ",wrap=" + var1;
- }
-
- protected void processComponentKeyEvent(KeyEvent var1) {
- super.processComponentKeyEvent(var1);
- if (this.isManagingFocus() && (var1.getKeyCode() == 9 || var1.getKeyChar() == '\t')) {
- ((InputEvent)var1).consume();
- }
-
- }
-
- public void replaceRange(String var1, int var2, int var3) {
- if (var3 < var2) {
- throw new IllegalArgumentException("end before start");
- } else {
- Document var4 = ((JTextComponent)this).getDocument();
- if (var4 != null) {
- try {
- var4.remove(var2, var3 - var2);
- var4.insertString(var2, var1, (AttributeSet)null);
- } catch (BadLocationException var6) {
- throw new IllegalArgumentException(((Throwable)var6).getMessage());
- }
- }
-
- }
- }
-
- public void setColumns(int var1) {
- int var2 = this.columns;
- if (var1 < 0) {
- throw new IllegalArgumentException("columns less than zero.");
- } else {
- if (var1 != var2) {
- this.columns = var1;
- ((Container)this).invalidate();
- }
-
- }
- }
-
- public void setFont(Font var1) {
- super.setFont(var1);
- this.rowHeight = 0;
- this.columnWidth = 0;
- }
-
- public void setLineWrap(boolean var1) {
- boolean var2 = this.wrap;
- this.wrap = var1;
- ((JComponent)this).firePropertyChange("lineWrap", var2, var1);
- }
-
- public void setRows(int var1) {
- int var2 = this.rows;
- if (var1 < 0) {
- throw new IllegalArgumentException("rows less than zero.");
- } else {
- if (var1 != var2) {
- this.rows = var1;
- ((Container)this).invalidate();
- }
-
- }
- }
-
- public void setTabSize(int var1) {
- Document var2 = ((JTextComponent)this).getDocument();
- if (var2 != null) {
- int var3 = this.getTabSize();
- var2.putProperty("tabSize", new Integer(var1));
- ((JComponent)this).firePropertyChange("tabSize", var3, var1);
- }
-
- }
-
- public void setWrapStyleWord(boolean var1) {
- boolean var2 = this.word;
- this.word = var1;
- ((JComponent)this).firePropertyChange("wrapStyleWord", var2, var1);
- }
-
- private void writeObject(ObjectOutputStream var1) throws IOException {
- var1.defaultWriteObject();
- if (super.ui != null && this.getUIClassID().equals("TextAreaUI")) {
- super.ui.installUI(this);
- }
-
- }
- }
-