diff --git a/java/src/org/openqa/selenium/print/PageSize.java b/java/src/org/openqa/selenium/print/PageSize.java index 9ca2b9810760a7..758c2e8c0db05f 100644 --- a/java/src/org/openqa/selenium/print/PageSize.java +++ b/java/src/org/openqa/selenium/print/PageSize.java @@ -21,41 +21,23 @@ import java.util.Map; public class PageSize { - private final double height; private final double width; - // Default Constructor (A4 by default) - public PageSize() { - this(PaperSize.A4); // Delegate to predefined size constructor - } + // Predefined constants + public static final PageSize A4 = new PageSize(27.94, 21.59); + public static final PageSize LEGAL = new PageSize(35.56, 21.59); + public static final PageSize TABLOID = new PageSize(43.18, 27.94); + public static final PageSize LETTER = new PageSize(27.94, 21.59); - // Custom Size Constructor public PageSize(double height, double width) { this.height = height; this.width = width; } - // Constructor for Predefined Sizes A4,A6,LEGAL,TABLOID using PaperSize Enum - public PageSize(PaperSize paperSize) { - this(paperSize.getHeight(), paperSize.getWidth()); // Delegate to custom size constructor - } - - // Factory Methods for Predefined Sizes - public static PageSize A4() { - return new PageSize(PaperSize.A4); - } - - public static PageSize A6() { - return new PageSize(PaperSize.A6); - } - - public static PageSize LEGAL() { - return new PageSize(PaperSize.LEGAL); - } - - public static PageSize TABLOID() { - return new PageSize(PaperSize.TABLOID); + // Default constructor (e.g., default to A4) + public PageSize() { + this(A4.getHeight(), A4.getWidth()); } // Getters for Height and Width @@ -67,41 +49,16 @@ public double getWidth() { return width; } - // Convert to Map (for serialization or configuration) public Map toMap() { - final Map options = new HashMap<>(); - options.put("height", getHeight()); - options.put("width", getWidth()); - return options; - } - - // Enum for Predefined Sizes - public enum PaperSize { - A4(27.94, 21.59), - A6(14.8, 10.5), - LEGAL(35.56, 21.59), - TABLOID(43.18, 27.94); - - private final double height; - private final double width; - - PaperSize(double height, double width) { - this.height = height; - this.width = width; - } - - public double getHeight() { - return height; - } - - public double getWidth() { - return width; - } + Map map = new HashMap<>(); + map.put("width", width); + map.put("height", height); + return map; } @Override public String toString() { - return String.format("PageSize[height=%.2f, width=%.2f]", height, width); + return "PageSize[width=" + this.getWidth() + ", height=" + this.getHeight() + "]"; } }