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 |
|
|
|
|
| 60.7% |
Uncovered Elements: 141 (359) |
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 |
2 |
private JalviewDialog createDialog()... |
192 |
|
{ |
193 |
|
|
194 |
2 |
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 |
6 |
public BlogReader(Desktop desktop)... |
249 |
|
{ |
250 |
6 |
Cache.log.debug("Constructing news reader."); |
251 |
|
|
252 |
6 |
parent = desktop; |
253 |
6 |
_channelModel = new ChannelListModel(); |
254 |
|
|
255 |
6 |
Channel chan = new Channel(); |
256 |
6 |
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 |
6 |
loadLastM(); |
262 |
6 |
_channelModel.addChannel(chan); |
263 |
6 |
updating = true; |
264 |
6 |
try |
265 |
|
{ |
266 |
6 |
jbInit(); |
267 |
6 |
postInit(); |
268 |
|
} catch (Exception e) |
269 |
|
{ |
270 |
0 |
e.printStackTrace(); |
271 |
|
} |
272 |
|
|
273 |
6 |
initItems(chan); |
274 |
6 |
updating = false; |
275 |
6 |
boolean setvisible = checkForNew(chan, true); |
276 |
|
|
277 |
6 |
if (setvisible) |
278 |
|
{ |
279 |
|
|
280 |
2 |
Cache.log.debug("Will show jalview news automatically"); |
281 |
2 |
showNews(); |
282 |
|
} |
283 |
6 |
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 |
107 |
@Override... |
291 |
|
public boolean isVisible() |
292 |
|
{ |
293 |
107 |
if (parent == null) |
294 |
|
{ |
295 |
0 |
return xf != null && xf.isVisible(); |
296 |
|
} |
297 |
107 |
return jd != null && jd.isVisible(); |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
303 |
2 |
public void showNews()... |
304 |
|
{ |
305 |
2 |
final BlogReader me = this; |
306 |
2 |
SwingUtilities.invokeLater(new Runnable() |
307 |
|
{ |
|
|
| 60% |
Uncovered Elements: 6 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
308 |
2 |
@Override... |
309 |
|
public void run() |
310 |
|
{ |
311 |
2 |
Rectangle bounds = new Rectangle(5, 5, 550, 350); |
312 |
2 |
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 |
2 |
createDialog(); |
338 |
2 |
bounds = new Rectangle(5, 5, 550, 350); |
339 |
2 |
jd.initDialogFrame(me, false, false, |
340 |
|
MessageManager.getString("label.news_from_jalview"), |
341 |
|
bounds.width, bounds.height); |
342 |
2 |
jd.frame.setModalExclusionType(ModalExclusionType.NO_EXCLUDE); |
343 |
2 |
Cache.log.debug("Displaying news."); |
344 |
2 |
jd.waitForInput(); |
345 |
|
} |
346 |
|
} |
347 |
|
}); |
348 |
|
} |
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
|
|
| 83.3% |
Uncovered Elements: 6 (36) |
Complexity: 17 |
Complexity Density: 0.85 |
|
353 |
18 |
private boolean checkForNew(Channel chan, boolean updateItems)... |
354 |
|
{ |
355 |
|
|
356 |
18 |
if (!updating || updateItems) |
357 |
|
{ |
358 |
18 |
newsnew = false; |
359 |
|
} |
360 |
18 |
java.util.Date earliest = null; |
361 |
18 |
try |
362 |
|
{ |
363 |
18 |
earliest = new SimpleDateFormat("YYYY-MM-DD") |
364 |
|
.parse(chan.getHTTPLastModified()); |
365 |
|
} catch (Exception x) |
366 |
|
{ |
367 |
|
} |
368 |
18 |
if (chan != null && chan.getItems() != null) |
369 |
|
{ |
370 |
18 |
Cache.log.debug("Scanning news items: newsnew=" + newsnew |
371 |
|
+ " and lastDate is " + lastDate); |
372 |
18 |
for (Item i : (List<Item>) chan.getItems()) |
373 |
|
{ |
374 |
180 |
Date published = i.getPublishDate(); |
375 |
180 |
boolean isread = lastDate == null ? false |
376 |
|
: (published != null && !lastDate.before(published)); |
377 |
|
|
378 |
180 |
if (!updating || updateItems) |
379 |
|
{ |
380 |
180 |
newsnew |= !isread; |
381 |
|
} |
382 |
180 |
if (updateItems) |
383 |
|
{ |
384 |
60 |
i.setRead(isread); |
385 |
|
} |
386 |
180 |
if (published != null && !i.isRead()) |
387 |
|
{ |
388 |
20 |
if (earliest == null || earliest.after(published)) |
389 |
|
{ |
390 |
20 |
earliest = published; |
391 |
|
} |
392 |
|
} |
393 |
|
} |
394 |
|
} |
395 |
18 |
if (!updateItems && !updating && lastDate == null) |
396 |
|
{ |
397 |
0 |
lastDate = earliest; |
398 |
|
} |
399 |
18 |
return newsnew; |
400 |
|
} |
401 |
|
|
402 |
|
java.util.Date lastDate = null; |
403 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
404 |
6 |
private void loadLastM()... |
405 |
|
{ |
406 |
6 |
lastDate = Cache.getDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED"); |
407 |
|
} |
408 |
|
|
|
|
| 73.7% |
Uncovered Elements: 5 (19) |
Complexity: 7 |
Complexity Density: 0.78 |
|
409 |
12 |
private void saveLastM(Item item)... |
410 |
|
{ |
411 |
12 |
if (item != null) |
412 |
|
{ |
413 |
12 |
if (item.getPublishDate() != null) |
414 |
|
{ |
415 |
8 |
if (lastDate == null || item.getPublishDate().after(lastDate)) |
416 |
|
{ |
417 |
0 |
lastDate = item.getPublishDate(); |
418 |
|
} |
419 |
|
} |
420 |
|
|
421 |
12 |
if (_channelModel.getElementAt(0) != null) |
422 |
|
{ |
423 |
12 |
checkForNew((Channel) _channelModel.getElementAt(0), false); |
424 |
|
} |
425 |
12 |
if (lastDate != null) |
426 |
|
{ |
427 |
12 |
String formatted = Cache |
428 |
|
.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", lastDate); |
429 |
12 |
Cache.log.debug("Saved last read date as " + formatted); |
430 |
|
} |
431 |
|
} |
432 |
|
} |
433 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 1 |
Complexity Density: 0.03 |
|
434 |
6 |
private void jbInit() throws Exception... |
435 |
|
{ |
436 |
6 |
setLayout(layoutMain); |
437 |
6 |
panelMain.setLayout(borderLayout1); |
438 |
6 |
topPanel.setLayout(borderLayout5); |
439 |
6 |
bottomPanel.setLayout(borderLayout4); |
440 |
6 |
topBottomSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); |
441 |
6 |
topBottomSplitPane.setDividerLocation(100); |
442 |
6 |
topBottomSplitPane.setTopComponent(topPanel); |
443 |
6 |
topBottomSplitPane.setBottomComponent(bottomPanel); |
444 |
6 |
JScrollPane spTextDescription = new JScrollPane(textDescription); |
445 |
6 |
textDescription.setText(""); |
446 |
6 |
statusBar.setText(new StringBuffer("[") |
447 |
|
.append(MessageManager.getString("label.status")).append("]") |
448 |
|
.toString()); |
449 |
6 |
buttonRefresh.addActionListener(new ActionListener() |
450 |
|
{ |
451 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
452 |
0 |
@Override... |
453 |
|
public void actionPerformed(ActionEvent e) |
454 |
|
{ |
455 |
0 |
refreshNews(); |
456 |
|
} |
457 |
|
}); |
458 |
6 |
add(statusBar, BorderLayout.SOUTH); |
459 |
6 |
toolBar.add(buttonRefresh); |
460 |
6 |
toolBar.addSeparator(); |
461 |
6 |
JLabel about = new JLabel( |
462 |
|
"brought to you by JSwingReader (jswingreader.sourceforge.net)"); |
463 |
6 |
toolBar.add(about); |
464 |
6 |
toolBar.setFloatable(false); |
465 |
6 |
add(toolBar, BorderLayout.NORTH); |
466 |
6 |
panelMain.add(topBottomSplitPane, BorderLayout.CENTER); |
467 |
6 |
add(panelMain, BorderLayout.CENTER); |
468 |
6 |
JScrollPane spListItems = new JScrollPane(listItems); |
469 |
6 |
listItems |
470 |
|
.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); |
471 |
6 |
topPanel.add(spListItems, BorderLayout.CENTER); |
472 |
6 |
bottomPanel.add(spTextDescription, BorderLayout.CENTER); |
473 |
6 |
listChannels.setModel(_channelModel); |
474 |
|
|
475 |
6 |
listItems.addMouseListener(new java.awt.event.MouseAdapter() |
476 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
477 |
0 |
@Override... |
478 |
|
public void mouseClicked(MouseEvent e) |
479 |
|
{ |
480 |
0 |
listItems_mouseClicked(e); |
481 |
|
} |
482 |
|
}); |
483 |
6 |
_popupItems = _buildItemsPopupMenu(); |
484 |
6 |
_popupChannels = _buildChannelsPopupMenu(); |
485 |
6 |
ContextMenuMouseAdapter popupAdapter = new ContextMenuMouseAdapter( |
486 |
|
_popupItems); |
487 |
6 |
ContextMenuMouseAdapter popupChannelsAdapter = new ContextMenuMouseAdapter( |
488 |
|
_popupChannels); |
489 |
6 |
listItems.addMouseListener(popupAdapter); |
490 |
6 |
listItems.setCellRenderer(new ItemsRenderer()); |
491 |
6 |
lblChannels.setText(MessageManager.getString("label.channels")); |
492 |
|
} |
493 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
494 |
6 |
private void postInit()... |
495 |
|
{ |
496 |
|
|
497 |
6 |
for (HyperlinkListener hll : textDescription.getHyperlinkListeners()) |
498 |
|
{ |
499 |
6 |
textDescription.removeHyperlinkListener(hll); |
500 |
|
} |
501 |
6 |
textDescription.addHyperlinkListener(new HyperlinkListener() |
502 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
503 |
0 |
@Override... |
504 |
|
public void hyperlinkUpdate(HyperlinkEvent e) |
505 |
|
{ |
506 |
0 |
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) |
507 |
|
{ |
508 |
0 |
Desktop.showUrl(e.getURL().toExternalForm()); |
509 |
|
} |
510 |
|
} |
511 |
|
}); |
512 |
|
|
513 |
6 |
listItems.addListSelectionListener(new ListSelectionListener() |
514 |
|
{ |
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
515 |
6 |
@Override... |
516 |
|
public void valueChanged(ListSelectionEvent e) |
517 |
|
{ |
518 |
6 |
if (e.getValueIsAdjusting() == false) |
519 |
|
{ |
520 |
6 |
_itemsValueChanged(listItems); |
521 |
|
} |
522 |
|
} |
523 |
|
}); |
524 |
6 |
listChannels.setSelectedIndex(1); |
525 |
6 |
_updateAllActions(); |
526 |
6 |
_updateToolbarButtons(); |
527 |
|
|
528 |
6 |
_itemTimer = new ItemReadTimer(listChannels, listItems); |
529 |
6 |
_itemsValueChanged(listItems); |
530 |
|
} |
531 |
|
|
|
|
| 20.8% |
Uncovered Elements: 19 (24) |
Complexity: 7 |
Complexity Density: 0.47 |
|
532 |
|
public class LaunchJvBrowserOnItem extends AbstractAction |
533 |
|
implements UpdatableAction |
534 |
|
{ |
535 |
|
JList _listItems = null; |
536 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
537 |
6 |
public LaunchJvBrowserOnItem(JList listItems)... |
538 |
|
{ |
539 |
6 |
super("Open in Browser"); |
540 |
6 |
this.putValue(MNEMONIC_KEY, Integer.valueOf(KeyEvent.VK_O)); |
541 |
6 |
this.putValue(Action.LONG_DESCRIPTION, "Open in Browser"); |
542 |
6 |
_listItems = listItems; |
543 |
|
} |
544 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
545 |
0 |
@Override... |
546 |
|
public void actionPerformed(ActionEvent e) |
547 |
|
{ |
548 |
0 |
Object o = _listItems.getSelectedValue(); |
549 |
0 |
if (o instanceof Item) |
550 |
|
{ |
551 |
0 |
Item item = (Item) o; |
552 |
0 |
item.setRead(true); |
553 |
0 |
_listItems.repaint(); |
554 |
|
|
555 |
0 |
Desktop.showUrl(item.getLink()); |
556 |
|
} |
557 |
|
} |
558 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
559 |
0 |
@Override... |
560 |
|
public void update(Object o) |
561 |
|
{ |
562 |
0 |
setEnabled(true); |
563 |
0 |
if (_listItems == null || _listItems.getModel().getSize() == 0) |
564 |
|
{ |
565 |
0 |
setEnabled(false); |
566 |
|
} |
567 |
0 |
else if (_listItems.getSelectedIndex() == -1) |
568 |
|
{ |
569 |
0 |
setEnabled(false); |
570 |
|
} |
571 |
|
} |
572 |
|
|
573 |
|
} |
574 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
575 |
6 |
private JPopupMenu _buildItemsPopupMenu()... |
576 |
|
{ |
577 |
6 |
JPopupMenu popup = new JPopupMenu(); |
578 |
6 |
popup.add(new JMenuItem(new LaunchJvBrowserOnItem(listItems))); |
579 |
6 |
popup.addSeparator(); |
580 |
6 |
popup.add(new JMenuItem(new MarkItemAsRead(listItems))); |
581 |
6 |
popup.add(new JMenuItem(new MarkItemAsUnread(listItems))); |
582 |
6 |
return popup; |
583 |
|
} |
584 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
585 |
6 |
private JPopupMenu _buildChannelsPopupMenu()... |
586 |
|
{ |
587 |
6 |
JPopupMenu popup = new JPopupMenu(); |
588 |
6 |
popup.add( |
589 |
|
new JMenuItem(new MarkChannelAsRead(listChannels, listItems))); |
590 |
6 |
popup.add(new JMenuItem( |
591 |
|
new MarkChannelAsUnread(listChannels, listItems))); |
592 |
6 |
return popup; |
593 |
|
} |
594 |
|
|
|
|
| 76.9% |
Uncovered Elements: 6 (26) |
Complexity: 8 |
Complexity Density: 0.5 |
|
595 |
6 |
private void initItems(Channel channel)... |
596 |
|
{ |
597 |
6 |
if (channel == null) |
598 |
|
{ |
599 |
0 |
channel = new Channel(); |
600 |
|
} |
601 |
6 |
if (!channel.isOpen() && channel.getURL() != null) |
602 |
|
{ |
603 |
6 |
try |
604 |
|
{ |
605 |
6 |
SimpleRSSParser.parse(channel); |
606 |
|
} catch (Exception ex) |
607 |
|
{ |
608 |
0 |
ex.printStackTrace(); |
609 |
|
} |
610 |
|
} |
611 |
6 |
DefaultListModel itemsModel = (DefaultListModel) listItems.getModel(); |
612 |
6 |
itemsModel.clear(); |
613 |
6 |
Iterator iter = (channel.getItems() != null) |
614 |
|
? channel.getItems().iterator() |
615 |
|
: Collections.EMPTY_LIST.iterator(); |
616 |
66 |
while (iter.hasNext()) |
617 |
|
{ |
618 |
60 |
itemsModel.addElement(iter.next()); |
619 |
|
} |
620 |
6 |
if (itemsModel.getSize() > 0) |
621 |
|
{ |
622 |
6 |
listItems.setSelectedIndex(0); |
623 |
6 |
_itemsValueChanged(listItems); |
624 |
|
} |
625 |
6 |
setStatusBarText(channel.getURL()); |
626 |
6 |
_updateAllActions(); |
627 |
|
} |
628 |
|
|
|
|
| 79.2% |
Uncovered Elements: 5 (24) |
Complexity: 5 |
Complexity Density: 0.31 |
|
629 |
18 |
private void _itemsValueChanged(JList itemList)... |
630 |
|
{ |
631 |
18 |
Item item = (Item) itemList.getSelectedValue(); |
632 |
18 |
if (item == null) |
633 |
|
{ |
634 |
6 |
if (itemList.getModel().getSize() > 0) |
635 |
|
{ |
636 |
0 |
item = (Item) itemList.getModel().getElementAt(0); |
637 |
|
} |
638 |
6 |
if (item == null) |
639 |
|
{ |
640 |
6 |
item = new Item(); |
641 |
|
} |
642 |
|
else |
643 |
|
{ |
644 |
0 |
itemList.setSelectedIndex(0); |
645 |
|
} |
646 |
|
} |
647 |
|
|
648 |
18 |
if (_itemTimer != null) |
649 |
|
{ |
650 |
|
|
651 |
18 |
_itemTimer.setDelay(300); |
652 |
18 |
_itemTimer.start(); |
653 |
18 |
_itemTimer.setLastItem(item); |
654 |
18 |
final Item lastitem = item; |
655 |
18 |
_itemTimer.addActionListener(new ActionListener() |
656 |
|
{ |
657 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
658 |
12 |
@Override... |
659 |
|
public void actionPerformed(ActionEvent e) |
660 |
|
{ |
661 |
12 |
saveLastM(lastitem); |
662 |
|
} |
663 |
|
}); |
664 |
|
} |
665 |
|
|
666 |
18 |
setStatusBarText(item.getLink()); |
667 |
18 |
textDescription.setBlogText(item); |
668 |
18 |
_updateAllActions(); |
669 |
|
} |
670 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
671 |
24 |
public void setStatusBarText(String text)... |
672 |
|
{ |
673 |
24 |
statusBar.setText(text); |
674 |
|
} |
675 |
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
676 |
30 |
private void _updateAllActions()... |
677 |
|
{ |
678 |
30 |
Iterator iter = _updatableActions.iterator(); |
679 |
30 |
while (iter.hasNext()) |
680 |
|
{ |
681 |
0 |
UpdatableAction action = (UpdatableAction) iter.next(); |
682 |
0 |
action.update(this); |
683 |
|
} |
684 |
|
} |
685 |
|
|
|
|
| 67.9% |
Uncovered Elements: 9 (28) |
Complexity: 7 |
Complexity Density: 0.44 |
|
686 |
6 |
private void _updateToolbarButtons()... |
687 |
|
{ |
688 |
6 |
Map general = (Map) Main.getPreferences().get("general"); |
689 |
6 |
if (general == null) |
690 |
|
{ |
691 |
0 |
return; |
692 |
|
} |
693 |
|
|
694 |
6 |
Component[] components = toolBar.getComponents(); |
695 |
24 |
for (int i = 0; i < components.length; i++) |
696 |
|
{ |
697 |
18 |
Component component = components[i]; |
698 |
18 |
if (component instanceof JButton) |
699 |
|
{ |
700 |
6 |
JButton button = (JButton) component; |
701 |
6 |
if (Boolean.toString(false).equals(general.get("useToolBarText"))) |
702 |
|
{ |
703 |
|
|
704 |
6 |
button.setText(""); |
705 |
|
} |
706 |
6 |
if (Boolean.toString(true).equals(general.get("radioTextBelow"))) |
707 |
|
{ |
708 |
0 |
button.setVerticalTextPosition(AbstractButton.BOTTOM); |
709 |
0 |
button.setHorizontalTextPosition(AbstractButton.CENTER); |
710 |
|
} |
711 |
6 |
else if (Boolean.toString(true) |
712 |
|
.equals(general.get("radioTextRight"))) |
713 |
|
{ |
714 |
0 |
button.setVerticalTextPosition(AbstractButton.CENTER); |
715 |
0 |
button.setHorizontalTextPosition(AbstractButton.RIGHT); |
716 |
|
} |
717 |
|
} |
718 |
|
} |
719 |
|
} |
720 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
721 |
0 |
private void listItems_mouseClicked(MouseEvent e)... |
722 |
|
{ |
723 |
0 |
if (e.getClickCount() == 2 && e.getModifiersEx() == MouseEvent.NOBUTTON) |
724 |
|
{ |
725 |
0 |
Item item = (Item) listItems.getSelectedValue(); |
726 |
0 |
item.setRead(true); |
727 |
0 |
saveLastM(item); |
728 |
0 |
if (_itemTimer != null) |
729 |
|
{ |
730 |
0 |
_itemTimer.stop(); |
731 |
|
} |
732 |
|
|
733 |
0 |
Action action = new LaunchJvBrowserOnItem(listItems); |
734 |
0 |
ActionEvent event = new ActionEvent(this, |
735 |
|
ActionEvent.ACTION_PERFORMED, "LaunchBrowserOnItem"); |
736 |
0 |
action.actionPerformed(event); |
737 |
|
} |
738 |
|
} |
739 |
|
|
740 |
|
|
741 |
|
|
742 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
743 |
0 |
public void refreshNews()... |
744 |
|
{ |
745 |
0 |
try |
746 |
|
{ |
747 |
0 |
initItems((Channel) _channelModel.getElementAt(0)); |
748 |
|
|
749 |
|
} catch (Exception x) |
750 |
|
{ |
751 |
|
} |
752 |
|
} |
753 |
|
|
754 |
|
|
755 |
|
|
756 |
|
@param |
757 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 7 |
Complexity Density: 0.29 |
|
758 |
0 |
public static void main(String args[])... |
759 |
|
{ |
760 |
|
|
761 |
|
|
762 |
0 |
jalview.bin.Cache.loadProperties(null); |
763 |
0 |
jalview.bin.Cache.initLogger(); |
764 |
|
|
765 |
0 |
Calendar today = Calendar.getInstance(), |
766 |
|
lastread = Calendar.getInstance(); |
767 |
0 |
lastread.set(1983, 01, 01); |
768 |
0 |
while (lastread.before(today)) |
769 |
|
{ |
770 |
0 |
String formattedDate = Cache.setDateProperty( |
771 |
|
"JALVIEW_NEWS_RSS_LASTMODIFIED", lastread.getTime()); |
772 |
0 |
BlogReader me = new BlogReader(); |
773 |
0 |
System.out.println("Set last date to " + formattedDate); |
774 |
0 |
if (me.isNewsNew()) |
775 |
|
{ |
776 |
0 |
Cache.log.debug("There is news to read."); |
777 |
|
} |
778 |
|
else |
779 |
|
{ |
780 |
0 |
Cache.log.debug("There is no new news."); |
781 |
0 |
me.xf.setTitle("Testing : Last read is " + me.lastDate); |
782 |
0 |
me.showNews(); |
783 |
0 |
me.xf.toFront(); |
784 |
|
} |
785 |
0 |
Cache.log.debug("Waiting for closure."); |
786 |
0 |
do |
787 |
|
{ |
788 |
0 |
try |
789 |
|
{ |
790 |
0 |
Thread.sleep(300); |
791 |
|
} catch (InterruptedException x) |
792 |
|
{ |
793 |
|
} |
794 |
0 |
} while (me.isVisible()); |
795 |
|
|
796 |
0 |
if (me.isNewsNew()) |
797 |
|
{ |
798 |
0 |
Cache.log.debug("Still new news after reader displayed."); |
799 |
|
} |
800 |
0 |
if (lastread.getTime().before(me.lastDate)) |
801 |
|
{ |
802 |
0 |
Cache.log.debug("The news was read."); |
803 |
0 |
lastread.setTime(me.lastDate); |
804 |
|
} |
805 |
|
else |
806 |
|
{ |
807 |
0 |
lastread.add(Calendar.MONTH, 1); |
808 |
|
} |
809 |
|
|
810 |
|
} |
811 |
|
} |
812 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
813 |
0 |
boolean isNewsNew()... |
814 |
|
{ |
815 |
0 |
return newsnew; |
816 |
|
} |
817 |
|
} |
818 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.29 |
|
819 |
|
class ChannelsRenderer extends DefaultListCellRenderer |
820 |
|
{ |
821 |
|
private final static Icon _icon = new ImageIcon( |
822 |
|
Main.class.getResource("image/ComposeMail16.gif")); |
823 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
824 |
0 |
@Override... |
825 |
|
public Component getListCellRendererComponent(JList list, Object value, |
826 |
|
int index, boolean isSelected, boolean cellHasFocus) |
827 |
|
{ |
828 |
0 |
JLabel component = (JLabel) super.getListCellRendererComponent(list, |
829 |
|
value, index, isSelected, cellHasFocus); |
830 |
0 |
component.setIcon(ChannelsRenderer._icon); |
831 |
0 |
if (value instanceof Channel) |
832 |
|
{ |
833 |
0 |
Channel channel = (Channel) value; |
834 |
0 |
component.setText(MessageManager |
835 |
|
.formatMessage("label.channel_title_item_count", new String[] |
836 |
|
{ channel.getTitle(), Integer |
837 |
|
.valueOf(channel.getUnreadItemCount()).toString() })); |
838 |
0 |
component.setToolTipText(channel.getURL()); |
839 |
|
} |
840 |
0 |
return component; |
841 |
|
} |
842 |
|
} |
843 |
|
|
|
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 4 |
Complexity Density: 0.36 |
|
844 |
|
class ItemsRenderer extends DefaultListCellRenderer |
845 |
|
{ |
846 |
|
private final static Icon _icon = new ImageIcon( |
847 |
|
Main.class.getResource("image/ComposeMail16.gif")); |
848 |
|
|
|
|
| 76.5% |
Uncovered Elements: 4 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
849 |
90 |
@Override... |
850 |
|
public Component getListCellRendererComponent(JList list, Object value, |
851 |
|
int index, boolean isSelected, boolean cellHasFocus) |
852 |
|
{ |
853 |
90 |
JLabel component = (JLabel) super.getListCellRendererComponent(list, |
854 |
|
value, index, isSelected, cellHasFocus); |
855 |
90 |
component.setIcon(ItemsRenderer._icon); |
856 |
90 |
if (value instanceof Item) |
857 |
|
{ |
858 |
90 |
Item item = (Item) value; |
859 |
90 |
if (item.getPublishDate() != null) |
860 |
|
{ |
861 |
90 |
component.setText(MessageManager.formatMessage( |
862 |
|
"label.blog_item_published_on_date", new String[] |
863 |
|
{ DateFormat |
864 |
|
.getDateInstance(DateFormat.LONG, |
865 |
|
MessageManager.getLocale()) |
866 |
|
.format(item.getPublishDate()).toString(), |
867 |
|
item.getTitle() })); |
868 |
|
} |
869 |
90 |
component.setToolTipText(item.getLink()); |
870 |
90 |
if (!item.isRead()) |
871 |
|
{ |
872 |
90 |
component.setFont(component.getFont().deriveFont(Font.BOLD)); |
873 |
|
} |
874 |
|
else |
875 |
|
{ |
876 |
0 |
component.setFont(component.getFont().deriveFont(Font.PLAIN)); |
877 |
|
} |
878 |
|
} |
879 |
90 |
return component; |
880 |
|
} |
881 |
|
} |