KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > LogFactor5InputDialog


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.log4j.lf5.viewer;
17
18 import javax.swing.*;
19 import java.awt.*;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22 import java.awt.event.KeyAdapter JavaDoc;
23 import java.awt.event.KeyEvent JavaDoc;
24
25 /**
26  * LogFactor5InputDialog
27  *
28  * Creates a popup input dialog box so that users can enter
29  * a URL to open a log file from.
30  *
31  * @author Richard Hurst
32  * @author Brad Marlborough
33  */

34
35 // Contributed by ThoughtWorks Inc.
36

37 public class LogFactor5InputDialog extends LogFactor5Dialog {
38   //--------------------------------------------------------------------------
39
// Constants:
40
//--------------------------------------------------------------------------
41
public static final int SIZE = 30;
42   //--------------------------------------------------------------------------
43
// Protected Variables:
44
//--------------------------------------------------------------------------
45

46   //--------------------------------------------------------------------------
47
// Private Variables:
48
//--------------------------------------------------------------------------
49
private JTextField _textField;
50   //--------------------------------------------------------------------------
51
// Constructors:
52
//--------------------------------------------------------------------------
53

54   /**
55    * Configures an input dialog box using a defualt size for the text field.
56    * param jframe the frame where the dialog will be loaded from.
57    * param title the title of the dialog box.
58    * param label the label to be put in the dialog box.
59    */

60   public LogFactor5InputDialog(JFrame jframe, String JavaDoc title, String JavaDoc label) {
61     this(jframe, title, label, SIZE);
62   }
63
64   /**
65    * Configures an input dialog box.
66    * param jframe the frame where the dialog will be loaded from.
67    * param title the title of the dialog box.
68    * param label the label to be put in the dialog box.
69    * param size the size of the text field.
70    */

71   public LogFactor5InputDialog(JFrame jframe, String JavaDoc title, String JavaDoc label,
72       int size) {
73     super(jframe, title, true);
74
75     JPanel bottom = new JPanel();
76     bottom.setLayout(new FlowLayout());
77
78     JPanel main = new JPanel();
79     main.setLayout(new FlowLayout());
80     main.add(new JLabel(label));
81     _textField = new JTextField(size);
82     main.add(_textField);
83
84     addKeyListener(new KeyAdapter JavaDoc() {
85       public void keyPressed(KeyEvent JavaDoc e) {
86         if (e.getKeyCode() == KeyEvent.VK_ENTER) {
87           hide();
88         }
89       }
90     });
91
92     JButton ok = new JButton("Ok");
93     ok.addActionListener(new ActionListener JavaDoc() {
94       public void actionPerformed(ActionEvent JavaDoc e) {
95         hide();
96       }
97     });
98
99     JButton cancel = new JButton("Cancel");
100     cancel.addActionListener(new ActionListener JavaDoc() {
101       public void actionPerformed(ActionEvent JavaDoc e) {
102         hide();
103         // set the text field to blank just in case
104
// a file was selected before the Cancel
105
// button was pressed.
106
_textField.setText("");
107       }
108     });
109
110     bottom.add(ok);
111     bottom.add(cancel);
112     getContentPane().add(main, BorderLayout.CENTER);
113     getContentPane().add(bottom, BorderLayout.SOUTH);
114     pack();
115     centerWindow(this);
116     show();
117   }
118
119   //--------------------------------------------------------------------------
120
// Public Methods:
121
//--------------------------------------------------------------------------
122
public String JavaDoc getText() {
123     String JavaDoc s = _textField.getText();
124
125     if (s != null && s.trim().length() == 0) {
126       return null;
127     }
128
129     return s;
130
131   }
132
133   //--------------------------------------------------------------------------
134
// Protected Methods:
135
//--------------------------------------------------------------------------
136

137   //--------------------------------------------------------------------------
138
// Private Methods:
139
//--------------------------------------------------------------------------
140

141   //--------------------------------------------------------------------------
142
// Nested Top-Level Classes or Interfaces
143
//--------------------------------------------------------------------------
144
}
Popular Tags