Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: openfuture/editxml/applet/AbsPanel.java


1   package openfuture.editxml.applet;
2   /*
3    * This library is free software; you can redistribute it and/or
4    * modify it under the terms of the GNU Lesser General Public
5    * License as published by the Free Software Foundation; either
6    * version 2 of the License, or (at your option) any later version.<p>
7    *
8    * This library is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11   * Lesser General Public License for more details.<p>
12   *
13   * You should have received a copy of the GNU Lesser General Public
14   * License along with this library; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA<br>
16   * http://www.gnu.org/copyleft/lesser.html
17   */
18  
19  import java.awt.Font;
20  import java.awt.event.ActionListener;
21  import java.awt.event.FocusListener;
22  import java.awt.event.ItemListener;
23  import java.awt.font.TextAttribute;
24  import java.net.URL;
25  import java.util.Date;
26  import java.util.Hashtable;
27  import java.util.Locale;
28  import java.util.ResourceBundle;
29  import java.util.Vector;
30  import javax.swing.ImageIcon;
31  import javax.swing.JButton;
32  import javax.swing.JComboBox;
33  import javax.swing.JLabel;
34  import javax.swing.JList;
35  import javax.swing.JPanel;
36  import javax.swing.JTextField;
37  import javax.swing.ListModel;
38  import javax.swing.event.ListSelectionListener;
39  
40  /**
41   * Abstract panel, after ideas from 
42   * <a href="http://www.openfuture.de/bugbase">Bug Base</a>.<p>
43   *
44   *
45   * Created: Wed Feb 02 05:57:21 2000
46   *
47   * @author Wolfgang Reissenberger
48   * @version $Revision: 1.2 $
49   */
50  // Configuration Management Information: 
51  // -------------------------------------
52  // $Id: AbsPanel.java,v 1.2 2001/07/22 09:19:23 wreissen Exp $
53  //
54  // Version History:
55  // ----------------
56  // $Log: AbsPanel.java,v $
57  // Revision 1.2  2001/07/22 09:19:23  wreissen
58  // resource bundle usage added.
59  //
60  // Revision 1.1.1.1  2001/07/08 18:29:29  wreissen
61  // initial version registered ad SourceForge
62  //
63  //
64  // ***********************************************************************************
65  
66  public abstract class AbsPanel extends JPanel {
67      
68      private FocusListener myFocusListener;
69      private ActionListener myActionListener;
70      private ListSelectionListener myListSelectionListener;
71      private ItemListener myItemListener;
72  
73      private AbsController myController;
74      private Locale locale;
75      private ResourceBundle resourceBundle;
76      
77  
78      static Font normalFont;
79      static Font bigFont;
80      static Font smallFont;
81      
82      /**
83       * Creates a new <code>AbsPanel</code> instance.
84       *
85       * @param locale the current locale
86       */
87      public AbsPanel(Locale locale) {
88    super();
89  
90    setLocale(locale);
91    setResourceBundle(ResourceBundle.getBundle("openfuture.editxml.EditXmlRes_txt", getLocale()));
92    // define fonts
93  
94    Hashtable mapNormal = new Hashtable();
95    mapNormal.put(TextAttribute.SIZE, new Float(11.0));
96    Hashtable mapBig = new Hashtable();
97    mapBig.put(TextAttribute.SIZE, new Float(13.2));
98    Hashtable mapSmall = new Hashtable();
99    mapSmall.put(TextAttribute.SIZE, new Float(9.0));
100 
101   normalFont = new Font(mapNormal);
102   bigFont = new Font(mapBig);
103   smallFont = new Font(mapSmall);
104     }
105 
106 
107 
108     /**
109      * Initialize the panel and sets all listeners.
110      *
111      * @param controller the panel controller
112      */
113     public void init(AbsController controller) {
114 
115   setMyActionListener(controller);
116   setMyFocusListener(controller);
117   setMyListSelectionListener(controller);
118   setMyItemListener(controller);
119     }
120 
121     /**
122      * Refreshs the panel and its subpanels.
123      *
124      */
125     abstract public void refreshView();
126 
127     /**
128      * Creates a text label.
129      *
130      * @param s label text
131      * @return a <code>JLabel</code> value
132      */
133     public JLabel createLabel(String s) {
134     JLabel theLabel = new JLabel(getResourceBundle().getString(s));
135 
136     return(theLabel);
137     }
138 
139     /**
140      * Creates a text field
141      *
142      * @param name the component's name.
143      * @param s initial text.
144      * @return a <code>JTextField</code> value
145      */
146     public JTextField createTextField(String name, String s) {
147     JTextField theField = new JTextField(s);
148   theField.setName(name);
149   theField.setFont(normalFont);
150   theField.setActionCommand(name);
151   theField.addFocusListener(getMyFocusListener());
152   theField.addActionListener(getMyActionListener());
153     return(theField);
154     }
155 
156     /**
157      * Create a button.
158      *
159      * @param s button text
160      * @return a <code>JButton</code> value
161      */
162     public JButton createButton(String s) {
163     JButton theButton = new JButton(getResourceBundle().getString(s));
164   theButton.setActionCommand(s);
165   theButton.addActionListener(getMyActionListener());
166     return(theButton);
167     }
168 
169 
170 
171     /**
172      * Create a button with an icon, but without any text.
173      *
174      * @param name name of the button recognized by the 
175      *        {@link #getMyActionListener() action listener}.
176      * @param imageURL URL of the image
177      * @param tooltipKey tool tip key of the button. The text
178      *        is extracted from the resource bundle.
179      * @return a <code>JButton</code> value
180      */
181     public JButton createIconButton(String name, URL imageURL,
182             String tooltipKey) {
183     JButton button = new JButton();
184   button.setActionCommand(name);
185   button.setIcon(new ImageIcon(imageURL));
186   if (tooltipKey != null) {
187       button.setToolTipText(getResourceBundle().getString(tooltipKey));
188   }
189   button.addActionListener(getMyActionListener());
190     return(button);
191     }
192 
193     /**
194      * Create a combo box.
195      *
196      * @param s initial values
197      * @param command The action commnand that is included in the
198      *                event sent to action listeners.
199      * @return a <code>JComboBox</code> value
200      */
201     public JComboBox createComboBox(Vector s, String command) {
202     JComboBox theComboBox = new JComboBox(s);
203   theComboBox.setFont(normalFont);
204   theComboBox.addActionListener(getMyActionListener());
205   theComboBox.setActionCommand(command);
206     return(theComboBox);
207     }
208 
209     /**
210      * Creates a list.
211      *
212      * @param theListModel the list model
213      * @return a <code>JList</code> value
214      */
215     public JList createList(ListModel theListModel) {
216       JList theList = new JList(theListModel);
217       theList.addListSelectionListener(getMyListSelectionListener());
218 
219       return(theList);
220     }
221 
222     /**
223        * Get the value of myFocusListener.
224        * @return Value of myFocusListener.
225        */
226     public FocusListener getMyFocusListener() {return myFocusListener;}
227     
228     /**
229        * Set the value of myFocusListener.
230        * @param v  Value to assign to myFocusListener.
231        */
232     public void setMyFocusListener(FocusListener  v) {
233   myFocusListener = v;
234     }
235 
236 
237     /**
238        * Get the value of myActionListener.
239        * @return Value of myActionListener.
240        */
241     public ActionListener getMyActionListener() {return this.myActionListener;}
242     
243     /**
244        * Set the value of myActionListener.
245        * @param v  Value to assign to myActionListener.
246        */
247     public void setMyActionListener(ActionListener  v) {
248   this.myActionListener = v;
249     }
250 
251 
252 
253     
254     /**
255        * Get the value of myItemListener.
256        * @return Value of myItemListener.
257        */
258     public ItemListener getMyItemListener() {return this.myItemListener;}
259     
260     /**
261        * Set the value of myItemListener.
262        * @param v  Value to assign to myItemListener.
263        */
264     public void setMyItemListener(ItemListener  v) {
265   this.myItemListener = v;
266     }
267 
268 
269 
270     
271     /**
272        * Get the value of myListSelectionListener.
273        * @return Value of myListSelectionListener.
274        */
275     public ListSelectionListener getMyListSelectionListener() {
276   return myListSelectionListener;
277     }
278     
279     /**
280        * Set the value of myListSelectionListener.
281        * @param v  Value to assign to myListSelectionListener.
282        */
283     public void setMyListSelectionListener(ListSelectionListener  v) {
284   this.myListSelectionListener = v;
285     }
286     
287 
288     /**
289      * Describe <code>getIndex</code> method here.
290      *
291      * @param toFind a <code>String</code> value
292      * @param choices a <code>Vector</code> value
293      * @return an <code>int</code> value
294      */
295     public int getIndex(String toFind, Vector choices) {
296 
297   return choices.indexOf(toFind);  
298     }
299 
300     /**
301      * Get the value of locale.
302      * @return value of locale.
303      */
304     public Locale getLocale() {
305   return locale;
306     }
307     
308     /**
309      * Set the value of locale.
310      * @param v  Value to assign to locale.
311      */
312     public void setLocale(Locale  v) {
313   this.locale = v;
314     }
315 
316 
317     /**
318      * Get the value of resourceBundle.
319      * @return value of resourceBundle.
320      */
321     public ResourceBundle getResourceBundle() {
322   return resourceBundle;
323     }
324     
325     /**
326      * Set the value of resourceBundle.
327      * @param v  Value to assign to resourceBundle.
328      */
329     public void setResourceBundle(ResourceBundle  v) {
330   this.resourceBundle = v;
331     }
332     
333 } // AbsPanel