X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPCAPanel.java;h=211c3706ef49da66f20ec0ff5f2b6e8b6cabfcfe;hb=051cab343aed415a342a787e10ebd075f05243f6;hp=df0cd03f3dbff3aba033a66164188d38df19f75c;hpb=c25cfde239527da78fecce55a877330afa90701d;p=jalview.git diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index df0cd03..211c370 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -20,23 +20,6 @@ */ 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 jalview.viewmodel.PCAModel; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -49,12 +32,31 @@ import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import javax.swing.ButtonGroup; -import javax.swing.JColorChooser; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; +import jalview.analysis.scoremodels.ScoreModels; +import jalview.api.AlignViewportI; +import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.SimilarityParamsI; +import jalview.bin.Console; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.AlignmentView; +import jalview.datamodel.HiddenColumns; +import jalview.datamodel.SequenceI; +import jalview.gui.ImageExporter.ImageWriterI; +import jalview.gui.JalviewColourChooser.ColourChooserListener; +import jalview.io.exceptions.ImageOutputException; +import jalview.jbgui.GPCAPanel; +import jalview.math.RotatableMatrix.Axis; +import jalview.util.ImageMaker; +import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.PCAModel; + /** * The panel holding the Principal Component Analysis 3-D visualisation */ @@ -91,6 +93,7 @@ public class PCAPanel extends GPCAPanel SimilarityParamsI params) { super(); + this.setFrameIcon(null); this.av = alignPanel.av; this.ap = alignPanel; boolean nucleotide = av.getAlignment().isNucleotide(); @@ -121,8 +124,8 @@ public class PCAPanel extends GPCAPanel ScoreModelI scoreModel = ScoreModels.getInstance() .getScoreModel(modelName, ap); - setPcaModel(new PCAModel(seqstrings, seqs, nucleotide, scoreModel, - params)); + setPcaModel( + new PCAModel(seqstrings, seqs, nucleotide, scoreModel, params)); PaintRefresher.Register(this, av.getSequenceSetId()); setRotatableCanvas(new RotatableCanvas(alignPanel)); @@ -130,8 +133,6 @@ public class PCAPanel extends GPCAPanel addKeyListener(getRotatableCanvas()); validate(); - - this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); } /** @@ -141,20 +142,29 @@ public class PCAPanel extends GPCAPanel protected void close_actionPerformed() { setPcaModel(null); + if (this.rc != null) + { + this.rc.sequencePoints = null; + this.rc.setAxisEndPoints(null); + this.rc = null; + } } @Override protected void bgcolour_actionPerformed() { - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_background_colour"), - getRotatableCanvas().getBgColour()); - - if (col != null) + String ttl = MessageManager.getString("label.select_background_colour"); + ColourChooserListener listener = new ColourChooserListener() { - getRotatableCanvas().setBgColour(col); - } - getRotatableCanvas().repaint(); + @Override + public void colourSelected(Color c) + { + rc.setBgColour(c); + rc.repaint(); + } + }; + JalviewColourChooser.showColourChooser(this, ttl, rc.getBgColour(), + listener); } /** @@ -202,6 +212,7 @@ public class PCAPanel extends GPCAPanel MessageManager.formatMessage("label.calc_title", "PCA", getPcaModel().getScoreModelName()), 475, 450); + this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); } working = false; } @@ -288,7 +299,7 @@ public class PCAPanel extends GPCAPanel // JAL-2647 disabled after load from project (until save to project done) if (getPcaModel().getInputData() == null) { - Cache.log.info( + Console.info( "Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action."); return; } @@ -408,58 +419,30 @@ public class PCAPanel extends GPCAPanel } } - /** - * Handler for 'Save as EPS' option - */ - @Override - protected void eps_actionPerformed() - { - makePCAImage(ImageMaker.TYPE.EPS); - } - - /** - * Handler for 'Save as PNG' option - */ - @Override - protected void png_actionPerformed() - { - makePCAImage(ImageMaker.TYPE.PNG); - } - - void makePCAImage(ImageMaker.TYPE type) + public void makePCAImage(ImageMaker.TYPE type) { int width = getRotatableCanvas().getWidth(); int height = getRotatableCanvas().getHeight(); - - ImageMaker im; - - switch (type) + ImageWriterI writer = new ImageWriterI() { - case PNG: - im = new ImageMaker(this, ImageMaker.TYPE.PNG, - "Make PNG image from PCA", width, height, null, null, null, 0, - false); - break; - case EPS: - im = new ImageMaker(this, ImageMaker.TYPE.EPS, - "Make EPS file from PCA", width, height, null, - this.getTitle(), null, 0, false); - 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) - { - getRotatableCanvas().drawBackground(im.getGraphics()); - getRotatableCanvas().drawScene(im.getGraphics()); - if (getRotatableCanvas().drawAxes) + @Override + public void exportImage(Graphics g) throws Exception { - getRotatableCanvas().drawAxes(im.getGraphics()); + RotatableCanvas canvas = getRotatableCanvas(); + canvas.drawBackground(g); + canvas.drawScene(g); + if (canvas.drawAxes) + { + canvas.drawAxes(g); + } } - im.writeImage(); + }; + String pca = MessageManager.getString("label.pca"); + ImageExporter exporter = new ImageExporter(writer, null, type, pca); + try { + exporter.doExport(null, this, width, height, pca); + } catch (ImageOutputException ioex) { + Console.error("Unexpected error whilst writing "+type.toString(),ioex); } } @@ -508,11 +491,7 @@ public class PCAPanel extends GPCAPanel @Override public void actionPerformed(ActionEvent evt) { - getRotatableCanvas().setApplyToAllViews(false); - getRotatableCanvas().av = panel.av; - getRotatableCanvas().ap = panel; - PaintRefresher.Register(PCAPanel.this, - panel.av.getSequenceSetId()); + selectAssociatedView(panel); } }); @@ -605,11 +584,11 @@ public class PCAPanel extends GPCAPanel // } // // 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; @@ -648,13 +627,14 @@ public class PCAPanel extends GPCAPanel 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( @@ -778,4 +758,21 @@ public class PCAPanel extends GPCAPanel { 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()); + } }