home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / jfc.bin / BasicTextFieldUI.java < prev    next >
Text File  |  1998-02-26  |  4KB  |  146 lines

  1. /*
  2.  * @(#)BasicTextFieldUI.java    1.71 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.plaf.basic;
  21.  
  22. import java.awt.*;
  23. import java.awt.event.KeyEvent;
  24. import java.awt.event.FocusEvent;
  25. import java.awt.event.InputEvent;
  26. import com.sun.java.swing.*;
  27. import com.sun.java.swing.border.*;
  28. import com.sun.java.swing.event.*;
  29. import com.sun.java.swing.text.*;
  30. import com.sun.java.swing.plaf.*;
  31.  
  32. /**
  33.  * Basis of a look and feel for a JTextField.
  34.  * <p>
  35.  * Warning: serialized objects of this class will not be compatible with
  36.  * future swing releases.  The current serialization support is appropriate
  37.  * for short term storage or RMI between Swing1.0 applications.  It will
  38.  * not be possible to load serialized Swing1.0 objects with future releases
  39.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  40.  * baseline for the serialized form of Swing objects.
  41.  *
  42.  * @author  Timothy Prinzing
  43.  * @version 1.71 02/02/98
  44.  */
  45. public class BasicTextFieldUI extends BasicTextUI {
  46.  
  47.     static Keymap defaultKeymap = null;
  48.  
  49.     /**
  50.      * Creates a UI for a JTextField.
  51.      *
  52.      * @param c the text field
  53.      * @return the UI
  54.      */
  55.     public static ComponentUI createUI(JComponent c) {
  56.         return new BasicTextFieldUI();
  57.     }
  58.  
  59.     /**
  60.      * Creates a new BasicTextFieldUI.
  61.      */
  62.     public BasicTextFieldUI() {
  63.     super();
  64.     }
  65.  
  66.     /**
  67.      * Fetches the name used as a key to lookup properties through the
  68.      * UIManager.  This is used as a prefix to all the standard
  69.      * text properties.
  70.      *
  71.      * @return the name
  72.      */
  73.     protected String getPropertyPrefix() {
  74.     return "TextField";
  75.     }
  76.  
  77.     /**
  78.      * Creates the caret for a field.
  79.      *
  80.      * @return the caret
  81.      */
  82.     protected Caret createCaret() {
  83.     return new BasicFieldCaret();
  84.     }
  85.  
  86.     /**
  87.      * Loads the given keymap with default settings
  88.      * appropriate for the UI being created.  This
  89.      * is implemented to do the superclass behavior 
  90.      * as well as load the settings appropriate for
  91.      * a single-line text editor.
  92.      *
  93.      * @param map the keymap to load
  94.      */
  95.     protected void loadDefaultKeymap(Keymap map) {
  96.     super.loadDefaultKeymap(map);
  97.     JTextComponent.loadKeymap(map, fieldBindings, 
  98.                      getComponent().getActions());
  99.     }
  100.  
  101.     /**
  102.      * Default bindings for the default keymap if no other bindings
  103.      * are given.  
  104.      */
  105.     static final JTextComponent.KeyBinding[] fieldBindings = {
  106.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
  107.                        JTextField.notifyAction)
  108.     };
  109.  
  110.     /**
  111.      * Creates a view based on an element.
  112.      *
  113.      * @param elem the element
  114.      * @return the view
  115.      */
  116.     public View create(Element elem) {
  117.     return new FieldView(elem);
  118.     }
  119.  
  120.     /**
  121.      * BasicFieldCaret has different scrolling behavior than
  122.      * DefaultCaret, selects the field when focus enters it, and
  123.      * deselects the field when focus leaves.
  124.      */
  125.     class BasicFieldCaret extends DefaultCaret implements UIResource {
  126.  
  127.     public BasicFieldCaret() {
  128.         super();
  129.     }
  130.  
  131.     /**
  132.      * Called when the component containing the caret loses
  133.      * focus.  This is implemented to set the caret to visibility
  134.      * to false, and to set the selection visibility to false.
  135.      *
  136.      * @param e the focus event
  137.      * @see FocusListener#focusLost
  138.      */
  139.         public void focusLost(FocusEvent e) {
  140.         setDot(getDot());
  141.         setVisible(false);
  142.     }
  143.     }
  144.  
  145. }
  146.