Revision: 1087
Author: lstreepy
Date: 2006-04-25 07:37:29 -0700 (Tue, 25 Apr 2006)
ViewCVS: http://svn.sourceforge.net/spring-rich-c/?rev=1087&view=rev
Log Message:
-----------
Initial checkin
Added Paths:
-----------
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/support/DialogPageUtils.java
Added:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/support/DialogPageUtils.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/support/DialogPageUtils.java
(rev 0)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/support/DialogPageUtils.java
2006-04-25 14:37:29 UTC (rev 1087)
@@ -0,0 +1,216 @@
+/*
+ * 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.dialog.support;
+
+import java.awt.BorderLayout;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+
+import org.springframework.richclient.command.ActionCommand;
+import org.springframework.richclient.command.CommandGroup;
+import org.springframework.richclient.core.Guarded;
+import org.springframework.richclient.core.Message;
+import org.springframework.richclient.dialog.DialogPage;
+import org.springframework.richclient.dialog.Messagable;
+import org.springframework.richclient.dialog.TitlePane;
+import org.springframework.richclient.dialog.TitledPageApplicationDialog;
+import org.springframework.richclient.util.GuiStandardUtils;
+
+/**
+ * Useful methods for working with [EMAIL PROTECTED] DialogPage}s. These
methods make it easier to
+ * place dialog pages in arbitrary containers, wire in message listeners, wire
actions
+ * to the page complete status, etc.
+ * <p>
+ * These helpers can be used to quickly construct a standard layout (like that
found in
+ * the [EMAIL PROTECTED] TitledPageApplicationDialog}, or you can use these
methods to construct the
+ * various components (title area and button bar) and then lay things out as
you like.
+ * <p>
+ * The standard layout is obtained using the
+ * [EMAIL PROTECTED] #createStandardView(DialogPage, ActionCommand,
ActionCommand)} or
+ * [EMAIL PROTECTED] #createStandardView(DialogPage, Object[])} methods. To
create the pieces and do
+ * the layout independently, use [EMAIL PROTECTED]
#createTitlePane(DialogPage)} to get the title
+ * pane and wire your OK command into the page complete status using
+ * [EMAIL PROTECTED] #adaptPageCompletetoGuarded(DialogPage, Guarded)}. If you
don't want to use the
+ * standard title pane, you can easily arrange for the messages coming from
the dialog
+ * page to be sent to a [EMAIL PROTECTED] Messagable} of your choice using
+ * [EMAIL PROTECTED] #addMessageMonitor(DialogPage, Messagable)}.
+ *
+ * @author Larry Streepy
+ *
+ */
+public class DialogPageUtils {
+
+ /**
+ * Create a standard [EMAIL PROTECTED] TitlePane} wired to receive
messages from the given dialog
+ * page. The title pane will also be configured from the dialog page's
title and icon.
+ *
+ * @param dialogPage to process
+ */
+ public static TitlePane createTitlePane( DialogPage dialogPage ) {
+ TitlePane titlePane = new TitlePane();
+ titlePane.setTitle(dialogPage.getTitle());
+ titlePane.setImage(dialogPage.getImage());
+ addMessageMonitor(dialogPage, titlePane);
+
+ return titlePane;
+ }
+
+ /**
+ * Construct a complete standard layout for a dialog page. This is a panel
with the
+ * title/message area at the top, the dialog page control in the center,
and the
+ * command button bar (using the provided ok and cancel commands) on the
bottom. The
+ * finishCommand provided will automatically be wired into the page
complete status of
+ * the dialog page.
+ *
+ * @param dialogPage to process
+ * @param okCommand Action command to wire into dialogPage's page complete
status
+ * @param cancelCommand to add to the command button bar
+ * @return created component
+ * @see #createTitlePane(DialogPage)
+ * @see #adaptToPageComplete(DialogPage, Guarded)
+ */
+ public static JComponent createStandardView( DialogPage dialogPage,
ActionCommand okCommand,
+ ActionCommand cancelCommand ) {
+ adaptPageCompletetoGuarded(dialogPage, okCommand);
+ return createStandardView(dialogPage, new Object[] { okCommand,
cancelCommand });
+ }
+
+ /**
+ * Construct a complete standard layout for a dialog page. This is a panel
with the
+ * title/message area at the top, the dialog page control in the center,
and the
+ * command button bar (using the provided group of commands) on the
bottom. You should
+ * have already wired any commands to the page complete status as needed.
+ *
+ * @param dialogPage to process
+ * @param commandGroupMembers Array of commands to place in the button bar
+ * @return created component
+ * @see #createTitlePane(DialogPage)
+ * @see #adaptToPageComplete(DialogPage, Guarded)
+ */
+ public static JComponent createStandardView( DialogPage dialogPage,
Object[] commandGroupMembers ) {
+ JPanel viewPanel = new JPanel(new BorderLayout());
+
+ JPanel titlePaneContainer = new JPanel(new BorderLayout());
+ titlePaneContainer.add(createTitlePane(dialogPage).getControl());
+ titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
+ viewPanel.add(titlePaneContainer, BorderLayout.NORTH);
+
+ JComponent pageControl = dialogPage.getControl();
+ GuiStandardUtils.attachDialogBorder(pageControl);
+ viewPanel.add(pageControl);
+
+ viewPanel.add(createButtonBar(commandGroupMembers),
BorderLayout.SOUTH);
+
+ return viewPanel;
+ }
+
+ /**
+ * Return a standardized row of command buttons.
+ *
+ * @param groupMembers
+ * @return button bar
+ */
+ public static JComponent createButtonBar( Object[] groupMembers ) {
+ CommandGroup dialogCommandGroup =
CommandGroup.createCommandGroup(null, groupMembers);
+ JComponent buttonBar = dialogCommandGroup.createButtonBar();
+ GuiStandardUtils.attachDialogBorder(buttonBar);
+ return buttonBar;
+ }
+
+ /**
+ * Add a message monitor. Each monitor will have its
+ * [EMAIL PROTECTED] Messagable#setMessage(Message)} method called
whenever the MESSAGE property
+ * on the dialog page changes.
+ *
+ * @param dialogPage to monitor
+ * @param monitor to add
+ */
+ public static void addMessageMonitor( DialogPage dialogPage, Messagable
monitor ) {
+ dialogPage.addPropertyChangeListener(Messagable.MESSAGE_PROPERTY, new
MessageHandler(monitor));
+ }
+
+ /**
+ * Create an adapter that will monitor the page complete status of the
dialog page and
+ * adapt it to operations on the provided Guarded object. If the page is
complete,
+ * then the guarded object will be enabled. If this page is not complete,
then the
+ * guarded object will be disabled.
+ *
+ * @param dialogPage to monitor
+ * @param guarded object to adapt
+ */
+ public static void adaptPageCompletetoGuarded( DialogPage dialogPage,
Guarded guarded ) {
+
dialogPage.addPropertyChangeListener(DialogPage.PAGE_COMPLETE_PROPERTY, new
PageCompleteAdapter(guarded));
+ }
+
+ /**
+ * Internal class to handle the PAGE_COMPLETE property changes in the
dialog page and
+ * adapt them to operations on a Guarded object.
+ */
+ protected static class PageCompleteAdapter implements
PropertyChangeListener {
+ private Guarded _guarded;
+
+ /**
+ * Construct a handler on the given guarded object.
+ *
+ * @param guarded object to manage
+ */
+ protected PageCompleteAdapter( Guarded guarded ) {
+ _guarded = guarded;
+ }
+
+ /**
+ * Handle a change in the page complete state of the dialog page
+ *
+ * @param e
+ */
+ public void propertyChange( PropertyChangeEvent e ) {
+ if( DialogPage.PAGE_COMPLETE_PROPERTY.equals(e.getPropertyName())
) {
+ _guarded.setEnabled(((Boolean)
e.getNewValue()).booleanValue());
+ }
+ }
+ }
+
+ /**
+ * Internal class to handle the MESSAGE_PROPERTY property changes in a
dialog page.
+ */
+ private static class MessageHandler implements PropertyChangeListener {
+ private Messagable monitor;
+
+ /**
+ * Construct a handler on the given message monitor.
+ *
+ * @param monitor to send messages to
+ */
+ public MessageHandler( Messagable monitor ) {
+ this.monitor = monitor;
+ }
+
+ /**
+ * Handle a change in the message or page complete state of the dialog
page.
+ *
+ * @param e
+ */
+ public void propertyChange( PropertyChangeEvent e ) {
+ if( Messagable.MESSAGE_PROPERTY.equals(e.getPropertyName()) ) {
+ monitor.setMessage((Message) e.getNewValue());
+ }
+ }
+ }
+}
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