< prev index next >

src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2019, 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


 339          // Not the same as default so proceed to get new PrintService.
 340 
 341         // clear defaultPrintService
 342         defaultPrintService = null;
 343 
 344         if (printServices != null) {
 345             for (int j=0; j<printServices.length; j++) {
 346                 if (defaultPrinter.equals(printServices[j].getName())) {
 347                     defaultPrintService = printServices[j];
 348                     break;
 349                 }
 350             }
 351         }
 352 
 353         if (defaultPrintService == null) {
 354             defaultPrintService = new Win32PrintService(defaultPrinter);
 355         }
 356         return defaultPrintService;
 357     }
 358 
 359     class PrinterChangeListener implements Runnable {
 360         long chgObj;
 361         PrinterChangeListener() {
 362             chgObj = notifyFirstPrinterChange(null);
 363         }
 364 
 365         @Override
 366         public void run() {
 367             if (chgObj != -1) {
 368                 while (true) {
 369                     // wait for configuration to change
 370                     if (notifyPrinterChange(chgObj) != 0) {
 371                         try {
 372                             refreshServices();
 373                         } catch (SecurityException se) {
 374                             break;
 375                         }
 376                     } else {
 377                         notifyClosePrinterChange(chgObj);
 378                         break;
 379                     }
 380                 }
 381             }
 382         }


 429 
 430                 String[] currentRemotePrinters = getRemotePrintersNames();
 431                 if (currentRemotePrinters != null) {
 432                     Arrays.sort(currentRemotePrinters, this);
 433                 }
 434                 if (!Arrays.equals(prevRemotePrinters, currentRemotePrinters)) {
 435                     // The list of remote printers got updated,
 436                     // so update the cached list printers which
 437                     // includes both local and network printers
 438                     refreshServices();
 439 
 440                     // store the current data for next comparison
 441                     prevRemotePrinters = currentRemotePrinters;
 442                 }
 443             }
 444         }
 445     }
 446 
 447     private native String getDefaultPrinterName();
 448     private native String[] getAllPrinterNames();
 449     private native long notifyFirstPrinterChange(String printer);
 450     private native void notifyClosePrinterChange(long chgObj);
 451     private native int notifyPrinterChange(long chgObj);
 452     private native String[] getRemotePrintersNames();
 453 }
   1 /*
   2  * Copyright (c) 2000, 2020, 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


 339          // Not the same as default so proceed to get new PrintService.
 340 
 341         // clear defaultPrintService
 342         defaultPrintService = null;
 343 
 344         if (printServices != null) {
 345             for (int j=0; j<printServices.length; j++) {
 346                 if (defaultPrinter.equals(printServices[j].getName())) {
 347                     defaultPrintService = printServices[j];
 348                     break;
 349                 }
 350             }
 351         }
 352 
 353         if (defaultPrintService == null) {
 354             defaultPrintService = new Win32PrintService(defaultPrinter);
 355         }
 356         return defaultPrintService;
 357     }
 358 
 359     private final class PrinterChangeListener implements Runnable {
 360         private final long chgObj;
 361         private PrinterChangeListener() {
 362             chgObj = notifyFirstPrinterChange();
 363         }
 364 
 365         @Override
 366         public void run() {
 367             if (chgObj != -1) {
 368                 while (true) {
 369                     // wait for configuration to change
 370                     if (notifyPrinterChange(chgObj) != 0) {
 371                         try {
 372                             refreshServices();
 373                         } catch (SecurityException se) {
 374                             break;
 375                         }
 376                     } else {
 377                         notifyClosePrinterChange(chgObj);
 378                         break;
 379                     }
 380                 }
 381             }
 382         }


 429 
 430                 String[] currentRemotePrinters = getRemotePrintersNames();
 431                 if (currentRemotePrinters != null) {
 432                     Arrays.sort(currentRemotePrinters, this);
 433                 }
 434                 if (!Arrays.equals(prevRemotePrinters, currentRemotePrinters)) {
 435                     // The list of remote printers got updated,
 436                     // so update the cached list printers which
 437                     // includes both local and network printers
 438                     refreshServices();
 439 
 440                     // store the current data for next comparison
 441                     prevRemotePrinters = currentRemotePrinters;
 442                 }
 443             }
 444         }
 445     }
 446 
 447     private native String getDefaultPrinterName();
 448     private native String[] getAllPrinterNames();
 449     private native long notifyFirstPrinterChange();
 450     private native void notifyClosePrinterChange(long chgObj);
 451     private native int notifyPrinterChange(long chgObj);
 452     private native String[] getRemotePrintersNames();
 453 }
< prev index next >