8204496: backout fix for 8203796 which was pushed under another ID
Reviewed-by: serb
This commit is contained in:
parent
24dd5debd4
commit
f6245c499f
@ -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();
|
||||
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* For class {@code DialogOwner}, the category name is
|
||||
* {@code "dialog-owner"}.
|
||||
*
|
||||
*/
|
||||
public final String getName() {
|
||||
return "dialog-owner";
|
||||
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
103
src/java.desktop/share/classes/sun/print/DialogOwner.java
Normal file
103
src/java.desktop/share/classes/sun/print/DialogOwner.java
Normal file
@ -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.
|
||||
*
|
||||
* <P>
|
||||
* <B>IPP Compatibility:</B> This is not an IPP attribute.
|
||||
* <P>
|
||||
*
|
||||
*/
|
||||
@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.
|
||||
* <P>
|
||||
* 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.
|
||||
* <P>
|
||||
* For class DialogOwner the category name is
|
||||
* {@code "dialog-owner"}.
|
||||
*
|
||||
* @return Attribute category name.
|
||||
*/
|
||||
public String getName() {
|
||||
return "dialog-owner";
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<Class<?>> categList = new ArrayList<>(otherAttrCats.length);
|
||||
for (Class<?> c : otherAttrCats) {
|
||||
categList.add(c);
|
||||
}
|
||||
if (GraphicsEnvironment.isHeadless() == false) {
|
||||
categList.add(DialogOwner.class);
|
||||
categList.add(DialogTypeSelection.class);
|
||||
}
|
||||
return categList.toArray(new Class<?>[categList.size()]);
|
||||
int totalCats = otherAttrCats.length;
|
||||
Class<?>[] cats = new Class<?>[totalCats];
|
||||
System.arraycopy(otherAttrCats, 0, cats, 0, otherAttrCats.length);
|
||||
return cats;
|
||||
}
|
||||
|
||||
public boolean
|
||||
@ -1032,24 +1023,6 @@ public class UnixPrintService implements PrintService, AttributeUpdater,
|
||||
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
|
||||
return false;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
// UnixPrintService is not used on Mac, so this is
|
||||
// always some Unix system that does not have CUPS/IPP
|
||||
// Which means we always use a Swing dialog and we need
|
||||
// only check if alwaysOnTop is supported by the toolkit.
|
||||
if (owner.getOwner() != null) {
|
||||
return true;
|
||||
} else {
|
||||
return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
|
||||
}
|
||||
} else if (attr.getCategory() == DialogTypeSelection.class) {
|
||||
DialogTypeSelection dts = (DialogTypeSelection)attr;
|
||||
return dts == DialogTypeSelection.COMMON;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -79,7 +79,6 @@ import javax.print.attribute.standard.PrinterResolution;
|
||||
import javax.print.attribute.standard.SheetCollate;
|
||||
import javax.print.attribute.standard.Copies;
|
||||
import javax.print.attribute.standard.Destination;
|
||||
import javax.print.attribute.standard.DialogOwner;
|
||||
import javax.print.attribute.standard.OrientationRequested;
|
||||
import javax.print.attribute.standard.Media;
|
||||
import javax.print.attribute.standard.MediaSizeName;
|
||||
@ -96,6 +95,7 @@ import sun.print.Win32MediaTray;
|
||||
import sun.print.Win32PrintService;
|
||||
import sun.print.PrintServiceLookupProvider;
|
||||
import sun.print.ServiceDialog;
|
||||
import sun.print.DialogOwner;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.io.FilePermission;
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package sun.print;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.awt.print.PrinterJob;
|
||||
import java.io.File;
|
||||
@ -56,8 +54,6 @@ import javax.print.attribute.standard.Chromaticity;
|
||||
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.MediaSizeName;
|
||||
@ -1046,10 +1042,6 @@ public class Win32PrintService implements PrintService, AttributeUpdater,
|
||||
categList.add(PrinterResolution.class);
|
||||
}
|
||||
|
||||
if (GraphicsEnvironment.isHeadless() == false) {
|
||||
categList.add(DialogOwner.class);
|
||||
categList.add(DialogTypeSelection.class);
|
||||
}
|
||||
return categList.toArray(new Class<?>[categList.size()]);
|
||||
}
|
||||
|
||||
@ -1593,23 +1585,6 @@ public class Win32PrintService implements PrintService, AttributeUpdater,
|
||||
(isColorSup && (attr == ColorSupported.NOT_SUPPORTED))) {
|
||||
return false;
|
||||
}
|
||||
} else if (category == DialogTypeSelection.class) {
|
||||
return true; // isHeadless was checked by category support
|
||||
} else if (category == DialogOwner.class) {
|
||||
DialogOwner owner = (DialogOwner)attr;
|
||||
DialogTypeSelection dts = (attributes == null) ? null :
|
||||
(DialogTypeSelection)attributes.get(DialogTypeSelection.class);
|
||||
if (dts == DialogTypeSelection.NATIVE) {
|
||||
return DialogOwnerAccessor.getID(owner) != 0;
|
||||
} else {
|
||||
if (DialogOwnerAccessor.getID(owner) != 0) {
|
||||
return false;
|
||||
} else if (owner.getOwner() != null) {
|
||||
return true;
|
||||
} else {
|
||||
return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,289 +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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
@bug 8203796
|
||||
@run main/manual DialogOwnerTest
|
||||
@summary Test DialogOwner API
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.print.PrinterJob;
|
||||
import javax.print.PrintService;
|
||||
import javax.print.PrintServiceLookup;
|
||||
import javax.print.ServiceUI;
|
||||
import javax.print.attribute.HashPrintRequestAttributeSet;
|
||||
import javax.print.attribute.PrintRequestAttributeSet;
|
||||
import javax.print.attribute.standard.DialogOwner;
|
||||
import javax.print.attribute.standard.DialogTypeSelection;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public class DialogOwnerTest extends JPanel {
|
||||
|
||||
static final int NONE = 0x0;
|
||||
static final int PRINT = 0x1;
|
||||
static final int PAGE = 0x2;
|
||||
static final int SWING2D = 0x4;
|
||||
static final int NATIVE2D = 0x8;
|
||||
static final int SERVICEUI = 0x10;
|
||||
|
||||
static final int ONTOP = 0x20;
|
||||
static final int OWNED = 0x40;
|
||||
|
||||
static PrintService[] services =
|
||||
PrintServiceLookup.lookupPrintServices(null, null);
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (services.length == 0) {
|
||||
System.out.println("No printers, exiting");
|
||||
return;
|
||||
} else {
|
||||
service = PrinterJob.getPrinterJob().getPrintService();
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
createUI();
|
||||
});
|
||||
while (!testFinished) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e){
|
||||
}
|
||||
}
|
||||
if (!testPassed) {
|
||||
throw new RuntimeException("TEST FAILED.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static final String otherText =
|
||||
"This window is used to test on top behaviour\n" +
|
||||
"For tests that are 'Owned' or 'On Top' the dialog\n" +
|
||||
"must always stay above this window. Verify this\n " +
|
||||
"by moving the dialog so that it partially obscures\n" +
|
||||
"this window and then trying to raise this window.";
|
||||
|
||||
static final String instructions =
|
||||
" Instructions\n" +
|
||||
"This tests that a print dialog stays on top of either another\n" +
|
||||
"window, or on top of all windows.\n" +
|
||||
"For Owned tests the window titled 'Owner Window' should always \n" +
|
||||
"stay behind the print dialog.\n" +
|
||||
"For On Top tests all windows should stay behind the owner window.\n" +
|
||||
"This test tracks if you have checked all the scenarios and will\n" +
|
||||
"not allow the test to pass unless you have visited them all.\n";
|
||||
|
||||
static PrintService service;
|
||||
|
||||
public DialogOwnerTest() {
|
||||
super();
|
||||
//setLayout(new GridLayout(24, 1));
|
||||
}
|
||||
|
||||
static boolean isNative(int flags) {
|
||||
return (flags & NATIVE2D) != 0;
|
||||
}
|
||||
|
||||
static boolean isCommon(int flags) {
|
||||
return (flags & SWING2D) != 0;
|
||||
}
|
||||
|
||||
static boolean is2D(int flags) {
|
||||
return (flags & SWING2D|NATIVE2D) != 0;
|
||||
}
|
||||
|
||||
static boolean isPage(int flags) {
|
||||
return (flags & PAGE ) != 0;
|
||||
}
|
||||
|
||||
static JFrame frame;
|
||||
static JFrame other;
|
||||
static JButton pass;
|
||||
static ArrayList<JPanel> panelList = new ArrayList<JPanel>();
|
||||
static volatile boolean testPassed, testFinished;
|
||||
|
||||
int testCount = 0;
|
||||
List<String> testList = new ArrayList<String>();
|
||||
|
||||
static void createUI() {
|
||||
other = new JFrame("Owner Window");
|
||||
JTextArea otherTextArea = new JTextArea(otherText, 10, 40);
|
||||
other.add(otherTextArea);
|
||||
other.pack();
|
||||
other.setVisible(true);
|
||||
other.setLocation(800, 100);
|
||||
|
||||
frame = new JFrame("Test Dialog Owner");
|
||||
frame.pack();
|
||||
JTextArea instructionsPanel = new JTextArea(instructions, 10, 50);
|
||||
instructionsPanel.setEditable(false);
|
||||
frame.add("North", instructionsPanel);
|
||||
DialogOwnerTest test = new DialogOwnerTest();
|
||||
|
||||
test.addTest("Owned Swing Print", OWNED, frame, PRINT|SWING2D);
|
||||
test.addTest("On Top Swing Print", ONTOP, null, PRINT|SWING2D);
|
||||
|
||||
test.addTest("Owned Swing Page", OWNED, frame, PAGE|SWING2D);
|
||||
test.addTest("On Top Swing Page", ONTOP, null, PAGE|SWING2D);
|
||||
|
||||
test.addTest("Owned javax.print", OWNED, frame, PRINT|SERVICEUI);
|
||||
test.addTest("On Top javax.print", OWNED, null, PRINT|SERVICEUI);
|
||||
|
||||
test.addTest("Owned Native Print", OWNED, frame, PRINT|NATIVE2D);
|
||||
test.addTest("On Top Native Print", OWNED, null, PRINT|NATIVE2D);
|
||||
|
||||
test.addTest("Owned Native Page", OWNED, frame, PAGE|NATIVE2D);
|
||||
test.addTest("On Top Native Page", OWNED, null, PAGE|NATIVE2D);
|
||||
|
||||
test.setLayout(new GridLayout(panelList.size()+2, 1));
|
||||
|
||||
pass = new JButton("Pass");
|
||||
pass.setEnabled(false);
|
||||
pass.addActionListener((ActionEvent e) -> {
|
||||
if (test.testList.size() > 0) {
|
||||
return;
|
||||
}
|
||||
frame.dispose();
|
||||
other.dispose();
|
||||
System.out.println("User says test passed.");
|
||||
testPassed = true;
|
||||
testFinished = true;
|
||||
});
|
||||
|
||||
JButton fail = new JButton("Fail");
|
||||
fail.addActionListener((ActionEvent e) -> {
|
||||
frame.dispose();
|
||||
other.dispose();
|
||||
System.out.println("User says test failed.");
|
||||
testPassed = false;
|
||||
testFinished = true;
|
||||
});
|
||||
|
||||
JPanel p = new JPanel();
|
||||
p.add(pass);
|
||||
p.add(fail);
|
||||
test.add(p);
|
||||
|
||||
|
||||
for (JPanel panel : panelList) {
|
||||
test.add(panel);
|
||||
}
|
||||
|
||||
frame.add("Center", test);
|
||||
frame.pack();
|
||||
frame.setLocation(0,0);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
boolean isSupported(PrintRequestAttributeSet aset,
|
||||
int ownerFlags, Window owner, int dlgFlags) {
|
||||
|
||||
boolean supported = true;
|
||||
DialogOwner ownerAttr = null;
|
||||
if (ownerFlags != NONE) {
|
||||
if (ownerFlags == ONTOP) {
|
||||
ownerAttr = new DialogOwner();
|
||||
} else if (ownerFlags == OWNED) {
|
||||
ownerAttr = new DialogOwner(owner);
|
||||
}
|
||||
aset.add(ownerAttr);
|
||||
}
|
||||
if (is2D(dlgFlags)) {
|
||||
DialogTypeSelection dst = null;
|
||||
if (isNative(dlgFlags)) {
|
||||
dst = DialogTypeSelection.NATIVE;
|
||||
} else if (isCommon(dlgFlags)) {
|
||||
dst = DialogTypeSelection.COMMON;
|
||||
}
|
||||
if (dst != null &&
|
||||
!service.isAttributeValueSupported(dst, null, aset)) {
|
||||
//System.out.println("This DialogType not supported");
|
||||
supported = false;
|
||||
}
|
||||
if (dst != null) {
|
||||
aset.add(dst);
|
||||
}
|
||||
if (ownerAttr != null &&
|
||||
!service.isAttributeValueSupported(ownerAttr, null, aset)) {
|
||||
//System.out.println("This DialogOwner not supported");
|
||||
supported = false;
|
||||
}
|
||||
}
|
||||
return supported;
|
||||
}
|
||||
|
||||
void addTest(String title, int ownerFlags, Window owner, int dlgFlags) {
|
||||
|
||||
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
|
||||
if (!isSupported(aset, ownerFlags, owner, dlgFlags)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if we are here then this is supportable and worth testing
|
||||
// and the attribute set is configured.
|
||||
|
||||
String label = title + " Dialog";
|
||||
JButton button = new JButton(label);
|
||||
JCheckBox tested = new JCheckBox("Tested");
|
||||
tested.setEnabled(false);
|
||||
JPanel panel = new JPanel();
|
||||
panel.add(tested);
|
||||
panel.add(button);
|
||||
panelList.add(panel);
|
||||
//add(panel);
|
||||
testList.add(title);
|
||||
if (++testCount != testList.size()) {
|
||||
throw new RuntimeException("Test titles must be unique");
|
||||
}
|
||||
|
||||
button.addActionListener((ActionEvent e) -> {
|
||||
tested.setSelected(true);
|
||||
testList.remove(title);
|
||||
if (testList.isEmpty()) {
|
||||
pass.setEnabled(true);
|
||||
}
|
||||
|
||||
if (is2D(dlgFlags)) {
|
||||
PrinterJob job = PrinterJob.getPrinterJob();
|
||||
if (isPage(dlgFlags)) {
|
||||
job.pageDialog(aset);
|
||||
} else {
|
||||
job.printDialog(aset);
|
||||
}
|
||||
} else {
|
||||
GraphicsConfiguration gc = null;
|
||||
int x = 0, y = 0;
|
||||
ServiceUI.printDialog(gc, x, y, services, services[0], null,aset);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user