Path: blob/master/src/java.desktop/share/classes/javax/print/attribute/standard/DialogOwner.java
41171 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.print.attribute.standard;2627import java.awt.Window;28import java.io.Serial;2930import javax.print.attribute.Attribute;31import javax.print.attribute.PrintRequestAttribute;3233import sun.print.DialogOwnerAccessor;3435/**36* An attribute class used to support requesting a print or page setup dialog37* be kept displayed on top of all windows or some specific window.38* <p>39* Constructed without any arguments it will request that a print or page40* setup dialog be configured as if the application directly was to specify41* {@code java.awt.Window.setAlwaysOnTop(true)}, subject to permission checks.42* <p>43* Constructed with a {@link java.awt.Window} parameter, it requests that44* the dialog be owned by the specified window.45*46* @since 1147*/48public final class DialogOwner implements PrintRequestAttribute {4950private static class Accessor extends DialogOwnerAccessor {5152public long getOwnerID(DialogOwner owner) {53return owner.getID();54}55}5657private static Accessor accessor = new Accessor();58static {59DialogOwnerAccessor.setAccessor(accessor);60}6162/**63* Use serialVersionUID from JDK 11 for interoperability.64*/65@Serial66private static final long serialVersionUID = -1901909867156076547L;6768/**69* The owner of the dialog.70*/71private Window owner;72private transient long id;7374/**75* Constructs an instance which can be used to request76* {@code java.awt.Window.setAlwaysOnTop(true)} behaviour.77* This should be used where there is no application preferred owner window.78* Whether this has any effect depends on if always on top is supported79* for this platform and the particular dialog to be displayed.80*/81public DialogOwner() {82}8384/**85* Constructs an instance which can be used to request that the86* specified {@link java.awt.Window} be the owner of the dialog.87* @param owner window.88*/89public DialogOwner(Window owner) {90this.owner = owner;91}9293/**94* Constructs an instance which requests that the dialog be displayed95* as if it were a child of a native platform window, specified96* using its opqaue platform identifier or handle.97* This is useful mainly for the case where the id represents a window98* which may not be an AWT {@code Window}, but instead was created by99* another UI toolkit, such as OpenJFX.100* Any effect is platform dependent.101* @param id a native window identifier or handle102*/103DialogOwner(long id) {104this.id = id;105}106107/**108* Returns a native platform id or handle, if one was specified,109* otherwise, zero.110* @return a native platform id.111*/112long getID() {113return id;114}115116/**117* Returns a {@code Window owner}, if one was specified,118* otherwise {@code null}.119* @return an owner window.120*/121public Window getOwner() {122return owner;123}124125/**126* Get the printing attribute class which is to be used as the "category"127* for this printing attribute value.128* <p>129* For class {@code DialogOwner}, the category is class130* {@code DialogOwner} itself.131*132* @return printing attribute class (category), an instance of class133* {@link Class java.lang.Class}134*/135public final Class<? extends Attribute> getCategory() {136return DialogOwner.class;137}138139/**140* Get the name of the category of which this attribute value is an141* instance.142* <p>143* For class {@code DialogOwner}, the category name is144* {@code "dialog-owner"}.145*146*/147public final String getName() {148return "dialog-owner";149150}151}152153154