From f39cac10ca29dc4745b565a7a60159da6f3daaee Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 15 Jul 2019 09:24:08 +0100 Subject: [PATCH] JAL-3364 submenu for Export Split Frame Image --- resources/lang/Messages.properties | 1 + resources/lang/Messages_es.properties | 1 + src/jalview/bin/Jalview.java | 4 +- src/jalview/gui/AlignFrame.java | 24 ++++++----- src/jalview/gui/AlignmentPanel.java | 72 +++++++++++++++++++++++---------- src/jalview/jbgui/GAlignFrame.java | 50 ++++++++++++++++++----- src/jalview/util/ImageMaker.java | 18 +++++++++ 7 files changed, 125 insertions(+), 45 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index d2d8e88..44125a6 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -689,6 +689,7 @@ label.show_non_positional_features = Show Non-Positional Features label.save_png_image = Save As PNG Image label.load_tree_for_sequence_set = Load a tree for this sequence set label.export_image = Export Image +label.export_split_frame = Export Split Frame Image label.vamsas_store = VAMSAS store label.translate_cDNA = Translate as cDNA label.reverse = Reverse diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index e9e18ce..80c15ab 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -639,6 +639,7 @@ label.show_non_positional_features = Mostrar las caracter label.save_png_image = Guardar como imagen PNG label.load_tree_for_sequence_set = Cargar un árbol para este conjunto de secuencias label.export_image = Exportar imagen +label.export_split_frame = Exportar imagen de la ventana dividida label.vamsas_store = Almacén VAMSAS label.translate_cDNA = Traducir cDNA label.extract_scores = Extraer puntuaciones diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index ca2a584..4bf811a 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -593,7 +593,7 @@ public class Jalview if (outputFormat.equalsIgnoreCase("png")) { - af.createPNG(new File(file)); + af.createPNG(new File(file), false); imageName = (new File(file)).getName(); System.out.println("Creating PNG image: " + file); continue; @@ -648,7 +648,7 @@ public class Jalview File outputFile = new File(file); System.out.println( "Creating EPS file: " + outputFile.getAbsolutePath()); - af.createEPS(outputFile); + af.createEPS(outputFile, false); continue; } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index fcb6572..235a5c8 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1358,33 +1358,35 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! + * Creates and writes a PNG image of the alignment, to the given file if + * specified, else after prompting for the output file * - * @param e - * DOCUMENT ME! + * @param f + * @param forSplitFrame */ @Override - public void createPNG(File f) + public void createPNG(File f, boolean forSplitFrame) { - alignPanel.makePNG(f); + alignPanel.makePNG(f, forSplitFrame); } /** - * DOCUMENT ME! + * Creates and writes an EPS image of the alignment, to the given file if + * specified, else after prompting for the output file * - * @param e - * DOCUMENT ME! + * @param f + * @param forSplitFrame */ @Override - public void createEPS(File f) + public void createEPS(File f, boolean forSplitFrame) { - alignPanel.makeEPS(f); + alignPanel.makeEPS(f, forSplitFrame); } @Override public void createSVG(File f) { - alignPanel.makeSVG(f); + alignPanel.makeSVG(f, false); } @Override diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 3fad3de..73d8148 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -36,6 +36,7 @@ import jalview.math.AlignmentDimension; import jalview.schemes.ResidueProperties; import jalview.structure.StructureSelectionManager; import jalview.util.Comparison; +import jalview.util.ImageMaker; import jalview.util.MessageManager; import jalview.viewmodel.ViewportListenerI; import jalview.viewmodel.ViewportRanges; @@ -1149,7 +1150,17 @@ public class AlignmentPanel extends GAlignmentPanel implements return idwidth.intValue() + 4; } - void makeAlignmentImage(jalview.util.ImageMaker.TYPE type, File file) + /** + * Generates an image of the alignment panel of the specified type. If + * {@code type} is not null, the image is written to the file, otherwise the + * user is prompted to specify the output file before writing to it. + * + * @param type + * @param file + * @param forSplitFrame + */ + void makeAlignmentImage(ImageMaker.TYPE type, File file, + boolean forSplitFrame) { int borderBottomOffset = 5; long pSessionId = System.currentTimeMillis(); @@ -1166,13 +1177,17 @@ public class AlignmentPanel extends GAlignmentPanel implements } try { - // todo splitFrame a parameter (optional menu item choice) - boolean splitFrame = av.getCodingComplement() != null; + /* + * if exporting a split frame image, the graphics object has + * width: maximum of the top and bottom image widths + * height: sum of the top and bottom image heights + */ + AlignmentPanel comp = null; AlignmentDimension dim1 = getAlignmentDimension(); AlignmentDimension dim2 = new AlignmentDimension(0, 0); - if (splitFrame) + if (forSplitFrame) { - AlignmentPanel comp = ((AlignViewport) av.getCodingComplement()) + comp = ((AlignViewport) av.getCodingComplement()) .getAlignPanel(); dim2 = comp.getAlignmentDimension(); } @@ -1180,14 +1195,13 @@ public class AlignmentPanel extends GAlignmentPanel implements + borderBottomOffset; final int graphicsWidth = Math.max(dim1.width, dim2.width); - jalview.util.ImageMaker im; final String imageAction, imageTitle; - if (type == jalview.util.ImageMaker.TYPE.PNG) + if (type == ImageMaker.TYPE.PNG) { imageAction = "Create PNG image from alignment"; imageTitle = null; } - else if (type == jalview.util.ImageMaker.TYPE.EPS) + else if (type == ImageMaker.TYPE.EPS) { imageAction = "Create EPS file from alignment"; imageTitle = alignFrame.getTitle(); @@ -1198,7 +1212,7 @@ public class AlignmentPanel extends GAlignmentPanel implements imageTitle = alignFrame.getTitle(); } - im = new jalview.util.ImageMaker(this, type, imageAction, + ImageMaker im = new ImageMaker(this, type, imageAction, graphicsWidth, graphicsHeight, file, imageTitle, alignFrame, pSessionId, headless); Graphics graphics = im.getGraphics(); @@ -1218,15 +1232,13 @@ public class AlignmentPanel extends GAlignmentPanel implements printUnwrapped(dim1.width, dim1.height, 0, graphics, graphics); } - if (splitFrame) + if (forSplitFrame) { /* * append coding complement image * todo: always write top frame first! */ graphics.translate(0, dim1.height); - AlignmentPanel comp = ((AlignViewport) av.getCodingComplement()) - .getAlignPanel(); if (av.getCodingComplement().getWrapAlignment()) { comp.printWrappedAlignment(dim2.width, @@ -1260,8 +1272,9 @@ public class AlignmentPanel extends GAlignmentPanel implements *
  • sequence ids
  • *
  • scale above, left or right if shown
  • *
  • sequences
  • - *
  • annotations, if shown
  • The alignment may be in wrapped or unwrapped - * mode. + *
  • annotations, if shown
  • + * + * The alignment may be in wrapped or unwrapped mode. *