X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fgui%2FBlogReader.java;h=7a1065de83e9dedf5a7bdb85951d052a1aebfd43;hb=aec85d6dfc1dd5970a50a53dc9d161635d1e9960;hp=3b7df4820309548f7325b6320e361a05272af5ad;hpb=3be300f0d9107885e183ae7c86b081c8e6c6780f;p=jalview.git
diff --git a/src/jalview/gui/BlogReader.java b/src/jalview/gui/BlogReader.java
index 3b7df48..7a1065d 100644
--- a/src/jalview/gui/BlogReader.java
+++ b/src/jalview/gui/BlogReader.java
@@ -1,13 +1,34 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Copyright (C) 2014 The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.gui;
import jalview.bin.Cache;
-import jalview.jbgui.GBlogReader;
+import jalview.util.MessageManager;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
+import java.awt.Dialog.ModalExclusionType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
@@ -32,6 +53,7 @@ import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
+import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuItem;
@@ -46,14 +68,11 @@ import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
-import javax.swing.text.DateFormatter;
-import org.robsite.jswingreader.action.AboutAction;
import org.robsite.jswingreader.action.MarkChannelAsRead;
import org.robsite.jswingreader.action.MarkChannelAsUnread;
import org.robsite.jswingreader.action.MarkItemAsRead;
import org.robsite.jswingreader.action.MarkItemAsUnread;
-import org.robsite.jswingreader.action.RefreshChannelAction;
import org.robsite.jswingreader.action.UpdatableAction;
import org.robsite.jswingreader.model.Channel;
import org.robsite.jswingreader.model.ChannelListModel;
@@ -63,19 +82,14 @@ import org.robsite.jswingreader.ui.BlogContentPane;
import org.robsite.jswingreader.ui.ItemReadTimer;
import org.robsite.jswingreader.ui.Main;
import org.robsite.jswingreader.ui.util.ContextMenuMouseAdapter;
-import org.robsite.jswingreader.util.BrowserUtils;
-
-import quicktime.std.movies.media.TextDescription;
/**
* Blog reading window, adapted from JSwingReader's
* org.robsite.jswingreader.ui.MainWindow class
*/
-public class BlogReader extends GBlogReader
+public class BlogReader extends JPanel
{
- private JButton buttonAbout = new JButton();
-
private JButton buttonRefresh = new JButton();
private JToolBar toolBar = new JToolBar();
@@ -92,10 +106,6 @@ public class BlogReader extends GBlogReader
private JPanel bottomPanel = new JPanel();
- private BorderLayout borderLayout2 = new BorderLayout();
-
- private BorderLayout borderLayout3 = new BorderLayout();
-
private JSplitPane topBottomSplitPane = new JSplitPane();
private JList listItems = new JList(new DefaultListModel());
@@ -118,7 +128,12 @@ public class BlogReader extends GBlogReader
@Override
public void actionPerformed(ActionEvent arg0)
{
- setVisible(false);
+ if (xf != null)
+ {
+ xf.dispose();
+ }
+ xf = null;
+ jd = null;
if (parent != null)
{
parent.showNews(false);
@@ -168,6 +183,43 @@ public class BlogReader extends GBlogReader
}
};
+ private JFrame xf = null;
+
+ private JalviewDialog jd = null;
+
+ private JalviewDialog createDialog()
+ {
+
+ return jd = new JalviewDialog()
+ {
+
+ @Override
+ protected void raiseClosed()
+ {
+ if (parent != null)
+ {
+ Cache.log.info("News window closed.");
+ jd = null;
+ parent.showNews(false);
+ }
+ }
+
+ @Override
+ protected void okPressed()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void cancelPressed()
+ {
+ // TODO Auto-generated method stub
+
+ }
+ };
+ };
+
private JLabel lblChannels = new JLabel();
private List _updatableActions = new ArrayList();
@@ -194,24 +246,9 @@ public class BlogReader extends GBlogReader
public BlogReader(Desktop desktop)
{
+ Cache.log.info("Constructing news reader.");
+
parent = desktop;
- if (parent == null)
- {
- this.setSize(new Dimension(550, 350));
- }
- else
- {
- Rectangle bounds = parent
- .getLastKnownDimensions("JALVIEW_RSS_WINDOW_");
- if (bounds == null)
- {
- setBounds(parent.getX(), parent.getY(), 550, 350);
- }
- else
- {
- setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
- }
- }
_channelModel = new ChannelListModel();
// Construct our jalview news channel
Channel chan = new Channel();
@@ -234,25 +271,74 @@ public class BlogReader extends GBlogReader
initItems(chan);
updating = false;
boolean setvisible = checkForNew(chan, true);
+
if (setvisible)
{
+
Cache.log.info("Will show jalview news automatically");
- SwingUtilities.invokeLater(new Runnable()
+ showNews();
+ }
+ Cache.log.info("Completed construction of reader.");
+
+ }
+
+ /**
+ * check if the news panel's container is visible
+ */
+ public boolean isVisible()
+ {
+ if (parent == null)
+ {
+ return xf != null && xf.isVisible();
+ }
+ return jd != null && jd.isVisible();
+ }
+
+ /**
+ * display the container for the news panel
+ */
+ public void showNews()
+ {
+ final BlogReader me = this;
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
{
- @Override
- public void run()
+ Rectangle bounds = new Rectangle(5, 5, 550, 350);
+ if (parent == null)
{
- if (parent != null)
+ xf = new JFrame();
+ xf.setContentPane(me);
+ xf.addWindowListener(new WindowAdapter()
{
- parent.showNews(true);
- }
- else
- {
- setVisible(true);
- }
+ public void windowClosing(WindowEvent e)
+ {
+ ActionEvent actionEvent = new ActionEvent(this,
+ ActionEvent.ACTION_FIRST, (String) exitAction
+ .getValue(Action.NAME));
+ exitAction.actionPerformed(actionEvent);
+ }
+
+ public void windowOpened(WindowEvent e)
+ {
+ }
+ });
+ me.setSize(new Dimension(550, 350));
+ xf.setVisible(true);
}
- });
- }
+ else
+ {
+ createDialog();
+ bounds = new Rectangle(5, 5, 550, 350);
+ jd.initDialogFrame(me, false, false, MessageManager.getString("label.news_from_jalview"),
+ bounds.width, bounds.height);
+ jd.frame.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
+ Cache.log.info("Displaying news.");
+ jd.waitForInput();
+ }
+ }
+ });
}
/**
@@ -260,18 +346,31 @@ public class BlogReader extends GBlogReader
*/
private boolean checkForNew(Channel chan, boolean updateItems)
{
+
if (!updating || updateItems)
{
newsnew = false;
}
+ java.util.Date earliest = null;
+ try
+ {
+ earliest = new SimpleDateFormat("YYYY-MM-DD").parse(chan
+ .getHTTPLastModified());
+ } catch (Exception x)
+ {
+ }
+ ;
if (chan != null && chan.getItems() != null)
{
+ Cache.log.debug("Scanning news items: newsnew=" + newsnew
+ + " and lastDate is " + lastDate);
for (Item i : (List- ) chan.getItems())
{
- boolean isread = (lastDate != null && i.getPublishDate() != null && !lastDate
- .before(i.getPublishDate()));
+ boolean isread = lastDate == null ? false
+ : (i.getPublishDate() != null && !lastDate.before(i
+ .getPublishDate()));
- if (i.getPublishDate() != null && (!updating || updateItems))
+ if (!updating || updateItems)
{
newsnew |= !isread;
}
@@ -279,8 +378,19 @@ public class BlogReader extends GBlogReader
{
i.setRead(isread);
}
+ if (i.getPublishDate() != null && !i.isRead())
+ {
+ if (earliest == null || earliest.after(i.getPublishDate()))
+ {
+ earliest = i.getPublishDate();
+ }
+ }
}
}
+ if (!updateItems && !updating && lastDate == null)
+ {
+ lastDate = earliest;
+ }
return newsnew;
}
@@ -293,10 +403,20 @@ public class BlogReader extends GBlogReader
private void saveLastM(Item item)
{
- if (item != null && item.getPublishDate() != null
- && (lastDate == null || item.getPublishDate().after(lastDate)))
+ if (item != null)
{
- lastDate = item.getPublishDate();
+ if (item.getPublishDate() != null)
+ {
+ if (lastDate == null || item.getPublishDate().after(lastDate))
+ {
+ lastDate = item.getPublishDate();
+ }
+ }
+
+ if (_channelModel.getElementAt(0) != null)
+ {
+ checkForNew((Channel) _channelModel.getElementAt(0), false);
+ }
if (lastDate != null)
{
jalview.bin.Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED",
@@ -305,17 +425,12 @@ public class BlogReader extends GBlogReader
+ jalview.bin.Cache.date_format.format(lastDate));
}
- if (_channelModel.getElementAt(0) != null)
- {
- checkForNew((Channel) _channelModel.getElementAt(0), false);
- }
}
}
private void jbInit() throws Exception
{
- this.setTitle("News from www.jalview.org");
- this.getContentPane().setLayout(layoutMain);
+ setLayout(layoutMain);
panelMain.setLayout(borderLayout1);
topPanel.setLayout(borderLayout5);
bottomPanel.setLayout(borderLayout4);
@@ -325,25 +440,26 @@ public class BlogReader extends GBlogReader
topBottomSplitPane.setBottomComponent(bottomPanel);
JScrollPane spTextDescription = new JScrollPane(textDescription);
textDescription.setText("");
- statusBar.setText(" [Status] ");
+ statusBar.setText(new StringBuffer("[").append(MessageManager.getString("label.status")).append("]").toString());
buttonRefresh.addActionListener(new ActionListener()
{
-
+
@Override
public void actionPerformed(ActionEvent e)
{
refreshNews();
}
});
- this.getContentPane().add(statusBar, BorderLayout.SOUTH);
+ add(statusBar, BorderLayout.SOUTH);
toolBar.add(buttonRefresh);
toolBar.addSeparator();
- JLabel about=new JLabel("brought to you by JSwingReader (jswingreader.sourceforge.net)");
+ JLabel about = new JLabel(
+ "brought to you by JSwingReader (jswingreader.sourceforge.net)");
toolBar.add(about);
toolBar.setFloatable(false);
- this.getContentPane().add(toolBar, BorderLayout.NORTH);
+ add(toolBar, BorderLayout.NORTH);
panelMain.add(topBottomSplitPane, BorderLayout.CENTER);
- this.getContentPane().add(panelMain, BorderLayout.CENTER);
+ add(panelMain, BorderLayout.CENTER);
JScrollPane spListItems = new JScrollPane(listItems);
listItems
.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
@@ -366,7 +482,7 @@ public class BlogReader extends GBlogReader
_popupChannels);
listItems.addMouseListener(popupAdapter);
listItems.setCellRenderer(new ItemsRenderer());
- lblChannels.setText("Channels");
+ lblChannels.setText(MessageManager.getString("label.channels"));
}
private void postInit()
@@ -387,21 +503,6 @@ public class BlogReader extends GBlogReader
}
});
- this.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- ActionEvent actionEvent = new ActionEvent(this,
- ActionEvent.ACTION_FIRST, (String) exitAction
- .getValue(Action.NAME));
- exitAction.actionPerformed(actionEvent);
- }
-
- public void windowOpened(WindowEvent e)
- {
- }
- });
-
listItems.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
@@ -629,11 +730,13 @@ public class BlogReader extends GBlogReader
*/
public void refreshNews()
{
- try {
- initItems((Channel)_channelModel.getElementAt(0));
-
+ try
+ {
+ initItems((Channel) _channelModel.getElementAt(0));
+
} catch (Exception x)
- {}
+ {
+ }
}
public static void main(String args[])
@@ -660,20 +763,22 @@ public class BlogReader extends GBlogReader
else
{
Cache.log.info("There is no new news.");
+ me.xf.setTitle("Testing : Last read is " + me.lastDate);
+ me.showNews();
+ me.xf.toFront();
}
- me.setTitle("Testing : Last read is " + me.lastDate);
- me.setVisible(true);
- me.toFront();
- while (me.isVisible())
+ Cache.log.info("Waiting for closure.");
+ do
{
try
{
- Thread.sleep(100);
+ Thread.sleep(300);
} catch (InterruptedException x)
{
}
;
- }
+ } while (me.isVisible());
+
if (me.isNewsNew())
{
Cache.log.info("Still new news after reader displayed.");
@@ -687,7 +792,7 @@ public class BlogReader extends GBlogReader
{
lastread.add(Calendar.MONTH, 1);
}
- me.dispose();
+
}
}
@@ -711,8 +816,14 @@ class ChannelsRenderer extends DefaultListCellRenderer
if (value instanceof Channel)
{
Channel channel = (Channel) value;
- component.setText(channel.getTitle() + " ("
- + channel.getUnreadItemCount() + ")");
+ component
+ .setText(MessageManager.formatMessage(
+ "label.channel_title_item_count",
+ new String[]
+ {
+ channel.getTitle(),
+ Integer.valueOf(channel.getUnreadItemCount())
+ .toString() }));
component.setToolTipText(channel.getURL());
}
return component;
@@ -735,9 +846,15 @@ class ItemsRenderer extends DefaultListCellRenderer
Item item = (Item) value;
if (item.getPublishDate() != null)
{
- component.setText(DateFormat.getDateInstance().format(
- item.getPublishDate())
- + " " + item.getTitle());
+ component.setText(MessageManager.formatMessage(
+ "label.blog_item_published_on_date",
+ new String[]
+ {
+ DateFormat
+ .getDateInstance(DateFormat.LONG,
+ MessageManager.getLocale())
+ .format(item.getPublishDate()).toString(),
+ item.getTitle() }));
}
component.setToolTipText(item.getLink());
if (!item.isRead())