Skip to content

Commit

Permalink
Show application name and disable system buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
prasser committed Jun 13, 2018
1 parent 88bd92f commit 210d109
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 76 deletions.
11 changes: 6 additions & 5 deletions src/gui/org/deidentifier/arx/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand All @@ -98,6 +98,7 @@ public void run(){
// Show window
main.show();

// Check for updates
new Update(main.getShell());

// Main event loop
Expand Down
122 changes: 51 additions & 71 deletions src/gui/org/deidentifier/arx/gui/view/SWTUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -693,7 +717,7 @@ public static String getPrettyString(Object value) {
}
return String.valueOf(value);
}

/**
* Are we running on an OSX system
* @return
Expand All @@ -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.
*
Expand All @@ -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<Listener> listeners = new ArrayList<Listener>(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);
}
}
}
}

0 comments on commit 210d109

Please sign in to comment.