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

  1. /*
  2.  * @(#)MotifTextAreaUI.java    1.13 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.motif;
  21.  
  22. import java.beans.*;
  23. import java.awt.*;
  24. import java.awt.event.KeyEvent;
  25. import java.awt.event.InputEvent;
  26. import com.sun.java.swing.*;
  27. import com.sun.java.swing.text.*;
  28. import com.sun.java.swing.plaf.*;
  29. import com.sun.java.swing.plaf.basic.BasicTextAreaUI;
  30.  
  31. /**
  32.  * Provides the look and feel for a plain text editor.  In this
  33.  * implementation the default UI is extended to act as a simple
  34.  * view factory.
  35.  * <p>
  36.  * Warning: serialized objects of this class will not be compatible with
  37.  * future swing releases.  The current serialization support is appropriate
  38.  * for short term storage or RMI between Swing1.0 applications.  It will
  39.  * not be possible to load serialized Swing1.0 objects with future releases
  40.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  41.  * baseline for the serialized form of Swing objects.
  42.  *
  43.  * @author  Timothy Prinzing
  44.  * @version 1.13 02/02/98
  45.  */
  46. public class MotifTextAreaUI extends MotifTextUI {
  47.  
  48.     /**
  49.      * Creates a UI for a JTextArea.
  50.      *
  51.      * @param ta a text area
  52.      * @return the UI
  53.      */
  54.     public static ComponentUI createUI(JComponent ta) {
  55.         return new MotifTextAreaUI();
  56.     }
  57.  
  58.     /**
  59.      * Fetches the name used as a key to lookup properties through the
  60.      * UIManager.  This is used as a prefix to all the standard
  61.      * text properties.
  62.      *
  63.      * @return the name
  64.      */
  65.     protected String getPropertyPrefix() {
  66.     return "TextArea";
  67.     }
  68.  
  69.     /**
  70.      * This method gets called when a bound property is changed
  71.      * on the associated JTextComponent.  This is a hook
  72.      * which UI implementations may change to reflect how the
  73.      * UI displays bound properties of JTextComponent subclasses.
  74.      * This is implemented to rebuild the View when the
  75.      * <em>WrapLine</em> property changes.
  76.      */
  77.     protected void propertyChange(PropertyChangeEvent evt) {
  78.     if (evt.getPropertyName().equals("LineWrap")) {
  79.         modelChanged();
  80.     }
  81.     }
  82.  
  83.     /**
  84.      * Creates the view for an element.
  85.      *
  86.      * @param elem the element
  87.      * @return the view
  88.      */
  89.     public View create(Element elem) {
  90.     JTextComponent c = getComponent();
  91.     if (c instanceof JTextArea) {
  92.         JTextArea area = (JTextArea) c;
  93.         View v;
  94.         if (area.getLineWrap()) {
  95.         v = new WrappedPlainView(elem);
  96.         } else {
  97.         v = new PlainView(elem);
  98.         }
  99.         return v;
  100.     }
  101.     return null;
  102.     }
  103.     
  104.     /**
  105.      * Loads the given keymap with default settings
  106.      * appropriate for the UI being created.  This
  107.      * is implemented to do the superclass behavior 
  108.      * as well as load the settings appropriate for
  109.      * a multi-line text editor.
  110.      *
  111.      * @param map the keymap
  112.      */
  113.     protected void loadDefaultKeymap(Keymap map) {
  114.     super.loadDefaultKeymap(map);
  115.     JTextComponent.loadKeymap(map, multilineBindings, 
  116.                      getComponent().getActions());
  117.     }
  118.  
  119.     /**
  120.      * Default bindings multi-line editor keymaps implementing the Motif feel.
  121.      */
  122.     static final JTextComponent.KeyBinding[] multilineBindings = {
  123.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0),
  124.                        DefaultEditorKit.pageUpAction),
  125.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
  126.                        DefaultEditorKit.pageDownAction),
  127.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
  128.                        DefaultEditorKit.insertBreakAction),
  129.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
  130.                        DefaultEditorKit.insertTabAction),
  131.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V, 
  132.                                     InputEvent.ALT_MASK),
  133.                          DefaultEditorKit.pageUpAction),
  134.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V,
  135.                                     InputEvent.CTRL_MASK),
  136.                          DefaultEditorKit.pageDownAction),
  137.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_N,
  138.                                     InputEvent.CTRL_MASK),
  139.                          DefaultEditorKit.downAction),
  140.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_P,
  141.                                     InputEvent.CTRL_MASK),
  142.                          DefaultEditorKit.upAction),
  143.     new JTextComponent.KeyBinding(
  144.         KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK),
  145.         DefaultEditorKit.beginAction),
  146.     new JTextComponent.KeyBinding(
  147.         KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK),
  148.         DefaultEditorKit.endAction),
  149.     };
  150.  
  151. }
  152.