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

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.accessibility.AccessibleContext;
  4. import com.sun.java.swing.text.Document;
  5. import com.sun.java.swing.text.JTextComponent;
  6. import com.sun.java.swing.text.PlainDocument;
  7. import com.sun.java.swing.text.TextAction;
  8. import java.awt.Component;
  9. import java.awt.Container;
  10. import java.awt.Dimension;
  11. import java.awt.Font;
  12. import java.awt.FontMetrics;
  13. import java.awt.Rectangle;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16.  
  17. public class JTextField extends JTextComponent implements SwingConstants {
  18.    public static final String notifyAction = "notify-field-accept";
  19.    private BoundedRangeModel visibility;
  20.    private int horizontalAlignment;
  21.    private int columns;
  22.    private int columnWidth;
  23.    private String command;
  24.    private static final String base = "textfield";
  25.    private static int nameCounter;
  26.    private static final Action[] defaultActions = new Action[]{new NotifyAction()};
  27.    // $FF: synthetic field
  28.    static Class class$java$awt$event$ActionListener;
  29.  
  30.    public JTextField() {
  31.       this((Document)null, (String)null, 0);
  32.    }
  33.  
  34.    public JTextField(String var1) {
  35.       this((Document)null, var1, 0);
  36.    }
  37.  
  38.    public JTextField(int var1) {
  39.       this((Document)null, (String)null, var1);
  40.    }
  41.  
  42.    public JTextField(String var1, int var2) {
  43.       this((Document)null, var1, var2);
  44.    }
  45.  
  46.    public JTextField(Document var1, String var2, int var3) {
  47.       this.horizontalAlignment = 2;
  48.       ((Component)this).setName("textfield" + nameCounter++);
  49.       if (var3 < 0) {
  50.          throw new IllegalArgumentException("columns less than zero.");
  51.       } else {
  52.          this.visibility = new DefaultBoundedRangeModel();
  53.          this.visibility.addChangeListener(new ScrollRepainter(this));
  54.          this.columns = var3;
  55.          if (var1 == null) {
  56.             var1 = this.createDefaultModel();
  57.          }
  58.  
  59.          ((JTextComponent)this).setDocument(var1);
  60.          if (var2 != null) {
  61.             ((JTextComponent)this).setText(var2);
  62.          }
  63.  
  64.       }
  65.    }
  66.  
  67.    public String getUIClassID() {
  68.       return "TextFieldUI";
  69.    }
  70.  
  71.    public int getHorizontalAlignment() {
  72.       return this.horizontalAlignment;
  73.    }
  74.  
  75.    public void setHorizontalAlignment(int var1) {
  76.       if (var1 != this.horizontalAlignment) {
  77.          int var2 = this.horizontalAlignment;
  78.          if (var1 != 2 && var1 != 0 && var1 != 4) {
  79.             throw new IllegalArgumentException("horizontalAlignment");
  80.          } else {
  81.             this.horizontalAlignment = var1;
  82.             ((JComponent)this).firePropertyChange("horizontalAlignment", var2, this.horizontalAlignment);
  83.             ((Container)this).invalidate();
  84.             ((Component)this).repaint();
  85.          }
  86.       }
  87.    }
  88.  
  89.    protected Document createDefaultModel() {
  90.       return new PlainDocument();
  91.    }
  92.  
  93.    public int getColumns() {
  94.       return this.columns;
  95.    }
  96.  
  97.    public void setColumns(int var1) {
  98.       int var2 = this.columns;
  99.       if (var1 < 0) {
  100.          throw new IllegalArgumentException("columns less than zero.");
  101.       } else {
  102.          if (var1 != var2) {
  103.             this.columns = var1;
  104.             ((Container)this).invalidate();
  105.          }
  106.  
  107.       }
  108.    }
  109.  
  110.    protected int getColumnWidth() {
  111.       if (this.columnWidth == 0) {
  112.          FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
  113.          this.columnWidth = var1.charWidth('m');
  114.       }
  115.  
  116.       return this.columnWidth;
  117.    }
  118.  
  119.    public Dimension getPreferredSize() {
  120.       Object var2 = ((Component)this).getTreeLock();
  121.       synchronized(var2){}
  122.  
  123.       Dimension var1;
  124.       try {
  125.          Dimension var4 = super.getPreferredSize();
  126.          if (this.columns != 0) {
  127.             var4.width = this.columns * this.getColumnWidth();
  128.          }
  129.  
  130.          var1 = var4;
  131.       } catch (Throwable var6) {
  132.          throw var6;
  133.       }
  134.  
  135.       return var1;
  136.    }
  137.  
  138.    public Dimension getMinimumSize() {
  139.       return this.getPreferredSize();
  140.    }
  141.  
  142.    public void setFont(Font var1) {
  143.       super.setFont(var1);
  144.       this.columnWidth = 0;
  145.       ((JComponent)this).revalidate();
  146.    }
  147.  
  148.    public synchronized void addActionListener(ActionListener var1) {
  149.       super.listenerList.add(class$java$awt$event$ActionListener != null ? class$java$awt$event$ActionListener : (class$java$awt$event$ActionListener = JComponent.class$("java.awt.event.ActionListener")), var1);
  150.    }
  151.  
  152.    public synchronized void removeActionListener(ActionListener var1) {
  153.       super.listenerList.remove(class$java$awt$event$ActionListener != null ? class$java$awt$event$ActionListener : (class$java$awt$event$ActionListener = JComponent.class$("java.awt.event.ActionListener")), var1);
  154.    }
  155.  
  156.    protected void fireActionPerformed() {
  157.       Object[] var1 = super.listenerList.getListenerList();
  158.       ActionEvent var2 = new ActionEvent(this, 1001, this.command != null ? this.command : ((JTextComponent)this).getText());
  159.  
  160.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  161.          if (var1[var3] == (class$java$awt$event$ActionListener != null ? class$java$awt$event$ActionListener : (class$java$awt$event$ActionListener = JComponent.class$("java.awt.event.ActionListener")))) {
  162.             ((ActionListener)var1[var3 + 1]).actionPerformed(var2);
  163.          }
  164.       }
  165.  
  166.    }
  167.  
  168.    public void setActionCommand(String var1) {
  169.       this.command = var1;
  170.    }
  171.  
  172.    public Action[] getActions() {
  173.       return TextAction.augmentList(super.getActions(), defaultActions);
  174.    }
  175.  
  176.    public void postActionEvent() {
  177.       this.fireActionPerformed();
  178.    }
  179.  
  180.    protected String paramString() {
  181.       return super.paramString() + ",columns=" + this.columns + ",command=" + this.command;
  182.    }
  183.  
  184.    public BoundedRangeModel getHorizontalVisibility() {
  185.       return this.visibility;
  186.    }
  187.  
  188.    public int getScrollOffset() {
  189.       return this.visibility.getValue();
  190.    }
  191.  
  192.    public void setScrollOffset(int var1) {
  193.       this.visibility.setValue(var1);
  194.    }
  195.  
  196.    public void scrollRectToVisible(Rectangle var1) {
  197.       int var2 = var1.x + this.visibility.getValue();
  198.       if (var2 < this.visibility.getValue()) {
  199.          this.visibility.setValue(var2 - 2);
  200.       } else {
  201.          if (var2 > this.visibility.getValue() + this.visibility.getExtent()) {
  202.             this.visibility.setValue(var2 - this.visibility.getExtent() + 2);
  203.          }
  204.  
  205.       }
  206.    }
  207.  
  208.    public AccessibleContext getAccessibleContext() {
  209.       if (super.accessibleContext == null) {
  210.          super.accessibleContext = new AccessibleJTextField(this);
  211.       }
  212.  
  213.       return super.accessibleContext;
  214.    }
  215. }
  216.