Source Code Cross Referenced for PreferencesDialog.java in  » Internationalization-Localization » RBManager » com » ibm » rbm » gui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » RBManager » com.ibm.rbm.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *****************************************************************************
003:         * Copyright (C) 2000-2004, International Business Machines Corporation and  *
004:         * others. All Rights Reserved.                                              *
005:         *****************************************************************************
006:         */
007:        package com.ibm.rbm.gui;
008:
009:        import java.awt.*;
010:        import java.awt.event.*;
011:        import java.io.IOException;
012:        import java.util.Locale;
013:
014:        import javax.swing.*;
015:
016:        import com.ibm.rbm.*;
017:
018:        /**
019:         * Dialog to display to a user about their preferences. 
020:         */
021:        class PreferencesDialog extends JDialog {
022:            String userName;
023:            Locale locale;
024:            LookAndFeel laf;
025:            RBManagerGUI gui;
026:
027:            // ** COMPONENTS **
028:            JTextField nameField;
029:            JRadioButton machineRadio;
030:            JRadioButton definedRadio;
031:            JRadioButton isoRadio;
032:            JComboBox machineCombo;
033:            JComboBox definedCombo;
034:            JComboBox isoLangCombo;
035:            JComboBox isoCounCombo;
036:            JComboBox lafCombo;
037:            JButton okButton;
038:            JButton cancelButton;
039:
040:            public PreferencesDialog(RBManagerGUI gui) {
041:                super (gui,
042:                        Resources.getTranslation("dialog_title_preferences"),
043:                        true);
044:                this .gui = gui;
045:                userName = gui.getUser();
046:                locale = Resources.getLocale();
047:                laf = UIManager.getLookAndFeel();
048:
049:                initComponents();
050:                enableEvents(AWTEvent.KEY_EVENT_MASK);
051:            }
052:
053:            protected void processKeyEvent(KeyEvent ev) {
054:                if (ev.getKeyCode() == KeyEvent.VK_ENTER) {
055:                    updatePreferences();
056:                } else if (ev.getKeyCode() == KeyEvent.VK_CANCEL) {
057:                    this WindowClosing();
058:                }
059:            }
060:
061:            private void initComponents() {
062:                UIManager.LookAndFeelInfo lafi[] = UIManager
063:                        .getInstalledLookAndFeels();
064:                String lafn[] = new String[lafi.length];
065:                for (int i = 0; i < lafi.length; i++) {
066:                    lafn[i] = lafi[i].getName();
067:                }
068:
069:                // COMPONENTS
070:
071:                JPanel panel1 = new JPanel();
072:                JPanel panel2 = new JPanel();
073:                JPanel panel3 = new JPanel();
074:                JPanel panel4 = new JPanel();
075:                Box mainBox = new Box(BoxLayout.Y_AXIS);
076:                Box localeBox1 = new Box(BoxLayout.Y_AXIS);
077:                Box localeBox2 = new Box(BoxLayout.Y_AXIS);
078:                JPanel localePanel = new JPanel();
079:
080:                Dimension localeDim1 = new Dimension(200, 25);
081:                Dimension localeDim2 = new Dimension(150, 25);
082:                Dimension localeDim3 = new Dimension(50, 25);
083:
084:                JLabel nameLabel = new JLabel(Resources
085:                        .getTranslation("dialog_preferences_username"));
086:                JLabel lafLabel = new JLabel(Resources
087:                        .getTranslation("dialog_preferences_lookandfeel"));
088:                JLabel warnLabel = new JLabel(Resources
089:                        .getTranslation("dialog_preferences_locale_warning"));
090:                JLabel underscoreLabel = new JLabel("_");
091:
092:                nameField = new JTextField(userName);
093:                machineRadio = new JRadioButton(Resources
094:                        .getTranslation("dialog_preferences_locale_machine"),
095:                        false);
096:                definedRadio = new JRadioButton(Resources
097:                        .getTranslation("dialog_preferences_locale_defined"),
098:                        true);
099:                isoRadio = new JRadioButton(Resources
100:                        .getTranslation("dialog_preferences_locale_iso"), false);
101:                machineCombo = new JComboBox(Locale.getAvailableLocales());
102:                definedCombo = new JComboBox(Resources.getAvailableLocales());
103:                isoLangCombo = new JComboBox(Locale.getISOLanguages());
104:                isoCounCombo = new JComboBox(Locale.getISOCountries());
105:                lafCombo = new JComboBox(lafn);
106:                okButton = new JButton(Resources
107:                        .getTranslation("button_update"));
108:                cancelButton = new JButton(Resources
109:                        .getTranslation("button_cancel"));
110:
111:                machineRadio.setPreferredSize(localeDim1);
112:                definedRadio.setPreferredSize(localeDim1);
113:                isoRadio.setPreferredSize(localeDim1);
114:
115:                nameLabel.setPreferredSize(localeDim1);
116:                lafLabel.setPreferredSize(localeDim1);
117:
118:                //localePanel.setPreferredSize(localeDim2);
119:                machineCombo.setPreferredSize(localeDim2);
120:                definedCombo.setPreferredSize(localeDim2);
121:
122:                nameField.setPreferredSize(localeDim2);
123:                lafCombo.setPreferredSize(localeDim2);
124:
125:                isoLangCombo.setPreferredSize(localeDim3);
126:                isoCounCombo.setPreferredSize(localeDim3);
127:
128:                // Select the appropriate entries in the combo boxes
129:                String lafname = UIManager.getLookAndFeel().getName();
130:                for (int i = 0; i < lafCombo.getItemCount(); i++) {
131:                    if (lafCombo.getItemAt(i).toString().equals(lafname)) {
132:                        lafCombo.setSelectedIndex(i);
133:                        break;
134:                    }
135:                }
136:                String locname = Resources.getLocale().toString();
137:                String loclang = Resources.getLocale().getLanguage();
138:                String loccoun = Resources.getLocale().getCountry();
139:                for (int i = 0; i < machineCombo.getItemCount(); i++) {
140:                    if (machineCombo.getItemAt(i).toString().equalsIgnoreCase(
141:                            locname)) {
142:                        machineCombo.setSelectedIndex(i);
143:                        break;
144:                    }
145:                }
146:                for (int i = 0; i < definedCombo.getItemCount(); i++) {
147:                    if (definedCombo.getItemAt(i).toString().equalsIgnoreCase(
148:                            locname)) {
149:                        definedCombo.setSelectedIndex(i);
150:                        break;
151:                    }
152:                }
153:                for (int i = 0; i < isoLangCombo.getItemCount(); i++) {
154:                    if (isoLangCombo.getItemAt(i).toString().equalsIgnoreCase(
155:                            loclang)) {
156:                        isoLangCombo.setSelectedIndex(i);
157:                        break;
158:                    }
159:                }
160:                for (int i = 0; i < isoCounCombo.getItemCount(); i++) {
161:                    if (isoCounCombo.getItemAt(i).toString().equalsIgnoreCase(
162:                            loccoun)) {
163:                        isoCounCombo.setSelectedIndex(i);
164:                        break;
165:                    }
166:                }
167:
168:                // Set the radio button group
169:                ButtonGroup group = new ButtonGroup();
170:                group.add(machineRadio);
171:                group.add(definedRadio);
172:                group.add(isoRadio);
173:
174:                nameField.setColumns(15);
175:
176:                // Add action listeners
177:                cancelButton.addActionListener(new ActionListener() {
178:                    public void actionPerformed(ActionEvent ev) {
179:                        this WindowClosing();
180:                    }
181:                });
182:
183:                okButton.addActionListener(new ActionListener() {
184:                    public void actionPerformed(ActionEvent ev) {
185:                        updatePreferences();
186:                    }
187:                });
188:                getRootPane().setDefaultButton(okButton);
189:
190:                panel3.setBorder(BorderFactory.createTitledBorder(BorderFactory
191:                        .createEtchedBorder(), Resources
192:                        .getTranslation("dialog_preferences_locale")));
193:                panel3.setLayout(new BorderLayout());
194:
195:                localePanel.add(isoLangCombo);
196:                localePanel.add(underscoreLabel);
197:                localePanel.add(isoCounCombo);
198:
199:                localeBox1.add(machineRadio);
200:                localeBox1.add(definedRadio);
201:                localeBox1.add(isoRadio);
202:                localeBox2.add(machineCombo);
203:                localeBox2.add(definedCombo);
204:                localeBox2.add(localePanel);
205:                localeBox1.add(Box.createVerticalStrut(5));
206:                localeBox2.add(Box.createVerticalStrut(5));
207:
208:                panel1.add(nameLabel);
209:                panel1.add(nameField);
210:                panel2.add(lafLabel);
211:                panel2.add(lafCombo);
212:                panel3.add(localeBox1, BorderLayout.WEST);
213:                panel3.add(localeBox2, BorderLayout.EAST);
214:                panel3.add(warnLabel, BorderLayout.SOUTH);
215:                panel4.add(okButton);
216:                panel4.add(cancelButton);
217:
218:                mainBox.add(panel1);
219:                mainBox.add(panel2);
220:                mainBox.add(panel3);
221:                mainBox.add(panel4);
222:
223:                getContentPane().add(mainBox);
224:                //validate();
225:                pack();
226:                setVisible(true);
227:            }
228:
229:            private void this WindowClosing() {
230:                setVisible(false);
231:                dispose();
232:            }
233:
234:            void updatePreferences() {
235:                // Set the user name
236:                gui.setUser(nameField.getText().trim());
237:                // Set the look and feel
238:                try {
239:                    UIManager.LookAndFeelInfo lafi[] = UIManager
240:                            .getInstalledLookAndFeels();
241:                    for (int i = 0; i < lafi.length; i++) {
242:                        if (lafi[i].getName().equals(
243:                                lafCombo.getSelectedItem().toString())) {
244:                            UIManager.setLookAndFeel(lafi[i].getClassName());
245:                            gui.updateUI();
246:                            break;
247:                        }
248:                    }
249:                } catch (Exception e) {
250:                    System.err.println("Could not change the look and feel");
251:                    e.printStackTrace(System.err);
252:                }
253:                // Set the locale
254:                String language = null;
255:                String country = null;
256:                String variant = null;
257:                if (definedRadio.isSelected()) {
258:                    String encoding = "";
259:                    if (definedCombo.getSelectedItem() != null) {
260:                        encoding = definedCombo.getSelectedItem().toString();
261:                    }
262:                    language = Resources.getLanguage(encoding);
263:                    country = Resources.getCountry(encoding);
264:                    variant = Resources.getVariant(encoding);
265:                    RBManagerGUI.debugMsg("Before: " + language + "_" + country
266:                            + "_" + variant);
267:                    if (country == null)
268:                        country = new String();
269:                    if (variant == null)
270:                        locale = new Locale(language, country);
271:                    else
272:                        locale = new Locale(language, country, variant);
273:                    RBManagerGUI.debugMsg("After: " + locale.toString());
274:                } else if (machineRadio.isSelected()) {
275:                    String encoding = machineCombo.getSelectedItem().toString();
276:                    language = Resources.getLanguage(encoding);
277:                    country = Resources.getCountry(encoding);
278:                    variant = Resources.getVariant(encoding);
279:                    if (country == null)
280:                        country = new String();
281:                    if (variant == null)
282:                        locale = new Locale(language, country);
283:                    else
284:                        locale = new Locale(language, country, variant);
285:                } else if (isoRadio.isSelected()) {
286:                    language = isoLangCombo.getSelectedItem().toString();
287:                    country = isoCounCombo.getSelectedItem().toString();
288:                    if (variant == null)
289:                        locale = new Locale(language, country);
290:                    else
291:                        locale = new Locale(language, country, variant);
292:                }
293:                Resources.setLocale(locale);
294:                gui.updateLocale(locale);
295:
296:                // Write the preferences
297:                Preferences.setPreference("username", gui.getUser());
298:                Preferences.setPreference("lookandfeel", UIManager
299:                        .getLookAndFeel().getClass().getName());
300:                Preferences.setPreference("locale", locale.toString());
301:                try {
302:                    Preferences.savePreferences();
303:                } catch (IOException ioe) {
304:                    JOptionPane.showMessageDialog(this , Resources
305:                            .getTranslation("error_preferences_save"),
306:                            Resources.getTranslation("error"),
307:                            JOptionPane.ERROR_MESSAGE);
308:                    ioe.printStackTrace(System.err);
309:                }
310:
311:                // Close the window
312:                thisWindowClosing();
313:            }
314:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.