Revision: 1705 http://svn.sourceforge.net/spring-rich-c/?rev=1705&view=rev Author: peterdb Date: 2007-02-02 00:10:16 -0800 (Fri, 02 Feb 2007)
Log Message: ----------- support commands for working with JDesktopPane Added Paths: ----------- trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/ trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/CascadeCommand.java trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/DesktopPaneContextMenuFactory.java trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/ShowFrameCommand.java trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/TileCommand.java Added: trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/CascadeCommand.java =================================================================== --- trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/CascadeCommand.java (rev 0) +++ trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/CascadeCommand.java 2007-02-02 08:10:16 UTC (rev 1705) @@ -0,0 +1,70 @@ +/* + * Copyright 2002-2007 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.contextmenu; + +import java.beans.PropertyVetoException; + +import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; + +import org.springframework.richclient.command.ActionCommand; + +/** + * Cascades all <code>JInternalFrame</code>s in a given <code>JDesktopPane</code>. + * + * @author Peter De Bruycker + */ +public class CascadeCommand extends ActionCommand { + private static final String ID = "cascadeCommand"; + + private JDesktopPane desktop; + private int offset = 20; + + public CascadeCommand( JDesktopPane desktopPane ) { + super( ID ); + desktop = desktopPane; + } + + public CascadeCommand( JDesktopPane desktopPane, int offset ) { + desktop = desktopPane; + this.offset = offset; + } + + protected void doExecuteCommand() { + int x = 0; + int y = 0; + JInternalFrame allFrames[] = desktop.getAllFrames(); + + // manager.setNormalSize(); + int frameHeight = (desktop.getBounds().height - 5) - allFrames.length * offset; + int frameWidth = (desktop.getBounds().width - 5) - allFrames.length * offset; + for( int i = allFrames.length - 1; i >= 0; i-- ) { + JInternalFrame frame = allFrames[i]; + if( frame.isIcon() ) { + try { + frame.setIcon( false ); + } catch( PropertyVetoException e ) { + // ignore + } + } + + frame.setSize( frameWidth, frameHeight ); + frame.setLocation( x, y ); + x = x + offset; + y = y + offset; + } + } +} Added: trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/DesktopPaneContextMenuFactory.java =================================================================== --- trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/DesktopPaneContextMenuFactory.java (rev 0) +++ trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/DesktopPaneContextMenuFactory.java 2007-02-02 08:10:16 UTC (rev 1705) @@ -0,0 +1,80 @@ +/* + * Copyright 2002-2007 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.contextmenu; + +import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; +import javax.swing.JPopupMenu; + +import org.springframework.richclient.command.CommandGroup; +import org.springframework.richclient.command.CommandManager; + +/** + * Helper class to create a context menu for a <code>JDesktopPane</code>. The context menu contains the following items: + * <ul> + * <li>tile command</li> + * <li>cascade command</li> + * <li>a separator</li> + * <li>a "show" command for each frame in the desktop pane</li> + * </ul> + * + * @author Peter De Bruycker + */ +public class DesktopPaneContextMenuFactory { + private JDesktopPane desktop; + + private CommandManager commandManager; + + public DesktopPaneContextMenuFactory( CommandManager commandManager, JDesktopPane desktopPane ) { + desktop = desktopPane; + this.commandManager = commandManager; + } + + public JPopupMenu getContextMenu() { + CommandGroup commandGroup = new CommandGroup(); + + TileCommand tileCommand = new TileCommand( desktop ); + CascadeCommand cascadeCommand = new CascadeCommand( desktop ); + + commandManager.configure( tileCommand ); + commandManager.configure( cascadeCommand ); + + commandGroup.add( tileCommand ); + commandGroup.add( cascadeCommand ); + + if( desktop.getAllFrames().length > 0 ) { + commandGroup.addSeparator(); + // TODO try to get the frames in the order they've been added to the desktop + // pane. + for( int i = 0; i < desktop.getAllFrames().length; i++ ) { + JInternalFrame frame = desktop.getAllFrames()[i]; + + ShowFrameCommand showFrameCommand = new ShowFrameCommand( frame ); + showFrameCommand.setIcon( frame.getFrameIcon() ); + showFrameCommand.setCaption( "ttt" ); + + String label = i + " " + frame.getTitle(); + if( i < 10 ) { + label = "&" + label; + } + showFrameCommand.setLabel( label ); + + commandGroup.add( showFrameCommand ); + } + } + return commandGroup.createPopupMenu(); + } +} Added: trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/ShowFrameCommand.java =================================================================== --- trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/ShowFrameCommand.java (rev 0) +++ trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/ShowFrameCommand.java 2007-02-02 08:10:16 UTC (rev 1705) @@ -0,0 +1,45 @@ +/* + * Copyright 2002-2007 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.contextmenu; + +import java.beans.PropertyVetoException; + +import javax.swing.JInternalFrame; + +import org.springframework.richclient.command.ActionCommand; + +/** + * Command to show a <code>JInternalFrame</code>, i.e. restore it, and bring it to the + * front. + * + * @author Peter De Bruycker + */ +public class ShowFrameCommand extends ActionCommand { + + private JInternalFrame frame; + + public ShowFrameCommand( JInternalFrame frame ) { + this.frame = frame; + } + + protected void doExecuteCommand() { + try { + frame.setSelected( true ); + } catch( PropertyVetoException e ) { + // ignore + } + } +} Added: trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/TileCommand.java =================================================================== --- trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/TileCommand.java (rev 0) +++ trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/application/mdi/contextmenu/TileCommand.java 2007-02-02 08:10:16 UTC (rev 1705) @@ -0,0 +1,59 @@ +/* + * Copyright 2002-2007 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.contextmenu; + +import java.beans.PropertyVetoException; + +import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; + +import org.springframework.richclient.command.ActionCommand; + +/** + * Tiles all <code>JInternalFrame</code>s in a given <code>JDesktopPane</code>. + * + * @author Peter De Bruycker + */ +public class TileCommand extends ActionCommand { + private static final String ID = "tileCommand"; + private JDesktopPane desktop; + + public TileCommand( JDesktopPane desktopPane ) { + super( ID ); + desktop = desktopPane; + } + + protected void doExecuteCommand() { + JInternalFrame allFrames[] = desktop.getAllFrames(); + + int frameHeight = desktop.getBounds().height / allFrames.length; + int y = 0; + for( int i = 0; i < allFrames.length; i++ ) { + JInternalFrame frame = allFrames[i]; + if( frame.isIcon() ) { + try { + frame.setIcon( false ); + } catch( PropertyVetoException e ) { + // ignore + } + } + + frame.setSize( desktop.getBounds().width, frameHeight ); + frame.setLocation( 0, y ); + y = y + frameHeight; + } + } +} 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 spring-rich-c-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs