http://www.jpicedt.org

jpicedt.graphic
Class PageFormat

java.lang.Object
  extended by jpicedt.graphic.PageFormat

public class PageFormat
extends Object

Size and margins data for a PECanvas.

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 PageFormat.

Since:
jpicedt 1.3.2
Version:
$Id: PageFormat.java,v 1.20 2013/03/27 07:00:53 vincentb1 Exp $
Author:
Sylvain Reynal

Nested Class Summary
static class PageFormat.Customizer
          a dialog box used to change a PageFormat
 
Field Summary
static double bottomMarginMmDEFAULT
           
static double DPMM
          screen dot per mm ; used during coordinates translation from model to view.
static double heightMmDEFAULT
           
static String KEY_PAGE_FORMAT
          key used to retrieve parameters from Properties
static double leftMarginMmDEFAULT
           
static double widthMmDEFAULT
           
 
Constructor Summary
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(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
 PageFormat.Customizer createCustomizer(PECanvas canvas)
          Return a dialog for editing this PageFormat attached to the given canvas (a reference to the hosting canvas is needed so that setPageFormat() can be ultimately called when "ok" is pressed).
static PageFormat.Customizer createCustomizer(Properties preferences)
          Return a dialog for editing the PageFormat's values stored in the given Properties.
 void enlargeTo(Rectangle2D r)
          Adjusts this PageFormat so that it is not smaller than the given rectangle (in mm)
 void fitTo(Rectangle2D r)
          Adjusts this PageFormat so that it fits to the given rectangle (in mm)
 double getBottomMarginMm()
          Return the bottom-margin in mm
 double getHeightMm()
          Return the page height in mm.
 int getHeightPx(double zoom)
          Return the page height in pixels.
 double getLeftMarginMm()
          Return the left-margin in mm
 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)
 PicPoint getOrgPx(double zoom)
          Return (x,y) double-precision pixel-coordinates of the (0,0) model origin.
 Dimension getSizePx(double zoom)
          Return the page dimension (w,h) in pixels.
 AffineTransform getView2ModelTransform(double zoom)
          x' = zoom * DPMM * (x + leftMarginMm)
y' = zoom * DPMM * (-y + heightMm-bottomMarginMm)
 double getWidthMm()
          Return the page width in mm.
 int getWidthPx(double zoom)
          Return the page width in pixels.
 int getXOrgPx(double zoom)
          Return the left margin in pixels, ie the x-coordinate of the (0,0) model origin.
 int getYOrgPx(double zoom)
          Return the y-coordinate in pixels (starting from the canvas's top-side) of the (0,0) model origin.
 boolean isFitInto(Rectangle2D r)
          Returns whether the given rectangle (in mm units) fits into this page.
 void setBottomMarginMm(double margin)
          Set the bottom margin in mm
 void setHeightMm(double h)
          Set the page height in mm.
 void setLeftMarginMm(double margin)
          Set the left margin in mm
 void setMarginsMm(double left, double bottom)
          Set the page margins in mm
 void setSizeMm(double w, double h)
          Sets the page size in millimeters
 void setWidthMm(double w)
          Set the page width in mm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 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(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 mm
heightMm - page height in mm
leftMarginMm - left margin in mm
bottomMarginMm - 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 mm
heightMm - 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(Rectangle2D r)
Returns whether the given rectangle (in mm units) fits into this page.


fitTo

public void fitTo(Rectangle2D r)
Adjusts this PageFormat so that it fits to the given rectangle (in mm)


enlargeTo

public void enlargeTo(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 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 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 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(PECanvas canvas)
Return a dialog for editing this PageFormat attached to the given canvas (a reference to the hosting canvas is needed so that setPageFormat() can be ultimately called when "ok" is pressed).


createCustomizer

public static PageFormat.Customizer createCustomizer(Properties preferences)
Return a dialog for editing the PageFormat's values stored in the given Properties.


http://www.jpicedt.org

Submit a bug : syd@jpicedt.org