From 3219581f933a24fb2466da2eaca3c325b437ce44 Mon Sep 17 00:00:00 2001 From: tkellner Date: Mon, 27 Jan 2014 18:12:26 +0000 Subject: Hook up main SWT menu on OS X git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@480 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../main/java/at/asit/pdfover/gui/MainWindow.java | 40 ++++++++++++++++++++++ .../gui/workflow/states/ConfigurationUIState.java | 2 ++ 2 files changed, 42 insertions(+) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java index e847fd0c..e68b4da4 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java @@ -39,17 +39,23 @@ import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.composites.StateComposite; +import at.asit.pdfover.gui.controls.Dialog; +import at.asit.pdfover.gui.controls.Dialog.BUTTONS; +import at.asit.pdfover.gui.controls.Dialog.ICON; import at.asit.pdfover.gui.controls.MainBarButton; import at.asit.pdfover.gui.controls.MainBarEndButton; import at.asit.pdfover.gui.controls.MainBarMiddleButton; import at.asit.pdfover.gui.controls.MainBarRectangleButton; import at.asit.pdfover.gui.controls.MainBarStartButton; +import at.asit.pdfover.gui.osx.CocoaUIEnhancer; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.utils.SWTLoader; import at.asit.pdfover.gui.workflow.StateMachine; @@ -198,6 +204,9 @@ public class MainWindow { this.shell = new Shell(); getShell().setSize(this.stateMachine.getConfigProvider().getMainWindowSize()); if (System.getProperty("os.name").toLowerCase().contains("mac")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (System.getProperty("os.name").contains("OS X")) { //$NON-NLS-1$ //$NON-NLS-2$ + hookupOSXMenu(); + } // Workaround for SWT bug on Mac: disable full screen mode try { Field field = Control.class.getDeclaredField("view"); //$NON-NLS-1$ @@ -375,6 +384,37 @@ public class MainWindow { this.container.setLayout(this.stack); } + /** + * Hook up SWT menu under OS X + */ + private void hookupOSXMenu() { + log.debug("Hooking up OS X menu"); //$NON-NLS-1$ + CocoaUIEnhancer.hookApplicationMenu(getShell().getDisplay(), new Listener() { + @Override + public void handleEvent(Event arg0) { + MainWindow.this.stateMachine.exit(); + } + }, new Listener() { + @Override + public void handleEvent(Event arg0) { + String version = getClass().getPackage() + .getImplementationVersion(); + version = (version == null ? "" : " v" + version); //$NON-NLS-1$ //$NON-NLS-2$ + String about = Constants.APP_NAME + version; + Dialog dialog = new Dialog(getShell(), + String.format(Messages.getString("main.about"), Constants.APP_NAME), //$NON-NLS-1$ + about, BUTTONS.OK, ICON.INFORMATION); + dialog.open(); + } + }, new Listener() { + @Override + public void handleEvent(Event arg0) { + if (MainWindow.this.stateMachine.getStatus().getBehavior().getEnabled(Buttons.CONFIG)) + MainWindow.this.stateMachine.jumpToState(new ConfigurationUIState(MainWindow.this.stateMachine)); + } + }); + } + /** * Update MainWindow to fit new status */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java index 4651ddf5..2d839bc0 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java @@ -21,6 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.composites.ConfigurationComposite; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; @@ -96,6 +97,7 @@ public class ConfigurationUIState extends State { public void updateMainWindowBehavior() { // Leave the state as it is MainWindowBehavior behavior = getStateMachine().getStatus().getBehavior(); + behavior.setEnabled(Buttons.CONFIG, false); behavior.setMainBarVisible(false); } -- cgit v1.2.3