From: jprocter Date: Mon, 26 Sep 2011 09:08:18 +0000 (+0100) Subject: make news window a modal dialog on the jalview desktop (JAL-943) X-Git-Tag: Release_2_7~20 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=ce08afbaee380a375cc5dc2c51892c820371c879 make news window a modal dialog on the jalview desktop (JAL-943) --- diff --git a/src/jalview/gui/BlogReader.java b/src/jalview/gui/BlogReader.java index 989d6c9..50d1e83 100644 --- a/src/jalview/gui/BlogReader.java +++ b/src/jalview/gui/BlogReader.java @@ -1,8 +1,6 @@ package jalview.gui; import jalview.bin.Cache; -import jalview.jbgui.GBlogReader; - import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; @@ -32,6 +30,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; @@ -66,7 +65,7 @@ import org.robsite.jswingreader.ui.util.ContextMenuMouseAdapter; * org.robsite.jswingreader.ui.MainWindow class */ -public class BlogReader extends GBlogReader +public class BlogReader extends JPanel { private JButton buttonRefresh = new JButton(); @@ -106,7 +105,11 @@ 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); @@ -156,6 +159,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(); @@ -182,24 +222,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(); @@ -222,25 +247,73 @@ 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) - { - parent.showNews(true); - } - else + xf = new JFrame(); + xf.setContentPane(me); + xf.addWindowListener(new WindowAdapter() { - 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, true, false, "News from www.jalview.org", + bounds.width, bounds.height); + Cache.log.info("Displaying news."); + jd.waitForInput(); + } + } + }); } /** @@ -248,22 +321,29 @@ 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) {}; + 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); + Cache.log.debug("Scanning news items: newsnew=" + newsnew + + " and lastDate is " + lastDate); for (Item i : (List) chan.getItems()) { - boolean isread = lastDate==null ? false : (i.getPublishDate() != null && !lastDate - .before(i.getPublishDate())); + boolean isread = lastDate == null ? false + : (i.getPublishDate() != null && !lastDate.before(i + .getPublishDate())); if (!updating || updateItems) { @@ -273,18 +353,18 @@ public class BlogReader extends GBlogReader { i.setRead(isread); } - if (i.getPublishDate()!=null && !i.isRead()) + if (i.getPublishDate() != null && !i.isRead()) { - if (earliest==null || earliest.after(i.getPublishDate())) + if (earliest == null || earliest.after(i.getPublishDate())) { - earliest=i.getPublishDate(); + earliest = i.getPublishDate(); } } } } - if (!updateItems && !updating && lastDate==null) + if (!updateItems && !updating && lastDate == null) { - lastDate=earliest; + lastDate = earliest; } return newsnew; } @@ -302,20 +382,20 @@ public class BlogReader extends GBlogReader { if (item.getPublishDate() != null) { - if (lastDate==null || item.getPublishDate().after(lastDate)) + 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", lastDate); + jalview.bin.Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", + lastDate); jalview.bin.Cache.log.info("Saved last read date as " + jalview.bin.Cache.date_format.format(lastDate)); @@ -325,8 +405,7 @@ public class BlogReader extends GBlogReader 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); @@ -339,22 +418,23 @@ public class BlogReader extends GBlogReader statusBar.setText(" [Status] "); 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); @@ -398,21 +478,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) @@ -640,11 +705,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[]) @@ -671,20 +738,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."); @@ -698,7 +767,7 @@ public class BlogReader extends GBlogReader { lastread.add(Calendar.MONTH, 1); } - me.dispose(); + } } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 3205cab..3838e50 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -319,8 +319,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements @Override public void run() { + Cache.log.debug("Starting news thread."); + jvnews = new BlogReader(me); showNews.setVisible(true); + Cache.log.debug("Completed news thread."); } }).start(); @@ -409,22 +412,19 @@ public class Desktop extends jalview.jbgui.GDesktop implements void showNews(boolean visible) { { - jvnews.setVisible(visible); + Cache.log.debug((visible?"Showing":"Hiding")+" news."); showNews.setSelected(visible); - if (visible) + if (visible && !jvnews.isVisible()) { - jvnews.refreshNews(); - jvnews.toFront(); - // try real hard to get focus when the news is first opened new Thread(new Runnable() { @Override public void run() { - while (jvnews.isVisible() && !jvnews.requestFocusInWindow()) - { - try { Thread.sleep(50); } catch (InterruptedException x) {}; - } - + long instance=System.currentTimeMillis(); + Desktop.instance.setProgressBar("Refreshing news", instance); + jvnews.refreshNews(); + Desktop.instance.setProgressBar(null, instance); + jvnews.showNews(); } }).start(); } @@ -2060,10 +2060,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ public void relayerWindows() { - if (jvnews!=null && jvnews.isVisible()) - { - jvnews.toFront(); - } + } protected JMenuItem groovyShell; diff --git a/src/jalview/jbgui/GBlogReader.java b/src/jalview/jbgui/GBlogReader.java deleted file mode 100644 index c27f4b1..0000000 --- a/src/jalview/jbgui/GBlogReader.java +++ /dev/null @@ -1,8 +0,0 @@ -package jalview.jbgui; - -import javax.swing.JFrame; - -public class GBlogReader extends JFrame -{ - -}