/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/i8n/SwitchLanguageDialog.java
ViewVC logotype

Annotation of /branches/1.0-gt2-2.6/src/skrueger/i8n/SwitchLanguageDialog.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 578 - (hide annotations)
Wed Nov 25 14:43:57 2009 UTC (15 years, 3 months ago) by alfonx
File size: 8618 byte(s)
SwitchLanguageDialog now it's itself to visible or diasoss itself if not needed
RasterlegendData not implements Copyable
StylingUtil createLegendPanel manages the gaps better
1 alfonx 244 /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3     *
4     * This file is part of the SCHMITZM library - a collection of utility
5 alfonx 256 * classes based on Java 1.6, focusing (not only) on Java Swing
6 alfonx 244 * and the Geotools library.
7     *
8     * The SCHMITZM project is hosted at:
9     * http://wald.intevation.org/projects/schmitzm/
10     *
11     * This program is free software; you can redistribute it and/or
12     * modify it under the terms of the GNU Lesser General Public License
13     * as published by the Free Software Foundation; either version 3
14     * of the License, or (at your option) any later version.
15     *
16     * This program is distributed in the hope that it will be useful,
17     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19     * GNU General Public License for more details.
20     *
21     * You should have received a copy of the GNU Lesser General Public License (license.txt)
22     * along with this program; if not, write to the Free Software
23     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24     * or try this link: http://www.gnu.org/licenses/lgpl.html
25     *
26     * Contributors:
27     * Martin O. J. Schmitz - initial API and implementation
28     * Stefan A. Krüger - additional utility classes
29     ******************************************************************************/
30     package skrueger.i8n;
31    
32     import java.awt.Component;
33     import java.awt.GridBagConstraints;
34     import java.awt.GridBagLayout;
35     import java.awt.Insets;
36     import java.awt.event.ActionEvent;
37     import java.awt.event.ActionListener;
38     import java.awt.event.MouseWheelListener;
39     import java.util.List;
40     import java.util.Locale;
41    
42     import javax.swing.DefaultComboBoxModel;
43     import javax.swing.ImageIcon;
44     import javax.swing.JButton;
45     import javax.swing.JComboBox;
46     import javax.swing.JDialog;
47     import javax.swing.JLabel;
48     import javax.swing.JPanel;
49    
50     import org.apache.log4j.Logger;
51    
52     import schmitzm.swing.SwingUtil;
53     import skrueger.swing.OkButton;
54     import skrueger.swing.TranslationEditJPanel;
55    
56     /**
57     * This dialog ask the user to select one of list of given languages. The dialog
58     * is modal and not visible after construction.
59     *
60     * @author Stefan A. Krueger
61     */
62     public class SwitchLanguageDialog extends JDialog {
63     protected Logger LOGGER = Logger.getLogger(SwitchLanguageDialog.class);
64    
65     private static final long serialVersionUID = 1L;
66    
67     private JPanel jContentPane = null;
68    
69     private JLabel jLabelFlagimage = null;
70    
71     private JPanel jPanel = null;
72    
73     private JButton jButton = null;
74    
75     private JPanel jPanel1 = null;
76    
77     private JLabel jLabel = null;
78    
79     private JComboBox jComboBox = null;
80    
81     private final List<String> languages;
82    
83     /**
84     * A dialog to select one of the available languages. If only one language
85     * is available, select it directly. Creating this object automatically
86 alfonx 578 * makes it visible, unless there is only one language to choose from.. it
87     * that case it disposes itself autmatically.
88 alfonx 244 */
89     public SwitchLanguageDialog(final Component owner,
90     final List<String> languages) {
91     super(SwingUtil.getParentWindow(owner));
92     this.languages = languages;
93    
94     Translation.setActiveLang(languages.get(0));
95    
96     if (languages.size() == 1) {
97     LOGGER.debug("Only language '" + languages.get(0)
98     + "' is available. It has been selected automatically.");
99 alfonx 578 dispose();
100 alfonx 244 return;
101     }
102    
103     initialize();
104     }
105    
106     /**
107     * This method initializes this
108     *
109     * @return void
110     */
111     private void initialize() {
112     this.setContentPane(getJContentPane());
113    
114     setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
115    
116     pack();
117 alfonx 578
118     SwingUtil.centerFrameOnScreenRandom(this);
119     setModal(true);
120     setVisible(true);
121 alfonx 244 }
122    
123     /**
124     * This method initializes jContentPane
125     *
126     * @return javax.swing.JPanel
127     */
128     private JPanel getJContentPane() {
129     if (jContentPane == null) {
130     final GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
131     gridBagConstraints11.gridx = 1;
132     gridBagConstraints11.fill = GridBagConstraints.HORIZONTAL;
133     gridBagConstraints11.gridy = 1;
134     final GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
135     gridBagConstraints3.gridx = 1;
136     gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL;
137     gridBagConstraints3.gridy = 2;
138     final GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
139     gridBagConstraints1.gridx = 0;
140     gridBagConstraints1.fill = GridBagConstraints.BOTH;
141     gridBagConstraints1.gridwidth = 2;
142     gridBagConstraints1.anchor = GridBagConstraints.NORTH;
143     gridBagConstraints1.gridy = 0;
144     jLabelFlagimage = new JLabel(new ImageIcon(
145     TranslationEditJPanel.class
146     .getResource("resource/flags.jpg")));
147     jContentPane = new JPanel();
148     jContentPane.setLayout(new GridBagLayout());
149     jContentPane.add(jLabelFlagimage, gridBagConstraints1);
150     jContentPane.add(getJPanel(), gridBagConstraints3);
151     jContentPane.add(getJPanel1(), gridBagConstraints11);
152     }
153     return jContentPane;
154     }
155    
156     /**
157     * This method initializes jPanel
158     *
159     * @return javax.swing.JPanel
160     */
161     private JPanel getJPanel() {
162     if (jPanel == null) {
163     final GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
164     gridBagConstraints4.gridx = 0;
165     gridBagConstraints4.anchor = GridBagConstraints.EAST;
166     gridBagConstraints4.weightx = 1.0;
167     gridBagConstraints4.insets = new Insets(5, 5, 5, 5);
168     gridBagConstraints4.gridy = 0;
169     jPanel = new JPanel();
170     jPanel.setLayout(new GridBagLayout());
171     jPanel.add(getJButton(), gridBagConstraints4);
172     }
173     return jPanel;
174     }
175    
176     /**
177     * This method initializes jButton
178     *
179     * @return javax.swing.JButton
180     */
181     private JButton getJButton() {
182     if (jButton == null) {
183     jButton = new OkButton();
184     jButton.setEnabled(false);
185    
186     jButton.addActionListener(new ActionListener() {
187    
188     public void actionPerformed(ActionEvent e) {
189     dispose();
190     }
191    
192     });
193     }
194     return jButton;
195     }
196    
197     /**
198     * This method initializes jPanel1
199     *
200     * @return javax.swing.JPanel
201     */
202     private JPanel getJPanel1() {
203     if (jPanel1 == null) {
204     final GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
205     gridBagConstraints2.fill = GridBagConstraints.VERTICAL;
206     gridBagConstraints2.gridy = 0;
207     gridBagConstraints2.weightx = 1.0;
208     gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
209     gridBagConstraints2.anchor = GridBagConstraints.WEST;
210     gridBagConstraints2.gridx = 1;
211     final GridBagConstraints gridBagConstraints = new GridBagConstraints();
212     gridBagConstraints.gridx = 0;
213     gridBagConstraints.insets = new Insets(0, 5, 0, 0);
214     gridBagConstraints.gridy = 0;
215     jLabel = new JLabel();
216     jLabel.setText("Select language: "); // i8n!?! Maybe replace with an
217 alfonx 578 // icon of an index finger
218 alfonx 244 jPanel1 = new JPanel();
219     jPanel1.setLayout(new GridBagLayout());
220     jPanel1.add(jLabel, gridBagConstraints);
221     jPanel1.add(getJComboBox(), gridBagConstraints2);
222     }
223     return jPanel1;
224     }
225    
226     /**
227     * This method initializes jComboBox
228     *
229     * @return javax.swing.JComboBox
230     */
231     private JComboBox getJComboBox() {
232     if (jComboBox == null) {
233     jComboBox = new JComboBox();
234    
235     jComboBox.addMouseWheelListener(new MouseWheelListener() {
236     public void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {
237    
238     if ((e.getWheelRotation() < 0)) {
239     if (jComboBox.getSelectedIndex() < jComboBox
240     .getItemCount() - 1)
241     jComboBox.setSelectedIndex(jComboBox
242     .getSelectedIndex() + 1);
243     } else {
244     if (jComboBox.getSelectedIndex() > 0)
245     jComboBox.setSelectedIndex(jComboBox
246     .getSelectedIndex() - 1);
247     }
248     }
249     });
250    
251     String[] langNames = new String[languages.size() + 1];
252     for (int i = 0; i < languages.size(); i++) {
253    
254     Locale locale = I8NUtil.getLocaleFor(languages.get(i));
255    
256     langNames[i] = locale.getDisplayLanguage(locale) + " / "
257     + locale.getDisplayLanguage() + " / "
258     + languages.get(i);
259     }
260     langNames[languages.size()] = "?";
261    
262     jComboBox.setModel(new DefaultComboBoxModel(langNames));
263     jComboBox.setSelectedItem(langNames[languages.size()]);
264    
265     jComboBox.addActionListener(new ActionListener() {
266    
267     public void actionPerformed(final ActionEvent e) {
268     if (jComboBox.getSelectedIndex() == languages.size()) {
269     getJButton().setEnabled(false);
270     return;
271     }
272    
273     String l = languages.get(jComboBox.getSelectedIndex());
274     try {
275     Translation.setActiveLang(l);
276    
277     getJButton().setEnabled(true);
278     } catch (java.lang.IllegalArgumentException ee) {
279     LOGGER.warn("The language " + l + " is not valid", ee);
280     getJButton().setEnabled(false);
281     }
282    
283     }
284    
285     });
286     }
287     return jComboBox;
288     }
289    
290 alfonx 578 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26