X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPCAPanel.java;h=65bfe1c9913e92e58e4f354a753f86da0c676bf5;hb=5e961ebc9a219d2e19341c0fc954f358699d3e20;hp=df0cd03f3dbff3aba033a66164188d38df19f75c;hpb=c25cfde239527da78fecce55a877330afa90701d;p=jalview.git diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index df0cd03..65bfe1c 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -30,10 +30,13 @@ 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.jbgui.GPCAPanel; import jalview.math.RotatableMatrix.Axis; import jalview.util.ImageMaker; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.PCAModel; @@ -49,7 +52,6 @@ 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; @@ -130,8 +132,6 @@ public class PCAPanel extends GPCAPanel addKeyListener(getRotatableCanvas()); validate(); - - this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); } /** @@ -146,15 +146,18 @@ public class PCAPanel extends GPCAPanel @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); } /** @@ -198,10 +201,8 @@ public class PCAPanel extends GPCAPanel repaint(); if (getParent() == null) { - Desktop.addInternalFrame(this, - MessageManager.formatMessage("label.calc_title", "PCA", - getPcaModel().getScoreModelName()), - 475, 450); + addToDesktop(this, getPcaModel().getScoreModelName()); + this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); } working = false; } @@ -408,59 +409,27 @@ 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); + exporter.doExport(null, this, width, height, pca); } @Override @@ -508,11 +477,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 +570,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; @@ -642,19 +607,31 @@ public class PCAPanel extends GPCAPanel // // setMenusForViewport(); // validate(); } + + @Override + public void addProgressBar(long id, String message) + { + progressBar.addProgressBar(id, message); + } + + @Override + public void removeProgressBar(long id) + { + progressBar.removeProgressBar(id); + } @Override public void registerHandler(final long id, 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 +755,29 @@ 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()); + } + + public static void addToDesktop(PCAPanel panel, String modelName) + { + Dimension dim = Platform.getDimIfEmbedded(panel, 475, 450); + Desktop.addInternalFrame(panel, MessageManager.formatMessage( + "label.calc_title", "PCA", modelName), dim.width, + dim.height); + } }