< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/WPrinterJob.java

Print this page




 461                 }
 462             }
 463             // Update attributes, this will preserve the page settings.
 464             //  - same code as in RasterPrinterJob.java
 465             updatePageAttributes(myService, pageClone);
 466 
 467             return pageClone;
 468         } else {
 469             return page;
 470         }
 471     }
 472 
 473 
 474     private boolean displayNativeDialog() {
 475         // "attributes" is required for getting the updated attributes
 476         if (attributes == null) {
 477             return false;
 478         }
 479 
 480         DialogOwner dlgOwner = (DialogOwner)attributes.get(DialogOwner.class);
 481         Frame ownerFrame = (dlgOwner != null) ? dlgOwner.getOwner() : null;
 482 
 483         WPrintDialog dialog = new WPrintDialog(ownerFrame, this);





 484         dialog.setRetVal(false);
 485         dialog.setVisible(true);
 486         boolean prv = dialog.getRetVal();
 487         dialog.dispose();
 488 
 489         Destination dest =
 490                 (Destination)attributes.get(Destination.class);
 491         if ((dest == null) || !prv){
 492                 return prv;
 493         } else {
 494             String title = null;
 495             String strBundle = "sun.print.resources.serviceui";
 496             ResourceBundle rb = ResourceBundle.getBundle(strBundle);
 497             try {
 498                 title = rb.getString("dialog.printtofile");
 499             } catch (MissingResourceException e) {
 500             }
 501             FileDialog fileDialog = new FileDialog(ownerFrame, title,


 502                                                    FileDialog.SAVE);




 503 
 504             URI destURI = dest.getURI();
 505             // Old code destURI.getPath() would return null for "file:out.prn"
 506             // so we use getSchemeSpecificPart instead.
 507             String pathName = (destURI != null) ?
 508                 destURI.getSchemeSpecificPart() : null;
 509             if (pathName != null) {
 510                File file = new File(pathName);
 511                fileDialog.setFile(file.getName());
 512                File parent = file.getParentFile();
 513                if (parent != null) {
 514                    fileDialog.setDirectory(parent.getPath());
 515                }
 516             } else {
 517                 fileDialog.setFile("out.prn");
 518             }
 519 
 520             fileDialog.setVisible(true);
 521             String fileName = fileDialog.getFile();
 522             if (fileName == null) {
 523                 fileDialog.dispose();
 524                 return false;
 525             }
 526             String fullName = fileDialog.getDirectory() + fileName;
 527             File f = new File(fullName);
 528             File pFile = f.getParentFile();
 529             while ((f.exists() &&
 530                       (!f.isFile() || !f.canWrite())) ||
 531                    ((pFile != null) &&
 532                       (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
 533 
 534                 (new PrintToFileErrorDialog(ownerFrame,

 535                                 ServiceDialog.getMsg("dialog.owtitle"),
 536                                 ServiceDialog.getMsg("dialog.writeerror")+" "+fullName,
 537                                 ServiceDialog.getMsg("button.ok"))).setVisible(true);






 538 
 539                 fileDialog.setVisible(true);
 540                 fileName = fileDialog.getFile();
 541                 if (fileName == null) {
 542                     fileDialog.dispose();
 543                     return false;
 544                 }
 545                 fullName = fileDialog.getDirectory() + fileName;
 546                 f = new File(fullName);
 547                 pFile = f.getParentFile();
 548             }
 549             fileDialog.dispose();
 550             attributes.add(new Destination(f.toURI()));
 551             return true;
 552         }
 553 
 554     }
 555 
 556     /**
 557      * Presents the user a dialog for changing properties of the




 461                 }
 462             }
 463             // Update attributes, this will preserve the page settings.
 464             //  - same code as in RasterPrinterJob.java
 465             updatePageAttributes(myService, pageClone);
 466 
 467             return pageClone;
 468         } else {
 469             return page;
 470         }
 471     }
 472 
 473 
 474     private boolean displayNativeDialog() {
 475         // "attributes" is required for getting the updated attributes
 476         if (attributes == null) {
 477             return false;
 478         }
 479 
 480         DialogOwner dlgOwner = (DialogOwner)attributes.get(DialogOwner.class);
 481         Window ownerFrame = (dlgOwner != null) ? dlgOwner.getOwner() : null;
 482 
 483         WPrintDialog dialog;
 484         if (ownerFrame instanceof Frame) {
 485             dialog = new WPrintDialog((Frame)ownerFrame, this);
 486         } else {
 487             dialog = new WPrintDialog((Dialog)ownerFrame, this);
 488         }
 489         dialog.setRetVal(false);
 490         dialog.setVisible(true);
 491         boolean prv = dialog.getRetVal();
 492         dialog.dispose();
 493 
 494         Destination dest =
 495                 (Destination)attributes.get(Destination.class);
 496         if ((dest == null) || !prv){
 497                 return prv;
 498         } else {
 499             String title = null;
 500             String strBundle = "sun.print.resources.serviceui";
 501             ResourceBundle rb = ResourceBundle.getBundle(strBundle);
 502             try {
 503                 title = rb.getString("dialog.printtofile");
 504             } catch (MissingResourceException e) {
 505             }
 506             FileDialog fileDialog;
 507             if (ownerFrame instanceof Frame) {
 508                 fileDialog = new FileDialog((Frame)ownerFrame, title,
 509                                                    FileDialog.SAVE);
 510             } else {
 511                 fileDialog = new FileDialog((Dialog)ownerFrame, title,
 512                                              FileDialog.SAVE);    
 513             }
 514 
 515             URI destURI = dest.getURI();
 516             // Old code destURI.getPath() would return null for "file:out.prn"
 517             // so we use getSchemeSpecificPart instead.
 518             String pathName = (destURI != null) ?
 519                 destURI.getSchemeSpecificPart() : null;
 520             if (pathName != null) {
 521                File file = new File(pathName);
 522                fileDialog.setFile(file.getName());
 523                File parent = file.getParentFile();
 524                if (parent != null) {
 525                    fileDialog.setDirectory(parent.getPath());
 526                }
 527             } else {
 528                 fileDialog.setFile("out.prn");
 529             }
 530 
 531             fileDialog.setVisible(true);
 532             String fileName = fileDialog.getFile();
 533             if (fileName == null) {
 534                 fileDialog.dispose();
 535                 return false;
 536             }
 537             String fullName = fileDialog.getDirectory() + fileName;
 538             File f = new File(fullName);
 539             File pFile = f.getParentFile();
 540             while ((f.exists() &&
 541                       (!f.isFile() || !f.canWrite())) ||
 542                    ((pFile != null) &&
 543                       (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
 544 
 545                 if (ownerFrame instanceof Frame) {
 546                     (new PrintToFileErrorDialog((Frame)ownerFrame,
 547                                 ServiceDialog.getMsg("dialog.owtitle"),
 548                                 ServiceDialog.getMsg("dialog.writeerror")+" "+fullName,
 549                                 ServiceDialog.getMsg("button.ok"))).setVisible(true);
 550                 } else {
 551                     (new PrintToFileErrorDialog((Dialog)ownerFrame,
 552                                 ServiceDialog.getMsg("dialog.owtitle"),
 553                                 ServiceDialog.getMsg("dialog.writeerror")+" "+fullName,
 554                                 ServiceDialog.getMsg("button.ok"))).setVisible(true);
 555                 }
 556 
 557                 fileDialog.setVisible(true);
 558                 fileName = fileDialog.getFile();
 559                 if (fileName == null) {
 560                     fileDialog.dispose();
 561                     return false;
 562                 }
 563                 fullName = fileDialog.getDirectory() + fileName;
 564                 f = new File(fullName);
 565                 pFile = f.getParentFile();
 566             }
 567             fileDialog.dispose();
 568             attributes.add(new Destination(f.toURI()));
 569             return true;
 570         }
 571 
 572     }
 573 
 574     /**
 575      * Presents the user a dialog for changing properties of the


< prev index next >