Class PageFormat


  • public class PageFormat
    extends java.lang.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 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 class  PageFormat.Customizer
      a dialog box used to change a PageFormat
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double bottomMarginMmDEFAULT  
      static 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
      static double heightMmDEFAULT  
      static java.lang.String KEY_PAGE_FORMAT
      key used to retrieve parameters from Properties
      static double leftMarginMmDEFAULT  
      static double widthMmDEFAULT  
    • 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.Customizer createCustomizer()
      Return a dialog for editing this PageFormat
      static PageFormat.Customizer createCustomizer​(java.util.Properties preferences)
      Return a dialog for editing the PageFormat's values stored in the given Properties.
      void enlargeTo​(java.awt.geom.Rectangle2D r)
      Adjusts this PageFormat so that it is not smaller than the given rectangle (in mm)
      void fitTo​(java.awt.geom.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
      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)
      PicPoint getOrgPx​(double zoom)
      Return (x,y) double-precision pixel-coordinates of the (0,0) model origin.
      java.awt.Dimension getSizePx​(double zoom)
      Return the page dimension (w,h) in pixels.
      java.awt.geom.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​(java.awt.geom.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 java.lang.String KEY_PAGE_FORMAT
        key used to retrieve parameters from Properties
        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 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​(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.