1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.lf5.viewer;
18
19 import javax.swing.*;
20 import java.awt.*;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.awt.event.KeyAdapter;
24 import java.awt.event.KeyEvent;
25
26 /***
27 * LogFactor5InputDialog
28 *
29 * Creates a popup input dialog box so that users can enter
30 * a URL to open a log file from.
31 *
32 * @author Richard Hurst
33 * @author Brad Marlborough
34 */
35
36
37
38 public class LogFactor5InputDialog extends LogFactor5Dialog {
39
40
41
42 public static final int SIZE = 30;
43
44
45
46
47
48
49
50 private JTextField _textField;
51
52
53
54
55 /***
56 * Configures an input dialog box using a defualt size for the text field.
57 * param jframe the frame where the dialog will be loaded from.
58 * param title the title of the dialog box.
59 * param label the label to be put in the dialog box.
60 */
61 public LogFactor5InputDialog(JFrame jframe, String title, String label) {
62 this(jframe, title, label, SIZE);
63 }
64
65 /***
66 * Configures an input dialog box.
67 * param jframe the frame where the dialog will be loaded from.
68 * param title the title of the dialog box.
69 * param label the label to be put in the dialog box.
70 * param size the size of the text field.
71 */
72 public LogFactor5InputDialog(JFrame jframe, String title, String label,
73 int size) {
74 super(jframe, title, true);
75
76 JPanel bottom = new JPanel();
77 bottom.setLayout(new FlowLayout());
78
79 JPanel main = new JPanel();
80 main.setLayout(new FlowLayout());
81 main.add(new JLabel(label));
82 _textField = new JTextField(size);
83 main.add(_textField);
84
85 addKeyListener(new KeyAdapter() {
86 public void keyPressed(KeyEvent e) {
87 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
88 hide();
89 }
90 }
91 });
92
93 JButton ok = new JButton("Ok");
94 ok.addActionListener(new ActionListener() {
95 public void actionPerformed(ActionEvent e) {
96 hide();
97 }
98 });
99
100 JButton cancel = new JButton("Cancel");
101 cancel.addActionListener(new ActionListener() {
102 public void actionPerformed(ActionEvent e) {
103 hide();
104
105
106
107 _textField.setText("");
108 }
109 });
110
111 bottom.add(ok);
112 bottom.add(cancel);
113 getContentPane().add(main, BorderLayout.CENTER);
114 getContentPane().add(bottom, BorderLayout.SOUTH);
115 pack();
116 centerWindow(this);
117 show();
118 }
119
120
121
122
123 public String getText() {
124 String s = _textField.getText();
125
126 if (s != null && s.trim().length() == 0) {
127 return null;
128 }
129
130 return s;
131
132 }
133
134
135
136
137
138
139
140
141
142
143
144
145 }