home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / JTextField.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  7.5 KB  |  313 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.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.beans.PropertyChangeListener;
  12. import java.io.IOException;
  13. import java.io.ObjectOutputStream;
  14. import javax.accessibility.AccessibleContext;
  15. import javax.swing.text.Document;
  16. import javax.swing.text.JTextComponent;
  17. import javax.swing.text.PlainDocument;
  18. import javax.swing.text.TextAction;
  19.  
  20. public class JTextField extends JTextComponent implements SwingConstants {
  21.    private Action action;
  22.    private PropertyChangeListener actionPropertyChangeListener;
  23.    public static final String notifyAction = "notify-field-accept";
  24.    private BoundedRangeModel visibility;
  25.    private int horizontalAlignment;
  26.    private int columns;
  27.    private int columnWidth;
  28.    private String command;
  29.    private static final Action[] defaultActions = new Action[]{new NotifyAction()};
  30.    private static final String uiClassID = "TextFieldUI";
  31.    // $FF: synthetic field
  32.    static Class class$java$awt$event$ActionListener;
  33.  
  34.    public JTextField() {
  35.       this((Document)null, (String)null, 0);
  36.    }
  37.  
  38.    public JTextField(String var1) {
  39.       this((Document)null, var1, 0);
  40.    }
  41.  
  42.    public JTextField(int var1) {
  43.       this((Document)null, (String)null, var1);
  44.    }
  45.  
  46.    public JTextField(String var1, int var2) {
  47.       this((Document)null, var1, var2);
  48.    }
  49.  
  50.    public JTextField(Document var1, String var2, int var3) {
  51.       this.horizontalAlignment = 10;
  52.       if (var3 < 0) {
  53.          throw new IllegalArgumentException("columns less than zero.");
  54.       } else {
  55.          this.visibility = new DefaultBoundedRangeModel();
  56.          this.visibility.addChangeListener(new ScrollRepainter(this));
  57.          this.columns = var3;
  58.          if (var1 == null) {
  59.             var1 = this.createDefaultModel();
  60.          }
  61.  
  62.          ((JTextComponent)this).setDocument(var1);
  63.          if (var2 != null) {
  64.             ((JTextComponent)this).setText(var2);
  65.          }
  66.  
  67.       }
  68.    }
  69.  
  70.    public String getUIClassID() {
  71.       return "TextFieldUI";
  72.    }
  73.  
  74.    public boolean isValidateRoot() {
  75.       Container var1 = ((Component)this).getParent();
  76.       return !(var1 instanceof JViewport);
  77.    }
  78.  
  79.    public int getHorizontalAlignment() {
  80.       return this.horizontalAlignment;
  81.    }
  82.  
  83.    public void setHorizontalAlignment(int var1) {
  84.       if (var1 != this.horizontalAlignment) {
  85.          int var2 = this.horizontalAlignment;
  86.          if (var1 != 2 && var1 != 0 && var1 != 4 && var1 != 10 && var1 != 11) {
  87.             throw new IllegalArgumentException("horizontalAlignment");
  88.          } else {
  89.             this.horizontalAlignment = var1;
  90.             ((JComponent)this).firePropertyChange("horizontalAlignment", var2, this.horizontalAlignment);
  91.             ((Container)this).invalidate();
  92.             ((Component)this).repaint();
  93.          }
  94.       }
  95.    }
  96.  
  97.    protected Document createDefaultModel() {
  98.       return new PlainDocument();
  99.    }
  100.  
  101.    public int getColumns() {
  102.       return this.columns;
  103.    }
  104.  
  105.    public void setColumns(int var1) {
  106.       int var2 = this.columns;
  107.       if (var1 < 0) {
  108.          throw new IllegalArgumentException("columns less than zero.");
  109.       } else {
  110.          if (var1 != var2) {
  111.             this.columns = var1;
  112.             ((Container)this).invalidate();
  113.          }
  114.  
  115.       }
  116.    }
  117.  
  118.    protected int getColumnWidth() {
  119.       if (this.columnWidth == 0) {
  120.          FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
  121.          this.columnWidth = var1.charWidth('m');
  122.       }
  123.  
  124.       return this.columnWidth;
  125.    }
  126.  
  127.    public Dimension getPreferredSize() {
  128.       Object var1 = ((Component)this).getTreeLock();
  129.       synchronized(var1) {
  130.          Dimension var2 = super.getPreferredSize();
  131.          if (this.columns != 0) {
  132.             var2.width = this.columns * this.getColumnWidth();
  133.          }
  134.  
  135.          return var2;
  136.       }
  137.    }
  138.  
  139.    public void setFont(Font var1) {
  140.       super.setFont(var1);
  141.       this.columnWidth = 0;
  142.    }
  143.  
  144.    public synchronized void addActionListener(ActionListener var1) {
  145.       super.listenerList.add(class$java$awt$event$ActionListener == null ? (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")) : class$java$awt$event$ActionListener, var1);
  146.    }
  147.  
  148.    public synchronized void removeActionListener(ActionListener var1) {
  149.       if (var1 != null && this.getAction() == var1) {
  150.          this.setAction((Action)null);
  151.       } else {
  152.          super.listenerList.remove(class$java$awt$event$ActionListener == null ? (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")) : class$java$awt$event$ActionListener, var1);
  153.       }
  154.  
  155.    }
  156.  
  157.    protected void fireActionPerformed() {
  158.       Object[] var1 = super.listenerList.getListenerList();
  159.       ActionEvent var2 = new ActionEvent(this, 1001, this.command != null ? this.command : ((JTextComponent)this).getText());
  160.  
  161.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  162.          if (var1[var3] == (class$java$awt$event$ActionListener == null ? (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")) : class$java$awt$event$ActionListener)) {
  163.             ((ActionListener)var1[var3 + 1]).actionPerformed(var2);
  164.          }
  165.       }
  166.  
  167.    }
  168.  
  169.    public void setActionCommand(String var1) {
  170.       this.command = var1;
  171.    }
  172.  
  173.    public void setAction(Action var1) {
  174.       Action var2 = this.getAction();
  175.       if (this.action == null || !this.action.equals(var1)) {
  176.          this.action = var1;
  177.          if (var2 != null) {
  178.             this.removeActionListener(var2);
  179.             var2.removePropertyChangeListener(this.actionPropertyChangeListener);
  180.             this.actionPropertyChangeListener = null;
  181.          }
  182.  
  183.          this.configurePropertiesFromAction(this.action);
  184.          if (this.action != null) {
  185.             if (!this.isListener(class$java$awt$event$ActionListener == null ? (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")) : class$java$awt$event$ActionListener, this.action)) {
  186.                this.addActionListener(this.action);
  187.             }
  188.  
  189.             this.actionPropertyChangeListener = this.createActionPropertyChangeListener(this.action);
  190.             this.action.addPropertyChangeListener(this.actionPropertyChangeListener);
  191.          }
  192.  
  193.          ((JComponent)this).firePropertyChange("action", var2, this.action);
  194.          ((JComponent)this).revalidate();
  195.          ((Component)this).repaint();
  196.       }
  197.  
  198.    }
  199.  
  200.    private boolean isListener(Class var1, ActionListener var2) {
  201.       boolean var3 = false;
  202.       Object[] var4 = super.listenerList.getListenerList();
  203.  
  204.       for(int var5 = var4.length - 2; var5 >= 0; var5 -= 2) {
  205.          if (var4[var5] == var1 && var4[var5 + 1] == var2) {
  206.             var3 = true;
  207.          }
  208.       }
  209.  
  210.       return var3;
  211.    }
  212.  
  213.    public Action getAction() {
  214.       return this.action;
  215.    }
  216.  
  217.    protected void configurePropertiesFromAction(Action var1) {
  218.       ((JComponent)this).setEnabled(var1 != null ? var1.isEnabled() : true);
  219.       ((JComponent)this).setToolTipText(var1 != null ? (String)var1.getValue("ShortDescription") : null);
  220.    }
  221.  
  222.    protected PropertyChangeListener createActionPropertyChangeListener(Action var1) {
  223.       return new 1(this, this, var1);
  224.    }
  225.  
  226.    public Action[] getActions() {
  227.       return TextAction.augmentList(super.getActions(), defaultActions);
  228.    }
  229.  
  230.    public void postActionEvent() {
  231.       this.fireActionPerformed();
  232.    }
  233.  
  234.    public BoundedRangeModel getHorizontalVisibility() {
  235.       return this.visibility;
  236.    }
  237.  
  238.    public int getScrollOffset() {
  239.       return this.visibility.getValue();
  240.    }
  241.  
  242.    public void setScrollOffset(int var1) {
  243.       this.visibility.setValue(var1);
  244.    }
  245.  
  246.    public void scrollRectToVisible(Rectangle var1) {
  247.       int var2 = var1.x + this.visibility.getValue();
  248.       if (var2 < this.visibility.getValue()) {
  249.          this.visibility.setValue(var2 - 2);
  250.       } else if (var2 > this.visibility.getValue() + this.visibility.getExtent()) {
  251.          this.visibility.setValue(var2 - this.visibility.getExtent() + 2);
  252.       }
  253.  
  254.    }
  255.  
  256.    boolean hasActionListener() {
  257.       Object[] var1 = super.listenerList.getListenerList();
  258.  
  259.       for(int var2 = var1.length - 2; var2 >= 0; var2 -= 2) {
  260.          if (var1[var2] == (class$java$awt$event$ActionListener == null ? (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")) : class$java$awt$event$ActionListener)) {
  261.             return true;
  262.          }
  263.       }
  264.  
  265.       return false;
  266.    }
  267.  
  268.    private void writeObject(ObjectOutputStream var1) throws IOException {
  269.       var1.defaultWriteObject();
  270.       if (super.ui != null && this.getUIClassID().equals("TextFieldUI")) {
  271.          super.ui.installUI(this);
  272.       }
  273.  
  274.    }
  275.  
  276.    protected String paramString() {
  277.       String var1;
  278.       if (this.horizontalAlignment == 2) {
  279.          var1 = "LEFT";
  280.       } else if (this.horizontalAlignment == 0) {
  281.          var1 = "CENTER";
  282.       } else if (this.horizontalAlignment == 4) {
  283.          var1 = "RIGHT";
  284.       } else if (this.horizontalAlignment == 10) {
  285.          var1 = "LEADING";
  286.       } else if (this.horizontalAlignment == 11) {
  287.          var1 = "TRAILING";
  288.       } else {
  289.          var1 = "";
  290.       }
  291.  
  292.       String var2 = this.command != null ? this.command : "";
  293.       return super.paramString() + ",columns=" + this.columns + ",columnWidth=" + this.columnWidth + ",command=" + var2 + ",horizontalAlignment=" + var1;
  294.    }
  295.  
  296.    public AccessibleContext getAccessibleContext() {
  297.       if (super.accessibleContext == null) {
  298.          super.accessibleContext = new AccessibleJTextField(this);
  299.       }
  300.  
  301.       return super.accessibleContext;
  302.    }
  303.  
  304.    // $FF: synthetic method
  305.    static Class class$(String var0) {
  306.       try {
  307.          return Class.forName(var0);
  308.       } catch (ClassNotFoundException var2) {
  309.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  310.       }
  311.    }
  312. }
  313.