KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > actions > ChangeLanguage


1 /*
2  * Authors:
3  * Stefanovic Nenad chupo@iis.ns.ac.yu
4  * Bojanic Sasa sasaboy@neobee.net
5  * Puskas Vladimir vpuskas@eunet.yu
6  * Pilipovic Goran zboniek@uns.ac.yu
7  *
8  */

9
10 package org.enhydra.jawe.actions;
11
12 import org.enhydra.jawe.*;
13 import org.enhydra.jawe.config.*;
14 import org.enhydra.jawe.ldap.*;
15 import org.enhydra.jawe.misc.*;
16
17 import org.enhydra.jawe.xml.*;
18
19 import java.awt.event.ActionEvent JavaDoc;
20 import java.util.*;
21 import javax.swing.*;
22 import java.awt.*;
23 import java.awt.event.*;
24
25 /**
26 * Class that realizes <B>change language</B> action.
27 */

28 public class ChangeLanguage extends ActionBase {
29    public ChangeLanguage (PackageEditor editor) {
30       super(editor);
31    }
32
33    public void actionPerformed(ActionEvent JavaDoc e) {
34       makeChangeLangDialog();
35    }
36
37    public void makeChangeLangDialog() {
38       final JList list;
39       JFrame frame = (JFrame)editor.getWindow();
40       String JavaDoc title = ResourceManager.getLanguageDependentString("DialogChangeLanguage");
41       final JDialog changeLangDlg = new JDialog(frame, title, true);
42       changeLangDlg.setSize(new Dimension(430, 280));
43       changeLangDlg.setLocationRelativeTo(frame);
44       //Cancel Button
45
JButton cancelButton = new JButton(ResourceManager.getLanguageDependentString("CancelKey"));
46       //Set Button
47
final JButton setButton = new JButton(ResourceManager.getLanguageDependentString("SetKey"));
48       changeLangDlg.getRootPane().setDefaultButton(setButton);
49       //Lay out the buttons from left to right
50
JPanel buttonPane = new JPanel();
51       buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
52       buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
53       buttonPane.add(Box.createHorizontalGlue());
54       buttonPane.add(cancelButton);
55       buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
56       buttonPane.add(setButton);
57
58       java.util.List JavaDoc pfLocales=Utils.findPropertyFiles();
59       if (pfLocales.size()==0) {
60          System.err.println("Can't find the property files - you have probably"+
61                " started JaWE from wrong location");
62          return;
63       }
64
65       //List
66
list = new JList(pfLocales.toArray());
67
68       //Scroll List
69
JScrollPane scroll = new JScrollPane(list);
70       scroll.setPreferredSize(new Dimension(350, 150));
71       scroll.setMinimumSize(new Dimension(350, 150));
72       scroll.setAlignmentX(JPanel.LEFT_ALIGNMENT);
73       //Label
74
JLabel lab = new JLabel(ResourceManager.getLanguageDependentString("AvailableLocales"));
75       lab.setLabelFor(list);
76       //Put it together
77
JPanel listPane = new JPanel();
78       listPane.setLayout(new BoxLayout(listPane, BoxLayout.Y_AXIS));
79       listPane.add(lab);
80       listPane.add(Box.createRigidArea(new Dimension(0,5)));
81       listPane.add(scroll);
82       listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
83       //Put everything together
84
Container contentPane = changeLangDlg.getContentPane();
85       contentPane.add(listPane, BorderLayout.CENTER);
86       contentPane.add(buttonPane, BorderLayout.SOUTH);
87       changeLangDlg.setResizable(true);
88       //Actions for buttons
89
cancelButton.addActionListener(new ActionListener() {
90          public void actionPerformed(ActionEvent JavaDoc e) {
91             changeLangDlg.dispose();
92          }
93       });
94       setButton.addActionListener(new ActionListener() {
95          public void actionPerformed(ActionEvent JavaDoc e) {
96             Object JavaDoc temp = list.getSelectedValue();
97             if(temp != null) {
98                PFLocale pfloc=(PFLocale)temp;
99                try {
100                   ResourceManager.setChoosen(pfloc.getLocale());
101                   // change title
102
try {
103                      editor.setTitle(editor.getWindow(),editor.getTitle());
104                   } catch (Exception JavaDoc ex) {}
105                   // change statusbar display
106
editor.getStatusBar().updateMessage();
107                   // change language of configuration dialog
108
ConfigDialog.getInstance().refreshLanguageDependentStrings();
109                   // change language of components of PackageEditor
110
changeLanguage(editor);
111                   // Call change language for package tree panel
112
changePackageSpecific((PackageEditor)editor);
113                   // get all process editor and block activity editor instances
114
// within current package and all external packages
115
// and change the language of it's components
116
changeLanguageForAllEditors();
117
118                   // Call change language for labels within all packages
119
Iterator it=JaWE.getInstance().getXMLInterface().getAllPackages().iterator();
120                   while (it.hasNext()) {
121                      ((org.enhydra.jawe.xml.elements.Package)
122                         it.next()).refreshLabelName();
123                   }
124
125                } catch(MissingResourceException mre) {
126                   String JavaDoc message=ResourceManager.getLanguageDependentString("NotFoundKey");
127                   message=message+": "+JaWEConstants.RESOURCE_PATH;
128                   message+=pfloc.getLocaleString();
129                   message=message+".properties";
130
131                   JOptionPane.showMessageDialog(editor.getWindow(),message,
132                      JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE);
133                }
134
135                changeLangDlg.dispose();
136             }
137             else {
138                JOptionPane.showMessageDialog(editor.getWindow(),
139                   ResourceManager.getLanguageDependentString("WarningEmptySelectionToEditOrDelete"),
140                   JaWE.getAppTitle(), JOptionPane.WARNING_MESSAGE);
141             }
142          }
143       });
144       list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
145       list.addMouseListener(new MouseAdapter() {
146          public void mouseClicked(MouseEvent e) {
147             if (e.getClickCount() == 2) {
148                setButton.doClick();
149             }
150          }
151       });
152
153       changeLangDlg.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
154             .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0,false),"Cancel");
155       changeLangDlg.getRootPane().getActionMap().put("Cancel", new AbstractAction() {
156          public void actionPerformed(ActionEvent JavaDoc e) {
157             changeLangDlg.dispose();
158          }
159       });
160       Utils.center(changeLangDlg,100,100);
161
162       changeLangDlg.show();
163    }
164
165    /** Changes the language and Locale of all process editors */
166    private void changeLanguageForAllEditors () {
167       // collect all process objects in the package (and all process
168
// objects from external packages)
169
Iterator pkgGraphs=((PackageEditor)editor).getPkgIdToGraphMap().values().iterator();
170       Set wObjects=new HashSet();
171       while (pkgGraphs.hasNext()) {
172          PackageGraph peg=(PackageGraph)pkgGraphs.next();
173          Set ws=JaWEGraphModel.getAllActivitiesInModel(peg.getModel());
174          if (ws!=null) {
175             wObjects.addAll(ws);
176          }
177       }
178
179       // collect all block activity objects in the model (and all block
180
// activity objects from external models), and call change language
181
// on editors
182
Iterator wObjs=wObjects.iterator();
183       Set baObjects=new HashSet();
184       while (wObjs.hasNext()) {
185          org.enhydra.jawe.graph.Process pr=(org.enhydra.jawe.graph.Process)wObjs.next();
186          ProcessEditor pe=pr.getImplementationEditor();
187          if (pe!=null) {
188             WorkflowManager wm=((ProcessGraph)pe.getGraph()).getWorkflowManager();
189             Set bas=wm.getBlockActivities(true);
190             baObjects.addAll(bas);
191             // change lang on wEditor
192
changeLanguage(pe);
193          }
194       }
195
196       // iterate through all block activity objects, get their editors and
197
// call change language on them
198
Iterator baObjs =baObjects.iterator();
199       while(baObjs.hasNext()) {
200          org.enhydra.jawe.graph.BlockActivity ba=
201             (org.enhydra.jawe.graph.BlockActivity)baObjs.next();
202          AbstractEditor bae=ba.getImplementationEditor();
203          if (bae!=null) {
204             changeLanguage(bae);
205          }
206       }
207    }
208
209    /** Changes the language and Locale of menu items */
210    private void changeMenuItems (AbstractEditor ed) {
211       Iterator iter = ed.getMenuItems().values().iterator();
212       while (iter.hasNext()) {
213          JMenuItem jmi = (JMenuItem) iter.next();
214          jmi.setLocale(ResourceManager.getChoosenLocale());
215          jmi.setText(ResourceManager.getLanguageDependentString(jmi.getActionCommand()+JaWEConstants.LABEL_SUFFIX));
216          // change mnemonic
217
ed.getBarFactory().setMnemonic(jmi,ResourceManager.getLanguageDependentString(jmi.getActionCommand()+JaWEConstants.MNEMONIC_SUFFIX));
218          // change accelerator
219
ed.getBarFactory().setAccelerator(jmi,ResourceManager.getLanguageDependentString(jmi.getActionCommand()+JaWEConstants.ACCEL_SUFFIX));
220       }
221    }
222
223    /** Changes the language and Locale of menu bar */
224    private void changeMenuBar (AbstractEditor ed) {
225       MenuElement[] me = ed.getMenubar().getSubElements();
226       for(int i = 0; i<me.length; i++) {
227          JMenu jm = (JMenu) me[i].getComponent();
228          jm.setLocale(ResourceManager.getChoosenLocale());
229          jm.setText(ResourceManager.getLanguageDependentString(jm.getActionCommand()+JaWEConstants.LABEL_SUFFIX));
230          // change mnemonic
231
ed.getBarFactory().setMnemonic(jm,ResourceManager.getLanguageDependentString(jm.getActionCommand()+JaWEConstants.MNEMONIC_SUFFIX));
232       }
233
234 //change language in textView menu bar.
235
JMenuBar textViewMenuBar = ed.getTextPreview().getMenuBar();
236       me = textViewMenuBar.getSubElements();
237       for(int i = 0; i<me.length; i++) {
238          JMenu jm = (JMenu) me[i].getComponent();
239          for( int j = 0; j < jm.getItemCount(); j++ ) {
240             JMenuItem jmi = (JMenuItem) jm.getItem(j);
241             jmi.setLocale(ResourceManager.getChoosenLocale());
242             jmi.setText(ResourceManager.getLanguageDependentString(jmi.getActionCommand()+JaWEConstants.LABEL_SUFFIX));
243             // change mnemonic
244
ed.getBarFactory().setMnemonic(jmi,ResourceManager.getLanguageDependentString(jmi.getActionCommand()+JaWEConstants.MNEMONIC_SUFFIX));
245             // change accelerator
246
ed.getBarFactory().setAccelerator(jmi,ResourceManager.getLanguageDependentString(jmi.getActionCommand()+JaWEConstants.ACCEL_SUFFIX));
247          }
248          jm.setLocale(ResourceManager.getChoosenLocale());
249          jm.setText(ResourceManager.getLanguageDependentString(jm.getActionCommand()+JaWEConstants.LABEL_SUFFIX));
250          // change mnemonic
251
ed.getBarFactory().setMnemonic(jm,ResourceManager.getLanguageDependentString(jm.getActionCommand()+JaWEConstants.MNEMONIC_SUFFIX));
252       }
253    }
254
255    /** Changes the language and Locale of toolbar components */
256    private void changeToolbarComponents (AbstractEditor ed) {
257       AbstractButton ab = null;
258       Iterator iter = ed.getToolbarComponents().values().iterator();
259       while (iter.hasNext()) {
260          ab = (AbstractButton) iter.next();
261          ab.setLocale(ResourceManager.getChoosenLocale());
262          ab.setToolTipText(ResourceManager.getLanguageDependentString(ab.getActionCommand()+JaWEConstants.TIP_SUFFIX));
263       }
264    }
265
266
267    /** Changes the language and Locale of tabbed pane items */
268    private void changeTabbedPaneItems (AbstractEditor ed) {
269       ed.getTabbedPane().setLocale(ResourceManager.getChoosenLocale());
270
271       String JavaDoc[] toolBars = Utils.tokenize(ResourceManager.getResourceString(ed.toolbarToLoad())," ");
272       for (int i=0; i<toolBars.length; i++) {
273          // if I found "-" it means that button follows
274
if (!toolBars[i].equals("-")) {
275             try {
276                String JavaDoc nm = ResourceManager.getLanguageDependentString(toolBars[i]+JaWEConstants.LABEL_SUFFIX);
277                ed.getTabbedPane().setTitleAt(i,nm);
278                ed.getTabbedPane().setToolTipTextAt(i,nm);
279             } catch (Exception JavaDoc ex) {
280                //
281
}
282          }
283          else {
284             break;
285          }
286       }
287    }
288
289    private void changeSpecialButtons (AbstractEditor ed) {
290       JComponent c;
291       Object JavaDoc[] keys=ed.getSpecialButtons().keySet().toArray();
292       for (int i=0; i<keys.length; i++) {
293          c=(JComponent)ed.getSpecialButtons().get(keys[i]);
294          c.setLocale(ResourceManager.getChoosenLocale());
295          c.setToolTipText(ResourceManager.getLanguageDependentString((String JavaDoc)keys[i]+JaWEConstants.TIP_SUFFIX));
296       }
297    }
298
299    private void changeSpecialItems(AbstractEditor ed) {
300       JMenuItem mi;
301       Object JavaDoc[] keys=ed.getSpecialItems().keySet().toArray();
302       for (int i=0; i<keys.length; i++) {
303          mi=(JMenuItem)ed.getSpecialItems().get(keys[i]);
304          mi.setLocale(ResourceManager.getChoosenLocale());
305          ed.getBarFactory().setAccelerator(mi,
306                ResourceManager.getLanguageDependentString((String JavaDoc)keys[i]+JaWEConstants.ACCEL_SUFFIX));
307          ed.getBarFactory().setMnemonic(mi,
308                ResourceManager.getLanguageDependentString((String JavaDoc)keys[i]+JaWEConstants.MNEMONIC_SUFFIX));
309       }
310    }
311
312    /**
313     * Changes the language and Locale of packagel tree panel and
314     * import external participants components.
315     */

316    private void changePackageSpecific(PackageEditor pe) {
317
318       pe.getPackageTreePanel().setLocale(ResourceManager.getChoosenLocale());
319       pe.getPackageTreePanel().setTitle(ResourceManager.
320             getLanguageDependentString("PackageAndExternalPackagesKey"),false);
321
322       // catche exception if LDAP dialog wasn't instantiated
323
try {
324          ((ImportExternalParticipants)pe.getAction(Utils.
325                getUnqualifiedClassName(ImportExternalParticipants.class))).
326                refreshLabels();
327       } catch (Exception JavaDoc ex) {}
328       org.enhydra.jawe.xml.elements.Participant.
329             getFreeTextExpressionParticipant().set("Name",ResourceManager.
330             getLanguageDependentString("FreeTextExpressionParticipantKey"));
331
332       // change the help tutorial and manual
333
try {
334          ((HelpTutorial)pe.getAction("HelpTutorial")).createHelp();
335       } catch (Exception JavaDoc ex) {}
336       try {
337          ((HelpManual)pe.getAction("HelpManual")).createHelp();
338       } catch (Exception JavaDoc ex) {}
339    }
340
341    private void changeContentTab (AbstractEditor ed) {
342       JTabbedPane ctp=ed.getContentTabbedPane();
343       ctp.setTitleAt(0,ResourceManager.getLanguageDependentString("GraphViewKey"));
344       ctp.setTitleAt(1,ResourceManager.getLanguageDependentString("TextViewKey"));
345       ctp.setTitleAt(2,ResourceManager.getLanguageDependentString("XPDLViewKey"));
346    }
347
348    private void changeTextViewTab( AbstractEditor ed ) {
349       ed.getTextPreview().getTextTreePanel().setTitle(
350           ResourceManager.getLanguageDependentString("PackageAndExternalPackagesXPDLKey"), false);
351    }
352
353    private void changeXPDLViewTab( AbstractEditor ed ) {
354       ed.getXPDLPreview().changeLanguage();
355    }
356
357    private void changeLanguage(AbstractEditor ed) {
358       // Call change language for menu items
359
changeMenuItems(ed);
360       // Call change language for toolbar components
361
changeToolbarComponents(ed);
362       // Call change language for menu bar
363
changeMenuBar(ed);
364       // Call change language for tabbed pane
365
changeTabbedPaneItems(ed);
366       // Call change language for special buttons
367
changeSpecialButtons(ed);
368       // Call change language for special items
369
changeSpecialItems(ed);
370       // Call change for some specific stuff
371
changeContentTab(ed);
372       // Cal change in text view tab
373
changeTextViewTab(ed);
374       // Cal change in XPDL view tab
375
changeXPDLViewTab(ed);
376
377    }
378
379 }
380
Popular Tags