Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.print; 027 028import java.util.Arrays; 029 030import javafx.beans.property.IntegerProperty; 031import javafx.beans.property.ReadOnlyIntegerProperty; 032import javafx.beans.property.ReadOnlyIntegerWrapper; 033 034/** 035 * A {@code PageRange} is used to select or constrain the job print 036 * stream pages to print. 037 * Page numbering starts from 1 to correspond to user expectations. 038 * The <i>start</i> page must be greater than zero and less than or 039 * equal to the <i>end</i>page. 040 * If start and end are equal, the range refers to a single page. 041 * Values that exceed the number of job pages are harmlessly ignored 042 * during printing. 043 * @since JavaFX 8 044 */ 045public final class PageRange { 046 047 private ReadOnlyIntegerWrapper startPage, endPage; 048 049 /** 050 * Create a new PageRange with the specified start and end page numbers. 051 * @param startPage the first page in the range. 052 * @param endPage the last page in the range. 053 * @throws IllegalArgumentException if the page range is not valid 054 */ 055 public PageRange(int startPage, int endPage) { 056 if (startPage <= 0 || startPage > endPage) { 057 throw new IllegalArgumentException("Invalid range : " + 058 startPage + " -> " + endPage); 059 } 060 startPageImplProperty().set(startPage); 061 endPageImplProperty().set(endPage); 062 } 063 064 /** 065 * <code>IntegerProperty</code> representing the starting 066 * page number of the range. See {@link #setStartPage setStartPage()} 067 * for more information. 068 */ 069 private ReadOnlyIntegerWrapper startPageImplProperty() { 070 if (startPage == null) { 071 startPage = 072 new ReadOnlyIntegerWrapper(PageRange.this, "startPage", 1) { 073 074 @Override 075 public void set(int value) { 076 if ((value <= 0) || 077 (endPage != null && value < endPage.get())) { 078 return; 079 } 080 super.set(value); 081 } 082 }; 083 } 084 return startPage; 085 } 086 087 /** 088 * <code>IntegerProperty</code> representing the starting 089 * page number of the range. See {@link getStartPage getStartPage()} 090 * for more information. 091 */ 092 public ReadOnlyIntegerProperty startPageProperty() { 093 return startPageImplProperty().getReadOnlyProperty(); 094 } 095 096 /** 097 * @return the starting page of the range. 098 */ 099 public int getStartPage() { 100 return startPageProperty().get(); 101 } 102 103 private ReadOnlyIntegerWrapper endPageImplProperty() { 104 if (endPage == null) { 105 endPage = 106 new ReadOnlyIntegerWrapper(PageRange.this, "endPage", 9999) { 107 108 @Override 109 public void set(int value) { 110 if ((value <= 0) || 111 (startPage != null && value < startPage.get())) { 112 return; 113 } 114 super.set(value); 115 } 116 117 }; 118 } 119 return endPage; 120 } 121 122 /** 123 * <code>IntegerProperty</code> representing the ending 124 * page number of the range. See {@link #getEndPage getEndPage()} 125 * for more information. 126 */ 127 public ReadOnlyIntegerProperty endPageProperty() { 128 return endPageImplProperty().getReadOnlyProperty(); 129 } 130 131 /** 132 * @return the ending page of the range. 133 */ 134 public int getEndPage() { 135 return endPageProperty().get(); 136 } 137}