changeset 5272:c71c80693664

RT-32841: Paper.Units does not need to be public Reviewed by: kcr, jgodinez
author prr
date Fri, 04 Oct 2013 11:05:03 -0700
parents 53288988ddf1
children 137e59786fc1
files modules/graphics/src/main/java/com/sun/javafx/print/PrintHelper.java modules/graphics/src/main/java/com/sun/javafx/print/Units.java modules/graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinter.java modules/graphics/src/main/java/javafx/print/Paper.java modules/graphics/src/main/java/javafx/print/Printer.java modules/graphics/src/test/java/test/javafx/print/PaperUnitsTest.java
diffstat 6 files changed, 133 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/print/PrintHelper.java	Fri Oct 04 10:37:56 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/print/PrintHelper.java	Fri Oct 04 11:05:03 2013 -0700
@@ -27,7 +27,6 @@
 
 import javafx.print.JobSettings;
 import javafx.print.Paper;
-import javafx.print.Paper.Units;
 import javafx.print.PaperSource;
 import javafx.print.PrintResolution;
 import javafx.print.Printer;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/javafx/print/Units.java	Fri Oct 04 11:05:03 2013 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.print;
+
+/**
+ * An enumeration used to specify the Units used for Paper measurement
+ * @since JavaFX 8.0
+ */
+public enum Units {
+    /**
+     * Specify Paper size in millimetres.
+     */
+    MM,
+    /**
+     * Specify Paper size in inches.
+     */
+    INCH,
+    /**
+     * Specify Paper size in points (1/72 of an inch).
+     */
+    POINT
+}
--- a/modules/graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinter.java	Fri Oct 04 10:37:56 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinter.java	Fri Oct 04 11:05:03 2013 -0700
@@ -62,7 +62,6 @@
 import javafx.print.Printer.MarginType;
 import javafx.print.Collation;
 import javafx.print.Paper;
-import javafx.print.Paper.Units;
 import javafx.print.PaperSource;
 import javafx.print.PageRange;
 import javafx.print.PrintColor;
@@ -75,6 +74,7 @@
 
 import com.sun.javafx.print.PrintHelper;
 import com.sun.javafx.print.PrinterImpl;
+import com.sun.javafx.print.Units;
 
 
 public class J2DPrinter implements PrinterImpl {
--- a/modules/graphics/src/main/java/javafx/print/Paper.java	Fri Oct 04 10:37:56 2013 -0700
+++ b/modules/graphics/src/main/java/javafx/print/Paper.java	Fri Oct 04 11:05:03 2013 -0700
@@ -25,7 +25,8 @@
 
 package javafx.print;
 
-import static javafx.print.Paper.Units.*;
+import com.sun.javafx.print.Units;
+import static com.sun.javafx.print.Units.*;
 
 /**
  * A class which encapsulates the size of paper media as used by printers.
@@ -42,25 +43,6 @@
 
 public final class Paper {
 
-    /**
-     * An enumeration used to specify the Units used for Paper measurement
-     * @since JavaFX 8.0
-     */
-    public static enum Units {
-        /**
-         * Specify Paper size in millimetres.
-         */
-        MM,
-        /**
-         * Specify Paper size in inches.
-         */
-        INCH,
-        /**
-         * Specify Paper size in points (1/72 of an inch).
-         */
-        POINT
-    }
-
     private String name;
     private double width, height;
     private Units units;
--- a/modules/graphics/src/main/java/javafx/print/Printer.java	Fri Oct 04 10:37:56 2013 -0700
+++ b/modules/graphics/src/main/java/javafx/print/Printer.java	Fri Oct 04 11:05:03 2013 -0700
@@ -35,6 +35,7 @@
 
 import com.sun.javafx.tk.PrintPipeline;
 import com.sun.javafx.print.PrinterImpl;
+import com.sun.javafx.print.Units;
 
 /**
  * A Printer instance represents the destination for a print job.
@@ -404,7 +405,7 @@
             public Paper createPaper(String paperName,
                                      double paperWidth,
                                      double paperHeight,
-                                     Paper.Units units) {
+                                     Units units) {
                 return new Paper(paperName, paperWidth, paperHeight, units);
             }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/test/java/test/javafx/print/PaperUnitsTest.java	Fri Oct 04 11:05:03 2013 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.javafx.print;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javafx.beans.property.ObjectProperty;
+
+import javafx.print.Paper;
+import com.sun.javafx.print.PrintHelper;
+import com.sun.javafx.print.Units;
+
+public class PaperUnitsTest {
+
+  @Test public void dummyTest() {
+  }
+
+  @Test public void createPaperPts() {
+     double wid = 100.0;
+     double hgt = 200.0;
+     Paper p = PrintHelper.createPaper("TestPOINT", wid, hgt, Units.POINT);
+     int ptsWid = (int)p.getWidth();
+     int ptsHgt = (int)p.getHeight();
+     int expectedPtsWid = (int)wid;
+     int expectedPtsHgt = (int)hgt;
+     assertTrue("Points width is not as expected", ptsWid == expectedPtsWid);
+     assertTrue("Points height is not as expected", ptsHgt == expectedPtsHgt);
+   }
+
+  @Test public void createPaperInches() {
+     double inWid = 100.0;
+     double inHgt = 200.0;
+     Paper p = PrintHelper.createPaper("TestINCH", inWid, inHgt, Units.INCH);
+     int ptsWid = (int)p.getWidth();
+     int ptsHgt = (int)p.getHeight();
+     int expectedPtsWid = (int)((inWid * 72) + 0.5);
+     int expectedPtsHgt = (int)((inHgt * 72) + 0.5);
+     assertTrue("Inches width is not as expected", ptsWid == expectedPtsWid);
+     assertTrue("Inches height is not as expected", ptsHgt == expectedPtsHgt);
+   }
+
+  @Test public void createPaperMM() {
+     double mmWid = 100.0;
+     double mmHgt = 200.0;
+     Paper p = PrintHelper.createPaper("TestMM", mmWid, mmHgt, Units.MM);
+     int ptsWid = (int)p.getWidth();
+     int ptsHgt = (int)p.getHeight();
+     int expectedPtsWid = (int)(((mmWid * 72) / 25.4) + 0.5);
+     int expectedPtsHgt = (int)(((mmHgt * 72) / 25.4) + 0.5);
+     assertTrue("MM width is not as expected", ptsWid == expectedPtsWid);
+     assertTrue("MM height is not as expected", ptsHgt == expectedPtsHgt);
+   }
+}