Package jpicedt.graphic
Class PageFormat
- java.lang.Object
-
- jpicedt.graphic.PageFormat
-
public class PageFormat extends java.lang.ObjectSize and margins data for aPECanvas.This class provides a convenient way of converting b/w millimeters (ie model) coordinates and pixel coordinates. The dot-per-mm scale factor is computed from the AWT's ToolKit.
[SR:todo] adapt to fit with
java.awt.print.PageFormat.- Since:
- jpicedt 1.3.2
- Version:
- $Id: PageFormat.java,v 1.12.2.1 2007/09/02 11:56:16 reynal Exp $
- Author:
- Sylvain Reynal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPageFormat.Customizera dialog box used to change a PageFormat
-
Field Summary
Fields Modifier and Type Field Description static doublebottomMarginMmDEFAULTstatic doubleDPMMscreen dot per mm ; used during coordinates translation from model to view.
the effect is to render 1 cm as a "true" cm (or approximately) on the screenstatic doubleheightMmDEFAULTstatic java.lang.StringKEY_PAGE_FORMATkey used to retrieve parameters from Propertiesstatic doubleleftMarginMmDEFAULTstatic doublewidthMmDEFAULT
-
Constructor Summary
Constructors Constructor Description PageFormat()Construct a new PageFormat with the default values (170,100,5,5)PageFormat(double widthMm, double heightMm)Constructor a new PageFormat with length given in mm.PageFormat(double widthMm, double heightMm, double leftMarginMm, double bottomMarginMm)Construct a new PageFormat with lengths given in mm.PageFormat(java.util.Properties preferences)Construct a new PageFormat with values fetched from the given Properties :
Key = KEY_PAGE_FORMAT
Value = width height leftMargin bottomMargin (separated with spaces)
If some values aren't found (including Properties's default), the local default values are used.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PageFormat.CustomizercreateCustomizer()Return a dialog for editing this PageFormatstatic PageFormat.CustomizercreateCustomizer(java.util.Properties preferences)Return a dialog for editing the PageFormat's values stored in the given Properties.voidenlargeTo(java.awt.geom.Rectangle2D r)Adjusts this PageFormat so that it is not smaller than the given rectangle (in mm)voidfitTo(java.awt.geom.Rectangle2D r)Adjusts this PageFormat so that it fits to the given rectangle (in mm)doublegetBottomMarginMm()Return the bottom-margin in mmdoublegetHeightMm()Return the page height in mm.intgetHeightPx(double zoom)Return the page height in pixels.doublegetLeftMarginMm()Return the left-margin in mmjava.awt.geom.AffineTransformgetModel2ViewTransform(double zoom)x' = zoom * DPMM * (x + leftMarginMm)
y' = zoom * DPMM * (-y + heightMm-bottomMarginMm)
Return the AffineTransform that translates from model to view coordinate using the given zoom factor and this page format (ie most notably the left and bottom margins)PicPointgetOrgPx(double zoom)Return (x,y) double-precision pixel-coordinates of the (0,0) model origin.java.awt.DimensiongetSizePx(double zoom)Return the page dimension (w,h) in pixels.java.awt.geom.AffineTransformgetView2ModelTransform(double zoom)x' = zoom * DPMM * (x + leftMarginMm)
y' = zoom * DPMM * (-y + heightMm-bottomMarginMm)doublegetWidthMm()Return the page width in mm.intgetWidthPx(double zoom)Return the page width in pixels.intgetXOrgPx(double zoom)Return the left margin in pixels, ie the x-coordinate of the (0,0) model origin.intgetYOrgPx(double zoom)Return the y-coordinate in pixels (starting from the canvas's top-side) of the (0,0) model origin.booleanisFitInto(java.awt.geom.Rectangle2D r)Returns whether the given rectangle (in mm units) fits into this page.voidsetBottomMarginMm(double margin)Set the bottom margin in mmvoidsetHeightMm(double h)Set the page height in mm.voidsetLeftMarginMm(double margin)Set the left margin in mmvoidsetMarginsMm(double left, double bottom)Set the page margins in mmvoidsetSizeMm(double w, double h)Sets the page size in millimetersvoidsetWidthMm(double w)Set the page width in mm.
-
-
-
Field Detail
-
DPMM
public static final double DPMM
screen dot per mm ; used during coordinates translation from model to view.
the effect is to render 1 cm as a "true" cm (or approximately) on the screen
-
KEY_PAGE_FORMAT
public static final java.lang.String KEY_PAGE_FORMAT
key used to retrieve parameters from Properties- See Also:
- Constant Field Values
-
widthMmDEFAULT
public static final double widthMmDEFAULT
- See Also:
- Constant Field Values
-
heightMmDEFAULT
public static final double heightMmDEFAULT
- See Also:
- Constant Field Values
-
leftMarginMmDEFAULT
public static final double leftMarginMmDEFAULT
- See Also:
- Constant Field Values
-
bottomMarginMmDEFAULT
public static final double bottomMarginMmDEFAULT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PageFormat
public PageFormat()
Construct a new PageFormat with the default values (170,100,5,5)
-
PageFormat
public PageFormat(java.util.Properties preferences)
Construct a new PageFormat with values fetched from the given Properties :
Key = KEY_PAGE_FORMAT
Value = width height leftMargin bottomMargin (separated with spaces)
If some values aren't found (including Properties's default), the local default values are used.
-
PageFormat
public PageFormat(double widthMm, double heightMm, double leftMarginMm, double bottomMarginMm)Construct a new PageFormat with lengths given in mm.- Parameters:
widthMm- page width in mmheightMm- page height in mmleftMarginMm- left margin in mmbottomMarginMm- bottom margin in mm
-
PageFormat
public PageFormat(double widthMm, double heightMm)Constructor a new PageFormat with length given in mm. Margins default to 0.- Parameters:
widthMm- page width in mmheightMm- page height in mm
-
-
Method Detail
-
getWidthMm
public double getWidthMm()
Return the page width in mm.
-
setWidthMm
public void setWidthMm(double w)
Set the page width in mm.
-
setHeightMm
public void setHeightMm(double h)
Set the page height in mm.
-
getHeightMm
public double getHeightMm()
Return the page height in mm.
-
setSizeMm
public void setSizeMm(double w, double h)Sets the page size in millimeters
-
getLeftMarginMm
public double getLeftMarginMm()
Return the left-margin in mm
-
getBottomMarginMm
public double getBottomMarginMm()
Return the bottom-margin in mm
-
setLeftMarginMm
public void setLeftMarginMm(double margin)
Set the left margin in mm
-
setBottomMarginMm
public void setBottomMarginMm(double margin)
Set the bottom margin in mm
-
setMarginsMm
public void setMarginsMm(double left, double bottom)Set the page margins in mm
-
isFitInto
public boolean isFitInto(java.awt.geom.Rectangle2D r)
Returns whether the given rectangle (in mm units) fits into this page.
-
fitTo
public void fitTo(java.awt.geom.Rectangle2D r)
Adjusts this PageFormat so that it fits to the given rectangle (in mm)
-
enlargeTo
public void enlargeTo(java.awt.geom.Rectangle2D r)
Adjusts this PageFormat so that it is not smaller than the given rectangle (in mm)
-
getWidthPx
public int getWidthPx(double zoom)
Return the page width in pixels.- Parameters:
zoom- the current zoom factor
-
getHeightPx
public int getHeightPx(double zoom)
Return the page height in pixels.- Parameters:
zoom- the current zoom factor
-
getSizePx
public java.awt.Dimension getSizePx(double zoom)
Return the page dimension (w,h) in pixels.- Parameters:
zoom- the current zoom factor
-
getXOrgPx
public int getXOrgPx(double zoom)
Return the left margin in pixels, ie the x-coordinate of the (0,0) model origin.- Parameters:
zoom- the current zoom factor
-
getYOrgPx
public int getYOrgPx(double zoom)
Return the y-coordinate in pixels (starting from the canvas's top-side) of the (0,0) model origin.- Parameters:
zoom- the current zoom factor
-
getOrgPx
public PicPoint getOrgPx(double zoom)
Return (x,y) double-precision pixel-coordinates of the (0,0) model origin.- Parameters:
zoom- the current zoom factor
-
getModel2ViewTransform
public java.awt.geom.AffineTransform getModel2ViewTransform(double zoom)
x' = zoom * DPMM * (x + leftMarginMm)
y' = zoom * DPMM * (-y + heightMm-bottomMarginMm)
Return the AffineTransform that translates from model to view coordinate using the given zoom factor and this page format (ie most notably the left and bottom margins)- Parameters:
zoom- the current zoom factor
-
getView2ModelTransform
public java.awt.geom.AffineTransform getView2ModelTransform(double zoom)
x' = zoom * DPMM * (x + leftMarginMm)
y' = zoom * DPMM * (-y + heightMm-bottomMarginMm)- Parameters:
zoom- the current zoom factor- Returns:
- the AffineTransform that translate from view (or mouse) coordinates to model-coordinates using the given zoom factor, and this page format (ie most notably the left and bottom margins)
-
createCustomizer
public PageFormat.Customizer createCustomizer()
Return a dialog for editing this PageFormat
-
createCustomizer
public static PageFormat.Customizer createCustomizer(java.util.Properties preferences)
Return a dialog for editing the PageFormat's values stored in the given Properties.
-
-