]>
git.ipfire.org Git - thirdparty/cups.git/blob - scripting/java/example/GLPdetail.java
3 import java
.awt
.event
.*;
8 import com
.easysw
.cups
.*;
10 public class GLPdetail
implements ActionListener
12 private JPanel mainPanel
= null;
13 private JPanel controlPanel
= null;
14 private JPanel detailPanel
= null;
15 private JScrollPane jobPanel
= null;
16 private BoxLayout mainLayout
= null;
18 private JLabel tmp
= null;
20 private JButton completedButton
= null;
21 private JButton myJobsButton
= null;
22 private JButton printFileButton
= null;
24 private String completedText
= "Show Completed";
25 private String myJobsText
= "Show My Jobs";
26 private String printFileText
= "Print a file";
28 private GLPprinterDetail detail
= null;
29 private GLPjobList joblist
= null;
30 private CupsPrinter printer
= null;
31 private Cups cups
= null;
38 mainPanel
= new JPanel();
39 mainPanel
.setBackground(GLPcolors
.backgroundColor
);
41 // Create the buttons panel
42 controlPanel
= new JPanel();
43 controlPanel
.setLayout(new GridLayout(1,3,2,2));
44 controlPanel
.setBorder(BorderFactory
.createEmptyBorder(5,5,5,5));
45 controlPanel
.setBackground(GLPcolors
.backgroundColor
);
46 completedButton
= new JButton(completedText
);
47 myJobsButton
= new JButton(myJobsText
);
48 printFileButton
= new JButton(printFileText
);
50 completedButton
.setActionCommand(completedText
);
51 completedButton
.addActionListener(this);
53 myJobsButton
.setActionCommand(myJobsText
);
54 myJobsButton
.addActionListener(this);
56 printFileButton
.setActionCommand(printFileText
);
57 printFileButton
.addActionListener(this);
59 completedButton
.setBackground(GLPcolors
.buttonBackgroundColor
);
60 completedButton
.setForeground(GLPcolors
.buttonForegroundColor
);
62 myJobsButton
.setBackground(GLPcolors
.buttonBackgroundColor
);
63 myJobsButton
.setForeground(GLPcolors
.buttonForegroundColor
);
65 printFileButton
.setBackground(GLPcolors
.buttonBackgroundColor
);
66 printFileButton
.setForeground(GLPcolors
.buttonForegroundColor
);
68 controlPanel
.add(completedButton
);
69 controlPanel
.add(myJobsButton
);
70 controlPanel
.add(printFileButton
);
72 // -----------------------------------------------------------
74 // Now get the printer objects
76 if (GLPvars
.selectedPrinterName
!= null)
80 u
= new URL("http://" + GLPvars
.getServerName() +
81 ":631/printers/" + GLPvars
.selectedPrinterName
);
83 cups
.setUser(GLPvars
.cupsUser
);
84 cups
.setPasswd(GLPvars
.cupsPasswd
);
85 printer
= new CupsPrinter( cups
, GLPvars
.selectedPrinterName
);
87 detail
= new GLPprinterDetail( printer
);
88 joblist
= new GLPjobList(printer
);
90 detailPanel
= detail
.getPanel();
91 jobPanel
= joblist
.getPanel();
93 mainLayout
= new BoxLayout(mainPanel
, BoxLayout
.Y_AXIS
);
94 mainPanel
.setLayout(mainLayout
);
95 mainPanel
.add(detailPanel
);
96 mainPanel
.add(controlPanel
);
97 mainPanel
.add(jobPanel
);
101 tmp
= new JLabel("Error loading printer: " + GLPvars
.selectedPrinterName
);
108 tmp
= new JLabel("No printer selected.");
117 public void topDetail()
121 mainPanel
= new JPanel();
122 mainPanel
.setBackground(GLPcolors
.backgroundColor
);
124 // Create the buttons panel
125 controlPanel
= new JPanel();
126 controlPanel
.setLayout(new GridLayout(1,3,2,2));
127 controlPanel
.setBorder(BorderFactory
.createEmptyBorder(5,5,5,5));
128 controlPanel
.setBackground(GLPcolors
.backgroundColor
);
129 completedButton
= new JButton();
130 myJobsButton
= new JButton();
131 printFileButton
= new JButton(printFileText
);
133 if (GLPvars
.showCompletedJobs
)
135 completedButton
.setText("Show Active");
136 completedButton
.setActionCommand("Show Active");
140 completedButton
.setText("Show Completed");
141 completedButton
.setActionCommand("Show Completed");
143 completedButton
.addActionListener(this);
145 if (GLPvars
.showMyJobs
)
147 myJobsButton
.setText("Show All Users");
148 myJobsButton
.setActionCommand("Show All Users");
152 myJobsButton
.setText("Show My Jobs");
153 myJobsButton
.setActionCommand("Show My Jobs");
155 myJobsButton
.addActionListener(this);
157 printFileButton
.setActionCommand(printFileText
);
158 printFileButton
.addActionListener(this);
160 completedButton
.setBackground(GLPcolors
.buttonBackgroundColor
);
161 completedButton
.setForeground(GLPcolors
.buttonForegroundColor
);
163 myJobsButton
.setBackground(GLPcolors
.buttonBackgroundColor
);
164 myJobsButton
.setForeground(GLPcolors
.buttonForegroundColor
);
166 printFileButton
.setBackground(GLPcolors
.buttonBackgroundColor
);
167 printFileButton
.setForeground(GLPcolors
.buttonForegroundColor
);
169 controlPanel
.add(completedButton
);
170 controlPanel
.add(myJobsButton
);
171 controlPanel
.add(printFileButton
);
173 // -----------------------------------------------------------
175 // Now get the printer objects
177 if (GLPvars
.selectedPrinterName
!= null)
184 u
= new URL("http://" + GLPvars
.getServerName() +
185 ":631/printers/" + GLPvars
.selectedPrinterName
);
187 cups
.setUser(GLPvars
.cupsUser
);
188 cups
.setPasswd(GLPvars
.cupsPasswd
);
192 printer
= new CupsPrinter( cups
, GLPvars
.selectedPrinterName
);
193 detail
= new GLPprinterDetail( printer
);
194 joblist
= new GLPjobList(printer
);
196 detailPanel
= detail
.getPanel();
198 jobPanel
= joblist
.getPanel();
200 mainLayout
= new BoxLayout(mainPanel
, BoxLayout
.Y_AXIS
);
201 mainPanel
.setLayout(mainLayout
);
202 mainPanel
.add(detailPanel
);
203 mainPanel
.add(controlPanel
);
204 mainPanel
.add(jobPanel
);
206 catch (IOException e
)
208 tmp
= new JLabel("IOException while loading printer: " +
209 GLPvars
.selectedPrinterName
);
216 tmp
= new JLabel("No printer selected.");
221 public JPanel
getPanel()
226 public void actionPerformed(ActionEvent e
)
228 // String source = e.getActionCommand();
229 Object source
= e
.getSource();
230 if (source
== completedButton
)
232 if (GLPvars
.showCompletedJobs
)
234 GLPvars
.showCompletedJobs
= !GLPvars
.showCompletedJobs
;
235 completedButton
.setText("Show Active");
236 completedButton
.setActionCommand("Show Active");
237 GLPvars
.tabs
.updateDetailPanel();
238 GLPvars
.tabs
.tabPanel
.setSelectedIndex(2);
242 completedButton
.setText("Show Completed");
243 completedButton
.setActionCommand("Show Completed");
244 GLPvars
.showCompletedJobs
= !GLPvars
.showCompletedJobs
;
245 GLPvars
.tabs
.updateDetailPanel();
246 GLPvars
.tabs
.tabPanel
.setSelectedIndex(2);
249 else if (source
== myJobsButton
)
251 if (GLPvars
.showMyJobs
)
253 GLPvars
.showMyJobs
= !GLPvars
.showMyJobs
;
254 myJobsButton
.setText("Show All Users");
255 myJobsButton
.setActionCommand("Show All Users");
256 GLPvars
.tabs
.updateDetailPanel();
257 GLPvars
.tabs
.tabPanel
.setSelectedIndex(2);
261 GLPvars
.showMyJobs
= !GLPvars
.showMyJobs
;
262 myJobsButton
.setText("Show My Jobs");
263 myJobsButton
.setActionCommand("Show My Jobs");
264 GLPvars
.tabs
.updateDetailPanel();
265 GLPvars
.tabs
.tabPanel
.setSelectedIndex(2);
268 else if (source
== printFileButton
)
272 GLPvars
.tabs
.updateOptionsPanel(printer
);
273 GLPvars
.tabs
.tabPanel
.setSelectedIndex(3);