001    /*
002     * Copyright 2002-2006 the original author or authors.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.richclient.dialog;
017    
018    import java.awt.BorderLayout;
019    import java.awt.event.ActionEvent;
020    import java.awt.event.ActionListener;
021    import java.util.Locale;
022    
023    import javax.swing.JButton;
024    import javax.swing.JFrame;
025    import javax.swing.JScrollPane;
026    import javax.swing.JTextArea;
027    import javax.swing.UIManager;
028    
029    import org.springframework.context.support.StaticApplicationContext;
030    import org.springframework.richclient.application.Application;
031    import org.springframework.richclient.application.config.DefaultApplicationLifecycleAdvisor;
032    
033    public class MessageDialogSample {
034    
035        public static void main( String[] args ) throws Exception {
036            UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
037    
038            final JFrame frame = new JFrame( "test" );
039            JButton openButton = new JButton( "open dialog" );
040            final JTextArea textField = new JTextArea( 8, 40 );
041            textField.setLineWrap( true );
042            textField.setWrapStyleWord( true );
043            textField.setText( "This is the first line.\n"
044                    + "This is the second line which is also much longer. "
045                    + "This is to check if the linewrapping occurs correctly. "
046                    + "Try resizing the frame to see how the MessageDialog behaves." );
047            frame.add( new JScrollPane( textField ) );
048            frame.add( openButton, BorderLayout.SOUTH );
049            frame.pack();
050    
051            frame.setLocationRelativeTo( null );
052            frame.setVisible( true );
053            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
054    
055            openButton.addActionListener( new ActionListener() {
056                public void actionPerformed( ActionEvent e ) {
057                    MessageDialog dialog = new MessageDialog( "Message", frame, textField.getText() );
058                    dialog.setMinimumWidth( 300 );
059                    dialog.showDialog();
060                }
061            } );
062    
063            // load dummy application
064            Application.load( null );
065            new Application( new DefaultApplicationLifecycleAdvisor() );
066            StaticApplicationContext applicationContext = new StaticApplicationContext();
067            Application.instance().setApplicationContext( applicationContext );
068            applicationContext.getStaticMessageSource().addMessage( "okCommand.label", Locale.getDefault(), "Ok" );
069            applicationContext.refresh();
070        }
071    }