KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > util > gui > LocationBar


1 /*
2
3    Copyright 2000,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.util.gui;
19
20 import java.awt.BorderLayout JavaDoc;
21 import java.awt.Dimension JavaDoc;
22 import java.awt.event.ActionListener JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.Locale JavaDoc;
25 import java.util.MissingResourceException JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27
28 import javax.swing.ImageIcon JavaDoc;
29 import javax.swing.JComboBox JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32
33 import org.apache.batik.util.gui.resource.ResourceManager;
34
35 /**
36  * This class represents a location bar.
37  *
38  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
39  * @version $Id: LocationBar.java,v 1.4 2004/08/18 07:15:54 vhardy Exp $
40  */

41 public class LocationBar extends JPanel JavaDoc {
42     /**
43      * The gui resources file name
44      */

45     protected final static String JavaDoc RESOURCES =
46         "org.apache.batik.util.gui.resources.LocationBar";
47
48     /**
49      * The resource bundle
50      */

51     protected static ResourceBundle JavaDoc bundle;
52
53     /**
54      * The resource manager
55      */

56     protected static ResourceManager rManager;
57     static {
58         bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault());
59         rManager = new ResourceManager(bundle);
60     }
61     
62     /**
63      * The combo box
64      */

65     protected JComboBox JavaDoc comboBox;
66
67     /**
68      * Creates a new location bar.
69      */

70     public LocationBar() {
71         super(new BorderLayout JavaDoc(5, 5));
72         JLabel JavaDoc label = new JLabel JavaDoc(rManager.getString("Panel.label"));
73         add("West", label);
74         try {
75             String JavaDoc s = rManager.getString("Panel.icon");
76             URL JavaDoc url = getClass().getResource(s);
77             if (url != null) {
78                 label.setIcon(new ImageIcon JavaDoc(url));
79             }
80         } catch (MissingResourceException JavaDoc e) {
81         }
82         add("Center", comboBox = new JComboBox JavaDoc());
83         comboBox.setEditable(true);
84     }
85
86     /**
87      * Adds an action listener to this component.
88      */

89     public void addActionListener(ActionListener JavaDoc listener) {
90         comboBox.addActionListener(listener);
91     }
92
93     /**
94      * returns the current item text.
95      */

96     public String JavaDoc getText() {
97         return (String JavaDoc)comboBox.getEditor().getItem();
98     }
99
100     /**
101      * Sets the current text.
102      */

103     public void setText(String JavaDoc text) {
104         comboBox.getEditor().setItem(text);
105     }
106
107     /**
108      * Adds the given text to the history.
109      */

110     public void addToHistory(String JavaDoc text) {
111         comboBox.addItem(text);
112         comboBox.setPreferredSize
113             (new Dimension JavaDoc(0, comboBox.getPreferredSize().height));
114     }
115 }
116
Popular Tags