You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/07/01 19:23:48 UTC
svn commit: r790280 - in /incubator/pivot/trunk/wtk:
src/org/apache/pivot/wtk/DesktopApplicationContext.java
test/org/apache/pivot/wtk/test/ShutdownTest.java
Author: gbrown
Date: Wed Jul 1 17:23:48 2009
New Revision: 790280
URL: http://svn.apache.org/viewvc?rev=790280&view=rev
Log:
Fix issue PIVOT-157.
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ShutdownTest.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java?rev=790280&r1=790279&r2=790280&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java Wed Jul 1 17:23:48 2009
@@ -72,17 +72,15 @@
createTimer();
- try {
- application.startup(applicationContext.getDisplay(),
- new ImmutableMap<String, String>(properties));
- } catch(Exception exception) {
- exception.printStackTrace();
- String message = exception.getMessage();
- if (message == null) {
- message = exception.getClass().getName();
+ if (application != null) {
+ try {
+ application.startup(applicationContext.getDisplay(),
+ new ImmutableMap<String, String>(properties));
+ } catch(Exception exception) {
+ exception.printStackTrace();
+ Alert.alert(MessageType.ERROR, exception.getMessage(),
+ applicationContext.getDisplay());
}
-
- Alert.alert(MessageType.ERROR, message, applicationContext.getDisplay());
}
break;
@@ -154,14 +152,16 @@
* Terminates the application context.
*/
public static void exit() {
- boolean cancelShutdown = true;
+ boolean cancelShutdown = false;
- try {
- cancelShutdown = application.shutdown(true);
- } catch(Exception exception) {
- exception.printStackTrace();
- Alert.alert(MessageType.ERROR, exception.getMessage(),
- applicationContext.getDisplay());
+ if (application != null) {
+ try {
+ cancelShutdown = application.shutdown(true);
+ } catch(Exception exception) {
+ exception.printStackTrace();
+ Alert.alert(MessageType.ERROR, exception.getMessage(),
+ applicationContext.getDisplay());
+ }
}
if (!cancelShutdown) {
@@ -266,6 +266,54 @@
}
}
+ // Add a listener for active window changes
+ final WindowListener rootOwnerListener = new WindowListener.Adapter() {
+ @Override
+ public void titleChanged(Window window, String previousTitle) {
+ updateFrameTitleBar(window);
+ }
+
+ @Override
+ public void iconChanged(Window window, Image previousIcon) {
+ updateFrameTitleBar(window);
+ }
+ };
+
+ Window.getWindowClassListeners().add(new WindowClassListener() {
+ public void activeWindowChanged(Window previousActiveWindow) {
+ if (previousActiveWindow != null) {
+ Window previousRootOwner = previousActiveWindow.getRootOwner();
+ previousRootOwner.getWindowListeners().remove(rootOwnerListener);
+ }
+
+ Window activeWindow = Window.getActiveWindow();
+
+ if (activeWindow != null) {
+ Window rootOwner = activeWindow.getRootOwner();
+ rootOwner.getWindowListeners().add(rootOwnerListener);
+ }
+
+ if (updateFrameTitleBarCallback == null) {
+ updateFrameTitleBarCallback = new Runnable() {
+ public void run() {
+ Window activeWindow = Window.getActiveWindow();
+ if (activeWindow == null) {
+ windowedHostFrame.setTitle(DEFAULT_HOST_FRAME_TITLE);
+ windowedHostFrame.setIconImage(null);
+ } else {
+ Window rootOwner = activeWindow.getRootOwner();
+ updateFrameTitleBar(rootOwner);
+ }
+
+ updateFrameTitleBarCallback = null;
+ }
+ };
+
+ queueCallback(updateFrameTitleBarCallback);
+ }
+ }
+ });
+
// Create the application context
applicationContext = new DesktopApplicationContext();
@@ -368,53 +416,6 @@
// Open the windowed host
windowedHostFrame.setVisible(true);
- final WindowListener rootOwnerListener = new WindowListener.Adapter() {
- @Override
- public void titleChanged(Window window, String previousTitle) {
- updateFrameTitleBar(window);
- }
-
- @Override
- public void iconChanged(Window window, Image previousIcon) {
- updateFrameTitleBar(window);
- }
- };
-
- Window.getWindowClassListeners().add(new WindowClassListener() {
- public void activeWindowChanged(Window previousActiveWindow) {
- if (previousActiveWindow != null) {
- Window previousRootOwner = previousActiveWindow.getRootOwner();
- previousRootOwner.getWindowListeners().remove(rootOwnerListener);
- }
-
- Window activeWindow = Window.getActiveWindow();
-
- if (activeWindow != null) {
- Window rootOwner = activeWindow.getRootOwner();
- rootOwner.getWindowListeners().add(rootOwnerListener);
- }
-
- if (updateFrameTitleBarCallback == null) {
- updateFrameTitleBarCallback = new Runnable() {
- public void run() {
- Window activeWindow = Window.getActiveWindow();
- if (activeWindow == null) {
- windowedHostFrame.setTitle(DEFAULT_HOST_FRAME_TITLE);
- windowedHostFrame.setIconImage(null);
- } else {
- Window rootOwner = activeWindow.getRootOwner();
- updateFrameTitleBar(rootOwner);
- }
-
- updateFrameTitleBarCallback = null;
- }
- };
-
- queueCallback(updateFrameTitleBarCallback);
- }
- }
- });
-
// Go to full-screen mode, if requested
setFullScreen(fullScreen);
}
Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ShutdownTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ShutdownTest.java?rev=790280&r1=790279&r2=790280&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ShutdownTest.java (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ShutdownTest.java Wed Jul 1 17:23:48 2009
@@ -27,8 +27,9 @@
import org.apache.pivot.wtk.MessageType;
public class ShutdownTest implements Application {
- Display display = null;
- boolean cancelShutdown = true;
+ private Display display = null;
+ private Alert alert = null;
+ private boolean cancelShutdown = true;
public void startup(Display display, Map<String, String> properties) {
this.display = display;
@@ -40,23 +41,27 @@
public boolean shutdown(boolean optional) {
System.out.println("shutdown()");
- ArrayList<String> options = new ArrayList<String>();
- options.add("Yes");
- options.add("No");
-
- Alert alert = new Alert(MessageType.QUESTION, "Cancel shutdown?", options);
- alert.open(display, new DialogCloseListener() {
- public void dialogClosed(Dialog dialog) {
- Alert alert = (Alert)dialog;
-
- if (alert.getResult()) {
- if (alert.getSelectedOption() == 1) {
- cancelShutdown = false;
- DesktopApplicationContext.exit();
+ if (alert == null) {
+ ArrayList<String> options = new ArrayList<String>();
+ options.add("Yes");
+ options.add("No");
+
+ alert = new Alert(MessageType.QUESTION, "Cancel shutdown?", options);
+ alert.open(display, new DialogCloseListener() {
+ public void dialogClosed(Dialog dialog) {
+ Alert alert = (Alert)dialog;
+
+ if (alert.getResult()) {
+ if (alert.getSelectedOption() == 1) {
+ cancelShutdown = false;
+ DesktopApplicationContext.exit();
+ }
}
+
+ ShutdownTest.this.alert = null;
}
- }
- });
+ });
+ }
return cancelShutdown;
}