001: /*
002: * $RCSfile: ProductVisualPanel.java,v $
003: * @modification $Date: 2002/12/16 13:23:45 $
004: * @version $Id: ProductVisualPanel.java,v 1.2 2002/12/16 13:23:45 deniger 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: import com.memoire.vainstall.builder.util.VAIImageFileFilter;
013:
014: import java.awt.*;
015: import java.awt.event.*;
016:
017: import java.io.File;
018:
019: import javax.swing.*;
020: import javax.swing.border.*;
021:
022: /**
023: * This panel is shown in the product dialog
024: *
025: * This is not just a view panel because it has a reference to the
026: * VAIProductModel.
027: *
028: *
029: * @see com.memoire.vainstall.builder.gui.VAIProductInternalFrame
030: * @see javax.swing.JPanel
031: *
032: * @author Henrik Falk
033: * @version $Id: ProductVisualPanel.java,v 1.2 2002/12/16 13:23:45 deniger Exp $
034: */
035: public class ProductVisualPanel extends JPanel implements
036: FocusListener, ItemListener, ActionListener {
037:
038: private VAIProductModel model;
039:
040: private final static Border loweredBorder = new SoftBevelBorder(
041: BevelBorder.LOWERED);
042:
043: JTextField bannerImageField;
044: JButton bannerImageButton;
045:
046: JComboBox uiInstallerBox;
047:
048: JCheckBox blueScreenBox;
049: JTextField blueScreenField;
050:
051: public ProductVisualPanel() {
052:
053: setBorder(loweredBorder);
054:
055: GridBagLayout layout = new GridBagLayout();
056: setLayout(layout);
057:
058: GridBagConstraints contraint = new GridBagConstraints();
059:
060: /*
061: # bluescreen or no blue screen?
062: vainstall.destination.ui.bluescreen=no
063:
064: # bluescreen colour
065: vainstall.destination.ui.bluescreen.colour=FFBBAA
066:
067: # banner image (if file not found, a default banner will be used)
068: vainstall.destination.ui.image=src/doc/images/example.gif
069: */
070: // Banner Image
071: JLabel bannerImageLabel = new JLabel();
072: bannerImageLabel.setText("Banner Image:");
073: contraint.fill = GridBagConstraints.HORIZONTAL;
074: contraint.insets = new Insets(16, 16, 0, 16);
075: contraint.anchor = GridBagConstraints.WEST;
076: contraint.gridx = 0;
077: contraint.gridy = 0;
078: contraint.gridwidth = 3;
079: contraint.gridheight = 1;
080: contraint.weightx = 0;
081: contraint.weighty = 0;
082: layout.setConstraints(bannerImageLabel, contraint);
083: add(bannerImageLabel);
084:
085: bannerImageField = new JTextField();
086: bannerImageField.setEditable(false);
087: contraint.fill = GridBagConstraints.HORIZONTAL;
088: contraint.insets = new Insets(4, 16, 0, 8);
089: contraint.anchor = GridBagConstraints.CENTER;
090: contraint.gridx = 0;
091: contraint.gridy = 1;
092: contraint.gridwidth = 2;
093: contraint.gridheight = 1;
094: contraint.weightx = 1;
095: contraint.weighty = 0;
096: layout.setConstraints(bannerImageField, contraint);
097: add(bannerImageField);
098:
099: bannerImageButton = new JButton();
100: // bannerImageButton.setSize(bannerImageButton.getSize().width,bannerImageField.getSize().height);
101: bannerImageButton.setText("Change");
102: bannerImageButton.setMnemonic('C');
103: contraint.fill = GridBagConstraints.BOTH;
104: contraint.insets = new Insets(4, 0, 0, 16);
105: contraint.anchor = GridBagConstraints.CENTER;
106: contraint.gridx = 2;
107: contraint.gridy = 1;
108: contraint.gridwidth = 1;
109: contraint.gridheight = 1;
110: contraint.weightx = 0;
111: contraint.weighty = 0;
112: layout.setConstraints(bannerImageButton, contraint);
113: add(bannerImageButton);
114:
115: // Installer UI
116: JLabel uiInstallerLabel = new JLabel();
117: uiInstallerLabel.setText("UI during Installation:");
118: contraint.fill = GridBagConstraints.NONE;
119: contraint.insets = new Insets(32, 16, 0, 8);
120: contraint.anchor = GridBagConstraints.WEST;
121: contraint.gridx = 0;
122: contraint.gridy = 2;
123: contraint.gridwidth = 1;
124: contraint.gridheight = 1;
125: contraint.weightx = 0;
126: contraint.weighty = 0;
127: layout.setConstraints(uiInstallerLabel, contraint);
128: add(uiInstallerLabel);
129:
130: uiInstallerBox = new JComboBox();
131: uiInstallerBox.addItem("graphic");
132: uiInstallerBox.addItem("xtra");
133: uiInstallerBox.addItem("text");
134: uiInstallerBox.addItem("ansi");
135: uiInstallerBox.setSelectedIndex(0);
136: contraint.fill = GridBagConstraints.HORIZONTAL;
137: contraint.insets = new Insets(32, 16, 0, 8);
138: contraint.anchor = GridBagConstraints.WEST;
139: contraint.gridx = 1;
140: contraint.gridy = 2;
141: contraint.gridwidth = 1;
142: contraint.gridheight = 1;
143: contraint.weightx = 0;
144: contraint.weighty = 0;
145: layout.setConstraints(uiInstallerBox, contraint);
146: add(uiInstallerBox);
147:
148: blueScreenBox = new JCheckBox();
149: blueScreenBox.setText("Use Blue Screen during install");
150: contraint.fill = GridBagConstraints.HORIZONTAL;
151: contraint.insets = new Insets(32, 16, 0, 16);
152: contraint.anchor = GridBagConstraints.WEST;
153: contraint.gridx = 0;
154: contraint.gridy = 4;
155: contraint.gridwidth = 3;
156: contraint.gridheight = 1;
157: contraint.weightx = 0;
158: contraint.weighty = 0;
159: layout.setConstraints(blueScreenBox, contraint);
160: add(blueScreenBox);
161:
162: JLabel blueScreenLabel = new JLabel();
163: blueScreenLabel.setText("Colour (FFFFFF = white) :");
164: contraint.fill = GridBagConstraints.HORIZONTAL;
165: contraint.insets = new Insets(4, 16, 0, 16);
166: contraint.anchor = GridBagConstraints.WEST;
167: contraint.gridx = 0;
168: contraint.gridy = 5;
169: contraint.gridwidth = 1;
170: contraint.gridheight = 1;
171: contraint.weightx = 0;
172: contraint.weighty = 0;
173: layout.setConstraints(blueScreenLabel, contraint);
174: add(blueScreenLabel);
175:
176: blueScreenField = new JTextField();
177: blueScreenField.setEditable(false);
178: contraint.fill = GridBagConstraints.HORIZONTAL;
179: contraint.insets = new Insets(4, 16, 0, 8);
180: contraint.anchor = GridBagConstraints.WEST;
181: contraint.gridx = 1;
182: contraint.gridy = 5;
183: contraint.gridwidth = 1;
184: contraint.gridheight = 1;
185: contraint.weightx = 0;
186: contraint.weighty = 0;
187: layout.setConstraints(blueScreenField, contraint);
188: add(blueScreenField);
189:
190: JPanel fillPanel = new JPanel();
191: contraint.fill = GridBagConstraints.BOTH;
192: contraint.insets = new Insets(4, 4, 4, 4);
193: contraint.anchor = GridBagConstraints.CENTER;
194: contraint.gridx = 0;
195: contraint.gridy = 6;
196: contraint.gridwidth = 1;
197: contraint.gridheight = 1;
198: contraint.weightx = 0;
199: contraint.weighty = 1;
200: layout.setConstraints(fillPanel, contraint);
201: add(fillPanel);
202:
203: }
204:
205: /**
206: * save
207: */
208: public void save() {
209: }
210:
211: /**
212: * initialize the panel
213: */
214: public void initialize(VAIProductModel model) {
215: this .model = model;
216:
217: if (model.getPropertyList().containsKey(
218: "vainstall.installer.ui.bluescreen") == true) {
219: if (model.getProperty("vainstall.installer.ui.bluescreen")
220: .equals("yes") == true) {
221: blueScreenBox.setSelected(true);
222: if (model
223: .getProperty("vainstall.installer.ui.bluescreen.colour") != null) {
224: blueScreenField
225: .setText(model
226: .getProperty("vainstall.installer.ui.bluescreen.colour"));
227: }
228: }
229: blueScreenField.setEditable(true);
230: }
231:
232: blueScreenBox.addItemListener(this );
233: uiInstallerBox.addItemListener(this );
234: if (model.getProperty("vainstall.installer.ui.mode") == null) {
235: uiInstallerBox.setSelectedIndex(0);
236: } else {
237: uiInstallerBox.setSelectedItem(model
238: .getProperty("vainstall.installer.ui.mode"));
239: }
240:
241: blueScreenField.addFocusListener(this );
242:
243: bannerImageButton.addActionListener(this );
244: if (model.getProperty("vainstall.installer.ui.banner") != null) {
245: bannerImageField.setText(model
246: .getProperty("vainstall.installer.ui.banner"));
247: }
248: }
249:
250: /**
251: * stop
252: */
253: public void stop() {
254: }
255:
256: public void focusGained(FocusEvent evt) {
257: }
258:
259: public void focusLost(FocusEvent evt) {
260:
261: if (evt.getSource() == blueScreenField) {
262: // we should handle non colour stuff
263: model.putProperty(
264: "vainstall.installer.ui.bluescreen.colour",
265: blueScreenField.getText());
266: }
267: }
268:
269: public void itemStateChanged(ItemEvent evt) {
270: if (evt.getItem() == blueScreenBox) {
271: if (blueScreenBox.isSelected() == true) {
272: blueScreenField.setEditable(true);
273: blueScreenField.requestFocus();
274:
275: model.putProperty("vainstall.installer.ui.bluescreen",
276: "yes");
277: } else {
278: blueScreenField.setText("");
279: blueScreenField.setEditable(false);
280:
281: model
282: .removeProperty("vainstall.installer.ui.bluescreen");
283: model
284: .removeProperty("vainstall.installer.ui.bluescreen.colour");
285: }
286: }
287:
288: if (evt.getSource() == uiInstallerBox
289: && evt.getStateChange() == ItemEvent.SELECTED) {
290: JComboBox box = (JComboBox) evt.getSource();
291: model.putProperty("vainstall.installer.ui.mode",
292: (String) box.getSelectedItem());
293: }
294: }
295:
296: public void actionPerformed(ActionEvent evt) {
297:
298: if (evt.getSource() == bannerImageButton) {
299:
300: JFileChooser jfc = new JFileChooser();
301: jfc.setDialogType(JFileChooser.OPEN_DIALOG);
302: jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
303:
304: String rootDirectory = (String) model.getPropertyList()
305: .get("vainstall.user.dir");
306: if (rootDirectory == null) {
307: rootDirectory = System.getProperty("user.dir");
308: }
309:
310: jfc.setCurrentDirectory(new File(rootDirectory));
311:
312: // we only allow 'vainstall.xml' files to be valid
313: jfc.setAcceptAllFileFilterUsed(false);
314: VAIImageFileFilter filter = new VAIImageFileFilter();
315: jfc.addChoosableFileFilter(filter);
316:
317: int result = jfc.showDialog(null, "Select Image");
318: if (result == JFileChooser.APPROVE_OPTION) {
319: bannerImageField.setText(jfc.getSelectedFile()
320: .getAbsolutePath());
321:
322: model.putProperty("vainstall.installer.ui.banner", jfc
323: .getSelectedFile().getAbsolutePath());
324:
325: // use internal method instead of model.putProperty()
326: model.getPropertyList().put("vainstall.user.dir",
327: jfc.getCurrentDirectory().getAbsolutePath());
328: }
329: }
330:
331: }
332: }
|