* @author $author$
* @version $Revision$
*/
-public class PCAPanel extends GPCAPanel implements Runnable
+public class PCAPanel extends GPCAPanel implements Runnable, IProgressIndicator
{
PCA pca;
*/
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();
new OOMWarning("calculating PCA", er);
return;
}
+ finally {
+ progress.setProgressBar("", progId);
+ }
calcSettings.setEnabled(true);
repaint();
if (getParent()==null)
@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!
}
}
+ // 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)
{
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
}
});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);