source: osm/applications/editors/josm/plugins/surveyor/src/test/DialogTest.java@ 2948

Last change on this file since 2948 was 2948, checked in by christofd, 18 years ago

moved test code

File size: 3.4 KB
Line 
1/**
2 *
3 */
4package test;
5
6import java.awt.BorderLayout;
7import java.awt.event.KeyEvent;
8import java.awt.event.KeyListener;
9import java.beans.PropertyChangeEvent;
10import java.beans.PropertyChangeListener;
11
12import javax.swing.JDialog;
13import javax.swing.JFrame;
14import javax.swing.JLabel;
15import javax.swing.JOptionPane;
16import javax.swing.JTextField;
17
18import at.dallermassl.josm.plugin.surveyor.MetaAction;
19
20/**
21 * @author cdaller
22 *
23 */
24public class DialogTest {
25
26 public void openDialog(JFrame frame) {
27
28 JTextField textField = new JTextField(10);
29
30 //Create an array of the text and components to be displayed.
31 String msgString1 = "What was Dr. SEUSS's real last name?";
32 String msgString2 = "(The answer is .)";
33 Object[] array = {msgString1, msgString2, textField};
34
35 //Create an array specifying the number of dialog buttons
36 //and their text.
37 Object[] options = {"button1", "button2"};
38
39 //Create the JOptionPane.
40 final JOptionPane optionPane = new JOptionPane(array,
41 JOptionPane.QUESTION_MESSAGE,
42 JOptionPane.YES_NO_OPTION,
43 null,
44 options,
45 options[0]);
46
47// final JOptionPane optionPane = new JOptionPane("The only way to close this dialog is by\n"
48// + "pressing one of the following buttons.\n" + "Do you understand?",
49// JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
50
51
52 final JDialog dialog = new JDialog(frame, "Click a button", true);
53 DialogClosingThread closer = new DialogClosingThread(dialog);
54 closer.observe(textField);
55 dialog.setContentPane(optionPane);
56 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
57 public void propertyChange(PropertyChangeEvent e) {
58 String prop = e.getPropertyName();
59
60 if (dialog.isVisible() && (e.getSource() == optionPane)
61 && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
62 // If you were going to check something
63 // before closing the window, you'd do
64 // it here.
65 dialog.setVisible(false);
66 }
67 }
68 });
69 closer.start();
70 dialog.pack();
71 dialog.setVisible(true);
72
73
74 System.out.println("value: " + optionPane.getValue());
75
76// int value = ((Integer) optionPane.getValue()).intValue();
77// if (value == JOptionPane.YES_OPTION) {
78// System.out.println("yes");
79// } else if (value == JOptionPane.NO_OPTION) {
80// System.out.println("no");
81// }
82
83 }
84
85 public static void main(String[] args) {
86 //1. Create the frame.
87 JFrame frame = new JFrame("FrameDemo");
88
89 //2. Optional: What happens when the frame closes?
90 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
91
92 //3. Create components and put them in the frame.
93 //...create emptyLabel...
94 frame.getContentPane().add(new JLabel("test"), BorderLayout.CENTER);
95
96 //4. Size the frame.
97 frame.pack();
98 frame.setSize(600,400);
99 frame.setLocation(0,0);
100
101 //5. Show it.
102 frame.setVisible(true);
103 new DialogTest().openDialog(frame);
104 }
105}
Note: See TracBrowser for help on using the repository browser.