home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
jfc.bin
/
BasicTextFieldUI.java
< prev
next >
Wrap
Text File
|
1998-02-26
|
4KB
|
146 lines
/*
* @(#)BasicTextFieldUI.java 1.71 98/02/02
*
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
package com.sun.java.swing.plaf.basic;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.FocusEvent;
import java.awt.event.InputEvent;
import com.sun.java.swing.*;
import com.sun.java.swing.border.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.text.*;
import com.sun.java.swing.plaf.*;
/**
* Basis of a look and feel for a JTextField.
* <p>
* Warning: serialized objects of this class will not be compatible with
* future swing releases. The current serialization support is appropriate
* for short term storage or RMI between Swing1.0 applications. It will
* not be possible to load serialized Swing1.0 objects with future releases
* of Swing. The JDK1.2 release of Swing will be the compatibility
* baseline for the serialized form of Swing objects.
*
* @author Timothy Prinzing
* @version 1.71 02/02/98
*/
public class BasicTextFieldUI extends BasicTextUI {
static Keymap defaultKeymap = null;
/**
* Creates a UI for a JTextField.
*
* @param c the text field
* @return the UI
*/
public static ComponentUI createUI(JComponent c) {
return new BasicTextFieldUI();
}
/**
* Creates a new BasicTextFieldUI.
*/
public BasicTextFieldUI() {
super();
}
/**
* Fetches the name used as a key to lookup properties through the
* UIManager. This is used as a prefix to all the standard
* text properties.
*
* @return the name
*/
protected String getPropertyPrefix() {
return "TextField";
}
/**
* Creates the caret for a field.
*
* @return the caret
*/
protected Caret createCaret() {
return new BasicFieldCaret();
}
/**
* Loads the given keymap with default settings
* appropriate for the UI being created. This
* is implemented to do the superclass behavior
* as well as load the settings appropriate for
* a single-line text editor.
*
* @param map the keymap to load
*/
protected void loadDefaultKeymap(Keymap map) {
super.loadDefaultKeymap(map);
JTextComponent.loadKeymap(map, fieldBindings,
getComponent().getActions());
}
/**
* Default bindings for the default keymap if no other bindings
* are given.
*/
static final JTextComponent.KeyBinding[] fieldBindings = {
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
JTextField.notifyAction)
};
/**
* Creates a view based on an element.
*
* @param elem the element
* @return the view
*/
public View create(Element elem) {
return new FieldView(elem);
}
/**
* BasicFieldCaret has different scrolling behavior than
* DefaultCaret, selects the field when focus enters it, and
* deselects the field when focus leaves.
*/
class BasicFieldCaret extends DefaultCaret implements UIResource {
public BasicFieldCaret() {
super();
}
/**
* Called when the component containing the caret loses
* focus. This is implemented to set the caret to visibility
* to false, and to set the selection visibility to false.
*
* @param e the focus event
* @see FocusListener#focusLost
*/
public void focusLost(FocusEvent e) {
setDot(getDot());
setVisible(false);
}
}
}