/*
* Copyright (C) 2001, 2002 Robert MacGrogan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* $Archive: SourceJammer$
* $FileName: ArchivePropsDialog.java$
* $FileID: 4163$
*
* Last change:
* $AuthorName: Rob MacGrogan$
* $Date: 8/10/03 1:39 AM$
* $Comment: Use new SourceJammerClient propery names.$
*/
package org.sourcejammer.client.gui.dialog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import org.sourcejammer.project.view.ArchiveProperties;
import org.sourcejammer.client.DisplayTextLibrary;
import org.sourcejammer.client.gui.GuiUtil;
import org.sourcejammer.client.gui.CommandCentral;
import org.sourcejammer.client.gui.GJApp;
/**
* Title: $FileName: ArchivePropsDialog.java$<br>
* @author $AuthorName: Rob MacGrogan$<br>
* @version $VerNum: 3$<br><br>
*
* $Description: $<br>
* $KeyWordsOff: $<br><br>
*/
public class ArchivePropsDialog extends SJDialog {
private ArchiveProperties props = null;
private JCheckBox jIsRestricted = null;
private JCheckBox jKeywordsEnabled = null;
private JTextArea jExtensions = null;
private ArchivePropsDialog dialog = null;
private int buttonClicked = ClickValues.DIALOG_CLOSED;
public ArchivePropsDialog(JFrame owner, ArchiveProperties props) {
super(owner);
this.props = props;
initializeDialog(owner);
}
public int getButtonClicked() {
return buttonClicked;
}
public ArchiveProperties getArchiveProperties() {
ArchiveProperties props = new ArchiveProperties();
props.setExpansionExtensions(jExtensions.getText());
props.setKeywordsEnabled(jKeywordsEnabled.isSelected());
props.setRestricted(jIsRestricted.isSelected());
//Archive root is read-only, so . . .
props.setArchiveRoot(this.props.getArchiveRoot());
return props;
}
private void initializeDialog(JFrame owner) {
dialog = this;
getContentPane().setLayout(new BorderLayout());
setTitle("SourceJammer");
JPanel north = new JPanel();
north.add(buildLabel());
JPanel top = buildArchiveRootDisplay();
JPanel center = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
GuiUtil.setConstraints(gbc, 0, 0, 1, 1, 0, 8, GridBagConstraints.NONE, GridBagConstraints.WEST);
center.add(top, gbc);
GuiUtil.setConstraints(gbc, 0, 1, 1, 1, 0, 8, GridBagConstraints.NONE, GridBagConstraints.WEST);
center.add(buildRestrictedCheckbox(), gbc);
GuiUtil.setConstraints(gbc, 0, 2, 1, 5, 0, 8, GridBagConstraints.NONE, GridBagConstraints.WEST);
center.add(buildKeywordsPanel(), gbc);
JPanel buttonPanel = buildButtonPanel();
getContentPane().add(north, BorderLayout.NORTH);
getContentPane().add(center, BorderLayout.CENTER);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
}
public void showDialog(Component c) {
this.setModal(true);
this.pack();
this.setLocationRelativeTo(c);
this.show();
}
private JLabel buildLabel() {
return new JLabel(
DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_ARCHIVE_PROPS)
+ " "
+ CommandCentral.getInstance().getArchiveName());
}
private JPanel buildArchiveRootDisplay() {
JLabel lbl = new JLabel(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_ARCHIVE_ROOT_PATH) + ":");
JTextField fld = new JTextField();
fld.setText(props.getArchiveRoot());
fld.setEditable(false);
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
GuiUtil.setConstraints(gbc, 0, 0, 1, 1, 0, 2, GridBagConstraints.NONE, GridBagConstraints.WEST);
panel.add(lbl, gbc);
GuiUtil.setConstraints(gbc, 0, 1, 1, 1, 0, 2, GridBagConstraints.NONE, GridBagConstraints.WEST);
panel.add(fld, gbc);
return panel;
}
private JPanel buildKeywordsPanel() {
buildExtensionsArea();
buildKeywordsEnabledCheckbox();
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(jKeywordsEnabled, BorderLayout.NORTH);
JScrollPane scroller = new JScrollPane(jExtensions);
scroller.setMinimumSize(new Dimension(50, 50));
scroller.setPreferredSize(new Dimension(50, 50));
panel.add(scroller, BorderLayout.CENTER);
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
return panel;
}
private JCheckBox buildRestrictedCheckbox() {
jIsRestricted = new JCheckBox(DisplayTextLibrary.displayText(DisplayTextLibrary.OPT_ARCH_RESTRICTED));
jIsRestricted.setSelected(props.isRestricted());
return jIsRestricted;
}
private JCheckBox buildKeywordsEnabledCheckbox() {
jKeywordsEnabled = new JCheckBox(DisplayTextLibrary.displayText(DisplayTextLibrary.OPT_KEYWORDS_ENABLED));
jKeywordsEnabled.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent event) {
if (jKeywordsEnabled.isSelected()) {
jExtensions.setEnabled(true);
}
else {
jExtensions.setEnabled(false);
}
}
} //end anon class
);
jKeywordsEnabled.setSelected(props.isKeywordsEnabled());
return jKeywordsEnabled;
}
private JTextArea buildExtensionsArea() {
jExtensions = new JTextArea();
jExtensions.setText(props.getExpansionExtensions());
if (!props.isKeywordsEnabled()) {
jExtensions.setEnabled(false);
}
return jExtensions;
}
private JPanel buildButtonPanel() {
JPanel panel = new JPanel();
JButton btnOK = buildOKButton();
JButton btnCancel = buildCancelButton();
panel.add(btnOK);
panel.add(btnCancel);
return panel;
}
private JButton buildOKButton() {
JButton btn = new JButton(DisplayTextLibrary.displayText(DisplayTextLibrary.BTN_OK));
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
buttonClicked = ClickValues.OK_BUTTON_CLICKED;
dialog.dispose();
}
} //end anon class
);
return btn;
}
private JButton buildCancelButton() {
JButton btn = new JButton(DisplayTextLibrary.displayText(DisplayTextLibrary.BTN_CANCEL));
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
buttonClicked = ClickValues.CANCEL_BUTTON_CLICKED;
dialog.dispose();
}
} //end anon class
);
return btn;
}
//For testing.
private static JFrame testFrame = null;
public static void main(String[] args) {
try {
String sConfPath = args[0];
org.sourcejammer.util.AppConfig.getInstance(sConfPath);
org.sourcejammer.client.SourceJammerClient client =
org.sourcejammer.client.SourceJammerClient.getInstance(sConfPath);
DisplayTextLibrary.initializeInstance(client.getDisplayTextPropertiesFileName());
testFrame = new JFrame();
JButton button = new JButton("View dialog.");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
ArchiveProperties props = new ArchiveProperties();
props.setArchiveRoot("C:\\SourceJammer\\server\\archives");
props.setExpansionExtensions("java sql xml");
props.setKeywordsEnabled(true);
props.setRestricted(true);
ArchivePropsDialog dialog = new ArchivePropsDialog(testFrame, props);
dialog.showDialog(testFrame);
}
});
testFrame.getContentPane().add(button);
GJApp.launch(testFrame, "test", 200, 200, 800, 500);
}
catch (Throwable thr) {
thr.printStackTrace();
}
}
}
|