1 package info.mikethomas.fahview.v6project.panels;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import info.mikethomas.fahview.v6project.model.QueueImpl;
25 import info.mikethomas.fahview.v6project.utilities.ProgressCellRenderer;
26 import info.mikethomas.fahview.v6project.utilities.QueueReader;
27 import javax.swing.JTable;
28 import org.netbeans.api.settings.ConvertAsProperties;
29 import org.openide.awt.ActionID;
30 import org.openide.awt.ActionReference;
31 import org.openide.windows.TopComponent;
32 import org.openide.util.NbBundle.Messages;
33
34
35
36
37
38
39
40
41 @ConvertAsProperties(
42 dtd="-//info.mikethomas.fahview.v6project.panels//Queue//EN",
43 autostore=false
44 )
45 @TopComponent.Description(
46 preferredID="QueueTopComponent",
47 iconBase="info/mikethomas/fahview/v6project/queue.png",
48 persistenceType=TopComponent.PERSISTENCE_ALWAYS
49 )
50 @TopComponent.Registration(mode = "editor", openAtStartup = false)
51 @ActionID(category = "Window", id = "info.mikethomas.fahview.v6project.panels.QueueTopComponent")
52 @ActionReference(path = "Menu/Window" )
53 @TopComponent.OpenActionRegistration(
54 displayName = "#CTL_QueueAction",
55 preferredID="QueueTopComponent"
56 )
57 @Messages({
58 "CTL_QueueAction=Queue",
59 "CTL_QueueTopComponent=Queue Window",
60 "HINT_QueueTopComponent=This is a Queue window"
61 })
62 public final class QueueTopComponent extends TopComponent {
63
64
65
66 public QueueTopComponent() {
67 initComponents();
68 setName(Bundle.CTL_QueueTopComponent());
69 setToolTipText(Bundle.HINT_QueueTopComponent());
70
71 table.getColumn("Progress").setCellRenderer(new ProgressCellRenderer());
72 }
73
74
75
76
77
78
79
80
81 private void initComponents() {
82
83 queueWindow = new javax.swing.JScrollPane();
84 table = new javax.swing.JTable();
85
86 table.setModel(new javax.swing.table.DefaultTableModel(
87 new Object [][] {
88 {"0", null, "0%", null},
89 {"1", null, "0%", null},
90 {"2", null, "0%", null},
91 {"3", null, "0%", null},
92 {"4", null, "0%", null},
93 {"5", null, "0%", null},
94 {"6", null, "0%", null},
95 {"7", null, "0%", null},
96 {"8", null, "0%", null},
97 {"9", null, "0%", null}
98 },
99 new String [] {
100 "Position", "Status", "Progress", "Project"
101 }
102 ) {
103 Class[] types = new Class [] {
104 java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class
105 };
106 boolean[] canEdit = new boolean [] {
107 true, false, true, false
108 };
109
110 public Class getColumnClass(int columnIndex) {
111 return types [columnIndex];
112 }
113
114 public boolean isCellEditable(int rowIndex, int columnIndex) {
115 return canEdit [columnIndex];
116 }
117 });
118 table.setDoubleBuffered(true);
119 queueWindow.setViewportView(table);
120
121 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
122 this.setLayout(layout);
123 layout.setHorizontalGroup(
124 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
125 .add(layout.createSequentialGroup()
126 .addContainerGap()
127 .add(queueWindow, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE)
128 .addContainerGap())
129 );
130 layout.setVerticalGroup(
131 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
132 .add(layout.createSequentialGroup()
133 .addContainerGap()
134 .add(queueWindow, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 181, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
135 .addContainerGap(113, Short.MAX_VALUE))
136 );
137 }
138
139
140
141 private javax.swing.JScrollPane queueWindow;
142 private javax.swing.JTable table;
143
144
145
146 @Override
147 public void componentOpened() {
148
149
150 QueueImpl queue = new QueueImpl(new QueueReader("/Users/mike/SkyDrive/Documents/University/Year 3/Computing Project/FAH/Core1/queue.dat"));
151 System.out.println(queue);
152
153
154 int current = queue.getCurrent();
155 getTable().getSelectionModel().setSelectionInterval(current, current);
156
157
158 for (int i = 0; i <= 9; i++) {
159 int status = queue.getQueueIndex(i).getStat();
160 String percentage = queue.getQueueIndex(i).getWuid().getPercentage();
161 int proj = queue.getQueueIndex(i).getWuid().getProj();
162 int run = queue.getQueueIndex(i).getWuid().getRun();
163 int clone = queue.getQueueIndex(i).getWuid().getClone();
164 int gen = queue.getQueueIndex(i).getWuid().getGen();
165 String project =
166 proj + " (Run "
167 + run + ", Clone "
168 + clone + ", Gen "
169 + gen + ")";
170 setStatus(i, status);
171 setPercentage(i, percentage);
172 setProject(i, project);
173 }
174 }
175
176
177 @Override
178 public void componentClosed() {
179
180 }
181
182
183
184
185
186
187 void writeProperties(java.util.Properties p) {
188
189
190 p.setProperty("version", "1.0");
191
192 }
193
194
195
196
197
198 void readProperties(java.util.Properties p) {
199 String version = p.getProperty("version");
200
201 }
202
203
204
205
206
207
208 public JTable getTable() {
209 return table;
210 }
211
212
213
214
215
216
217
218
219 protected void setStatus(int position, int value) {
220 table.getModel().setValueAt(value, position, 1);
221 }
222
223
224
225
226
227
228
229
230 protected void setPercentage(int position, String value) {
231 table.getModel().setValueAt(value, position, 2);
232 }
233
234
235
236
237
238
239
240
241 protected void setProject(int position, String value) {
242 table.getModel().setValueAt(value, position, 3);
243 }
244 }