Class ExtendedPrintable
- java.lang.Object
-
- com.biomatters.geneious.publicapi.plugin.ExtendedPrintable
-
- Direct Known Subclasses:
ExtendedPrintable.Wrapper
public abstract class ExtendedPrintable extends java.lang.Object
An alternative toPrintable
which provides additional information and options which also provides useful information when saving to an image. May be supplied by aDocumentViewer
The following example shows how to construct an ExtendedPrintable as an anonymous inner class. Note that this code comes from the example in
DocumentViewerFactory
and assumes that there is a global String variable calledresidues
present.final Font font = new Font("monospaced",Font.PLAIN,48); ExtendedPrintable ep = new ExtendedPrintable(){ //This
Options
appears at the top of the print options dialog that is opened when //the user selects "Print" public Options getOptions(boolean isSavingToFile) { Options options = new Options(this.getClass()); options.addLabel("It is ludicrous to print this"); return options; } //we need to be aware of what page we are on, and print the correct section of the sequence. //in a more robust implementation we would deal with characters being split between two pages. public int print(Graphics2D g, Dimension d, int pageIndex, Options options) throws PrinterException { //clear the background g.setColor(Color.white); g.fillRect(0,0,d.width,d.height); //set a clip to make sure that the graphics does not draw outside the printable area g.setClip(0,0,d.width,d.height); //move the graphics so that the correct section of the sequence is drawn to the page g.translate(-d.width*pageIndex,0); //paint the page g.setColor(Color.black); g.setFont(font); g.drawString(residues,10,50); //tell the printing subsystem whether the page requested was a valid page or not. return (getPagesRequired(d, null) >= pageIndex)? Printable.PAGE_EXISTS : Printable.NO_SUCH_PAGE; } //these two methods are used by the save to image feature public int getRequiredWidth(Options options) { FontRenderContext frc = new FontRenderContext(new AffineTransform(), false, false); Rectangle2D fontBounds = font.getStringBounds(residues, frc); return (int)fontBounds.getWidth()+20; } //these two methods are used by the save to image feature public int getRequiredHeight(Options options, int width) { FontRenderContext frc = new FontRenderContext(new AffineTransform(), false, false); Rectangle2D fontBounds = font.getStringBounds(residues, frc); return (int)fontBounds.getHeight()+60; } //returns the number of pages required to print the entire document. public int getPagesRequired(Dimension dimensions, Options options) { return (int)Math.ceil(((double)getRequiredWidth(null))/dimensions.width); } };
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExtendedPrintable.Factory
Provides factory methods for creating ExtendedPrintablesstatic class
ExtendedPrintable.Wrapper
Wrapper that delegates all methods to the source ExtendedPrintable.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
IS_HIGH_RESOLUTION_GRAPHICS_OPTION_NAME
The options returned fromgetOptions(boolean)
may include a hiddenOptions.BooleanOption
with this name in which case the printing system will set this to true when the format the user has selected is a Vector format (e.g.static java.lang.String
IS_PREVIEW_OPTION_NAME
The options returned fromgetOptions(boolean)
may include a hiddenOptions.BooleanOption
with this name in which case the printing system will set this to true when generating an image for the PrintPreview dialog rather than actually saving the image or printingstatic java.lang.String
SUPPORTS_GRADIENT_PAINTING_OPTION_NAME
The options returned fromgetOptions(boolean)
may include a hiddenOptions.BooleanOption
with this name in which case the printing system will set this to true when the format the user has selected is a format (e.g.
-
Constructor Summary
Constructors Constructor Description ExtendedPrintable()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
getDefaultHeight(int width, Options options)
If this component does not have a required height (i.e.int
getDefaultWidth(Options options)
If this component does not have a required width (i.e.java.lang.String
getDocumentName()
Returns the name of the document that we are printing (if applicable)int
getMaximumHeight(int width, Options options)
Get the maximum height (inclusive) of the component when saved as an image.int
getMaximumWidth(Options options)
Get the maximum width (inclusive) of the component when saved as an image.int
getMinimumHeight(int width, Options options)
Get the minimum height (inclusive) of the component when saved as an image.int
getMinimumWidth(Options options)
Get the minimum width (inclusive) of the component when saved as an image.Options
getOptions(boolean isSavingToFile)
Optionally provide additional printing and/or saving image to file options.abstract int
getPagesRequired(java.awt.Dimension dimensions, Options options)
int
getRequiredHeight(int width, Options options)
Deprecated.int
getRequiredWidth(Options options)
Deprecated.abstract int
print(java.awt.Graphics2D graphics, java.awt.Dimension dimensions, int pageIndex, Options options)
print a single page of this component.
-
-
-
Field Detail
-
IS_HIGH_RESOLUTION_GRAPHICS_OPTION_NAME
public static final java.lang.String IS_HIGH_RESOLUTION_GRAPHICS_OPTION_NAME
The options returned fromgetOptions(boolean)
may include a hiddenOptions.BooleanOption
with this name in which case the printing system will set this to true when the format the user has selected is a Vector format (e.g. PDF) or greater than 100% resolution for raster formats. This is useful sinceGraphics2D.drawString(String, float, float)
positions text slightly differently in these 2 cases.- Since:
- API 4.910 (Geneious 9.1.0)
- See Also:
- Constant Field Values
-
SUPPORTS_GRADIENT_PAINTING_OPTION_NAME
public static final java.lang.String SUPPORTS_GRADIENT_PAINTING_OPTION_NAME
The options returned fromgetOptions(boolean)
may include a hiddenOptions.BooleanOption
with this name in which case the printing system will set this to true when the format the user has selected is a format (e.g. anything except EMF) that does supports gradient painting- Since:
- API 4.913 (Geneious 9.1.3)
- See Also:
- Constant Field Values
-
IS_PREVIEW_OPTION_NAME
public static final java.lang.String IS_PREVIEW_OPTION_NAME
The options returned fromgetOptions(boolean)
may include a hiddenOptions.BooleanOption
with this name in which case the printing system will set this to true when generating an image for the PrintPreview dialog rather than actually saving the image or printing- Since:
- API 4.910 (Geneious 9.1.0)
- See Also:
- Constant Field Values
-
-
Method Detail
-
getOptions
public Options getOptions(boolean isSavingToFile)
Optionally provide additional printing and/or saving image to file options.- Parameters:
isSavingToFile
- true when saving to a file, false when printing- Returns:
- a panel of options specific to this printable component or null if it has no options. The default implementation returns null.
-
getDocumentName
public java.lang.String getDocumentName()
Returns the name of the document that we are printing (if applicable)- Returns:
- the name of the document we're printing, or null if there isn't one
-
print
public abstract int print(java.awt.Graphics2D graphics, java.awt.Dimension dimensions, int pageIndex, Options options) throws java.awt.print.PrinterException
print a single page of this component.- Parameters:
graphics
- the graphics to render to.dimensions
- the dimensions of the page to be printed to.pageIndex
- index of the page to be printed or saved as an image.options
- an options panel returned bygetOptions(boolean)
- Returns:
Printable.PAGE_EXISTS
orPrintable.NO_SUCH_PAGE
- Throws:
java.awt.print.PrinterException
- the printerexception
-
getRequiredWidth
@Deprecated public int getRequiredWidth(Options options)
Deprecated.- Parameters:
options
- an options panel returned bygetOptions(boolean)
- Returns:
- a required width for this component when saved as an image. May return 0 to let the user choose the width.
-
getDefaultWidth
public int getDefaultWidth(Options options)
If this component does not have a required width (i.e.getRequiredWidth(Options)
returned 0)), then this returns the default width for the component, which the user may adjust.- Parameters:
options
- an options panel returned bygetOptions(boolean)
- Returns:
- a default width for this component when saved as an image.
- See Also:
getMinimumWidth(Options)
,getMinimumWidth(Options)
,getDefaultHeight(int, Options)
-
getMaximumWidth
public int getMaximumWidth(Options options)
Get the maximum width (inclusive) of the component when saved as an image.- Parameters:
options
- an options panel returned bygetOptions(boolean)
- Returns:
- the maximum width (inclusive) of the component when saved as an image.
-
getMinimumWidth
public int getMinimumWidth(Options options)
Get the minimum width (inclusive) of the component when saved as an image.- Parameters:
options
- an options panel returned bygetOptions(boolean)
- Returns:
- the minimum width (inclusive) of the component when saved as an image.
-
getRequiredHeight
@Deprecated public int getRequiredHeight(int width, Options options)
Deprecated.- Parameters:
options
- an options panel returned bygetOptions(boolean)
width
- a width chosen either by the user or returned fromgetRequiredWidth(Options)
- Returns:
- a required height for this component when saved as an image using the given width. May return 0 to let the user choose the height.
-
getDefaultHeight
public int getDefaultHeight(int width, Options options)
If this component does not have a required height (i.e.getRequiredHeight(int, Options)
returned 0), then this returns the default height for the component, which the user may adjust.- Parameters:
width
- a width chosen either by the user or returned fromgetDefaultWidth(Options)
options
- an options panel returned bygetOptions(boolean)
- Returns:
- a default height for this component when saved as an image using the given width.
- See Also:
getMinimumHeight(int, Options)
,getMaximumHeight(int, Options)
,getDefaultWidth(Options)
-
getMaximumHeight
public int getMaximumHeight(int width, Options options)
Get the maximum height (inclusive) of the component when saved as an image.- Parameters:
width
- a width chosen either by the user or returned fromgetDefaultWidth(Options)
options
- an options panel returned bygetOptions(boolean)
- Returns:
- the maximum height (inclusive) of the component when saved as an image.
-
getMinimumHeight
public int getMinimumHeight(int width, Options options)
Get the minimum height (inclusive) of the component when saved as an image.- Parameters:
width
- a width chosen either by the user or returned fromgetDefaultWidth(Options)
options
- an options panel returned bygetOptions(boolean)
- Returns:
- the minimum height (inclusive) of the component when saved as an image.
-
getPagesRequired
public abstract int getPagesRequired(java.awt.Dimension dimensions, Options options)
- Parameters:
dimensions
- the dimensionsoptions
- an options panel returned bygetOptions(boolean)
- Returns:
- the number of pages required to print this document with the specified dimensions and options
-
-