diff --git a/src/gui/org/deidentifier/arx/gui/Main.java b/src/gui/org/deidentifier/arx/gui/Main.java index 7ca0cb5e5f..3b307abb67 100644 --- a/src/gui/org/deidentifier/arx/gui/Main.java +++ b/src/gui/org/deidentifier/arx/gui/Main.java @@ -66,6 +66,10 @@ public static void main(Display display, final String[] args) { } try { + + // Update display settings + Display.setAppName(Resources.getMessage("MainWindow.0")); + Display.setAppVersion(Resources.getVersion()); // Display if (display == null) { @@ -81,11 +85,7 @@ public static void main(Display display, final String[] args) { // Create main window main = new MainWindow(display, monitor); - - // Update display settings - Display.setAppName(Resources.getMessage("MainWindow.0")); - Display.setAppVersion(Resources.getVersion()); - + // Handler for loading a project if (args.length > 0 && args[0].endsWith(".deid")) { //$NON-NLS-1$ main.onShow(new Runnable() { @@ -98,6 +98,7 @@ public void run(){ // Show window main.show(); + // Check for updates new Update(main.getShell()); // Main event loop diff --git a/src/gui/org/deidentifier/arx/gui/view/SWTUtil.java b/src/gui/org/deidentifier/arx/gui/view/SWTUtil.java index a95116a189..8e286f166b 100644 --- a/src/gui/org/deidentifier/arx/gui/view/SWTUtil.java +++ b/src/gui/org/deidentifier/arx/gui/view/SWTUtil.java @@ -19,9 +19,6 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.Locale; import java.util.Map; @@ -580,7 +577,6 @@ public static void enable(final Control elem) { /** * Fixes the application menu on OSX. - * Inspired by https://stackoverflow.com/questions/32409679/capture-about-preferences-and-quit-menu-items * @param controller */ public static void fixOSXMenu(final Controller controller) { @@ -590,9 +586,14 @@ public static void fixOSXMenu(final Controller controller) { return; } - fixOSXMenuItem(Resources.getMessage("MainMenu.19"), new Listener() { public void handleEvent(Event event){controller.actionMenuFileExit();}}, SWT.ID_QUIT); - fixOSXMenuItem(Resources.getMessage("MainMenu.29"), new Listener() { public void handleEvent(Event event){controller.actionMenuHelpAbout();}}, SWT.ID_ABOUT); - fixOSXMenuItem(Resources.getMessage("MainMenu.25"), new Listener() { public void handleEvent(Event event){controller.actionMenuEditSettings();}}, SWT.ID_PREFERENCES); + // Just disable all items in the system menu + // TODO: Something like this could help: + // https://stackoverflow.com/questions/32409679/capture-about-preferences-and-quit-menu-items + // However, I had trouble unregistering the existing events for the items + Menu systemMenu = Display.getCurrent().getSystemMenu(); + for (MenuItem systemItem : systemMenu.getItems()) { + systemItem.setEnabled(false); + } } /** @@ -621,6 +622,29 @@ public void controlResized(ControlEvent arg0) { } } + /** + * Fixes bugs on OSX when scrolling in tables + * @param table + */ + private static void fixOSXTableBug(final Table table) { + if (isMac()) { + SelectionListener bugFixer = new SelectionListener(){ + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + widgetSelected(arg0); + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + table.redraw(); + } + }; + table.getVerticalBar().addSelectionListener(bugFixer); + table.getHorizontalBar().addSelectionListener(bugFixer); + } + } + /** * Converts a boolean into a pretty string * @param value @@ -633,7 +657,7 @@ public static String getPrettyString(boolean value) { return Resources.getMessage("PropertiesView.170"); } } - + /** * Returns a pretty string representing the given double * @param value @@ -657,7 +681,7 @@ public static String getPrettyString(double value) { return String.valueOf(value).replace('E', 'e'); } } - + /** * Returns a pretty string representing the given value * @param value @@ -693,7 +717,7 @@ public static String getPrettyString(Object value) { } return String.valueOf(value); } - + /** * Are we running on an OSX system * @return @@ -702,6 +726,23 @@ public static boolean isMac() { return System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0; //$NON-NLS-1$ //$NON-NLS-2$ } + /** + * En-/disables the composite and its children. + * + * @param elem + * @param val + */ + private static void setEnabled(final Composite elem, final boolean val) { + elem.setEnabled(val); + for (final Control c : elem.getChildren()) { + if (c instanceof Composite) { + setEnabled((Composite) c, val); + } else { + c.setEnabled(val); + } + } + } + /** * Converts the slider value to a double. * @@ -722,65 +763,4 @@ public static double sliderToDouble(final double min, } return val; } - - /** - * Update menu item - * @param name - * @param listener - * @param id - */ - private static void fixOSXMenuItem(String name, Listener listener, int id) { - Menu systemMenu = Display.getCurrent().getSystemMenu(); - for (MenuItem systemItem : systemMenu.getItems()) { - if (systemItem.getID() == id) { - List listeners = new ArrayList(Arrays.asList(systemItem.getListeners(SWT.Selection))); - for (Listener _listener : listeners) { - systemItem.removeListener(SWT.Selection, _listener); - } - systemItem.setText(name); - systemItem.addListener(SWT.Selection, listener); - return; - } - } - } - - /** - * Fixes bugs on OSX when scrolling in tables - * @param table - */ - private static void fixOSXTableBug(final Table table) { - if (isMac()) { - SelectionListener bugFixer = new SelectionListener(){ - - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - widgetSelected(arg0); - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - table.redraw(); - } - }; - table.getVerticalBar().addSelectionListener(bugFixer); - table.getHorizontalBar().addSelectionListener(bugFixer); - } - } - - /** - * En-/disables the composite and its children. - * - * @param elem - * @param val - */ - private static void setEnabled(final Composite elem, final boolean val) { - elem.setEnabled(val); - for (final Control c : elem.getChildren()) { - if (c instanceof Composite) { - setEnabled((Composite) c, val); - } else { - c.setEnabled(val); - } - } - } } \ No newline at end of file