home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.motif;
-
- import java.awt.Dialog;
- import java.awt.Dimension;
- import java.awt.Frame;
- import java.awt.PrintJob;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.PrintStream;
- import java.util.Hashtable;
- import java.util.MissingResourceException;
- import java.util.Properties;
- import java.util.ResourceBundle;
-
- public class PSPrintControl implements PrintControl {
- public static final String DEST_PROP = "awt.print.destination";
- public static final String PRINTER = "printer";
- public static final String FILE = "file";
- public static final String PRINTER_PROP = "awt.print.printer";
- public static final String FILENAME_PROP = "awt.print.fileName";
- public static final String NUMCOPIES_PROP = "awt.print.numCopies";
- public static final String OPTIONS_PROP = "awt.print.options";
- public static final String ORIENT_PROP = "awt.print.orientation";
- public static final String PORTRAIT = "portrait";
- public static final String LANDSCAPE = "landscape";
- public static final String PAPERSIZE_PROP = "awt.print.paperSize";
- public static final String LETTER = "letter";
- public static final String LEGAL = "legal";
- public static final String EXECUTIVE = "executive";
- // $FF: renamed from: A4 java.lang.String
- public static final String field_0 = "a4";
- private static ResourceBundle messageRB;
- private UPrintDialog printDialog;
- private Frame parentFrame;
- private String destStr;
- private String copiesStr;
- private String bannerStr;
- private String orientStr;
- private String paperStr;
- private String printerName;
- private String fileName;
- private String lpOptions;
- private int destType = 0;
- private int orient = 1;
- private int paperSize = 0;
- private int numCopies = 1;
-
- static void initResource() {
- try {
- messageRB = ResourceBundle.getBundle("sun.awt.motif.resources.printcontrol");
- } catch (MissingResourceException var0) {
- throw new Error("Fatal: Resource for PSPrintControl is missing.");
- }
- }
-
- static String getMsg(String var0) {
- if (messageRB == null) {
- initResource();
- }
-
- try {
- return messageRB.getString(var0);
- } catch (MissingResourceException var1) {
- throw new Error("Fatal: Resource for PSPrintControl is broken, There is no " + var0 + " key in resource");
- }
- }
-
- public PSPrintControl(Frame var1) {
- this.printDialog = new UPrintDialog(var1, "Print Dialog");
- this.parentFrame = var1;
- }
-
- public PSPrintJob initJob(String var1, Properties var2, boolean var3) {
- Object var4 = null;
- this.readProps(var2);
- this.printDialog.setDocumentTitle(var1);
- this.printDialog.setNumCopies(this.numCopies);
- this.printDialog.setDestType(this.destType);
- this.printDialog.setDestString(0, this.printerName != null ? this.printerName : "lp");
- this.printDialog.setDestString(1, this.fileName != null ? this.fileName : "");
- this.printDialog.setOptionsString(this.lpOptions != null ? this.lpOptions : "");
- this.printDialog.setBannerString(var1);
- this.printDialog.setOrientation(this.orient);
- this.printDialog.setPaperSize(this.paperSize);
- PSPrintJob var5 = (PSPrintJob)this.printDialog.getPrintJob(this);
- if (var5 != null && var3) {
- this.writeProps(var2);
- }
-
- return var5;
- }
-
- public PrintJob createPrintJob(int var1, String var2, String var3, String var4, int var5, int var6, int var7) {
- Object var8 = null;
- String[] var10 = new String[1];
- String var11 = null;
- this.destType = var1;
- this.bannerStr = var4;
- this.numCopies = var7;
- this.orient = var6;
- switch (var1) {
- case 0:
- this.printerName = var2;
- this.lpOptions = var3;
-
- try {
- var10 = this.printExecCmd(var2, var3, var4, var7);
- SecurityManager.enablePrivilege("UniversalExecAccess");
- Process var9 = Runtime.getRuntime().exec(var10);
- SecurityManager.revertPrivilege();
- var8 = var9.getOutputStream();
- } catch (IOException var18) {
- var11 = getMsg("error_msg.exec_print") + var10;
- }
- break;
- case 1:
- this.fileName = var2;
- File var12 = new File(this.fileName);
- String var13 = "";
-
- try {
- SecurityManager.enablePrivilege("UniversalFileAccess");
- var13 = var12.getCanonicalPath();
- if (var12.exists()) {
- String var14 = getMsg("warning_button.cancel");
- String var15 = getMsg("warning_button.overwrite");
- PrintStatusDialog var16 = new PrintStatusDialog(this.parentFrame, getMsg("warning_dialog.title"), getMsg("warning_msg.file_exists") + this.fileName, var15, var14);
- ((Dialog)var16).show();
- if (var16.getCommand().equals(var14)) {
- return null;
- }
- }
-
- var8 = new FileOutputStream(var12);
- } catch (IOException var17) {
- var11 = getMsg("error_msg.create_file") + var13;
- }
-
- SecurityManager.revertPrivilege();
- break;
- default:
- return null;
- }
-
- if (var11 != null) {
- PrintStatusDialog var21 = new PrintStatusDialog(this.parentFrame, getMsg("error_dialog.title"), var11, getMsg("error_button.ok"));
- ((Dialog)var21).show();
- return null;
- } else {
- Dimension var20;
- switch (var5) {
- case 0:
- default:
- var20 = PSGraphics.Letter;
- break;
- case 1:
- var20 = PSGraphics.Legal;
- break;
- case 2:
- var20 = PSGraphics.Executive;
- break;
- case 3:
- var20 = PSGraphics.A4;
- }
-
- if (var6 == 0) {
- var20 = new Dimension(var20.height, var20.width);
- }
-
- return new PSPrintJob(new PrintStream(new BufferedOutputStream((OutputStream)var8), false), var4, var20, 72);
- }
- }
-
- private void readProps(Properties var1) {
- if (var1 != null) {
- if ((this.destStr = var1.getProperty("awt.print.destination")) != null) {
- this.destType = this.destStr.equals("file") ? 1 : 0;
- }
-
- this.printerName = var1.getProperty("awt.print.printer");
- this.fileName = var1.getProperty("awt.print.fileName");
- this.lpOptions = var1.getProperty("awt.print.options");
- if ((this.orientStr = var1.getProperty("awt.print.orientation")) != null) {
- this.orient = this.orientStr.equals("landscape") ? 0 : 1;
- }
-
- if ((this.paperStr = var1.getProperty("awt.print.paperSize")) != null) {
- if (this.paperStr.equals("letter")) {
- this.paperSize = 0;
- } else if (this.paperStr.equals("legal")) {
- this.paperSize = 1;
- } else if (this.paperStr.equals("executive")) {
- this.paperSize = 2;
- } else if (this.paperStr.equals("a4")) {
- this.paperSize = 3;
- }
- }
-
- if ((this.copiesStr = var1.getProperty("awt.print.numCopies")) != null) {
- Integer var2 = new Integer(this.copiesStr);
- this.numCopies = var2;
- }
-
- }
- }
-
- private void writeProps(Properties var1) {
- if (var1 != null) {
- ((Hashtable)var1).put("awt.print.destination", this.destType == 0 ? "printer" : "file");
- if (this.printerName != null && !this.printerName.equals("") && !this.printerName.equals("lp")) {
- ((Hashtable)var1).put("awt.print.printer", this.printerName);
- }
-
- if (this.fileName != null && !this.fileName.equals("")) {
- ((Hashtable)var1).put("awt.print.fileName", this.fileName);
- }
-
- if (this.lpOptions != null && !this.lpOptions.equals("")) {
- ((Hashtable)var1).put("awt.print.options", this.lpOptions);
- }
-
- ((Hashtable)var1).put("awt.print.orientation", this.orient == 1 ? "portrait" : "landscape");
- switch (this.paperSize) {
- case 0:
- default:
- this.paperStr = "letter";
- break;
- case 1:
- this.paperStr = "legal";
- break;
- case 2:
- this.paperStr = "executive";
- break;
- case 3:
- this.paperStr = "a4";
- }
-
- ((Hashtable)var1).put("awt.print.paperSize", this.paperStr);
- if (this.numCopies > 0) {
- ((Hashtable)var1).put("awt.print.numCopies", (new Integer(this.numCopies)).toString());
- }
-
- }
- }
-
- private String[] printExecCmd(String var1, String var2, String var3, int var4) {
- boolean var5 = true;
- boolean var6 = true;
- boolean var7 = true;
- boolean var8 = true;
- boolean var9 = false;
- int var11 = 1;
- int var12 = 0;
- if (var1 != null && !var1.equals("") && !var1.equals("lp")) {
- var9 |= var5;
- ++var11;
- }
-
- if (var2 != null && !var2.equals("")) {
- var9 |= var6;
- ++var11;
- }
-
- if (var3 != null && !var3.equals("")) {
- var9 |= var7;
- ++var11;
- }
-
- if (var4 > 1) {
- var9 |= var8;
- ++var11;
- }
-
- String[] var10 = new String[var11];
- var10[var12++] = "/usr/bin/lp";
- if (var9 & var5) {
- var10[var12++] = new String("-d" + var1);
- }
-
- if (var9 & var7) {
- var10[var12++] = new String("-t" + var3);
- }
-
- if (var9 & var8) {
- var10[var12++] = new String("-n" + (new Integer(var4)).toString());
- }
-
- if (var9 & var6) {
- var10[var12++] = new String("-o" + var2);
- }
-
- return var10;
- }
- }
-