diff --git a/src/java.desktop/share/classes/javax/print/ServiceUI.java b/src/java.desktop/share/classes/javax/print/ServiceUI.java index 3990ba6c942..eca9faadc53 100644 --- a/src/java.desktop/share/classes/javax/print/ServiceUI.java +++ b/src/java.desktop/share/classes/javax/print/ServiceUI.java @@ -25,6 +25,8 @@ package javax.print; +import java.awt.Dialog; +import java.awt.Frame; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; import java.awt.HeadlessException; @@ -33,11 +35,11 @@ import java.awt.Window; import javax.print.attribute.Attribute; import javax.print.attribute.AttributeSet; -import javax.print.attribute.standard.DialogOwner; import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.Destination; import javax.print.attribute.standard.Fidelity; +import sun.print.DialogOwner; import sun.print.ServiceDialog; import sun.print.SunAlternateMedia; @@ -183,7 +185,6 @@ public class ServiceUI { DialogOwner dlgOwner = (DialogOwner)attributes.get(DialogOwner.class); Window owner = (dlgOwner != null) ? dlgOwner.getOwner() : null; - boolean setOnTop = (dlgOwner != null) && (owner == null); Rectangle gcBounds = (gc == null) ? GraphicsEnvironment. getLocalGraphicsEnvironment().getDefaultScreenDevice(). @@ -191,17 +192,21 @@ public class ServiceUI { x += gcBounds.x; y += gcBounds.y; - ServiceDialog dialog = new ServiceDialog(gc, - x, - y, - services, defaultIndex, - flavor, attributes, - owner); - if (setOnTop) { - try { - dialog.setAlwaysOnTop(true); - } catch (SecurityException e) { - } + ServiceDialog dialog; + if (owner instanceof Frame) { + dialog = new ServiceDialog(gc, + x, + y, + services, defaultIndex, + flavor, attributes, + (Frame)owner); + } else { + dialog = new ServiceDialog(gc, + x, + y, + services, defaultIndex, + flavor, attributes, + (Dialog)owner); } Rectangle dlgBounds = dialog.getBounds(); diff --git a/src/java.desktop/share/classes/javax/print/attribute/standard/DialogOwner.java b/src/java.desktop/share/classes/javax/print/attribute/standard/DialogOwner.java deleted file mode 100644 index 6e966c1ed0d..00000000000 --- a/src/java.desktop/share/classes/javax/print/attribute/standard/DialogOwner.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.print.attribute.standard; - -import java.awt.Window; -import javax.print.attribute.Attribute; -import javax.print.attribute.PrintRequestAttribute; -import sun.print.DialogOwnerAccessor; - -/** - * An attribute class used to support requesting a print or page setup dialog - * be kept displayed on top of all windows or some specific window. - *
- * Constructed without any arguments it will request that a print or page - * setup dialog be configured as if the application directly was to specify - * {@code java.awt.Window.setAlwaysOnTop(true)}, subject to permission checks. - *
- * Constructed with a {@link java.awt.Window} parameter, it requests that - * the dialog be owned by the specified window. - * - * @since 11 - */ -public final class DialogOwner implements PrintRequestAttribute { - - private static class Accessor extends DialogOwnerAccessor { - - public long getOwnerID(DialogOwner owner) { - return owner.getID(); - } - } - - static private Accessor accessor = new Accessor(); - static { - DialogOwnerAccessor.setAccessor(accessor); - } - - private static final long serialVersionUID = -1901909867156076547L; - - private Window owner; - private transient long id; - - /** - * Constructs an instance which can be used to request - * {@code java.awt.Window.setAlwaysOnTop(true)} behaviour. - * This should be used where there is no application preferred owner window. - * Whether this has any effect depends on if always on top is supported - * for this platform and the particular dialog to be displayed. - */ - public DialogOwner() { - } - - /** - * Constructs an instance which can be used to request that the - * specified {@link java.awt.Window} be the owner of the dialog. - * @param owner window. - */ - public DialogOwner(Window owner) { - this.owner = owner; - } - - /** - * Constructs an instance which requests that the dialog be displayed - * as if it were a child of a native platform window, specified - * using its opqaue platform identifier or handle. - * This is useful mainly for the case where the id represents a window - * which may not be an AWT {@code Window}, but instead was created by - * another UI toolkit, such as OpenJFX. - * Any effect is platform dependent. - * @param id a native window identifier or handle - */ - DialogOwner(long id) { - this.id = id; - } - - /** - * Returns a native platform id or handle, if one was specified, - * otherwise, zero. - * @return a native platform id. - */ - long getID() { - return id; - } - - /** - * Returns a {@code Window owner}, if one was specified, - * otherwise {@code null}. - * @return an owner window. - */ - public Window getOwner() { - return owner; - } - - /** - * Get the printing attribute class which is to be used as the "category" - * for this printing attribute value. - *
- * For class {@code DialogOwner}, the category is class - * {@code DialogOwner} itself. - * - * @return printing attribute class (category), an instance of class - * {@link Class java.lang.Class} - */ - public final Class extends Attribute> getCategory() { - return DialogOwner.class; - } - - /** - * Get the name of the category of which this attribute value is an - * instance. - *
- * For class {@code DialogOwner}, the category name is - * {@code "dialog-owner"}. - * - */ - public final String getName() { - return "dialog-owner"; - - } -} diff --git a/src/java.desktop/share/classes/sun/print/DialogOwnerAccessor.java b/src/java.desktop/share/classes/sun/print/DialogOnTop.java similarity index 56% rename from src/java.desktop/share/classes/sun/print/DialogOwnerAccessor.java rename to src/java.desktop/share/classes/sun/print/DialogOnTop.java index db029f3ee03..821e4e0beee 100644 --- a/src/java.desktop/share/classes/sun/print/DialogOwnerAccessor.java +++ b/src/java.desktop/share/classes/sun/print/DialogOnTop.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,23 +25,40 @@ package sun.print; -import javax.print.attribute.standard.DialogOwner; +import javax.print.attribute.Attribute; +import javax.print.attribute.PrintRequestAttribute; -public abstract class DialogOwnerAccessor { +/* + * An implementation class used to request the dialog be set always-on-top. + * It needs to be read and honoured by the dialog code which will use + * java.awt.Window.setAlwaysOnTop(true) in cases where it is supported. + */ +public class DialogOnTop implements PrintRequestAttribute { - public abstract long getOwnerID(DialogOwner owner); + private static final long serialVersionUID = -1901909867156076547L; - public static DialogOwnerAccessor accessor = null; + long id; - public static void setAccessor(DialogOwnerAccessor acc) { - accessor = acc; + public DialogOnTop() { } - public static long getID(DialogOwner owner) { - if (accessor == null || owner == null) { - return 0; - } else { - return accessor.getOwnerID(owner); - } + public DialogOnTop(long id) { + this.id = id; + } + + public final Class extends Attribute> getCategory() { + return DialogOnTop.class; + } + + public long getID() { + return id; + } + + public final String getName() { + return "dialog-on-top"; + } + + public String toString() { + return "dialog-on-top"; } } diff --git a/src/java.desktop/share/classes/sun/print/DialogOwner.java b/src/java.desktop/share/classes/sun/print/DialogOwner.java new file mode 100644 index 00000000000..f3f50391754 --- /dev/null +++ b/src/java.desktop/share/classes/sun/print/DialogOwner.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package sun.print; + +import java.awt.Dialog; +import javax.print.attribute.Attribute; +import javax.print.attribute.PrintRequestAttribute; +import java.awt.Frame; +import java.awt.Window; + +/** + * Class DialogOwner is a printing attribute class that identifies + * the window that owns the print dialog. + * + *
+ * IPP Compatibility: This is not an IPP attribute. + *
+ * + */ +@SuppressWarnings("serial") // JDK-implementation class +public final class DialogOwner + implements PrintRequestAttribute { + + private Window dlgOwner; + + /** + * Construct a new dialog owner attribute with the given frame. + * + * @param frame the frame that owns the print dialog + */ + public DialogOwner(Frame frame) { + dlgOwner = frame; + } + + /** + * Construct a new dialog owner attribute with the given dialog. + * + * @param dialog the dialog that owns the print dialog + */ + public DialogOwner(Dialog dialog) { + dlgOwner = dialog; + } + + /** + * Returns the string table for class DialogOwner. + */ + public Window getOwner() { + return dlgOwner; + } + + + /** + * Get the printing attribute class which is to be used as the "category" + * for this printing attribute value. + *
+ * For class DialogOwner the category is class + * DialogOwner itself. + * + * @return Printing attribute class (category), an instance of class + * {@link java.lang.Class java.lang.Class}. + */ + public Class extends Attribute> getCategory() { + return DialogOwner.class; + } + + + /** + * Get the name of the category of which this attribute value is an + * instance. + *
+ * For class DialogOwner the category name is
+ * {@code "dialog-owner"}.
+ *
+ * @return Attribute category name.
+ */
+ public String getName() {
+ return "dialog-owner";
+ }
+
+}
diff --git a/src/java.desktop/share/classes/sun/print/PrintJob2D.java b/src/java.desktop/share/classes/sun/print/PrintJob2D.java
index 861f496e0c3..9d9b2009af3 100644
--- a/src/java.desktop/share/classes/sun/print/PrintJob2D.java
+++ b/src/java.desktop/share/classes/sun/print/PrintJob2D.java
@@ -60,7 +60,6 @@ import javax.print.attribute.standard.Chromaticity;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.Destination;
import javax.print.attribute.standard.DialogTypeSelection;
-import javax.print.attribute.standard.DialogOwner;
import javax.print.attribute.standard.JobName;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.PrintQuality;
diff --git a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
index 5d584e587df..0decacad4af 100644
--- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
+++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
@@ -74,7 +74,6 @@ import javax.print.attribute.Size2DSyntax;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.Destination;
import javax.print.attribute.standard.DialogTypeSelection;
-import javax.print.attribute.standard.DialogOwner;
import javax.print.attribute.standard.Fidelity;
import javax.print.attribute.standard.JobName;
import javax.print.attribute.standard.JobSheets;
@@ -831,24 +830,17 @@ public abstract class RasterPrinterJob extends PrinterJob {
int x = gcBounds.x+50;
int y = gcBounds.y+50;
ServiceDialog pageDialog;
- boolean setOnTop = false;
if (onTop != null) {
attributes.add(onTop);
- Window owner = onTop.getOwner();
- if (owner != null) {
- w = owner; // use the one specifed by the app
- } else if (DialogOwnerAccessor.getID(onTop) == 0) {
- setOnTop = true;
- }
}
+ if (w instanceof Frame) {
pageDialog = new ServiceDialog(gc, x, y, service,
DocFlavor.SERVICE_FORMATTED.PAGEABLE,
- attributes, w);
- if (setOnTop) {
- try {
- pageDialog.setAlwaysOnTop(true);
- } catch (SecurityException e) {
- }
+ attributes,(Frame)w);
+ } else {
+ pageDialog = new ServiceDialog(gc, x, y, service,
+ DocFlavor.SERVICE_FORMATTED.PAGEABLE,
+ attributes, (Dialog)w);
}
Rectangle dlgBounds = pageDialog.getBounds();
@@ -996,7 +988,8 @@ public abstract class RasterPrinterJob extends PrinterJob {
* (it might be set in java.awt.PrintJob.printDialog)
*/
if (attributes.get(DialogOwner.class) == null) {
- attributes.add(new DialogOwner(w));
+ attributes.add(w instanceof Frame ? new DialogOwner((Frame)w) :
+ new DialogOwner((Dialog)w));
}
} else {
grCfg = GraphicsEnvironment.getLocalGraphicsEnvironment().
@@ -2588,7 +2581,7 @@ public abstract class RasterPrinterJob extends PrinterJob {
}
}
- private DialogOwner onTop = null;
+ private DialogOnTop onTop = null;
private long parentWindowID = 0L;
@@ -2604,9 +2597,9 @@ public abstract class RasterPrinterJob extends PrinterJob {
private void setParentWindowID(PrintRequestAttributeSet attrs) {
parentWindowID = 0L;
- onTop = (DialogOwner)attrs.get(DialogOwner.class);
+ onTop = (DialogOnTop)attrs.get(DialogOnTop.class);
if (onTop != null) {
- parentWindowID = DialogOwnerAccessor.getID(onTop);
+ parentWindowID = onTop.getID();
}
}
}
diff --git a/src/java.desktop/share/classes/sun/print/ServiceDialog.java b/src/java.desktop/share/classes/sun/print/ServiceDialog.java
index 7e5cba3dfec..c253332231b 100644
--- a/src/java.desktop/share/classes/sun/print/ServiceDialog.java
+++ b/src/java.desktop/share/classes/sun/print/ServiceDialog.java
@@ -38,7 +38,6 @@ import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Toolkit;
-import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
@@ -137,13 +136,33 @@ public class ServiceDialog extends JDialog implements ActionListener {
int defaultServiceIndex,
DocFlavor flavor,
PrintRequestAttributeSet attributes,
- Window window)
+ Dialog dialog)
{
- super(window, getMsg("dialog.printtitle"), Dialog.DEFAULT_MODALITY_TYPE, gc);
+ super(dialog, getMsg("dialog.printtitle"), true, gc);
initPrintDialog(x, y, services, defaultServiceIndex,
flavor, attributes);
}
+
+
+ /**
+ * Constructor for the "standard" print dialog (containing all relevant
+ * tabs)
+ */
+ public ServiceDialog(GraphicsConfiguration gc,
+ int x, int y,
+ PrintService[] services,
+ int defaultServiceIndex,
+ DocFlavor flavor,
+ PrintRequestAttributeSet attributes,
+ Frame frame)
+ {
+ super(frame, getMsg("dialog.printtitle"), true, gc);
+ initPrintDialog(x, y, services, defaultServiceIndex,
+ flavor, attributes);
+ }
+
+
/**
* Initialize print dialog.
*/
@@ -165,22 +184,8 @@ public class ServiceDialog extends JDialog implements ActionListener {
isAWT = true;
}
- if (attributes.get(DialogOwner.class) != null) {
- DialogOwner owner = (DialogOwner)attributes.get(DialogOwner.class);
- /* When the ServiceDialog is constructed the caller of the
- * constructor checks for this attribute and if it specifies a
- * window then it will use that in the constructor instead of
- * inferring one from keyboard focus.
- * In this case the owner of the dialog is the same as that
- * specified in the attribute and we do not need to set the
- * on top property
- */
- if ((getOwner() == null) || (owner.getOwner() != getOwner())) {
- try {
- setAlwaysOnTop(true);
- } catch (SecurityException e) {
- }
- }
+ if (attributes.get(DialogOnTop.class) != null) {
+ setAlwaysOnTop(true);
}
Container c = getContentPane();
c.setLayout(new BorderLayout());
@@ -239,12 +244,27 @@ public class ServiceDialog extends JDialog implements ActionListener {
PrintService ps,
DocFlavor flavor,
PrintRequestAttributeSet attributes,
- Window window)
+ Dialog dialog)
{
- super(window, getMsg("dialog.pstitle"), Dialog.DEFAULT_MODALITY_TYPE, gc);
+ super(dialog, getMsg("dialog.pstitle"), true, gc);
initPageDialog(x, y, ps, flavor, attributes);
}
+ /**
+ * Constructor for the solitary "page setup" dialog
+ */
+ public ServiceDialog(GraphicsConfiguration gc,
+ int x, int y,
+ PrintService ps,
+ DocFlavor flavor,
+ PrintRequestAttributeSet attributes,
+ Frame frame)
+ {
+ super(frame, getMsg("dialog.pstitle"), true, gc);
+ initPageDialog(x, y, ps, flavor, attributes);
+ }
+
+
/**
* Initialize "page setup" dialog
*/
@@ -258,15 +278,8 @@ public class ServiceDialog extends JDialog implements ActionListener {
this.asOriginal = attributes;
this.asCurrent = new HashPrintRequestAttributeSet(attributes);
- if (attributes.get(DialogOwner.class) != null) {
- /* See comments in same block in initPrintDialog */
- DialogOwner owner = (DialogOwner)attributes.get(DialogOwner.class);
- if ((getOwner() == null) || (owner.getOwner() != getOwner())) {
- try {
- setAlwaysOnTop(true);
- } catch (SecurityException e) {
- }
- }
+ if (attributes.get(DialogOnTop.class) != null) {
+ setAlwaysOnTop(true);
}
Container c = getContentPane();
diff --git a/src/java.desktop/unix/classes/sun/print/IPPPrintService.java b/src/java.desktop/unix/classes/sun/print/IPPPrintService.java
index b3c54bc9264..aeb95e5fa8f 100644
--- a/src/java.desktop/unix/classes/sun/print/IPPPrintService.java
+++ b/src/java.desktop/unix/classes/sun/print/IPPPrintService.java
@@ -25,8 +25,6 @@
package sun.print;
-import java.awt.GraphicsEnvironment;
-import java.awt.Toolkit;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.DocFlavor;
@@ -1073,11 +1071,6 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
catList.add(PrinterResolution.class);
}
- if (GraphicsEnvironment.isHeadless() == false) {
- catList.add(DialogOwner.class);
- catList.add(DialogTypeSelection.class);
- }
-
supportedCats = new Class>[catList.size()];
catList.toArray(supportedCats);
Class>[] copyCats = new Class>[supportedCats.length];
@@ -1399,38 +1392,10 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
}
}
return false;
- } else if (attr.getCategory() == PrinterResolution.class) {
+ } if (attr.getCategory() == PrinterResolution.class) {
if (attr instanceof PrinterResolution) {
return isSupportedResolution((PrinterResolution)attr);
}
- } else if (attr.getCategory() == DialogOwner.class) {
- DialogOwner owner = (DialogOwner)attr;
- // ID not supported on any dialog type on Unix platforms.
- if (DialogOwnerAccessor.getID(owner) != 0) {
- return false;
- }
- // On Mac we have no control over the native dialog.
- DialogTypeSelection dst = (attributes == null) ? null :
- (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
- if (PrintServiceLookupProvider.isMac() &&
- dst == DialogTypeSelection.NATIVE) {
- return false;
- }
- // The other case is always a Swing dialog on all Unix platforms.
- // So we only need to check that the toolkit supports
- // always on top.
- if (owner.getOwner() != null) {
- return true;
- } else {
- return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
- }
- } else if (attr.getCategory() == DialogTypeSelection.class) {
- if (PrintServiceLookupProvider.isMac()) {
- return true;
- } else {
- DialogTypeSelection dst = (DialogTypeSelection)attr;
- return attr == DialogTypeSelection.COMMON;
- }
}
return true;
}
diff --git a/src/java.desktop/unix/classes/sun/print/UnixPrintService.java b/src/java.desktop/unix/classes/sun/print/UnixPrintService.java
index 0abc76d2677..c02a57cdc3e 100644
--- a/src/java.desktop/unix/classes/sun/print/UnixPrintService.java
+++ b/src/java.desktop/unix/classes/sun/print/UnixPrintService.java
@@ -31,8 +31,6 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Locale;
-import java.awt.GraphicsEnvironment;
-import java.awt.Toolkit;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
@@ -56,8 +54,6 @@ import javax.print.attribute.standard.ColorSupported;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.CopiesSupported;
import javax.print.attribute.standard.Destination;
-import javax.print.attribute.standard.DialogOwner;
-import javax.print.attribute.standard.DialogTypeSelection;
import javax.print.attribute.standard.Fidelity;
import javax.print.attribute.standard.Media;
import javax.print.attribute.standard.MediaPrintableArea;
@@ -623,15 +619,10 @@ public class UnixPrintService implements PrintService, AttributeUpdater,
}
public Class>[] getSupportedAttributeCategories() {
- ArrayList