Revision: 1205
Author: jhoskens
Date: 2006-06-21 01:45:15 -0700 (Wed, 21 Jun 2006)
ViewCVS: http://svn.sourceforge.net/spring-rich-c/?rev=1205&view=rev
Log Message:
-----------
ActiveWindow is tracked by the WindowManager (already holds the created
windows, so seems logical to keep track there).
Each window is attached to a windowManager and will set itself as activeWindow
when it gains focus.
Modified Paths:
--------------
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/Application.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/WindowManager.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationWindow.java
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/Application.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/Application.java
2006-06-17 14:23:08 UTC (rev 1204)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/Application.java
2006-06-21 08:45:15 UTC (rev 1205)
@@ -52,8 +52,6 @@
private ApplicationLifecycleAdvisor lifecycleAdvisor;
- private ApplicationWindow activeWindow;
-
private WindowManager windowManager;
/**
@@ -152,8 +150,6 @@
public void openWindow( String pageDescriptorId ) {
ApplicationWindow newWindow = initWindow(createNewWindow());
newWindow.showPage(pageDescriptorId);
- // @TODO track active window...
- this.activeWindow = newWindow;
}
private ApplicationWindow initWindow( ApplicationWindow window ) {
@@ -174,8 +170,14 @@
return windowManager;
}
+ /**
+ * ActiveWindow is tracked by windowManager. When a window gains focus, the
+ * manager will receive this window as the active one.
+ *
+ * @return the activeWindow.
+ */
public ApplicationWindow getActiveWindow() {
- return activeWindow;
+ return windowManager.getActiveWindow();
}
public void close() {
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/WindowManager.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/WindowManager.java
2006-06-17 14:23:08 UTC (rev 1204)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/WindowManager.java
2006-06-21 08:45:15 UTC (rev 1205)
@@ -55,6 +55,11 @@
* (element type: <code>WindowManager</code>).
*/
private List subManagers;
+
+ /**
+ * Holds the currently active window.
+ */
+ private ApplicationWindow activeWindow;
/**
* Creates an empty window manager without a parent window manager (that
is,
@@ -143,6 +148,9 @@
return managed;
}
+ /**
+ * @return the parent of this WindowManager
+ */
public WindowManager getParent() {
return parentManager;
}
@@ -164,6 +172,32 @@
}
}
+ /**
+ * Set the currently active window. When a window gets focus, it will set
itself
+ * as the current window of it's manager.
+ *
+ * TODO maybe provide a way to listen to activeWindow changes?
+ *
+ * @param window
+ */
+ public final void setActiveWindow(ApplicationWindow window)
+ {
+ this.activeWindow = window;
+ if (getParent() != null) // let things ripple up
+ getParent().setActiveWindow(window);
+ }
+
+ /**
+ * @return the active window.
+ */
+ public final ApplicationWindow getActiveWindow()
+ {
+ return this.activeWindow;
+ }
+
+ /**
+ * @return Number of windows managed by this instance.
+ */
public int size() {
return windows.size();
}
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationWindow.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationWindow.java
2006-06-17 14:23:08 UTC (rev 1204)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationWindow.java
2006-06-21 08:45:15 UTC (rev 1205)
@@ -21,6 +21,7 @@
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
import java.util.Iterator;
import javax.swing.JComponent;
@@ -52,7 +53,7 @@
/**
* Provides a default implementation of [EMAIL PROTECTED] ApplicationWindow}
*/
-public class DefaultApplicationWindow implements ApplicationWindow {
+public class DefaultApplicationWindow implements ApplicationWindow,
WindowFocusListener {
protected Log logger = LogFactory.getLog(getClass());
private static final String DEFAULT_APPLICATION_PAGE_BEAN_ID =
"defaultApplicationPagePrototype";
@@ -240,6 +241,7 @@
private void initWindow() {
this.control = createNewWindowControl();
+ this.control.addWindowFocusListener(this);
initWindowControl(this.control);
getAdvisor().onWindowCreated(this);
getAdvisor().showIntroComponentIfNecessary(this);
@@ -361,4 +363,24 @@
}
return canClose;
}
+
+ /**
+ * When gaining focus, set this window as the active one on it's manager.
+ */
+ public void windowGainedFocus(WindowEvent e)
+ {
+ if (this.windowManager != null)
+ this.windowManager.setActiveWindow(this);
+ }
+
+ /**
+ * When losing focus set actieve window to <code>null</code>. This is
+ * ok because focus lost/gained events always arrive in sequence.
+ * (no focus gained without a focus lost somewhere)
+ */
+ public void windowLostFocus(WindowEvent e)
+ {
+ if (this.windowManager != null)
+ this.windowManager.setActiveWindow(null);
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs