/[schmitzm]/trunk/src/skrueger/i8n/SwitchLanguageDialog.java
ViewVC logotype

Annotation of /trunk/src/skrueger/i8n/SwitchLanguageDialog.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Tue Feb 24 22:43:52 2009 UTC (16 years ago) by mojays
File size: 7012 byte(s)
First Commit, corresponds to Revision 1008 of Wikisquare-SVN
includes:
- schmitzm.* (except schmitzm.test)
- org.geotools.* (all overridden classes)
- skrueger.geotools
- skrueger.i8n
- skrueger.swing
- appl.data.LateLoadable (dependency in SCHMITZM)
- appl.data.LoadingException (dependency in SCHMITZM)
- appl.util.RasterMetaData (dependency in SCHMITZM)

1 mojays 2 package skrueger.i8n;
2    
3     import java.awt.GridBagConstraints;
4     import java.awt.GridBagLayout;
5     import java.awt.Insets;
6     import java.awt.Window;
7     import java.awt.event.ActionEvent;
8     import java.awt.event.ActionListener;
9     import java.awt.event.MouseWheelListener;
10     import java.util.List;
11     import java.util.Locale;
12    
13     import javax.swing.DefaultComboBoxModel;
14     import javax.swing.ImageIcon;
15     import javax.swing.JButton;
16     import javax.swing.JComboBox;
17     import javax.swing.JDialog;
18     import javax.swing.JLabel;
19     import javax.swing.JPanel;
20    
21     import org.apache.log4j.Logger;
22    
23     import schmitzm.swing.SwingUtil;
24     import skrueger.swing.OkButton;
25     import skrueger.swing.TranslationEditJPanel;
26    
27     public class SwitchLanguageDialog extends JDialog {
28     protected Logger LOGGER = Logger.getLogger(SwitchLanguageDialog.class);
29    
30     private static final long serialVersionUID = 1L;
31    
32     private JPanel jContentPane = null;
33    
34     private JLabel jLabelFlagimage = null;
35    
36     private JPanel jPanel = null;
37    
38     private JButton jButton = null;
39    
40     private JPanel jPanel1 = null;
41    
42     private JLabel jLabel = null;
43    
44     private JComboBox jComboBox = null;
45    
46     private final List<String> languages;
47    
48     /**
49     * A dialog to select one of the available languages. If only one language
50     * is available, select it directly. Creating this object automatically
51     * makes it visible.
52     *
53     * @param owner
54     * @param atlasConfig
55     */
56     public SwitchLanguageDialog(final Window owner, final List<String> languages) {
57     super(owner);
58     this.languages = languages;
59    
60     Translation.setActiveLang(languages.get(0));
61    
62     if (languages.size() == 1) {
63     LOGGER.debug("Only language '" + languages.get(0)
64     + "' is available. It has been selected automatically.");
65     return;
66     }
67    
68     initialize();
69    
70     setVisible(true);
71     }
72    
73     /**
74     * This method initializes this
75     *
76     * @return void
77     */
78     private void initialize() {
79     this.setContentPane(getJContentPane());
80     setModal(true);
81     SwingUtil.centerFrameOnScreenRandom(this);
82     pack();
83     }
84    
85     /**
86     * This method initializes jContentPane
87     *
88     * @return javax.swing.JPanel
89     */
90     private JPanel getJContentPane() {
91     if (jContentPane == null) {
92     final GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
93     gridBagConstraints11.gridx = 1;
94     gridBagConstraints11.fill = GridBagConstraints.HORIZONTAL;
95     gridBagConstraints11.gridy = 1;
96     final GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
97     gridBagConstraints3.gridx = 1;
98     gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL;
99     gridBagConstraints3.gridy = 2;
100     final GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
101     gridBagConstraints1.gridx = 0;
102     gridBagConstraints1.fill = GridBagConstraints.BOTH;
103     gridBagConstraints1.gridwidth = 2;
104     gridBagConstraints1.anchor = GridBagConstraints.NORTH;
105     gridBagConstraints1.gridy = 0;
106     jLabelFlagimage = new JLabel(new ImageIcon(
107     TranslationEditJPanel.class
108     .getResource("resource/flags.jpg")));
109     jContentPane = new JPanel();
110     jContentPane.setLayout(new GridBagLayout());
111     jContentPane.add(jLabelFlagimage, gridBagConstraints1);
112     jContentPane.add(getJPanel(), gridBagConstraints3);
113     jContentPane.add(getJPanel1(), gridBagConstraints11);
114     }
115     return jContentPane;
116     }
117    
118     /**
119     * This method initializes jPanel
120     *
121     * @return javax.swing.JPanel
122     */
123     private JPanel getJPanel() {
124     if (jPanel == null) {
125     final GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
126     gridBagConstraints4.gridx = 0;
127     gridBagConstraints4.anchor = GridBagConstraints.EAST;
128     gridBagConstraints4.weightx = 1.0;
129     gridBagConstraints4.insets = new Insets(5, 5, 5, 5);
130     gridBagConstraints4.gridy = 0;
131     jPanel = new JPanel();
132     jPanel.setLayout(new GridBagLayout());
133     jPanel.add(getJButton(), gridBagConstraints4);
134     }
135     return jPanel;
136     }
137    
138     /**
139     * This method initializes jButton
140     *
141     * @return javax.swing.JButton
142     */
143     private JButton getJButton() {
144     if (jButton == null) {
145     jButton = new OkButton();
146     jButton.setEnabled(false);
147    
148     jButton.addActionListener(new ActionListener() {
149    
150     public void actionPerformed(ActionEvent e) {
151     dispose();
152     }
153    
154     });
155     }
156     return jButton;
157     }
158    
159     /**
160     * This method initializes jPanel1
161     *
162     * @return javax.swing.JPanel
163     */
164     private JPanel getJPanel1() {
165     if (jPanel1 == null) {
166     final GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
167     gridBagConstraints2.fill = GridBagConstraints.VERTICAL;
168     gridBagConstraints2.gridy = 0;
169     gridBagConstraints2.weightx = 1.0;
170     gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
171     gridBagConstraints2.anchor = GridBagConstraints.WEST;
172     gridBagConstraints2.gridx = 1;
173     final GridBagConstraints gridBagConstraints = new GridBagConstraints();
174     gridBagConstraints.gridx = 0;
175     gridBagConstraints.insets = new Insets(0, 5, 0, 0);
176     gridBagConstraints.gridy = 0;
177     jLabel = new JLabel();
178     jLabel.setText("Select language: ");
179     jPanel1 = new JPanel();
180     jPanel1.setLayout(new GridBagLayout());
181     jPanel1.add(jLabel, gridBagConstraints);
182     jPanel1.add(getJComboBox(), gridBagConstraints2);
183     }
184     return jPanel1;
185     }
186    
187     /**
188     * This method initializes jComboBox
189     *
190     * @return javax.swing.JComboBox
191     */
192     private JComboBox getJComboBox() {
193     if (jComboBox == null) {
194     jComboBox = new JComboBox();
195    
196     jComboBox.addMouseWheelListener(new MouseWheelListener() {
197     public void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {
198    
199     if ((e.getWheelRotation() < 0)) {
200     if (jComboBox.getSelectedIndex() < jComboBox
201     .getItemCount() - 1)
202     jComboBox.setSelectedIndex(jComboBox
203     .getSelectedIndex() + 1);
204     } else {
205     if (jComboBox.getSelectedIndex() > 0)
206     jComboBox.setSelectedIndex(jComboBox
207     .getSelectedIndex() - 1);
208     }
209     }
210     });
211    
212     String[] langNames = new String[languages.size() + 1];
213     for (int i = 0; i < languages.size(); i++) {
214    
215     Locale locale = null;
216     for (Locale l : Locale.getAvailableLocales()) {
217     if (l.getLanguage().equals(languages.get(i))) {
218     locale = l;
219     }
220     }
221    
222     langNames[i] = locale.getDisplayLanguage(locale) + " / "
223     + locale.getDisplayLanguage() + " / "
224     + languages.get(i);
225     }
226     langNames[languages.size()] = "?";
227    
228     jComboBox.setModel(new DefaultComboBoxModel(langNames));
229     jComboBox.setSelectedItem(langNames[languages.size()]);
230    
231     jComboBox.addActionListener(new ActionListener() {
232    
233     public void actionPerformed(final ActionEvent e) {
234     if (jComboBox.getSelectedIndex() == languages.size()) {
235     getJButton().setEnabled(false);
236     return;
237     }
238     Translation.setActiveLang(languages.get(jComboBox
239     .getSelectedIndex()));
240     getJButton().setEnabled(true);
241     }
242    
243     });
244     }
245     return jComboBox;
246     }
247    
248     } // @jve:decl-index=0:visual-constraint="0,0"

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26