home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
jfc.bin
/
BasicTextAreaUI.java
< prev
next >
Wrap
Text File
|
1998-02-26
|
4KB
|
140 lines
/*
* @(#)BasicTextAreaUI.java 1.49 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.beans.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
import com.sun.java.swing.*;
import com.sun.java.swing.text.*;
import com.sun.java.swing.plaf.*;
/**
* Provides the look and feel for a plain text editor. In this
* implementation the default UI is extended to act as a simple
* view factory.
* <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.49 02/02/98
*/
public class BasicTextAreaUI extends BasicTextUI {
/**
* Creates a UI for a JTextArea.
*
* @param ta a text area
* @return the UI
*/
public static ComponentUI createUI(JComponent ta) {
return new BasicTextAreaUI();
}
/**
* Constructs a new BasicTextAreaUI object.
*/
public BasicTextAreaUI() {
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 "TextArea";
}
/**
* This method gets called when a bound property is changed
* on the associated JTextComponent. This is a hook
* which UI implementations may change to reflect how the
* UI displays bound properties of JTextComponent subclasses.
* This is implemented to rebuild the View when the
* <em>WrapLine</em> property changes.
*/
protected void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("LineWrap")) {
modelChanged();
}
}
/**
* Creates the view for an element.
*
* @param elem the element
* @return the view
*/
public View create(Element elem) {
JTextComponent c = getComponent();
if (c instanceof JTextArea) {
JTextArea area = (JTextArea) c;
View v;
if (area.getLineWrap()) {
v = new WrappedPlainView(elem);
} else {
v = new PlainView(elem);
}
return v;
}
return null;
}
/**
* 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 multi-line text editor.
*
* @param map the keymap to load
*/
protected void loadDefaultKeymap(Keymap map) {
super.loadDefaultKeymap(map);
JTextComponent.loadKeymap(map, multilineBindings,
getComponent().getActions());
}
/**
* Default bindings multi-line editor keymaps.
*/
static final JTextComponent.KeyBinding[] multilineBindings = {
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0),
DefaultEditorKit.pageUpAction),
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
DefaultEditorKit.pageDownAction),
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
DefaultEditorKit.insertBreakAction),
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
DefaultEditorKit.insertTabAction)
};
}