KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $RCSfile: ProductStepShortcutsPanel.java,v $
3  * @modification $Date: 2001/09/28 19:35:30 $
4  * @version $Id: ProductStepShortcutsPanel.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  *
28  * @see com.memoire.vainstall.builder.gui.VAIProductInternalFrame
29  * @see javax.swing.JPanel
30  *
31  * @author Henrik Falk
32  * @version $Id: ProductStepShortcutsPanel.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
33  */

34 public class ProductStepShortcutsPanel extends JPanel implements FocusListener, ActionListener {
35
36     private VAIProductModel model;
37
38     private final static Border loweredBorder = new SoftBevelBorder(BevelBorder.LOWERED);
39
40     JTextField submenuField;
41     JTextField submenuIconField;
42     JButton submenuIconButton;
43
44     JTextField nameField;
45     JTextField nameIconField;
46     JButton nameIconButton;
47
48     public ProductStepShortcutsPanel() {
49
50         setBorder(loweredBorder);
51
52         GridBagLayout layout = new GridBagLayout();
53         setLayout(layout);
54
55         GridBagConstraints contraint=new GridBagConstraints();
56
57 /*
58 # Link section (sub-menu) name (default="Applications")
59 vainstall.destination.linkSectionName=Utilities
60
61 # Link section (sub-menu) icon (default=none)
62 vainstall.destination.linkSectionIcon=
63
64 # Link entry (shortcut) name (default=appName)
65 vainstall.destination.linkEntryName=
66
67 # Link entry (shortcut) icon (default=none)
68 vainstall.destination.linkEntryIcon=
69 */

70         // Description
71
JLabel decriptionLabel = new JLabel();
72         decriptionLabel.setBorder(BorderFactory.createTitledBorder("Description"));
73         decriptionLabel.setText("This step creates shortcuts for the product.");
74         contraint.fill = GridBagConstraints.BOTH;
75         contraint.insets = new Insets(16,16,0,16);
76         contraint.anchor = GridBagConstraints.WEST;
77         contraint.gridx = 0;
78         contraint.gridy = 0;
79         contraint.gridwidth = 3;
80         contraint.gridheight = 1;
81         contraint.weightx = 0;
82         contraint.weighty = 0;
83         layout.setConstraints(decriptionLabel,contraint);
84         add(decriptionLabel);
85
86         // Sub-menu Name
87
JLabel submenuLabel = new JLabel();
88         submenuLabel.setText("Sub-menu Name:");
89         contraint.fill = GridBagConstraints.HORIZONTAL;
90         contraint.insets = new Insets(16,16,0,16);
91         contraint.anchor = GridBagConstraints.WEST;
92         contraint.gridx = 0;
93         contraint.gridy = 1;
94         contraint.gridwidth = 1;
95         contraint.gridheight = 1;
96         contraint.weightx = 0;
97         contraint.weighty = 0;
98         layout.setConstraints(submenuLabel,contraint);
99         add(submenuLabel);
100
101         submenuField = new JTextField();
102         submenuField.setEditable(false);
103         contraint.fill = GridBagConstraints.HORIZONTAL;
104         contraint.insets = new Insets(4,16,0,16);
105         contraint.anchor = GridBagConstraints.WEST;
106         contraint.gridx = 0;
107         contraint.gridy = 2;
108         contraint.gridwidth = 1;
109         contraint.gridheight = 1;
110         contraint.weightx = 0;
111         contraint.weighty = 0;
112         layout.setConstraints(submenuField,contraint);
113         add(submenuField);
114
115         // Sub-menu Icon
116
JLabel submenuIconLabel = new JLabel();
117         submenuIconLabel.setText("Sub-menu Icon:");
118         contraint.fill = GridBagConstraints.HORIZONTAL;
119         contraint.insets = new Insets(16,16,0,16);
120         contraint.anchor = GridBagConstraints.WEST;
121         contraint.gridx = 0;
122         contraint.gridy = 3;
123         contraint.gridwidth = 1;
124         contraint.gridheight = 1;
125         contraint.weightx = 0;
126         contraint.weighty = 0;
127         layout.setConstraints(submenuIconLabel,contraint);
128         add(submenuIconLabel);
129
130         submenuIconField = new JTextField();
131         submenuIconField.setEditable(false);
132         contraint.fill = GridBagConstraints.HORIZONTAL;
133         contraint.insets = new Insets(4,16,0,16);
134         contraint.anchor = GridBagConstraints.WEST;
135         contraint.gridx = 0;
136         contraint.gridy = 4;
137         contraint.gridwidth = 2;
138         contraint.gridheight = 1;
139         contraint.weightx = 1;
140         contraint.weighty = 0;
141         layout.setConstraints(submenuIconField,contraint);
142         add(submenuIconField);
143
144         submenuIconButton = new JButton();
145         submenuIconButton.setText("Change");
146         submenuIconButton.setMnemonic('C');
147         contraint.fill = GridBagConstraints.NONE;
148         contraint.insets = new Insets(4,16,0,16);
149         contraint.anchor = GridBagConstraints.WEST;
150         contraint.gridx = 2;
151         contraint.gridy = 4;
152         contraint.gridwidth = 1;
153         contraint.gridheight = 1;
154         contraint.weightx = 0;
155         contraint.weighty = 0;
156         layout.setConstraints(submenuIconButton,contraint);
157         add(submenuIconButton);
158
159         // Program Name
160
JLabel nameLabel = new JLabel();
161         nameLabel.setText("Program Shortcut Name:");
162         contraint.fill = GridBagConstraints.HORIZONTAL;
163         contraint.insets = new Insets(16,16,0,16);
164         contraint.anchor = GridBagConstraints.WEST;
165         contraint.gridx = 0;
166         contraint.gridy = 5;
167         contraint.gridwidth = 1;
168         contraint.gridheight = 1;
169         contraint.weightx = 0;
170         contraint.weighty = 0;
171         layout.setConstraints(nameLabel,contraint);
172         add(nameLabel);
173
174         nameField = new JTextField();
175         nameField.setEditable(false);
176         contraint.fill = GridBagConstraints.HORIZONTAL;
177         contraint.insets = new Insets(4,16,0,16);
178         contraint.anchor = GridBagConstraints.WEST;
179         contraint.gridx = 0;
180         contraint.gridy = 6;
181         contraint.gridwidth = 1;
182         contraint.gridheight = 1;
183         contraint.weightx = 0;
184         contraint.weighty = 0;
185         layout.setConstraints(nameField,contraint);
186         add(nameField);
187
188         // Program Icon
189
JLabel nameIconLabel = new JLabel();
190         nameIconLabel.setText("Program Icon:");
191         contraint.fill = GridBagConstraints.HORIZONTAL;
192         contraint.insets = new Insets(16,16,0,16);
193         contraint.anchor = GridBagConstraints.WEST;
194         contraint.gridx = 0;
195         contraint.gridy = 7;
196         contraint.gridwidth = 1;
197         contraint.gridheight = 1;
198         contraint.weightx = 0;
199         contraint.weighty = 0;
200         layout.setConstraints(nameIconLabel,contraint);
201         add(nameIconLabel);
202
203         nameIconField = new JTextField();
204         nameIconField.setEditable(false);
205         contraint.fill = GridBagConstraints.HORIZONTAL;
206         contraint.insets = new Insets(4,16,0,16);
207         contraint.anchor = GridBagConstraints.WEST;
208         contraint.gridx = 0;
209         contraint.gridy = 8;
210         contraint.gridwidth = 2;
211         contraint.gridheight = 1;
212         contraint.weightx = 0;
213         contraint.weighty = 0;
214         layout.setConstraints(nameIconField,contraint);
215         add(nameIconField);
216
217         nameIconButton = new JButton();
218         nameIconButton.setText("Change");
219         nameIconButton.setMnemonic('C');
220         contraint.fill = GridBagConstraints.NONE;
221         contraint.insets = new Insets(4,16,0,16);
222         contraint.anchor = GridBagConstraints.WEST;
223         contraint.gridx = 2;
224         contraint.gridy = 8;
225         contraint.gridwidth = 1;
226         contraint.gridheight = 1;
227         contraint.weightx = 0;
228         contraint.weighty = 0;
229         layout.setConstraints(nameIconButton,contraint);
230         add(nameIconButton);
231
232         JPanel fillPanel = new JPanel();
233         contraint.fill = GridBagConstraints.BOTH;
234         contraint.insets = new Insets(4,4,4,4);
235         contraint.anchor = GridBagConstraints.CENTER;
236         contraint.gridx = 0;
237         contraint.gridy = 9;
238         contraint.gridwidth = 1;
239         contraint.gridheight = 1;
240         contraint.weightx = 0;
241         contraint.weighty = 1;
242         layout.setConstraints(fillPanel,contraint);
243         add(fillPanel);
244
245     }
246
247
248     /**
249      * save
250      */

251     public void save() {
252     }
253
254     /**
255      * initialize the panel
256      */

257     public void initialize(VAIProductModel model) {
258         this.model = model;
259
260         if (model.getProperty("vainstall.installer.link.section.name") != null) {
261             submenuField.setText(model.getProperty("vainstall.installer.link.section.name"));
262         }
263         submenuField.setEditable(true);
264         submenuField.addFocusListener(this);
265
266         if (model.getProperty("vainstall.installer.link.entry.name") != null) {
267             nameField.setText(model.getProperty("vainstall.installer.link.entry.name"));
268         }
269         nameField.setEditable(true);
270         nameField.addFocusListener(this);
271
272         submenuIconButton.addActionListener(this);
273         if (model.getProperty("vainstall.installer.link.section.icon") != null) {
274             submenuIconField.setText(model.getProperty("vainstall.installer.link.section.icon"));
275         }
276
277         nameIconButton.addActionListener(this);
278         if (model.getProperty("vainstall.installer.link.entry.icon") != null) {
279             nameIconField.setText(model.getProperty("vainstall.installer.link.entry.icon"));
280         }
281
282     }
283
284     /**
285      * stop
286      */

287     public void stop() {
288     }
289
290     public void focusGained(FocusEvent evt) {
291     }
292
293     public void focusLost(FocusEvent evt) {
294
295         if (evt.getSource() == submenuField) {
296             model.putProperty("vainstall.installer.link.section.name",submenuField.getText());
297         }
298
299         if (evt.getSource() == nameField) {
300             model.putProperty("vainstall.installer.link.entry.name",nameField.getText());
301         }
302
303     }
304
305     public void actionPerformed(ActionEvent evt) {
306
307         if (evt.getSource() == submenuIconButton) {
308
309             JFileChooser jfc = new JFileChooser();
310             jfc.setDialogType(JFileChooser.OPEN_DIALOG);
311             jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
312
313             String JavaDoc rootDirectory = (String JavaDoc)model.getPropertyList().get("vainstall.user.dir");
314             if (rootDirectory == null) {
315                 rootDirectory = System.getProperty("user.dir");
316             }
317
318             jfc.setCurrentDirectory(new File JavaDoc(rootDirectory));
319
320             // we allow all files to be valid
321
// jfc.setAcceptAllFileFilterUsed(false);
322
// VAIImageFileFilter filter = new VAIImageFileFilter();
323
// jfc.addChoosableFileFilter(filter);
324

325             int result = jfc.showDialog(null,"Select Image");
326             if (result == JFileChooser.APPROVE_OPTION) {
327                 submenuIconField.setText(jfc.getSelectedFile().getAbsolutePath());
328
329                 model.putProperty("vainstall.installer.link.section.icon",jfc.getSelectedFile().getAbsolutePath());
330
331                 // use internal method instead of model.putProperty()
332
model.getPropertyList().put("vainstall.user.dir",jfc.getCurrentDirectory().getAbsolutePath());
333             }
334         }
335
336         if (evt.getSource() == nameIconButton) {
337
338             JFileChooser jfc = new JFileChooser();
339             jfc.setDialogType(JFileChooser.OPEN_DIALOG);
340             jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
341
342             String JavaDoc rootDirectory = (String JavaDoc)model.getPropertyList().get("vainstall.user.dir");
343             if (rootDirectory == null) {
344                 rootDirectory = System.getProperty("user.dir");
345             }
346
347             jfc.setCurrentDirectory(new File JavaDoc(rootDirectory));
348
349             // we allow all files to be valid
350
// jfc.setAcceptAllFileFilterUsed(false);
351
// VAIImageFileFilter filter = new VAIImageFileFilter();
352
// jfc.addChoosableFileFilter(filter);
353

354             int result = jfc.showDialog(null,"Select Image");
355             if (result == JFileChooser.APPROVE_OPTION) {
356                 nameIconField.setText(jfc.getSelectedFile().getAbsolutePath());
357
358                 model.putProperty("vainstall.installer.link.entry.icon",jfc.getSelectedFile().getAbsolutePath());
359
360                 // use internal method instead of model.putProperty()
361
model.getPropertyList().put("vainstall.user.dir",jfc.getCurrentDirectory().getAbsolutePath());
362             }
363         }
364
365     }
366
367 }
368
Popular Tags