001: /*
002: * Created on 19/09/2006
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2006 Igor Regis da Silva Simões
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: */
023: package br.com.gfp.windows;
024:
025: import java.awt.GridBagConstraints;
026: import java.awt.GridBagLayout;
027: import java.awt.Insets;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030: import java.io.IOException;
031: import java.util.ArrayList;
032: import java.util.Locale;
033:
034: import javax.swing.JButton;
035: import javax.swing.JDialog;
036: import javax.swing.JLabel;
037:
038: import br.com.gfp.windows.config.LocaleConf;
039: import br.com.gfpshare.beans.CountryEditor;
040: import br.com.gfpshare.beans.LanguageEditor;
041:
042: public class LocaleWindowSetup extends JDialog {
043:
044: private LanguageEditor languageEditor;
045: private CountryEditor countryEditor;
046:
047: public LocaleWindowSetup() {
048: setModal(true);
049: getContentPane().setLayout(new GridBagLayout());
050:
051: ArrayList<Locale> languages = new ArrayList<Locale>();
052: languages.add(Locale.ENGLISH);
053: languages.add(Locale.FRENCH);
054: languages.add(Locale.GERMAN);
055: languages.add(Locale.ITALIAN);
056: languages.add(Locale.CHINESE);
057: languages.add(new Locale("es"));
058: languages.add(new Locale("pt"));
059: languages.add(new Locale("ar"));
060: languages.add(new Locale("ro"));
061: languages.add(new Locale("pl"));
062: languages.add(new Locale("fa"));
063: languageEditor = new LanguageEditor(languages);
064: languageEditor.setSelectedItem(Locale.getDefault()
065: .getLanguage());
066:
067: JLabel selecioneLanguageLabel = new JLabel(
068: "Select your preferred language:");
069: selecioneLanguageLabel.setLabelFor(languageEditor);
070:
071: GridBagConstraints c = new GridBagConstraints();
072: c.gridx = 0;
073: c.gridy = 0;
074: c.anchor = GridBagConstraints.WEST;
075: c.insets = new Insets(5, 5, 5, 5);
076: getContentPane().add(selecioneLanguageLabel, c);
077:
078: c = new GridBagConstraints();
079: c.gridx = 1;
080: c.gridy = 0;
081: c.anchor = GridBagConstraints.WEST;
082: c.insets = new Insets(5, 5, 5, 5);
083: getContentPane().add(languageEditor, c);
084:
085: countryEditor = new CountryEditor();
086: countryEditor.setSelectedItem(Locale.getDefault().getCountry());
087:
088: JLabel selecioneCountryLabel = new JLabel(
089: "Select your country:");
090: selecioneCountryLabel.setLabelFor(countryEditor);
091:
092: c = new GridBagConstraints();
093: c.gridx = 0;
094: c.gridy = 1;
095: c.anchor = GridBagConstraints.WEST;
096: c.insets = new Insets(5, 5, 5, 5);
097: getContentPane().add(selecioneCountryLabel, c);
098:
099: c = new GridBagConstraints();
100: c.gridx = 1;
101: c.gridy = 1;
102: c.anchor = GridBagConstraints.WEST;
103: c.insets = new Insets(5, 5, 5, 5);
104: getContentPane().add(countryEditor, c);
105:
106: JButton ok = new JButton("Ok");
107: ok.addActionListener(new ActionListener() {
108: public void actionPerformed(ActionEvent e) {
109: gravarLocale();
110: }
111: });
112: c = new GridBagConstraints();
113: c.gridx = 0;
114: c.gridy = 2;
115: c.gridwidth = 2;
116: c.anchor = GridBagConstraints.CENTER;
117: c.insets = new Insets(5, 5, 5, 0);
118: getContentPane().add(ok, c);
119:
120: setSize(330, 135);
121: setLocationRelativeTo(null);
122: pack();
123: setVisible(true);
124: }
125:
126: private void gravarLocale() {
127: LocaleConf localeConf = null;
128: try {
129: localeConf = new LocaleConf();
130: } catch (IOException e) {
131: e.printStackTrace();
132: }
133:
134: localeConf.setCountry(countryEditor.getSelectedItem()
135: .toString());
136: localeConf.setLanguage(languageEditor.getSelectedItem()
137: .toString());
138: try {
139: localeConf.saveData();
140: } catch (IOException e) {
141: e.printStackTrace();
142: }
143: this .setVisible(false);
144: this .dispose();
145: }
146:
147: public static void main(String[] args) {
148: new LocaleWindowSetup();
149: }
150: }
|