Revision: 1119
Author:   peterdb
Date:     2006-05-07 12:53:36 -0700 (Sun, 07 May 2006)
ViewCVS:  http://svn.sourceforge.net/spring-rich-c/?rev=1119&view=rev

Log Message:
-----------
changes for RCP-185: add height restriction to MessageDialog

Modified Paths:
--------------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/AlertMessageAreaPane.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/MessageDialog.java

Added Paths:
-----------
    
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/dialog/MessageDialogSample.java
Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/AlertMessageAreaPane.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/AlertMessageAreaPane.java
       2006-05-07 19:27:17 UTC (rev 1118)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/AlertMessageAreaPane.java
       2006-05-07 19:53:36 UTC (rev 1119)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2004 the original author or authors.
+ * 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
@@ -39,6 +39,7 @@
 
 /**
  * MessagePane implementation used by <code>MessageDialog</code>
+ * 
  * @author Peter De Bruycker
  */
 public class AlertMessageAreaPane extends AbstractControlFactory implements 
MessagePane, PropertyChangeListener {
@@ -50,42 +51,33 @@
     private DefaultMessageAreaModel messageAreaModel;
 
     public AlertMessageAreaPane() {
-        init(this);
+        init( this );
     }
 
-    public AlertMessageAreaPane(Messagable delegate) {
-        init(delegate);
+    public AlertMessageAreaPane( Messagable delegate ) {
+        init( delegate );
     }
 
-    private void init(Messagable delegate) {
-        this.messageAreaModel = new DefaultMessageAreaModel(delegate);
-        this.messageAreaModel.addPropertyChangeListener(this);
+    private void init( Messagable delegate ) {
+        this.messageAreaModel = new DefaultMessageAreaModel( delegate );
+        this.messageAreaModel.addPropertyChangeListener( this );
 
         iconLabel = new JLabel();
         messageArea = new HtmlPane();
 
-        Font defaultFont = UIManager.getFont("Button.font");
-        String stylesheet =
-            "body {  font-family: "
-                + defaultFont.getName()
-                + "; font-size: "
-                + defaultFont.getSize()
-                + "pt;  }"
-                + "a, p, li { font-family: "
-                + defaultFont.getName()
-                + "; font-size: "
-                + defaultFont.getSize()
-                + "pt;  }";
+        Font defaultFont = UIManager.getFont( "Button.font" );
+        String stylesheet = "body {  font-family: " + defaultFont.getName() + 
"; font-size: " + defaultFont.getSize()
+                + "pt;  }" + "a, p, li { font-family: " + 
defaultFont.getName() + "; font-size: "
+                + defaultFont.getSize() + "pt;  }";
         try {
-            ((HTMLDocument) 
messageArea.getDocument()).getStyleSheet().loadRules(new 
StringReader(stylesheet), null);
+            ((HTMLDocument) 
messageArea.getDocument()).getStyleSheet().loadRules( new StringReader( 
stylesheet ), null );
+        } catch( IOException e ) {
         }
-        catch (IOException e) {
-        }
 
-        //        messageArea.setContentType("text/html");
-        GuiStandardUtils.textComponentAsLabel(messageArea);
-        messageArea.setFont(new JLabel().getFont());
-        //        messageArea.setVerticalAlignment(SwingConstants.TOP);
+        // messageArea.setContentType("text/html");
+        GuiStandardUtils.textComponentAsLabel( messageArea );
+        messageArea.setFont( new JLabel().getFont() );
+        // messageArea.setVerticalAlignment(SwingConstants.TOP);
     }
 
     public int getPreferredHeight() {
@@ -93,9 +85,9 @@
     }
 
     protected JComponent createControl() {
-        JPanel panel = new JPanel(new BorderLayout(UIConstants.TWO_SPACES, 0));
-        panel.add(iconLabel, BorderLayout.LINE_START);
-        panel.add(messageArea);
+        JPanel panel = new JPanel( new BorderLayout( UIConstants.TWO_SPACES, 0 
) );
+        panel.add( iconLabel, BorderLayout.LINE_START );
+        panel.add( messageArea );
 
         return panel;
     }
@@ -104,101 +96,101 @@
         return messageAreaModel.getMessage();
     }
 
-    public void setMessage(Message message) {
-        messageAreaModel.setMessage(message);
+    public void setMessage( Message message ) {
+        messageAreaModel.setMessage( message );
     }
 
     public boolean isMessageShowing() {
-        if (messageArea == null) {
+        if( messageArea == null ) {
             return false;
         }
-        return StringUtils.hasText(messageArea.getText()) && 
messageArea.isVisible();
+        return StringUtils.hasText( messageArea.getText() ) && 
messageArea.isVisible();
     }
 
-    public void addPropertyChangeListener(PropertyChangeListener listener) {
-        messageAreaModel.addPropertyChangeListener(listener);
+    public void addPropertyChangeListener( PropertyChangeListener listener ) {
+        messageAreaModel.addPropertyChangeListener( listener );
     }
 
-    public void addPropertyChangeListener(String propertyName, 
PropertyChangeListener listener) {
-        messageAreaModel.addPropertyChangeListener(propertyName, listener);
+    public void addPropertyChangeListener( String propertyName, 
PropertyChangeListener listener ) {
+        messageAreaModel.addPropertyChangeListener( propertyName, listener );
     }
 
-    public void removePropertyChangeListener(PropertyChangeListener listener) {
-        messageAreaModel.removePropertyChangeListener(listener);
+    public void removePropertyChangeListener( PropertyChangeListener listener 
) {
+        messageAreaModel.removePropertyChangeListener( listener );
     }
 
-    public void removePropertyChangeListener(String propertyName, 
PropertyChangeListener listener) {
-        messageAreaModel.removePropertyChangeListener(propertyName, listener);
+    public void removePropertyChangeListener( String propertyName, 
PropertyChangeListener listener ) {
+        messageAreaModel.removePropertyChangeListener( propertyName, listener 
);
     }
 
-    public void propertyChange(PropertyChangeEvent evt) {
-        update(getMessage());
+    public void propertyChange( PropertyChangeEvent evt ) {
+        update( getMessage() );
     }
 
-    private void update(Message message) {
+    private void update( Message message ) {
         String text = message.getText();
 
         // try to split it into two parts
-        String[] parts = message.getText().split("\\n");
-        if (parts.length > 1) {
+        String[] parts = message.getText().split( "\\n" );
+        if( parts.length > 1 ) {
             StringBuffer sb = new StringBuffer();
-            sb.append("<html>");
-            sb.append("<b>");
-            sb.append(parts[0]);
-            sb.append("</b>");
+            sb.append( "<html>" );
+            sb.append( "<b>" );
+            sb.append( parts[0] );
+            sb.append( "</b>" );
 
-            for (int i = 1; i < parts.length; i++) {
-                sb.append("<p>");
-                sb.append(parts[i]);
+            for( int i = 1; i < parts.length; i++ ) {
+                sb.append( "<p>" );
+                sb.append( parts[i] );
             }
 
             text = sb.toString();
         }
 
-        messageArea.setText(text);
-        iconLabel.setIcon(getIcon(message.getSeverity()));
+        messageArea.setText( text );
+        iconLabel.setIcon( getIcon( message.getSeverity() ) );
     }
 
-    private Icon getIcon(Severity severity) {
-        if (severity == Severity.ERROR) {
+    private Icon getIcon( Severity severity ) {
+        if( severity == Severity.ERROR ) {
             return getErrorIcon();
         }
-        if (severity == Severity.WARNING) {
+        if( severity == Severity.WARNING ) {
             return getWarningIcon();
         }
         return getInfoIcon();
     }
 
     private Icon getErrorIcon() {
-        if (errorIcon == null) {
-            errorIcon = UIManager.getIcon("OptionPane.errorIcon");
+        if( errorIcon == null ) {
+            errorIcon = UIManager.getIcon( "OptionPane.errorIcon" );
         }
         return errorIcon;
     }
 
-    public void setErrorIcon(Icon icon) {
+    public void setErrorIcon( Icon icon ) {
         errorIcon = icon;
     }
 
     private Icon getWarningIcon() {
-        if (warningIcon == null) {
-            warningIcon = UIManager.getIcon("OptionPane.warningIcon");
+        if( warningIcon == null ) {
+            warningIcon = UIManager.getIcon( "OptionPane.warningIcon" );
         }
         return warningIcon;
     }
 
-    public void setWarningIcon(Icon icon) {
+    public void setWarningIcon( Icon icon ) {
         warningIcon = icon;
     }
 
     private Icon getInfoIcon() {
-        if (infoIcon == null) {
-            infoIcon = UIManager.getIcon("OptionPane.informationIcon");
+        if( infoIcon == null ) {
+            infoIcon = UIManager.getIcon( "OptionPane.informationIcon" );
         }
         return infoIcon;
     }
 
-    public void setInfoIcon(Icon icon) {
+    public void setInfoIcon( Icon icon ) {
         infoIcon = icon;
     }
 }

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/MessageDialog.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/MessageDialog.java
      2006-05-07 19:27:17 UTC (rev 1118)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/dialog/MessageDialog.java
      2006-05-07 19:53:36 UTC (rev 1119)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2004 the original author or authors.
+ * 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
@@ -25,8 +25,8 @@
 import org.springframework.util.Assert;
 
 /**
- * Dialog for showing an message to the user. The severity of the message
- * is used to determine the icon.
+ * Dialog for showing an message to the user. The severity of the message is 
used to
+ * determine the icon.
  * <p>
  * If the message text contains line feeds ('\n'), the message is split into 
different
  * parts, and the first part is rendered in bold. This is to mimic the 
guidelines in
@@ -41,72 +41,77 @@
     private Message message;
 
     private float dialogScaleFactor = 0.55f;
-    
+
     /** Minimum width for the dialog, in case the scale factor results in a 
tiny value. */
     private int minimumWidth = 600;
 
     /**
      * Constructs a new dialog.
+     * 
      * @param title the title
      * @param message the message
      */
-    public MessageDialog(String title, Message message) {
-        this(title, null, message);
+    public MessageDialog( String title, Message message ) {
+        this( title, null, message );
     }
 
     /**
      * Constructs a new dialog.
+     * 
      * @param title the title
      * @param parent the parent window
      * @param message the message
      */
-    public MessageDialog(String title, Window parent, Message message) {
-        super(title, parent);
-        setMessage(message);
+    public MessageDialog( String title, Window parent, Message message ) {
+        super( title, parent );
+        setMessage( message );
     }
 
     /**
-     * Constructs a new dialog, the message is converted to an information
-     * message
+     * Constructs a new dialog, the message is converted to an information 
message
+     * 
      * @param title the title
      * @param message the message text
      */
-    public MessageDialog(String title, String message) {
-        this(title, null, message);
+    public MessageDialog( String title, String message ) {
+        this( title, null, message );
     }
 
     /**
-     * Constructs a new dialog, the message is converted to an information
-     * message
+     * Constructs a new dialog, the message is converted to an information 
message
+     * 
      * @param title the title
      * @param parent the parent window
      * @param message the message text
      */
-    public MessageDialog(String title, Window parent, String message) {
-        super(title, parent);
-        setMessage(message);
+    public MessageDialog( String title, Window parent, String message ) {
+        super( title, parent );
+        setMessage( message );
     }
 
     /**
      * Set the message text, severity is info.
+     * 
      * @param text the message text
      */
-    public void setMessage(String text) {
-        setMessage(new Message(text));
+    public void setMessage( String text ) {
+        setMessage( new Message( text ) );
     }
 
     /**
      * Set the message.
+     * 
      * @param message the message
      */
-    public void setMessage(Message message) {
-        Assert.notNull(message, "The message is required");
-        Assert.hasText(message.getText(), "The message text is required");
+    public void setMessage( Message message ) {
+        Assert.notNull( message, "The message is required" );
+        Assert.hasText( message.getText(), "The message text is required" );
         this.message = message;
     }
 
     /**
      * Get the message
+     * 
      * @return message
      */
     public Message getMessage() {
@@ -131,7 +136,7 @@
      * @see 
org.springframework.richclient.dialog.ApplicationDialog#getCommandGroupMembers()
      */
     protected Object[] getCommandGroupMembers() {
-        return new Object[] {getCancelCommand()};
+        return new Object[] { getCancelCommand() };
     }
 
     /**
@@ -139,7 +144,7 @@
      */
     protected JComponent createDialogContentPane() {
         this.messageAreaPane = new AlertMessageAreaPane();
-        this.messageAreaPane.setMessage(message);
+        this.messageAreaPane.setMessage( message );
         return messageAreaPane.getControl();
     }
 
@@ -158,27 +163,28 @@
         int width = getDialog().getWidth();
         float scale = getDialogScaleFactor();
         int parentWidth = getDialog().getParent().getWidth();
-        if (width > parentWidth * scale) {
+        if( width > parentWidth * scale ) {
             final int messageAreaPaneHeight = 
messageAreaPane.getPreferredHeight();
-            width = (int)(parentWidth * scale);
+            width = (int) (parentWidth * scale);
             if( width < getMinimumWidth() ) {
                 width = getMinimumWidth();
             }
-            
+
             // adjust the width
-            getDialog().setSize(width, getDialog().getHeight());
+            getDialog().setSize( width, getDialog().getHeight() );
 
             // dirty hack, because messageAreaPane.getPreferredHeight() 
doesn't respond
             // immediately to dialog resize when dialog is not visible
-            DialogSizeUpdater dialogSizeUpdater = new 
DialogSizeUpdater(messageAreaPaneHeight);
-            getDialog().addComponentListener(dialogSizeUpdater);
+            DialogSizeUpdater dialogSizeUpdater = new DialogSizeUpdater( 
messageAreaPaneHeight );
+            getDialog().addComponentListener( dialogSizeUpdater );
         }
-        getDialog().setResizable(false);
+        getDialog().setResizable( false );
     }
 
     /**
      * Get the scale factor for the dialog size (as compared to the parent 
window). The
      * default returned here is 55% (.55).
+     * 
      * @return scale factor
      */
     public float getDialogScaleFactor() {
@@ -187,28 +193,31 @@
 
     /**
      * Set the scale factory for the dialog size.
+     * 
      * @param dialogScaleFactor New dialog scale factor
      */
-    public void setDialogScaleFactor(float dialogScaleFactor) {
+    public void setDialogScaleFactor( float dialogScaleFactor ) {
         this.dialogScaleFactor = dialogScaleFactor;
     }
 
     /**
-     * Get the minimum width for the dialog.  This overrides the value 
calculated
-     * by the scale factor.
+     * Get the minimum width for the dialog. This overrides the value 
calculated by the
+     * scale factor.
+     * 
      * @return minimum width
      * @see #setDialogScaleFactor
      */
     public int getMinimumWidth() {
         return minimumWidth;
     }
-    
+
     /**
-     * Set the minimum width for the dialog.  This overrides the value 
calculated
-     * by the scale factor.
+     * Set the minimum width for the dialog. This overrides the value 
calculated by the
+     * scale factor.
+     * 
      * @return minimum width
      */
-    public void setMinimumWidth(int minimumWidth) {
+    public void setMinimumWidth( int minimumWidth ) {
         this.minimumWidth = minimumWidth;
     }
 
@@ -218,15 +227,15 @@
     private class DialogSizeUpdater extends ComponentAdapter {
         private final int height;
 
-        private DialogSizeUpdater(int height) {
+        private DialogSizeUpdater( int height ) {
             super();
             this.height = height;
         }
 
-        public void componentShown(ComponentEvent e) {
+        public void componentShown( ComponentEvent e ) {
             // we must also change the height
             int newHeight = getDialog().getHeight() + 
messageAreaPane.getPreferredHeight() - height;
-            getDialog().setSize(getDialog().getWidth(), newHeight);
+            getDialog().setSize( getDialog().getWidth(), newHeight );
         }
     }
 }

Added: 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/dialog/MessageDialogSample.java
===================================================================
--- 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/dialog/MessageDialogSample.java
                                (rev 0)
+++ 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/dialog/MessageDialogSample.java
        2006-05-07 19:53:36 UTC (rev 1119)
@@ -0,0 +1,74 @@
+/*
+ * 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;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import java.util.Locale;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.UIManager;
+
+import org.springframework.binding.value.support.EqualsValueChangeDetector;
+import org.springframework.context.support.StaticApplicationContext;
+import org.springframework.richclient.application.Application;
+import 
org.springframework.richclient.application.config.DefaultApplicationLifecycleAdvisor;
+
+public class MessageDialogSample {
+
+    public static void main( String[] args ) throws Exception {
+        UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
+
+        final JFrame frame = new JFrame( "test" );
+        JButton openButton = new JButton( "open dialog" );
+        final JTextArea textField = new JTextArea( 8, 40 );
+        textField.setLineWrap( true );
+        textField.setWrapStyleWord( true );
+        textField.setText( "This is the first line.\n"
+                + "This is the second line which is also much longer. "
+                + "This is to check if the linewrapping occurs correctly. "
+                + "Try resizing the frame to see how the MessageDialog 
behaves." );
+        frame.add( new JScrollPane( textField ) );
+        frame.add( openButton, BorderLayout.SOUTH );
+        frame.pack();
+
+        frame.setLocationRelativeTo( null );
+        frame.setVisible( true );
+        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
+
+        openButton.addActionListener( new ActionListener() {
+            public void actionPerformed( ActionEvent e ) {
+                MessageDialog dialog = new MessageDialog( "Message", frame, 
textField.getText() );
+                dialog.setMinimumWidth( 300 );
+                dialog.showDialog();
+            }
+        } );
+
+        // load dummy application
+        Application.load( null );
+        new Application( new DefaultApplicationLifecycleAdvisor() );
+        StaticApplicationContext applicationContext = new 
StaticApplicationContext();
+        Application.services().setApplicationContext( applicationContext );
+        Application.services().setValueChangeDetector( new 
EqualsValueChangeDetector() );
+        applicationContext.getStaticMessageSource().addMessage( 
"okCommand.label", Locale.getDefault(), "Ok" );
+        applicationContext.refresh();
+    }
+}


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

Reply via email to