Load cups into easysw/current.
[thirdparty/cups.git] / scripting / java / example / GLPdetail.java
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 GLPdetail implements ActionListener 
11 {
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;
17
18     private JLabel  tmp           = null;
19
20     private JButton completedButton = null;
21     private JButton myJobsButton    = null;
22     private JButton printFileButton = null;
23
24     private String completedText = "Show Completed";
25     private String myJobsText    = "Show My Jobs";
26     private String printFileText = "Print a file";
27
28     private GLPprinterDetail detail = null;
29     private GLPjobList       joblist = null;
30     private CupsPrinter      printer = null;
31     private Cups             cups   = null;
32
33
34     public GLPdetail()
35     {
36       URL           u;
37
38       mainPanel = new JPanel();
39       mainPanel.setBackground(GLPcolors.backgroundColor);
40
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);
49    
50       completedButton.setActionCommand(completedText);
51       completedButton.addActionListener(this); 
52
53       myJobsButton.setActionCommand(myJobsText);
54       myJobsButton.addActionListener(this); 
55
56       printFileButton.setActionCommand(printFileText);
57       printFileButton.addActionListener(this); 
58
59       completedButton.setBackground(GLPcolors.buttonBackgroundColor);
60       completedButton.setForeground(GLPcolors.buttonForegroundColor);
61
62       myJobsButton.setBackground(GLPcolors.buttonBackgroundColor);
63       myJobsButton.setForeground(GLPcolors.buttonForegroundColor);
64
65       printFileButton.setBackground(GLPcolors.buttonBackgroundColor);
66       printFileButton.setForeground(GLPcolors.buttonForegroundColor);
67
68       controlPanel.add(completedButton);
69       controlPanel.add(myJobsButton);
70       controlPanel.add(printFileButton);
71
72       //  -----------------------------------------------------------
73       //
74       //  Now get the printer objects
75       //
76       if (GLPvars.selectedPrinterName != null)
77       {
78         try
79         {
80             u    = new URL("http://" + GLPvars.getServerName() + 
81                            ":631/printers/" + GLPvars.selectedPrinterName );
82             cups = new Cups(u);
83             cups.setUser(GLPvars.cupsUser);
84             cups.setPasswd(GLPvars.cupsPasswd);
85             printer = new CupsPrinter( cups, GLPvars.selectedPrinterName );
86
87             detail = new GLPprinterDetail( printer );
88             joblist = new GLPjobList(printer);
89
90             detailPanel = detail.getPanel();
91             jobPanel    = joblist.getPanel();
92
93             mainLayout = new BoxLayout(mainPanel, BoxLayout.Y_AXIS);
94             mainPanel.setLayout(mainLayout);
95             mainPanel.add(detailPanel);
96             mainPanel.add(controlPanel);
97             mainPanel.add(jobPanel);
98         }
99         catch (IOException e)
100         {
101           tmp = new JLabel("Error loading printer: " + GLPvars.selectedPrinterName);
102           mainPanel.add(tmp);
103           return;
104         }
105       }
106       else
107       {
108         tmp = new JLabel("No printer selected.");
109         mainPanel.add(tmp);
110       }
111
112
113     } // 
114
115
116
117     public void topDetail()
118     {
119       URL           u;
120
121       mainPanel = new JPanel();
122       mainPanel.setBackground(GLPcolors.backgroundColor);
123
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);
132    
133       if (GLPvars.showCompletedJobs)
134       {
135         completedButton.setText("Show Active");
136         completedButton.setActionCommand("Show Active");
137       }
138       else
139       {
140         completedButton.setText("Show Completed");
141         completedButton.setActionCommand("Show Completed");
142       }
143       completedButton.addActionListener(this); 
144
145       if (GLPvars.showMyJobs)
146       {
147         myJobsButton.setText("Show All Users");
148         myJobsButton.setActionCommand("Show All Users");
149       }
150       else
151       {
152         myJobsButton.setText("Show My Jobs");
153         myJobsButton.setActionCommand("Show My Jobs");
154       }
155       myJobsButton.addActionListener(this); 
156
157       printFileButton.setActionCommand(printFileText);
158       printFileButton.addActionListener(this); 
159    
160       completedButton.setBackground(GLPcolors.buttonBackgroundColor);
161       completedButton.setForeground(GLPcolors.buttonForegroundColor);
162
163       myJobsButton.setBackground(GLPcolors.buttonBackgroundColor);
164       myJobsButton.setForeground(GLPcolors.buttonForegroundColor);
165
166       printFileButton.setBackground(GLPcolors.buttonBackgroundColor);
167       printFileButton.setForeground(GLPcolors.buttonForegroundColor);
168
169       controlPanel.add(completedButton);
170       controlPanel.add(myJobsButton);
171       controlPanel.add(printFileButton);
172
173       //  -----------------------------------------------------------
174       //
175       //  Now get the printer objects
176       //
177       if (GLPvars.selectedPrinterName != null)
178       {
179         try
180         {
181             //
182             //  Create connection
183             //
184             u    = new URL("http://" + GLPvars.getServerName() + 
185                            ":631/printers/" + GLPvars.selectedPrinterName );  
186             cups = new Cups(u);
187             cups.setUser(GLPvars.cupsUser);
188             cups.setPasswd(GLPvars.cupsPasswd);
189             //
190             //
191
192             printer = new CupsPrinter( cups, GLPvars.selectedPrinterName );
193             detail  = new GLPprinterDetail( printer );
194             joblist = new GLPjobList(printer);
195
196             detailPanel = detail.getPanel();
197
198             jobPanel    = joblist.getPanel();
199
200             mainLayout = new BoxLayout(mainPanel, BoxLayout.Y_AXIS);
201             mainPanel.setLayout(mainLayout);
202             mainPanel.add(detailPanel);
203             mainPanel.add(controlPanel);
204             mainPanel.add(jobPanel);
205         }
206         catch (IOException e)
207         {
208           tmp = new JLabel("IOException while loading printer: " + 
209                 GLPvars.selectedPrinterName);
210           mainPanel.add(tmp);
211           return;
212         }
213       }
214       else
215       {
216         tmp = new JLabel("No printer selected.");
217         mainPanel.add(tmp);
218       }
219     }
220
221     public JPanel getPanel()
222     {
223       return(mainPanel);
224     }
225
226     public void actionPerformed(ActionEvent e)
227     {
228       // String source = e.getActionCommand();
229       Object source = e.getSource();
230       if (source == completedButton)
231       {
232         if (GLPvars.showCompletedJobs)
233         {
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);
239         }
240         else
241         {
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);
247         }
248       }
249       else if (source == myJobsButton)
250       {
251         if (GLPvars.showMyJobs)
252         {
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);
258         }
259         else
260         {
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);
266         }
267       }
268       else if (source == printFileButton)
269       {
270         if (printer != null)
271         {
272           GLPvars.tabs.updateOptionsPanel(printer);
273           GLPvars.tabs.tabPanel.setSelectedIndex(3);
274         }
275       }
276     }
277
278 }
279