KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > just4log > integration > gui > Just4LogGui


1 /*
2  * ============================================================================
3  * The Apache Software License, Version 1.1
4  * ============================================================================
5  *
6  * Copyright (C) 2000-2003 Lucas Bruand. All
7  * rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modifica-
10  * tion, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if any, must
20  * include the following acknowledgment: "This product includes software
21  * developed by the Apache Software Foundation (http://www.apache.org/)."
22  * Alternately, this acknowledgment may appear in the software itself, if
23  * and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "Just4Log" and "Apache Software Foundation" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * apache@apache.org.
29  *
30  * 5. Products derived from this software may not be called "Apache", nor may
31  * "Apache" appear in their name, without prior written permission of the
32  * Apache Software Foundation.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  *
45  * This software consists of voluntary contributions made by many individuals
46  * on behalf of the Apache Software Foundation. For more information on the
47  * Apache Software Foundation, please see <http://www.apache.org/>.
48  *
49  */

50
51 package net.sf.just4log.integration.gui;
52
53 import java.awt.BorderLayout JavaDoc;
54 import java.awt.GridBagConstraints JavaDoc;
55 import java.awt.GridBagLayout JavaDoc;
56 import java.awt.event.ActionEvent JavaDoc;
57 import java.awt.event.ActionListener JavaDoc;
58 import java.awt.event.WindowAdapter JavaDoc;
59 import java.awt.event.WindowEvent JavaDoc;
60 import java.io.File JavaDoc;
61
62 import javax.swing.JButton JavaDoc;
63 import javax.swing.JComponent JavaDoc;
64 import javax.swing.JFileChooser JavaDoc;
65 import javax.swing.JFrame JavaDoc;
66 import javax.swing.JLabel JavaDoc;
67 import javax.swing.JPanel JavaDoc;
68 import javax.swing.JTextField JavaDoc;
69
70 import org.apache.commons.logging.Log;
71 import org.apache.commons.logging.LogFactory;
72
73 /**
74  * @author Lucas Bruand
75  * @version $Id: Just4LogGui.java,v 1.2 2003/07/20 18:02:39 lbruand Exp $
76  */

77
78 public class Just4LogGui {
79     public static final String JavaDoc CLASSID =
80         "$Id: Just4LogGui.java,v 1.2 2003/07/20 18:02:39 lbruand Exp $";
81     private static Log logger = LogFactory.getLog(Just4LogGui.class);
82     private static JFrame JavaDoc frame;
83     JTextField JavaDoc source;
84     JTextField JavaDoc target;
85     JButton JavaDoc srcbutton;
86     JButton JavaDoc targetbutton;
87     JButton JavaDoc runbutton;
88     JLabel JavaDoc infolabel;
89     JFileChooser JavaDoc sourcefc;
90     JFileChooser JavaDoc targetfc;
91     /**
92      *
93      */

94     public Just4LogGui() {
95         super();
96     }
97
98     public static void main(String JavaDoc[] args) {
99         logger.info("Building up GUI");
100         frame = new JFrame JavaDoc("Just4Log");
101         Just4LogGui app = new Just4LogGui();
102
103         JComponent JavaDoc contents = app.createComponents();
104         frame.getContentPane().add(contents, BorderLayout.CENTER);
105
106         frame.addWindowListener(new WindowAdapter JavaDoc() {
107             public void windowClosing(WindowEvent JavaDoc e) {
108                 System.exit(0);
109             }
110         });
111
112         frame.pack();
113         logger.info("Starting GUI");
114         frame.setVisible(true);
115     }
116
117     /**
118      *
119      */

120
121     private static final int FILEFIELDSIZE = 20;
122     private JComponent JavaDoc createComponents() {
123         sourcefc = new JFileChooser JavaDoc();
124         sourcefc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
125         targetfc = new JFileChooser JavaDoc();
126         targetfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
127
128         GridBagConstraints JavaDoc constraint;
129
130         JPanel JavaDoc pane = new JPanel JavaDoc();
131         pane.setLayout(new GridBagLayout JavaDoc());
132
133         JLabel JavaDoc srclbl = new JLabel JavaDoc("Source file/dir:");
134         constraint = new GridBagConstraints JavaDoc();
135         constraint.gridx = 0;
136         constraint.gridy = 0;
137         pane.add(srclbl, constraint);
138
139         source = new JTextField JavaDoc(FILEFIELDSIZE);
140         constraint = new GridBagConstraints JavaDoc();
141         constraint.gridx = 1;
142         constraint.gridy = 0;
143         pane.add(source, constraint);
144
145         srcbutton = new JButton JavaDoc("Choose");
146         constraint = new GridBagConstraints JavaDoc();
147         constraint.gridx = 2;
148         constraint.gridy = 0;
149         pane.add(srcbutton, constraint);
150
151         srcbutton.addActionListener(new ActionListener JavaDoc() {
152             public void actionPerformed(ActionEvent JavaDoc evt) {
153                 srcbuttonActionPerformed(evt);
154             }
155         });
156
157         JLabel JavaDoc targetlbl = new JLabel JavaDoc("Target file/dir:");
158         constraint = new GridBagConstraints JavaDoc();
159         constraint.gridx = 0;
160         constraint.gridy = 1;
161         pane.add(targetlbl, constraint);
162
163         target = new JTextField JavaDoc(FILEFIELDSIZE);
164         constraint = new GridBagConstraints JavaDoc();
165         constraint.gridx = 1;
166         constraint.gridy = 1;
167         pane.add(target, constraint);
168
169         targetbutton = new JButton JavaDoc("Choose");
170         constraint = new GridBagConstraints JavaDoc();
171         constraint.gridx = 2;
172         constraint.gridy = 1;
173         pane.add(targetbutton, constraint);
174         targetbutton.addActionListener(new ActionListener JavaDoc() {
175             public void actionPerformed(ActionEvent JavaDoc evt) {
176                 targetbuttonActionPerformed(evt);
177             }
178         });
179
180         infolabel = new JLabel JavaDoc("text");
181         constraint.gridx = 0;
182         constraint.gridy = 2;
183         constraint.gridwidth = 2;
184         pane.add(infolabel, constraint);
185
186         runbutton = new JButton JavaDoc("Run!");
187         constraint.gridx = 2;
188         constraint.gridy = 2;
189         pane.add(runbutton, constraint);
190         runbutton.addActionListener(new ActionListener JavaDoc() {
191             public void actionPerformed(ActionEvent JavaDoc evt) {
192                 runbuttonActionPerformed(evt);
193             }
194         });
195         return pane;
196
197     }
198
199     /**
200      * @param evt
201      */

202     protected void runbuttonActionPerformed(ActionEvent JavaDoc evt) {
203         
204         runbutton.setText("Stop");
205         runbutton.repaint();
206     }
207
208     /**
209      * @param evt
210      */

211     private void targetbuttonActionPerformed(ActionEvent JavaDoc evt) {
212         int returnVal = targetfc.showOpenDialog(frame);
213
214         if (returnVal == JFileChooser.APPROVE_OPTION) {
215             File JavaDoc file = targetfc.getSelectedFile();
216             target.setText(file.toString());
217             logger.info("Opening: " + file.getName() + ".");
218         } else {
219             logger.warn("Open command cancelled by user.");
220         }
221
222     }
223
224     private void srcbuttonActionPerformed(ActionEvent JavaDoc evt) {
225         int returnVal = sourcefc.showOpenDialog(frame);
226
227                 if (returnVal == JFileChooser.APPROVE_OPTION) {
228                     File JavaDoc file = sourcefc.getSelectedFile();
229                     source.setText(file.toString());
230                     logger.info("Opening: " + file.getName() + ".");
231                 } else {
232                     logger.warn("Open command cancelled by user.");
233                 }
234     }
235 }
236
Popular Tags