From 4e06055734abdda4bc0dbbe9a1b88dcb806cdd2b Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 15 Jun 2012 11:49:37 +0100 Subject: [PATCH] JAL-1120 patch for desktop --- src/jalview/gui/PCAPanel.java | 123 +++++++++++++++++++++++++++++++++++++- src/jalview/jbgui/GPCAPanel.java | 16 ++++- 2 files changed, 135 insertions(+), 4 deletions(-) diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index adbe906..4c8a251 100755 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -34,7 +34,7 @@ import jalview.jbgui.*; * @author $author$ * @version $Revision$ */ -public class PCAPanel extends GPCAPanel implements Runnable +public class PCAPanel extends GPCAPanel implements Runnable, IProgressIndicator { PCA pca; @@ -131,9 +131,18 @@ public class PCAPanel extends GPCAPanel implements Runnable */ public void run() { + long progId=System.currentTimeMillis(); + IProgressIndicator progress=this; + String message="Recalculating PCA"; + if (getParent()==null) { + progress=ap.alignFrame; + message = "Calculating PCA"; + } + progress.setProgressBar(message, progId); try { calcSettings.setEnabled(false); + pca = new PCA(seqstrings.getSequenceStrings(' '), nucleotide); pca.run(); @@ -181,6 +190,9 @@ public class PCAPanel extends GPCAPanel implements Runnable new OOMWarning("calculating PCA", er); return; } + finally { + progress.setProgressBar("", progId); + } calcSettings.setEnabled(true); repaint(); if (getParent()==null) @@ -192,16 +204,24 @@ public class PCAPanel extends GPCAPanel implements Runnable @Override protected void nuclSetting_actionPerfomed(ActionEvent arg0) { + if (!nucleotide) + { nucleotide=true; Thread worker = new Thread(this); worker.start(); + } + } @Override protected void protSetting_actionPerfomed(ActionEvent arg0) { + + if (nucleotide) + { nucleotide=false; Thread worker = new Thread(this); worker.start(); + } } /** * DOCUMENT ME! @@ -609,7 +629,108 @@ public class PCAPanel extends GPCAPanel implements Runnable } } + // methods for implementing IProgressIndicator + // need to refactor to a reusable stub class + Hashtable progressBars, progressBarHandlers; + + /* + * (non-Javadoc) + * + * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) + */ @Override + public void setProgressBar(String message, long id) + { + if (progressBars == null) + { + progressBars = new Hashtable(); + progressBarHandlers = new Hashtable(); + } + + JPanel progressPanel; + Long lId = new Long(id); + GridLayout layout = (GridLayout) statusPanel.getLayout(); + if (progressBars.get(lId) != null) + { + progressPanel = (JPanel) progressBars.get(new Long(id)); + statusPanel.remove(progressPanel); + progressBars.remove(lId); + progressPanel = null; + if (message != null) + { + statusBar.setText(message); + } + if (progressBarHandlers.contains(lId)) + { + progressBarHandlers.remove(lId); + } + layout.setRows(layout.getRows() - 1); + } + else + { + progressPanel = new JPanel(new BorderLayout(10, 5)); + + JProgressBar progressBar = new JProgressBar(); + progressBar.setIndeterminate(true); + + progressPanel.add(new JLabel(message), BorderLayout.WEST); + progressPanel.add(progressBar, BorderLayout.CENTER); + + layout.setRows(layout.getRows() + 1); + statusPanel.add(progressPanel); + + progressBars.put(lId, progressPanel); + } + // update GUI + // setMenusForViewport(); + validate(); + } + + @Override + public void registerHandler(final long id, + final IProgressIndicatorHandler handler) + { + if (progressBarHandlers == null || !progressBars.contains(new Long(id))) + { + throw new Error( + "call setProgressBar before registering the progress bar's handler."); + } + progressBarHandlers.put(new Long(id), handler); + final JPanel progressPanel = (JPanel) progressBars.get(new Long(id)); + if (handler.canCancel()) + { + JButton cancel = new JButton("Cancel"); + final IProgressIndicator us = this; + cancel.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + handler.cancelActivity(id); + us.setProgressBar( + "Cancelled " + + ((JLabel) progressPanel.getComponent(0)) + .getText(), id); + } + }); + progressPanel.add(cancel, BorderLayout.EAST); + } + } + + /** + * + * @return true if any progress bars are still active + */ + @Override + public boolean operationInProgress() + { + if (progressBars != null && progressBars.size() > 0) + { + return true; + } + return false; + } @Override protected void resetButton_actionPerformed(ActionEvent e) { diff --git a/src/jalview/jbgui/GPCAPanel.java b/src/jalview/jbgui/GPCAPanel.java index e677f4d..c0905a8 100755 --- a/src/jalview/jbgui/GPCAPanel.java +++ b/src/jalview/jbgui/GPCAPanel.java @@ -76,6 +76,10 @@ public class GPCAPanel extends JInternalFrame protected JMenu calcSettings=new JMenu(); protected JCheckBoxMenuItem nuclSetting=new JCheckBoxMenuItem(); protected JCheckBoxMenuItem protSetting=new JCheckBoxMenuItem(); + + protected JLabel statusBar = new JLabel(); + protected GridLayout statusPanelLayout = new GridLayout(); + protected JPanel statusPanel=new JPanel(); public GPCAPanel() { try @@ -255,9 +259,15 @@ public class GPCAPanel extends JInternalFrame } });calcSettings.add(nuclSetting); calcSettings.add(protSetting); - - - this.getContentPane().add(jPanel2, BorderLayout.SOUTH); + statusPanel.setLayout(statusPanelLayout); + statusBar.setFont(new java.awt.Font("Verdana",0,12)); + //statusPanel.setBackground(Color.lightGray); + //statusBar.setBackground(Color.lightGray); + //statusPanel.add(statusBar, null); + JPanel panelBar = new JPanel(new BorderLayout()); + panelBar.add(jPanel2, BorderLayout.NORTH); + panelBar.add(statusPanel, BorderLayout.SOUTH); + this.getContentPane().add(panelBar, BorderLayout.SOUTH); jPanel2.add(jLabel1, null); jPanel2.add(xCombobox, null); jPanel2.add(jLabel2, null); -- 1.7.10.2