home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / awt / FocusingTextField.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  2.8 KB  |  106 lines

  1. /*
  2.  * @(#)FocusingTextField.java    1.3 95/09/17 Herb Jellinek
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.awt;
  21.  
  22. import java.awt.*;
  23.  
  24. /**
  25.  * FocusingTextField: a subclass of java.awt.TextField that handles moving the
  26.  * input focus from field to field, as when the user hits 'return.'
  27.  *
  28.  * @version 1.3, 09/17/95
  29.  * @author Herb Jellinek
  30.  */
  31.  
  32. public class FocusingTextField extends TextField {
  33.  
  34.     /** The field to move to on 'return' - can be null. */
  35.     TextField next;
  36.  
  37.     /** If true, select the contents of the field when it gets the focus. */
  38.     boolean willSelect;
  39.  
  40.     /**
  41.      * Create a FocusingTextField.
  42.      * @param cols number of columns of text.
  43.      */
  44.     public FocusingTextField(int cols) {
  45.     super("", cols);
  46.     }
  47.  
  48.     /**
  49.      * Create a FocusingTextField.
  50.      * @param cols number of columns of text.
  51.      * @param willSelect if true, will select all contents of field when
  52.      * focus is gained.
  53.      */
  54.     public FocusingTextField(int cols, boolean willSelect) {
  55.     this(cols);
  56.     this.willSelect = willSelect;
  57.     }
  58.       
  59.     public void setWillSelect(boolean will) {
  60.     willSelect = will;
  61.     }
  62.  
  63.     public boolean getWillSelect() {
  64.     return willSelect;
  65.     }
  66.     
  67.     /**
  68.      * Call this to set the next field to receive the input focus.
  69.      * @param next the next TextField in order - can be null.
  70.      */
  71.     public void setNextField(TextField next) {
  72.     this.next = next;
  73.     }
  74.     
  75.     /**
  76.      * We got the focus.  If willSelect is true, select everything.
  77.      */
  78.     public boolean gotFocus(Event e, Object arg) {
  79.     if (willSelect) {
  80.         select(0, getText().length());
  81.     }
  82.     return true;
  83.     }
  84.     
  85.     /**
  86.      * We lost the focus.  If willSelect is true, deselect everything.
  87.      */
  88.     public boolean lostFocus(Event e, Object arg) {
  89.     if (willSelect) {
  90.         select(0, 0);
  91.     }
  92.     return true;
  93.     }
  94.  
  95.     /**
  96.      * Pass the focus to the next guy, if any.
  97.      */
  98.     public void nextFocus() {
  99.     if (next != null) {
  100.         next.requestFocus();
  101.     }
  102.     super.nextFocus();
  103.     }
  104. }
  105.  
  106.