/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 2000-2003 Lucas Bruand. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Just4Log" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package net.sf.just4log.integration.gui;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Lucas Bruand
* @version $Id: Just4LogGui.java,v 1.2 2003/07/20 18:02:39 lbruand Exp $
*/
public class Just4LogGui {
public static final String CLASSID =
"$Id: Just4LogGui.java,v 1.2 2003/07/20 18:02:39 lbruand Exp $";
private static Log logger = LogFactory.getLog(Just4LogGui.class);
private static JFrame frame;
JTextField source;
JTextField target;
JButton srcbutton;
JButton targetbutton;
JButton runbutton;
JLabel infolabel;
JFileChooser sourcefc;
JFileChooser targetfc;
/**
*
*/
public Just4LogGui() {
super();
}
public static void main(String[] args) {
logger.info("Building up GUI");
frame = new JFrame("Just4Log");
Just4LogGui app = new Just4LogGui();
JComponent contents = app.createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
logger.info("Starting GUI");
frame.setVisible(true);
}
/**
*
*/
private static final int FILEFIELDSIZE = 20;
private JComponent createComponents() {
sourcefc = new JFileChooser();
sourcefc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
targetfc = new JFileChooser();
targetfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
GridBagConstraints constraint;
JPanel pane = new JPanel();
pane.setLayout(new GridBagLayout());
JLabel srclbl = new JLabel("Source file/dir:");
constraint = new GridBagConstraints();
constraint.gridx = 0;
constraint.gridy = 0;
pane.add(srclbl, constraint);
source = new JTextField(FILEFIELDSIZE);
constraint = new GridBagConstraints();
constraint.gridx = 1;
constraint.gridy = 0;
pane.add(source, constraint);
srcbutton = new JButton("Choose");
constraint = new GridBagConstraints();
constraint.gridx = 2;
constraint.gridy = 0;
pane.add(srcbutton, constraint);
srcbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
srcbuttonActionPerformed(evt);
}
});
JLabel targetlbl = new JLabel("Target file/dir:");
constraint = new GridBagConstraints();
constraint.gridx = 0;
constraint.gridy = 1;
pane.add(targetlbl, constraint);
target = new JTextField(FILEFIELDSIZE);
constraint = new GridBagConstraints();
constraint.gridx = 1;
constraint.gridy = 1;
pane.add(target, constraint);
targetbutton = new JButton("Choose");
constraint = new GridBagConstraints();
constraint.gridx = 2;
constraint.gridy = 1;
pane.add(targetbutton, constraint);
targetbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
targetbuttonActionPerformed(evt);
}
});
infolabel = new JLabel("text");
constraint.gridx = 0;
constraint.gridy = 2;
constraint.gridwidth = 2;
pane.add(infolabel, constraint);
runbutton = new JButton("Run!");
constraint.gridx = 2;
constraint.gridy = 2;
pane.add(runbutton, constraint);
runbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
runbuttonActionPerformed(evt);
}
});
return pane;
}
/**
* @param evt
*/
protected void runbuttonActionPerformed(ActionEvent evt) {
runbutton.setText("Stop");
runbutton.repaint();
}
/**
* @param evt
*/
private void targetbuttonActionPerformed(ActionEvent evt) {
int returnVal = targetfc.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = targetfc.getSelectedFile();
target.setText(file.toString());
logger.info("Opening: " + file.getName() + ".");
} else {
logger.warn("Open command cancelled by user.");
}
}
private void srcbuttonActionPerformed(ActionEvent evt) {
int returnVal = sourcefc.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = sourcefc.getSelectedFile();
source.setText(file.toString());
logger.info("Opening: " + file.getName() + ".");
} else {
logger.warn("Open command cancelled by user.");
}
}
}