• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *****************************************************************************
3  * Copyright (C) 2000-2004, International Business Machines Corporation and  *
4  * others. All Rights Reserved.                                              *
5  *****************************************************************************
6  */
7 package com.ibm.rbm.gui;
8 
9 import java.awt.*;
10 import java.awt.event.*;
11 import java.io.*;
12 import java.util.*;
13 import javax.swing.*;
14 import javax.swing.event.*;
15 import javax.swing.tree.*;
16 
17 import com.ibm.rbm.*;
18 
19 /**
20  * The Graphical User Interface for working with and through a Resource Bundle Manager. The GUI has no public main
21  * method. It is instead instantiated from running the main method in RBManager. For help with using this interface,
22  * consult the documentation included in the project.
23  *
24  * @author Jared Jackson
25  * @see com.ibm.rbm.RBManager
26  */
27 public class RBManagerGUI extends JFrame implements ActionListener, MouseListener, ChangeListener, TreeSelectionListener
28 {
29 	// CONSTANTS
30 	private static final int buffer = 20;
31 	private static final Dimension dimMain = new Dimension(750,550);
32 	private static final Dimension dimMainMax = new Dimension(2000,1500);
33 	private static final Dimension dimMainMin = new Dimension(550,350);
34 	private static final Dimension dimTop = new Dimension(dimMain.width - buffer,50);
35 	private static final Dimension dimTopMax = new Dimension(dimMainMax.width - buffer,50);
36 	private static final Dimension dimTopMin = new Dimension(dimMainMin.width - buffer,50);
37 	private static final Dimension dimBottom = new Dimension(dimMain.width - buffer,dimMain.height-dimTop.height - buffer);
38 	private static final Dimension dimBottomMax = new Dimension(dimMainMax.width - buffer,dimMainMax.height-dimTopMin.height - buffer);
39 	private static final Dimension dimBottomMin = new Dimension(dimMainMin.width - buffer,dimMainMin.height-dimTopMax.height - buffer);
40 	private static final Dimension dimLeft = new Dimension(175,dimBottom.height - buffer);
41 	private static final Dimension dimRight = new Dimension(dimMain.width-dimLeft.width - buffer,dimBottom.height - buffer);
42 
43 	/**
44 	 * Used for toggling the debug mode
45 	 */
46 	public static final boolean debug = false;
47 	/**
48 	 * Used to count debug messages
49 	 */
50 	public static int debugcount = 0;
51 
52 	// member declarations
53 
54 	// ** DATA **
55 	RBManager rbm = null;
56 	String userName = Resources.getTranslation("unknown_user");
57 
58 	DefaultMutableTreeNode activeNode = null;
59 
60 	// ** MAIN MENU **
61 	RBManagerMenuBar         jMenuBarMain = null;
62 
63 	// ** CONTENT PANES **
64 	Box          boxMain = new Box(BoxLayout.Y_AXIS);
65 	//JPanel       jPanelTop = new JPanel();
66 	JPanel       jPanelBottom = new JPanel();
67 	JSplitPane   jSplitPaneMain = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
68 
69 	// ** SPLIT PANE COMPONENTS **
70 	JTree        jTreeDisplay = new JTree();
71 	JTabbedPane  jTabbedPaneMain = new JTabbedPane();
72 	RBStatisticsPanel        jPanelStats = new RBStatisticsPanel();
73 	RBUntranslatedPanel      jPanelUntrans = new RBUntranslatedPanel(this);
74 	RBGroupPanel             jPanelGroups = new RBGroupPanel(this);
75 	RBSearchPanel            jPanelSearch = new RBSearchPanel(this);
76 	JScrollPane  jScrollPaneTree = new JScrollPane(jTreeDisplay,
77 													ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
78 													ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
79 	// ** PROJECT VIEW SPLIT PANE COMPONENTS
80 	JTabbedPane              treeTabbedPane = new JTabbedPane();
81 	JTree                    projectTree = new JTree();
82 	JScrollPane              projectScrollPane = new JScrollPane(projectTree,
83 																ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
84 																ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
85 	RBProjectItemPanel       projectPanel = new RBProjectItemPanel(this);
86 	RBProject                project = null;
87 
88 	// ** File Chooser **
89 	JFileChooser openFileChooser = new JFileChooser();
90 	JFileChooser saveFileChooser = new JFileChooser();
91 	JFileChooser projectFileChooser = new JFileChooser();
92 
93 	/**
94 	 * Creation of the GUI should be immediately followed by the method calls to initComponents() and setVisible(true).
95 	 * These methods were not called by default for programming discretion
96 	 */
97 
RBManagerGUI()98 	public RBManagerGUI()
99 	{
100 	}
101 
102 	/**
103 	 * Inherits from JFrame.validate(), with some component updates
104 	 */
105 
validate()106 	public void validate() {
107 		super.validate();
108 		updateDisplayPanels();
109 	}
110 
111 	/**
112 	 * Initial construction of all of the GUI components. This method should be called immediately following the
113 	 * construction of the GUI object.
114 	 */
115 
initComponents()116 	public void initComponents() throws Exception
117 	{
118 		this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
119 		// the following code sets the frame's initial state
120 
121 		openFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
122 			public boolean accept(File f) {
123 				if (f.isDirectory()) return true;
124 
125 				String name = f.getName();
126 				if (!(name.toLowerCase().endsWith(".properties"))) return false;
127 				if (name.indexOf("_") > 0) return false;
128 				return true;
129 			}
130 
131 			public String getDescription() {
132 				return Resources.getTranslation("dialog_file_filter_description");
133 			}
134 		});
135 
136 		saveFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
137 			public boolean accept(File f) {
138 				if (f.isDirectory()) return true;
139 
140 				String name = f.getName();
141 				if (!(name.toLowerCase().endsWith(".properties"))) return false;
142 				if (name.indexOf("_") > 0) return false;
143 				return true;
144 			}
145 
146 			public String getDescription() {
147 				return Resources.getTranslation("dialog_file_filter_description");
148 			}
149 		});
150 
151 		projectFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
152 			public boolean accept(File f) {
153 				if (f.isDirectory()) return true;
154 
155 				String name = f.getName();
156 				if (!(name.toLowerCase().endsWith(".rbproject"))) return false;
157 				return true;
158 			}
159 
160 			public String getDescription() {
161 				return Resources.getTranslation("dialog_project_filter_description");
162 			}
163 		});
164 
165         // ** The Main program icon **
166         setIconImage((new ImageIcon(getClass().getResource("images/tree_icon_bundle.gif"))).getImage());
167 
168 		// ** MAIN MENU BAR ITEMS **
169 		jMenuBarMain = new RBManagerMenuBar(this);
170 
171 		// ** DISPLAY TREE **
172 		//jScrollPaneTree.setSize(dimLeft);
173 		updateDisplayTree();
174 		updateProjectTree();
175 		updateProjectPanels();
176 
177 		jPanelStats.setSize(dimRight);
178 		jPanelUntrans.setSize(dimRight);
179 		jPanelGroups.setSize(dimRight);
180 		jPanelSearch.setSize(dimRight);
181 
182 		// ** MAIN TABBED PANE **
183 		jTabbedPaneMain.setSize(dimRight);
184 		jTabbedPaneMain.addTab(Resources.getTranslation("tab_statistics"), jPanelStats);
185 		jTabbedPaneMain.addTab(Resources.getTranslation("tab_untranslated"), jPanelUntrans);
186 		jTabbedPaneMain.addTab(Resources.getTranslation("tab_groups"), jPanelGroups);
187 		jTabbedPaneMain.addTab(Resources.getTranslation("tab_search"), jPanelSearch);
188 
189 		// ** LEFT TABBED PANE **
190 		treeTabbedPane.setSize(dimLeft);
191 		treeTabbedPane.setPreferredSize(dimLeft);
192 		treeTabbedPane.addTab(Resources.getTranslation("tab_bundle"), jScrollPaneTree);
193 		treeTabbedPane.addTab(Resources.getTranslation("tab_project"), projectScrollPane);
194 		treeTabbedPane.addChangeListener(this);
195 
196 		// ** MAIN SPLIT PANE **
197 		//jSplitPaneMain.setSize(dimBottom);
198 		//jSplitPaneMain.setLeftComponent(jScrollPaneTree);
199 		jSplitPaneMain.setLeftComponent(treeTabbedPane);
200 		jSplitPaneMain.setRightComponent(jTabbedPaneMain);
201 		jSplitPaneMain.setContinuousLayout(true);
202 
203 		// ** BOTTOM PANEL **
204 		//jPanelBottom.setPreferredSize(dimBottom);
205 		jPanelBottom.setMaximumSize(dimBottomMax);
206 		jPanelBottom.setMinimumSize(dimBottomMin);
207 		jPanelBottom.setBorder(BorderFactory.createLineBorder(Color.black));
208 		jPanelBottom.setLayout(new BorderLayout(1,1));
209 		jPanelBottom.removeAll();
210 		jPanelBottom.add(jSplitPaneMain, BorderLayout.CENTER);
211 
212 		// ** MAIN FRAME SETUP **
213 		dimMain.height += jMenuBarMain.getPreferredSize().height;
214 		setSize(dimMain);
215 		((JComponent)getContentPane()).setMaximumSize(dimMainMax);
216 		((JComponent)getContentPane()).setMinimumSize(dimMainMin);
217 		setJMenuBar(jMenuBarMain);
218 		getContentPane().removeAll();
219 		getContentPane().add(jPanelBottom, BorderLayout.CENTER);
220 		setTitle(Resources.getTranslation("resource_bundle_manager"));
221 		validateTree();
222 
223 		addWindowListener(new java.awt.event.WindowAdapter() {
224 			public void windowClosing(java.awt.event.WindowEvent e) {
225 				thisWindowClosing(e);
226 			}
227 		});
228 	}
229 
230   	private boolean mShown = false;
231 
232 	/**
233 	 * Reveals the private method of JFrame.validateTree()
234 	 */
235 
validateMyTree()236 	public void validateMyTree() {
237 		validateTree();
238 	}
239 
240 	/**
241 	 * Creates a new Resource File (i.e. English, English Canada, Finnish, etc.)
242 	 */
243 
createResourceFile()244 	public void createResourceFile() {
245 		new ResourceCreationDialog(rbm, this, Resources.getTranslation("dialog_title_new_file"), true);
246 	}
247 
248 	/**
249 	 * Creates a new group for grouping BundleItems
250 	 */
251 
createBundleGroup()252 	public void createBundleGroup() {
253 		new BundleGroupCreationDialog(rbm, this, Resources.getTranslation("dialog_title_new_group"), true);
254 		updateDisplayPanels();
255 	}
256 
257 	/**
258 	 * Creates a new BundleItem
259 	 */
260 
createBundleItem()261 	public void createBundleItem() {
262 		new BundleItemCreationDialog(rbm, this, Resources.getTranslation("dialog_title_new_item"), true);
263 		updateDisplayPanels();
264 		updateProjectTree();
265 	}
266 
267 	/**
268 	 * Handles events generated
269 	 */
270 
valueChanged(TreeSelectionEvent ev)271 	public void valueChanged(TreeSelectionEvent ev) {
272 		if (ev.getSource() == projectTree) updateProjectPanels();
273 		else if (ev.getSource() == jTreeDisplay) {
274 			TreePath selPath = jTreeDisplay.getSelectionPath();
275 			activeNode = (DefaultMutableTreeNode)selPath.getLastPathComponent();
276 			updateDisplayPanels();
277 			/*
278 			int selRow = jTreeDisplay.getRowForLocation(ev.getX(), ev.getY());
279 			TreePath selPath = jTreeDisplay.getPathForLocation(ev.getX(), ev.getY());
280 			if (selRow != -1) {
281             if (ev.getClickCount() == 1 && ev.getSource() == jTreeDisplay) {
282 
283 				System.out.println("Other tree");
284 			} else if (ev.getClickCount() == 1 && ev.getSource() == projectTree) {
285 				System.out.println("Mouse pressed");
286 				updateProjectPanels();
287 			} else System.out.println(String.valueOf(ev.getClickCount()) + " " + ev.getSource().toString());
288 
289 			*/
290 		}
291 	}
292 
stateChanged(ChangeEvent ev)293 	public void stateChanged(ChangeEvent ev) {
294 		if (ev.getSource() == treeTabbedPane) {
295 			int index = treeTabbedPane.getSelectedIndex();
296 			String title = treeTabbedPane.getTitleAt(index);
297 			if (title.equals(Resources.getTranslation("tab_bundle"))) {
298 				jSplitPaneMain.setRightComponent(jTabbedPaneMain);
299 				updateDisplayPanels();
300 			} else if (title.equals(Resources.getTranslation("tab_project"))) {
301 				jSplitPaneMain.setRightComponent(projectPanel);
302 				updateProjectPanels();
303 			}
304 		}
305 	}
306 
actionPerformed(ActionEvent ev)307 	public void actionPerformed(ActionEvent ev) {
308 		if (ev.getID() == ActionEvent.ACTION_PERFORMED) {
309 			if (ev.getSource() instanceof JMenuItem && ((JMenuItem)ev.getSource()).getName() != null &&
310 				((JMenuItem)ev.getSource()).getName().startsWith("__")) {               // Menu -> File -> __Recent File
311 				// This item is a recent file selection. We need to open that file
312 				String fileLocation = ((JMenuItem)ev.getSource()).getName();
313 				fileLocation = fileLocation.substring(2,fileLocation.length());
314 				try {
315 					rbm = new RBManager(new File(fileLocation));
316 					updateDisplayTree();
317 					updateProjectTree();
318 					updateProjectPanels();
319 				} catch (IOException ioe) {
320 					JOptionPane.showMessageDialog(this,Resources.getTranslation("error_opening_file", ev.getActionCommand()),
321 												  Resources.getTranslation("dialog_title_error_opening_file"),
322 												  JOptionPane.ERROR_MESSAGE);
323 					rbm = null;
324 				}
325 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_tree_save")) &&
326 					   ((JMenuItem)ev.getSource()).getName() != null) {                // Popup Tree Menu -> Save
327 				String selectedEncoding = ((JMenuItem)ev.getSource()).getName();
328 				saveResources(selectedEncoding);
329 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_tree_hide")) &&
330 					   ((JMenuItem)ev.getSource()).getName() != null) {                // Popup Tree Menu -> Hide
331 				String selectedEncoding = ((JMenuItem)ev.getSource()).getName();
332 				// Should I prompt for this?
333 				hideResources(selectedEncoding);
334 			}  else if (ev.getActionCommand().equals(Resources.getTranslation("menu_tree_delete")) &&
335 					   ((JMenuItem)ev.getSource()).getName() != null) {                // Popup Tree Menu -> Delete
336 				String selectedEncoding = ((JMenuItem)ev.getSource()).getName();
337 				int response = JOptionPane.showConfirmDialog(this,
338 					Resources.getTranslation("dialog_delete_warning"),
339 					Resources.getTranslation("dialog_title_quit"), JOptionPane.YES_NO_CANCEL_OPTION,
340 					JOptionPane.WARNING_MESSAGE);
341 				if (response == JOptionPane.YES_OPTION) {
342 					deleteResources(selectedEncoding);
343 				}
344 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_tree_new_project"))) {
345 				String response = JOptionPane.showInputDialog(this,                   // Popup Project Menu -> New Project
346 					Resources.getTranslation("dialog_new_project"), Resources.getTranslation("dialog_title_new_project"),
347 					JOptionPane.QUESTION_MESSAGE);
348 				if (response == null || response.trim().equals("")) return;
349 				project = new RBProject(response);
350 				updateProjectTree();
351 				updateProjectPanels();
352 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_tree_open_project"))) {
353 				int result = projectFileChooser.showOpenDialog(this);                // Popup Project Menu -> Open Project
354 				if (result == JFileChooser.APPROVE_OPTION) {
355 					File f = projectFileChooser.getSelectedFile();
356 					try {
357 						project = new RBProject(f);
358 						updateProjectTree();
359 						updateProjectPanels();
360 					} catch (Exception ex) {
361 						JOptionPane.showMessageDialog(this,
362 							Resources.getTranslation("error_creating_project"),
363 							Resources.getTranslation("dialog_title_error"), JOptionPane.ERROR_MESSAGE);
364 					}
365 				}
366 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_tree_save_project"))) {
367 				int result = projectFileChooser.showSaveDialog(this);                // Popup Project Menu -> Save Project
368 				if (result == JFileChooser.APPROVE_OPTION) {
369 					File f = projectFileChooser.getSelectedFile();
370 					try {
371 						project.write(f);
372 					} catch (Exception ex) {
373 						JOptionPane.showMessageDialog(this,
374 							Resources.getTranslation("error_saving_project"),
375 							Resources.getTranslation("dialog_title_error"), JOptionPane.ERROR_MESSAGE);
376 					}
377 				}
378 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_tree_add_project_bundle"))) {
379 				int result = openFileChooser.showOpenDialog(this);                   // Popup Project Menu -> Add Bundle
380 				if (result == JFileChooser.APPROVE_OPTION) {
381 					File f = openFileChooser.getSelectedFile();
382 					try {
383 						project.addBundle(f.getAbsolutePath());
384 						updateProjectTree();
385 						updateProjectPanels();
386 					} catch (Exception ex) {
387 						JOptionPane.showMessageDialog(this,
388 							Resources.getTranslation("error_adding_project_bundle"),
389 							Resources.getTranslation("dialog_title_error"), JOptionPane.ERROR_MESSAGE);
390 					}
391 				}
392 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_tree_remove_project_bundle"))) {
393 				String bundleName = ((JMenuItem)ev.getSource()).getName();           // Popup Project Menu -> Remove Bundle
394 				project.removeBundle(bundleName);
395 				updateProjectTree();
396 				updateProjectPanels();
397 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_tree_select_project_bundle"))) {
398 				String bundleName = ((JMenuItem)ev.getSource()).getName();           // Popup Project Menu -> Select Bundle
399 				RBManager bundle = project.getBundle(bundleName);
400 				rbm = bundle;
401 				updateDisplayTree();
402 				updateDisplayPanels();
403 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_quit"))) {
404 																					   // Menu -> File -> Quit
405 				thisWindowClosing(null);
406 				return;
407 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_new"))) {
408 																					   // Menu -> File -> New Resource Bundle
409 				promptForSave(null);
410 				String oldUser = getUser();
411 				if (rbm != null && rbm.getUser() != null && !(rbm.getUser().equals(Resources.getTranslation("unknown_user"))))
412 					oldUser = rbm.getUser();
413 				String response = JOptionPane.showInputDialog(this,
414 					Resources.getTranslation("dialog_new_baseclass"), Resources.getTranslation("dialog_title_new_bundle"),
415 					JOptionPane.QUESTION_MESSAGE);
416 				if (response != null) {
417 					// Test the response for white space
418 					if (response.indexOf(" ") > 0 || response.indexOf("\t") > 0 || response.indexOf("\n") > 0) {
419 						JOptionPane.showMessageDialog(this,
420 							Resources.getTranslation("error_baseclass_whitespace") + "\n" + Resources.getTranslation("error_bundle_not_created"),
421 							Resources.getTranslation("dialog_title_error_creating_bundle"), JOptionPane.ERROR_MESSAGE);
422 					} else {
423 						rbm = new RBManager(response);
424 						updateDisplayTree();
425 						updateProjectTree();
426 						updateProjectPanels();
427 						updateDisplayPanels();
428 					}
429 				}
430 				// Update the user information
431 				if (oldUser.equals(Resources.getTranslation("unknown_user"))) {
432 					String user = JOptionPane.showInputDialog(this,
433 						Resources.getTranslation("dialog_user_name"), Resources.getTranslation("dialog_title_user_name"),
434 						JOptionPane.QUESTION_MESSAGE);
435 					if (user != null && !(user.equals(""))) setUser(user);
436 				} else rbm.setUser(oldUser);
437 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_open"))) {
438 																					   // Menu -> File -> Open Resource Bundle
439 				promptForSave(null);
440 				String oldUser = getUser();
441 				if (rbm != null && rbm.getUser() != null && !(rbm.getUser().equals(Resources.getTranslation("unknown_user"))))
442 					oldUser = rbm.getUser();
443 				openFileChooser.setSelectedFile(new File("Resources" + File.separator + "RBManager.properties"));
444 				int status = openFileChooser.showOpenDialog(this);
445 				if (status == JFileChooser.CANCEL_OPTION) {
446 					// File opening canceled
447 				} else if (status == JFileChooser.ERROR_OPTION) {
448 					// Error in file open
449 				} else {
450 					// A file has been selected
451 					try {
452 						rbm = new RBManager(openFileChooser.getSelectedFile());
453 						updateDisplayTree();
454 						updateProjectTree();
455 						updateProjectPanels();
456 					} catch (IOException ioe) {
457 						// Should provide some alert here
458 						System.err.println("Could not open the file " + openFileChooser.getSelectedFile().getAbsolutePath() +
459 										   ": " + ioe.getMessage());
460 						rbm = null;
461 					}
462 				}
463 				if (rbm == null) return;
464 				// Update the user information
465 				if (oldUser.equals(Resources.getTranslation("unknown_user"))) {
466 					String user = JOptionPane.showInputDialog(this,
467 						Resources.getTranslation("dialog_user_name"), Resources.getTranslation("dialog_title_user_name"),
468 						JOptionPane.QUESTION_MESSAGE);
469 					if (user != null && !(user.equals("")))
470 						setUser(user);
471 				} else
472 					rbm.setUser(oldUser);
473 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_save"))) {
474 																					   // Menu -> File -> Save Resource Bundle
475 				saveResources();
476 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_saveas"))) {
477 																					   // Menu -> File -> Save Resource Bundle As
478 				saveResourcesAs();
479 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_import_properties"))) {
480 																					   // Menu -> File -> Import -> Properties
481 				if (rbm == null || rbm.getBundles() == null) return;
482 				RBPropertiesImporter importer = new RBPropertiesImporter(Resources.getTranslation("import_properties_title"), rbm, this);
483 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_import_java"))) {
484 																					   // Menu -> File -> Import -> Java
485 				if (rbm == null || rbm.getBundles() == null) return;
486 				RBJavaImporter importer = new RBJavaImporter(Resources.getTranslation("import_java_title"), rbm, this);
487 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_import_TMX"))) {
488 																					   // Menu -> File -> Import -> TMX
489 				if (rbm == null || rbm.getBundles() == null)
490 					return;
491 				RBTMXImporter importer = new RBTMXImporter(Resources.getTranslation("import_TMX_title"), rbm, this);
492 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_import_XLF"))) {
493 				   // Menu -> File -> Import -> XLIFF
494 				if (rbm == null || rbm.getBundles() == null)
495 				    return;
496 				RBxliffImporter importer = new RBxliffImporter(Resources.getTranslation("import_XLF_title"), rbm, this);
497 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_export_properties"))) {
498 																					   // Menu -> File -> Export -> Properties
499 				RBPropertiesExporter exp = new RBPropertiesExporter();
500 				try {
501 					if (rbm != null && rbm.getBundles() != null)
502 						exp.export(rbm);
503 				} catch (IOException ioe) {
504 					JOptionPane.showMessageDialog(this, Resources.getTranslation("error_export"),
505 												  Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
506 				}
507 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_export_java"))) {
508 																					   // Menu -> File -> Export -> Java
509 				RBJavaExporter exp = new RBJavaExporter();
510 				try {
511 					if (rbm != null && rbm.getBundles() != null) exp.export(rbm);
512 				} catch (IOException ioe) {
513 					JOptionPane.showMessageDialog(this, Resources.getTranslation("error_export"),
514 												  Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
515 				}
516 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_export_ICU"))) {
517 																					   // Menu -> File -> Export -> Java
518 				RBICUExporter exp = new RBICUExporter();
519 				try {
520 					if (rbm != null && rbm.getBundles() != null) exp.export(rbm);
521 				} catch (IOException ioe) {
522 					JOptionPane.showMessageDialog(this, Resources.getTranslation("error_export"),
523 												  Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
524 				}
525 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_export_TMX"))) {
526 																					   // Menu -> File -> Export -> TMX
527 				RBTMXExporter exp = new RBTMXExporter();
528 				try {
529 					if (rbm != null && rbm.getBundles() != null) exp.export(rbm);
530 				} catch (IOException ioe) {
531 					JOptionPane.showMessageDialog(this, Resources.getTranslation("error_export"),
532 												  Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
533 				}
534 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_export_XLF"))) {
535 				   // Menu -> File -> Export -> XLIFF
536 				RBxliffExporter exp = new RBxliffExporter();
537 				try {
538 					if (rbm != null && rbm.getBundles() != null)
539 					    exp.export(rbm);
540 				} catch (IOException ioe) {
541 					JOptionPane.showMessageDialog(this, Resources.getTranslation("error_export"),
542 					Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
543 				}
544 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_options_addfile"))) {
545 																					   // Menu -> Options -> Add New Resource
546 				createResourceFile();
547 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_options_addgroup")) ||
548 					   ev.getActionCommand().equals(Resources.getTranslation("button_create_group"))) {
549 																					   // Menu -> Options -> Add New Group
550 				createBundleGroup();
551 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_options_addentry"))) {
552 																					   // Menu -> Options -> Add New Entry
553 				createBundleItem();
554 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_options_preferences"))) {
555 																					   // Menu -> Options -> Preferences
556 				PreferencesDialog pd = new PreferencesDialog(this);
557 			} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_help_about"))) {
558 																					   // Menu -> Help -> About RBManager
559 				AboutDialog.showDialog(this);
560 			} else RBManagerGUI.debugMsg("Missed Action Command: " + ev.getActionCommand());
561 
562 		}
563 
564 	}
565 
566 	/**
567 	 * Handles events generated
568 	 */
569 
mousePopup(MouseEvent ev)570 	public void mousePopup(MouseEvent ev) {
571 		if (ev.getSource() == jTreeDisplay) {
572 			int selRow = jTreeDisplay.getRowForLocation(ev.getX(), ev.getY());
573 			TreePath selPath = jTreeDisplay.getPathForLocation(ev.getX(), ev.getY());
574 			if (selRow != -1) {
575 			    if (ev.getClickCount() == 1) {
576 					DefaultMutableTreeNode node = (DefaultMutableTreeNode)selPath.getLastPathComponent();
577 					Object obj = node.getUserObject();
578 					if (obj == null || !(obj instanceof Bundle)) return;
579 					Bundle bundle = (Bundle)obj;
580 					String encoding = bundle.encoding;
581 					if (encoding == null) encoding = new String();
582 
583 					// Create the menu to display
584 					JPopupMenu popupMenu = new JPopupMenu();
585 					JMenuItem saveItem = new JMenuItem(Resources.getTranslation("menu_tree_save"));
586 					JMenuItem hideItem = new JMenuItem(Resources.getTranslation("menu_tree_hide"));
587 					JMenuItem deleteItem = new JMenuItem(Resources.getTranslation("menu_tree_delete"));
588 
589 					saveItem.setName(encoding); saveItem.addActionListener(this);
590 					hideItem.setName(encoding); hideItem.addActionListener(this);
591 					deleteItem.setName(encoding); deleteItem.addActionListener(this);
592 
593 					popupMenu.add(saveItem);
594 					if (node.getLevel() != 1) {
595 						popupMenu.add(hideItem);
596 						popupMenu.add(deleteItem);
597 					}
598 
599 					popupMenu.show(ev.getComponent(), ev.getX(), ev.getY());
600 			    }
601 			}
602 		} else if (ev.getSource() == projectTree) {
603 			int selRow = projectTree.getRowForLocation(ev.getX(), ev.getY());
604 			TreePath selPath = projectTree.getPathForLocation(ev.getX(), ev.getY());
605 			if (selRow != -1 && ev.getClickCount() == 1) {
606 				DefaultMutableTreeNode node = (DefaultMutableTreeNode)selPath.getLastPathComponent();
607 				Object obj = node.getUserObject();
608 				if (obj == null) return;
609 				else if (obj instanceof String) {
610 					JPopupMenu popupMenu = new JPopupMenu();
611 					JMenuItem newItem = new JMenuItem(Resources.getTranslation("menu_tree_new_project"));
612 					JMenuItem openItem = new JMenuItem(Resources.getTranslation("menu_tree_open_project"));
613 					JMenuItem saveItem = new JMenuItem(Resources.getTranslation("menu_tree_save_project"));
614 					newItem.addActionListener(this);
615 					openItem.addActionListener(this);
616 					saveItem.addActionListener(this);
617 					popupMenu.add(newItem);
618 					popupMenu.add(openItem);
619 					popupMenu.add(saveItem);
620 					popupMenu.show(ev.getComponent(), ev.getX(), ev.getY());
621 				} else if (obj instanceof RBProject) {
622 					JPopupMenu popupMenu = new JPopupMenu();
623 					JMenuItem newItem = new JMenuItem(Resources.getTranslation("menu_tree_new_project"));
624 					JMenuItem openItem = new JMenuItem(Resources.getTranslation("menu_tree_open_project"));
625 					JMenuItem saveItem = new JMenuItem(Resources.getTranslation("menu_tree_save_project"));
626 					JMenuItem addItem = new JMenuItem(Resources.getTranslation("menu_tree_add_project_bundle"));
627 					newItem.addActionListener(this);
628 					openItem.addActionListener(this);
629 					saveItem.addActionListener(this);
630 					addItem.addActionListener(this);
631 					popupMenu.add(newItem);
632 					popupMenu.add(openItem);
633 					popupMenu.add(saveItem);
634 					popupMenu.add(addItem);
635 					popupMenu.show(ev.getComponent(), ev.getX(), ev.getY());
636 				} else if (obj instanceof RBManager) {
637 					RBManager rbm = (RBManager)obj;
638 					JPopupMenu popupMenu = new JPopupMenu();
639 					JMenuItem selectItem = new JMenuItem(Resources.getTranslation("menu_tree_select_project_bundle"));
640 					JMenuItem removeItem = new JMenuItem(Resources.getTranslation("menu_tree_remove_project_bundle"));
641 					selectItem.setName(rbm.getBaseClass());
642 					removeItem.setName(rbm.getBaseClass());
643 					selectItem.addActionListener(this);
644 					removeItem.addActionListener(this);
645 					popupMenu.add(selectItem);
646 					popupMenu.add(removeItem);
647 					popupMenu.show(ev.getComponent(), ev.getX(), ev.getY());
648 				}
649 			}
650 		}
651 	}
652 
mousePressed(MouseEvent ev)653 	public void mousePressed(MouseEvent ev)  {
654 		if (ev.isPopupTrigger()) {
655 			mousePopup(ev);
656 		}
657 	}
658 
mouseReleased(MouseEvent ev)659 	public void mouseReleased(MouseEvent ev) {
660 		if (ev.isPopupTrigger()) {
661 			mousePopup(ev);
662 			return;
663 		}
664 		// Not the popup trigger
665 	}
666 
mouseEntered(MouseEvent ev)667 	public void mouseEntered(MouseEvent ev)  { }
668 
mouseExited(MouseEvent ev)669 	public void mouseExited(MouseEvent ev)   { }
670 
mouseClicked(MouseEvent ev)671 	public void mouseClicked(MouseEvent ev) {
672 		if (ev.getClickCount() == 2 && ev.getSource() instanceof JTable) {
673 			// We are going to display the edit frame for the item selected
674 			BundleItem item = null;
675 			JTable table = (JTable) ev.getSource();
676 			if (table.getModel() instanceof UntranslatedItemsTableModel) {
677 				int row = table.getSelectedRow();
678 				UntranslatedItemsTableModel model = (UntranslatedItemsTableModel)table.getModel();
679 				item = model.getBundleItem(row);
680 				BundleItemDialog biDialog = new BundleItemDialog(rbm, item, (rbm == null ? "" : rbm.getUser()),
681 															 this, Resources.getTranslation("dialog_title_edit_item"), true);
682 				model.update();
683 			} else if (table.getModel() instanceof SearchItemsTableModel) {
684 				int row = table.getSelectedRow();
685 				SearchItemsTableModel model = (SearchItemsTableModel)table.getModel();
686 				item = model.getBundleItem(row);
687 				BundleItemDialog biDialog = new BundleItemDialog(rbm, item, (rbm == null ? "" : rbm.getUser()),
688 															 this, Resources.getTranslation("dialog_title_edit_item"), true);
689 				model.update();
690 			} else if (table.getModel() instanceof GroupItemsTableModel) {
691 				int row = table.getSelectedRow();
692 				GroupItemsTableModel model = (GroupItemsTableModel)table.getModel();
693 				item = model.getBundleItem(row);
694 				BundleItemDialog biDialog = new BundleItemDialog(rbm, item, (rbm == null ? "" : rbm.getUser()),
695 															 this, Resources.getTranslation("dialog_title_edit_item"), true);
696 				model.update();
697 			}
698 			updateDisplayPanels();
699 		}
700 	}
701 
updateProjectPanels()702 	protected void updateProjectPanels() {
703 		projectPanel.updateComponents();
704 	}
705 
706 	// Update the display of the main panels (stats, untrans, groups). Should be called after a new tree selection
updateDisplayPanels()707 	protected void updateDisplayPanels() {
708 		debugMsg("Updating Display Panels");
709 
710 		Bundle bundle = null;
711 		if (activeNode == null) return;
712 		Object o = activeNode.getUserObject();
713 		if (o == null)
714 			return;
715 		if (o instanceof String) {
716 			// A node that is not a root was selected.... I need to do something here
717 			String str = (String)o;
718 			if (rbm == null) return;
719 			if (str.equals(rbm.getBaseClass())) {
720 				// The base class node was selected
721 				jPanelStats.setManager(rbm);
722 				jPanelUntrans.setManager(rbm);
723 				jPanelGroups.setManager(rbm);
724 				jPanelSearch.setManager(rbm);
725 			} else {
726 				jPanelStats.removeElements();
727 				jPanelUntrans.removeElements();
728 				jPanelGroups.removeElements();
729 				jPanelSearch.removeElements();
730 			}
731 			//return;
732 		}
733 		else if (o instanceof Bundle) {
734 			bundle = (Bundle) activeNode.getUserObject();
735 			jPanelStats.setBundle(bundle);
736 			jPanelUntrans.setBundle(bundle);
737 			jPanelGroups.setBundle(bundle);
738 			jPanelSearch.setBundle(bundle);
739 		}
740 		else
741 			RBManagerGUI.debugMsg(o.toString());
742 
743 		jPanelStats.updateComponents();
744 		jPanelUntrans.updateComponents();
745 		jPanelGroups.updateComponents();
746 		jPanelSearch.updateComponents();
747 
748 		validateTree();
749 	}
750 
updateProjectTree()751 	public void updateProjectTree() {
752 		debugMsg("Updating Project Trees");
753 
754 		DefaultMutableTreeNode root = null;
755 
756 		if (project != null) {
757 			root = new DefaultMutableTreeNode(project);
758 			for (int i=0; i < project.getSize(); i++) {
759 				RBManager rbm = project.getBundle(i);
760 				DefaultMutableTreeNode bundleNode = new DefaultMutableTreeNode(rbm);
761 				root.add(bundleNode);
762 				Bundle mainBundle = (Bundle)rbm.getBundles().firstElement();
763 				Vector groups = mainBundle.getGroupsAsVector();
764 				for (int j=0; j < groups.size(); j++) {
765 					BundleGroup group = (BundleGroup)groups.elementAt(j);
766 					DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode(group);
767 					bundleNode.add(groupNode);
768 					Vector items = group.getItemsAsVector();
769 					for (int k=0; k < items.size(); k++) {
770 						BundleItem item = (BundleItem)items.elementAt(k);
771 						DefaultMutableTreeNode itemNode = new DefaultMutableTreeNode(item);
772 						groupNode.add(itemNode);
773 					}
774 				}
775 			}
776 		} else if (rbm != null) {
777 			// There is a resource bundle open, but no project
778 			root = new DefaultMutableTreeNode(Resources.getTranslation("no_project"));
779 			Bundle mainBundle = (Bundle)rbm.getBundles().firstElement();
780 			DefaultMutableTreeNode bundleNode = new DefaultMutableTreeNode(rbm);//(rbm.getBaseClass());
781 			root.add(bundleNode);
782 			Vector groups = mainBundle.getGroupsAsVector();
783 			for (int i=0; i < groups.size(); i++) {
784 				BundleGroup group = (BundleGroup)groups.elementAt(i);
785 				DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode(group);
786 				bundleNode.add(groupNode);
787 				Vector items = group.getItemsAsVector();
788 				for (int j=0; j < items.size(); j++) {
789 					BundleItem item = (BundleItem)items.elementAt(j);
790 					DefaultMutableTreeNode itemNode = new DefaultMutableTreeNode(item);
791 					groupNode.add(itemNode);
792 				}
793 			}
794 		} else {
795 			root = new DefaultMutableTreeNode(Resources.getTranslation("no_project_bundle"));
796 		}
797 
798 		// Create the tree from the roots
799 		projectTree = new JTree(root);
800 		projectTree.addMouseListener(this);
801 		projectTree.addTreeSelectionListener(this);
802 		projectTree.setCellRenderer(RBTreeCellRenderer.getInstance());
803 		projectScrollPane.getViewport().removeAll();
804 		projectScrollPane.getViewport().add(projectTree);
805 		repaint();
806 		validateTree();
807 		return;
808 	}
809 
810 	// Update the display of the tree file map. Should be called when the tree is changed/updated
updateDisplayTree()811 	public void updateDisplayTree() {
812 		debugMsg("Updating Display Trees");
813 
814 		DefaultMutableTreeNode root = null;
815 
816 		if (rbm == null || rbm.getBundles() == null) {
817 			root = new DefaultMutableTreeNode(Resources.getTranslation("no_resource_bundle"));
818 		} else {
819 			// From here on out, there is a defined resource bundle manager
820 			Bundle mainBundle = (Bundle)rbm.getBundles().firstElement();
821 			root = new DefaultMutableTreeNode(rbm.getBaseClass());
822 			// Add the base class
823 			root.add(new DefaultMutableTreeNode(mainBundle));
824 
825 			//DefaultMutableTreeNode currNode = root;
826 			for (int i = 1; i < rbm.getBundles().size(); i++) {
827 				Bundle currBundle = (Bundle)rbm.getBundles().elementAt(i);
828 				String variant = currBundle.getVariantEncoding();
829 				String country = currBundle.getCountryEncoding();
830 				String language = currBundle.getLanguageEncoding();
831 				//DefaultMutableTreeNode languageNode = null;
832 				// Look for a node representing this language
833 				if (language == null || language.equals("")) continue;
834 				boolean languageNodeFound = false;
835 				for (int j=0; j < root.getChildCount(); j++) {
836 					DefaultMutableTreeNode langNode = (DefaultMutableTreeNode)root.getChildAt(j);
837 					Object o = langNode.getUserObject();
838 					if (o == null || !(o instanceof String)) continue;
839 					String str = (String)o;
840 					if (str.equals(Resources.getTranslation("tree_language_node", language))) {
841 						// There is a non-leaf node with this language
842 						languageNodeFound = true;
843 						if (country == null || country.equals(""))
844 							 langNode.add(new DefaultMutableTreeNode(currBundle));
845 						else {
846 							// We need to look at country, variant
847 							boolean countryNodeFound = false;
848 							for (int k=0; k < langNode.getChildCount(); k++) {
849 								DefaultMutableTreeNode countryNode = (DefaultMutableTreeNode)langNode.getChildAt(k);
850 								Object o2 = countryNode.getUserObject();
851 								if (o2 == null || !(o2 instanceof String)) continue;
852 								String str2 = (String)o2;
853 								if (str2.equals(Resources.getTranslation("tree_country_node", country))) {
854 									// There is a non-leaf node for this country
855 									countryNodeFound = true;
856 									if (variant == null || variant.equals("")) {
857 										countryNode.add(new DefaultMutableTreeNode(currBundle));
858 									} else {
859 										// We need to look at variant
860 										boolean variantNodeFound = false;
861 										for (int l=0; l < countryNode.getChildCount(); l++) {
862 											DefaultMutableTreeNode variantNode = (DefaultMutableTreeNode)countryNode.getChildAt(l);
863 											Object o3 = variantNode.getUserObject();
864 											if (o3 == null || !(o3 instanceof String)) continue;
865 											String str3 = (String)o3;
866 											if (str3.equals(Resources.getTranslation("tree_variant_node"))) {
867 												variantNodeFound = true;
868 												variantNode.add(new DefaultMutableTreeNode(currBundle));
869 											}
870 										} // end for - country node loop
871 										if (!variantNodeFound) {
872 											DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(Resources.getTranslation("tree_variant_node"));
873 											countryNode.add(variantNode);
874 											variantNode.add(new DefaultMutableTreeNode(currBundle));
875 										}
876 									}
877 								}
878 							} // end for - language node loop
879 							if (!countryNodeFound) {
880 								DefaultMutableTreeNode countryNode = new DefaultMutableTreeNode(Resources.getTranslation("tree_country_node", country));
881 								langNode.add(countryNode);
882 								if (variant == null || variant.equals("")) {
883 									countryNode.add(new DefaultMutableTreeNode(currBundle));
884 								} else {
885 									// We need to look at the variant
886 									boolean variantNodeFound = false;
887 									for (int l=0; l < countryNode.getChildCount(); l++) {
888 										DefaultMutableTreeNode variantNode = (DefaultMutableTreeNode)countryNode.getChildAt(l);
889 										Object o3 = variantNode.getUserObject();
890 										if (o3 == null || !(o3 instanceof String)) continue;
891 										String str3 = (String)o3;
892 										if (str3.equals(Resources.getTranslation("tree_variant_node"))) {
893 											variantNodeFound = true;
894 											variantNode.add(new DefaultMutableTreeNode(currBundle));
895 										}
896 									} // end for - country node loop
897 									if (!variantNodeFound) {
898 										DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(Resources.getTranslation("tree_variant_node"));
899 										countryNode.add(variantNode);
900 										variantNode.add(new DefaultMutableTreeNode(currBundle));
901 									}
902 								}
903 							}
904 						}
905 					}
906 				}
907 				if (!languageNodeFound) {
908 					// We need to create a node for this country
909 					DefaultMutableTreeNode langNode = new DefaultMutableTreeNode(Resources.getTranslation("tree_language_node", language));
910 					root.add(langNode);
911 					if (country == null || country.equals("")) {
912 						langNode.add(new DefaultMutableTreeNode(currBundle));
913 					} else {
914 						// We need to look at the country, variant
915 						boolean countryNodeFound = false;
916 						for (int k=0; k < langNode.getChildCount(); k++) {
917 							DefaultMutableTreeNode countryNode = (DefaultMutableTreeNode)langNode.getChildAt(k);
918 							Object o2 = countryNode.getUserObject();
919 							if (o2 == null || !(o2 instanceof String)) continue;
920 							String str2 = (String)o2;
921 							if (str2.equals(Resources.getTranslation("tree_country_node", country))) {
922 								// There is a non-leaf node for this country
923 								countryNodeFound = true;
924 								if (variant == null || variant.equals("")) {
925 									countryNode.add(new DefaultMutableTreeNode(currBundle));
926 								} else {
927 									// We need to look at variant
928 									boolean variantNodeFound = false;
929 									for (int l=0; l < countryNode.getChildCount(); l++) {
930 										DefaultMutableTreeNode variantNode = (DefaultMutableTreeNode)countryNode.getChildAt(l);
931 										Object o3 = variantNode.getUserObject();
932 										if (o3 == null || !(o3 instanceof String)) continue;
933 										String str3 = (String)o3;
934 										if (str3.equals(Resources.getTranslation("tree_variant_node"))) {
935 											variantNodeFound = true;
936 											variantNode.add(new DefaultMutableTreeNode(currBundle));
937 										}
938 									} // end for - country node loop
939 									if (!variantNodeFound) {
940 										DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(Resources.getTranslation("tree_variant_node"));
941 										countryNode.add(variantNode);
942 										variantNode.add(new DefaultMutableTreeNode(currBundle));
943 									}
944 								}
945 							}
946 						} // end for - language node loop
947 						if (!countryNodeFound) {
948 							DefaultMutableTreeNode countryNode = new DefaultMutableTreeNode(Resources.getTranslation("tree_country_node", country));
949 							langNode.add(countryNode);
950 							if (variant == null || variant.equals("")) {
951 								countryNode.add(new DefaultMutableTreeNode(currBundle));
952 							} else {
953 								// We need to look at the variant
954 								boolean variantNodeFound = false;
955 								for (int l=0; l < countryNode.getChildCount(); l++) {
956 									DefaultMutableTreeNode variantNode = (DefaultMutableTreeNode)countryNode.getChildAt(l);
957 									Object o3 = variantNode.getUserObject();
958 									if (o3 == null || !(o3 instanceof String)) continue;
959 									String str3 = (String)o3;
960 									if (str3.equals(Resources.getTranslation("tree_variant_node"))) {
961 										variantNodeFound = true;
962 										variantNode.add(new DefaultMutableTreeNode(currBundle));
963 									}
964 								} // end for - country node loop
965 								if (!variantNodeFound) {
966 									DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(Resources.getTranslation("tree_variant_node", variant));
967 									countryNode.add(variantNode);
968 									variantNode.add(new DefaultMutableTreeNode(currBundle));
969 								}
970 							}
971 						}
972 					}
973 				}
974 			}
975 		}
976 
977 		// Create the tree from the roots
978 		jTreeDisplay = new JTree(root);
979 		jTreeDisplay.addMouseListener(this);
980 		jTreeDisplay.addTreeSelectionListener(this);
981 		jTreeDisplay.setCellRenderer(RBTreeCellRenderer.getInstance());
982 		jScrollPaneTree.getViewport().removeAll();
983 		jScrollPaneTree.getViewport().add(jTreeDisplay);
984 		repaint();
985 		validateTree();
986 		return;
987 	}
988 
989 	/**
990 	 * Inherits from JFrame.addNotify(), but also inserts the menu bar
991 	 */
992 
addNotify()993 	public void addNotify()
994 	{
995 		super.addNotify();
996 
997 		if (mShown)
998 			return;
999 
1000 		// resize frame to account for menubar
1001 		JMenuBar jMenuBar = getJMenuBar();
1002 		if (jMenuBar != null) {
1003 			int jMenuBarHeight = jMenuBar.getPreferredSize().height;
1004 			Dimension dimension = getSize();
1005 			dimension.height += jMenuBarHeight;
1006 			setSize(dimension);
1007 		}
1008 
1009 		mShown = true;
1010 	}
1011 
1012 	/**
1013 	 * Called when it may be appropriate to check with the user if they want to save the file
1014 	 */
1015 
promptForSave(String message)1016 	boolean promptForSave(String message) {
1017 		if (rbm != null) {
1018 			int response = JOptionPane.showConfirmDialog(this,
1019 				(message == null ? Resources.getTranslation("dialog_save") : message),
1020 				Resources.getTranslation("dialog_title_quit"), JOptionPane.YES_NO_CANCEL_OPTION,
1021 				JOptionPane.QUESTION_MESSAGE);
1022 			if (response == JOptionPane.CANCEL_OPTION) return false;
1023 			if (response == JOptionPane.YES_OPTION) {
1024 				return saveResources();
1025 			}
1026 		}
1027 		return true;
1028 	}
1029 
deleteResources(String encoding)1030 	public boolean deleteResources(String encoding) {
1031 		if (rbm == null) return false;  // This should never happen
1032 		try {
1033 			rbm.eraseFile(encoding);
1034 		} catch (IOException ioe) {
1035 			JOptionPane.showMessageDialog(this, Resources.getTranslation("error_deleting", ioe.getMessage()),
1036 										  Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
1037 			if (RBManagerGUI.debug) System.err.println(ioe);
1038 			return false;
1039 		}
1040 		updateDisplayTree();
1041 		updateProjectTree();
1042 		updateProjectPanels();
1043 		updateDisplayPanels();
1044 		return true;
1045 	}
1046 
hideResources(String encoding)1047 	public void hideResources(String encoding) {
1048 		rbm.hideResource(encoding);
1049 		updateDisplayTree();
1050 		updateProjectTree();
1051 		updateProjectPanels();
1052 		updateDisplayPanels();
1053 	}
1054 
1055 	/**
1056 	 * Save a particular resources file within the bundle.
1057 	 */
1058 
saveResources(String encoding)1059 	public boolean saveResources(String encoding) {
1060 		if (rbm == null) return false;  // This should never happen
1061 		return saveResources(rbm, encoding);
1062 	}
1063 
saveResources(RBManager bundle, String encoding)1064 	public boolean saveResources(RBManager bundle, String encoding) {
1065 		try {
1066 			bundle.writeToFile(encoding);
1067 		} catch (IOException ioe) {
1068 			JOptionPane.showMessageDialog(this, Resources.getTranslation("error_saving", ioe.getMessage()),
1069 										  Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
1070 			if (RBManagerGUI.debug) System.err.println(ioe);
1071 			return false;
1072 		}
1073 		return true;
1074 	}
1075 
1076 	/**
1077 	 * Called when the resources are to be saved
1078 	 */
1079 
saveResources()1080 	public boolean saveResources() {
1081 		if (rbm == null) return true;
1082 		return saveResources(rbm);
1083 	}
1084 
saveResources(RBManager bundle)1085 	public boolean saveResources(RBManager bundle) {
1086 		try {
1087 			bundle.writeToFile();
1088 		} catch (IOException ioe) {
1089 			JOptionPane.showMessageDialog(this, Resources.getTranslation("error_saving", ioe.getMessage()),
1090 										  Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
1091 			if (RBManagerGUI.debug) System.err.println(ioe);
1092 			return false;
1093 		}
1094 		return true;
1095 	}
1096 
1097 	/**
1098 	 * Called when the resource bundle is to be saved, but displays a window to the user allowing them
1099 	 * to selecte the file destination of the folder in which to save the bundle as well as the base
1100 	 * class name for the bundle.
1101 	 */
1102 
saveResourcesAs()1103 	public boolean saveResourcesAs() {
1104 		if (rbm == null) return true;
1105 		int result = saveFileChooser.showSaveDialog(this);
1106 		if (result == JFileChooser.APPROVE_OPTION) {
1107 			try {
1108 				File newFile = saveFileChooser.getSelectedFile();
1109 				String fileName = newFile.getName();
1110 				String baseName = fileName;
1111 				if (fileName.toLowerCase().endsWith(".properties"))
1112 					baseName = baseName.substring(0,baseName.length()-11);
1113 				rbm.setBaseClass(baseName);
1114 				rbm.setFileDirectory(newFile.getParentFile());
1115 				rbm.writeToFile();
1116 			} catch (IOException ioe) {
1117 				JOptionPane.showMessageDialog(this, Resources.getTranslation("error_saving", ioe.getMessage()),
1118 											  Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
1119 				if (RBManagerGUI.debug) System.err.println(ioe);
1120 				return false;
1121 			}
1122 		}
1123 		return true;
1124 	}
1125 
updateLocale(Locale l)1126 	void updateLocale(Locale l) {
1127 		// Update the menubars
1128 		jMenuBarMain.updateLocale();
1129 
1130 		updateLocale(getContentPane(), l);
1131 		updateLocale(openFileChooser, l);
1132 		updateLocale(saveFileChooser, l);
1133 		// Redraw the panes
1134 		updateDisplayTree();
1135 		updateProjectTree();
1136 		updateProjectPanels();
1137 		updateDisplayPanels();
1138 		// update the tab titles
1139 		jTabbedPaneMain.setTitleAt(0,Resources.getTranslation("tab_statistics"));
1140 		jTabbedPaneMain.setTitleAt(1,Resources.getTranslation("tab_untranslated"));
1141 		jTabbedPaneMain.setTitleAt(2,Resources.getTranslation("tab_groups"));
1142 		setTitle(Resources.getTranslation("resource_bundle_manager"));
1143 	}
1144 
updateLocale(Container c, Locale l)1145 	static void updateLocale(Container c, Locale l) {
1146 		Component comp[] = c.getComponents();
1147 		for (int i=0; i < comp.length; i++) {
1148 			if (comp[i] instanceof JComponent) {
1149 				((JComponent)comp[i]).setLocale(l);
1150 			}
1151 			if (comp[i] instanceof Container) {
1152 				updateLocale((Container)comp[i],l);
1153 			}
1154 		}
1155 		if (c instanceof JMenu) {
1156 			comp = ((JMenu)c).getMenuComponents();
1157 			for (int i=0; i < comp.length; i++) {
1158 				if (comp[i] instanceof JComponent) {
1159 					((JComponent)comp[i]).setLocale(l);
1160 				}
1161 				if (comp[i] instanceof Container) {
1162 					updateLocale((Container)comp[i],l);
1163 				}
1164 			}
1165 		}
1166 	}
1167 
updateUI()1168 	void updateUI() {
1169 		updateUI(getContentPane());
1170 		jMenuBarMain.updateUI();
1171 		updateUI(jMenuBarMain);
1172 		updateUI(openFileChooser);
1173 		updateUI(saveFileChooser);
1174 	}
1175 
updateUI(Container c)1176 	static void updateUI(Container c) {
1177 		Component comp[] = c.getComponents();
1178 		for (int i=0; i < comp.length; i++) {
1179 			if (comp[i] instanceof JComponent) {
1180 				((JComponent)comp[i]).updateUI();
1181 			}
1182 			if (comp[i] instanceof Container) {
1183 				updateUI((Container)comp[i]);
1184 			}
1185 		}
1186 		if (c instanceof JMenu) {
1187 			comp = ((JMenu)c).getMenuComponents();
1188 			for (int i=0; i < comp.length; i++) {
1189 				if (comp[i] instanceof JComponent) {
1190 					((JComponent)comp[i]).updateUI();
1191 				}
1192 				if (comp[i] instanceof Container) {
1193 					updateUI((Container)comp[i]);
1194 				}
1195 			}
1196 		}
1197 	}
1198 
1199 	// Close the window when the close box is clicked
thisWindowClosing(java.awt.event.WindowEvent e)1200 	void thisWindowClosing(java.awt.event.WindowEvent e)
1201 	{
1202 		if (promptForSave(Resources.getTranslation("dialog_quit_save"))) {
1203 			setVisible(false);
1204 			dispose();
1205 			System.exit(0);
1206 		}
1207 	}
1208 
setUser(String userName)1209 	public void setUser(String userName) {
1210 		this.userName = userName;
1211 		if (rbm != null) rbm.setUser(userName);
1212 	}
1213 
getUser()1214 	public String getUser() {
1215 		return userName;
1216 	}
1217 
getSelectedProjectBundleItem()1218 	public BundleItem getSelectedProjectBundleItem() {
1219 		TreePath path = projectTree.getSelectionPath();
1220 		if (path == null) return null;
1221 		DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
1222 		Object obj = node.getUserObject();
1223 		if (obj == null || !(obj instanceof BundleItem)) return null;
1224 		return (BundleItem)obj;
1225 	}
1226 
getSelectedProjectBundle()1227 	public RBManager getSelectedProjectBundle() {
1228 		TreePath path = projectTree.getSelectionPath();
1229 		if (path == null) return null;
1230 		for (int i=0; i < path.getPathCount(); i++) {
1231 			DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getPathComponent(i);
1232 			Object obj = node.getUserObject();
1233 			if (obj != null && obj instanceof RBManager) return (RBManager)obj;
1234 		}
1235 		return null;
1236 	}
1237 
debugMsg(String msg)1238 	public static void debugMsg(String msg) {
1239 		if (debug) System.out.println("Debug Message [" + debugcount++ + "]: " + msg);
1240 	}
1241 }
1242 
1243 class RBTreeCellRenderer extends DefaultTreeCellRenderer {
1244 	private static RBTreeCellRenderer cellRend = null;
1245 	private static ImageIcon bundleIcon   = null;
1246 	private static ImageIcon languageIcon = null;
1247 	private static ImageIcon countryIcon  = null;
1248 	private static ImageIcon variantIcon  = null;
1249 	private static ImageIcon fileIcon     = null;
1250 	private static ImageIcon groupIcon    = null;
1251 	private static ImageIcon itemIcon     = null;
1252 	private static ImageIcon projectIcon  = null;
1253 
RBTreeCellRenderer()1254 	private RBTreeCellRenderer() {
1255 
1256 	}
1257 
getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)1258 	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
1259 												  boolean leaf, int row, boolean hasFocus) {
1260 		super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
1261 
1262 		DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
1263 		int level = node.getLevel();
1264 		Object obj = node.getUserObject();
1265 
1266 		if (obj instanceof BundleGroup) {
1267 			setIcon(groupIcon);
1268 		} else if (obj instanceof BundleItem) {
1269 			setIcon(itemIcon);
1270 		} else if (obj instanceof RBManager) {
1271 			setIcon(bundleIcon);
1272 		} else if (obj instanceof RBProject) {
1273 			setIcon(projectIcon);
1274 		} else if (leaf) {
1275 			if (level != 0) setIcon(fileIcon);
1276 		} else {
1277 			if (level == 0) {
1278 				if (obj instanceof String && ((String)obj).equals(Resources.getTranslation("no_project")))
1279 					setIcon(projectIcon);
1280 				else setIcon(bundleIcon);
1281 			}
1282 			else if (level == 1) setIcon(languageIcon);
1283 			else if (level == 2) setIcon(countryIcon);
1284 			else if (level == 3) setIcon(variantIcon);
1285 		}
1286 
1287 		return this;
1288 	}
1289 
getInstance()1290 	public static RBTreeCellRenderer getInstance() {
1291 		if (cellRend == null) {
1292             try {
1293                 Class thisClass = Class.forName("com.ibm.rbm.gui.RBManagerGUI");
1294 			    // Create instances of the icons
1295                 Image scaledImage = (new ImageIcon(thisClass.getResource("images/tree_icon_bundle.gif"))).getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT);
1296 			    bundleIcon   = new ImageIcon(scaledImage);
1297 			    languageIcon = new ImageIcon(thisClass.getResource("images/tree_icon_language.gif"));
1298 			    countryIcon  = new ImageIcon(thisClass.getResource("images/tree_icon_country.gif"));
1299 			    variantIcon  = new ImageIcon(thisClass.getResource("images/tree_icon_variant.gif"));
1300 			    fileIcon     = new ImageIcon(thisClass.getResource("images/tree_icon_file.gif"));
1301 			    groupIcon    = new ImageIcon(thisClass.getResource("images/tree_icon_group.gif"));
1302 			    itemIcon     = new ImageIcon(thisClass.getResource("images/tree_icon_item.gif"));
1303 			    projectIcon  = new ImageIcon(thisClass.getResource("images/tree_icon_project.gif"));
1304             } catch (ClassNotFoundException e) {
1305                 RBManagerGUI.debugMsg(e.toString());
1306             }
1307 			// Create the instance of the renderer
1308 			cellRend = new RBTreeCellRenderer();
1309 		}
1310 		return cellRend;
1311 	}
1312 }
1313 
1314 /**
1315  * Table model for resource bundle projects
1316  */
1317 class RBProject {
1318 	java.util.List bundleNames;
1319 	java.util.List bundleFileNames;
1320 	java.util.List bundles;
1321 	String projectName;
1322 
RBProject(String projectName)1323 	public RBProject(String projectName) {
1324 		this.projectName = projectName;
1325 		bundleNames = new java.util.LinkedList();
1326 		bundleFileNames = new java.util.LinkedList();
1327 		bundles = new java.util.LinkedList();
1328 	}
1329 
RBProject(File inputFile)1330 	public RBProject(File inputFile) throws IOException {
1331 		this(inputFile.getName());
1332 
1333 		if (projectName.indexOf(".") > 0) {
1334 			projectName = projectName.substring(0,projectName.lastIndexOf("."));
1335 		}
1336 
1337 		FileReader fr = new FileReader(inputFile);
1338 		BufferedReader br = new BufferedReader(fr);
1339 		String line = null;
1340 		int linecount = 0;
1341 		while ((line = br.readLine()) != null) {
1342 			if (linecount % 2 == 0) {
1343 				bundleNames.add(line.trim());
1344 			} else {
1345 				bundleFileNames.add(line.trim());
1346 			}
1347 			linecount++;
1348 		}
1349 		fr.close();
1350 		try {
1351 			for (int i=0; i < bundleFileNames.size(); i++) {
1352 				RBManager rbm = new RBManager(new File((String)bundleFileNames.get(i)));
1353 				bundles.add(rbm);
1354 			}
1355 		} catch (Exception ex) {
1356 			JOptionPane.showMessageDialog(new JFrame(), Resources.getTranslation("error_load_project"),
1357 										  Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
1358 			ex.printStackTrace();
1359 			bundleNames.clear();
1360 			bundleFileNames.clear();
1361 		}
1362 	}
1363 
toString()1364 	public String toString() { return projectName; }
1365 
getSize()1366 	public int getSize() { return bundleNames.size(); }
1367 
getBundleName(int index)1368 	public String getBundleName(int index) {
1369 		return (String)bundleNames.get(index);
1370 	}
1371 
getFileName(int index)1372 	public String getFileName(int index) {
1373 		return (String)bundleFileNames.get(index);
1374 	}
1375 
getBundle(int index)1376 	public RBManager getBundle(int index) {
1377 		return (RBManager)bundles.get(index);
1378 	}
1379 
getBundle(String bundleName)1380 	public RBManager getBundle(String bundleName) {
1381 		int index = bundleNames.indexOf(bundleName);
1382 		if (index >= 0) return getBundle(index);
1383 		return null;
1384 	}
1385 
write(File outputFile)1386 	public void write(File outputFile) throws IOException {
1387 		FileWriter fw = new FileWriter(outputFile);
1388 		for (int i=0; i < bundleNames.size(); i++) {
1389 			fw.write((String)bundleNames.get(i));
1390 			fw.write("\n");
1391 			fw.write((String)bundleFileNames.get(i));
1392 			if (i != bundleNames.size()-1) fw.write("\n");
1393 		}
1394 		fw.flush();
1395 		fw.close();
1396 	}
1397 
addBundle(String bundleFileName)1398 	public void addBundle(String bundleFileName) throws IOException {
1399 		RBManager bundle = new RBManager(new File(bundleFileName));
1400 		bundles.add(bundle);
1401 		bundleNames.add(bundle.getBaseClass());
1402 		bundleFileNames.add(bundleFileName);
1403 	}
1404 
removeBundle(String bundleName)1405 	public void removeBundle(String bundleName) {
1406 		int index = bundleNames.indexOf(bundleName);
1407 		if (index >= 0) {
1408 			bundleNames.remove(index);
1409 			bundleFileNames.remove(index);
1410 			bundles.remove(index);
1411 		}
1412 	}
1413 }
1414 
1415 class RBManagerMenuBar extends JMenuBar {
1416 	RBManagerGUI             listener;
1417 
1418 	JMenu        jMenuFile = new JMenu();                                     // Menu -> File
1419 	JMenuItem    jMenuFileNewResourceBundle = new JMenuItem();
1420 	JMenuItem    jMenuFileOpenResourceBundle = new JMenuItem();
1421 	JMenuItem    jMenuFileSaveResourceBundle = new JMenuItem();
1422 	JMenuItem    jMenuFileSaveResourceBundleAs = new JMenuItem();
1423 	JMenu        jMenuFileImportResourceBundle = new JMenu();                 // Menu -> File -> Import
1424 	JMenuItem    jMenuFileImportJava = new JMenuItem();
1425 	JMenuItem    jMenuFileImportProperties = new JMenuItem();
1426 	JMenuItem    jMenuFileImportTMX = new JMenuItem();
1427 	JMenuItem    jMenuFileImportXLF = new JMenuItem();
1428 	JMenu        jMenuFileExportResourceBundle = new JMenu();                 // Menu -> File -> Export
1429 	JMenuItem    jMenuFileExportJava = new JMenuItem();
1430 	JMenuItem    jMenuFileExportICU = new JMenuItem();
1431 	JMenuItem    jMenuFileExportProperties = new JMenuItem();
1432 	JMenuItem    jMenuFileExportTMX = new JMenuItem();
1433 	JMenuItem    jMenuFileExportXLF = new JMenuItem();
1434 	JMenuItem    jMenuFileExit = new JMenuItem();
1435 	JMenu        jMenuEdit = new JMenu();                                     // Menu -> Edit
1436 	JMenuItem    jMenuEditCut = new JMenuItem();
1437 	JMenuItem    jMenuEditCopy = new JMenuItem();
1438 	JMenuItem    jMenuEditPaste = new JMenuItem();
1439 	JMenuItem    jMenuEditDelete = new JMenuItem();
1440 	JMenu        jMenuOptions = new JMenu();                                  // Menu -> Options
1441 	JMenuItem    jMenuOptionsAddNewEntry = new JMenuItem();
1442 	JMenuItem    jMenuOptionsAddNewGroup = new JMenuItem();
1443 	JMenuItem    jMenuOptionsAddNewResourceFile = new JMenuItem();
1444 	//JMenuItem    jMenuOptionsProjectViewer = new JMenuItem();
1445 	JMenuItem    jMenuOptionsPreferences = new JMenuItem();
1446 	JMenu        jMenuView = new JMenu();                                     // Menu -> View
1447 	JMenuItem    jMenuViewViewStatistics = new JMenuItem();
1448 	JMenu        jMenuHelp = new JMenu();                                     // Menu -> Help
1449 	JMenuItem    jMenuHelpAboutResourceBundleManager = new JMenuItem();
1450 
updateLocale()1451 	void updateLocale() {
1452 		//FILE
1453 		jMenuFile.setText(Resources.getTranslation("menu_file"));
1454 		jMenuFile.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_trigger")));
1455 		jMenuFileNewResourceBundle.setText(Resources.getTranslation("menu_file_new"));
1456 		jMenuFileNewResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_new_trigger")));
1457 		jMenuFileOpenResourceBundle.setText(Resources.getTranslation("menu_file_open"));
1458 		jMenuFileOpenResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_open_trigger")));
1459 		jMenuFileSaveResourceBundle.setText(Resources.getTranslation("menu_file_save"));
1460 		jMenuFileSaveResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_save_trigger")));
1461 		jMenuFileSaveResourceBundleAs.setText(Resources.getTranslation("menu_file_saveas"));
1462 		jMenuFileSaveResourceBundleAs.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_saveas_trigger")));
1463 		jMenuFileImportResourceBundle.setText(Resources.getTranslation("menu_file_import"));
1464 		jMenuFileImportResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_trigger")));
1465 		jMenuFileImportJava.setText(Resources.getTranslation("menu_file_import_java"));
1466 		jMenuFileImportJava.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_java_trigger")));
1467 		jMenuFileImportProperties.setText(Resources.getTranslation("menu_file_import_properties"));
1468 		jMenuFileImportProperties.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_properties_trigger")));
1469 		jMenuFileImportTMX.setText(Resources.getTranslation("menu_file_import_TMX"));
1470 		jMenuFileImportTMX.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_TMX_trigger")));
1471 		jMenuFileImportXLF.setText(Resources.getTranslation("menu_file_import_XLF"));
1472 		jMenuFileImportXLF.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_XLF_trigger")));
1473 		jMenuFileExportResourceBundle.setText(Resources.getTranslation("menu_file_export"));
1474 		jMenuFileExportResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_trigger")));
1475 		jMenuFileExportJava.setText(Resources.getTranslation("menu_file_export_java"));
1476 		jMenuFileExportJava.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_java_trigger")));
1477 		jMenuFileExportICU.setText(Resources.getTranslation("menu_file_export_ICU"));
1478 		jMenuFileExportICU.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_ICU_trigger")));
1479 		jMenuFileExportProperties.setText(Resources.getTranslation("menu_file_export_properties"));
1480 		jMenuFileExportProperties.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_properties_trigger")));
1481 		jMenuFileExportTMX.setText(Resources.getTranslation("menu_file_export_TMX"));
1482 		jMenuFileExportTMX.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_TMX_trigger")));
1483 		jMenuFileExportXLF.setText(Resources.getTranslation("menu_file_export_XLF"));
1484 		jMenuFileExportXLF.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_XLF_trigger")));
1485 		jMenuFileExit.setText(Resources.getTranslation("menu_file_quit"));
1486 		jMenuFileExit.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_quit_trigger")));
1487 		//EDIT
1488 		jMenuEdit.setText(Resources.getTranslation("menu_edit"));
1489 		jMenuEdit.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_trigger")));
1490 		jMenuEditCut.setText(Resources.getTranslation("menu_edit_cut"));
1491 		jMenuEditCut.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_cut_trigger")));
1492 		jMenuEditCopy.setText(Resources.getTranslation("menu_edit_copy"));
1493 		jMenuEditCopy.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_copy_trigger")));
1494 		jMenuEditPaste.setText(Resources.getTranslation("menu_edit_paste"));
1495 		jMenuEditPaste.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_paste_trigger")));
1496 		jMenuEditDelete.setText(Resources.getTranslation("menu_edit_delete"));
1497 		jMenuEditDelete.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_delete_trigger")));
1498 		//OPTIONS
1499 		jMenuOptions.setText(Resources.getTranslation("menu_options"));
1500 		jMenuOptions.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_trigger")));
1501 		jMenuOptionsAddNewEntry.setText(Resources.getTranslation("menu_options_addentry"));
1502 		jMenuOptionsAddNewEntry.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_addentry_trigger")));
1503 		jMenuOptionsAddNewGroup.setText(Resources.getTranslation("menu_options_addgroup"));
1504 		jMenuOptionsAddNewGroup.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_addgroup_trigger")));
1505 		jMenuOptionsAddNewResourceFile.setText(Resources.getTranslation("menu_options_addfile"));
1506 		jMenuOptionsAddNewResourceFile.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_addfile_trigger")));
1507 		//jMenuOptionsProjectViewer.setText(Resources.getTranslation("menu_options_project_viewer"));
1508 		//jMenuOptionsProjectViewer.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_project_viewer_trigger")));
1509 		jMenuOptionsPreferences.setText(Resources.getTranslation("menu_options_preferences"));
1510 		jMenuOptionsPreferences.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_preferences_trigger")));
1511 		//VIEW
1512 		jMenuView.setText(Resources.getTranslation("menu_view"));
1513 		jMenuView.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_view_trigger")));
1514 		jMenuViewViewStatistics.setText(Resources.getTranslation("menu_view_statistics"));
1515 		jMenuViewViewStatistics.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_view_statistics_trigger")));
1516 		//HELP
1517 		jMenuHelp.setText(Resources.getTranslation("menu_help"));
1518 		jMenuHelp.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_trigger")));
1519 		jMenuHelpAboutResourceBundleManager.setText(Resources.getTranslation("menu_help_about"));
1520 		jMenuHelpAboutResourceBundleManager.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_help_about_trigger")));
1521 	}
1522 
RBManagerMenuBar(RBManagerGUI gui)1523 	public RBManagerMenuBar(RBManagerGUI gui) {
1524 		super();
1525 
1526         boolean xmlAvailable;
1527 		try {
1528             Class.forName("org.apache.xerces.parsers.DOMParser");
1529             Class.forName("javax.xml.parsers.DocumentBuilder");
1530             xmlAvailable = true;
1531         } catch (ClassNotFoundException e) {
1532             xmlAvailable = false;
1533         }
1534 		listener = gui;
1535 
1536 		// Add the menus to the menu bar
1537 		setVisible(true);
1538 		add(jMenuFile);
1539 		//add(jMenuEdit);
1540 		add(jMenuOptions);
1541 		//add(jMenuView);
1542 		add(jMenuHelp);
1543 
1544 		// Add File Menu Items to the File Menu
1545 		jMenuFile.setVisible(true);
1546 		jMenuFile.setText(Resources.getTranslation("menu_file"));
1547 		jMenuFile.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_trigger")));
1548 		jMenuFile.add(jMenuFileNewResourceBundle);
1549 		jMenuFile.add(jMenuFileOpenResourceBundle);
1550 		jMenuFile.add(jMenuFileSaveResourceBundle);
1551 		jMenuFile.add(jMenuFileSaveResourceBundleAs);
1552 		jMenuFile.addSeparator();
1553 		jMenuFile.add(jMenuFileImportResourceBundle);
1554 		jMenuFile.add(jMenuFileExportResourceBundle);
1555 		jMenuFile.addSeparator();
1556 		// Add the recent files to the file menu
1557 		Vector recentFiles = Preferences.getRecentFilesPreferences();
1558 		if (recentFiles.size() > 0) {
1559 			for (int i=0; i < recentFiles.size(); i+=2) {
1560 				String name = (String)recentFiles.elementAt(i);
1561 				String location = (String)recentFiles.elementAt(i+1);
1562 				JMenuItem recentMenuItem = new JMenuItem();
1563 				recentMenuItem.setVisible(true);
1564 				recentMenuItem.setText(name);
1565 				recentMenuItem.setName("__" + location.trim());
1566 				recentMenuItem.addActionListener(listener);
1567 				jMenuFile.add(recentMenuItem);
1568 			}
1569 			jMenuFile.addSeparator();
1570 		}
1571 		jMenuFile.add(jMenuFileExit);
1572 
1573 		//jMenuFileImportResourceBundle.add(jMenuFileImportJava);
1574 		jMenuFileImportResourceBundle.add(jMenuFileImportProperties);
1575         jMenuFileImportTMX.setEnabled(xmlAvailable);
1576 		jMenuFileImportResourceBundle.add(jMenuFileImportTMX);
1577         jMenuFileImportXLF.setEnabled(xmlAvailable);
1578 		jMenuFileImportResourceBundle.add(jMenuFileImportXLF);
1579 		jMenuFileExportResourceBundle.add(jMenuFileExportJava);
1580 		jMenuFileExportResourceBundle.add(jMenuFileExportICU);
1581 		jMenuFileExportResourceBundle.add(jMenuFileExportProperties);
1582         jMenuFileExportTMX.setEnabled(xmlAvailable);
1583 		jMenuFileExportResourceBundle.add(jMenuFileExportTMX);
1584         jMenuFileExportXLF.setEnabled(xmlAvailable);
1585 		jMenuFileExportResourceBundle.add(jMenuFileExportXLF);
1586 
1587 		jMenuFileNewResourceBundle.setVisible(true);
1588 		jMenuFileNewResourceBundle.setText(Resources.getTranslation("menu_file_new"));
1589 		jMenuFileNewResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_new_trigger")));
1590 		jMenuFileNewResourceBundle.setAccelerator(KeyStroke.getKeyStroke(
1591                   KeyEvent.VK_N, ActionEvent.CTRL_MASK));
1592 		jMenuFileNewResourceBundle.addActionListener(listener);
1593 
1594 		jMenuFileOpenResourceBundle.setVisible(true);
1595 		jMenuFileOpenResourceBundle.setText(Resources.getTranslation("menu_file_open"));
1596 		jMenuFileOpenResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_open_trigger")));
1597 		jMenuFileOpenResourceBundle.setAccelerator(KeyStroke.getKeyStroke(
1598                   KeyEvent.VK_O, ActionEvent.CTRL_MASK));
1599 		jMenuFileOpenResourceBundle.addActionListener(listener);
1600 
1601 		jMenuFileSaveResourceBundle.setVisible(true);
1602 		jMenuFileSaveResourceBundle.setText(Resources.getTranslation("menu_file_save"));
1603 		jMenuFileSaveResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_save_trigger")));
1604 		jMenuFileSaveResourceBundle.setAccelerator(KeyStroke.getKeyStroke(
1605                   KeyEvent.VK_S, ActionEvent.CTRL_MASK));
1606 		jMenuFileSaveResourceBundle.addActionListener(listener);
1607 
1608 		jMenuFileSaveResourceBundleAs.setVisible(true);
1609 		jMenuFileSaveResourceBundleAs.setText(Resources.getTranslation("menu_file_saveas"));
1610 		jMenuFileSaveResourceBundleAs.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_saveas_trigger")));
1611 		jMenuFileSaveResourceBundleAs.setAccelerator(KeyStroke.getKeyStroke(
1612                   KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
1613 		jMenuFileSaveResourceBundleAs.addActionListener(listener);
1614 
1615 		jMenuFileImportResourceBundle.setVisible(true);
1616 		jMenuFileImportResourceBundle.setText(Resources.getTranslation("menu_file_import"));
1617 		jMenuFileImportResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_trigger")));
1618 		jMenuFileImportResourceBundle.addActionListener(listener);
1619 
1620 		jMenuFileImportJava.setVisible(true);
1621 		jMenuFileImportJava.setText(Resources.getTranslation("menu_file_import_java"));
1622 		jMenuFileImportJava.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_java_trigger")));
1623 		jMenuFileImportJava.addActionListener(listener);
1624 
1625 		jMenuFileImportProperties.setVisible(true);
1626 		jMenuFileImportProperties.setText(Resources.getTranslation("menu_file_import_properties"));
1627 		jMenuFileImportProperties.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_properties_trigger")));
1628 		jMenuFileImportProperties.addActionListener(listener);
1629 
1630 		jMenuFileImportTMX.setVisible(true);
1631 		jMenuFileImportTMX.setText(Resources.getTranslation("menu_file_import_TMX"));
1632 		jMenuFileImportTMX.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_TMX_trigger")));
1633 		jMenuFileImportTMX.addActionListener(listener);
1634 
1635 		jMenuFileImportXLF.setVisible(true);
1636 		jMenuFileImportXLF.setText(Resources.getTranslation("menu_file_import_XLF"));
1637 		jMenuFileImportXLF.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_import_XLF_trigger")));
1638 		jMenuFileImportXLF.addActionListener(listener);
1639 
1640 		jMenuFileExportResourceBundle.setVisible(true);
1641 		jMenuFileExportResourceBundle.setText(Resources.getTranslation("menu_file_export"));
1642 		jMenuFileExportResourceBundle.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_trigger")));
1643 		jMenuFileExportResourceBundle.addActionListener(listener);
1644 
1645 		jMenuFileExportJava.setVisible(true);
1646 		jMenuFileExportJava.setText(Resources.getTranslation("menu_file_export_java"));
1647 		jMenuFileExportJava.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_java_trigger")));
1648 		jMenuFileExportJava.addActionListener(listener);
1649 
1650 		jMenuFileExportICU.setVisible(true);
1651 		jMenuFileExportICU.setText(Resources.getTranslation("menu_file_export_ICU"));
1652 		jMenuFileExportICU.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_ICU_trigger")));
1653 		jMenuFileExportICU.addActionListener(listener);
1654 
1655 		jMenuFileExportProperties.setVisible(true);
1656 		jMenuFileExportProperties.setText(Resources.getTranslation("menu_file_export_properties"));
1657 		jMenuFileExportProperties.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_properties_trigger")));
1658 		jMenuFileExportProperties.addActionListener(listener);
1659 
1660 		jMenuFileExportTMX.setVisible(true);
1661 		jMenuFileExportTMX.setText(Resources.getTranslation("menu_file_export_TMX"));
1662 		jMenuFileExportTMX.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_TMX_trigger")));
1663 		jMenuFileExportTMX.addActionListener(listener);
1664 
1665 		jMenuFileExportXLF.setVisible(true);
1666 		jMenuFileExportXLF.setText(Resources.getTranslation("menu_file_export_XLF"));
1667 		jMenuFileExportXLF.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_export_XLF_trigger")));
1668 		jMenuFileExportXLF.addActionListener(listener);
1669 
1670 		jMenuFileExit.setVisible(true);
1671 		jMenuFileExit.setText(Resources.getTranslation("menu_file_quit"));
1672 		jMenuFileExit.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_file_quit_trigger")));
1673 		jMenuFileExit.setAccelerator(KeyStroke.getKeyStroke(
1674                   KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
1675 		jMenuFileExit.addActionListener(listener);
1676 
1677 		// Add Edit Menu Items to the Edit Menu
1678 		jMenuEdit.setVisible(true);
1679 		jMenuEdit.setText(Resources.getTranslation("menu_edit"));
1680 		jMenuEdit.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_trigger")));
1681 		jMenuEdit.add(jMenuEditCut);
1682 		jMenuEdit.add(jMenuEditCopy);
1683 		jMenuEdit.add(jMenuEditPaste);
1684 		jMenuEdit.add(jMenuEditDelete);
1685 
1686 		jMenuEditCut.setVisible(true);
1687 		jMenuEditCut.setText(Resources.getTranslation("menu_edit_cut"));
1688 		jMenuEditCut.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_cut_trigger")));
1689 		jMenuEditCut.setAccelerator(KeyStroke.getKeyStroke(
1690 				KeyEvent.VK_X, ActionEvent.CTRL_MASK));
1691 
1692 		jMenuEditCopy.setVisible(true);
1693 		jMenuEditCopy.setText(Resources.getTranslation("menu_edit_copy"));
1694 		jMenuEditCopy.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_copy_trigger")));
1695 		jMenuEditCopy.setAccelerator(KeyStroke.getKeyStroke(
1696 				KeyEvent.VK_C, ActionEvent.CTRL_MASK));
1697 
1698 		jMenuEditPaste.setVisible(true);
1699 		jMenuEditPaste.setText(Resources.getTranslation("menu_edit_paste"));
1700 		jMenuEditPaste.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_paste_trigger")));
1701 		jMenuEditPaste.setAccelerator(KeyStroke.getKeyStroke(
1702 				KeyEvent.VK_V, ActionEvent.CTRL_MASK));
1703 
1704 		jMenuEditDelete.setVisible(true);
1705 		jMenuEditDelete.setText(Resources.getTranslation("menu_edit_delete"));
1706 		jMenuEditDelete.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_edit_delete_trigger")));
1707 
1708 		// Add Options Menu Items to the Options Menu
1709 		jMenuOptions.setVisible(true);
1710 		jMenuOptions.setText(Resources.getTranslation("menu_options"));
1711 		jMenuOptions.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_trigger")));
1712 		jMenuOptions.add(jMenuOptionsAddNewEntry);
1713 		jMenuOptions.add(jMenuOptionsAddNewGroup);
1714 		jMenuOptions.add(jMenuOptionsAddNewResourceFile);
1715 		//jMenuOptions.addSeparator();
1716 		//jMenuOptions.add(jMenuOptionsProjectViewer);
1717 		jMenuOptions.addSeparator();
1718 		jMenuOptions.add(jMenuOptionsPreferences);
1719 
1720 		jMenuOptionsAddNewEntry.setVisible(true);
1721 		jMenuOptionsAddNewEntry.setText(Resources.getTranslation("menu_options_addentry"));
1722 		jMenuOptionsAddNewEntry.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_addentry_trigger")));
1723 		jMenuOptionsAddNewEntry.addActionListener(listener);
1724 
1725 		jMenuOptionsAddNewGroup.setVisible(true);
1726 		jMenuOptionsAddNewGroup.setText(Resources.getTranslation("menu_options_addgroup"));
1727 		jMenuOptionsAddNewGroup.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_addgroup_trigger")));
1728 		jMenuOptionsAddNewGroup.addActionListener(listener);
1729 
1730 		jMenuOptionsAddNewResourceFile.setVisible(true);
1731 		jMenuOptionsAddNewResourceFile.setText(Resources.getTranslation("menu_options_addfile"));
1732 		jMenuOptionsAddNewResourceFile.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_addfile_trigger")));
1733 		jMenuOptionsAddNewResourceFile.addActionListener(listener);
1734 
1735 		/*
1736 		jMenuOptionsProjectViewer.setVisible(true);
1737 		jMenuOptionsProjectViewer.setText(Resources.getTranslation("menu_options_project_viewer"));
1738 		jMenuOptionsProjectViewer.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_project_viewer_trigger")));
1739 		jMenuOptionsProjectViewer.addActionListener(listener);
1740 		*/
1741 
1742 		jMenuOptionsPreferences.setVisible(true);
1743 		jMenuOptionsPreferences.setText(Resources.getTranslation("menu_options_preferences"));
1744 		jMenuOptionsPreferences.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_options_preferences_trigger")));
1745 		jMenuOptionsPreferences.addActionListener(listener);
1746 
1747 		// Add View Menu Items to the View Menu
1748 		jMenuView.setVisible(true);
1749 		jMenuView.setText(Resources.getTranslation("menu_view"));
1750 		jMenuView.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_view_trigger")));
1751 		jMenuView.add(jMenuViewViewStatistics);
1752 
1753 		jMenuViewViewStatistics.setVisible(true);
1754 		jMenuViewViewStatistics.setText(Resources.getTranslation("menu_view_statistics"));
1755 		jMenuViewViewStatistics.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_view_statistics_trigger")));
1756 
1757 		// Add Help Menu Items to the Help Menu
1758 		jMenuHelp.setVisible(true);
1759 		jMenuHelp.setText(Resources.getTranslation("menu_help"));
1760 		jMenuHelp.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_help_trigger")));
1761 		jMenuHelp.add(jMenuHelpAboutResourceBundleManager);
1762 
1763 		jMenuHelpAboutResourceBundleManager.setVisible(true);
1764 		jMenuHelpAboutResourceBundleManager.setText(Resources.getTranslation("menu_help_about"));
1765 		jMenuHelpAboutResourceBundleManager.setMnemonic(getKeyEventKey(Resources.getTranslation("menu_help_about_trigger")));
1766 		jMenuHelpAboutResourceBundleManager.setAccelerator(KeyStroke.getKeyStroke(
1767 				KeyEvent.VK_H, ActionEvent.CTRL_MASK));
1768 		jMenuHelpAboutResourceBundleManager.addActionListener(listener);
1769 	}
1770 
getKeyEventKey(String character)1771 	public static int getKeyEventKey(String character) {
1772 		if (character == null) return KeyEvent.VK_A;
1773 		character = character.toUpperCase();
1774 
1775 		if (character.startsWith("A")) return KeyEvent.VK_A;
1776 		else if (character.startsWith("B")) return KeyEvent.VK_B;
1777 		else if (character.startsWith("C")) return KeyEvent.VK_C;
1778 		else if (character.startsWith("D")) return KeyEvent.VK_D;
1779 		else if (character.startsWith("E")) return KeyEvent.VK_E;
1780 		else if (character.startsWith("F")) return KeyEvent.VK_F;
1781 		else if (character.startsWith("G")) return KeyEvent.VK_G;
1782 		else if (character.startsWith("H")) return KeyEvent.VK_H;
1783 		else if (character.startsWith("I")) return KeyEvent.VK_I;
1784 		else if (character.startsWith("J")) return KeyEvent.VK_J;
1785 		else if (character.startsWith("K")) return KeyEvent.VK_K;
1786 		else if (character.startsWith("L")) return KeyEvent.VK_L;
1787 		else if (character.startsWith("M")) return KeyEvent.VK_M;
1788 		else if (character.startsWith("N")) return KeyEvent.VK_N;
1789 		else if (character.startsWith("O")) return KeyEvent.VK_O;
1790 		else if (character.startsWith("P")) return KeyEvent.VK_P;
1791 		else if (character.startsWith("Q")) return KeyEvent.VK_Q;
1792 		else if (character.startsWith("R")) return KeyEvent.VK_R;
1793 		else if (character.startsWith("S")) return KeyEvent.VK_S;
1794 		else if (character.startsWith("T")) return KeyEvent.VK_T;
1795 		else if (character.startsWith("U")) return KeyEvent.VK_U;
1796 		else if (character.startsWith("V")) return KeyEvent.VK_V;
1797 		else if (character.startsWith("W")) return KeyEvent.VK_W;
1798 		else if (character.startsWith("X")) return KeyEvent.VK_X;
1799 		else if (character.startsWith("Y")) return KeyEvent.VK_Y;
1800 		else if (character.startsWith("Z")) return KeyEvent.VK_Z;
1801 		else if (character.startsWith("0")) return KeyEvent.VK_0;
1802 		else if (character.startsWith("1")) return KeyEvent.VK_1;
1803 		else if (character.startsWith("2")) return KeyEvent.VK_2;
1804 		else if (character.startsWith("3")) return KeyEvent.VK_3;
1805 		else if (character.startsWith("4")) return KeyEvent.VK_4;
1806 		else if (character.startsWith("5")) return KeyEvent.VK_5;
1807 		else if (character.startsWith("6")) return KeyEvent.VK_6;
1808 		else if (character.startsWith("7")) return KeyEvent.VK_7;
1809 		else if (character.startsWith("8")) return KeyEvent.VK_8;
1810 		else if (character.startsWith("9")) return KeyEvent.VK_9;
1811 
1812 		return KeyEvent.VK_A;
1813 	}
1814 
1815 }
1816