Source for javax.swing.plaf.basic.BasicComboBoxEditor

   1: /* BasicComboBoxEditor.java --
   2:    Copyright (C) 2004, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.plaf.basic;
  40: 
  41: import java.awt.Component;
  42: import java.awt.event.ActionListener;
  43: import java.awt.event.FocusEvent;
  44: import java.awt.event.FocusListener;
  45: 
  46: import javax.swing.ComboBoxEditor;
  47: import javax.swing.JTextField;
  48: import javax.swing.border.EmptyBorder;
  49: 
  50: /**
  51:  * This is a component that is responsible for displaying/editting  selected
  52:  * item in comboBox. By default, the  JTextField is returned as
  53:  * BasicComboBoxEditor.
  54:  *
  55:  * @author Olga Rodimina
  56:  */
  57: public class BasicComboBoxEditor extends Object implements ComboBoxEditor,
  58:                                                            FocusListener
  59: {
  60:   protected JTextField editor;
  61: 
  62:   /**
  63:    * Creates a new BasicComboBoxEditor object.
  64:    */
  65:   public BasicComboBoxEditor()
  66:   {
  67:     editor = new JTextField();
  68:     editor.setBorder(new EmptyBorder(1, 1, 1, 1));
  69:   }
  70: 
  71:   /**
  72:    * This method returns textfield that will be used by the combo  box to
  73:    * display/edit currently selected item in the combo box.
  74:    *
  75:    * @return textfield that will be used by the combo box to  display/edit
  76:    *         currently selected item
  77:    */
  78:   public Component getEditorComponent()
  79:   {
  80:     return editor;
  81:   }
  82: 
  83:   /**
  84:    * Sets item that should be edited when any editing operation is performed
  85:    * by the user. The value is always equal to the currently selected value
  86:    * in the combo box. Thus whenever a different value is selected from the
  87:    * combo box list then this method should be  called to change editing
  88:    * item to the new selected item.
  89:    *
  90:    * @param item item that is currently selected in the combo box
  91:    */
  92:   public void setItem(Object item)
  93:   {
  94:     editor.setText(item.toString());
  95:   }
  96: 
  97:   /**
  98:    * This method returns item that is currently editable.
  99:    *
 100:    * @return item in the combo box that is currently editable
 101:    */
 102:   public Object getItem()
 103:   {
 104:     return editor.getText();
 105:   }
 106: 
 107:   public void selectAll()
 108:   {
 109:     editor.selectAll();
 110:   }
 111: 
 112:   /**
 113:    * This method is called when textfield gains focus. This will enable
 114:    * editing of the selected item.
 115:    *
 116:    * @param e the FocusEvent describing change in focus.
 117:    */
 118:   public void focusGained(FocusEvent e)
 119:   {
 120:     // FIXME: Need to implement
 121:   }
 122: 
 123:   /**
 124:    * This method is called when textfield loses focus. If during this time any
 125:    * editting operation was performed by the user, then it will be cancelled
 126:    * and selected item will not be changed.
 127:    *
 128:    * @param e the FocusEvent describing change in focus
 129:    */
 130:   public void focusLost(FocusEvent e)
 131:   {
 132:     // FIXME: Need to implement
 133:   }
 134: 
 135:   /**
 136:    * This method adds actionListener to the editor. If the user will edit
 137:    * currently selected item in the textfield and pressEnter, then action
 138:    * will be performed. The actionPerformed of this ActionListener should
 139:    * change the selected item of the comboBox to the newly editted  selected
 140:    * item.
 141:    *
 142:    * @param l the ActionListener responsible for changing selected item of the
 143:    *        combo box when it is editted by the user.
 144:    */
 145:   public void addActionListener(ActionListener l)
 146:   {
 147:     // FIXME: Need to implement
 148:   }
 149: 
 150:   /**
 151:    * This method removes actionListener from the textfield.
 152:    *
 153:    * @param l the ActionListener to remove from the textfield.
 154:    */
 155:   public void removeActionListener(ActionListener l)
 156:   {
 157:     // FIXME: Need to implement
 158:   }
 159: 
 160:   public static class UIResource extends BasicComboBoxEditor
 161:     implements javax.swing.plaf.UIResource
 162:   {
 163:     /**
 164:      * Creates a new UIResource object.
 165:      */
 166:     public UIResource()
 167:     {
 168:     }
 169:   }
 170: }