Class PrintPreview
PrintPreview preview = new PrintPreview(order);
dialogBody.add(preview); // with the application's own Print and Paper buttons
preview.setZoom(PrintPreview.Zoom.FIT_WIDTH);
It shows the document's own recording, the one its PDF is written from, so what it shows is what the file and the printer get. The pages scroll as a column, one sheet under the next, at a zoom that fits a whole page, fits the width, or is a percentage of the paper's real size. It is the toolkit's and the same on every system, because only one of the three systems' print dialogs previews an application's pages.
The user zooms it as a document viewer is zoomed: a pinch on a trackpad, or the wheel with
Command held on macOS and Control elsewhere (Control on macOS too), around the point under the
pointer (MouseEvent.Type.ZOOM), and, with the preview focused, Command or Control with + or = to zoom in, - to zoom out
and 0 for the paper's real size. A zoom the user made is a PrintPreview.Zoom.PERCENT one and is
announced as a Change.Aspect.VALUE change of the user's, which a toolbar showing the zoom
watches. Focused, the arrows, Page Up, Page Down, Home and End scroll the pages.
A reader hears a group named "Print preview", described by the page in the middle of the view and the count ("Page 3 of 12"); the pages' own text is not published to it.
The pages are recorded when the preview is made and again by refresh(); a face the
text asked for that was still loading records them again once it has loaded, or after ten
seconds without it, with a warning. A recording made again that fails, when nobody is in a call
to hear it, leaves the pages recorded before on show, and failure() says why. UI thread
only.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow the sheets are sized to the view. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint@Nullable RuntimeExceptionfailure()Why the pages shown are not the document's last recording, or null when they are.protected voidSays what this widget is, for an assistive technology.protected voidCalled when this widget takes keyboard focus.protected voidCalled when this widget loses keyboard focus.protected voidonKeyEvent(KeyEvent event) Key events (focused widget first, then ancestors).protected voidonLayout()Containers position children here (measure +Widget.layoutBox(float, float, float, float)per child).protected SizeonMeasure(Constraints constraints) Reports the size this widget wants withinconstraints.protected voidonPaintOverlay(Canvas canvas) Painted after children (scrollbars, focus rings…).intrefresh()Records the document's pages again and shows them: after the application changed what its widgets show, or the document's paper.setZoom(PrintPreview.Zoom zoom) setZoomPercent(float percent) Sizes the sheets at a percentage of the paper's real size, on a screen of 96 dots per inch at 100 %, and sets the zoom toPrintPreview.Zoom.PERCENT.showPage(int number) Scrolls a page's top into the view.zoom()floatMethods inherited from class limn.scene.Widget
acceptsTextInput, accessibleLabelAccessKey, accessibleLabelTarget, accessibleLabelText, add, add, announceChange, backdropReach, baselineOffset, baselineOffsetOf, caretRect, children, clipboard, clipHeight, clipsChildren, clipWidth, clipX, clipY, controlSize, cursor, declaredControlSize, declaredLayoutDirection, declaredLocale, focusArrivedBackward, focusArrivedByTraversal, handleUserChange, height, hitTest, hitTestChild, id, imageCursor, inheritanceHost, invalidate, invalidate, invalidateAccessible, isEnabled, isFocusable, isFocused, isRightToLeft, isSelfEnabled, isShowing, isVisible, isVisibleByItsOwnFlag, layoutBox, layoutDirection, locale, localToScene, localToSceneBounds, markNeedsContainedLayout, markNeedsLayout, markNeedsLayoutInPlace, maxHeight, maxWidth, measure, minHeight, minWidth, moveChild, moveChild, moveChild, neutralBase, notifyChange, notifyTextEdit, observeChanges, onAccessibilityAction, onAccessibilityChild, onAccessibilityChildAction, onAccessibilityChildIdentity, onAttached, onCanEdit, onCharTyped, onDetached, onDragExit, onDragOver, onDragStart, onDrop, onEdit, onHitTest, onMouseEvent, onPaint, onPreedit, onSyntheticAction, overlayPassesPointer, paintChildren, paintOutset, paintsDecoration, paintsFromBackdrop, paintWidget, parent, remove, remove, requestFocus, requestFocus, revealInView, revealInView, runHandler, scene, sceneNanos, sceneToLocal, self, setAccessibleDescribedBy, setAccessibleDescription, setAccessibleDescription, setAccessibleIgnored, setAccessibleLabelledBy, setAccessibleName, setAccessibleName, setAccessibleRole, setControlSize, setCursor, setEnabled, setFocusable, setId, setImageCursor, setInheritanceHost, setLayoutDirection, setLocale, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setPresentedElsewhere, setTooltip, setTooltip, setVisible, shapeText, textRuler, tooltip, tooltipSource, width, x, y
-
Constructor Details
-
PrintPreview
- Parameters:
document- the document to show; its pages are recorded now- Throws:
IllegalStateException- if the document's margins, header and footer leave a content box smaller than a quarter inch either way (Documentsays why)
-
-
Method Details
-
refresh
Records the document's pages again and shows them: after the application changed what its widgets show, or the document's paper.- Returns:
- this preview
- Throws:
IllegalStateException- as the constructor does, for what the document's widgets show now
-
failure
Why the pages shown are not the document's last recording, or null when they are.A face the text asked for that was still loading records the pages again once it has loaded, after the constructor or
refresh()has returned, so no caller is there to hear a throw. That recording can fail where the first did not: a header or a footer that measures taller in the face that loaded can leave less than the quarter inchDocumentrequires. The preview then keeps showing the pages recorded before the face loaded, logs a warning, answers the exception here, and announces aChange.Aspect.VALIDITYchange, which a dialog around it watches to say that the document cannot be printed as it is. The next recording that succeeds clears it, with another such change.- Returns:
- the
IllegalStateExceptionthe recording made again threw (or what wraps any other failure), or null
-
pageCount
public int pageCount()- Returns:
- how many pages the document has, as last recorded
-
currentPage
public int currentPage()- Returns:
- the page in the middle of the view, from 1
-
showPage
Scrolls a page's top into the view.- Parameters:
number- the page, from 1; clamped to the document's pages- Returns:
- this preview
-
setZoom
- Parameters:
zoom- how the sheets are sized;PrintPreview.Zoom.PERCENTuses the last percentage set- Returns:
- this preview
-
zoom
- Returns:
- how the sheets are sized
-
setZoomPercent
Sizes the sheets at a percentage of the paper's real size, on a screen of 96 dots per inch at 100 %, and sets the zoom toPrintPreview.Zoom.PERCENT.- Parameters:
percent- from 10 to 800- Returns:
- this preview
-
zoomPercent
public float zoomPercent()- Returns:
- the size the sheets are shown at, as a percentage of the paper's real size on a 96-dpi screen, whichever the zoom: what a fitting zoom comes to at the view's size
-
onKeyEvent
Description copied from class:WidgetKey events (focused widget first, then ancestors).- Overrides:
onKeyEventin classWidget<PrintPreview>
-
onFocusGained
protected void onFocusGained()Description copied from class:WidgetCalled when this widget takes keyboard focus. Default: nothing.- Overrides:
onFocusGainedin classWidget<PrintPreview>
-
onFocusLost
protected void onFocusLost()Description copied from class:WidgetCalled when this widget loses keyboard focus. Default: nothing.- Overrides:
onFocusLostin classWidget<PrintPreview>
-
onMeasure
Description copied from class:WidgetReports the size this widget wants withinconstraints. Called once per layout pass, and the result is cached against the constraints and the resolved axes (size step, layout direction, locale), so it must be a pure function of them and of this widget's own state.Resolve the
ControlSizeand theLayoutDirectiononce each here and thread them down; never read either in a constructor. The locale needs no threading: it is in scope, andI18n.locale()answers it wherever text is resolved.- Specified by:
onMeasurein classWidget<PrintPreview>
-
onLayout
protected void onLayout()Description copied from class:WidgetContainers position children here (measure +Widget.layoutBox(float, float, float, float)per child).- Overrides:
onLayoutin classWidget<PrintPreview>
-
onPaintOverlay
Description copied from class:WidgetPainted after children (scrollbars, focus rings…).- Overrides:
onPaintOverlayin classWidget<PrintPreview>
-
onAccessibility
Description copied from class:WidgetSays what this widget is, for an assistive technology.Called on the UI thread inside the publish step, with this widget's own locale in scope, and never from a paint. A widget that overrides nothing still gets a node with its bounds, its enabled, focusable, visible and showing states, its language, its children in tree order, the focus and scroll-into-view verbs when it is focusable, and its tooltip as a name when nothing else supplied one. What it does not get is a role: a widget that declares no role, no name, no description, no state, no verb and no facet is scaffolding, and the tree removes it and hoists its children in its place, so that a screen reader hears the controls rather than the boxes.
Nothing here may allocate. The builder's setters take a facet's fields rather than a facet, and a name is handed over as the localizable string this widget holds rather than as a resolved one, so that a frame which damaged this widget and changed nothing about it costs a comparison and no memory at all.
Accessibilitystates the two rules and what breaks when they are ignored.- Overrides:
onAccessibilityin classWidget<PrintPreview>- Parameters:
a- the node being described; write into it, and never keep it
-