package jalview.gui;
import jalview.analysis.scoremodels.ScoreModels;
+import jalview.api.AlignViewportI;
import jalview.api.analysis.ScoreModelI;
import jalview.api.analysis.SimilarityParamsI;
+import jalview.bin.Cache;
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.math.RotatableMatrix.Axis;
import jalview.util.ImageMaker;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
import javax.swing.event.InternalFrameEvent;
/**
- * The panel holding the Principal Component Analysis 3-d visualisation
+ * The panel holding the Principal Component Analysis 3-D visualisation
*/
public class PCAPanel extends GPCAPanel
implements Runnable, IProgressIndicator
{
- RotatableCanvas rc;
+ private static final int MIN_WIDTH = 470;
- AlignmentPanel ap;
+ private static final int MIN_HEIGHT = 250;
- AlignmentViewport av;
+ private RotatableCanvas rc;
- PCAModel pcaModel;
+ AlignmentPanel ap;
- int top = 0;
+ AlignmentViewport av;
- private static final int MIN_WIDTH = 470;
+ private PCAModel pcaModel;
- private static final int MIN_HEIGHT = 250;
+ private int top = 0;
private IProgressIndicator progressBar;
ScoreModelI scoreModel = ScoreModels.getInstance()
.getScoreModel(modelName, ap);
- pcaModel = new PCAModel(seqstrings, seqs, nucleotide, scoreModel,
- params);
+ setPcaModel(new PCAModel(seqstrings, seqs, nucleotide, scoreModel,
+ params));
PaintRefresher.Register(this, av.getSequenceSetId());
- rc = new RotatableCanvas(alignPanel);
- this.getContentPane().add(rc, BorderLayout.CENTER);
+ setRotatableCanvas(new RotatableCanvas(alignPanel));
+ this.getContentPane().add(getRotatableCanvas(), BorderLayout.CENTER);
- /*
- * perform calculation in a new Thread
- */
- Thread worker = new Thread(this);
- worker.start();
+ addKeyListener(getRotatableCanvas());
+ validate();
+
+ this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
}
/**
*/
protected void close_actionPerformed()
{
- pcaModel = null;
+ setPcaModel(null);
}
@Override
{
Color col = JColorChooser.showDialog(this,
MessageManager.getString("label.select_background_colour"),
- rc.bgColour);
+ getRotatableCanvas().getBgColour());
if (col != null)
{
- rc.bgColour = col;
+ getRotatableCanvas().setBgColour(col);
}
- rc.repaint();
+ getRotatableCanvas().repaint();
}
/**
@Override
public void run()
{
+ working = true;
long progId = System.currentTimeMillis();
IProgressIndicator progress = this;
String message = MessageManager.getString("label.pca_recalculating");
message = MessageManager.getString("label.pca_calculating");
}
progress.setProgressBar(message, progId);
- working = true;
try
{
- pcaModel.calculate();
- // ////////////////
+ getPcaModel().calculate();
+
xCombobox.setSelectedIndex(0);
yCombobox.setSelectedIndex(1);
zCombobox.setSelectedIndex(2);
- pcaModel.updateRc(rc);
+ getPcaModel().updateRc(getRotatableCanvas());
// rc.invalidate();
- top = pcaModel.getTop();
+ setTop(getPcaModel().getTop());
} catch (OutOfMemoryError er)
{
repaint();
if (getParent() == null)
{
- addKeyListener(rc);
Desktop.addInternalFrame(this,
MessageManager.formatMessage("label.calc_title", "PCA",
- pcaModel.getScoreModelName()),
+ getPcaModel().getScoreModelName()),
475, 450);
- this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
}
working = false;
}
@Override
protected void doDimensionChange()
{
- if (top == 0)
+ if (getTop() == 0)
{
return;
}
- int dim1 = top - xCombobox.getSelectedIndex();
- int dim2 = top - yCombobox.getSelectedIndex();
- int dim3 = top - zCombobox.getSelectedIndex();
- pcaModel.updateRcView(dim1, dim2, dim3);
- rc.img = null;
- rc.rotmat.setIdentity();
- rc.initAxes();
- rc.paint(rc.getGraphics());
+ int dim1 = getTop() - xCombobox.getSelectedIndex();
+ int dim2 = getTop() - yCombobox.getSelectedIndex();
+ int dim3 = getTop() - zCombobox.getSelectedIndex();
+ getPcaModel().updateRcView(dim1, dim2, dim3);
+ getRotatableCanvas().resetView();
+ }
+
+ /**
+ * Sets the selected checkbox item index for PCA dimension (1, 2, 3...) for
+ * the given axis (X/Y/Z)
+ *
+ * @param index
+ * @param axis
+ */
+ public void setSelectedDimensionIndex(int index, Axis axis)
+ {
+ switch (axis)
+ {
+ case X:
+ xCombobox.setSelectedIndex(index);
+ break;
+ case Y:
+ yCombobox.setSelectedIndex(index);
+ break;
+ case Z:
+ zCombobox.setSelectedIndex(index);
+ break;
+ default:
+ }
}
@Override
CutAndPasteTransfer cap = new CutAndPasteTransfer();
try
{
- cap.setText(pcaModel.getDetails());
+ cap.setText(getPcaModel().getDetails());
Desktop.addInternalFrame(cap,
MessageManager.getString("label.pca_details"), 500, 500);
} catch (OutOfMemoryError oom)
@Override
protected void showLabels_actionPerformed()
{
- rc.showLabels(showLabels.getState());
+ getRotatableCanvas().showLabels(showLabels.getState());
}
@Override
printer.start();
}
+ /**
+ * If available, shows the data which formed the inputs for the PCA as a new
+ * alignment
+ */
@Override
public void originalSeqData_actionPerformed()
{
- // 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)
+ // JAL-2647 disabled after load from project (until save to project done)
+ if (getPcaModel().getInputData() == null)
{
- jalview.bin.Cache.log.info(
+ 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
// warrant a new window to be created
- // create new alignmnt window with hidden regions (unhiding hidden regions
+ // create new alignment window with hidden regions (unhiding hidden regions
// yields unaligned seqs)
// or create a selection box around columns in alignment view
// test Alignment(SeqCigar[])
{
}
- Object[] alAndColsel = pcaModel.getSeqtrings()
+ Object[] alAndColsel = getPcaModel().getInputData()
.getAlignmentAndHiddenColumns(gc);
if (alAndColsel != null && alAndColsel[0] != null)
{
pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
- rc.drawBackground(pg, rc.bgColour);
- rc.drawScene(pg);
- if (rc.drawAxes)
+ getRotatableCanvas().drawBackground(pg);
+ getRotatableCanvas().drawScene(pg);
+ if (getRotatableCanvas().drawAxes)
{
- rc.drawAxes(pg);
+ getRotatableCanvas().drawAxes(pg);
}
if (pi == 0)
void makePCAImage(ImageMaker.TYPE type)
{
- int width = rc.getWidth();
- int height = rc.getHeight();
+ int width = getRotatableCanvas().getWidth();
+ int height = getRotatableCanvas().getHeight();
ImageMaker im;
- if (type == ImageMaker.TYPE.PNG)
+ switch (type)
{
+ case PNG:
im = new ImageMaker(this, ImageMaker.TYPE.PNG,
"Make PNG image from PCA", width, height, null, null, null, 0,
false);
- }
- else if (type == jalview.util.ImageMaker.TYPE.EPS)
- {
+ break;
+ case EPS:
im = new ImageMaker(this, ImageMaker.TYPE.EPS,
"Make EPS file from PCA", width, height, null,
this.getTitle(), null, 0, false);
- }
- else
- {
+ break;
+ default:
im = new ImageMaker(this, ImageMaker.TYPE.SVG,
"Make SVG file from PCA", width, height, null,
this.getTitle(), null, 0, false);
if (im.getGraphics() != null)
{
- rc.drawBackground(im.getGraphics(), Color.black);
- rc.drawScene(im.getGraphics());
- if (rc.drawAxes)
+ getRotatableCanvas().drawBackground(im.getGraphics());
+ getRotatableCanvas().drawScene(im.getGraphics());
+ if (getRotatableCanvas().drawAxes)
{
- rc.drawAxes(im.getGraphics());
+ getRotatableCanvas().drawAxes(im.getGraphics());
}
im.writeImage();
}
{
AlignmentPanel[] aps = PaintRefresher
.getAssociatedPanels(av.getSequenceSetId());
- if (aps.length == 1 && rc.av == aps[0].av)
+ if (aps.length == 1 && getRotatableCanvas().av == aps[0].av)
{
associateViewsMenu.setVisible(false);
return;
for (int i = 0; i < iSize; i++)
{
final AlignmentPanel panel = aps[i];
- item = new JRadioButtonMenuItem(panel.av.viewName, panel.av == rc.av);
+ item = new JRadioButtonMenuItem(panel.av.getViewName(),
+ panel.av == getRotatableCanvas().av);
buttonGroup.add(item);
item.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent evt)
{
- rc.applyToAllViews = false;
- rc.av = panel.av;
- rc.ap = panel;
- PaintRefresher.Register(PCAPanel.this,
- panel.av.getSequenceSetId());
+ selectAssociatedView(panel);
}
});
buttonGroup.add(itemf);
- itemf.setSelected(rc.applyToAllViews);
+ itemf.setSelected(getRotatableCanvas().isApplyToAllViews());
itemf.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent evt)
{
- rc.applyToAllViews = itemf.isSelected();
+ getRotatableCanvas().setApplyToAllViews(itemf.isSelected());
}
});
associateViewsMenu.add(itemf);
CutAndPasteTransfer cap = new CutAndPasteTransfer();
try
{
- cap.setText(pcaModel.getPointsasCsv(false,
+ cap.setText(getPcaModel().getPointsasCsv(false,
xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(),
zCombobox.getSelectedIndex()));
Desktop.addInternalFrame(cap, MessageManager
CutAndPasteTransfer cap = new CutAndPasteTransfer();
try
{
- cap.setText(pcaModel.getPointsasCsv(true,
+ cap.setText(getPcaModel().getPointsasCsv(true,
xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(),
zCombobox.getSelectedIndex()));
Desktop.addInternalFrame(cap, MessageManager.formatMessage(
// }
//
// JPanel progressPanel;
- // Long lId = new Long(id);
+ // Long lId = Long.valueOf(id);
// GridLayout layout = (GridLayout) statusPanel.getLayout();
// if (progressBars.get(lId) != null)
// {
- // progressPanel = (JPanel) progressBars.get(new Long(id));
+ // progressPanel = (JPanel) progressBars.get(Long.valueOf(id));
// statusPanel.remove(progressPanel);
// progressBars.remove(lId);
// progressPanel = null;
final IProgressIndicatorHandler handler)
{
progressBar.registerHandler(id, handler);
- // if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
+ // if (progressBarHandlers == null || !progressBars.contains(Long.valueOf(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));
+ // progressBarHandlers.put(Long.valueOf(id), handler);
+ // final JPanel progressPanel = (JPanel) progressBars.get(Long.valueOf(id));
// if (handler.canCancel())
// {
// JButton cancel = new JButton(
@Override
protected void resetButton_actionPerformed()
{
- int t = top;
- top = 0; // ugly - prevents dimensionChanged events from being processed
+ int t = getTop();
+ setTop(0); // ugly - prevents dimensionChanged events from being processed
xCombobox.setSelectedIndex(0);
yCombobox.setSelectedIndex(1);
- top = t;
+ setTop(t);
zCombobox.setSelectedIndex(2);
}
{
return working;
}
+
+ /**
+ * Answers the selected checkbox item index for PCA dimension for the X, Y or
+ * Z axis of the display
+ *
+ * @param axis
+ * @return
+ */
+ public int getSelectedDimensionIndex(Axis axis)
+ {
+ switch (axis)
+ {
+ case X:
+ return xCombobox.getSelectedIndex();
+ case Y:
+ return yCombobox.getSelectedIndex();
+ default:
+ return zCombobox.getSelectedIndex();
+ }
+ }
+
+ public void setShowLabels(boolean show)
+ {
+ showLabels.setSelected(show);
+ }
+
+ /**
+ * Sets the input data used to calculate the PCA. This is provided for
+ * 'restore from project', which does not currently support this (AL-2647), so
+ * sets the value to null, and hides the menu option for "Input Data...". J
+ *
+ * @param data
+ */
+ public void setInputData(AlignmentView data)
+ {
+ getPcaModel().setInputData(data);
+ originalSeqData.setVisible(data != null);
+ }
+
+ public AlignViewportI getAlignViewport()
+ {
+ return av;
+ }
+
+ public PCAModel getPcaModel()
+ {
+ return pcaModel;
+ }
+
+ public void setPcaModel(PCAModel pcaModel)
+ {
+ this.pcaModel = pcaModel;
+ }
+
+ public RotatableCanvas getRotatableCanvas()
+ {
+ return rc;
+ }
+
+ public void setRotatableCanvas(RotatableCanvas rc)
+ {
+ this.rc = rc;
+ }
+
+ public int getTop()
+ {
+ return top;
+ }
+
+ public void setTop(int top)
+ {
+ this.top = top;
+ }
+
+ /**
+ * set the associated view for this PCA.
+ *
+ * @param panel
+ */
+ public void selectAssociatedView(AlignmentPanel panel)
+ {
+ getRotatableCanvas().setApplyToAllViews(false);
+
+ ap = panel;
+ av = panel.av;
+
+ getRotatableCanvas().av = panel.av;
+ getRotatableCanvas().ap = panel;
+ PaintRefresher.Register(PCAPanel.this, panel.av.getSequenceSetId());
+ }
}