18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.print;
27
28 import java.awt.Dialog;
29 import java.awt.Frame;
30 import java.awt.GraphicsConfiguration;
31 import java.awt.GraphicsEnvironment;
32 import java.awt.HeadlessException;
33 import java.awt.Rectangle;
34 import java.awt.Window;
35
36 import javax.print.attribute.Attribute;
37 import javax.print.attribute.AttributeSet;
38 import javax.print.attribute.PrintRequestAttributeSet;
39 import javax.print.attribute.standard.Destination;
40 import javax.print.attribute.standard.Fidelity;
41
42 import sun.print.DialogOwner;
43 import sun.print.ServiceDialog;
44 import sun.print.SunAlternateMedia;
45
46 /**
47 * This class is a collection of UI convenience methods which provide a
48 * graphical user dialog for browsing print services looked up through the Java
49 * Print Service API.
50 * <p>
51 * The dialogs follow a standard pattern of acting as a continue/cancel option
52 * for a user as well as allowing the user to select the print service to use
53 * and specify choices such as paper size and number of copies.
54 * <p>
55 * The dialogs are designed to work with pluggable print services though the
56 * public APIs of those print services.
57 * <p>
58 * If a print service provides any vendor extensions these may be made
59 * accessible to the user through a vendor supplied tab panel {@code Component}.
60 * Such a vendor extension is encouraged to use Swing! and to support its
61 * accessibility APIs. The vendor extensions should return the settings as part
62 * of the {@code AttributeSet}. Applications which want to preserve the user
168 }
169
170 if (defaultService != null) {
171 for (int i = 0; i < services.length; i++) {
172 if (services[i].equals(defaultService)) {
173 defaultIndex = i;
174 break;
175 }
176 }
177
178 if (defaultIndex < 0) {
179 throw new IllegalArgumentException("services must contain " +
180 "defaultService");
181 }
182 } else {
183 defaultIndex = 0;
184 }
185
186 DialogOwner dlgOwner = (DialogOwner)attributes.get(DialogOwner.class);
187 Window owner = (dlgOwner != null) ? dlgOwner.getOwner() : null;
188
189 Rectangle gcBounds = (gc == null) ? GraphicsEnvironment.
190 getLocalGraphicsEnvironment().getDefaultScreenDevice().
191 getDefaultConfiguration().getBounds() : gc.getBounds();
192
193 x += gcBounds.x;
194 y += gcBounds.y;
195 ServiceDialog dialog;
196 if (owner instanceof Frame) {
197 dialog = new ServiceDialog(gc,
198 x,
199 y,
200 services, defaultIndex,
201 flavor, attributes,
202 (Frame)owner);
203 } else {
204 dialog = new ServiceDialog(gc,
205 x,
206 y,
207 services, defaultIndex,
208 flavor, attributes,
209 (Dialog)owner);
210 }
211 Rectangle dlgBounds = dialog.getBounds();
212
213 // if portion of dialog is not within the gc boundary
214 if (!gcBounds.contains(dlgBounds)) {
215 // check if dialog exceed window bounds at left or bottom
216 // Then position the dialog by moving it by the amount it exceeds
217 // the window bounds
218 // If it results in dialog moving beyond the window bounds at
219 // top/left then position it at window top/left
220 if (dlgBounds.x + dlgBounds.width > gcBounds.x + gcBounds.width) {
221 if ((gcBounds.x + gcBounds.width - dlgBounds.width) > gcBounds.x) {
222 x = (gcBounds.x + gcBounds.width) - dlgBounds.width;
223 } else {
224 x = gcBounds.x;
225 }
226 }
227 if (dlgBounds.y + dlgBounds.height > gcBounds.y + gcBounds.height) {
228 if ((gcBounds.y + gcBounds.height - dlgBounds.height) > gcBounds.y) {
229 y = (gcBounds.y + gcBounds.height) - dlgBounds.height;
|
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.print;
27
28 import java.awt.Dialog;
29 import java.awt.Frame;
30 import java.awt.GraphicsConfiguration;
31 import java.awt.GraphicsEnvironment;
32 import java.awt.HeadlessException;
33 import java.awt.Rectangle;
34 import java.awt.Window;
35
36 import javax.print.attribute.Attribute;
37 import javax.print.attribute.AttributeSet;
38 import javax.print.attribute.standard.DialogOwner;
39 import javax.print.attribute.PrintRequestAttributeSet;
40 import javax.print.attribute.standard.Destination;
41 import javax.print.attribute.standard.Fidelity;
42
43 import sun.print.ServiceDialog;
44 import sun.print.SunAlternateMedia;
45
46 /**
47 * This class is a collection of UI convenience methods which provide a
48 * graphical user dialog for browsing print services looked up through the Java
49 * Print Service API.
50 * <p>
51 * The dialogs follow a standard pattern of acting as a continue/cancel option
52 * for a user as well as allowing the user to select the print service to use
53 * and specify choices such as paper size and number of copies.
54 * <p>
55 * The dialogs are designed to work with pluggable print services though the
56 * public APIs of those print services.
57 * <p>
58 * If a print service provides any vendor extensions these may be made
59 * accessible to the user through a vendor supplied tab panel {@code Component}.
60 * Such a vendor extension is encouraged to use Swing! and to support its
61 * accessibility APIs. The vendor extensions should return the settings as part
62 * of the {@code AttributeSet}. Applications which want to preserve the user
168 }
169
170 if (defaultService != null) {
171 for (int i = 0; i < services.length; i++) {
172 if (services[i].equals(defaultService)) {
173 defaultIndex = i;
174 break;
175 }
176 }
177
178 if (defaultIndex < 0) {
179 throw new IllegalArgumentException("services must contain " +
180 "defaultService");
181 }
182 } else {
183 defaultIndex = 0;
184 }
185
186 DialogOwner dlgOwner = (DialogOwner)attributes.get(DialogOwner.class);
187 Window owner = (dlgOwner != null) ? dlgOwner.getOwner() : null;
188 boolean setOnTop = (dlgOwner != null) && (owner == null);
189
190 Rectangle gcBounds = (gc == null) ? GraphicsEnvironment.
191 getLocalGraphicsEnvironment().getDefaultScreenDevice().
192 getDefaultConfiguration().getBounds() : gc.getBounds();
193
194 x += gcBounds.x;
195 y += gcBounds.y;
196 ServiceDialog dialog;
197 if (owner instanceof Frame) {
198 dialog = new ServiceDialog(gc,
199 x,
200 y,
201 services, defaultIndex,
202 flavor, attributes,
203 (Frame)owner);
204 } else {
205 dialog = new ServiceDialog(gc,
206 x,
207 y,
208 services, defaultIndex,
209 flavor, attributes,
210 (Dialog)owner);
211 }
212 if (setOnTop) {
213 dialog.setAlwaysOnTop(true);
214 }
215 Rectangle dlgBounds = dialog.getBounds();
216
217 // if portion of dialog is not within the gc boundary
218 if (!gcBounds.contains(dlgBounds)) {
219 // check if dialog exceed window bounds at left or bottom
220 // Then position the dialog by moving it by the amount it exceeds
221 // the window bounds
222 // If it results in dialog moving beyond the window bounds at
223 // top/left then position it at window top/left
224 if (dlgBounds.x + dlgBounds.width > gcBounds.x + gcBounds.width) {
225 if ((gcBounds.x + gcBounds.width - dlgBounds.width) > gcBounds.x) {
226 x = (gcBounds.x + gcBounds.width) - dlgBounds.width;
227 } else {
228 x = gcBounds.x;
229 }
230 }
231 if (dlgBounds.y + dlgBounds.height > gcBounds.y + gcBounds.height) {
232 if ((gcBounds.y + gcBounds.height - dlgBounds.height) > gcBounds.y) {
233 y = (gcBounds.y + gcBounds.height) - dlgBounds.height;
|