+ /**
+ * Convenience method for making a menu item using a function
+ * @param inFunction function
+ * @return menu item using localized name of function
+ */
+ private static JMenuItem makeMenuItem(GenericFunction inFunction)
+ {
+ JMenuItem item = new JMenuItem(I18nManager.getText(inFunction.getNameKey()));
+ item.addActionListener(new FunctionLauncher(inFunction));
+ return item;
+ }
+
+ /**
+ * Set the alt key for the given menu
+ * @param inMenu menu to set
+ * @param inKey key to lookup to get language-sensitive altkey
+ */
+ private static void setAltKey(JMenu inMenu, String inKey)
+ {
+ // Lookup the key in the properties
+ String altKey = I18nManager.getText(inKey);
+ if (altKey != null && altKey.length() == 1)
+ {
+ int code = altKey.charAt(0) - 'A';
+ if (code >= 0 && code < 26)
+ {
+ // Found a valid code between A and Z
+ inMenu.setMnemonic(KEY_EVENTS[code]);
+ }
+ }
+ }
+
+ /**
+ * Set the shortcut key for the given menu item
+ * @param inMenuItem menu item to set
+ * @param inKey key to lookup to get language-sensitive shortcut
+ */
+ private static void setShortcut(JMenuItem inMenuItem, String inKey)
+ {
+ // Lookup the key in the properties
+ String altKey = I18nManager.getText(inKey);
+ if (altKey != null && altKey.length() == 1)
+ {
+ int code = altKey.charAt(0) - 'A';
+ if (code >= 0 && code < 26)
+ {
+ // Found a valid code between A and Z
+ inMenuItem.setAccelerator(KeyStroke.getKeyStroke(KEY_EVENTS[code],
+ Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
+ // use platform-specific key mask so Ctrl on Linux/Win, Clover on Mac
+ }
+ }
+ }
+
+ /**
+ * Create a JToolBar containing all toolbar buttons
+ * @return toolbar containing buttons
+ */
+ public JToolBar createToolBar()
+ {
+ JToolBar toolbar = new JToolBar();
+ // Add text file
+ JButton openFileButton = new JButton(IconManager.getImageIcon(IconManager.OPEN_FILE));
+ openFileButton.setToolTipText(I18nManager.getText("function.open"));
+ openFileButton.addActionListener(_openFileAction);
+ toolbar.add(openFileButton);
+ // Add photo
+ JButton addPhotoButton = new JButton(IconManager.getImageIcon(IconManager.ADD_PHOTO));
+ addPhotoButton.setToolTipText(I18nManager.getText("menu.file.addphotos"));
+ addPhotoButton.addActionListener(_addPhotoAction);
+ toolbar.add(addPhotoButton);
+ // Save
+ _saveButton = new JButton(IconManager.getImageIcon(IconManager.SAVE_FILE));
+ _saveButton.setToolTipText(I18nManager.getText("menu.file.save"));
+ _saveButton.addActionListener(_saveAction);
+ _saveButton.setEnabled(false);
+ toolbar.add(_saveButton);
+ // Undo
+ _undoButton = new JButton(IconManager.getImageIcon(IconManager.UNDO));
+ _undoButton.setToolTipText(I18nManager.getText("menu.track.undo"));
+ _undoButton.addActionListener(_undoAction);
+ _undoButton.setEnabled(false);
+ toolbar.add(_undoButton);
+ // Edit point
+ _editPointButton = new JButton(IconManager.getImageIcon(IconManager.EDIT_POINT));
+ _editPointButton.setToolTipText(I18nManager.getText("menu.point.editpoint"));
+ _editPointButton.addActionListener(_editPointAction);
+ _editPointButton.setEnabled(false);
+ toolbar.add(_editPointButton);
+ // Delete point
+ _deletePointButton = new JButton(IconManager.getImageIcon(IconManager.DELETE_POINT));
+ _deletePointButton.setToolTipText(I18nManager.getText("menu.point.deletepoint"));
+ _deletePointButton.addActionListener(_deletePointAction);
+ _deletePointButton.setEnabled(false);
+ toolbar.add(_deletePointButton);
+ // Delete range
+ _deleteRangeButton = new JButton(IconManager.getImageIcon(IconManager.DELETE_RANGE));
+ _deleteRangeButton.setToolTipText(I18nManager.getText("menu.range.deleterange"));
+ _deleteRangeButton.addActionListener(_deleteRangeAction);
+ _deleteRangeButton.setEnabled(false);
+ toolbar.add(_deleteRangeButton);
+ // Select start, end
+ _selectStartButton = new JButton(IconManager.getImageIcon(IconManager.SET_RANGE_START));
+ _selectStartButton.setToolTipText(I18nManager.getText("menu.range.start"));
+ _selectStartButton.addActionListener(_selectStartAction);
+ _selectStartButton.setEnabled(false);
+ toolbar.add(_selectStartButton);
+ _selectEndButton = new JButton(IconManager.getImageIcon(IconManager.SET_RANGE_END));
+ _selectEndButton.setToolTipText(I18nManager.getText("menu.range.end"));
+ _selectEndButton.addActionListener(_selectEndAction);
+ _selectEndButton.setEnabled(false);
+ toolbar.add(_selectEndButton);
+ _connectPhotoButton = new JButton(IconManager.getImageIcon(IconManager.CONNECT_PHOTO));
+ _connectPhotoButton.setToolTipText(I18nManager.getText("menu.photo.connect"));
+ _connectPhotoButton.addActionListener(_connectPhotoAction);
+ _connectPhotoButton.setEnabled(false);
+ toolbar.add(_connectPhotoButton);
+ // finish off
+ toolbar.setFloatable(false);
+ return toolbar;
+ }
+