1 /*
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
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 sun.print;
27
28 import java.io.File;
29 import java.net.URI;
30 import java.net.URISyntaxException;
31 import java.net.URL;
32
33 import java.util.Vector;
34 import java.util.HashMap;
35
36 import javax.print.DocFlavor;
37 import javax.print.DocPrintJob;
38 import javax.print.PrintService;
39 import javax.print.ServiceUIFactory;
40 import javax.print.attribute.Attribute;
41 import javax.print.attribute.AttributeSet;
42 import javax.print.attribute.AttributeSetUtilities;
43 import javax.print.attribute.EnumSyntax;
44 import javax.print.attribute.HashAttributeSet;
45 import javax.print.attribute.PrintServiceAttribute;
46 import javax.print.attribute.PrintServiceAttributeSet;
47 import javax.print.attribute.HashPrintServiceAttributeSet;
48 import javax.print.attribute.standard.PrinterName;
49 import javax.print.attribute.standard.PrinterIsAcceptingJobs;
50 import javax.print.attribute.standard.QueuedJobCount;
51 import javax.print.attribute.standard.JobName;
52 import javax.print.attribute.standard.RequestingUserName;
53 import javax.print.attribute.standard.Chromaticity;
54 import javax.print.attribute.standard.Copies;
55 import javax.print.attribute.standard.CopiesSupported;
56 import javax.print.attribute.standard.Destination;
57 import javax.print.attribute.standard.Fidelity;
58 import javax.print.attribute.standard.Media;
59 import javax.print.attribute.standard.MediaSizeName;
60 import javax.print.attribute.standard.MediaSize;
61 import javax.print.attribute.standard.MediaTray;
62 import javax.print.attribute.standard.MediaPrintableArea;
63 import javax.print.attribute.standard.OrientationRequested;
64 import javax.print.attribute.standard.PageRanges;
65 import javax.print.attribute.standard.PrinterState;
66 import javax.print.attribute.standard.PrinterStateReason;
67 import javax.print.attribute.standard.PrinterStateReasons;
68 import javax.print.attribute.standard.Severity;
69 import javax.print.attribute.standard.Sides;
70 import javax.print.attribute.standard.ColorSupported;
71 import javax.print.attribute.standard.PrintQuality;
72 import javax.print.attribute.ResolutionSyntax;
73 import javax.print.attribute.standard.PrinterResolution;
74 import javax.print.attribute.standard.SheetCollate;
75 import javax.print.event.PrintServiceAttributeListener;
76 import java.util.ArrayList;
77
78 import sun.print.SunPrinterJobService;
79
80 public class Win32PrintService implements PrintService, AttributeUpdater,
81 SunPrinterJobService {
82
83 public static MediaSize[] predefMedia;
84
85 static {
86 Class c = Win32MediaSize.class;
87 }
88
89 private static final DocFlavor[] supportedFlavors = {
90 DocFlavor.BYTE_ARRAY.GIF,
91 DocFlavor.INPUT_STREAM.GIF,
92 DocFlavor.URL.GIF,
93 DocFlavor.BYTE_ARRAY.JPEG,
94 DocFlavor.INPUT_STREAM.JPEG,
95 DocFlavor.URL.JPEG,
96 DocFlavor.BYTE_ARRAY.PNG,
97 DocFlavor.INPUT_STREAM.PNG,
98 DocFlavor.URL.PNG,
293 public MediaTray findMediaTray(int dmBin) {
294 if (dmBin >= 1 && dmBin <= dmPaperBinToPrintService.length) {
295 return dmPaperBinToPrintService[dmBin-1];
296 }
297 MediaTray[] trays = getMediaTrays();
298 if (trays != null) {
299 for (int i=0;i<trays.length;i++) {
300 if(trays[i] instanceof Win32MediaTray) {
301 Win32MediaTray win32Tray = (Win32MediaTray)trays[i];
302 if (win32Tray.winID == dmBin) {
303 return win32Tray;
304 }
305 }
306 }
307 }
308 return Win32MediaTray.AUTO;
309 }
310
311 public MediaSizeName findWin32Media(int dmIndex) {
312 if (dmIndex >= 1 && dmIndex <= dmPaperToPrintService.length) {
313 switch(dmIndex) {
314 /* matching media sizes with indices beyond
315 dmPaperToPrintService's length */
316 case DMPAPER_A2:
317 return MediaSizeName.ISO_A2;
318 case DMPAPER_A6:
319 return MediaSizeName.ISO_A6;
320 case DMPAPER_B6_JIS:
321 return MediaSizeName.JIS_B6;
322 default:
323 return dmPaperToPrintService[dmIndex - 1];
324 }
325 }
326
327 return null;
328 }
329
330 private boolean addToUniqueList(ArrayList msnList, MediaSizeName mediaName) {
331 MediaSizeName msn;
332 for (int i=0; i< msnList.size(); i++) {
333 msn = (MediaSizeName)msnList.get(i);
334 if (msn == mediaName) {
335 return false;
336 }
337 }
338 msnList.add(mediaName);
339 return true;
340 }
341
342 private synchronized void initMedia() {
343 if (mediaInitialized == true) {
344 return;
345 }
346 mediaInitialized = true;
347 int[] media = getAllMediaIDs(printer, getPort());
348 if (media == null) {
351
352 ArrayList msnList = new ArrayList();
353 ArrayList printableList = new ArrayList();
354 MediaSizeName mediaName;
355 boolean added;
356 boolean queryFailure = false;
357 float[] prnArea;
358
359 // Get all mediaSizes supported by the printer.
360 // We convert media to ArrayList idList and pass this to the
361 // function for getting mediaSizes.
362 // This is to ensure that mediaSizes and media IDs have 1-1 correspondence.
363 // We remove from ID list any invalid mediaSize. Though this is rare,
364 // it happens in HP 4050 German driver.
365
366 idList = new ArrayList();
367 for (int i=0; i < media.length; i++) {
368 idList.add(Integer.valueOf(media[i]));
369 }
370
371 mediaSizes = getMediaSizes(idList, media);
372 for (int i = 0; i < idList.size(); i++) {
373
374 // match Win ID with our predefined ID using table
375 mediaName = findWin32Media(((Integer)idList.get(i)).intValue());
376 // Verify that this standard size is the same size as that
377 // reported by the driver. This should be the case except when
378 // the driver is mis-using a standard windows paper ID.
379 if (mediaName != null &&
380 idList.size() == mediaSizes.length) {
381 MediaSize win32Size = MediaSize.getMediaSizeForName(mediaName);
382 MediaSize driverSize = mediaSizes[i];
383 int error = 2540; // == 1/10"
384 if (Math.abs(win32Size.getX(1)-driverSize.getX(1)) > error ||
385 Math.abs(win32Size.getY(1)-driverSize.getY(1)) > error)
386 {
387 mediaName = null;
388 }
389 }
390
391 // No match found, then we get the MediaSizeName out of the MediaSize
392 // This requires 1-1 correspondence, lengths must be checked.
393 if ((mediaName == null) && (idList.size() == mediaSizes.length)) {
394 mediaName = mediaSizes[i].getMediaSizeName();
395 }
396
397 // Add mediaName to the msnList
398 if (mediaName != null) {
399 added = addToUniqueList(msnList, mediaName);
400 }
401 }
402
403 // init mediaSizeNames
404 mediaSizeNames = new MediaSizeName[msnList.size()];
405 msnList.toArray(mediaSizeNames);
406 }
407
408
409 /*
410 * Gets a list of MediaPrintableAreas using a call to native function.
411 * msn is MediaSizeName used to get a specific printable area. If null,
412 * it will get all the supported MediPrintableAreas.
413 */
414 private synchronized MediaPrintableArea[] getMediaPrintables(MediaSizeName msn)
415 {
416 if (msn == null) {
417 if (mpaListInitialized == true) {
418 return mediaPrintables;
419 }
571 }
572
573 public MediaSizeName findMatchingMediaSizeNameMM (float w, float h){
574 if (predefMedia != null) {
575 for (int k=0; k<predefMedia.length;k++) {
576 if (predefMedia[k] == null) {
577 continue;
578 }
579
580 if (isSameSize(predefMedia[k].getX(MediaSize.MM),
581 predefMedia[k].getY(MediaSize.MM),
582 w, h)) {
583 return predefMedia[k].getMediaSizeName();
584 }
585 }
586 }
587 return null;
588 }
589
590
591 private MediaSize[] getMediaSizes(ArrayList idList, int[] media) {
592 String prnPort = getPort();
593 int[] mediaSz = getAllMediaSizes(printer, prnPort);
594 String[] winMediaNames = getAllMediaNames(printer, prnPort);
595 MediaSizeName msn = null;
596 MediaSize ms = null;
597 float wid, ht;
598
599 if ((mediaSz == null) || (winMediaNames == null)) {
600 return null;
601 }
602
603 int nMedia = mediaSz.length/2;
604 ArrayList msList = new ArrayList();
605
606 for (int i = 0; i < nMedia; i++, ms=null) {
607 wid = mediaSz[i*2]/10f;
608 ht = mediaSz[i*2+1]/10f;
609
610 // Make sure to validate wid & ht.
611 // HP LJ 4050 (german) causes IAE in Sonderformat paper, wid & ht
612 // returned is not constant.
613 if ((wid <= 0) || (ht <= 0)) {
614 //Remove corresponding ID from list
615 if (nMedia == media.length) {
616 Integer remObj = Integer.valueOf(media[i]);
617 idList.remove(idList.indexOf(remObj));
618 }
619 continue;
620 }
621 // Find matching media using dimensions.
622 // This call matches only with our own predefined sizes.
623 msn = findMatchingMediaSizeNameMM(wid, ht);
624 if (msn != null) {
625 ms = MediaSize.getMediaSizeForName(msn);
626 }
627
628 if (ms != null) {
629 msList.add(ms);
630 } else {
631 Win32MediaSize wms =
632 new Win32MediaSize(winMediaNames[i], media[i]);
633 try {
634 ms = new MediaSize(wid, ht, MediaSize.MM, wms);
635 msList.add(ms);
636 } catch(IllegalArgumentException e) {
637 if (nMedia == media.length) {
638 Integer remObj = Integer.valueOf(media[i]);
639 idList.remove(idList.indexOf(remObj));
640 }
641 }
642 }
643
644 }
645
646 MediaSize[] arr2 = new MediaSize[msList.size()];
647 msList.toArray(arr2);
648
649 return arr2;
650 }
651
652
653 private PrinterIsAcceptingJobs getPrinterIsAcceptingJobs() {
654 if (getJobStatus(printer, 2) != 1) {
655 return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;
656 }
657 else {
658 return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
659 }
660 }
661
662 private PrinterState getPrinterState() {
663 if (isInvalid) {
1608 private native int[] getDefaultSettings(String printerName, String port);
1609 private native int getJobStatus(String printerName, int type);
1610 private native String getPrinterPort(String printerName);
1611 }
1612
1613
1614 class Win32MediaSize extends MediaSizeName {
1615 private static ArrayList winStringTable = new ArrayList();
1616 private static ArrayList winEnumTable = new ArrayList();
1617
1618 private int dmPaperID; // driver ID for this paper.
1619
1620 private Win32MediaSize(int x) {
1621 super(x);
1622
1623 }
1624
1625 private synchronized static int nextValue(String name) {
1626 winStringTable.add(name);
1627 return (winStringTable.size()-1);
1628 }
1629
1630 public Win32MediaSize(String name, int dmPaper) {
1631 super(nextValue(name));
1632 dmPaperID = dmPaper;
1633 winEnumTable.add(this);
1634 }
1635
1636 private MediaSizeName[] getSuperEnumTable() {
1637 return (MediaSizeName[])super.getEnumValueTable();
1638 }
1639
1640 static {
1641 /* initialize Win32PrintService.predefMedia */
1642 {
1643 Win32MediaSize winMedia = new Win32MediaSize(-1);
1644
1645 // cannot call getSuperEnumTable directly because of static context
1646 MediaSizeName[] enumMedia = winMedia.getSuperEnumTable();
1647 if (enumMedia != null) {
|
1 /*
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
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 sun.print;
27
28 import java.io.File;
29 import java.net.URI;
30 import java.net.URISyntaxException;
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import javax.print.DocFlavor;
34 import javax.print.DocPrintJob;
35 import javax.print.PrintService;
36 import javax.print.ServiceUIFactory;
37 import javax.print.attribute.Attribute;
38 import javax.print.attribute.AttributeSet;
39 import javax.print.attribute.AttributeSetUtilities;
40 import javax.print.attribute.EnumSyntax;
41 import javax.print.attribute.HashAttributeSet;
42 import javax.print.attribute.PrintServiceAttribute;
43 import javax.print.attribute.PrintServiceAttributeSet;
44 import javax.print.attribute.HashPrintServiceAttributeSet;
45 import javax.print.attribute.standard.PrinterName;
46 import javax.print.attribute.standard.PrinterIsAcceptingJobs;
47 import javax.print.attribute.standard.QueuedJobCount;
48 import javax.print.attribute.standard.JobName;
49 import javax.print.attribute.standard.RequestingUserName;
50 import javax.print.attribute.standard.Chromaticity;
51 import javax.print.attribute.standard.Copies;
52 import javax.print.attribute.standard.CopiesSupported;
53 import javax.print.attribute.standard.Destination;
54 import javax.print.attribute.standard.Fidelity;
55 import javax.print.attribute.standard.Media;
56 import javax.print.attribute.standard.MediaSizeName;
57 import javax.print.attribute.standard.MediaSize;
58 import javax.print.attribute.standard.MediaTray;
59 import javax.print.attribute.standard.MediaPrintableArea;
60 import javax.print.attribute.standard.OrientationRequested;
61 import javax.print.attribute.standard.PageRanges;
62 import javax.print.attribute.standard.PrinterState;
63 import javax.print.attribute.standard.PrinterStateReason;
64 import javax.print.attribute.standard.PrinterStateReasons;
65 import javax.print.attribute.standard.Severity;
66 import javax.print.attribute.standard.Sides;
67 import javax.print.attribute.standard.ColorSupported;
68 import javax.print.attribute.standard.PrintQuality;
69 import javax.print.attribute.standard.PrinterResolution;
70 import javax.print.attribute.standard.SheetCollate;
71 import javax.print.event.PrintServiceAttributeListener;
72
73 public class Win32PrintService implements PrintService, AttributeUpdater,
74 SunPrinterJobService {
75
76 public static MediaSize[] predefMedia;
77
78 static {
79 Class c = Win32MediaSize.class;
80 }
81
82 private static final DocFlavor[] supportedFlavors = {
83 DocFlavor.BYTE_ARRAY.GIF,
84 DocFlavor.INPUT_STREAM.GIF,
85 DocFlavor.URL.GIF,
86 DocFlavor.BYTE_ARRAY.JPEG,
87 DocFlavor.INPUT_STREAM.JPEG,
88 DocFlavor.URL.JPEG,
89 DocFlavor.BYTE_ARRAY.PNG,
90 DocFlavor.INPUT_STREAM.PNG,
91 DocFlavor.URL.PNG,
286 public MediaTray findMediaTray(int dmBin) {
287 if (dmBin >= 1 && dmBin <= dmPaperBinToPrintService.length) {
288 return dmPaperBinToPrintService[dmBin-1];
289 }
290 MediaTray[] trays = getMediaTrays();
291 if (trays != null) {
292 for (int i=0;i<trays.length;i++) {
293 if(trays[i] instanceof Win32MediaTray) {
294 Win32MediaTray win32Tray = (Win32MediaTray)trays[i];
295 if (win32Tray.winID == dmBin) {
296 return win32Tray;
297 }
298 }
299 }
300 }
301 return Win32MediaTray.AUTO;
302 }
303
304 public MediaSizeName findWin32Media(int dmIndex) {
305 if (dmIndex >= 1 && dmIndex <= dmPaperToPrintService.length) {
306 return dmPaperToPrintService[dmIndex - 1];
307 }
308 switch(dmIndex) {
309 /* matching media sizes with indices beyond
310 dmPaperToPrintService's length */
311 case DMPAPER_A2:
312 return MediaSizeName.ISO_A2;
313 case DMPAPER_A6:
314 return MediaSizeName.ISO_A6;
315 case DMPAPER_B6_JIS:
316 return MediaSizeName.JIS_B6;
317 default:
318 return null;
319 }
320 }
321
322 private boolean addToUniqueList(ArrayList msnList, MediaSizeName mediaName) {
323 MediaSizeName msn;
324 for (int i=0; i< msnList.size(); i++) {
325 msn = (MediaSizeName)msnList.get(i);
326 if (msn == mediaName) {
327 return false;
328 }
329 }
330 msnList.add(mediaName);
331 return true;
332 }
333
334 private synchronized void initMedia() {
335 if (mediaInitialized == true) {
336 return;
337 }
338 mediaInitialized = true;
339 int[] media = getAllMediaIDs(printer, getPort());
340 if (media == null) {
343
344 ArrayList msnList = new ArrayList();
345 ArrayList printableList = new ArrayList();
346 MediaSizeName mediaName;
347 boolean added;
348 boolean queryFailure = false;
349 float[] prnArea;
350
351 // Get all mediaSizes supported by the printer.
352 // We convert media to ArrayList idList and pass this to the
353 // function for getting mediaSizes.
354 // This is to ensure that mediaSizes and media IDs have 1-1 correspondence.
355 // We remove from ID list any invalid mediaSize. Though this is rare,
356 // it happens in HP 4050 German driver.
357
358 idList = new ArrayList();
359 for (int i=0; i < media.length; i++) {
360 idList.add(Integer.valueOf(media[i]));
361 }
362
363 ArrayList<String> dmPaperNameList = new ArrayList<String>();
364 mediaSizes = getMediaSizes(idList, media, dmPaperNameList);
365 for (int i = 0; i < idList.size(); i++) {
366
367 // match Win ID with our predefined ID using table
368 mediaName = findWin32Media(((Integer)idList.get(i)).intValue());
369 // Verify that this standard size is the same size as that
370 // reported by the driver. This should be the case except when
371 // the driver is mis-using a standard windows paper ID.
372 if (mediaName != null &&
373 idList.size() == mediaSizes.length) {
374 MediaSize win32Size = MediaSize.getMediaSizeForName(mediaName);
375 MediaSize driverSize = mediaSizes[i];
376 int error = 2540; // == 1/10"
377 if (Math.abs(win32Size.getX(1)-driverSize.getX(1)) > error ||
378 Math.abs(win32Size.getY(1)-driverSize.getY(1)) > error)
379 {
380 mediaName = null;
381 }
382 }
383
384 // No match found, then we get the MediaSizeName out of the MediaSize
385 // This requires 1-1 correspondence, lengths must be checked.
386 if ((mediaName == null) && (idList.size() == mediaSizes.length)) {
387 mediaName = mediaSizes[i].getMediaSizeName();
388 }
389
390 // Add mediaName to the msnList
391 if (mediaName != null) {
392 added = addToUniqueList(msnList, mediaName);
393 /* The following block allows to add such media names to the list, whose sizes
394 * matched with media sizes predefined in JDK, while whose paper IDs did not.
395 */
396 if (!added && (idList.size() == dmPaperNameList.size())) {
397 Win32MediaSize wms = Win32MediaSize.findMediaName(dmPaperNameList.get(i));
398 if ((wms == null) && (idList.size() == mediaSizes.length)) {
399 wms = new Win32MediaSize(dmPaperNameList.get(i), (Integer)idList.get(i));
400 mediaSizes[i] = new MediaSize(mediaSizes[i].getX(MediaSize.MM),
401 mediaSizes[i].getY(MediaSize.MM), MediaSize.MM, wms);
402 }
403 if (wms != null) {
404 mediaName = wms;
405 added = addToUniqueList(msnList, mediaName);
406 }
407 }
408 }
409 }
410
411 // init mediaSizeNames
412 mediaSizeNames = new MediaSizeName[msnList.size()];
413 msnList.toArray(mediaSizeNames);
414 }
415
416
417 /*
418 * Gets a list of MediaPrintableAreas using a call to native function.
419 * msn is MediaSizeName used to get a specific printable area. If null,
420 * it will get all the supported MediPrintableAreas.
421 */
422 private synchronized MediaPrintableArea[] getMediaPrintables(MediaSizeName msn)
423 {
424 if (msn == null) {
425 if (mpaListInitialized == true) {
426 return mediaPrintables;
427 }
579 }
580
581 public MediaSizeName findMatchingMediaSizeNameMM (float w, float h){
582 if (predefMedia != null) {
583 for (int k=0; k<predefMedia.length;k++) {
584 if (predefMedia[k] == null) {
585 continue;
586 }
587
588 if (isSameSize(predefMedia[k].getX(MediaSize.MM),
589 predefMedia[k].getY(MediaSize.MM),
590 w, h)) {
591 return predefMedia[k].getMediaSizeName();
592 }
593 }
594 }
595 return null;
596 }
597
598
599 private MediaSize[] getMediaSizes(ArrayList idList, int[] media, ArrayList<String> dmPaperNameList) {
600 if (dmPaperNameList == null) {
601 dmPaperNameList = new ArrayList<String>();
602 }
603
604 String prnPort = getPort();
605 int[] mediaSz = getAllMediaSizes(printer, prnPort);
606 String[] winMediaNames = getAllMediaNames(printer, prnPort);
607 MediaSizeName msn = null;
608 MediaSize ms = null;
609 float wid, ht;
610
611 if ((mediaSz == null) || (winMediaNames == null)) {
612 return null;
613 }
614
615 int nMedia = mediaSz.length/2;
616 ArrayList msList = new ArrayList();
617
618 for (int i = 0; i < nMedia; i++, ms=null) {
619 wid = mediaSz[i*2]/10f;
620 ht = mediaSz[i*2+1]/10f;
621
622 // Make sure to validate wid & ht.
623 // HP LJ 4050 (german) causes IAE in Sonderformat paper, wid & ht
624 // returned is not constant.
625 if ((wid <= 0) || (ht <= 0)) {
626 //Remove corresponding ID from list
627 if (nMedia == media.length) {
628 Integer remObj = Integer.valueOf(media[i]);
629 idList.remove(idList.indexOf(remObj));
630 }
631 continue;
632 }
633 // Find matching media using dimensions.
634 // This call matches only with our own predefined sizes.
635 msn = findMatchingMediaSizeNameMM(wid, ht);
636 if (msn != null) {
637 ms = MediaSize.getMediaSizeForName(msn);
638 }
639
640 if (ms != null) {
641 msList.add(ms);
642 dmPaperNameList.add(winMediaNames[i]);
643 } else {
644 Win32MediaSize wms = Win32MediaSize.findMediaName(winMediaNames[i]);
645 if (wms == null) {
646 wms = new Win32MediaSize(winMediaNames[i], media[i]);
647 }
648 try {
649 ms = new MediaSize(wid, ht, MediaSize.MM, wms);
650 msList.add(ms);
651 dmPaperNameList.add(winMediaNames[i]);
652 } catch(IllegalArgumentException e) {
653 if (nMedia == media.length) {
654 Integer remObj = Integer.valueOf(media[i]);
655 idList.remove(idList.indexOf(remObj));
656 }
657 }
658 }
659 }
660
661 MediaSize[] arr2 = new MediaSize[msList.size()];
662 msList.toArray(arr2);
663
664 return arr2;
665 }
666
667
668 private PrinterIsAcceptingJobs getPrinterIsAcceptingJobs() {
669 if (getJobStatus(printer, 2) != 1) {
670 return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;
671 }
672 else {
673 return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
674 }
675 }
676
677 private PrinterState getPrinterState() {
678 if (isInvalid) {
1623 private native int[] getDefaultSettings(String printerName, String port);
1624 private native int getJobStatus(String printerName, int type);
1625 private native String getPrinterPort(String printerName);
1626 }
1627
1628
1629 class Win32MediaSize extends MediaSizeName {
1630 private static ArrayList winStringTable = new ArrayList();
1631 private static ArrayList winEnumTable = new ArrayList();
1632
1633 private int dmPaperID; // driver ID for this paper.
1634
1635 private Win32MediaSize(int x) {
1636 super(x);
1637
1638 }
1639
1640 private synchronized static int nextValue(String name) {
1641 winStringTable.add(name);
1642 return (winStringTable.size()-1);
1643 }
1644
1645 public static synchronized Win32MediaSize findMediaName(String name) {
1646 int nameIndex = winStringTable.indexOf(name);
1647 if (nameIndex != -1) {
1648 return (Win32MediaSize)winEnumTable.get(nameIndex);
1649 }
1650 return null;
1651 }
1652
1653 public Win32MediaSize(String name, int dmPaper) {
1654 super(nextValue(name));
1655 dmPaperID = dmPaper;
1656 winEnumTable.add(this);
1657 }
1658
1659 private MediaSizeName[] getSuperEnumTable() {
1660 return (MediaSizeName[])super.getEnumValueTable();
1661 }
1662
1663 static {
1664 /* initialize Win32PrintService.predefMedia */
1665 {
1666 Win32MediaSize winMedia = new Win32MediaSize(-1);
1667
1668 // cannot call getSuperEnumTable directly because of static context
1669 MediaSizeName[] enumMedia = winMedia.getSuperEnumTable();
1670 if (enumMedia != null) {
|