|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.openqa.selenium.print; |
| 19 | + |
| 20 | +import org.openqa.selenium.internal.Require; |
| 21 | + |
| 22 | +public class PrintOptions { |
| 23 | + |
| 24 | + public enum Orientation { |
| 25 | + Portrait, |
| 26 | + Landscape |
| 27 | + } |
| 28 | + private Orientation orientation = Orientation.Portrait; |
| 29 | + private double scale = 1.0; |
| 30 | + private boolean background = false; |
| 31 | + private boolean shrinkToFit = true; |
| 32 | + private PageSize pageSize = new PageSize(); |
| 33 | + private PageMargin pageMargin = new PageMargin(); |
| 34 | + private String[] pageRanges; |
| 35 | + |
| 36 | + public Orientation getOrientation() { |
| 37 | + return this.orientation; |
| 38 | + } |
| 39 | + |
| 40 | + public void setOrientation(Orientation orientation) { |
| 41 | + this.orientation = Require.nonNull("orientation", orientation); |
| 42 | + } |
| 43 | + |
| 44 | + public String[] getPageRanges() { |
| 45 | + return this.pageRanges; |
| 46 | + } |
| 47 | + |
| 48 | + public void setPageRanges(String firstRange, String ... ranges) { |
| 49 | + Require.nonNull("pageRanges", firstRange); |
| 50 | + this.pageRanges = new String[ranges.length + 1]; // Need to add all ranges and the initial range too. |
| 51 | + |
| 52 | + this.pageRanges[0] = firstRange; |
| 53 | + |
| 54 | + for (int i = 1; i < ranges.length; i++) { |
| 55 | + this.pageRanges[i] = ranges[i - 1]; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + public void setBackground(boolean background) { |
| 60 | + this.background = Require.nonNull("background", background); |
| 61 | + } |
| 62 | + |
| 63 | + public boolean getBackground() { |
| 64 | + return this.background; |
| 65 | + } |
| 66 | + |
| 67 | + public void setScale(double scale) { |
| 68 | + if (scale < 0.1 || scale > 2) { |
| 69 | + throw new IllegalArgumentException("Scale value should be between 0.1 and 2"); |
| 70 | + } |
| 71 | + this.scale = scale; |
| 72 | + } |
| 73 | + |
| 74 | + public double getScale() { |
| 75 | + return this.scale; |
| 76 | + } |
| 77 | + |
| 78 | + public boolean getShrinkToFit() { |
| 79 | + return this.shrinkToFit; |
| 80 | + } |
| 81 | + |
| 82 | + public void setShrinkToFit(boolean value) { |
| 83 | + this.shrinkToFit = Require.nonNull("value", value); |
| 84 | + } |
| 85 | + |
| 86 | + public void setPageSize(PageSize pageSize) { |
| 87 | + this.pageSize = Require.nonNull("pageSize", pageSize); |
| 88 | + } |
| 89 | + |
| 90 | + public void setPageMargin(PageMargin margin) { |
| 91 | + this.pageMargin = Require.nonNull("margin", margin); |
| 92 | + } |
| 93 | + |
| 94 | + public PageSize getPageSize() { |
| 95 | + return this.pageSize; |
| 96 | + } |
| 97 | + |
| 98 | + public PageMargin getPageMargin() { |
| 99 | + return this.pageMargin; |
| 100 | + } |
| 101 | +} |
0 commit comments