package jalview.gui;
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.HiddenColumns;
import jalview.datamodel.SequenceI;
import jalview.jbgui.GPCAPanel;
+import jalview.util.ImageMaker;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.PCAModel;
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.InternalFrameEvent;
/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
+ * The panel holding the Principal Component Analysis 3-d visualisation
*/
public class PCAPanel extends GPCAPanel
implements Runnable, IProgressIndicator
{
-
- private IProgressIndicator progressBar;
-
RotatableCanvas rc;
AlignmentPanel ap;
PCAModel pcaModel;
+ int top = 0;
+
private static final int MIN_WIDTH = 470;
private static final int MIN_HEIGHT = 250;
- int top = 0;
+ private IProgressIndicator progressBar;
private boolean working;
/**
- * Creates a new PCAPanel object using default score model and parameters
- *
- * @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
*
rc = new RotatableCanvas(alignPanel);
this.getContentPane().add(rc, BorderLayout.CENTER);
+
+ /*
+ * perform calculation in a new Thread
+ */
Thread worker = new Thread(this);
worker.start();
}
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)
+ protected void bgcolour_actionPerformed()
{
Color col = JColorChooser.showDialog(this,
MessageManager.getString("label.select_background_colour"),
}
/**
- * DOCUMENT ME!
+ * Calculates the PCA and displays the results
*/
@Override
public void run()
working = true;
try
{
- calcSettings.setEnabled(false);
pcaModel.run();
// ////////////////
xCombobox.setSelectedIndex(0);
pcaModel.updateRc(rc);
// rc.invalidate();
- nuclSetting.setSelected(pcaModel.isNucleotide());
- protSetting.setSelected(!pcaModel.isNucleotide());
top = pcaModel.getTop();
} catch (OutOfMemoryError er)
{
progress.setProgressBar("", progId);
}
- calcSettings.setEnabled(true);
+
repaint();
if (getParent() == null)
{
addKeyListener(rc);
- Desktop.addInternalFrame(this, MessageManager
- .getString("label.principal_component_analysis"), 475, 450);
+ Desktop.addInternalFrame(this,
+ MessageManager.formatMessage("label.calc_title", "PCA",
+ pcaModel.getScoreModelName()),
+ 475, 450);
this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
}
working = false;
}
- @Override
- protected void nuclSetting_actionPerfomed(ActionEvent arg0)
- {
- if (!pcaModel.isNucleotide())
- {
- pcaModel.setNucleotide(true);
- pcaModel.setScoreModel(
- ScoreModels.getInstance().getDefaultModel(false));
- Thread worker = new Thread(this);
- worker.start();
- }
-
- }
-
- @Override
- protected void protSetting_actionPerfomed(ActionEvent arg0)
- {
-
- if (pcaModel.isNucleotide())
- {
- pcaModel.setNucleotide(false);
- pcaModel.setScoreModel(
- ScoreModels.getInstance().getDefaultModel(true));
- Thread worker = new Thread(this);
- worker.start();
- }
- }
-
/**
- * DOCUMENT ME!
+ * Updates the PCA display after a change of component to use for x, y or z
+ * axis
*/
- void doDimensionChange()
+ @Override
+ protected void doDimensionChange()
{
if (top == 0)
{
rc.paint(rc.getGraphics());
}
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- protected void xCombobox_actionPerformed(ActionEvent e)
- {
- doDimensionChange();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
@Override
- protected void yCombobox_actionPerformed(ActionEvent e)
- {
- doDimensionChange();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- protected void zCombobox_actionPerformed(ActionEvent e)
- {
- doDimensionChange();
- }
-
- @Override
- public void outputValues_actionPerformed(ActionEvent e)
+ protected void outputValues_actionPerformed()
{
CutAndPasteTransfer cap = new CutAndPasteTransfer();
try
}
@Override
- public void showLabels_actionPerformed(ActionEvent e)
+ protected void showLabels_actionPerformed()
{
rc.showLabels(showLabels.getState());
}
@Override
- public void print_actionPerformed(ActionEvent e)
+ protected void print_actionPerformed()
{
PCAPrinter printer = new PCAPrinter();
printer.start();
}
@Override
- public void originalSeqData_actionPerformed(ActionEvent e)
+ 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
} catch (Exception ex)
{
}
- ;
+
Object[] alAndColsel = pcaModel.getSeqtrings()
.getAlignmentAndHiddenColumns(gc);
rc.drawBackground(pg, rc.bgColour);
rc.drawScene(pg);
- if (rc.drawAxes == true)
+ if (rc.drawAxes)
{
rc.drawAxes(pg);
}
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Handler for 'Save as EPS' option
*/
@Override
- public void eps_actionPerformed(ActionEvent e)
+ protected void eps_actionPerformed()
{
- makePCAImage(jalview.util.ImageMaker.TYPE.EPS);
+ makePCAImage(ImageMaker.TYPE.EPS);
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Handler for 'Save as PNG' option
*/
@Override
- public void png_actionPerformed(ActionEvent e)
+ protected void png_actionPerformed()
{
- makePCAImage(jalview.util.ImageMaker.TYPE.PNG);
+ makePCAImage(ImageMaker.TYPE.PNG);
}
- void makePCAImage(jalview.util.ImageMaker.TYPE type)
+ void makePCAImage(ImageMaker.TYPE type)
{
int width = rc.getWidth();
int height = rc.getHeight();
- jalview.util.ImageMaker im;
+ ImageMaker im;
- if (type == jalview.util.ImageMaker.TYPE.PNG)
+ if (type == ImageMaker.TYPE.PNG)
{
- im = new jalview.util.ImageMaker(this,
- jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from PCA",
- width, height, null, null, null, 0, false);
+ 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)
{
- im = new jalview.util.ImageMaker(this,
- jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from PCA",
- width, height, null, this.getTitle(), null, 0, false);
+ im = new ImageMaker(this, 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.TYPE.SVG, "Make SVG file from PCA",
- width, height, null, this.getTitle(), null, 0, false);
-
+ 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 == true)
+ if (rc.drawAxes)
{
rc.drawAxes(im.getGraphics());
}
}
@Override
- public void viewMenu_menuSelected()
+ protected void viewMenu_menuSelected()
{
buildAssociatedViewMenu();
}
+ /**
+ * Builds the menu showing the choice of possible views (for the associated
+ * sequence data) to which the PCA may be linked
+ */
void buildAssociatedViewMenu()
{
AlignmentPanel[] aps = PaintRefresher
JRadioButtonMenuItem item;
ButtonGroup buttonGroup = new ButtonGroup();
- int i, iSize = aps.length;
- final PCAPanel thisPCAPanel = this;
- for (i = 0; i < iSize; i++)
+ int iSize = aps.length;
+
+ for (int i = 0; i < iSize; i++)
{
- final AlignmentPanel ap = aps[i];
- item = new JRadioButtonMenuItem(ap.av.viewName, ap.av == rc.av);
+ final AlignmentPanel panel = aps[i];
+ item = new JRadioButtonMenuItem(panel.av.viewName, panel.av == rc.av);
buttonGroup.add(item);
item.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
rc.applyToAllViews = false;
- rc.av = ap.av;
- rc.ap = ap;
- PaintRefresher.Register(thisPCAPanel, ap.av.getSequenceSetId());
+ rc.av = panel.av;
+ rc.ap = panel;
+ PaintRefresher.Register(PCAPanel.this,
+ panel.av.getSequenceSetId());
}
});
* )
*/
@Override
- protected void outputPoints_actionPerformed(ActionEvent e)
+ protected void outputPoints_actionPerformed()
{
CutAndPasteTransfer cap = new CutAndPasteTransfer();
try
* .ActionEvent)
*/
@Override
- protected void outputProjPoints_actionPerformed(ActionEvent e)
+ protected void outputProjPoints_actionPerformed()
{
CutAndPasteTransfer cap = new CutAndPasteTransfer();
try
}
@Override
- protected void resetButton_actionPerformed(ActionEvent e)
+ protected void resetButton_actionPerformed()
{
int t = top;
top = 0; // ugly - prevents dimensionChanged events from being processed
{
private static final Font VERDANA_12 = new Font("Verdana", 0, 12);
- protected JComboBox<String> xCombobox = new JComboBox<String>();
+ protected JComboBox<String> xCombobox = new JComboBox<>();
- protected JComboBox<String> yCombobox = new JComboBox<String>();
+ protected JComboBox<String> yCombobox = new JComboBox<>();
- protected JComboBox<String> zCombobox = new JComboBox<String>();
-
- protected JMenu scoreModelMenu = new JMenu();
+ protected JComboBox<String> zCombobox = new JComboBox<>();
protected JMenu viewMenu = new JMenu();
protected JMenu associateViewsMenu = new JMenu();
- protected JMenu calcSettings = new JMenu();
-
- protected JCheckBoxMenuItem nuclSetting = new JCheckBoxMenuItem();
-
- protected JCheckBoxMenuItem protSetting = new JCheckBoxMenuItem();
-
protected JLabel statusBar = new JLabel();
protected JPanel statusPanel = new JPanel();
+ /**
+ * Constructor
+ */
public GPCAPanel()
{
try
@Override
public void actionPerformed(ActionEvent e)
{
- zCombobox_actionPerformed(e);
+ doDimensionChange();
}
});
yCombobox.setFont(VERDANA_12);
@Override
public void actionPerformed(ActionEvent e)
{
- yCombobox_actionPerformed(e);
+ doDimensionChange();
}
});
xCombobox.setFont(VERDANA_12);
@Override
public void actionPerformed(ActionEvent e)
{
- xCombobox_actionPerformed(e);
+ doDimensionChange();
}
});
JButton resetButton = new JButton();
@Override
public void actionPerformed(ActionEvent e)
{
- resetButton_actionPerformed(e);
+ resetButton_actionPerformed();
}
});
JMenu fileMenu = new JMenu();
@Override
public void actionPerformed(ActionEvent e)
{
- eps_actionPerformed(e);
+ eps_actionPerformed();
}
});
JMenuItem png = new JMenuItem("PNG");
@Override
public void actionPerformed(ActionEvent e)
{
- png_actionPerformed(e);
+ png_actionPerformed();
}
});
JMenuItem outputValues = new JMenuItem();
@Override
public void actionPerformed(ActionEvent e)
{
- outputValues_actionPerformed(e);
+ outputValues_actionPerformed();
}
});
JMenuItem outputPoints = new JMenuItem();
@Override
public void actionPerformed(ActionEvent e)
{
- outputPoints_actionPerformed(e);
+ outputPoints_actionPerformed();
}
});
JMenuItem outputProjPoints = new JMenuItem();
@Override
public void actionPerformed(ActionEvent e)
{
- outputProjPoints_actionPerformed(e);
+ outputProjPoints_actionPerformed();
}
});
JMenuItem print = new JMenuItem();
@Override
public void actionPerformed(ActionEvent e)
{
- print_actionPerformed(e);
+ print_actionPerformed();
}
});
viewMenu.setText(MessageManager.getString("action.view"));
{
}
});
- scoreModelMenu
- .setText(MessageManager.getString("label.select_score_model"));
- scoreModelMenu.addMenuListener(new MenuListener()
- {
- @Override
- public void menuSelected(MenuEvent e)
- {
- scoreModel_menuSelected();
- }
-
- @Override
- public void menuDeselected(MenuEvent e)
- {
- }
-
- @Override
- public void menuCanceled(MenuEvent e)
- {
- }
- });
showLabels.setText(MessageManager.getString("label.show_labels"));
showLabels.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- showLabels_actionPerformed(e);
+ showLabels_actionPerformed();
}
});
JMenuItem bgcolour = new JMenuItem();
@Override
public void actionPerformed(ActionEvent e)
{
- bgcolour_actionPerformed(e);
+ bgcolour_actionPerformed();
}
});
JMenuItem originalSeqData = new JMenuItem();
@Override
public void actionPerformed(ActionEvent e)
{
- originalSeqData_actionPerformed(e);
+ originalSeqData_actionPerformed();
}
});
associateViewsMenu.setText(
MessageManager.getString("label.associate_nodes_with"));
- calcSettings.setText(MessageManager.getString("action.change_params"));
- nuclSetting
- .setText(MessageManager.getString("label.nucleotide_matrix"));
- protSetting.setText(MessageManager.getString("label.protein_matrix"));
- nuclSetting.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent arg0)
- {
- nuclSetting_actionPerfomed(arg0);
- }
- });
- protSetting.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent arg0)
- {
- protSetting_actionPerfomed(arg0);
- }
- });
-
- calcSettings.add(nuclSetting);
- calcSettings.add(protSetting);
- calcSettings.add(scoreModelMenu);
statusPanel.setLayout(new GridLayout());
statusBar.setFont(VERDANA_12);
// statusPanel.setBackground(Color.lightGray);
JMenuBar jMenuBar1 = new JMenuBar();
jMenuBar1.add(fileMenu);
jMenuBar1.add(viewMenu);
- jMenuBar1.add(calcSettings);
setJMenuBar(jMenuBar1);
fileMenu.add(saveMenu);
fileMenu.add(outputValues);
viewMenu.add(associateViewsMenu);
}
- protected void scoreModel_menuSelected()
- {
- // TODO Auto-generated method stub
-
- }
-
- protected void resetButton_actionPerformed(ActionEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- protected void protSetting_actionPerfomed(ActionEvent arg0)
- {
- // TODO Auto-generated method stub
-
- }
-
- protected void nuclSetting_actionPerfomed(ActionEvent arg0)
- {
- // TODO Auto-generated method stub
-
- }
-
- protected void outputPoints_actionPerformed(ActionEvent e)
+ protected void resetButton_actionPerformed()
{
- // TODO Auto-generated method stub
-
}
- protected void outputProjPoints_actionPerformed(ActionEvent e)
+ protected void outputPoints_actionPerformed()
{
- // TODO Auto-generated method stub
-
}
- protected void xCombobox_actionPerformed(ActionEvent e)
+ protected void outputProjPoints_actionPerformed()
{
}
- protected void yCombobox_actionPerformed(ActionEvent e)
+ protected void eps_actionPerformed()
{
}
- protected void zCombobox_actionPerformed(ActionEvent e)
+ protected void png_actionPerformed()
{
}
- public void eps_actionPerformed(ActionEvent e)
+ protected void outputValues_actionPerformed()
{
-
}
- public void png_actionPerformed(ActionEvent e)
+ protected void print_actionPerformed()
{
-
}
- public void outputValues_actionPerformed(ActionEvent e)
+ protected void showLabels_actionPerformed()
{
-
}
- public void print_actionPerformed(ActionEvent e)
+ protected void bgcolour_actionPerformed()
{
-
}
- public void showLabels_actionPerformed(ActionEvent e)
+ protected void originalSeqData_actionPerformed()
{
-
}
- public void bgcolour_actionPerformed(ActionEvent e)
+ protected void viewMenu_menuSelected()
{
-
}
- public void originalSeqData_actionPerformed(ActionEvent e)
+ protected void doDimensionChange()
{
-
- }
-
- public void viewMenu_menuSelected()
- {
-
}
}