src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java
changeset 53936 03163eb3b2d4
parent 50838 732a3b600098
child 54400 31c35004f300
equal deleted inserted replaced
53935:49b74aa7d2e3 53936:03163eb3b2d4
   401        Hence an alternative mechanism is choosen via the EnumPrinters by polling for the
   401        Hence an alternative mechanism is choosen via the EnumPrinters by polling for the
   402        count of printer status changes(add\remove) and based on it update the printers
   402        count of printer status changes(add\remove) and based on it update the printers
   403        list.
   403        list.
   404     */
   404     */
   405     class RemotePrinterChangeListener implements Runnable {
   405     class RemotePrinterChangeListener implements Runnable {
   406         private String[] prevRemotePrinters;
   406         private String[] prevRemotePrinters = null;
   407 
   407 
   408         RemotePrinterChangeListener() {
   408         RemotePrinterChangeListener() {
   409             prevRemotePrinters = getRemotePrintersNames();
   409             prevRemotePrinters = getRemotePrintersNames();
   410         }
   410         }
   411 
   411 
   412         boolean doCompare(String[] str1, String[] str2) {
   412         boolean doCompare(String[] str1, String[] str2) {
       
   413             if (str1 == null && str2 == null) {
       
   414                 return false;
       
   415             } else if (str1 == null || str2 == null) {
       
   416                 return true;
       
   417             }
       
   418 
   413             if (str1.length != str2.length) {
   419             if (str1.length != str2.length) {
   414                 return true;
   420                 return true;
   415             } else {
   421             } else {
   416                 for (int i = 0;i < str1.length;i++) {
   422                 for (int i = 0;i < str1.length;i++) {
   417                     for (int j = 0;j < str2.length;j++) {
   423                     for (int j = 0;j < str2.length;j++) {
       
   424                         // skip if both are nulls
       
   425                         if (str1[i] == null && str2[j] == null) {
       
   426                             continue;
       
   427                         }
       
   428 
       
   429                         // return true if there is a 'difference' but
       
   430                         // no need to access the individual string
       
   431                         if (str1[i] == null || str2[j] == null) {
       
   432                             return true;
       
   433                         }
       
   434 
       
   435                         // do comparison only if they are non-nulls
   418                         if (!str1[i].equals(str2[j])) {
   436                         if (!str1[i].equals(str2[j])) {
   419                             return true;
   437                             return true;
   420                         }
   438                         }
   421                     }
   439                     }
   422                 }
   440                 }
   426         }
   444         }
   427 
   445 
   428         @Override
   446         @Override
   429         public void run() {
   447         public void run() {
   430             while (true) {
   448             while (true) {
   431                 String[] currentRemotePrinters = getRemotePrintersNames();
   449                 if (prevRemotePrinters != null && prevRemotePrinters.length > 0) {
   432                 if (doCompare(prevRemotePrinters, currentRemotePrinters)) {
   450                     String[] currentRemotePrinters = getRemotePrintersNames();
   433 
   451                     if (doCompare(prevRemotePrinters, currentRemotePrinters)) {
   434                     // updated the printers data
   452 
   435                     // printers list now contains both local and network printer data
   453                         // updated the printers data
   436                     refreshServices();
   454                         // printers list now contains both local and network printer data
   437 
   455                         refreshServices();
   438                     // store the current data for next comparison
   456 
   439                     prevRemotePrinters = currentRemotePrinters;
   457                         // store the current data for next comparison
       
   458                         prevRemotePrinters = currentRemotePrinters;
       
   459                     }
       
   460                 } else {
       
   461                     prevRemotePrinters = getRemotePrintersNames();
   440                 }
   462                 }
   441 
   463 
   442                 try {
   464                 try {
   443                     Thread.sleep(minRefreshTime * 1000);
   465                     Thread.sleep(minRefreshTime * 1000);
   444                 } catch (InterruptedException e) {
   466                 } catch (InterruptedException e) {