Rev 91 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 91 | Rev 93 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | 39 | ||
40 | private ArrayList<Task> tasks = new ArrayList<Task>(); |
40 | private ArrayList<Task> tasks = new ArrayList<Task>(); |
41 | private javax.swing.Timer timer = new javax.swing.Timer(300000, this); |
41 | private javax.swing.Timer timer = new javax.swing.Timer(300000, this); |
42 | 42 | ||
43 | private MessageFormat timeFormat = new MessageFormat("{0,number}:{1,number,00}"); |
43 | private MessageFormat timeFormat = new MessageFormat("{0,number}:{1,number,00}"); |
- | 44 | private MessageFormat priceFormat = new MessageFormat("{0,number}.{1,number,00}"); |
|
44 | 45 | ||
45 | private TaskFrame taskFrame = null; |
46 | private TaskFrame taskFrame = null; |
46 | 47 | ||
47 | /**
|
48 | /**
|
48 | * Creates a new instance of TaskTableModel
|
49 | * Creates a new instance of TaskTableModel
|
Line 67... | Line 68... | ||
67 | return tasks.get(rowIndex).getName(); |
68 | return tasks.get(rowIndex).getName(); |
68 | case 1: |
69 | case 1: |
69 | long mins = tasks.get(rowIndex).getConsumption() / 60000; |
70 | long mins = tasks.get(rowIndex).getConsumption() / 60000; |
70 | BigDecimal hm[] = new BigDecimal((int) mins).divideAndRemainder(new BigDecimal(60)); |
71 | BigDecimal hm[] = new BigDecimal((int) mins).divideAndRemainder(new BigDecimal(60)); |
71 | return timeFormat.format(hm); |
72 | return timeFormat.format(hm); |
- | 73 | case 2: |
|
- | 74 | double tp = tasks.get(rowIndex).getTotalPrice(); |
|
- | 75 | BigDecimal pr[] = new BigDecimal(tp * 100).divideAndRemainder(new BigDecimal(100)); |
|
- | 76 | return priceFormat.format(pr); |
|
72 | default: return null; |
77 | default: return null; |
73 | }
|
78 | }
|
74 | }
|
79 | }
|
75 | 80 | ||
76 | /**
|
81 | /**
|
Line 84... | Line 89... | ||
84 | /**
|
89 | /**
|
85 | * Returns the column count (currently 2).
|
90 | * Returns the column count (currently 2).
|
86 | * @return column count
|
91 | * @return column count
|
87 | */
|
92 | */
|
88 | public int getColumnCount() { |
93 | public int getColumnCount() { |
89 | return 2; |
94 | return 3; |
90 | }
|
95 | }
|
91 | 96 | ||
92 | /**
|
97 | /**
|
93 | * Sets a new value of the given cell. If at least one of the
|
98 | * Sets a new value of the given cell. If at least one of the
|
94 | * coordinates is invalid it does nothing.
|
99 | * coordinates is invalid it does nothing.
|
Line 113... | Line 118... | ||
113 | @Override |
118 | @Override |
114 | public String getColumnName(int column) { |
119 | public String getColumnName(int column) { |
115 | switch (column) { |
120 | switch (column) { |
116 | case 0: return "Task name"; |
121 | case 0: return "Task name"; |
117 | case 1: return "Time consumption [h:min]"; |
122 | case 1: return "Time consumption [h:min]"; |
- | 123 | case 2: return "Total price"; |
|
118 | default: return ""; |
124 | default: return ""; |
119 | }
|
125 | }
|
120 | }
|
126 | }
|
121 | 127 | ||
122 | /**
|
128 | /**
|
Line 128... | Line 134... | ||
128 | @Override |
134 | @Override |
129 | public Class<?> getColumnClass(int columnIndex) { |
135 | public Class<?> getColumnClass(int columnIndex) { |
130 | switch (columnIndex) { |
136 | switch (columnIndex) { |
131 | case 0: return String.class; |
137 | case 0: return String.class; |
132 | case 1: return StringBuffer.class; |
138 | case 1: return StringBuffer.class; |
- | 139 | case 2: return StringBuffer.class; |
|
133 | default: return Void.class; |
140 | default: return Void.class; |
134 | }
|
141 | }
|
135 | }
|
142 | }
|
136 | 143 | ||
137 | /**
|
144 | /**
|
Line 144... | Line 151... | ||
144 | @Override |
151 | @Override |
145 | public boolean isCellEditable(int rowIndex, int columnIndex) { |
152 | public boolean isCellEditable(int rowIndex, int columnIndex) { |
146 | return columnIndex == 0; |
153 | return columnIndex == 0; |
147 | }
|
154 | }
|
148 | 155 | ||
- | 156 | public Task getTask(int index) { |
|
- | 157 | return tasks.get(index); |
|
- | 158 | }
|
|
- | 159 | ||
149 | /**
|
160 | /**
|
150 | * Creates a new task.
|
161 | * Creates a new task.
|
151 | */
|
162 | */
|
152 | public void addNewTask() { |
163 | public void addNewTask() { |
153 | Task t = new Task(); |
164 | Task t = new Task(); |
Line 181... | Line 192... | ||
181 | public void startTasks(int start, int end) { |
192 | public void startTasks(int start, int end) { |
182 | for (int i=start; i<=end; i++) { |
193 | for (int i=start; i<=end; i++) { |
183 | Task t = tasks.get(i); |
194 | Task t = tasks.get(i); |
184 | t.start(); |
195 | t.start(); |
185 | fireTableCellUpdated(i, 1); |
196 | fireTableCellUpdated(i, 1); |
- | 197 | fireTableCellUpdated(i, 2); |
|
186 | }
|
198 | }
|
187 | }
|
199 | }
|
188 | 200 | ||
189 | /**
|
201 | /**
|
190 | * Stops the given tasks.
|
202 | * Stops the given tasks.
|
Line 194... | Line 206... | ||
194 | public void stopTasks(int start, int end) { |
206 | public void stopTasks(int start, int end) { |
195 | for (int i=start; i<=end; i++) { |
207 | for (int i=start; i<=end; i++) { |
196 | Task t = tasks.get(i); |
208 | Task t = tasks.get(i); |
197 | t.stop(); |
209 | t.stop(); |
198 | fireTableCellUpdated(i, 1); |
210 | fireTableCellUpdated(i, 1); |
- | 211 | fireTableCellUpdated(i, 2); |
|
199 | }
|
212 | }
|
200 | }
|
213 | }
|
201 | 214 | ||
202 | /**
|
215 | /**
|
203 | * Stops all tasks.
|
216 | * Stops all tasks.
|
Line 219... | Line 232... | ||
219 | public void resetTasks(int start, int end) { |
232 | public void resetTasks(int start, int end) { |
220 | for (int i=start; i<=end; i++) { |
233 | for (int i=start; i<=end; i++) { |
221 | Task t = tasks.get(i); |
234 | Task t = tasks.get(i); |
222 | t.setConsumption(0); |
235 | t.setConsumption(0); |
223 | fireTableCellUpdated(i, 1); |
236 | fireTableCellUpdated(i, 1); |
- | 237 | fireTableCellUpdated(i, 2); |
|
224 | }
|
238 | }
|
225 | }
|
239 | }
|
226 | 240 | ||
227 | /**
|
241 | /**
|
228 | * Destroys the timer controlling automatic data saving.
|
242 | * Destroys the timer controlling automatic data saving.
|
Line 286... | Line 300... | ||
286 | String key = (String) it.next(); |
300 | String key = (String) it.next(); |
287 | if (key.endsWith(".name")) { |
301 | if (key.endsWith(".name")) { |
288 | String ids = key.substring(0, key.length() - 5); |
302 | String ids = key.substring(0, key.length() - 5); |
289 | String name = props.getProperty(ids + ".name"); |
303 | String name = props.getProperty(ids + ".name"); |
290 | String cons = props.getProperty(ids + ".consumption"); |
304 | String cons = props.getProperty(ids + ".consumption"); |
- | 305 | String price = props.getProperty(ids + ".price", "1"); |
|
291 | try { |
306 | try { |
292 | int id = Integer.parseInt(ids); |
307 | int id = Integer.parseInt(ids); |
293 | long cn = Long.parseLong(cons); |
308 | long cn = Long.parseLong(cons); |
- | 309 | double pr = Double.parseDouble(price); |
|
294 | Task t = new Task(id, name, cn); |
310 | Task t = new Task(id, name, cn, pr); |
295 | t.setActionListener(this); |
311 | t.setActionListener(this); |
296 | tasks.add(t); |
312 | tasks.add(t); |
297 | } catch (NumberFormatException e) { |
313 | } catch (NumberFormatException e) { |
298 | JOptionPane.showMessageDialog(null, "Cannot load data from file (bad format).", "Error", JOptionPane.ERROR_MESSAGE); |
314 | JOptionPane.showMessageDialog(null, "Cannot load data from file (bad format).", "Error", JOptionPane.ERROR_MESSAGE); |
299 | }
|
315 | }
|
Line 329... | Line 345... | ||
329 | for (int i=0; i<tasks.size(); i++) { |
345 | for (int i=0; i<tasks.size(); i++) { |
330 | Task t = tasks.get(i); |
346 | Task t = tasks.get(i); |
331 | String id = Integer.toString(t.getId()); |
347 | String id = Integer.toString(t.getId()); |
332 | props.setProperty(id + ".name", t.getName()); |
348 | props.setProperty(id + ".name", t.getName()); |
333 | props.setProperty(id + ".consumption", Long.toString(t.getConsumption())); |
349 | props.setProperty(id + ".consumption", Long.toString(t.getConsumption())); |
- | 350 | props.setProperty(id + ".price", Double.toString(t.getPrice())); |
|
334 | }
|
351 | }
|
335 | 352 | ||
336 | try { |
353 | try { |
337 | FileOutputStream os = new FileOutputStream(getPath()); |
354 | FileOutputStream os = new FileOutputStream(getPath()); |
338 | props.storeToXML(os, "LWTT task data"); |
355 | props.storeToXML(os, "LWTT task data"); |
Line 356... | Line 373... | ||
356 | saveToFile(); |
373 | saveToFile(); |
357 | }
|
374 | }
|
358 | else { |
375 | else { |
359 | int row = tasks.indexOf(src); |
376 | int row = tasks.indexOf(src); |
360 | fireTableCellUpdated(row, 1); |
377 | fireTableCellUpdated(row, 1); |
- | 378 | fireTableCellUpdated(row, 2); |
|
361 | }
|
379 | }
|
362 | }
|
380 | }
|
363 | 381 | ||
364 | }
|
382 | }
|