X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FPCAPanel.java;h=9f52d26bc76ed8e1b68709fce057b33d97b24d55;hb=062ebc02980364930ceb26dd6c06448af971fe20;hp=d2a6426a00c025b121fd30fb99a213399b23f58d;hpb=ad20cd92225f2ee8c251d39b00b90555d382a616;p=jalview.git
diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java
old mode 100755
new mode 100644
index d2a6426..9f52d26
--- a/src/jalview/gui/PCAPanel.java
+++ b/src/jalview/gui/PCAPanel.java
@@ -1,71 +1,131 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ 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.
+ * 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 .
+ * 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 java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.awt.print.*;
-import javax.swing.*;
-
-import jalview.datamodel.*;
-import jalview.jbgui.*;
+import jalview.analysis.scoremodels.ScoreModels;
+import jalview.analysis.scoremodels.SimilarityParams;
+import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AlignmentView;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.SequenceI;
+import jalview.jbgui.GPCAPanel;
+import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.PCAModel;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JMenuItem;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
+
/**
* DOCUMENT ME!
*
* @author $author$
* @version $Revision$
*/
-public class PCAPanel extends GPCAPanel implements Runnable,
- IProgressIndicator
+public class PCAPanel extends GPCAPanel
+ implements Runnable, IProgressIndicator
{
+ private IProgressIndicator progressBar;
+
RotatableCanvas rc;
AlignmentPanel ap;
- AlignViewport av;
+ AlignmentViewport av;
PCAModel pcaModel;
+ private static final int MIN_WIDTH = 470;
+
+ private static final int MIN_HEIGHT = 250;
+
int top = 0;
+ private boolean working;
+
/**
- * Creates a new PCAPanel object.
+ * Creates a new PCAPanel object using default score model and parameters
*
- * @param av
- * DOCUMENT ME!
- * @param s
- * DOCUMENT ME!
+ * @param alignPanel
+ */
+ public PCAPanel(AlignmentPanel alignPanel)
+ {
+ this(alignPanel,
+ ScoreModels.getInstance()
+ .getDefaultModel(
+ !alignPanel.av.getAlignment().isNucleotide())
+ .getName(),
+ SimilarityParams.SeqSpace);
+ }
+
+ /**
+ * Constructor given sequence data, a similarity (or distance) score model
+ * name, and score calculation parameters
+ *
+ * @param alignPanel
+ * @param modelName
+ * @param params
*/
- public PCAPanel(AlignmentPanel ap)
+ public PCAPanel(AlignmentPanel alignPanel, String modelName,
+ SimilarityParamsI params)
{
- this.av = ap.av;
- this.ap = ap;
+ super();
+ this.av = alignPanel.av;
+ this.ap = alignPanel;
+ boolean nucleotide = av.getAlignment().isNucleotide();
+
+ progressBar = new ProgressBar(statusPanel, statusBar);
+
+ addInternalFrameListener(new InternalFrameAdapter()
+ {
+ @Override
+ public void internalFrameClosed(InternalFrameEvent e)
+ {
+ close_actionPerformed();
+ }
+ });
- boolean sameLength = true;
boolean selected = av.getSelectionGroup() != null
&& av.getSelectionGroup().getSize() > 0;
AlignmentView seqstrings = av.getAlignmentView(selected);
- boolean nucleotide = av.getAlignment().isNucleotide();
SequenceI[] seqs;
if (!selected)
{
@@ -75,42 +135,83 @@ public class PCAPanel extends GPCAPanel implements Runnable,
{
seqs = av.getSelectionGroup().getSequencesInOrder(av.getAlignment());
}
- SeqCigar sq[] = seqstrings.getSequences();
- int length = sq[0].getWidth();
-
- for (int i = 0; i < seqs.length; i++)
- {
- if (sq[i].getWidth() != length)
- {
- sameLength = false;
- break;
- }
- }
- if (!sameLength)
- {
- JOptionPane
- .showMessageDialog(
- Desktop.desktop,
- "The sequences must be aligned before calculating PCA.\n"
- + "Try using the Pad function in the edit menu,\n"
- + "or one of the multiple sequence alignment web services.",
- "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
-
- return;
- }
- pcaModel = new PCAModel(seqstrings, seqs, nucleotide);
+ ScoreModelI scoreModel = ScoreModels.getInstance()
+ .getScoreModel(modelName, ap);
+ pcaModel = new PCAModel(seqstrings, seqs, nucleotide, scoreModel,
+ params);
PaintRefresher.Register(this, av.getSequenceSetId());
- rc = new RotatableCanvas(ap);
+ rc = new RotatableCanvas(alignPanel);
this.getContentPane().add(rc, BorderLayout.CENTER);
Thread worker = new Thread(this);
worker.start();
}
+ /**
+ * Ensure references to potentially very large objects (the PCA matrices) are
+ * nulled when the frame is closed
+ */
+ protected void close_actionPerformed()
+ {
+ pcaModel = null;
+ }
+
+ /**
+ * Repopulate the options and actions under the score model menu when it is
+ * selected. Options will depend on whether 'nucleotide' or 'peptide'
+ * modelling is selected (and also possibly on whether any additional score
+ * models have been added).
+ */
+ @Override
+ protected void scoreModel_menuSelected()
+ {
+ scoreModelMenu.removeAll();
+ for (final ScoreModelI sm : ScoreModels.getInstance().getModels())
+ {
+ final String name = sm.getName();
+ JCheckBoxMenuItem jm = new JCheckBoxMenuItem(name);
+
+ /*
+ * if the score model doesn't provide a description, try to look one
+ * up in the text bundle, falling back on its name
+ */
+ String tooltip = sm.getDescription();
+ if (tooltip == null)
+ {
+ tooltip = MessageManager.getStringOrReturn("label.score_model_",
+ name);
+ }
+ jm.setToolTipText(tooltip);
+ jm.setSelected(pcaModel.getScoreModelName().equals(name));
+ if ((pcaModel.isNucleotide() && sm.isDNA())
+ || (!pcaModel.isNucleotide() && sm.isProtein()))
+ {
+ jm.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (!pcaModel.getScoreModelName().equals(name))
+ {
+ ScoreModelI sm2 = ScoreModels.getInstance()
+ .getScoreModel(name, ap);
+ pcaModel.setScoreModel(sm2);
+ Thread worker = new Thread(PCAPanel.this);
+ worker.start();
+ }
+ }
+ });
+ scoreModelMenu.add(jm);
+ }
+ }
+ }
+
+ @Override
public void bgcolour_actionPerformed(ActionEvent e)
{
- Color col = JColorChooser.showDialog(this, "Select Background Colour",
+ Color col = JColorChooser.showDialog(this,
+ MessageManager.getString("label.select_background_colour"),
rc.bgColour);
if (col != null)
@@ -123,17 +224,19 @@ public class PCAPanel extends GPCAPanel implements Runnable,
/**
* DOCUMENT ME!
*/
+ @Override
public void run()
{
long progId = System.currentTimeMillis();
IProgressIndicator progress = this;
- String message = "Recalculating PCA";
+ String message = MessageManager.getString("label.pca_recalculating");
if (getParent() == null)
{
progress = ap.alignFrame;
- message = "Calculating PCA";
+ message = MessageManager.getString("label.pca_calculating");
}
progress.setProgressBar(message, progId);
+ working = true;
try
{
calcSettings.setEnabled(false);
@@ -147,12 +250,12 @@ public class PCAPanel extends GPCAPanel implements Runnable,
// rc.invalidate();
nuclSetting.setSelected(pcaModel.isNucleotide());
protSetting.setSelected(!pcaModel.isNucleotide());
- jvVersionSetting.setSelected(pcaModel.isJvCalcMode());
top = pcaModel.getTop();
} catch (OutOfMemoryError er)
{
new OOMWarning("calculating PCA", er);
+ working = false;
return;
} finally
{
@@ -163,9 +266,11 @@ public class PCAPanel extends GPCAPanel implements Runnable,
if (getParent() == null)
{
addKeyListener(rc);
- Desktop.addInternalFrame(this, "Principal component analysis", 475,
- 450);
+ Desktop.addInternalFrame(this, MessageManager
+ .getString("label.principal_component_analysis"), 475, 450);
+ this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
}
+ working = false;
}
@Override
@@ -174,6 +279,8 @@ public class PCAPanel extends GPCAPanel implements Runnable,
if (!pcaModel.isNucleotide())
{
pcaModel.setNucleotide(true);
+ pcaModel.setScoreModel(
+ ScoreModels.getInstance().getDefaultModel(false));
Thread worker = new Thread(this);
worker.start();
}
@@ -187,19 +294,13 @@ public class PCAPanel extends GPCAPanel implements Runnable,
if (pcaModel.isNucleotide())
{
pcaModel.setNucleotide(false);
+ pcaModel.setScoreModel(
+ ScoreModels.getInstance().getDefaultModel(true));
Thread worker = new Thread(this);
worker.start();
}
}
- @Override
- protected void jvVersionSetting_actionPerfomed(ActionEvent arg0)
- {
- pcaModel.setJvCalcMode(jvVersionSetting.isSelected());
- Thread worker = new Thread(this);
- worker.start();
- }
-
/**
* DOCUMENT ME!
*/
@@ -226,6 +327,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void xCombobox_actionPerformed(ActionEvent e)
{
doDimensionChange();
@@ -237,6 +339,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void yCombobox_actionPerformed(ActionEvent e)
{
doDimensionChange();
@@ -248,18 +351,21 @@ public class PCAPanel extends GPCAPanel implements Runnable,
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void zCombobox_actionPerformed(ActionEvent e)
{
doDimensionChange();
}
+ @Override
public void outputValues_actionPerformed(ActionEvent e)
{
CutAndPasteTransfer cap = new CutAndPasteTransfer();
try
{
cap.setText(pcaModel.getDetails());
- Desktop.addInternalFrame(cap, "PCA details", 500, 500);
+ Desktop.addInternalFrame(cap,
+ MessageManager.getString("label.pca_details"), 500, 500);
} catch (OutOfMemoryError oom)
{
new OOMWarning("opening PCA details", oom);
@@ -267,25 +373,28 @@ public class PCAPanel extends GPCAPanel implements Runnable,
}
}
+ @Override
public void showLabels_actionPerformed(ActionEvent e)
{
rc.showLabels(showLabels.getState());
}
+ @Override
public void print_actionPerformed(ActionEvent e)
{
PCAPrinter printer = new PCAPrinter();
printer.start();
}
+ @Override
public void originalSeqData_actionPerformed(ActionEvent e)
{
// this was cut'n'pasted from the equivalent TreePanel method - we should
// make this an abstract function of all jalview analysis windows
if (pcaModel.getSeqtrings() == null)
{
- jalview.bin.Cache.log
- .info("Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action.");
+ jalview.bin.Cache.log.info(
+ "Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action.");
return;
}
// decide if av alignment is sufficiently different to original data to
@@ -305,15 +414,16 @@ public class PCAPanel extends GPCAPanel implements Runnable,
}
;
Object[] alAndColsel = pcaModel.getSeqtrings()
- .getAlignmentAndColumnSelection(gc);
+ .getAlignmentAndHiddenColumns(gc);
if (alAndColsel != null && alAndColsel[0] != null)
{
// AlignmentOrder origorder = new AlignmentOrder(alAndColsel[0]);
- Alignment al = new Alignment((SequenceI[]) alAndColsel[0]);
- Alignment dataset = (av != null && av.getAlignment() != null) ? av
- .getAlignment().getDataset() : null;
+ AlignmentI al = new Alignment((SequenceI[]) alAndColsel[0]);
+ AlignmentI dataset = (av != null && av.getAlignment() != null)
+ ? av.getAlignment().getDataset()
+ : null;
if (dataset != null)
{
al.setDataset(dataset);
@@ -322,9 +432,8 @@ public class PCAPanel extends GPCAPanel implements Runnable,
if (true)
{
// make a new frame!
- AlignFrame af = new AlignFrame(al,
- (ColumnSelection) alAndColsel[1], AlignFrame.DEFAULT_WIDTH,
- AlignFrame.DEFAULT_HEIGHT);
+ AlignFrame af = new AlignFrame(al, (HiddenColumns) alAndColsel[1],
+ AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
// >>>This is a fix for the moment, until a better solution is
// found!!<<<
@@ -333,8 +442,10 @@ public class PCAPanel extends GPCAPanel implements Runnable,
// af.addSortByOrderMenuItem(ServiceName + " Ordering",
// msaorder);
- Desktop.addInternalFrame(af, "Original Data for " + this.title,
- AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+ Desktop.addInternalFrame(af, MessageManager.formatMessage(
+ "label.original_data_for_params", new String[]
+ { this.title }), AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
}
}
/*
@@ -349,6 +460,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
class PCAPrinter extends Thread implements Printable
{
+ @Override
public void run()
{
PrinterJob printJob = PrinterJob.getPrinterJob();
@@ -368,6 +480,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
}
}
+ @Override
public int print(Graphics pg, PageFormat pf, int pi)
throws PrinterException
{
@@ -397,9 +510,10 @@ public class PCAPanel extends GPCAPanel implements Runnable,
* @param e
* DOCUMENT ME!
*/
+ @Override
public void eps_actionPerformed(ActionEvent e)
{
- makePCAImage(jalview.util.ImageMaker.EPS);
+ makePCAImage(jalview.util.ImageMaker.TYPE.EPS);
}
/**
@@ -408,28 +522,37 @@ public class PCAPanel extends GPCAPanel implements Runnable,
* @param e
* DOCUMENT ME!
*/
+ @Override
public void png_actionPerformed(ActionEvent e)
{
- makePCAImage(jalview.util.ImageMaker.PNG);
+ makePCAImage(jalview.util.ImageMaker.TYPE.PNG);
}
- void makePCAImage(int type)
+ void makePCAImage(jalview.util.ImageMaker.TYPE type)
{
int width = rc.getWidth();
int height = rc.getHeight();
jalview.util.ImageMaker im;
- if (type == jalview.util.ImageMaker.PNG)
+ if (type == jalview.util.ImageMaker.TYPE.PNG)
{
- im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
- "Make PNG image from PCA", width, height, null, null);
+ im = new jalview.util.ImageMaker(this,
+ jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from PCA",
+ width, height, null, null, null, 0, false);
+ }
+ else if (type == jalview.util.ImageMaker.TYPE.EPS)
+ {
+ im = new jalview.util.ImageMaker(this,
+ jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from PCA",
+ width, height, null, this.getTitle(), null, 0, false);
}
else
{
- im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
- "Make EPS file from PCA", width, height, null,
- this.getTitle());
+ im = new jalview.util.ImageMaker(this,
+ jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
+ width, height, null, this.getTitle(), null, 0, false);
+
}
if (im.getGraphics() != null)
@@ -444,6 +567,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
}
}
+ @Override
public void viewMenu_menuSelected()
{
buildAssociatedViewMenu();
@@ -451,8 +575,8 @@ public class PCAPanel extends GPCAPanel implements Runnable,
void buildAssociatedViewMenu()
{
- AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(av
- .getSequenceSetId());
+ AlignmentPanel[] aps = PaintRefresher
+ .getAssociatedPanels(av.getSequenceSetId());
if (aps.length == 1 && rc.av == aps[0].av)
{
associateViewsMenu.setVisible(false);
@@ -461,7 +585,8 @@ public class PCAPanel extends GPCAPanel implements Runnable,
associateViewsMenu.setVisible(true);
- if ((viewMenu.getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem))
+ if ((viewMenu
+ .getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem))
{
viewMenu.insertSeparator(viewMenu.getItemCount() - 1);
}
@@ -479,6 +604,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
buttonGroup.add(item);
item.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent evt)
{
rc.applyToAllViews = false;
@@ -491,13 +617,15 @@ public class PCAPanel extends GPCAPanel implements Runnable,
associateViewsMenu.add(item);
}
- final JRadioButtonMenuItem itemf = new JRadioButtonMenuItem("All Views");
+ final JRadioButtonMenuItem itemf = new JRadioButtonMenuItem(
+ "All Views");
buttonGroup.add(itemf);
itemf.setSelected(rc.applyToAllViews);
itemf.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent evt)
{
rc.applyToAllViews = itemf.isSelected();
@@ -514,6 +642,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
* jalview.jbgui.GPCAPanel#outputPoints_actionPerformed(java.awt.event.ActionEvent
* )
*/
+ @Override
protected void outputPoints_actionPerformed(ActionEvent e)
{
CutAndPasteTransfer cap = new CutAndPasteTransfer();
@@ -522,7 +651,9 @@ public class PCAPanel extends GPCAPanel implements Runnable,
cap.setText(pcaModel.getPointsasCsv(false,
xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(),
zCombobox.getSelectedIndex()));
- Desktop.addInternalFrame(cap, "Points for " + getTitle(), 500, 500);
+ Desktop.addInternalFrame(cap, MessageManager
+ .formatMessage("label.points_for_params", new String[]
+ { this.getTitle() }), 500, 500);
} catch (OutOfMemoryError oom)
{
new OOMWarning("exporting PCA points", oom);
@@ -537,6 +668,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
* jalview.jbgui.GPCAPanel#outputProjPoints_actionPerformed(java.awt.event
* .ActionEvent)
*/
+ @Override
protected void outputProjPoints_actionPerformed(ActionEvent e)
{
CutAndPasteTransfer cap = new CutAndPasteTransfer();
@@ -545,8 +677,9 @@ public class PCAPanel extends GPCAPanel implements Runnable,
cap.setText(pcaModel.getPointsasCsv(true,
xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(),
zCombobox.getSelectedIndex()));
- Desktop.addInternalFrame(cap, "Transformed points for " + getTitle(),
- 500, 500);
+ Desktop.addInternalFrame(cap, MessageManager.formatMessage(
+ "label.transformed_points_for_params", new String[]
+ { this.getTitle() }), 500, 500);
} catch (OutOfMemoryError oom)
{
new OOMWarning("exporting transformed PCA points", oom);
@@ -554,10 +687,6 @@ public class PCAPanel extends GPCAPanel implements Runnable,
}
}
- // methods for implementing IProgressIndicator
- // need to refactor to a reusable stub class
- Hashtable progressBars, progressBarHandlers;
-
/*
* (non-Javadoc)
*
@@ -566,81 +695,82 @@ public class PCAPanel extends GPCAPanel implements Runnable,
@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();
+ progressBar.setProgressBar(message, 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);
- }
+ progressBar.registerHandler(id, handler);
+ // if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
+ // {
+ // throw new
+ // Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler"));
+ // }
+ // progressBarHandlers.put(new Long(id), handler);
+ // final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
+ // if (handler.canCancel())
+ // {
+ // JButton cancel = new JButton(
+ // MessageManager.getString("action.cancel"));
+ // final IProgressIndicator us = this;
+ // cancel.addActionListener(new ActionListener()
+ // {
+ //
+ // @Override
+ // public void actionPerformed(ActionEvent e)
+ // {
+ // handler.cancelActivity(id);
+ // us.setProgressBar(MessageManager.formatMessage("label.cancelled_params",
+ // new String[]{((JLabel) progressPanel.getComponent(0)).getText()}), id);
+ // }
+ // });
+ // progressPanel.add(cancel, BorderLayout.EAST);
+ // }
}
/**
@@ -650,11 +780,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
@Override
public boolean operationInProgress()
{
- if (progressBars != null && progressBars.size() > 0)
- {
- return true;
- }
- return false;
+ return progressBar.operationInProgress();
}
@Override
@@ -667,4 +793,14 @@ public class PCAPanel extends GPCAPanel implements Runnable,
top = t;
zCombobox.setSelectedIndex(2);
}
+
+ /**
+ * Answers true if PCA calculation is in progress, else false
+ *
+ * @return
+ */
+ public boolean isWorking()
+ {
+ return working;
+ }
}