]> git.ipfire.org Git - thirdparty/cups.git/blob - scripting/java/example/GLPjobList.java
Add missing files for test.
[thirdparty/cups.git] / scripting / java / example / GLPjobList.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 java.util.*;
9 import com.easysw.cups.*;
10
11 public class GLPjobList implements ActionListener
12 {
13 Cups cups = null;
14 GridLayout mainLayout = null;
15 JPanel errorPanel = null;
16 JScrollPane jobPane = null;
17
18 public GLPjobList(CupsPrinter cp)
19 {
20 load(cp);
21 }
22
23 // Constructor
24 public void load(CupsPrinter cp)
25 {
26 URL u;
27 CupsJob[] jobs;
28 int num_jobs = 0;
29
30 try
31 {
32 u = new URL("http://" + GLPvars.cupsServerName + ":631/printers/" +
33 cp.getPrinterName());
34 cups = new Cups(u);
35 cups.setUser(GLPvars.cupsUser);
36 cups.setPasswd(GLPvars.cupsPasswd);
37
38 jobs = cups.cupsGetJobs(GLPvars.showMyJobs,
39 GLPvars.showCompletedJobs );
40 }
41 catch (IOException e)
42 {
43 GLPjobTableModel tm = new GLPjobTableModel(1,1);
44 tm.setValueAt("Error getting job list(IOException)",0,0);
45 JTable table = new JTable(tm);
46 jobPane = new JScrollPane(table);
47 jobPane.setBackground(GLPcolors.backgroundColor);
48 return;
49 }
50
51 if (jobs == null)
52 {
53 String job_user = "";
54 String job_type = "";
55 if (GLPvars.showCompletedJobs)
56 job_type = "No completed jobs";
57 else
58 job_type = "No active jobs";
59 if (GLPvars.showMyJobs)
60 job_user = " for " + GLPvars.cupsUser;
61
62 GLPjobTableModel tm = new GLPjobTableModel(1,1);
63 tm.setValueAt(job_type + job_user + ".",0,0);
64 JTable table = new JTable(tm);
65 jobPane = new JScrollPane(table);
66 jobPane.setBackground(GLPcolors.backgroundColor);
67 return;
68 }
69
70 num_jobs = jobs.length;
71 int jobcount = 0;
72 for (int i=0; i < num_jobs; i++)
73 {
74 if (jobs[i].job_id < 0)
75 continue;
76 jobcount++;
77 }
78
79 if (jobcount < 1)
80 {
81 GLPjobTableModel tm = new GLPjobTableModel(1,1);
82 String comp_str = "active";
83 if (GLPvars.showCompletedJobs)
84 comp_str = "completed";
85
86 tm.setValueAt("No " + comp_str + " jobs on " +
87 cp.getPrinterName(),0,0);
88 JTable table = new JTable(tm);
89 jobPane = new JScrollPane(table);
90 jobPane.setBackground(GLPcolors.backgroundColor);
91 return;
92 }
93
94 GLPjobTableModel tm = new GLPjobTableModel(jobcount,6);
95 tm.setColumnName(0,"ID");
96 tm.setColumnName(1,"Name");
97 tm.setColumnName(2,"User");
98 tm.setColumnName(3,"Create Time");
99 tm.setColumnName(4,"Size");
100 tm.setColumnName(5,"Status");
101
102 String szString;
103 Date date = new Date();
104 int currjob = 0;
105 for (int i=0; i < num_jobs; i++)
106 {
107 //
108 // Bug in cupsGetJobs?
109 //
110 if (jobs[i].job_id < 0)
111 continue;
112
113 tm.setValueAt( new Integer( jobs[i].job_id), currjob, 0 );
114 tm.setValueAt( (Object)jobs[i].job_name, currjob, 1 );
115 tm.setValueAt( (Object)jobs[i].job_originating_user_name,currjob,2);
116
117 date.setTime(jobs[i].time_at_creation * 1000);
118 tm.setValueAt( date.toString(), currjob, 3 );
119
120 if (jobs[i].job_k_octets < 1000)
121 szString = Integer.toString(jobs[i].job_k_octets) + "k";
122 else
123 szString = Double.toString((float)jobs[i].job_k_octets / 1000.0) + "mb";
124 tm.setValueAt( szString, currjob, 4 );
125 tm.setValueAt( jobs[i].jobStatusText(), currjob, 5 );
126 currjob++;
127 }
128
129 JTable table = new JTable( tm );
130
131 jobPane = new JScrollPane(table);
132 jobPane.setBackground(GLPcolors.backgroundColor);
133 jobPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
134 jobPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
135 }
136
137 public void actionPerformed(ActionEvent e)
138 {
139 // if (e.getActionCommand().equals(maskFieldString))
140 // {
141 // }
142 }
143
144
145 public JScrollPane getPanel()
146 {
147 return(jobPane);
148 }
149
150 }