001    /** =====================================================================       
002    *
003    *  File Name : $Id: LabelTextBox.java,v 1.4 2007/12/17 10:34:13 cb Exp $
004    *
005    *  Description
006    *  -----------
007    *
008    *  See javadoc comment 
009    * 
010    *  =====================================================================
011    *
012    *   @Author : Craige Bevil 
013    *             Control Software Group
014    *             Isaac Newton Group of Telescopes
015    *
016    *  =====================================================================
017    *
018    *     Modification Log
019    *
020    *     Vers         Date        Author       Reason
021    *     ----         ----        ------       ------
022    *      1            3 Jul 2007 C.Bevil      First Release
023    *
024    *     Commissioning Notes
025    *     -------------------
026    *
027    *     None
028    *     
029    *  =====================================================================
030    *
031    *     @Version   : $Id: LabelTextBox.java,v 1.4 2007/12/17 10:34:13 cb Exp $
032    *
033    *     @Author    : $Author: cb $
034    *
035    *     Header     : $Header: /opt/INGsrc/src/CVS/softproj/FaultDatabase/src/FaultDatabase/FaultDatabase/src/GWTApplication/client/LabelTextBox.java,v 1.4 2007/12/17 10:34:13 cb Exp $
036    *
037    *     Log        : $Log: LabelTextBox.java,v $
038    *     Log        : Revision 1.4  2007/12/17 10:34:13  cb
039    *     Log        : Added the ability to set the focus to the text entry widget
040    *     Log        :
041    *     Log        : Revision 1.3  2007/08/17 14:26:42  cb
042    *     Log        : Updated for lastest prototype incorporating a lot of Nikos comments
043    *     Log        :
044    *     Log        : Revision 1.2  2007/07/13 10:54:06  cb
045    *     Log        : Complete interface prototype
046    *     Log        :
047    *     Log        : Revision 1.1.1.1  2007/06/01 08:33:26  cb
048    *     Log        : Imported using TkCVS
049    *     Log        :
050    *
051    * =====================================================================*/
052    
053    package GWTApplication.client;
054    
055    import com.google.gwt.user.client.*;
056    import com.google.gwt.user.client.rpc.*;
057    import com.google.gwt.user.client.ui.*;
058    import com.google.gwt.user.client.ui.FlexTable.*;
059    
060    /**
061     *  This is a composite Widget which is comprised of a label and a
062     *  text box into which the user can enter free-format text.  I have
063     *  purposefully allowed the caller to access the widgets in order to
064     *  simplify the creation of the class.
065     *  @author Craige Bevil
066     *  @version $Id: LabelTextBox.java,v 1.4 2007/12/17 10:34:13 cb Exp $
067     */
068    
069    class LabelTextBox extends Composite {
070        
071        /**
072         * This is the container panel 
073         */
074        
075        CellPanel containerPanel;
076        
077        /**
078         *  This static is used to indicate that the label and the text
079         *  box should be packed in a horizontal manner
080         */
081        
082        public static final int HORIZONTAL = 0;
083        
084        /**
085         * This static is used to indicate that the label and the text box
086         * should be packed in a vertical manner
087         */
088         
089         public static final int VERTICAL   = 1;
090    
091        /**
092          * This is the text box widget which is used To enter free-form text into. 
093          */
094          
095        public TextBox textBox = new TextBox();
096       
097        /**
098         * This is the label widget which is associated with the text box
099         */
100        
101        public Label label     = new Label();
102        
103        /**
104         * This is the constructor for the class
105         * @param Orientation This should be one of the above statics VERTICAL or HORIZONTAL
106         */
107      
108        LabelTextBox (final int Orientation) {
109    
110            label.setWidth("100%");
111            textBox.setWidth("100%");
112    
113            if (Orientation == HORIZONTAL) {
114    
115                final HorizontalPanel panel = new HorizontalPanel();
116                
117                panel.add(label);
118                panel.add(textBox);
119                initWidget(panel);              
120                containerPanel = panel;
121                        
122            } else {
123    
124                final VerticalPanel panel = new VerticalPanel();
125                
126                panel.add(label);
127                panel.add(textBox);
128                initWidget(panel);  
129                containerPanel = panel;                 
130            }
131        }    
132        
133        /**
134         * This is a convenience method which allows the caller to set the
135         * width of both the label and the text box simultaneously.
136         * @param labelWidth this is the expected width of the label and should be specified in a valid CSS unit. 
137         * @param textBoxWidth this is the expected width of the text box and should be specified in a valid CSS unit. 
138         */
139        
140        public void setWidth(final String labelWidth,final String textBoxWidth) {
141            label.setWidth(labelWidth);
142            textBox.setWidth(textBoxWidth);
143        }
144        
145        /**
146         * Allows the user to set the with of the containing panel which
147         * contains the subwidgets
148         * @param width This is the width of the panel 
149         */
150    
151        public void setWidth(final String width) {
152            containerPanel.setWidth(width);
153        }
154        
155        /**
156         * Allows the user to set the focus
157         * @param focusState Sets the focus on this widget
158         */
159        
160        public void setFocus(final boolean focusState) {
161            textBox.setFocus(focusState);
162        }
163    }