KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > panels > SelectPrinterPanel


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2006 Hal Vaughan
8  * http://thresholddigital.com
9  * hal@thresholddigital.com
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  * Updated by Fabrice Mirabile the 06/01/2006
23  *
24  */

25
26 package com.izforge.izpack.panels;
27
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.awt.GridBagConstraints JavaDoc;
31 import java.awt.GridBagLayout JavaDoc;
32 import java.awt.Insets JavaDoc;
33
34 import javax.print.PrintServiceLookup JavaDoc;
35 import javax.print.PrintService JavaDoc;
36
37 import javax.swing.Box JavaDoc;
38 import javax.swing.BoxLayout JavaDoc;
39 import javax.swing.JComboBox JavaDoc;
40 import javax.swing.JLabel JavaDoc;
41 import javax.swing.JPanel JavaDoc;
42
43 import com.izforge.izpack.gui.LabelFactory;
44 import com.izforge.izpack.installer.InstallData;
45 import com.izforge.izpack.installer.InstallerFrame;
46 import com.izforge.izpack.installer.IzPanel;
47
48 /**
49  * The SelectPrinter panel class.
50  *
51  * @author Hal Vaughan
52  */

53 public class SelectPrinterPanel extends IzPanel implements ActionListener JavaDoc
54 {
55
56     /**
57      *
58      */

59     private static final long serialVersionUID = 3257848774955905587L;
60
61     /** The ComboBox to list the printers. */
62      private JComboBox JavaDoc cbPrinters;
63
64     /** Install data variables. */
65      private InstallData iData;
66
67     /**
68      * The constructor.
69      *
70      * @param parent The parent.
71      * @param id The installation data.
72      */

73     public SelectPrinterPanel(InstallerFrame parent, InstallData id)
74     {
75         super(parent, id);
76         
77         iData = id;
78
79         // The 'super' layout
80
GridBagLayout JavaDoc superLayout = new GridBagLayout JavaDoc();
81         setLayout(superLayout);
82         GridBagConstraints JavaDoc gbConstraints = new GridBagConstraints JavaDoc();
83         gbConstraints.insets = new Insets JavaDoc(0, 0, 0, 0);
84         gbConstraints.fill = GridBagConstraints.NONE;
85         gbConstraints.anchor = GridBagConstraints.CENTER;
86
87         // We initialize our 'real' layout
88
JPanel JavaDoc centerPanel = new JPanel JavaDoc();
89         BoxLayout JavaDoc layout = new BoxLayout JavaDoc(centerPanel, BoxLayout.Y_AXIS);
90         centerPanel.setLayout(layout);
91         superLayout.addLayoutComponent(centerPanel, gbConstraints);
92         add(centerPanel);
93
94         cbPrinters = new JComboBox JavaDoc();
95         PrintService JavaDoc[] pServices = PrintServiceLookup.lookupPrintServices(null, null);
96         iData.setVariable("SELECTED_PRINTER", pServices[0].getName());
97         for (int i = 0; i < pServices.length; i++)
98         {
99             cbPrinters.addItem(pServices[i].getName());
100         }
101         cbPrinters.addActionListener(this);
102
103         // We create and put the labels
104
String JavaDoc str;
105
106         centerPanel.add(Box.createVerticalStrut(10));
107         
108         str = parent.langpack.getString("PrinterSelectPanel.select_printer");
109         JLabel JavaDoc 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
120     public void actionPerformed(ActionEvent JavaDoc event)
121     {
122         String JavaDoc sPrinter = (String JavaDoc) cbPrinters.getSelectedItem();
123         iData.setVariable("SELECTED_PRINTER", sPrinter);
124     }
125
126     /**
127      * Indicates wether the panel has been validated or not.
128      *
129      * @return Always true.
130      */

131     public boolean isValidated()
132     {
133         return true;
134     }
135 }
136
Popular Tags