*
* A typical basic usage of this method may be :
* <pre>
* PrintService[] services = PrintServiceLookup.lookupPrintServices(
* DocFlavor.INPUT_STREAM.JPEG, null);
* PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
* if (services.length > 0) {
* PrintService service = ServiceUI.printDialog(null, 50, 50,
* services, services[0],
* null,
* attributes);
* if (service != null) {
* ... print ...
* }
* }
* </pre>
* <p>
* @param gc used to select screen. null means primary or default screen.
* @param x location of dialog including border in screen coordinates
* @param y location of dialog including border in screen coordinates
* @param services to be browsable, must be non-null.
* @param defaultService - initial PrintService to display.
* @param flavor - the flavor to be printed, or null.
* @param attributes on input is the initial application supplied
* preferences. This cannot be null but may be empty.
* On output the attributes reflect changes made by the user.
* @return print service selected by the user, or null if the user
* cancelled the dialog.
* @throws HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @throws IllegalArgumentException if services is null or empty,
* or attributes is null, or the initial PrintService is not in the
* list of browsable services.
*/
public static PrintService printDialog(GraphicsConfiguration gc,
int x, int y,
PrintService[] services,
PrintService defaultService,
DocFlavor flavor,
PrintRequestAttributeSet attributes)
throws HeadlessException
{
int defaultIndex = -1;
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
} else if ((services == null) || (services.length == 0)) {
throw new IllegalArgumentException("services must be non-null " +
"and non-empty");
} else if (attributes == null) {
throw new IllegalArgumentException("attributes must be non-null");
}
if (defaultService != null) {
for (int i = 0; i < services.length; i++) {
if (services[i].equals(defaultService)) {
defaultIndex = i;
break;
}
}
if (defaultIndex < 0) {
throw new IllegalArgumentException("services must contain " +
"defaultService");
}
} else {
defaultIndex = 0;
}
// For now we set owner to null. In the future, it may be passed
// as an argument.
Window owner = null;
Rectangle gcBounds = (gc == null) ? GraphicsEnvironment.
getLocalGraphicsEnvironment().getDefaultScreenDevice().
getDefaultConfiguration().getBounds() : gc.getBounds();
ServiceDialog dialog;
if (owner instanceof Frame) {
dialog = new ServiceDialog(gc,
x + gcBounds.x,
y + gcBounds.y,
services, defaultIndex,
flavor, attributes,
(Frame)owner);
} else {
dialog = new ServiceDialog(gc,
x + gcBounds.x,
y + gcBounds.y,
services, defaultIndex,
flavor, attributes,
(Dialog)owner);
}
Rectangle dlgBounds = dialog.getBounds();
// get union of all GC bounds
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
for (int j=0; j<gs.length; j++) {
=2= |