]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | |
2 | import java.awt.*; | |
3 | import java.awt.event.*; | |
4 | import javax.swing.*; | |
5 | import java.net.URL; | |
6 | import java.net.*; | |
7 | import java.io.*; | |
8 | import com.easysw.cups.*; | |
9 | ||
10 | public class GLPprinterDetail | |
11 | { | |
12 | ||
13 | private CupsPrinter printer = null; | |
14 | private JScrollPane scrollPane = null; | |
15 | private JPanel mainPanel = null; | |
16 | ||
17 | ||
18 | // Constructor | |
19 | public GLPprinterDetail( CupsPrinter cp ) | |
20 | { | |
21 | printer = cp; | |
22 | load(); | |
23 | } | |
24 | ||
25 | public void load() | |
26 | { | |
27 | mainPanel = new JPanel(); | |
28 | mainPanel = printerInfoPanel( printer ); | |
29 | } | |
30 | ||
31 | ||
32 | ||
33 | // ----------------------------------------------------------- | |
34 | // | |
35 | // Build an info panel for an individual printer. | |
36 | // | |
37 | private JPanel printerInfoPanel( CupsPrinter cp ) | |
38 | { | |
39 | JPanel printerPanel = new JPanel(); | |
40 | BoxLayout printerBox; | |
41 | ||
42 | JPanel leftHeader = new JPanel(); | |
43 | JPanel rightHeader = new JPanel(); | |
44 | ||
45 | JPanel leftPane = new JPanel(); | |
46 | JPanel rightPane = new JPanel(); | |
47 | ||
48 | GridBagLayout leftLayout = new GridBagLayout(); | |
49 | GridBagLayout rightLayout = new GridBagLayout(); | |
50 | ||
51 | GridBagConstraints leftConst = new GridBagConstraints(); | |
52 | GridBagConstraints rightConst = new GridBagConstraints(); | |
53 | ||
54 | ||
55 | JLabel printerIconLabel = null; | |
56 | JLabel printerInfoLabel = null; | |
57 | JLabel printerNameLabel = null; | |
58 | JLabel printerMakeLabel = null; | |
59 | ||
60 | JTable printerStatusTable = null; | |
61 | ||
62 | printerBox = new BoxLayout(printerPanel, BoxLayout.X_AXIS); | |
63 | printerPanel.setLayout(printerBox); | |
64 | printerPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); | |
65 | printerPanel.setBackground(GLPcolors.backgroundColor); | |
66 | ||
67 | // Add border around the panel. | |
68 | ||
69 | ||
70 | // ------------------------------------------------------------ | |
71 | // Left pane | |
72 | // ------------------------------------------------------------ | |
73 | leftPane.setLayout(leftLayout); | |
74 | leftPane.setBackground(GLPcolors.backgroundColor); | |
75 | ||
76 | leftHeader.setLayout(new BorderLayout()); | |
77 | leftHeader.setBackground(GLPcolors.highlightColor); | |
78 | leftHeader.setBorder(BorderFactory.createEmptyBorder(3,3,3,3)); | |
79 | ||
80 | printerNameLabel = new JLabel(cp.getPrinterName()); | |
81 | printerNameLabel.setForeground(Color.black); | |
82 | leftHeader.add( printerNameLabel, BorderLayout.WEST); | |
83 | leftConst.gridwidth = GridBagConstraints.RELATIVE; | |
84 | leftConst.gridx = 0; | |
85 | leftConst.gridy = 0; | |
86 | leftConst.fill = GridBagConstraints.HORIZONTAL; | |
87 | leftConst.weightx = 0.0; | |
88 | leftConst.weighty = 0.0; | |
89 | leftConst.ipady = 4; | |
90 | leftLayout.setConstraints( leftHeader, leftConst ); | |
91 | leftPane.add(leftHeader); | |
92 | ||
93 | String imageName = "./images/printer-" + | |
94 | cp.getStateText() + ".gif"; | |
95 | JButton printerButton; | |
96 | try | |
97 | { | |
98 | URL iconURL = ClassLoader.getSystemResource(imageName); | |
99 | ImageIcon icon = new ImageIcon(iconURL); | |
100 | printerButton = new JButton( "<html><center><b>" + | |
101 | cp.getPrinterName() + | |
102 | "</b></center></html>", | |
103 | icon ); | |
104 | } | |
105 | catch (NullPointerException e) | |
106 | { | |
107 | printerButton = new JButton( "<html><center><b>" + | |
108 | cp.getPrinterName() + | |
109 | "</b></center></html>"); | |
110 | } | |
111 | printerButton.setBorder(BorderFactory.createEmptyBorder(3,3,3,3)); | |
112 | printerButton.setBackground(GLPcolors.backgroundColor); | |
113 | printerButton.setActionCommand( cp.getPrinterName() ); | |
114 | // printerButton.addActionListener(this); | |
115 | printerButton.setToolTipText("Click to go to " + cp.getPrinterName() + | |
116 | "'s extended informtion page."); | |
117 | ||
118 | leftConst.gridwidth = GridBagConstraints.REMAINDER; | |
119 | leftConst.gridx = 0; | |
120 | leftConst.gridy = 1; | |
121 | leftConst.fill = GridBagConstraints.BOTH; | |
122 | leftConst.weightx = 1.0; | |
123 | leftConst.weighty = 1.0; | |
124 | leftConst.ipady = 4; | |
125 | leftLayout.setConstraints( printerButton, leftConst ); | |
126 | leftPane.add(printerButton); | |
127 | ||
128 | ||
129 | // ------------------------------------------------------------ | |
130 | // Right pane | |
131 | // ------------------------------------------------------------ | |
132 | rightPane.setLayout(rightLayout); | |
133 | rightPane.setBackground(GLPcolors.backgroundColor); | |
134 | ||
135 | rightHeader.setLayout(new BorderLayout()); | |
136 | rightHeader.setBackground(GLPcolors.highlightColor); | |
137 | rightHeader.setBorder(BorderFactory.createEmptyBorder(3,3,3,3)); | |
138 | ||
139 | printerMakeLabel = new JLabel(cp.getMakeAndModel()); | |
140 | printerMakeLabel.setForeground(Color.black); | |
141 | rightHeader.add( printerMakeLabel, BorderLayout.WEST); | |
142 | ||
143 | rightConst.gridwidth = GridBagConstraints.RELATIVE; | |
144 | rightConst.gridx = 0; | |
145 | rightConst.gridy = 0; | |
146 | rightConst.fill = GridBagConstraints.HORIZONTAL; | |
147 | rightConst.weightx = 0.0; | |
148 | rightConst.weighty = 0.0; | |
149 | rightConst.ipady = 4; | |
150 | rightLayout.setConstraints( rightHeader, rightConst ); | |
151 | rightPane.add(rightHeader); | |
152 | ||
153 | ||
154 | Font labelFont = new Font("Serif",Font.BOLD, 12 ); | |
155 | // Font textFont = new Font("Serif", Font.NORMAL, 12 ); | |
156 | Font messageFont = new Font("Serif", Font.ITALIC, 12 ); | |
157 | ||
158 | JLabel pdServerLabel = new JLabel("Server"); | |
159 | JLabel pdNameLabel = new JLabel("Name"); | |
160 | JLabel pdLocationLabel = new JLabel("Location"); | |
161 | JLabel pdStatusLabel = new JLabel("Status"); | |
162 | JLabel pdMessageLabel = new JLabel("Message"); | |
163 | ||
164 | JLabel pdServerText = new JLabel(GLPvars.cupsServerName); | |
165 | JLabel pdNameText = new JLabel(cp.getPrinterName()); | |
166 | JLabel pdLocationText = new JLabel(cp.getLocation()); | |
167 | JLabel pdStatusText = new JLabel(cp.getStateText()); | |
168 | JLabel pdMessageText = new JLabel(cp.getStateReasons()); | |
169 | ||
170 | pdServerLabel.setFont(labelFont); | |
171 | pdNameLabel.setFont(labelFont); | |
172 | pdLocationLabel.setFont(labelFont); | |
173 | pdStatusLabel.setFont(labelFont); | |
174 | pdMessageLabel.setFont(labelFont); | |
175 | pdMessageText.setFont(messageFont); | |
176 | ||
177 | pdServerLabel.setForeground(Color.black); | |
178 | pdNameLabel.setForeground(Color.black); | |
179 | pdLocationLabel.setForeground(Color.black); | |
180 | pdStatusLabel.setForeground(Color.black); | |
181 | pdMessageLabel.setForeground(Color.black); | |
182 | ||
183 | ||
184 | JPanel tablePane; | |
185 | if ((cp.getStateReasons().length() > 0) && | |
186 | (!cp.getStateReasons().equals("none"))) | |
187 | { | |
188 | tablePane = new JPanel(new GridLayout(5,2,2,2)); | |
189 | tablePane.add(pdServerLabel); | |
190 | tablePane.add(pdServerText); | |
191 | ||
192 | tablePane.add(pdNameLabel); | |
193 | tablePane.add(pdNameText); | |
194 | ||
195 | tablePane.add(pdLocationLabel); | |
196 | tablePane.add(pdLocationText); | |
197 | ||
198 | tablePane.add(pdStatusLabel); | |
199 | tablePane.add(pdStatusText); | |
200 | ||
201 | tablePane.add(pdMessageLabel); | |
202 | tablePane.add(pdMessageText); | |
203 | } | |
204 | else | |
205 | { | |
206 | tablePane = new JPanel(new GridLayout(4,2,2,2)); | |
207 | tablePane.add(pdServerLabel); | |
208 | tablePane.add(pdServerText); | |
209 | ||
210 | tablePane.add(pdNameLabel); | |
211 | tablePane.add(pdNameText); | |
212 | ||
213 | tablePane.add(pdLocationLabel); | |
214 | tablePane.add(pdLocationText); | |
215 | ||
216 | tablePane.add(pdStatusLabel); | |
217 | tablePane.add(pdStatusText); | |
218 | ||
219 | } | |
220 | tablePane.setBackground(GLPcolors.backgroundColor); | |
221 | ||
222 | // printerStatusTable.setShowGrid(false); | |
223 | rightConst.gridwidth = GridBagConstraints.REMAINDER; | |
224 | rightConst.gridx = 0; | |
225 | rightConst.gridy = 1; | |
226 | rightConst.fill = GridBagConstraints.BOTH; | |
227 | rightConst.weightx = 1.0; | |
228 | rightConst.weighty = 1.0; | |
229 | rightConst.ipady = 4; | |
230 | rightLayout.setConstraints( tablePane, rightConst ); | |
231 | rightPane.add(tablePane); | |
232 | ||
233 | printerPanel.add(leftPane); | |
234 | printerPanel.add(rightPane); | |
235 | ||
236 | return(printerPanel); | |
237 | } | |
238 | ||
239 | ||
240 | public JPanel getPanel() | |
241 | { | |
242 | return(mainPanel); | |
243 | } | |
244 | } |