KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > builder > gui > ProductStepReadmePanel


1 /*
2  * $RCSfile: ProductStepReadmePanel.java,v $
3  * @modification $Date: 2001/09/28 19:35:30 $
4  * @version $Id: ProductStepReadmePanel.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
5  *
6  */

7
8 package com.memoire.vainstall.builder.gui;
9
10 import com.memoire.vainstall.VAGlobals;
11 import com.memoire.vainstall.builder.*;
12
13 import java.awt.*;
14 import java.awt.event.*;
15
16 import java.io.File JavaDoc;
17
18 import javax.swing.*;
19 import javax.swing.border.*;
20
21 /**
22  * This panel is shown in the product dialog
23  *
24  * This is not just a view panel because it has a reference to the
25  * VAIProductModel.
26  *
27  * # Path of readme file
28  * vainstall.archive.readme=src/doc/readme.txt
29  *
30  * # Encoding of readme file, Optional
31  * #vainstall.archive.readme.encoding = Shift_JIS
32  *
33  * @see javax.swing.JPanel
34  *
35  * @author Henrik Falk
36  * @version $Id: ProductStepReadmePanel.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
37  */

38 public class ProductStepReadmePanel extends JPanel implements FocusListener, ActionListener {
39
40     private VAIProductModel model;
41
42     private final static Border loweredBorder = new SoftBevelBorder(BevelBorder.LOWERED);
43
44     RequiredTextField readmeFileNameField;
45
46     JButton readmeFileNameButton;
47
48     JTextField encodingField;
49
50     public ProductStepReadmePanel() {
51
52         setBorder(loweredBorder);
53
54         GridBagLayout layout = new GridBagLayout();
55         setLayout(layout);
56
57         GridBagConstraints contraint=new GridBagConstraints();
58
59         // Description
60
JLabel decriptionLabel = new JLabel();
61         decriptionLabel.setBorder(BorderFactory.createTitledBorder("Description"));
62         decriptionLabel.setText("This step shows the readme for the product.");
63         contraint.fill = GridBagConstraints.BOTH;
64         contraint.insets = new Insets(16,16,0,16);
65         contraint.anchor = GridBagConstraints.WEST;
66         contraint.gridx = 0;
67         contraint.gridy = 0;
68         contraint.gridwidth = 3;
69         contraint.gridheight = 1;
70         contraint.weightx = 1;
71         contraint.weighty = 0;
72         layout.setConstraints(decriptionLabel,contraint);
73         add(decriptionLabel);
74
75         // License file
76
JLabel licenseFileNameLabel = new JLabel();
77         licenseFileNameLabel.setText("Filename of readme file:");
78         contraint.fill = GridBagConstraints.BOTH;
79         contraint.insets = new Insets(16,16,0,16);
80         contraint.anchor = GridBagConstraints.WEST;
81         contraint.gridx = 0;
82         contraint.gridy = 1;
83         contraint.gridwidth = 2;
84         contraint.gridheight = 1;
85         contraint.weightx = 1;
86         contraint.weighty = 0;
87         layout.setConstraints(licenseFileNameLabel,contraint);
88         add(licenseFileNameLabel);
89
90         readmeFileNameField = new RequiredTextField();
91         readmeFileNameField.setEditable(false);
92         readmeFileNameField.setColumns(40);
93         contraint.fill = GridBagConstraints.NONE;
94         contraint.insets = new Insets(16,16,0,16);
95         contraint.anchor = GridBagConstraints.WEST;
96         contraint.gridx = 0;
97         contraint.gridy = 2;
98         contraint.gridwidth = 2;
99         contraint.gridheight = 1;
100         contraint.weightx = 0;
101         contraint.weighty = 0;
102         layout.setConstraints(readmeFileNameField,contraint);
103         add(readmeFileNameField);
104
105         readmeFileNameButton = new JButton();
106         readmeFileNameButton.setText("Change");
107         readmeFileNameButton.setMnemonic('C');
108         readmeFileNameButton.setSize(readmeFileNameButton.getSize().width,readmeFileNameField.getSize().height);
109         readmeFileNameButton.addActionListener(this);
110         contraint.fill = GridBagConstraints.NONE;
111         contraint.insets = new Insets(16,0,0,16);
112         contraint.anchor = GridBagConstraints.WEST;
113         contraint.gridx = 2;
114         contraint.gridy = 2;
115         contraint.gridwidth = 1;
116         contraint.gridheight = 1;
117         contraint.weightx = 0;
118         contraint.weighty = 0;
119         layout.setConstraints(readmeFileNameButton,contraint);
120         add(readmeFileNameButton);
121
122         // license encoding
123
JLabel encodingLabel = new JLabel();
124         encodingLabel.setText("Encoding of readme file:");
125         contraint.fill = GridBagConstraints.BOTH;
126         contraint.insets = new Insets(16,16,0,16);
127         contraint.anchor = GridBagConstraints.WEST;
128         contraint.gridx = 0;
129         contraint.gridy = 3;
130         contraint.gridwidth = 2;
131         contraint.gridheight = 1;
132         contraint.weightx = 1;
133         contraint.weighty = 0;
134         layout.setConstraints(encodingLabel,contraint);
135         add(encodingLabel);
136
137         encodingField = new JTextField();
138         encodingField.addFocusListener(this);
139         encodingField.setColumns(12);
140         contraint.fill = GridBagConstraints.HORIZONTAL;
141         contraint.insets = new Insets(16,16,0,16);
142         contraint.anchor = GridBagConstraints.WEST;
143         contraint.gridx = 0;
144         contraint.gridy = 4;
145         contraint.gridwidth = 1;
146         contraint.gridheight = 1;
147         contraint.weightx = 0;
148         contraint.weighty = 0;
149         layout.setConstraints(encodingField,contraint);
150         add(encodingField);
151
152         JPanel fillPanel = new JPanel();
153         contraint.fill = GridBagConstraints.BOTH;
154         contraint.insets = new Insets(4,4,4,4);
155         contraint.anchor = GridBagConstraints.CENTER;
156         contraint.gridx = 3;
157         contraint.gridy = 5;
158         contraint.gridwidth = 1;
159         contraint.gridheight = 1;
160         contraint.weightx = 1;
161         contraint.weighty = 1;
162         layout.setConstraints(fillPanel,contraint);
163         add(fillPanel);
164
165     }
166
167
168     /**
169      * save
170      */

171     public void save() {
172     }
173
174     /**
175      * initialize the panel
176      */

177     public void initialize(VAIProductModel model) {
178         this.model = model;
179
180         readmeFileNameField.addFocusListener(this);
181         readmeFileNameField.initialize(model,"Readme File");
182
183         if (model.getReadmeName() != null) {
184             readmeFileNameField.setText(model.getReadmeName());
185         }
186         if (model.getReadmeEncoding() != null) {
187             encodingField.setText(model.getReadmeEncoding());
188         }
189
190     }
191
192     /**
193      * stop
194      */

195     public void stop() {
196     }
197
198     /**
199      * Implement the actionPerformed method
200      * @param evt the action event
201      */

202     public void actionPerformed(ActionEvent evt) {
203         try {
204
205         // extract the control that sends the event
206
Object JavaDoc source = evt.getSource();
207
208         if (source == readmeFileNameButton) {
209
210             // show filechooser dialog
211
JFileChooser jfc = new JFileChooser();
212             jfc.setDialogType(JFileChooser.OPEN_DIALOG);
213             jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
214
215             String JavaDoc rootDirectory = (String JavaDoc)model.getPropertyList().get("vainstall.user.dir");
216             if (rootDirectory == null) {
217                 rootDirectory = System.getProperty("user.dir");
218             }
219
220             jfc.setCurrentDirectory(new File JavaDoc(rootDirectory));
221
222             int result = jfc.showDialog(new JFrame(),"Select Readme File");
223             if (result == JFileChooser.APPROVE_OPTION) {
224                 readmeFileNameField.setText(jfc.getSelectedFile().getAbsolutePath());
225
226                 model.getPropertyList().put("vainstall.user.dir",jfc.getCurrentDirectory().getAbsolutePath());
227
228                 // save project root
229
model.setReadmeName(jfc.getSelectedFile().getAbsolutePath());
230             }
231         }
232
233         } catch(Exception JavaDoc exc) {
234             // Due to bug in JDK 1.4beta ???
235
// System.out.println(exc.getMessage());
236
return;
237         }
238     }
239
240     public void focusGained(FocusEvent evt) {
241     }
242
243     public void focusLost(FocusEvent evt) {
244         if (evt.getSource() == encodingField) {
245             if (encodingField.getText().length() > 0) {
246                 model.setReadmeEncoding(encodingField.getText());
247             }
248         }
249     }
250 }
251
Popular Tags