001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2006 Hal Vaughan
008: * http://thresholddigital.com
009: * hal@thresholddigital.com
010: * Licensed under the Apache License, Version 2.0 (the "License");
011: * you may not use this file except in compliance with the License.
012: * You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: *
022: * Updated by Fabrice Mirabile the 06/01/2006
023: *
024: */
025:
026: package com.izforge.izpack.panels;
027:
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030: import java.awt.GridBagConstraints;
031: import java.awt.GridBagLayout;
032: import java.awt.Insets;
033:
034: import javax.print.PrintServiceLookup;
035: import javax.print.PrintService;
036:
037: import javax.swing.Box;
038: import javax.swing.BoxLayout;
039: import javax.swing.JComboBox;
040: import javax.swing.JLabel;
041: import javax.swing.JPanel;
042:
043: import com.izforge.izpack.gui.LabelFactory;
044: import com.izforge.izpack.installer.InstallData;
045: import com.izforge.izpack.installer.InstallerFrame;
046: import com.izforge.izpack.installer.IzPanel;
047:
048: /**
049: * The SelectPrinter panel class.
050: *
051: * @author Hal Vaughan
052: */
053: public class SelectPrinterPanel extends IzPanel implements
054: ActionListener {
055:
056: /**
057: *
058: */
059: private static final long serialVersionUID = 3257848774955905587L;
060:
061: /** The ComboBox to list the printers. */
062: private JComboBox cbPrinters;
063:
064: /** Install data variables. */
065: private InstallData iData;
066:
067: /**
068: * The constructor.
069: *
070: * @param parent The parent.
071: * @param id The installation data.
072: */
073: public SelectPrinterPanel(InstallerFrame parent, InstallData id) {
074: super (parent, id);
075:
076: iData = id;
077:
078: // The 'super' layout
079: GridBagLayout super Layout = new GridBagLayout();
080: setLayout(super Layout);
081: GridBagConstraints gbConstraints = new GridBagConstraints();
082: gbConstraints.insets = new Insets(0, 0, 0, 0);
083: gbConstraints.fill = GridBagConstraints.NONE;
084: gbConstraints.anchor = GridBagConstraints.CENTER;
085:
086: // We initialize our 'real' layout
087: JPanel centerPanel = new JPanel();
088: BoxLayout layout = new BoxLayout(centerPanel, BoxLayout.Y_AXIS);
089: centerPanel.setLayout(layout);
090: super Layout.addLayoutComponent(centerPanel, gbConstraints);
091: add(centerPanel);
092:
093: cbPrinters = new JComboBox();
094: PrintService[] pServices = PrintServiceLookup
095: .lookupPrintServices(null, null);
096: iData.setVariable("SELECTED_PRINTER", pServices[0].getName());
097: for (PrintService pService : pServices) {
098: cbPrinters.addItem(pService.getName());
099: }
100: cbPrinters.addActionListener(this );
101:
102: // We create and put the labels
103: String str;
104:
105: centerPanel.add(Box.createVerticalStrut(10));
106:
107: str = parent.langpack
108: .getString("PrinterSelectPanel.select_printer");
109: JLabel selectLabel = LabelFactory.create(str, JLabel.LEADING);
110: selectLabel.setAlignmentX(JLabel.LEADING);
111: centerPanel.add(selectLabel);
112:
113: centerPanel.add(Box.createVerticalStrut(20));
114:
115: centerPanel.add(cbPrinters);
116:
117: }
118:
119: public void actionPerformed(ActionEvent event) {
120: String sPrinter = (String) cbPrinters.getSelectedItem();
121: iData.setVariable("SELECTED_PRINTER", sPrinter);
122: }
123:
124: /**
125: * Indicates wether the panel has been validated or not.
126: *
127: * @return Always true.
128: */
129: public boolean isValidated() {
130: return true;
131: }
132: }
|