1 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 ; 20 import java.util.*; 21 import javax.swing.*; 22 import java.awt.*; 23 import java.awt.event.*; 24 25 28 public class ChangeLanguage extends ActionBase { 29 public ChangeLanguage (PackageEditor editor) { 30 super(editor); 31 } 32 33 public void actionPerformed(ActionEvent e) { 34 makeChangeLangDialog(); 35 } 36 37 public void makeChangeLangDialog() { 38 final JList list; 39 JFrame frame = (JFrame)editor.getWindow(); 40 String 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 JButton cancelButton = new JButton(ResourceManager.getLanguageDependentString("CancelKey")); 46 final JButton setButton = new JButton(ResourceManager.getLanguageDependentString("SetKey")); 48 changeLangDlg.getRootPane().setDefaultButton(setButton); 49 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 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 = new JList(pfLocales.toArray()); 67 68 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 JLabel lab = new JLabel(ResourceManager.getLanguageDependentString("AvailableLocales")); 75 lab.setLabelFor(list); 76 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 Container contentPane = changeLangDlg.getContentPane(); 85 contentPane.add(listPane, BorderLayout.CENTER); 86 contentPane.add(buttonPane, BorderLayout.SOUTH); 87 changeLangDlg.setResizable(true); 88 cancelButton.addActionListener(new ActionListener() { 90 public void actionPerformed(ActionEvent e) { 91 changeLangDlg.dispose(); 92 } 93 }); 94 setButton.addActionListener(new ActionListener() { 95 public void actionPerformed(ActionEvent e) { 96 Object temp = list.getSelectedValue(); 97 if(temp != null) { 98 PFLocale pfloc=(PFLocale)temp; 99 try { 100 ResourceManager.setChoosen(pfloc.getLocale()); 101 try { 103 editor.setTitle(editor.getWindow(),editor.getTitle()); 104 } catch (Exception ex) {} 105 editor.getStatusBar().updateMessage(); 107 ConfigDialog.getInstance().refreshLanguageDependentStrings(); 109 changeLanguage(editor); 111 changePackageSpecific((PackageEditor)editor); 113 changeLanguageForAllEditors(); 117 118 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 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 e) { 157 changeLangDlg.dispose(); 158 } 159 }); 160 Utils.center(changeLangDlg,100,100); 161 162 changeLangDlg.show(); 163 } 164 165 166 private void changeLanguageForAllEditors () { 167 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 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 changeLanguage(pe); 193 } 194 } 195 196 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 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 ed.getBarFactory().setMnemonic(jmi,ResourceManager.getLanguageDependentString(jmi.getActionCommand()+JaWEConstants.MNEMONIC_SUFFIX)); 218 ed.getBarFactory().setAccelerator(jmi,ResourceManager.getLanguageDependentString(jmi.getActionCommand()+JaWEConstants.ACCEL_SUFFIX)); 220 } 221 } 222 223 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 ed.getBarFactory().setMnemonic(jm,ResourceManager.getLanguageDependentString(jm.getActionCommand()+JaWEConstants.MNEMONIC_SUFFIX)); 232 } 233 234 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 ed.getBarFactory().setMnemonic(jmi,ResourceManager.getLanguageDependentString(jmi.getActionCommand()+JaWEConstants.MNEMONIC_SUFFIX)); 245 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 ed.getBarFactory().setMnemonic(jm,ResourceManager.getLanguageDependentString(jm.getActionCommand()+JaWEConstants.MNEMONIC_SUFFIX)); 252 } 253 } 254 255 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 268 private void changeTabbedPaneItems (AbstractEditor ed) { 269 ed.getTabbedPane().setLocale(ResourceManager.getChoosenLocale()); 270 271 String [] toolBars = Utils.tokenize(ResourceManager.getResourceString(ed.toolbarToLoad())," "); 272 for (int i=0; i<toolBars.length; i++) { 273 if (!toolBars[i].equals("-")) { 275 try { 276 String nm = ResourceManager.getLanguageDependentString(toolBars[i]+JaWEConstants.LABEL_SUFFIX); 277 ed.getTabbedPane().setTitleAt(i,nm); 278 ed.getTabbedPane().setToolTipTextAt(i,nm); 279 } catch (Exception ex) { 280 } 282 } 283 else { 284 break; 285 } 286 } 287 } 288 289 private void changeSpecialButtons (AbstractEditor ed) { 290 JComponent c; 291 Object [] 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 )keys[i]+JaWEConstants.TIP_SUFFIX)); 296 } 297 } 298 299 private void changeSpecialItems(AbstractEditor ed) { 300 JMenuItem mi; 301 Object [] 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 )keys[i]+JaWEConstants.ACCEL_SUFFIX)); 307 ed.getBarFactory().setMnemonic(mi, 308 ResourceManager.getLanguageDependentString((String )keys[i]+JaWEConstants.MNEMONIC_SUFFIX)); 309 } 310 } 311 312 316 private void changePackageSpecific(PackageEditor pe) { 317 318 pe.getPackageTreePanel().setLocale(ResourceManager.getChoosenLocale()); 319 pe.getPackageTreePanel().setTitle(ResourceManager. 320 getLanguageDependentString("PackageAndExternalPackagesKey"),false); 321 322 try { 324 ((ImportExternalParticipants)pe.getAction(Utils. 325 getUnqualifiedClassName(ImportExternalParticipants.class))). 326 refreshLabels(); 327 } catch (Exception ex) {} 328 org.enhydra.jawe.xml.elements.Participant. 329 getFreeTextExpressionParticipant().set("Name",ResourceManager. 330 getLanguageDependentString("FreeTextExpressionParticipantKey")); 331 332 try { 334 ((HelpTutorial)pe.getAction("HelpTutorial")).createHelp(); 335 } catch (Exception ex) {} 336 try { 337 ((HelpManual)pe.getAction("HelpManual")).createHelp(); 338 } catch (Exception 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 changeMenuItems(ed); 360 changeToolbarComponents(ed); 362 changeMenuBar(ed); 364 changeTabbedPaneItems(ed); 366 changeSpecialButtons(ed); 368 changeSpecialItems(ed); 370 changeContentTab(ed); 372 changeTextViewTab(ed); 374 changeXPDLViewTab(ed); 376 377 } 378 379 } 380 | Popular Tags |