001: /*
002: * $RCSfile: PreferencesProjectPanel.java,v $
003: * @modification $Date: 2001/09/28 19:35:30 $
004: * @version $Id: PreferencesProjectPanel.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
005: *
006: */
007:
008: package com.memoire.vainstall.builder.gui;
009:
010: import com.memoire.vainstall.VAGlobals;
011: import com.memoire.vainstall.builder.*;
012:
013: import java.awt.*;
014: import java.awt.event.*;
015: import java.io.File;
016:
017: import javax.swing.*;
018: import javax.swing.border.*;
019:
020: /**
021: * This panel enables the user to change the root directory
022: * where VAInstall install projects a saved.
023: *
024: * @see javax.swing.JPanel
025: *
026: * @author Henrik Falk
027: * @version $Id: PreferencesProjectPanel.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
028: */
029: public class PreferencesProjectPanel extends JPanel implements
030: ActionListener {
031:
032: /**
033: * The VAInstall builder data model
034: */
035: private VAIBuilderModel model = null;
036:
037: /**
038: * a lowered border for the panel
039: */
040: private final static Border loweredBorder = new SoftBevelBorder(
041: BevelBorder.LOWERED);
042:
043: JTextField directoryField;
044:
045: JButton directoryButton;
046:
047: /**
048: * Default constructor
049: */
050: public PreferencesProjectPanel() {
051:
052: setBorder(loweredBorder);
053:
054: GridBagLayout layout = new GridBagLayout();
055: setLayout(layout);
056:
057: GridBagConstraints constraint = new GridBagConstraints();
058:
059: JLabel directoryLabel = new JLabel();
060: directoryLabel.setText(VAGlobals.getResource(
061: "com.memoire.vainstall.builder.Language",
062: "PreferencesProjectPanel_Root"));
063: directoryLabel.setFont(new java.awt.Font("TimesRoman",
064: java.awt.Font.PLAIN, 14));
065: constraint.fill = GridBagConstraints.BOTH;
066: constraint.insets = new Insets(4, 8, 0, 4);
067: constraint.anchor = GridBagConstraints.WEST;
068: constraint.gridx = 0;
069: constraint.gridy = 0;
070: constraint.gridwidth = 1;
071: constraint.gridheight = 1;
072: constraint.weightx = 0;
073: constraint.weighty = 0;
074: layout.setConstraints(directoryLabel, constraint);
075: add(directoryLabel);
076:
077: directoryField = new JTextField();
078: directoryField.setEditable(false);
079: // directoryField.setEnabled(false);
080: directoryField.setFont(new java.awt.Font("TimesRoman",
081: java.awt.Font.PLAIN, 14));
082: constraint.fill = GridBagConstraints.BOTH;
083: constraint.insets = new Insets(4, 8, 4, 4);
084: constraint.anchor = GridBagConstraints.CENTER;
085: constraint.gridx = 0;
086: constraint.gridy = 1;
087: constraint.gridwidth = 1;
088: constraint.gridheight = 1;
089: constraint.weightx = 1;
090: constraint.weighty = 0;
091: layout.setConstraints(directoryField, constraint);
092: add(directoryField);
093:
094: directoryButton = new JButton();
095: directoryButton.setText(VAGlobals.getResource(
096: "com.memoire.vainstall.builder.Language",
097: "PreferencesProjectPanel_Change"));
098: directoryButton.setSize(directoryButton.getSize().width,
099: directoryField.getSize().height);
100: directoryButton.addActionListener(this );
101: // directoryButton.setFont(new java.awt.Font("TimesRoman", java.awt.Font.PLAIN, 14));
102: constraint.fill = GridBagConstraints.BOTH;
103: constraint.insets = new Insets(4, 4, 4, 8);
104: constraint.anchor = GridBagConstraints.CENTER;
105: constraint.gridx = 1;
106: constraint.gridy = 1;
107: constraint.gridwidth = 1;
108: constraint.gridheight = 1;
109: constraint.weightx = 0;
110: constraint.weighty = 0;
111: layout.setConstraints(directoryButton, constraint);
112: add(directoryButton);
113:
114: JPanel fillPanel = new JPanel();
115: constraint.fill = GridBagConstraints.BOTH;
116: constraint.insets = new Insets(4, 4, 4, 4);
117: constraint.anchor = GridBagConstraints.WEST;
118: constraint.gridx = 0;
119: constraint.gridy = 2;
120: constraint.gridwidth = 1;
121: constraint.gridheight = 1;
122: constraint.weightx = 0;
123: constraint.weighty = 1;
124: layout.setConstraints(fillPanel, constraint);
125: add(fillPanel);
126:
127: }
128:
129: /**
130: * Implement the actionPerformed method
131: * @param evt the action event
132: */
133: public void actionPerformed(ActionEvent evt) {
134:
135: // extract the control that sends the event
136: Object source = evt.getSource();
137:
138: if (source == directoryButton) {
139:
140: // show filechooser dialog
141: JFileChooser jfc = new JFileChooser();
142: jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
143:
144: String rootDirectory = (String) model.getPropertyList()
145: .get("vainstall.projectroot");
146: if (rootDirectory == null) {
147: rootDirectory = System.getProperty("user.dir");
148: }
149: jfc.setCurrentDirectory(new File(rootDirectory));
150:
151: int result = jfc.showDialog(null, VAGlobals.getResource(
152: "com.memoire.vainstall.builder.Language",
153: "PreferencesProjectPanel_Select"));
154: if (result == JFileChooser.APPROVE_OPTION) {
155: directoryField.setText(jfc.getSelectedFile()
156: .getAbsolutePath());
157:
158: // save project root
159: model.getPropertyList().put("vainstall.projectroot",
160: jfc.getSelectedFile().getAbsolutePath());
161: }
162: }
163: }
164:
165: /**
166: * save
167: */
168: public void save() {
169: }
170:
171: public void initialize(VAIBuilderModel model) {
172: this .model = model;
173:
174: String rootDirectory = (String) model.getPropertyList().get(
175: "vainstall.projectroot");
176:
177: if (rootDirectory == null) {
178: rootDirectory = System.getProperty("user.dir");
179: }
180: directoryField.setText(rootDirectory);
181: }
182:
183: public void stop() {
184: }
185:
186: }
|