/// <summary> /// A new instance where 'format' describes the page's /// size and orientation and 'painter' is the instance /// that will draw the page's graphics. </summary> /// <exception cref="NullPointerException"> /// If the <code>painter</code> or <code>format</code> /// argument is <code>null</code> </exception> internal BookPage(Book outerInstance, Printable painter, PageFormat format) { this.OuterInstance = outerInstance; if (painter == null || format == null) { throw new NullPointerException(); } MFormat = format; MPainter = painter; }
/// <summary> /// Appends <code>numPages</code> pages to the end of this /// <code>Book</code>. Each of the pages is associated with /// <code>page</code>. </summary> /// <param name="painter"> the <code>Printable</code> instance that renders /// the page </param> /// <param name="page"> the size and orientation of the page </param> /// <param name="numPages"> the number of pages to be added to the /// this <code>Book</code>. </param> /// <exception cref="NullPointerException"> /// If the <code>painter</code> or <code>page</code> /// argument is <code>null</code> </exception> public virtual void Append(Printable painter, PageFormat page, int numPages) { BookPage bookPage = new BookPage(this, painter, page); int pageIndex = MPages.Count; int newSize = pageIndex + numPages; MPages.Capacity = newSize; for (int i = pageIndex; i < newSize; i++) { MPages[i] = bookPage; } }
/// <summary> /// Sets the <code>PageFormat</code> and the <code>Painter</code> for a /// specified page number. </summary> /// <param name="pageIndex"> the zero based index of the page whose /// painter and format is altered </param> /// <param name="painter"> the <code>Printable</code> instance that /// renders the page </param> /// <param name="page"> the size and orientation of the page </param> /// <exception cref="IndexOutOfBoundsException"> if the specified /// page is not already in this <code>Book</code> </exception> /// <exception cref="NullPointerException"> if the <code>painter</code> or /// <code>page</code> argument is <code>null</code> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void setPage(int pageIndex, Printable painter, PageFormat page) throws IndexOutOfBoundsException public virtual void SetPage(int pageIndex, Printable painter, PageFormat page) { if (painter == null) { throw new NullPointerException("painter is null"); } if (page == null) { throw new NullPointerException("page is null"); } MPages[pageIndex] = new BookPage(this, painter, page); }
/// <summary> /// Returns the clone of <code>page</code> with its settings /// adjusted to be compatible with the current printer of this /// <code>PrinterJob</code>. For example, the returned /// <code>PageFormat</code> could have its imageable area /// adjusted to fit within the physical area of the paper that /// is used by the current printer. </summary> /// <param name="page"> the <code>PageFormat</code> that is cloned and /// whose settings are changed to be compatible with /// the current printer </param> /// <returns> a <code>PageFormat</code> that is cloned from /// <code>page</code> and whose settings are changed /// to conform with this <code>PrinterJob</code>. </returns> public abstract PageFormat ValidatePage(PageFormat page);
/// <summary> /// Calculates a <code>PageFormat</code> with values consistent with those /// supported by the current <code>PrintService</code> for this job /// (ie the value returned by <code>getPrintService()</code>) and media, /// printable area and orientation contained in <code>attributes</code>. /// <para> /// Calling this method does not update the job. /// It is useful for clients that have a set of attributes obtained from /// <code>printDialog(PrintRequestAttributeSet attributes)</code> /// and need a PageFormat to print a Pageable object. /// </para> /// </summary> /// <param name="attributes"> a set of printing attributes, for example obtained /// from calling printDialog. If <code>attributes</code> is null a default /// PageFormat is returned. </param> /// <returns> a <code>PageFormat</code> whose settings conform with /// those of the current service and the specified attributes. /// @since 1.6 </returns> public virtual PageFormat GetPageFormat(PrintRequestAttributeSet attributes) { PrintService service = PrintService; PageFormat pf = DefaultPage(); if (service == null || attributes == null) { return(pf); } Media media = (Media)attributes.get(typeof(Media)); MediaPrintableArea mpa = (MediaPrintableArea)attributes.get(typeof(MediaPrintableArea)); OrientationRequested orientReq = (OrientationRequested)attributes.get(typeof(OrientationRequested)); if (media == null && mpa == null && orientReq == null) { return(pf); } Paper paper = pf.Paper; /* If there's a media but no media printable area, we can try * to retrieve the default value for mpa and use that. */ if (mpa == null && media != null && service.isAttributeCategorySupported(typeof(MediaPrintableArea))) { Object mpaVals = service.getSupportedAttributeValues(typeof(MediaPrintableArea), null, attributes); if (mpaVals is MediaPrintableArea[] && ((MediaPrintableArea[])mpaVals).Length > 0) { mpa = ((MediaPrintableArea[])mpaVals)[0]; } } if (media != null && service.isAttributeValueSupported(media, null, attributes)) { if (media is MediaSizeName) { MediaSizeName msn = (MediaSizeName)media; MediaSize msz = MediaSize.getMediaSizeForName(msn); if (msz != null) { double inch = 72.0; double paperWid = msz.getX(MediaSize.INCH) * inch; double paperHgt = msz.getY(MediaSize.INCH) * inch; paper.SetSize(paperWid, paperHgt); if (mpa == null) { paper.SetImageableArea(inch, inch, paperWid - 2 * inch, paperHgt - 2 * inch); } } } } if (mpa != null && service.isAttributeValueSupported(mpa, null, attributes)) { float[] printableArea = mpa.getPrintableArea(MediaPrintableArea.INCH); for (int i = 0; i < printableArea.Length; i++) { printableArea[i] = printableArea[i] * 72.0f; } paper.SetImageableArea(printableArea[0], printableArea[1], printableArea[2], printableArea[3]); } if (orientReq != null && service.isAttributeValueSupported(orientReq, null, attributes)) { int orient; if (orientReq.Equals(OrientationRequested.REVERSE_LANDSCAPE)) { orient = PageFormat.REVERSE_LANDSCAPE; } else if (orientReq.Equals(OrientationRequested.LANDSCAPE)) { orient = PageFormat.LANDSCAPE; } else { orient = PageFormat.PORTRAIT; } pf.Orientation = orient; } pf.Paper = paper; pf = ValidatePage(pf); return(pf); }
/// <summary> /// Clones the <code>PageFormat</code> argument and alters the /// clone to describe a default page size and orientation. </summary> /// <param name="page"> the <code>PageFormat</code> to be cloned and altered </param> /// <returns> clone of <code>page</code>, altered to describe a default /// <code>PageFormat</code>. </returns> public abstract PageFormat DefaultPage(PageFormat page);
/// <summary> /// Displays a dialog that allows modification of a /// <code>PageFormat</code> instance. /// The <code>page</code> argument is used to initialize controls /// in the page setup dialog. /// If the user cancels the dialog then this method returns the /// original <code>page</code> object unmodified. /// If the user okays the dialog then this method returns a new /// <code>PageFormat</code> object with the indicated changes. /// In either case, the original <code>page</code> object is /// not modified. </summary> /// <param name="page"> the default <code>PageFormat</code> presented to the /// user for modification </param> /// <returns> the original <code>page</code> object if the dialog /// is cancelled; a new <code>PageFormat</code> object /// containing the format indicated by the user if the /// dialog is acknowledged. </returns> /// <exception cref="HeadlessException"> if GraphicsEnvironment.isHeadless() /// returns true. </exception> /// <seealso cref= java.awt.GraphicsEnvironment#isHeadless /// @since 1.2 </seealso> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public abstract PageFormat pageDialog(PageFormat page) throws java.awt.HeadlessException; public abstract PageFormat PageDialog(PageFormat page);
/// <summary> /// Calls <code>painter</code> to render the pages in the specified /// <code>format</code>. The pages in the document to be printed by /// this <code>PrinterJob</code> are rendered by the /// <code>Printable</code> object, <code>painter</code>. The /// <code>PageFormat</code> of each page is <code>format</code>. </summary> /// <param name="painter"> the <code>Printable</code> called to render /// each page of the document </param> /// <param name="format"> the size and orientation of each page to /// be printed </param> public abstract void SetPrintable(Printable painter, PageFormat format);
/// <summary> /// Appends a single page to the end of this <code>Book</code>. </summary> /// <param name="painter"> the <code>Printable</code> instance that /// renders the page </param> /// <param name="page"> the size and orientation of the page </param> /// <exception cref="NullPointerException"> /// If the <code>painter</code> or <code>page</code> /// argument is <code>null</code> </exception> public virtual void Append(Printable painter, PageFormat page) { MPages.Add(new BookPage(this, painter, page)); }