001: /*
002: * $RCSfile: ProductStepReadmePanel.java,v $
003: * @modification $Date: 2001/09/28 19:35:30 $
004: * @version $Id: ProductStepReadmePanel.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:
016: import java.io.File;
017:
018: import javax.swing.*;
019: import javax.swing.border.*;
020:
021: /**
022: * This panel is shown in the product dialog
023: *
024: * This is not just a view panel because it has a reference to the
025: * VAIProductModel.
026: *
027: * # Path of readme file
028: * vainstall.archive.readme=src/doc/readme.txt
029: *
030: * # Encoding of readme file, Optional
031: * #vainstall.archive.readme.encoding = Shift_JIS
032: *
033: * @see javax.swing.JPanel
034: *
035: * @author Henrik Falk
036: * @version $Id: ProductStepReadmePanel.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
037: */
038: public class ProductStepReadmePanel extends JPanel implements
039: FocusListener, ActionListener {
040:
041: private VAIProductModel model;
042:
043: private final static Border loweredBorder = new SoftBevelBorder(
044: BevelBorder.LOWERED);
045:
046: RequiredTextField readmeFileNameField;
047:
048: JButton readmeFileNameButton;
049:
050: JTextField encodingField;
051:
052: public ProductStepReadmePanel() {
053:
054: setBorder(loweredBorder);
055:
056: GridBagLayout layout = new GridBagLayout();
057: setLayout(layout);
058:
059: GridBagConstraints contraint = new GridBagConstraints();
060:
061: // Description
062: JLabel decriptionLabel = new JLabel();
063: decriptionLabel.setBorder(BorderFactory
064: .createTitledBorder("Description"));
065: decriptionLabel
066: .setText("This step shows the readme for the product.");
067: contraint.fill = GridBagConstraints.BOTH;
068: contraint.insets = new Insets(16, 16, 0, 16);
069: contraint.anchor = GridBagConstraints.WEST;
070: contraint.gridx = 0;
071: contraint.gridy = 0;
072: contraint.gridwidth = 3;
073: contraint.gridheight = 1;
074: contraint.weightx = 1;
075: contraint.weighty = 0;
076: layout.setConstraints(decriptionLabel, contraint);
077: add(decriptionLabel);
078:
079: // License file
080: JLabel licenseFileNameLabel = new JLabel();
081: licenseFileNameLabel.setText("Filename of readme file:");
082: contraint.fill = GridBagConstraints.BOTH;
083: contraint.insets = new Insets(16, 16, 0, 16);
084: contraint.anchor = GridBagConstraints.WEST;
085: contraint.gridx = 0;
086: contraint.gridy = 1;
087: contraint.gridwidth = 2;
088: contraint.gridheight = 1;
089: contraint.weightx = 1;
090: contraint.weighty = 0;
091: layout.setConstraints(licenseFileNameLabel, contraint);
092: add(licenseFileNameLabel);
093:
094: readmeFileNameField = new RequiredTextField();
095: readmeFileNameField.setEditable(false);
096: readmeFileNameField.setColumns(40);
097: contraint.fill = GridBagConstraints.NONE;
098: contraint.insets = new Insets(16, 16, 0, 16);
099: contraint.anchor = GridBagConstraints.WEST;
100: contraint.gridx = 0;
101: contraint.gridy = 2;
102: contraint.gridwidth = 2;
103: contraint.gridheight = 1;
104: contraint.weightx = 0;
105: contraint.weighty = 0;
106: layout.setConstraints(readmeFileNameField, contraint);
107: add(readmeFileNameField);
108:
109: readmeFileNameButton = new JButton();
110: readmeFileNameButton.setText("Change");
111: readmeFileNameButton.setMnemonic('C');
112: readmeFileNameButton.setSize(
113: readmeFileNameButton.getSize().width,
114: readmeFileNameField.getSize().height);
115: readmeFileNameButton.addActionListener(this );
116: contraint.fill = GridBagConstraints.NONE;
117: contraint.insets = new Insets(16, 0, 0, 16);
118: contraint.anchor = GridBagConstraints.WEST;
119: contraint.gridx = 2;
120: contraint.gridy = 2;
121: contraint.gridwidth = 1;
122: contraint.gridheight = 1;
123: contraint.weightx = 0;
124: contraint.weighty = 0;
125: layout.setConstraints(readmeFileNameButton, contraint);
126: add(readmeFileNameButton);
127:
128: // license encoding
129: JLabel encodingLabel = new JLabel();
130: encodingLabel.setText("Encoding of readme file:");
131: contraint.fill = GridBagConstraints.BOTH;
132: contraint.insets = new Insets(16, 16, 0, 16);
133: contraint.anchor = GridBagConstraints.WEST;
134: contraint.gridx = 0;
135: contraint.gridy = 3;
136: contraint.gridwidth = 2;
137: contraint.gridheight = 1;
138: contraint.weightx = 1;
139: contraint.weighty = 0;
140: layout.setConstraints(encodingLabel, contraint);
141: add(encodingLabel);
142:
143: encodingField = new JTextField();
144: encodingField.addFocusListener(this );
145: encodingField.setColumns(12);
146: contraint.fill = GridBagConstraints.HORIZONTAL;
147: contraint.insets = new Insets(16, 16, 0, 16);
148: contraint.anchor = GridBagConstraints.WEST;
149: contraint.gridx = 0;
150: contraint.gridy = 4;
151: contraint.gridwidth = 1;
152: contraint.gridheight = 1;
153: contraint.weightx = 0;
154: contraint.weighty = 0;
155: layout.setConstraints(encodingField, contraint);
156: add(encodingField);
157:
158: JPanel fillPanel = new JPanel();
159: contraint.fill = GridBagConstraints.BOTH;
160: contraint.insets = new Insets(4, 4, 4, 4);
161: contraint.anchor = GridBagConstraints.CENTER;
162: contraint.gridx = 3;
163: contraint.gridy = 5;
164: contraint.gridwidth = 1;
165: contraint.gridheight = 1;
166: contraint.weightx = 1;
167: contraint.weighty = 1;
168: layout.setConstraints(fillPanel, contraint);
169: add(fillPanel);
170:
171: }
172:
173: /**
174: * save
175: */
176: public void save() {
177: }
178:
179: /**
180: * initialize the panel
181: */
182: public void initialize(VAIProductModel model) {
183: this .model = model;
184:
185: readmeFileNameField.addFocusListener(this );
186: readmeFileNameField.initialize(model, "Readme File");
187:
188: if (model.getReadmeName() != null) {
189: readmeFileNameField.setText(model.getReadmeName());
190: }
191: if (model.getReadmeEncoding() != null) {
192: encodingField.setText(model.getReadmeEncoding());
193: }
194:
195: }
196:
197: /**
198: * stop
199: */
200: public void stop() {
201: }
202:
203: /**
204: * Implement the actionPerformed method
205: * @param evt the action event
206: */
207: public void actionPerformed(ActionEvent evt) {
208: try {
209:
210: // extract the control that sends the event
211: Object source = evt.getSource();
212:
213: if (source == readmeFileNameButton) {
214:
215: // show filechooser dialog
216: JFileChooser jfc = new JFileChooser();
217: jfc.setDialogType(JFileChooser.OPEN_DIALOG);
218: jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
219:
220: String rootDirectory = (String) model.getPropertyList()
221: .get("vainstall.user.dir");
222: if (rootDirectory == null) {
223: rootDirectory = System.getProperty("user.dir");
224: }
225:
226: jfc.setCurrentDirectory(new File(rootDirectory));
227:
228: int result = jfc.showDialog(new JFrame(),
229: "Select Readme File");
230: if (result == JFileChooser.APPROVE_OPTION) {
231: readmeFileNameField.setText(jfc.getSelectedFile()
232: .getAbsolutePath());
233:
234: model.getPropertyList()
235: .put(
236: "vainstall.user.dir",
237: jfc.getCurrentDirectory()
238: .getAbsolutePath());
239:
240: // save project root
241: model.setReadmeName(jfc.getSelectedFile()
242: .getAbsolutePath());
243: }
244: }
245:
246: } catch (Exception exc) {
247: // Due to bug in JDK 1.4beta ???
248: // System.out.println(exc.getMessage());
249: return;
250: }
251: }
252:
253: public void focusGained(FocusEvent evt) {
254: }
255:
256: public void focusLost(FocusEvent evt) {
257: if (evt.getSource() == encodingField) {
258: if (encodingField.getText().length() > 0) {
259: model.setReadmeEncoding(encodingField.getText());
260: }
261: }
262: }
263: }
|