1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import jalview.bin.Cache; |
24 |
|
import jalview.util.MessageManager; |
25 |
|
|
26 |
|
import java.awt.BorderLayout; |
27 |
|
import java.awt.Component; |
28 |
|
import java.awt.Dialog.ModalExclusionType; |
29 |
|
import java.awt.Dimension; |
30 |
|
import java.awt.Font; |
31 |
|
import java.awt.Rectangle; |
32 |
|
import java.awt.event.ActionEvent; |
33 |
|
import java.awt.event.ActionListener; |
34 |
|
import java.awt.event.KeyEvent; |
35 |
|
import java.awt.event.MouseEvent; |
36 |
|
import java.awt.event.WindowAdapter; |
37 |
|
import java.awt.event.WindowEvent; |
38 |
|
import java.beans.PropertyChangeListener; |
39 |
|
import java.text.DateFormat; |
40 |
|
import java.text.SimpleDateFormat; |
41 |
|
import java.util.ArrayList; |
42 |
|
import java.util.Calendar; |
43 |
|
import java.util.Collections; |
44 |
|
import java.util.Date; |
45 |
|
import java.util.Iterator; |
46 |
|
import java.util.List; |
47 |
|
import java.util.Map; |
48 |
|
|
49 |
|
import javax.swing.AbstractAction; |
50 |
|
import javax.swing.AbstractButton; |
51 |
|
import javax.swing.Action; |
52 |
|
import javax.swing.DefaultListCellRenderer; |
53 |
|
import javax.swing.DefaultListModel; |
54 |
|
import javax.swing.Icon; |
55 |
|
import javax.swing.ImageIcon; |
56 |
|
import javax.swing.JButton; |
57 |
|
import javax.swing.JFrame; |
58 |
|
import javax.swing.JLabel; |
59 |
|
import javax.swing.JList; |
60 |
|
import javax.swing.JMenuItem; |
61 |
|
import javax.swing.JPanel; |
62 |
|
import javax.swing.JPopupMenu; |
63 |
|
import javax.swing.JScrollPane; |
64 |
|
import javax.swing.JSplitPane; |
65 |
|
import javax.swing.JToolBar; |
66 |
|
import javax.swing.ListSelectionModel; |
67 |
|
import javax.swing.SwingUtilities; |
68 |
|
import javax.swing.event.HyperlinkEvent; |
69 |
|
import javax.swing.event.HyperlinkListener; |
70 |
|
import javax.swing.event.ListSelectionEvent; |
71 |
|
import javax.swing.event.ListSelectionListener; |
72 |
|
|
73 |
|
import org.robsite.jswingreader.action.MarkChannelAsRead; |
74 |
|
import org.robsite.jswingreader.action.MarkChannelAsUnread; |
75 |
|
import org.robsite.jswingreader.action.MarkItemAsRead; |
76 |
|
import org.robsite.jswingreader.action.MarkItemAsUnread; |
77 |
|
import org.robsite.jswingreader.action.UpdatableAction; |
78 |
|
import org.robsite.jswingreader.model.Channel; |
79 |
|
import org.robsite.jswingreader.model.ChannelListModel; |
80 |
|
import org.robsite.jswingreader.model.Item; |
81 |
|
import org.robsite.jswingreader.model.SimpleRSSParser; |
82 |
|
import org.robsite.jswingreader.ui.BlogContentPane; |
83 |
|
import org.robsite.jswingreader.ui.ItemReadTimer; |
84 |
|
import org.robsite.jswingreader.ui.Main; |
85 |
|
import org.robsite.jswingreader.ui.util.ContextMenuMouseAdapter; |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
|
|
| 61.2% |
Uncovered Elements: 140 (361) |
Complexity: 98 |
Complexity Density: 0.42 |
|
92 |
|
public class BlogReader extends JPanel |
93 |
|
{ |
94 |
|
private JButton buttonRefresh = new JButton(); |
95 |
|
|
96 |
|
private JToolBar toolBar = new JToolBar(); |
97 |
|
|
98 |
|
private JLabel statusBar = new JLabel(); |
99 |
|
|
100 |
|
private JPanel panelMain = new JPanel(); |
101 |
|
|
102 |
|
private BorderLayout layoutMain = new BorderLayout(); |
103 |
|
|
104 |
|
private BorderLayout borderLayout1 = new BorderLayout(); |
105 |
|
|
106 |
|
private JPanel topPanel = new JPanel(); |
107 |
|
|
108 |
|
private JPanel bottomPanel = new JPanel(); |
109 |
|
|
110 |
|
private JSplitPane topBottomSplitPane = new JSplitPane(); |
111 |
|
|
112 |
|
private JList listItems = new JList(new DefaultListModel()); |
113 |
|
|
114 |
|
|
115 |
|
private BlogContentPane textDescription = new BlogContentPane(); |
116 |
|
|
117 |
|
|
118 |
|
private BorderLayout borderLayout4 = new BorderLayout(); |
119 |
|
|
120 |
|
private BorderLayout borderLayout5 = new BorderLayout(); |
121 |
|
|
122 |
|
private ChannelListModel _channelModel = null; |
123 |
|
|
124 |
|
private JList listChannels = new JList(); |
125 |
|
|
126 |
|
private Action exitAction = new Action() |
127 |
|
{ |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
129 |
0 |
@Override... |
130 |
|
public void actionPerformed(ActionEvent arg0) |
131 |
|
{ |
132 |
0 |
if (xf != null) |
133 |
|
{ |
134 |
0 |
xf.dispose(); |
135 |
|
} |
136 |
0 |
xf = null; |
137 |
0 |
jd = null; |
138 |
0 |
if (parent != null) |
139 |
|
{ |
140 |
0 |
parent.showNews(false); |
141 |
|
} |
142 |
|
|
143 |
|
} |
144 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
145 |
0 |
@Override... |
146 |
|
public void setEnabled(boolean arg0) |
147 |
|
{ |
148 |
|
|
149 |
|
} |
150 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
151 |
0 |
@Override... |
152 |
|
public void removePropertyChangeListener(PropertyChangeListener arg0) |
153 |
|
{ |
154 |
|
|
155 |
|
|
156 |
|
} |
157 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
158 |
0 |
@Override... |
159 |
|
public void putValue(String arg0, Object arg1) |
160 |
|
{ |
161 |
|
|
162 |
|
|
163 |
|
} |
164 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
0 |
@Override... |
166 |
|
public boolean isEnabled() |
167 |
|
{ |
168 |
|
|
169 |
0 |
return true; |
170 |
|
} |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
0 |
@Override... |
173 |
|
public Object getValue(String arg0) |
174 |
|
{ |
175 |
|
|
176 |
0 |
return null; |
177 |
|
} |
178 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
179 |
0 |
@Override... |
180 |
|
public void addPropertyChangeListener(PropertyChangeListener arg0) |
181 |
|
{ |
182 |
|
|
183 |
|
|
184 |
|
} |
185 |
|
}; |
186 |
|
|
187 |
|
private JFrame xf = null; |
188 |
|
|
189 |
|
private JalviewDialog jd = null; |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
191 |
1 |
private JalviewDialog createDialog()... |
192 |
|
{ |
193 |
|
|
194 |
1 |
return jd = new JalviewDialog() |
195 |
|
{ |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
197 |
0 |
@Override... |
198 |
|
protected void raiseClosed() |
199 |
|
{ |
200 |
0 |
if (parent != null) |
201 |
|
{ |
202 |
0 |
Cache.log.debug("News window closed."); |
203 |
0 |
jd = null; |
204 |
0 |
parent.showNews(false); |
205 |
|
} |
206 |
|
} |
207 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
208 |
0 |
@Override... |
209 |
|
protected void okPressed() |
210 |
|
{ |
211 |
|
|
212 |
|
|
213 |
|
} |
214 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
215 |
0 |
@Override... |
216 |
|
protected void cancelPressed() |
217 |
|
{ |
218 |
|
|
219 |
|
|
220 |
|
} |
221 |
|
}; |
222 |
|
}; |
223 |
|
|
224 |
|
private JLabel lblChannels = new JLabel(); |
225 |
|
|
226 |
|
private List _updatableActions = new ArrayList(); |
227 |
|
|
228 |
|
private ItemReadTimer _itemTimer = null; |
229 |
|
|
230 |
|
private JPopupMenu _popupItems = null; |
231 |
|
|
232 |
|
private JPopupMenu _popupChannels = null; |
233 |
|
|
234 |
|
private String lastm = ""; |
235 |
|
|
236 |
|
private boolean newsnew = false; |
237 |
|
|
238 |
|
private Desktop parent = null; |
239 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
240 |
0 |
BlogReader()... |
241 |
|
{ |
242 |
0 |
this(null); |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
private boolean updating = false; |
247 |
|
|
|
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 3 |
Complexity Density: 0.16 |
|
248 |
3 |
public BlogReader(Desktop desktop)... |
249 |
|
{ |
250 |
3 |
Cache.log.debug("Constructing news reader."); |
251 |
|
|
252 |
3 |
parent = desktop; |
253 |
3 |
_channelModel = new ChannelListModel(); |
254 |
|
|
255 |
3 |
Channel chan = new Channel(); |
256 |
3 |
chan.setURL( |
257 |
|
jalview.bin.Cache.getDefault("JALVIEW_NEWS_RSS", |
258 |
|
jalview.bin.Cache.getDefault("www.jalview.org", |
259 |
|
"http://www.jalview.org") |
260 |
|
+ "/feeds/desktop/rss")); |
261 |
3 |
loadLastM(); |
262 |
3 |
_channelModel.addChannel(chan); |
263 |
3 |
updating = true; |
264 |
3 |
try |
265 |
|
{ |
266 |
3 |
jbInit(); |
267 |
3 |
postInit(); |
268 |
|
} catch (Exception e) |
269 |
|
{ |
270 |
0 |
e.printStackTrace(); |
271 |
|
} |
272 |
|
|
273 |
3 |
initItems(chan); |
274 |
3 |
updating = false; |
275 |
3 |
boolean setvisible = checkForNew(chan, true); |
276 |
|
|
277 |
3 |
if (setvisible) |
278 |
|
{ |
279 |
|
|
280 |
1 |
Cache.log.debug("Will show jalview news automatically"); |
281 |
1 |
showNews(); |
282 |
|
} |
283 |
3 |
Cache.log.debug("Completed construction of reader."); |
284 |
|
|
285 |
|
} |
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
290 |
50 |
@Override... |
291 |
|
public boolean isVisible() |
292 |
|
{ |
293 |
50 |
if (parent == null) |
294 |
|
{ |
295 |
0 |
return xf != null && xf.isVisible(); |
296 |
|
} |
297 |
50 |
return jd != null && jd.isVisible(); |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
303 |
1 |
public void showNews()... |
304 |
|
{ |
305 |
1 |
final BlogReader me = this; |
306 |
1 |
SwingUtilities.invokeLater(new Runnable() |
307 |
|
{ |
|
|
| 60% |
Uncovered Elements: 6 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
308 |
1 |
@Override... |
309 |
|
public void run() |
310 |
|
{ |
311 |
1 |
Rectangle bounds = new Rectangle(5, 5, 550, 350); |
312 |
1 |
if (parent == null) |
313 |
|
{ |
314 |
0 |
xf = new JFrame(); |
315 |
0 |
xf.setContentPane(me); |
316 |
0 |
xf.addWindowListener(new WindowAdapter() |
317 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
318 |
0 |
@Override... |
319 |
|
public void windowClosing(WindowEvent e) |
320 |
|
{ |
321 |
0 |
ActionEvent actionEvent = new ActionEvent(this, |
322 |
|
ActionEvent.ACTION_FIRST, |
323 |
|
(String) exitAction.getValue(Action.NAME)); |
324 |
0 |
exitAction.actionPerformed(actionEvent); |
325 |
|
} |
326 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
327 |
0 |
@Override... |
328 |
|
public void windowOpened(WindowEvent e) |
329 |
|
{ |
330 |
|
} |
331 |
|
}); |
332 |
0 |
me.setSize(new Dimension(550, 350)); |
333 |
0 |
xf.setVisible(true); |
334 |
|
} |
335 |
|
else |
336 |
|
{ |
337 |
1 |
createDialog(); |
338 |
1 |
bounds = new Rectangle(5, 5, 550, 350); |
339 |
1 |
jd.initDialogFrame(me, false, false, |
340 |
|
MessageManager.getString("label.news_from_jalview"), |
341 |
|
bounds.width, bounds.height); |
342 |
1 |
jd.frame.setModalExclusionType(ModalExclusionType.NO_EXCLUDE); |
343 |
1 |
Cache.log.debug("Displaying news."); |
344 |
1 |
jd.waitForInput(); |
345 |
|
} |
346 |
|
} |
347 |
|
}); |
348 |
|
} |
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
|
|
| 83.8% |
Uncovered Elements: 6 (37) |
Complexity: 17 |
Complexity Density: 0.81 |
|
353 |
9 |
private boolean checkForNew(Channel chan, boolean updateItems)... |
354 |
|
{ |
355 |
|
|
356 |
9 |
if (!updating || updateItems) |
357 |
|
{ |
358 |
9 |
newsnew = false; |
359 |
|
} |
360 |
9 |
java.util.Date earliest = null; |
361 |
9 |
try |
362 |
|
{ |
363 |
9 |
earliest = new SimpleDateFormat("YYYY-MM-DD") |
364 |
|
.parse(chan.getHTTPLastModified()); |
365 |
|
} catch (Exception x) |
366 |
|
{ |
367 |
|
} |
368 |
9 |
; |
369 |
9 |
if (chan != null && chan.getItems() != null) |
370 |
|
{ |
371 |
9 |
Cache.log.debug("Scanning news items: newsnew=" + newsnew |
372 |
|
+ " and lastDate is " + lastDate); |
373 |
9 |
for (Item i : (List<Item>) chan.getItems()) |
374 |
|
{ |
375 |
90 |
Date published = i.getPublishDate(); |
376 |
90 |
boolean isread = lastDate == null ? false |
377 |
|
: (published != null && !lastDate.before(published)); |
378 |
|
|
379 |
90 |
if (!updating || updateItems) |
380 |
|
{ |
381 |
90 |
newsnew |= !isread; |
382 |
|
} |
383 |
90 |
if (updateItems) |
384 |
|
{ |
385 |
30 |
i.setRead(isread); |
386 |
|
} |
387 |
90 |
if (published != null && !i.isRead()) |
388 |
|
{ |
389 |
40 |
if (earliest == null || earliest.after(published)) |
390 |
|
{ |
391 |
40 |
earliest = published; |
392 |
|
} |
393 |
|
} |
394 |
|
} |
395 |
|
} |
396 |
9 |
if (!updateItems && !updating && lastDate == null) |
397 |
|
{ |
398 |
0 |
lastDate = earliest; |
399 |
|
} |
400 |
9 |
return newsnew; |
401 |
|
} |
402 |
|
|
403 |
|
java.util.Date lastDate = null; |
404 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
405 |
3 |
private void loadLastM()... |
406 |
|
{ |
407 |
3 |
lastDate = Cache.getDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED"); |
408 |
|
} |
409 |
|
|
|
|
| 84.2% |
Uncovered Elements: 3 (19) |
Complexity: 7 |
Complexity Density: 0.78 |
|
410 |
6 |
private void saveLastM(Item item)... |
411 |
|
{ |
412 |
6 |
if (item != null) |
413 |
|
{ |
414 |
6 |
if (item.getPublishDate() != null) |
415 |
|
{ |
416 |
4 |
if (lastDate == null || item.getPublishDate().after(lastDate)) |
417 |
|
{ |
418 |
1 |
lastDate = item.getPublishDate(); |
419 |
|
} |
420 |
|
} |
421 |
|
|
422 |
6 |
if (_channelModel.getElementAt(0) != null) |
423 |
|
{ |
424 |
6 |
checkForNew((Channel) _channelModel.getElementAt(0), false); |
425 |
|
} |
426 |
6 |
if (lastDate != null) |
427 |
|
{ |
428 |
6 |
String formatted = Cache |
429 |
|
.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", lastDate); |
430 |
6 |
Cache.log.debug("Saved last read date as " + formatted); |
431 |
|
} |
432 |
|
} |
433 |
|
} |
434 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 1 |
Complexity Density: 0.03 |
|
435 |
3 |
private void jbInit() throws Exception... |
436 |
|
{ |
437 |
3 |
setLayout(layoutMain); |
438 |
3 |
panelMain.setLayout(borderLayout1); |
439 |
3 |
topPanel.setLayout(borderLayout5); |
440 |
3 |
bottomPanel.setLayout(borderLayout4); |
441 |
3 |
topBottomSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); |
442 |
3 |
topBottomSplitPane.setDividerLocation(100); |
443 |
3 |
topBottomSplitPane.setTopComponent(topPanel); |
444 |
3 |
topBottomSplitPane.setBottomComponent(bottomPanel); |
445 |
3 |
JScrollPane spTextDescription = new JScrollPane(textDescription); |
446 |
3 |
textDescription.setText(""); |
447 |
3 |
statusBar.setText(new StringBuffer("[") |
448 |
|
.append(MessageManager.getString("label.status")).append("]") |
449 |
|
.toString()); |
450 |
3 |
buttonRefresh.addActionListener(new ActionListener() |
451 |
|
{ |
452 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
453 |
0 |
@Override... |
454 |
|
public void actionPerformed(ActionEvent e) |
455 |
|
{ |
456 |
0 |
refreshNews(); |
457 |
|
} |
458 |
|
}); |
459 |
3 |
add(statusBar, BorderLayout.SOUTH); |
460 |
3 |
toolBar.add(buttonRefresh); |
461 |
3 |
toolBar.addSeparator(); |
462 |
3 |
JLabel about = new JLabel( |
463 |
|
"brought to you by JSwingReader (jswingreader.sourceforge.net)"); |
464 |
3 |
toolBar.add(about); |
465 |
3 |
toolBar.setFloatable(false); |
466 |
3 |
add(toolBar, BorderLayout.NORTH); |
467 |
3 |
panelMain.add(topBottomSplitPane, BorderLayout.CENTER); |
468 |
3 |
add(panelMain, BorderLayout.CENTER); |
469 |
3 |
JScrollPane spListItems = new JScrollPane(listItems); |
470 |
3 |
listItems |
471 |
|
.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); |
472 |
3 |
topPanel.add(spListItems, BorderLayout.CENTER); |
473 |
3 |
bottomPanel.add(spTextDescription, BorderLayout.CENTER); |
474 |
3 |
listChannels.setModel(_channelModel); |
475 |
|
|
476 |
3 |
listItems.addMouseListener(new java.awt.event.MouseAdapter() |
477 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
478 |
0 |
@Override... |
479 |
|
public void mouseClicked(MouseEvent e) |
480 |
|
{ |
481 |
0 |
listItems_mouseClicked(e); |
482 |
|
} |
483 |
|
}); |
484 |
3 |
_popupItems = _buildItemsPopupMenu(); |
485 |
3 |
_popupChannels = _buildChannelsPopupMenu(); |
486 |
3 |
ContextMenuMouseAdapter popupAdapter = new ContextMenuMouseAdapter( |
487 |
|
_popupItems); |
488 |
3 |
ContextMenuMouseAdapter popupChannelsAdapter = new ContextMenuMouseAdapter( |
489 |
|
_popupChannels); |
490 |
3 |
listItems.addMouseListener(popupAdapter); |
491 |
3 |
listItems.setCellRenderer(new ItemsRenderer()); |
492 |
3 |
lblChannels.setText(MessageManager.getString("label.channels")); |
493 |
|
} |
494 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
495 |
3 |
private void postInit()... |
496 |
|
{ |
497 |
|
|
498 |
3 |
for (HyperlinkListener hll : textDescription.getHyperlinkListeners()) |
499 |
|
{ |
500 |
3 |
textDescription.removeHyperlinkListener(hll); |
501 |
|
} |
502 |
3 |
textDescription.addHyperlinkListener(new HyperlinkListener() |
503 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
504 |
0 |
@Override... |
505 |
|
public void hyperlinkUpdate(HyperlinkEvent e) |
506 |
|
{ |
507 |
0 |
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) |
508 |
|
{ |
509 |
0 |
Desktop.showUrl(e.getURL().toExternalForm()); |
510 |
|
} |
511 |
|
} |
512 |
|
}); |
513 |
|
|
514 |
3 |
listItems.addListSelectionListener(new ListSelectionListener() |
515 |
|
{ |
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
516 |
3 |
@Override... |
517 |
|
public void valueChanged(ListSelectionEvent e) |
518 |
|
{ |
519 |
3 |
if (e.getValueIsAdjusting() == false) |
520 |
|
{ |
521 |
3 |
_itemsValueChanged(listItems); |
522 |
|
} |
523 |
|
} |
524 |
|
}); |
525 |
3 |
listChannels.setSelectedIndex(1); |
526 |
3 |
_updateAllActions(); |
527 |
3 |
_updateToolbarButtons(); |
528 |
|
|
529 |
3 |
_itemTimer = new ItemReadTimer(listChannels, listItems); |
530 |
3 |
_itemsValueChanged(listItems); |
531 |
|
} |
532 |
|
|
|
|
| 20.8% |
Uncovered Elements: 19 (24) |
Complexity: 7 |
Complexity Density: 0.47 |
|
533 |
|
public class LaunchJvBrowserOnItem extends AbstractAction |
534 |
|
implements UpdatableAction |
535 |
|
{ |
536 |
|
JList _listItems = null; |
537 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
538 |
3 |
public LaunchJvBrowserOnItem(JList listItems)... |
539 |
|
{ |
540 |
3 |
super("Open in Browser"); |
541 |
3 |
this.putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_O)); |
542 |
3 |
this.putValue(Action.LONG_DESCRIPTION, "Open in Browser"); |
543 |
3 |
_listItems = listItems; |
544 |
|
} |
545 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
546 |
0 |
@Override... |
547 |
|
public void actionPerformed(ActionEvent e) |
548 |
|
{ |
549 |
0 |
Object o = _listItems.getSelectedValue(); |
550 |
0 |
if (o instanceof Item) |
551 |
|
{ |
552 |
0 |
Item item = (Item) o; |
553 |
0 |
item.setRead(true); |
554 |
0 |
_listItems.repaint(); |
555 |
|
|
556 |
0 |
Desktop.showUrl(item.getLink()); |
557 |
|
} |
558 |
|
} |
559 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
560 |
0 |
@Override... |
561 |
|
public void update(Object o) |
562 |
|
{ |
563 |
0 |
setEnabled(true); |
564 |
0 |
if (_listItems == null || _listItems.getModel().getSize() == 0) |
565 |
|
{ |
566 |
0 |
setEnabled(false); |
567 |
|
} |
568 |
0 |
else if (_listItems.getSelectedIndex() == -1) |
569 |
|
{ |
570 |
0 |
setEnabled(false); |
571 |
|
} |
572 |
|
} |
573 |
|
|
574 |
|
} |
575 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
576 |
3 |
private JPopupMenu _buildItemsPopupMenu()... |
577 |
|
{ |
578 |
3 |
JPopupMenu popup = new JPopupMenu(); |
579 |
3 |
popup.add(new JMenuItem(new LaunchJvBrowserOnItem(listItems))); |
580 |
3 |
popup.addSeparator(); |
581 |
3 |
popup.add(new JMenuItem(new MarkItemAsRead(listItems))); |
582 |
3 |
popup.add(new JMenuItem(new MarkItemAsUnread(listItems))); |
583 |
3 |
return popup; |
584 |
|
} |
585 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
586 |
3 |
private JPopupMenu _buildChannelsPopupMenu()... |
587 |
|
{ |
588 |
3 |
JPopupMenu popup = new JPopupMenu(); |
589 |
3 |
popup.add( |
590 |
|
new JMenuItem(new MarkChannelAsRead(listChannels, listItems))); |
591 |
3 |
popup.add(new JMenuItem( |
592 |
|
new MarkChannelAsUnread(listChannels, listItems))); |
593 |
3 |
return popup; |
594 |
|
} |
595 |
|
|
|
|
| 76.9% |
Uncovered Elements: 6 (26) |
Complexity: 8 |
Complexity Density: 0.5 |
|
596 |
3 |
private void initItems(Channel channel)... |
597 |
|
{ |
598 |
3 |
if (channel == null) |
599 |
|
{ |
600 |
0 |
channel = new Channel(); |
601 |
|
} |
602 |
3 |
if (!channel.isOpen() && channel.getURL() != null) |
603 |
|
{ |
604 |
3 |
try |
605 |
|
{ |
606 |
3 |
SimpleRSSParser.parse(channel); |
607 |
|
} catch (Exception ex) |
608 |
|
{ |
609 |
0 |
ex.printStackTrace(); |
610 |
|
} |
611 |
|
} |
612 |
3 |
DefaultListModel itemsModel = (DefaultListModel) listItems.getModel(); |
613 |
3 |
itemsModel.clear(); |
614 |
3 |
Iterator iter = (channel.getItems() != null) |
615 |
|
? channel.getItems().iterator() |
616 |
|
: Collections.EMPTY_LIST.iterator(); |
617 |
33 |
while (iter.hasNext()) |
618 |
|
{ |
619 |
30 |
itemsModel.addElement(iter.next()); |
620 |
|
} |
621 |
3 |
if (itemsModel.getSize() > 0) |
622 |
|
{ |
623 |
3 |
listItems.setSelectedIndex(0); |
624 |
3 |
_itemsValueChanged(listItems); |
625 |
|
} |
626 |
3 |
setStatusBarText(channel.getURL()); |
627 |
3 |
_updateAllActions(); |
628 |
|
} |
629 |
|
|
|
|
| 79.2% |
Uncovered Elements: 5 (24) |
Complexity: 5 |
Complexity Density: 0.31 |
|
630 |
9 |
private void _itemsValueChanged(JList itemList)... |
631 |
|
{ |
632 |
9 |
Item item = (Item) itemList.getSelectedValue(); |
633 |
9 |
if (item == null) |
634 |
|
{ |
635 |
3 |
if (itemList.getModel().getSize() > 0) |
636 |
|
{ |
637 |
0 |
item = (Item) itemList.getModel().getElementAt(0); |
638 |
|
} |
639 |
3 |
if (item == null) |
640 |
|
{ |
641 |
3 |
item = new Item(); |
642 |
|
} |
643 |
|
else |
644 |
|
{ |
645 |
0 |
itemList.setSelectedIndex(0); |
646 |
|
} |
647 |
|
} |
648 |
|
|
649 |
9 |
if (_itemTimer != null) |
650 |
|
{ |
651 |
|
|
652 |
9 |
_itemTimer.setDelay(300); |
653 |
9 |
_itemTimer.start(); |
654 |
9 |
_itemTimer.setLastItem(item); |
655 |
9 |
final Item lastitem = item; |
656 |
9 |
_itemTimer.addActionListener(new ActionListener() |
657 |
|
{ |
658 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
659 |
6 |
@Override... |
660 |
|
public void actionPerformed(ActionEvent e) |
661 |
|
{ |
662 |
6 |
saveLastM(lastitem); |
663 |
|
} |
664 |
|
}); |
665 |
|
} |
666 |
|
|
667 |
9 |
setStatusBarText(item.getLink()); |
668 |
9 |
textDescription.setBlogText(item); |
669 |
9 |
_updateAllActions(); |
670 |
|
} |
671 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
672 |
12 |
public void setStatusBarText(String text)... |
673 |
|
{ |
674 |
12 |
statusBar.setText(text); |
675 |
|
} |
676 |
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
677 |
15 |
private void _updateAllActions()... |
678 |
|
{ |
679 |
15 |
Iterator iter = _updatableActions.iterator(); |
680 |
15 |
while (iter.hasNext()) |
681 |
|
{ |
682 |
0 |
UpdatableAction action = (UpdatableAction) iter.next(); |
683 |
0 |
action.update(this); |
684 |
|
} |
685 |
|
} |
686 |
|
|
|
|
| 67.9% |
Uncovered Elements: 9 (28) |
Complexity: 7 |
Complexity Density: 0.44 |
|
687 |
3 |
private void _updateToolbarButtons()... |
688 |
|
{ |
689 |
3 |
Map general = (Map) Main.getPreferences().get("general"); |
690 |
3 |
if (general == null) |
691 |
|
{ |
692 |
0 |
return; |
693 |
|
} |
694 |
|
|
695 |
3 |
Component[] components = toolBar.getComponents(); |
696 |
12 |
for (int i = 0; i < components.length; i++) |
697 |
|
{ |
698 |
9 |
Component component = components[i]; |
699 |
9 |
if (component instanceof JButton) |
700 |
|
{ |
701 |
3 |
JButton button = (JButton) component; |
702 |
3 |
if (Boolean.toString(false).equals(general.get("useToolBarText"))) |
703 |
|
{ |
704 |
|
|
705 |
3 |
button.setText(""); |
706 |
|
} |
707 |
3 |
if (Boolean.toString(true).equals(general.get("radioTextBelow"))) |
708 |
|
{ |
709 |
0 |
button.setVerticalTextPosition(AbstractButton.BOTTOM); |
710 |
0 |
button.setHorizontalTextPosition(AbstractButton.CENTER); |
711 |
|
} |
712 |
3 |
else if (Boolean.toString(true) |
713 |
|
.equals(general.get("radioTextRight"))) |
714 |
|
{ |
715 |
0 |
button.setVerticalTextPosition(AbstractButton.CENTER); |
716 |
0 |
button.setHorizontalTextPosition(AbstractButton.RIGHT); |
717 |
|
} |
718 |
|
} |
719 |
|
} |
720 |
|
} |
721 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
722 |
0 |
private void listItems_mouseClicked(MouseEvent e)... |
723 |
|
{ |
724 |
0 |
if (e.getClickCount() == 2 && e.getModifiersEx() == MouseEvent.NOBUTTON) |
725 |
|
{ |
726 |
0 |
Item item = (Item) listItems.getSelectedValue(); |
727 |
0 |
item.setRead(true); |
728 |
0 |
saveLastM(item); |
729 |
0 |
if (_itemTimer != null) |
730 |
|
{ |
731 |
0 |
_itemTimer.stop(); |
732 |
|
} |
733 |
|
|
734 |
0 |
Action action = new LaunchJvBrowserOnItem(listItems); |
735 |
0 |
ActionEvent event = new ActionEvent(this, |
736 |
|
ActionEvent.ACTION_PERFORMED, "LaunchBrowserOnItem"); |
737 |
0 |
action.actionPerformed(event); |
738 |
|
} |
739 |
|
} |
740 |
|
|
741 |
|
|
742 |
|
|
743 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
744 |
0 |
public void refreshNews()... |
745 |
|
{ |
746 |
0 |
try |
747 |
|
{ |
748 |
0 |
initItems((Channel) _channelModel.getElementAt(0)); |
749 |
|
|
750 |
|
} catch (Exception x) |
751 |
|
{ |
752 |
|
} |
753 |
|
} |
754 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 7 |
Complexity Density: 0.28 |
|
755 |
0 |
public static void main(String args[])... |
756 |
|
{ |
757 |
|
|
758 |
|
|
759 |
0 |
jalview.bin.Cache.loadProperties(null); |
760 |
0 |
jalview.bin.Cache.initLogger(); |
761 |
|
|
762 |
0 |
Calendar today = Calendar.getInstance(), |
763 |
|
lastread = Calendar.getInstance(); |
764 |
0 |
lastread.set(1983, 01, 01); |
765 |
0 |
while (lastread.before(today)) |
766 |
|
{ |
767 |
0 |
String formattedDate = Cache.setDateProperty( |
768 |
|
"JALVIEW_NEWS_RSS_LASTMODIFIED", lastread.getTime()); |
769 |
0 |
BlogReader me = new BlogReader(); |
770 |
0 |
System.out.println("Set last date to " + formattedDate); |
771 |
0 |
if (me.isNewsNew()) |
772 |
|
{ |
773 |
0 |
Cache.log.debug("There is news to read."); |
774 |
|
} |
775 |
|
else |
776 |
|
{ |
777 |
0 |
Cache.log.debug("There is no new news."); |
778 |
0 |
me.xf.setTitle("Testing : Last read is " + me.lastDate); |
779 |
0 |
me.showNews(); |
780 |
0 |
me.xf.toFront(); |
781 |
|
} |
782 |
0 |
Cache.log.debug("Waiting for closure."); |
783 |
0 |
do |
784 |
|
{ |
785 |
0 |
try |
786 |
|
{ |
787 |
0 |
Thread.sleep(300); |
788 |
|
} catch (InterruptedException x) |
789 |
|
{ |
790 |
|
} |
791 |
0 |
; |
792 |
0 |
} while (me.isVisible()); |
793 |
|
|
794 |
0 |
if (me.isNewsNew()) |
795 |
|
{ |
796 |
0 |
Cache.log.debug("Still new news after reader displayed."); |
797 |
|
} |
798 |
0 |
if (lastread.getTime().before(me.lastDate)) |
799 |
|
{ |
800 |
0 |
Cache.log.debug("The news was read."); |
801 |
0 |
lastread.setTime(me.lastDate); |
802 |
|
} |
803 |
|
else |
804 |
|
{ |
805 |
0 |
lastread.add(Calendar.MONTH, 1); |
806 |
|
} |
807 |
|
|
808 |
|
} |
809 |
|
} |
810 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
811 |
0 |
boolean isNewsNew()... |
812 |
|
{ |
813 |
0 |
return newsnew; |
814 |
|
} |
815 |
|
} |
816 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.29 |
|
817 |
|
class ChannelsRenderer extends DefaultListCellRenderer |
818 |
|
{ |
819 |
|
private final static Icon _icon = new ImageIcon( |
820 |
|
Main.class.getResource("image/ComposeMail16.gif")); |
821 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
822 |
0 |
@Override... |
823 |
|
public Component getListCellRendererComponent(JList list, Object value, |
824 |
|
int index, boolean isSelected, boolean cellHasFocus) |
825 |
|
{ |
826 |
0 |
JLabel component = (JLabel) super.getListCellRendererComponent(list, |
827 |
|
value, index, isSelected, cellHasFocus); |
828 |
0 |
component.setIcon(ChannelsRenderer._icon); |
829 |
0 |
if (value instanceof Channel) |
830 |
|
{ |
831 |
0 |
Channel channel = (Channel) value; |
832 |
0 |
component.setText(MessageManager |
833 |
|
.formatMessage("label.channel_title_item_count", new String[] |
834 |
|
{ channel.getTitle(), Integer |
835 |
|
.valueOf(channel.getUnreadItemCount()).toString() })); |
836 |
0 |
component.setToolTipText(channel.getURL()); |
837 |
|
} |
838 |
0 |
return component; |
839 |
|
} |
840 |
|
} |
841 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.36 |
|
842 |
|
class ItemsRenderer extends DefaultListCellRenderer |
843 |
|
{ |
844 |
|
private final static Icon _icon = new ImageIcon( |
845 |
|
Main.class.getResource("image/ComposeMail16.gif")); |
846 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
847 |
40 |
@Override... |
848 |
|
public Component getListCellRendererComponent(JList list, Object value, |
849 |
|
int index, boolean isSelected, boolean cellHasFocus) |
850 |
|
{ |
851 |
40 |
JLabel component = (JLabel) super.getListCellRendererComponent(list, |
852 |
|
value, index, isSelected, cellHasFocus); |
853 |
40 |
component.setIcon(ItemsRenderer._icon); |
854 |
40 |
if (value instanceof Item) |
855 |
|
{ |
856 |
40 |
Item item = (Item) value; |
857 |
40 |
if (item.getPublishDate() != null) |
858 |
|
{ |
859 |
40 |
component.setText(MessageManager.formatMessage( |
860 |
|
"label.blog_item_published_on_date", new String[] |
861 |
|
{ DateFormat |
862 |
|
.getDateInstance(DateFormat.LONG, |
863 |
|
MessageManager.getLocale()) |
864 |
|
.format(item.getPublishDate()).toString(), |
865 |
|
item.getTitle() })); |
866 |
|
} |
867 |
40 |
component.setToolTipText(item.getLink()); |
868 |
40 |
if (!item.isRead()) |
869 |
|
{ |
870 |
39 |
component.setFont(component.getFont().deriveFont(Font.BOLD)); |
871 |
|
} |
872 |
|
else |
873 |
|
{ |
874 |
1 |
component.setFont(component.getFont().deriveFont(Font.PLAIN)); |
875 |
|
} |
876 |
|
} |
877 |
40 |
return component; |
878 |
|
} |
879 |
|
} |