1   /*
2    * Copyright 2002-2006 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.springframework.richclient.dialog;
17  
18  import java.awt.BorderLayout;
19  import java.awt.event.ActionEvent;
20  import java.awt.event.ActionListener;
21  import java.util.Locale;
22  
23  import javax.swing.JButton;
24  import javax.swing.JFrame;
25  import javax.swing.JScrollPane;
26  import javax.swing.JTextArea;
27  import javax.swing.UIManager;
28  
29  import org.springframework.context.support.StaticApplicationContext;
30  import org.springframework.richclient.application.Application;
31  import org.springframework.richclient.application.config.DefaultApplicationLifecycleAdvisor;
32  
33  public class MessageDialogSample {
34  
35      public static void main( String[] args ) throws Exception {
36          UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
37  
38          final JFrame frame = new JFrame( "test" );
39          JButton openButton = new JButton( "open dialog" );
40          final JTextArea textField = new JTextArea( 8, 40 );
41          textField.setLineWrap( true );
42          textField.setWrapStyleWord( true );
43          textField.setText( "This is the first line.\n"
44                  + "This is the second line which is also much longer. "
45                  + "This is to check if the linewrapping occurs correctly. "
46                  + "Try resizing the frame to see how the MessageDialog behaves." );
47          frame.add( new JScrollPane( textField ) );
48          frame.add( openButton, BorderLayout.SOUTH );
49          frame.pack();
50  
51          frame.setLocationRelativeTo( null );
52          frame.setVisible( true );
53          frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
54  
55          openButton.addActionListener( new ActionListener() {
56              public void actionPerformed( ActionEvent e ) {
57                  MessageDialog dialog = new MessageDialog( "Message", frame, textField.getText() );
58                  dialog.setMinimumWidth( 300 );
59                  dialog.showDialog();
60              }
61          } );
62  
63          // load dummy application
64          Application.load( null );
65          new Application( new DefaultApplicationLifecycleAdvisor() );
66          StaticApplicationContext applicationContext = new StaticApplicationContext();
67          Application.instance().setApplicationContext( applicationContext );
68          applicationContext.getStaticMessageSource().addMessage( "okCommand.label", Locale.getDefault(), "Ok" );
69          applicationContext.refresh();
70      }
71  }