001: /*
002: * Gruntspud
003: *
004: * Copyright (C) 2002 Brett Smith.
005: *
006: * Written by: Brett Smith <t_magicthize@users.sourceforge.net>
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public License
010: * as published by the Free Software Foundation; either version 2 of
011: * the License, or (at your option) any later version.
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Library General Public License for more details.
016: *
017: * You should have received a copy of the GNU Library General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: */
021:
022: package gruntspud.connection.local;
023:
024: import gruntspud.ResourceUtil;
025: import gruntspud.connection.ConnectionProfile;
026: import gruntspud.ui.FileNameTextField;
027: import gruntspud.ui.UIUtil;
028: import gruntspud.ui.XTextField;
029: import gruntspud.ui.preferences.AbstractAdditionalOptionsPane;
030:
031: import java.awt.GridBagConstraints;
032: import java.awt.GridBagLayout;
033: import java.awt.Insets;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036: import java.io.File;
037: import java.util.Locale;
038: import java.util.ResourceBundle;
039:
040: import javax.swing.JButton;
041: import javax.swing.JFileChooser;
042: import javax.swing.JLabel;
043:
044: /**
045: * A <strong>:local</strong> connection is similar to <strong>:ext</strong> except it
046: * assumes the CVS command is avaiable locally. This class provides a component for
047: * any additioanl arguments to the command that might be required.
048: *
049: * @author magicthize
050: */
051: public class AdditionalLocalConnectionOptions extends
052: AbstractAdditionalOptionsPane implements ActionListener {
053: // Private instance variables
054: static ResourceBundle res = ResourceBundle.getBundle(
055: "gruntspud.connection.local.ResourceBundle", Locale
056: .getDefault(),
057: AdditionalLocalConnectionOptions.class.getClassLoader());
058: private XTextField alternativeCVSCommand;
059: private ConnectionProfile profile;
060: private JButton browse;
061:
062: /**
063: * Constructor for the AdditionalLocalConnectionOptions object
064: */
065: public AdditionalLocalConnectionOptions() {
066: setLayout(new GridBagLayout());
067:
068: GridBagConstraints gbc = new GridBagConstraints();
069: gbc.insets = new Insets(3, 3, 3, 3);
070: gbc.anchor = GridBagConstraints.NORTHWEST;
071: gbc.fill = GridBagConstraints.HORIZONTAL;
072:
073: gbc.weighty = 1.0;
074: UIUtil
075: .jGridBagAdd(
076: this ,
077: new JLabel(
078: res
079: .getString("additionalLocalConnectionOptions.alternativeCVS.text")),
080: gbc, 1);
081: gbc.weightx = 1.0;
082: UIUtil.jGridBagAdd(this ,
083: alternativeCVSCommand = new FileNameTextField(null, "",
084: 15, true, true), gbc,
085: GridBagConstraints.RELATIVE);
086: gbc.weightx = 0.0;
087: UIUtil
088: .jGridBagAdd(
089: this ,
090: browse = new JButton(
091: res
092: .getString("additionalLocalConnectionOptions.browse.text")),
093: gbc, GridBagConstraints.RELATIVE);
094: browse.setMnemonic(ResourceUtil.getResourceMnemonic(res,
095: "additionalLocalConnectionOptions.browse.mnemonic"));
096: browse.addActionListener(this );
097: }
098:
099: public void actionPerformed(ActionEvent evt) {
100: if (evt.getSource() == browse) {
101: File f = new File(alternativeCVSCommand.getText()
102: .equals("") ? System.getProperty("user.dir")
103: : alternativeCVSCommand.getText());
104: JFileChooser chooser = new JFileChooser(f);
105: chooser.setSelectedFile(f);
106: chooser.setDialogTitle("Choose application ..");
107: chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
108:
109: if (chooser.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
110: String s = chooser.getSelectedFile().getAbsolutePath();
111: alternativeCVSCommand.setText("\"" + s + "\"");
112: }
113: }
114: }
115:
116: /* (non-Javadoc)
117: * @see gruntspud.ui.preferences.AbstractAdditionalOptionsPane#setProfile(gruntspud.connection.ConnectionProfile)
118: */
119: public void setProfile(ConnectionProfile profile) {
120: this .profile = profile;
121: alternativeCVSCommand
122: .setText(profile
123: .getProperty(
124: CVSRootLocalConnection.PROFILE_PROPERTY_ALTERNATIVE_CVS_COMMAND,
125: "cvs"));
126: }
127:
128: /* (non-Javadoc)
129: * @see gruntspud.ui.preferences.AbstractAdditionalOptionsPane#validateOptions()
130: */
131: public boolean validateOptions() {
132: if (profile == null) {
133: return false;
134: }
135:
136: return true;
137: }
138:
139: /* (non-Javadoc)
140: * @see gruntspud.ui.preferences.AbstractAdditionalOptionsPane#applyOptions()
141: */
142: public void applyOptions() {
143: profile
144: .setProperty(
145: CVSRootLocalConnection.PROFILE_PROPERTY_ALTERNATIVE_CVS_COMMAND,
146: alternativeCVSCommand.getText());
147: }
148: }
|