Revision: 1304
Author: peterdb
Date: 2006-08-17 06:02:43 -0700 (Thu, 17 Aug 2006)
ViewCVS: http://svn.sourceforge.net/spring-rich-c/?rev=1304&view=rev
Log Message:
-----------
- Introduced AbstractApplicationWindow to allow easier creation of custom
ApplicationWindows
- removed magic bean "defaultApplicationPagePrototype" in
DefaultApplicationWindow
- added ApplicationPageFactory service factory + default implementation
- updated sandbox "mdi" applicationpage:
- deleted DesktopApplicationWindow and factory as they are obsolote
(register the DesktopApplicationPageFactory instead)
- created DesktopApplicationPageFactory implementation
Modified Paths:
--------------
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationServices.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationWindow.java
Added Paths:
-----------
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationPageFactory.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/ApplicationPageFactory.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/AbstractApplicationWindow.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationPageFactory.java
Removed Paths:
-------------
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationWindow.java
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationWindowFactory.java
Added:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationPageFactory.java
===================================================================
---
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationPageFactory.java
(rev 0)
+++
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationPageFactory.java
2006-08-17 13:02:43 UTC (rev 1304)
@@ -0,0 +1,14 @@
+package org.springframework.richclient.application.mdi;
+
+import org.springframework.richclient.application.ApplicationPage;
+import org.springframework.richclient.application.ApplicationPageFactory;
+import org.springframework.richclient.application.ApplicationWindow;
+import org.springframework.richclient.application.PageDescriptor;
+
+public class DesktopApplicationPageFactory implements ApplicationPageFactory{
+
+ public ApplicationPage createApplicationPage( ApplicationWindow window,
PageDescriptor descriptor ) {
+ return new DesktopApplicationPage(window, descriptor);
+ }
+
+}
Deleted:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationWindow.java
===================================================================
---
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationWindow.java
2006-08-16 22:03:56 UTC (rev 1303)
+++
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationWindow.java
2006-08-17 13:02:43 UTC (rev 1304)
@@ -1,29 +0,0 @@
-/*
- * Copyright 2002-2004 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
under
- * the License.
- */
-package org.springframework.richclient.application.mdi;
-
-import org.springframework.richclient.application.ApplicationPage;
-import org.springframework.richclient.application.PageDescriptor;
-import
org.springframework.richclient.application.support.DefaultApplicationWindow;
-
-/**
- * @author Peter De Bruycker
- */
-public class DesktopApplicationWindow extends DefaultApplicationWindow {
- protected ApplicationPage createPage(PageDescriptor descriptor) {
- return new DesktopApplicationPage(this, descriptor);
- }
-}
\ No newline at end of file
Deleted:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationWindowFactory.java
===================================================================
---
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationWindowFactory.java
2006-08-16 22:03:56 UTC (rev 1303)
+++
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/DesktopApplicationWindowFactory.java
2006-08-17 13:02:43 UTC (rev 1304)
@@ -1,32 +0,0 @@
-/*
- * Copyright 2002-2006 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
under
- * the License.
- */
-package org.springframework.richclient.application.mdi;
-
-import org.springframework.richclient.application.ApplicationWindow;
-import org.springframework.richclient.application.ApplicationWindowFactory;
-
-/**
- * Factory for <code>DesktopApplicationWindow</code> instances.
- *
- * @author Peter De Bruycker
- */
-public class DesktopApplicationWindowFactory implements
ApplicationWindowFactory {
-
- public ApplicationWindow createApplicationWindow() {
- return new DesktopApplicationWindow();
- }
-
-}
Added:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/ApplicationPageFactory.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/ApplicationPageFactory.java
(rev 0)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/ApplicationPageFactory.java
2006-08-17 13:02:43 UTC (rev 1304)
@@ -0,0 +1,15 @@
+package org.springframework.richclient.application;
+
+/**
+ * Service interface for creating <code>ApplicationPage</code>s.
+ *
+ * @author Peter De Bruycker
+ */
+public interface ApplicationPageFactory {
+ /**
+ * Create a new <code>ApplicationPage</code>.
+ *
+ * @return the window
+ */
+ ApplicationPage createApplicationPage( ApplicationWindow window,
PageDescriptor descriptor );
+}
Added:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/AbstractApplicationWindow.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/AbstractApplicationWindow.java
(rev 0)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/AbstractApplicationWindow.java
2006-08-17 13:02:43 UTC (rev 1304)
@@ -0,0 +1,367 @@
+package org.springframework.richclient.application.support;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.GraphicsEnvironment;
+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;
+import javax.swing.JFrame;
+import javax.swing.JMenuBar;
+import javax.swing.WindowConstants;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.richclient.application.Application;
+import org.springframework.richclient.application.ApplicationPage;
+import org.springframework.richclient.application.ApplicationPageFactory;
+import org.springframework.richclient.application.ApplicationServices;
+import org.springframework.richclient.application.ApplicationServicesLocator;
+import org.springframework.richclient.application.ApplicationWindow;
+import org.springframework.richclient.application.PageDescriptor;
+import org.springframework.richclient.application.PageListener;
+import org.springframework.richclient.application.ViewDescriptor;
+import org.springframework.richclient.application.WindowManager;
+import
org.springframework.richclient.application.config.ApplicationLifecycleAdvisor;
+import
org.springframework.richclient.application.config.ApplicationWindowConfigurer;
+import org.springframework.richclient.command.CommandGroup;
+import org.springframework.richclient.command.CommandManager;
+import org.springframework.richclient.progress.StatusBarCommandGroup;
+import org.springframework.richclient.util.EventListenerListHelper;
+import org.springframework.util.Assert;
+
+/**
+ * Abstract helper implementation for <code>ApplicationWindow</code>.
+ */
+public abstract class AbstractApplicationWindow implements ApplicationWindow,
WindowFocusListener {
+ protected Log logger = LogFactory.getLog( getClass() );
+
+ private final EventListenerListHelper pageListeners = new
EventListenerListHelper( PageListener.class );
+
+ private int number;
+
+ private ApplicationWindowCommandManager commandManager;
+
+ private CommandGroup menuBarCommandGroup;
+
+ private CommandGroup toolBarCommandGroup;
+
+ private StatusBarCommandGroup statusBarCommandGroup;
+
+ private ApplicationWindowConfigurer windowConfigurer;
+
+ private JFrame control;
+
+ private ApplicationPage currentPage;
+
+ private WindowManager windowManager;
+
+ public AbstractApplicationWindow() {
+ this( Application.instance().getWindowManager().size() );
+ }
+
+ public AbstractApplicationWindow( int number ) {
+ this.number = number;
+ getAdvisor().setOpeningWindow( this );
+ getAdvisor().onPreWindowOpen( getWindowConfigurer() );
+ init();
+ getAdvisor().onCommandsCreated( this );
+ }
+
+ protected void init() {
+ this.commandManager = getAdvisor().createWindowCommandManager();
+ this.menuBarCommandGroup = getAdvisor().getMenuBarCommandGroup();
+ this.toolBarCommandGroup = getAdvisor().getToolBarCommandGroup();
+ this.statusBarCommandGroup = getAdvisor().getStatusBarCommandGroup();
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public ApplicationPage getPage() {
+ return currentPage;
+ }
+
+ protected ApplicationLifecycleAdvisor getAdvisor() {
+ return Application.instance().getLifecycleAdvisor();
+ }
+
+ protected ApplicationServices getServices() {
+ return ApplicationServicesLocator.services();
+ }
+
+ protected ApplicationWindowConfigurer getWindowConfigurer() {
+ if( windowConfigurer == null ) {
+ this.windowConfigurer = initWindowConfigurer();
+ }
+ return windowConfigurer;
+ }
+
+ protected ApplicationWindowConfigurer initWindowConfigurer() {
+ return new DefaultApplicationWindowConfigurer( this );
+ }
+
+ public CommandManager getCommandManager() {
+ return commandManager;
+ }
+
+ public Iterator getSharedCommands() {
+ return commandManager.getSharedCommands();
+ }
+
+ public CommandGroup getMenuBar() {
+ return menuBarCommandGroup;
+ }
+
+ public CommandGroup getToolBar() {
+ return toolBarCommandGroup;
+ }
+
+ public StatusBarCommandGroup getStatusBar() {
+ return statusBarCommandGroup;
+ }
+
+ public void setWindowManager( WindowManager windowManager ) {
+ this.windowManager = windowManager;
+ }
+
+ /**
+ * Show the given page in this window.
+ *
+ * @param pageId the page to show, identified by id
+ *
+ * @throws IllegalArgumentException if pageId == null
+ */
+ public void showPage( String pageId ) {
+ if( pageId == null )
+ throw new IllegalArgumentException( "pageId == null" );
+
+ if( getPage() == null || !getPage().getId().equals( pageId ) ) {
+ showPage( createPage( this, pageId ) );
+ } else {
+ // asking for the same page, so ignore
+ }
+ }
+
+ public void showPage( PageDescriptor pageDescriptor ) {
+ Assert.notNull( pageDescriptor, "pageDescriptor == null" );
+
+ if( getPage() == null || !getPage().getId().equals(
pageDescriptor.getId() ) ) {
+ showPage( createPage( pageDescriptor ) );
+ } else {
+ // asking for the same page, so ignore
+ }
+ }
+
+ /**
+ * Show the given page in this window.
+ *
+ * @param page the page to show
+ *
+ * @throws IllegalArgumentException if page == null
+ */
+ public void showPage( ApplicationPage page ) {
+ if( page == null )
+ throw new IllegalArgumentException( "page == null" );
+
+ if( this.currentPage == null ) {
+ this.currentPage = page;
+ initWindow();
+ setActivePage( page );
+ } else {
+ if( !currentPage.getId().equals( page.getId() ) ) {
+ final ApplicationPage oldPage = this.currentPage;
+ this.currentPage = page;
+ setActivePage( page );
+ pageListeners.fire( "pageClosed", oldPage );
+ } else {
+ // asking for the same page, so ignore
+ }
+ }
+ pageListeners.fire( "pageOpened", this.currentPage );
+ }
+
+ protected final ApplicationPage createPage( ApplicationWindow window,
String pageDescriptorId ) {
+ PageDescriptor descriptor = getPageDescriptor( pageDescriptorId );
+ return createPage( descriptor );
+ }
+
+ /**
+ * Factory method for creating the page area managed by this window.
Subclasses may
+ * override to return a custom page implementation.
+ *
+ * @param descriptor The page descriptor
+ *
+ * @return The window's page
+ */
+ protected ApplicationPage createPage( PageDescriptor descriptor ) {
+ ApplicationPageFactory windowFactory = (ApplicationPageFactory)
getServices().getService(
+ ApplicationPageFactory.class );
+ return windowFactory.createApplicationPage( this, descriptor );
+ }
+
+ protected PageDescriptor getPageDescriptor( String pageDescriptorId ) {
+ ApplicationContext ctx =
Application.instance().getApplicationContext();
+ Assert.state( ctx.containsBean( pageDescriptorId ), "Do not know about
page or view descriptor with name '"
+ + pageDescriptorId + "' - check your context config" );
+ Object desc = ctx.getBean( pageDescriptorId );
+ if( desc instanceof PageDescriptor ) {
+ return (PageDescriptor) desc;
+ } else if( desc instanceof ViewDescriptor ) {
+ return new SingleViewPageDescriptor( (ViewDescriptor) desc );
+ } else {
+ throw new IllegalArgumentException( "Page id '" + pageDescriptorId
+ + "' is not backed by an ApplicationPageDescriptor" );
+ }
+ }
+
+ private void initWindow() {
+ this.control = createNewWindowControl();
+ this.control.addWindowFocusListener( this );
+ initWindowControl( this.control );
+ getAdvisor().onWindowCreated( this );
+ getAdvisor().showIntroComponentIfNecessary( this );
+ this.control.setVisible( true );
+ getAdvisor().onWindowOpened( this );
+ }
+
+ protected void initWindowControl( JFrame windowControl ) {
+ ApplicationWindowConfigurer configurer = getWindowConfigurer();
+ applyStandardLayout( windowControl, configurer );
+ prepareWindowForView( windowControl, configurer );
+ }
+
+ protected void applyStandardLayout( JFrame windowControl,
ApplicationWindowConfigurer configurer ) {
+ windowControl.setTitle( configurer.getTitle() );
+ windowControl.setIconImage( configurer.getImage() );
+ windowControl.setJMenuBar( createMenuBarControl() );
+ windowControl.getContentPane().setLayout( new BorderLayout() );
+ windowControl.getContentPane().add( createToolBarControl(),
BorderLayout.NORTH );
+ windowControl.getContentPane().add( createWindowContentPane() );
+ windowControl.getContentPane().add( createStatusBarControl(),
BorderLayout.SOUTH );
+ }
+
+ /**
+ * Set the given <code>ApplicationPage</code> active (visible + selected if
+ * applicable)
+ *
+ * @param page the <code>ApplicationPage</code>
+ */
+ protected abstract void setActivePage( ApplicationPage page );
+
+ protected void prepareWindowForView( JFrame windowControl,
ApplicationWindowConfigurer configurer ) {
+ windowControl.pack();
+ windowControl.setSize( configurer.getInitialSize() );
+
+ // This works around a bug in setLocationRelativeTo(...): it currently
+ // does not take multiple monitors into accounts on all operating
+ // systems.
+ try {
+ // Note that if this is running on a JVM prior to 1.4, then an
+ // exception will be thrown and we will fall back to
+ // setLocationRelativeTo(...).
+ final Rectangle screenBounds =
GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
+
+ final Dimension windowSize = windowControl.getSize();
+ final int x = screenBounds.x + ((screenBounds.width -
windowSize.width) / 2);
+ final int y = screenBounds.y + ((screenBounds.height -
windowSize.height) / 2);
+ windowControl.setLocation( x, y );
+ } catch( Throwable t ) {
+ windowControl.setLocationRelativeTo( null );
+ }
+ }
+
+ protected JFrame createNewWindowControl() {
+ JFrame frame = new JFrame();
+ frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
+ WindowAdapter windowCloseHandler = new WindowAdapter() {
+ public void windowClosing( WindowEvent e ) {
+ close();
+ }
+ };
+ frame.addWindowListener( windowCloseHandler );
+ return frame;
+ }
+
+ public JFrame getControl() {
+ return control;
+ }
+
+ public boolean isControlCreated() {
+ return control != null;
+ }
+
+ protected JMenuBar createMenuBarControl() {
+ JMenuBar menuBar = menuBarCommandGroup.createMenuBar();
+ menuBarCommandGroup.setVisible( getWindowConfigurer().getShowMenuBar()
);
+ return menuBar;
+ }
+
+ protected JComponent createToolBarControl() {
+ JComponent toolBar = toolBarCommandGroup.createToolBar();
+ toolBarCommandGroup.setVisible( getWindowConfigurer().getShowToolBar()
);
+ return toolBar;
+ }
+
+ protected JComponent createStatusBarControl() {
+ JComponent statusBar = statusBarCommandGroup.getControl();
+ statusBarCommandGroup.setVisible(
getWindowConfigurer().getShowStatusBar() );
+ return statusBar;
+ }
+
+ public void addPageListener( PageListener listener ) {
+ this.pageListeners.add( listener );
+ }
+
+ public void removePageListener( PageListener listener ) {
+ this.pageListeners.remove( listener );
+ }
+
+ public boolean close() {
+ boolean canClose = getAdvisor().onPreWindowClose( this );
+ if( canClose ) {
+ if( currentPage != null ) {
+ currentPage.close();
+ }
+
+ if( control != null ) {
+ control.dispose();
+ control = null;
+ }
+
+ if( windowManager != null ) {
+ windowManager.remove( this );
+ }
+ windowManager = null;
+ }
+ 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 no action is done. This way the last focussed window
will stay
+ * listed as the activeWindow.
+ */
+ public void windowLostFocus( WindowEvent e ) {
+ }
+
+ /**
+ * Implementors create the component that contains the contents of this
window.
+ *
+ * @return the content pane
+ */
+ protected abstract JComponent createWindowContentPane();
+}
Added:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationPageFactory.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationPageFactory.java
(rev 0)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationPageFactory.java
2006-08-17 13:02:43 UTC (rev 1304)
@@ -0,0 +1,29 @@
+package org.springframework.richclient.application.support;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.richclient.application.ApplicationPage;
+import org.springframework.richclient.application.ApplicationPageFactory;
+import org.springframework.richclient.application.ApplicationWindow;
+import org.springframework.richclient.application.PageDescriptor;
+
+/**
+ * <code>ApplicationPageFactory</code> implementation for
+ * <code>DefaultApplicationPage</code>.
+ *
+ * @author Peter De Bruycker
+ *
+ */
+public class DefaultApplicationPageFactory implements ApplicationPageFactory{
+ private static final Log logger = LogFactory.getLog(
DefaultApplicationWindowFactory.class );
+
+ public ApplicationPage createApplicationPage( ApplicationWindow window,
PageDescriptor descriptor ) {
+ logger.info( "Creating new DefaultApplicationPage" );
+
+ DefaultApplicationPage page = new DefaultApplicationPage();
+ page.setApplicationWindow( window );
+ page.setDescriptor( descriptor );
+
+ return page;
+ }
+}
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationServices.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationServices.java
2006-08-16 22:03:56 UTC (rev 1303)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationServices.java
2006-08-17 13:02:43 UTC (rev 1304)
@@ -35,6 +35,7 @@
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.core.enums.LabeledEnumResolver;
import org.springframework.core.enums.StaticLabeledEnumResolver;
+import org.springframework.richclient.application.ApplicationPageFactory;
import org.springframework.richclient.application.ApplicationServices;
import org.springframework.richclient.application.ApplicationWindowFactory;
import org.springframework.richclient.application.DefaultConversionService;
@@ -282,7 +283,24 @@
public void setApplicationWindowFactoryId( String factoryId ) {
services.put( ApplicationWindowFactory.class, factoryId );
}
+
+ /**
+ * Set the <code>ApplicationPage</code> factory service implementation
+ *
+ * @param factory
+ */
+ public void setApplicationPageFactory( ApplicationPageFactory factory ) {
+ services.put( ApplicationPageFactory.class, factory );
+ }
+ /**
+ * Set the <code>ApplicationPage</code> factory service implementation
bean id
+ *
+ * @param factoryId bean id
+ */
+ public void setApplicationPageFactoryId( String factoryId ) {
+ services.put( ApplicationPageFactory.class, factoryId );
+ }
/**
* Set the binder selection strategy service implementation
@@ -874,6 +892,13 @@
}
};
+ protected static final ImplBuilder applicationPageFactoryImplBuilder = new
ImplBuilder() {
+ public Object build( DefaultApplicationServices applicationServices ) {
+ logger.info( "Creating default service impl:
ApplicationPageFactory" );
+ return new DefaultApplicationPageFactory();
+ }
+ };
+
/**
* Static initializer to construct the implementation builder map.
*/
@@ -882,6 +907,7 @@
serviceImplBuilders.put(ApplicationContext.class,
applicationContextImplBuilder);
serviceImplBuilders.put(ApplicationObjectConfigurer.class,
applicationObjectConfigurerImplBuilder);
serviceImplBuilders.put(ApplicationSecurityManager.class,
applicationSecurityManagerImplBuilder);
+ serviceImplBuilders.put(ApplicationPageFactory.class,
applicationPageFactoryImplBuilder);
serviceImplBuilders.put(ApplicationWindowFactory.class,
applicationWindowFactoryImplBuilder);
serviceImplBuilders.put(BinderSelectionStrategy.class,
binderSelectionStrategyImplBuilder);
serviceImplBuilders.put(BindingFactoryProvider.class,
bindingFactoryProviderImplBuilder);
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-08-16 22:03:56 UTC (rev 1303)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationWindow.java
2006-08-17 13:02:43 UTC (rev 1304)
@@ -16,379 +16,35 @@
package org.springframework.richclient.application.support;
import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.GraphicsEnvironment;
-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;
-import javax.swing.JFrame;
-import javax.swing.JMenuBar;
-import javax.swing.WindowConstants;
+import javax.swing.JPanel;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.richclient.application.Application;
import org.springframework.richclient.application.ApplicationPage;
-import org.springframework.richclient.application.ApplicationServices;
-import org.springframework.richclient.application.ApplicationServicesLocator;
-import org.springframework.richclient.application.ApplicationWindow;
-import org.springframework.richclient.application.PageDescriptor;
-import org.springframework.richclient.application.PageListener;
-import org.springframework.richclient.application.ViewDescriptor;
-import org.springframework.richclient.application.WindowManager;
-import
org.springframework.richclient.application.config.ApplicationLifecycleAdvisor;
-import
org.springframework.richclient.application.config.ApplicationWindowConfigurer;
-import org.springframework.richclient.command.CommandGroup;
-import org.springframework.richclient.command.CommandManager;
-import org.springframework.richclient.progress.StatusBarCommandGroup;
-import org.springframework.richclient.util.EventListenerListHelper;
-import org.springframework.util.Assert;
/**
* Provides a default implementation of [EMAIL PROTECTED] ApplicationWindow}
*/
-public class DefaultApplicationWindow implements ApplicationWindow,
WindowFocusListener {
- protected Log logger = LogFactory.getLog(getClass());
-
- private static final String DEFAULT_APPLICATION_PAGE_BEAN_ID =
"defaultApplicationPagePrototype";
-
- private final EventListenerListHelper pageListeners = new
EventListenerListHelper(PageListener.class);
-
- private int number;
-
- private ApplicationWindowCommandManager commandManager;
-
- private CommandGroup menuBarCommandGroup;
-
- private CommandGroup toolBarCommandGroup;
-
- private StatusBarCommandGroup statusBarCommandGroup;
-
- private ApplicationWindowConfigurer windowConfigurer;
-
- private JFrame control;
-
- private ApplicationPage currentPage;
-
- private WindowManager windowManager;
-
+public class DefaultApplicationWindow extends AbstractApplicationWindow {
+ private JPanel panel;
+
public DefaultApplicationWindow() {
- this(Application.instance().getWindowManager().size());
+ super();
}
- public DefaultApplicationWindow(int number) {
- this.number = number;
- getAdvisor().setOpeningWindow(this);
- getAdvisor().onPreWindowOpen(getWindowConfigurer());
- init();
- getAdvisor().onCommandsCreated(this);
+ public DefaultApplicationWindow( int number ) {
+ super( number );
}
- protected void init() {
- this.commandManager = getAdvisor().createWindowCommandManager();
- this.menuBarCommandGroup = getAdvisor().getMenuBarCommandGroup();
- this.toolBarCommandGroup = getAdvisor().getToolBarCommandGroup();
- this.statusBarCommandGroup = getAdvisor().getStatusBarCommandGroup();
- }
-
- public int getNumber() {
- return number;
- }
-
- public ApplicationPage getPage() {
- return currentPage;
- }
-
- protected ApplicationLifecycleAdvisor getAdvisor() {
- return Application.instance().getLifecycleAdvisor();
- }
-
- protected ApplicationServices getServices() {
- return ApplicationServicesLocator.services();
- }
-
- protected ApplicationWindowConfigurer getWindowConfigurer() {
- if (windowConfigurer == null) {
- this.windowConfigurer = initWindowConfigurer();
- }
- return windowConfigurer;
- }
-
- protected ApplicationWindowConfigurer initWindowConfigurer() {
- return new DefaultApplicationWindowConfigurer(this);
- }
-
- public CommandManager getCommandManager() {
- return commandManager;
- }
-
- public Iterator getSharedCommands() {
- return commandManager.getSharedCommands();
- }
-
- public CommandGroup getMenuBar() {
- return menuBarCommandGroup;
- }
-
- public CommandGroup getToolBar() {
- return toolBarCommandGroup;
- }
-
- public StatusBarCommandGroup getStatusBar() {
- return statusBarCommandGroup;
- }
-
- public void setWindowManager(WindowManager windowManager) {
- this.windowManager = windowManager;
- }
-
- /**
- * Show the given page in this window.
- *
- * @param pageId the page to show, identified by id
- *
- * @throws IllegalArgumentException if pageId == null
- */
- public void showPage(String pageId) {
- if (pageId == null) throw new IllegalArgumentException("pageId ==
null");
-
- if (getPage() == null || !getPage().getId().equals(pageId)) {
- showPage(createPage(this, pageId));
- }
- else {
- // asking for the same page, so ignore
- }
- }
-
- public void showPage(PageDescriptor pageDescriptor) {
- Assert.notNull(pageDescriptor, "pageDescriptor == null");
+ protected JComponent createWindowContentPane(){
+ panel = new JPanel(new BorderLayout());
- if(getPage() == null ||
!getPage().getId().equals(pageDescriptor.getId())) {
- showPage(createPage(pageDescriptor));
- }
- else {
- // asking for the same page, so ignore
- }
+ return panel;
}
- /**
- * Show the given page in this window.
- *
- * @param page the page to show
- *
- * @throws IllegalArgumentException if page == null
- */
- public void showPage(ApplicationPage page) {
- if (page == null) throw new IllegalArgumentException("page == null");
-
- if (this.currentPage == null) {
- this.currentPage = page;
- initWindow();
- }
- else {
- if (!currentPage.getId().equals(page.getId())) {
- final ApplicationPage oldPage = this.currentPage;
- this.currentPage = page;
- updatePageControl(oldPage);
- pageListeners.fire("pageClosed", oldPage);
- }
- else {
- // asking for the same page, so ignore
- }
- }
- pageListeners.fire("pageOpened", this.currentPage);
+ protected void setActivePage( ApplicationPage page ) {
+ panel.removeAll();
+ panel.add(page.getControl());
+ panel.validate();
}
-
- protected final ApplicationPage createPage(ApplicationWindow window,
String pageDescriptorId) {
- PageDescriptor descriptor = getPageDescriptor(pageDescriptorId);
- return createPage(descriptor);
- }
-
- /**
- * Factory method for creating the page area managed by this window.
- * Subclasses may override to return a custom page implementation.
- *
- * @param descriptor The page descriptor
- *
- * @return The window's page
- */
- protected ApplicationPage createPage(PageDescriptor descriptor) {
- ApplicationContext ctx =
Application.instance().getApplicationContext();
- try {
- ApplicationPage page = (ApplicationPage)ctx.getBean(
- DEFAULT_APPLICATION_PAGE_BEAN_ID, ApplicationPage.class);
- page.setApplicationWindow(this);
- page.setDescriptor(descriptor);
- return page;
- }
- catch (NoSuchBeanDefinitionException e) {
- return new DefaultApplicationPage(this, descriptor);
- }
- }
-
- protected PageDescriptor getPageDescriptor(String pageDescriptorId) {
- ApplicationContext ctx =
Application.instance().getApplicationContext();
- Assert.state(ctx.containsBean(pageDescriptorId),
- "Do not know about page or view descriptor with name '" +
pageDescriptorId
- + "' - check your context config");
- Object desc = ctx.getBean(pageDescriptorId);
- if (desc instanceof PageDescriptor) {
- return (PageDescriptor)desc;
- }
- else if (desc instanceof ViewDescriptor) {
- return new SingleViewPageDescriptor((ViewDescriptor)desc);
- }
- else {
- throw new IllegalArgumentException("Page id '" + pageDescriptorId
- + "' is not backed by an ApplicationPageDescriptor");
- }
- }
-
- private void initWindow() {
- this.control = createNewWindowControl();
- this.control.addWindowFocusListener(this);
- initWindowControl(this.control);
- getAdvisor().onWindowCreated(this);
- getAdvisor().showIntroComponentIfNecessary(this);
- this.control.setVisible(true);
- getAdvisor().onWindowOpened(this);
- }
-
- protected void initWindowControl(JFrame windowControl) {
- ApplicationWindowConfigurer configurer = getWindowConfigurer();
- applyStandardLayout(windowControl, configurer);
- applyCustomLayout(windowControl, configurer);
- prepareWindowForView(windowControl, configurer);
- }
-
- protected void applyStandardLayout(JFrame windowControl,
ApplicationWindowConfigurer configurer) {
- windowControl.setTitle(configurer.getTitle());
- windowControl.setIconImage(configurer.getImage());
- windowControl.setJMenuBar(createMenuBarControl());
- windowControl.getContentPane().setLayout(new BorderLayout());
- windowControl.getContentPane().add(createToolBarControl(),
BorderLayout.NORTH);
- windowControl.getContentPane().add(createStatusBarControl(),
BorderLayout.SOUTH);
- }
-
- protected void applyCustomLayout(JFrame windowControl,
ApplicationWindowConfigurer configurer) {
- windowControl.getContentPane().add(this.currentPage.getControl());
- }
-
- protected void prepareWindowForView(JFrame windowControl,
ApplicationWindowConfigurer configurer) {
- windowControl.pack();
- windowControl.setSize(configurer.getInitialSize());
-
- // This works around a bug in setLocationRelativeTo(...): it currently
- // does not take multiple monitors into accounts on all operating
- // systems.
- try {
- // Note that if this is running on a JVM prior to 1.4, then an
- // exception will be thrown and we will fall back to
- // setLocationRelativeTo(...).
- final Rectangle screenBounds =
GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
-
- final Dimension windowSize = windowControl.getSize();
- final int x = screenBounds.x + ((screenBounds.width -
windowSize.width) / 2);
- final int y = screenBounds.y + ((screenBounds.height -
windowSize.height) / 2);
- windowControl.setLocation(x, y);
- }
- catch (Throwable t) {
- windowControl.setLocationRelativeTo(null);
- }
- }
-
- protected JFrame createNewWindowControl() {
- JFrame frame = new JFrame();
- frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
- WindowAdapter windowCloseHandler = new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- close();
- }
- };
- frame.addWindowListener(windowCloseHandler);
- return frame;
- }
-
- protected void updatePageControl(ApplicationPage oldPage) {
- control.getContentPane().remove(oldPage.getControl());
- control.getContentPane().add(this.currentPage.getControl());
- control.validate();
- }
-
- public JFrame getControl() {
- return control;
- }
-
- public boolean isControlCreated() {
- return control != null;
- }
-
- protected JMenuBar createMenuBarControl() {
- JMenuBar menuBar = menuBarCommandGroup.createMenuBar();
- menuBarCommandGroup.setVisible(getWindowConfigurer().getShowMenuBar());
- return menuBar;
- }
-
- protected JComponent createToolBarControl() {
- JComponent toolBar = toolBarCommandGroup.createToolBar();
- toolBarCommandGroup.setVisible(getWindowConfigurer().getShowToolBar());
- return toolBar;
- }
-
- protected JComponent createStatusBarControl() {
- JComponent statusBar = statusBarCommandGroup.getControl();
-
statusBarCommandGroup.setVisible(getWindowConfigurer().getShowStatusBar());
- return statusBar;
- }
-
- public void addPageListener(PageListener listener) {
- this.pageListeners.add(listener);
- }
-
- public void removePageListener(PageListener listener) {
- this.pageListeners.remove(listener);
- }
-
- public boolean close() {
- boolean canClose = getAdvisor().onPreWindowClose(this);
- if (canClose) {
- if (currentPage != null) {
- currentPage.close();
- }
-
- if (control != null) {
- control.dispose();
- control = null;
- }
-
- if (windowManager != null) {
- windowManager.remove(this);
- }
- windowManager = null;
- }
- 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 no action is done. This way the last focussed window
- * will stay listed as the activeWindow.
- */
- public void windowLostFocus(WindowEvent e)
- {
- }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs