1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }