*/
package jalview.appletgui;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.CheckboxMenuItem;
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Label;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.Panel;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import org.jmol.viewer.Viewer;
+
import jalview.analysis.AlignmentSorter;
import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
import jalview.analysis.TreeBuilder;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.ViewportRanges;
-import java.awt.BorderLayout;
-import java.awt.Canvas;
-import java.awt.CheckboxMenuItem;
-import java.awt.Color;
-import java.awt.FlowLayout;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Frame;
-import java.awt.Graphics;
-import java.awt.Label;
-import java.awt.Menu;
-import java.awt.MenuBar;
-import java.awt.MenuItem;
-import java.awt.Panel;
-import java.awt.Rectangle;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.util.Arrays;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import org.jmol.viewer.Viewer;
-
public class AlignFrame extends EmbmenuFrame implements ActionListener,
ItemListener, KeyListener, AlignViewControllerGuiI
{
import java.util.Map;
import jalview.analysis.AlignmentUtils;
+import jalview.api.structures.JalviewStructureDisplayI;
import jalview.bin.argparser.Arg;
import jalview.bin.argparser.ArgParser;
import jalview.bin.argparser.ArgParser.Position;
import jalview.datamodel.annotations.AlphaFoldAnnotationRowBuilder;
import jalview.gui.AlignFrame;
import jalview.gui.AlignmentPanel;
+import jalview.gui.AppJmol;
import jalview.gui.Desktop;
import jalview.gui.Preferences;
import jalview.gui.StructureChooser;
import jalview.io.NewickFile;
import jalview.structure.StructureImportSettings.TFType;
import jalview.structure.StructureSelectionManager;
+import jalview.util.FileUtils;
import jalview.util.HttpUtils;
+import jalview.util.ImageMaker;
+import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.imagemaker.BitmapImageSizing;
public class Commands
{
argParser = argparser;
headless = h;
desktop = d;
- afMap = new HashMap<String, AlignFrame>();
+ afMap = new HashMap<>();
if (argparser != null)
{
processArgs(argparser, headless);
|| Cache.getDefault("ADD_TEMPFACT_ANN", false));
// TODO use ssFromStructure
- StructureChooser.openStructureFileForSequence(null, null, ap, seq,
- false, structureFilepath, tft, paeFilepath, false,
- ssFromStructure, false, viewerType);
+ StructureViewer sv = StructureChooser
+ .openStructureFileForSequence(null, null, ap, seq, false,
+ structureFilepath, tft, paeFilepath, false,
+ ssFromStructure, false, viewerType);
- String structureImage = ArgParser.getValueFromSubValOrArg(avm, av,
- Arg.STRUCTUREIMAGE, subVals);
+ if (headless)
+ {
+ sv.setAsync(false);
+ }
+
+ String structureImageFilename = ArgParser.getValueFromSubValOrArg(
+ avm, av, Arg.STRUCTUREIMAGE, subVals);
+ if (sv != null && structureImageFilename != null)
+ {
+ File structureImageFile = new File(structureImageFilename);
+ String width = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGEWIDTH, subVals);
+ String height = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGEHEIGHT, subVals);
+ String scale = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGESCALE, subVals);
+ String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGETEXTRENDERER, subVals);
+ String typeS = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGETYPE, subVals);
+ if (typeS == null || typeS.length() == 0)
+ {
+ typeS = FileUtils.getExtension(structureImageFile);
+ }
+ TYPE imageType;
+ try
+ {
+ imageType = Enum.valueOf(TYPE.class,
+ typeS.toUpperCase(Locale.ROOT));
+ } catch (IllegalArgumentException e)
+ {
+ Console.warn("Do not know image format '" + typeS
+ + "', using PNG");
+ imageType = TYPE.PNG;
+ }
+ BitmapImageSizing userBis = ImageMaker
+ .parseScaleWidthHeightStrings(scale, width, height);
+ switch (sv.getViewerType())
+ {
+ case JMOL:
+ try
+ {
+ Thread.sleep(1000);
+ } catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ JalviewStructureDisplayI sview = sv
+ .getJalviewStructureDisplay();
+ if (sview instanceof AppJmol)
+ {
+ AppJmol jmol = (AppJmol) sview;
+ jmol.makePDBImage(structureImageFile, imageType, renderer,
+ userBis);
+ }
+ break;
+ default:
+ Console.warn("Cannot export image for structure viewer "
+ + sv.getViewerType() + " yet");
+ break;
+ }
+ }
}
}
}
renderer = "text";
String type = "png"; // default
- float bitmapscale = 0.0f;
- int bitmapwidth = 0;
- int bitmapheight = 0;
String scale = ArgParser.getValueFromSubValOrArg(avm, av, Arg.SCALE,
subVal);
- if (scale != null)
- {
- try
- {
- bitmapscale = Float.parseFloat(scale);
- } catch (NumberFormatException e)
- {
- Console.warn("Did not understand scale '" + scale
- + "', won't be used.");
- }
- }
String width = ArgParser.getValueFromSubValOrArg(avm, av, Arg.WIDTH,
subVal);
- if (width != null)
- {
- try
- {
- bitmapwidth = Integer.parseInt(width);
- } catch (NumberFormatException e)
- {
- Console.warn("Did not understand width '" + width
- + "', won't be used.");
- }
- }
String height = ArgParser.getValueFromSubValOrArg(avm, av,
Arg.HEIGHT, subVal);
- if (height != null)
- {
- try
- {
- bitmapheight = Integer.parseInt(height);
- } catch (NumberFormatException e)
- {
- Console.warn("Did not understand height '" + height
- + "', won't be used.");
- }
- }
+ BitmapImageSizing userBis = ImageMaker
+ .parseScaleWidthHeightStrings(scale, width, height);
type = ArgParser.getValueFromSubValOrArg(avm, av, Arg.TYPE, subVal);
if (type == null && fileName != null)
case "png":
Console.debug("Outputting type '" + type + "' to " + fileName);
- af.createPNG(file, null, bitmapscale, bitmapwidth, bitmapheight);
+ af.createPNG(file, null, userBis);
break;
case "html":
return set;
}
+ /*
private static void showUsage()
{
System.out.println(
+ "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
+ "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
}
+ */
private static void startUsageStats(final Desktop desktop)
{
+ "none,\n" + "jmol,\n" + "chimera,\n" + "chimerax,\n"
+ "pymol.",
Opt.STRING, Opt.LINKED, Opt.MULTI),
- STRUCTUREIMAGE(Type.STRUCTURE,
- "Export an image of a 3D structure opened in JMOL", Opt.STRING,
- Opt.LINKED, Opt.MULTI),
NOTEMPFAC(Type.STRUCTURE,
"Do not show the temperature factor annotation for the preceding --structure.",
Opt.UNARY, Opt.LINKED, Opt.ALLOWALL, Opt.SECRET), // keep this secret
Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS, Opt.ALLOWALL,
Opt.REQUIREINPUT, Opt.OUTPUT, Opt.PRIMARY),
TYPE(Type.IMAGE,
- "Set the image format for the preceding --image to name. Valid values for name are: svg,\n"
- + "png,\n" + "eps,\n" + "html,\n" + "biojs.",
+ "Set the image format for the preceding --image. Valid values are:\n"
+ + "svg,\n" + "png,\n" + "eps,\n" + "html,\n" + "biojs.",
Opt.STRING, Opt.LINKED, Opt.ALLOWALL),
TEXTRENDERER(Type.IMAGE,
- "Sets whether text in a vector image format (SVG, HTML, EPS) should be rendered as text or vector line-art. Possible values for name are:\n"
+ "Sets whether text in a vector image format (SVG, HTML, EPS) should be rendered as text or vector line-art. Possible values are:\n"
+ "text,\n" + "lineart.",
Opt.STRING, Opt.LINKED, Opt.ALLOWALL),
SCALE(Type.IMAGE,
HEIGHT(Type.IMAGE,
"Sets a height for bitmap image format (PNG) with the width maintaining the aspect ratio. Should be given as a positive integer. If used in conjunction with --scale and --width then the smallest scaling will be used (scale, width and height provide bounds for the image).",
Opt.STRING, Opt.LINKED, Opt.ALLOWALL),
+ STRUCTUREIMAGE(Type.IMAGE,
+ "Export an image of a 3D structure opened in JMOL", Opt.STRING,
+ Opt.LINKED, Opt.MULTI),
+
+ STRUCTUREIMAGETYPE(Type.IMAGE,
+ "Set the structure image format for the preceding --structureimage. Valid values are:\n"
+ + "svg,\n" + "png,\n" + "eps,\n" + "html,\n" + "biojs.",
+ Opt.STRING, Opt.LINKED, Opt.ALLOWALL),
+ STRUCTUREIMAGETEXTRENDERER(Type.IMAGE,
+ "Sets whether text in a vector structure image format (SVG, HTML, EPS) should be rendered as text or vector line-art. Possible values are:\n"
+ + "text,\n" + "lineart.",
+ Opt.STRING, Opt.LINKED, Opt.ALLOWALL),
+ STRUCTUREIMAGESCALE(Type.IMAGE,
+ "Sets a scaling for bitmap structure image format (PNG). Should be given as a floating point number. If used in conjunction with --structureimagewidth and --structureimageheight then the smallest scaling will be used (structureimagescale, structureimagewidth and structureimageheight provide bounds for the structure image).",
+ Opt.STRING, Opt.LINKED, Opt.ALLOWALL),
+ STRUCTUREIMAGEWIDTH(Type.IMAGE,
+ "Sets a width for bitmap structure image format (PNG) with the height maintaining the aspect ratio. Should be given as a positive integer. If used in conjunction with --structureimagescale and --structureimageheight then the smallest scaling will be used (structureimagescale, structureimagewidth and structureimageheight provide bounds for the structure image).",
+ Opt.STRING, Opt.LINKED, Opt.ALLOWALL),
+ STRUCTUREIMAGEHEIGHT(Type.IMAGE,
+ "Sets a height for bitmap structure image format (PNG) with the width maintaining the aspect ratio. Should be given as a positive integer. If used in conjunction with --structureimagescale and --structureimagewidth then the smallest scaling will be used (structureimagescale, structureimagewidth and structureimageheight provide bounds for the structure image).",
+ Opt.STRING, Opt.LINKED, Opt.ALLOWALL),
+
OUTPUT(Type.OUTPUT,
"Export the open alignment to file filename. The format name is specified by the subval modifier format=name, a following --format name argument or guessed from the file extension. Valid format names (and file extensions) are:\n"
+ "fasta (fa, fasta, mfa, fastq),\n" + "pfam (pfam),\n"
import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.imagemaker.BitmapImageSizing;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
@Override
public void createPNG(File f)
{
- createPNG(f, null, 0.0f, 0, 0);
+ createPNG(f, null, BitmapImageSizing.nullBitmapImageSizing());
}
- public void createPNG(File f, String renderer, float bitmapscale,
- int bitmapwidth, int bitmapheight)
+ public void createPNG(File f, String renderer, BitmapImageSizing userBis)
{
- alignPanel.makeAlignmentImage(TYPE.PNG, f, renderer, bitmapscale,
- bitmapwidth, bitmapheight);
+ alignPanel.makeAlignmentImage(TYPE.PNG, f, renderer, userBis);
}
/**
import jalview.util.Comparison;
import jalview.util.ImageMaker;
import jalview.util.MessageManager;
+import jalview.util.imagemaker.BitmapImageSizing;
import jalview.viewmodel.ViewportListenerI;
import jalview.viewmodel.ViewportRanges;
void makeAlignmentImage(ImageMaker.TYPE type, File file, String renderer)
{
- makeAlignmentImage(type, file, renderer, 0.0f, 0, 0);
+ makeAlignmentImage(type, file, renderer,
+ BitmapImageSizing.nullBitmapImageSizing());
}
/**
* @param bitmapscale
*/
void makeAlignmentImage(ImageMaker.TYPE type, File file, String renderer,
- float bitmapscale, int bitmapwidth, int bitmapheight)
+ BitmapImageSizing userBis)
{
final int borderBottomOffset = 5;
int imageHeight = aDimension.getHeight() + borderBottomOffset;
String of = MessageManager.getString("label.alignment");
exporter.doExport(file, this, imageWidth, imageHeight, of, renderer,
- bitmapscale, bitmapwidth, bitmapheight);
+ userBis);
}
/**
*/
package jalview.gui;
-import java.util.Locale;
-
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
import java.io.File;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import javax.swing.JPanel;
import jalview.datamodel.SequenceI;
import jalview.datamodel.StructureViewerModel;
import jalview.datamodel.StructureViewerModel.StructureData;
-import jalview.fts.service.alphafold.AlphafoldRestClient;
import jalview.gui.ImageExporter.ImageWriterI;
import jalview.gui.StructureViewer.ViewerType;
import jalview.structure.StructureCommand;
import jalview.structures.models.AAStructureBindingModel;
import jalview.util.BrowserLauncher;
import jalview.util.ImageMaker;
+import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.imagemaker.BitmapImageSizing;
public class AppJmol extends StructureViewerBase
{
@Override
public void makePDBImage(ImageMaker.TYPE type)
{
+ makePDBImage(null, type, null,
+ BitmapImageSizing.nullBitmapImageSizing());
+ }
+
+ public void makePDBImage(File file, ImageMaker.TYPE type, String renderer,
+ BitmapImageSizing userBis)
+ {
int width = getWidth();
int height = getHeight();
+
+ BitmapImageSizing bis = ImageMaker.getScaleWidthHeight(width, height,
+ userBis);
+ float usescale = bis.scale;
+ int usewidth = bis.width;
+ int useheight = bis.height;
+
ImageWriterI writer = new ImageWriterI()
{
@Override
public void exportImage(Graphics g) throws Exception
{
- jmb.jmolViewer.renderScreenImage(g, width, height);
+ Graphics2D ig2 = (Graphics2D) g;
+ ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ if (type == TYPE.PNG && usescale > 0.0f)
+ {
+ // for a scaled image, this scales down a bigger image to increase
+ // resolution
+
+ ig2.scale(1 / usescale, 1 / usescale);
+ }
+
+ jmb.jmolViewer.antialiased = true;
+ jmb.jmolViewer.requestRepaintAndWait("image export");
+ jmb.jmolViewer.renderScreenImage(ig2, usewidth, useheight);
}
};
String view = MessageManager.getString("action.view")
.toLowerCase(Locale.ROOT);
ImageExporter exporter = new ImageExporter(writer,
getProgressIndicator(), type, getTitle());
- exporter.doExport(null, this, width, height, view);
+ exporter.doExport(file, this, width, height, view, renderer, userBis);
}
@Override
import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.imagemaker.BitmapImageSizing;
/**
* A class that marshals steps in exporting a view in image graphics format
public void doExport(File file, Component parent, int width, int height,
String imageSource)
{
- doExport(file, parent, width, height, imageSource, null, 0.0f, 0, 0);
+ doExport(file, parent, width, height, imageSource, null,
+ BitmapImageSizing.nullBitmapImageSizing());
}
public void doExport(File file, Component parent, int width, int height,
- String imageSource, String renderer, float bitmapscale,
- int bitmapwidth, int bitmapheight)
+ String imageSource, String renderer, BitmapImageSizing userBis)
{
final long messageId = System.currentTimeMillis();
setStatus(
final File chosenFile = file;
Callable<Void> okAction = () -> {
exportImage(chosenFile, !textSelected.get(), width, height,
- messageId, bitmapscale, bitmapwidth, bitmapheight);
+ messageId, userBis);
return null;
};
LineartOptions epsOption = new LineartOptions(TYPE.EPS.getName(),
* - just do the export
*/
exportImage(file, !textSelected.get(), width, height, messageId,
- bitmapscale, bitmapwidth, bitmapheight);
+ userBis);
}
}
* @param messageId
*/
protected void exportImage(File chosenFile, boolean asLineart, int width,
- int height, long messageId, float bitmapscale, int bitmapwidth,
- int bitmapheight)
+ int height, long messageId, BitmapImageSizing userBis)
{
String type = imageType.getName();
try
// "status.exporting_alignment_as_x_file", type),
// messageId);
ImageMaker im = new ImageMaker(imageType, width, height, chosenFile,
- title, asLineart, bitmapscale, bitmapwidth, bitmapheight);
+ title, asLineart, userBis);
imageWriter.exportImage(im.getGraphics());
im.writeImage();
setStatus(
paeFilename, false, true, doXferSettings, null);
}
- public static void openStructureFileForSequence(
+ public static StructureViewer openStructureFileForSequence(
StructureSelectionManager ssm, StructureChooser sc,
AlignmentPanel ap, SequenceI seq, boolean prompt,
String sFilename, TFType tft, String paeFilename,
boolean forceHeadless, boolean showRefAnnotations,
boolean doXferSettings, ViewerType viewerType)
{
+ StructureViewer sv = null;
boolean headless = forceHeadless;
if (sc == null)
{
sc = new StructureChooser(new SequenceI[] { seq }, seq, ap, false);
}
if (ssm == null)
+ {
ssm = ap.getStructureSelectionManager();
+ }
PDBEntry fileEntry = new AssociatePdbFileWithSeq().associatePdbWithSeq(
sFilename, DataSourceType.FILE, seq, prompt, Desktop.instance,
// if headless, "false" in the sc constructor above will avoid GUI behaviour
// in sc.launchStructureViewer()
if (!headless && !(viewerType == null))
- sc.launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
+ {
+ sv = sc.launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
new SequenceI[]
{ seq }, viewerType);
+ }
if (headless)
sc.mainFrame.dispose();
if (showRefAnnotations)
showReferenceAnnotationsForSequence(ap.alignFrame, seq);
+
+ return sv;
}
public static void showReferenceAnnotationsForSequence(AlignFrame af,
*/
private boolean superposeAdded = true;
+ /**
+ * whether to open structures in their own thread or not
+ */
+ private boolean async = true;
+
+ public void setAsync(boolean b)
+ {
+ async = b;
+ }
+
public enum ViewerType
{
JMOL, CHIMERA, CHIMERAX, PYMOL
if (sview != null)
{
sview.setAlignAddedStructures(superposeAdded);
- new Thread(new Runnable()
+
+ Runnable viewRunnable = new Runnable()
{
@Override
public void run()
sview.updateTitleAndMenus();
}
- }).start();
+ };
+ if (async)
+ {
+ new Thread(viewRunnable).start();
+ }
+ else
+ {
+ viewRunnable.run();
+ }
return sview;
}
JalviewStructureDisplayI sview = null;
+ public JalviewStructureDisplayI getJalviewStructureDisplay()
+ {
+ return sview;
+ }
+
public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
SequenceI[] seqsForPdb, AlignmentPanel ap)
{
import org.jfree.graphics2d.svg.SVGHints;
import org.jibble.epsgraphics.EpsGraphics2D;
+import jalview.bin.Console;
import jalview.io.JalviewFileChooser;
+import jalview.util.imagemaker.BitmapImageSizing;
public class ImageMaker
{
* @throws IOException
*/
public ImageMaker(TYPE imageType, int width, int height, File file,
- String fileTitle, boolean useLineart, float bitmapscale,
- int bitmapwidth, int bitmapheight) throws IOException
+ String fileTitle, boolean useLineart, BitmapImageSizing userBis)
+ throws IOException
{
this.type = imageType;
setupEPS(width, height, fileTitle, useLineart);
break;
case PNG:
- setupPNG(width, height, bitmapscale, bitmapwidth, bitmapheight);
+ setupPNG(width, height, userBis);
break;
default:
}
* @param height
* @param scale
*/
- protected void setupPNG(int width, int height, float scale,
- int bitmapwidth, int bitmapheight)
+ protected void setupPNG(int width, int height, BitmapImageSizing userBis)
{
if (width == 0 || height == 0)
return;
- float usescale = 0.0f;
- int usewidth = width;
- int useheight = height;
+ BitmapImageSizing bis = ImageMaker.getScaleWidthHeight(width, height,
+ userBis);
+ float usescale = bis.scale;
+ int usewidth = bis.width;
+ int useheight = bis.height;
- // use the smallest positive scale (i.e. fit in the box)
- if (scale > 0.0f)
- {
- usescale = scale;
- usewidth = Math.round(scale * width);
- useheight = Math.round(scale * height);
- }
- if (bitmapwidth > 0)
- {
- float wscale = (float) bitmapwidth / width;
- if (wscale > 0.0f && (usescale == 0.0f || wscale < usescale))
- {
- usescale = wscale;
- usewidth = bitmapwidth;
- useheight = Math.round(usescale * height);
- }
- }
- if (bitmapheight > 0)
- {
- float hscale = (float) bitmapheight / height;
- if (hscale > 0.0f && (usescale == 0.0f || hscale < usescale))
- {
- usescale = hscale;
- usewidth = Math.round(usescale * width);
- useheight = bitmapheight;
- }
- }
bi = new BufferedImage(usewidth, useheight, BufferedImage.TYPE_INT_RGB);
graphics = bi.getGraphics();
Graphics2D ig2 = (Graphics2D) graphics;
ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (usescale > 0.0f)
+ {
ig2.scale(usescale, usescale);
+ }
}
/**
pg.setAccurateTextMode(useLineart);
graphics = pg;
}
+
+ /**
+ * Takes suggested float scale, int width, int height and create a bounding
+ * box returned as a BitmapImageSizing object with consistent scale, width,
+ * height fields.
+ *
+ * @param scale
+ * @param bitmapwidth
+ * @param bitmapheight
+ * @return BitmapImageSizing
+ */
+ public static BitmapImageSizing getScaleWidthHeight(int width, int height,
+ float scale, int bitmapwidth, int bitmapheight)
+ {
+ float usescale = 0.0f;
+ int usewidth = width;
+ int useheight = height;
+
+ // use the smallest positive scale (i.e. fit in the box)
+ if (scale > 0.0f)
+ {
+ usescale = scale;
+ usewidth = Math.round(scale * width);
+ useheight = Math.round(scale * height);
+ }
+ if (bitmapwidth > 0)
+ {
+ float wscale = (float) bitmapwidth / width;
+ if (wscale > 0.0f && (usescale == 0.0f || wscale < usescale))
+ {
+ usescale = wscale;
+ usewidth = bitmapwidth;
+ useheight = Math.round(usescale * height);
+ }
+ }
+ if (bitmapheight > 0)
+ {
+ float hscale = (float) bitmapheight / height;
+ if (hscale > 0.0f && (usescale == 0.0f || hscale < usescale))
+ {
+ usescale = hscale;
+ usewidth = Math.round(usescale * width);
+ useheight = bitmapheight;
+ }
+ }
+ return new BitmapImageSizing(usescale, usewidth, useheight);
+ }
+
+ /**
+ * Takes suggested scale, width, height as a BitmapImageSizing object and
+ * create a bounding box returned as a BitmapImageSizing object with
+ * consistent scale, width, height fields.
+ *
+ * @param bis
+ * @return BitmapImageSizing
+ */
+ public static BitmapImageSizing getScaleWidthHeight(int width, int height,
+ BitmapImageSizing bis)
+ {
+ return ImageMaker.getScaleWidthHeight(width, height, bis.scale,
+ bis.width, bis.height);
+ }
+
+ /**
+ * Takes String versions of suggested float scale, int width, int height and
+ * create a bounding box returned as a BitmapImageSizing object with
+ * consistent scale, width, height fields.
+ *
+ * @param scaleS
+ * @param widthS
+ * @param heightS
+ * @return BitmapImageSizing
+ */
+ public static BitmapImageSizing parseScaleWidthHeightStrings(
+ String scaleS, String widthS, String heightS)
+ {
+ float scale = 0.0f;
+ int width = 0;
+ int height = 0;
+
+ if (scaleS != null)
+ {
+ try
+ {
+ scale = Float.parseFloat(scaleS);
+ } catch (NumberFormatException e)
+ {
+ Console.warn("Did not understand scale '" + scaleS
+ + "', won't be used.");
+ }
+ }
+ if (widthS != null)
+ {
+ try
+ {
+ width = Integer.parseInt(widthS);
+ } catch (NumberFormatException e)
+ {
+ Console.warn("Did not understand width '" + widthS
+ + "', won't be used.");
+ }
+ }
+ if (heightS != null)
+ {
+ try
+ {
+ height = Integer.parseInt(heightS);
+ } catch (NumberFormatException e)
+ {
+ Console.warn("Did not understand height '" + heightS
+ + "', won't be used.");
+ }
+ }
+
+ return new BitmapImageSizing(scale, width, height);
+ }
}
--- /dev/null
+package jalview.util.imagemaker;
+
+public class BitmapImageSizing
+{
+ public final float scale;
+
+ public final int width;
+
+ public final int height;
+
+ public BitmapImageSizing(float scale, int width, int height)
+ {
+ this.scale = scale;
+ this.width = width;
+ this.height = height;
+ }
+
+ public static BitmapImageSizing nullBitmapImageSizing()
+ {
+ return new BitmapImageSizing(0.0f, 0, 0);
+ }
+}