Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

TModelComboBox.java

00001 /*
00002 *  Name:      TModelComboBox.java
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Combo-box for model instances
00005 *  Date:      $Date: 2003/10/06 12:45:11 $
00006 *  Revision:  $Revision: 1.9 $
00007 *
00008 *  Copyright (C) 2003  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00027 package org.mpcl.nui;
00028 
00029 import java.util.Observable;
00030 import java.util.Observer;
00031 import javax.swing.JComboBox;
00032 
00033 
00039 public class TModelComboBox extends JComboBox implements Observer
00040 {
00041 
00043   private TAbstractModelToComboBoxAdapter   tModelToComboBoxAdapter;
00044 
00045 
00046   //
00047   //  C O N S T R U C T O R S
00048   //
00049 
00055   private void readFromModel()
00056   {
00057     int   iOldSelectedIndex = getSelectedIndex();
00058     int   iSize             = tModelToComboBoxAdapter.size();
00059 
00060     removeAllItems();
00061     for (int I = 0; ( I < iSize ) ;++I)
00062     {
00063       addItem (tModelToComboBoxAdapter.getText (I));
00064     }
00065     if ( iOldSelectedIndex >= 0 )
00066     {
00067       setSelectedIndex (Math.min (iSize - 1, iOldSelectedIndex));
00068     }
00069   }
00070 
00071 
00072   //
00073   //  C O N S T R U C T O R S
00074   //
00075 
00080   public TModelComboBox (TAbstractModelToComboBoxAdapter tMODEL_TO_COMBO_BOX_ADAPTER)
00081   {
00082     super();
00083     tModelToComboBoxAdapter = tMODEL_TO_COMBO_BOX_ADAPTER;
00084     tModelToComboBoxAdapter.addObserver (this);
00085     readFromModel();
00086   }
00087 
00093   public void setSelectedCode (Integer tCODE)
00094   {
00095     Integer   tCurrentCode;
00096 
00097     for (int I = 0; ( I < tModelToComboBoxAdapter.size() ) ;++I)
00098     {
00099       tCurrentCode = tModelToComboBoxAdapter.getCode (I);
00100       if ( ( tCODE == tCurrentCode ) || tCODE.equals (tCurrentCode) )
00101       {
00102         setSelectedIndex (I);
00103         break;
00104       }
00105     }
00106   }
00107 
00112   public void setSelectedCode (int iCODE)
00113   {
00114     setSelectedCode (new Integer (iCODE));
00115   }
00116 
00124   public void update (Observable tOBSERVABLE, Object tARGUMENT)
00125   {
00126     readFromModel();
00127   }
00128 
00129 
00130   //
00131   //  S E L E C T O R S
00132   //
00133 
00139   public Integer getSelectedCode()
00140   {
00141     return tModelToComboBoxAdapter.getCode (getSelectedIndex());
00142   }
00143 
00144 }  // class TModelComboBox

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18