// {{{ savePrintSpec() method
  private static void savePrintSpec() {
    // String settings = jEdit.getSettingsDirectory();
    // if(settings == null)
    // return;
    String settings = ".jedit"; // $NON-NLS-1$

    String printSpecPath = MiscUtilities.constructPath(settings, "printspec"); // $NON-NLS-1$
    File filePrintSpec = new File(printSpecPath);
    ObjectOutputStream obOut = null;
    try {
      FileOutputStream fileOut = new FileOutputStream(filePrintSpec);
      obOut = new ObjectOutputStream(fileOut);
      obOut.writeObject(format);
      // for backwards compatibility, the color variable is stored also as
      // a property
      Chromaticity cc = (Chromaticity) format.get(Chromaticity.class);
      if (cc != null) {
        jEdit.setBooleanProperty(
            "print.color", //$NON-NLS-1$
            cc.getValue() == Chromaticity.COLOR.getValue());
      }
    } catch (Exception e) {
      new Warning(Resources.get(WarningStrings.FAILED_PRINT_SETTINGS_SAVE), e);
    } finally {
      if (obOut != null) {
        try {
          obOut.close();
        } catch (IOException e) {
          new Warning(Resources.get(WarningStrings.FAILED_OUTSTREAM_CLOSE), e);
        }
      }
    }
  }
  private static PrinterJob getPrintJob(String jobName) {
    job = PrinterJob.getPrinterJob();

    format = new HashPrintRequestAttributeSet();

    String settings = ".jedit"; // $NON-NLS-1$
    jEdit.getSettingsDirectory();
    if (settings != null) {
      String printSpecPath = MiscUtilities.constructPath(settings, "printspec"); // $NON-NLS-1$
      File filePrintSpec = new File(printSpecPath);

      if (filePrintSpec.exists()) {
        try {
          FileInputStream fileIn = new FileInputStream(filePrintSpec);
          ObjectInputStream obIn = new ObjectInputStream(fileIn);
          format = (HashPrintRequestAttributeSet) obIn.readObject();
          obIn.close();
        } catch (Exception e) {
          Log.log(Log.ERROR, ModifiedBufferPrinter1_4.class, e);
        }
        // for backwards compatibility, the color variable is stored
        // also as a property
        // disabled, getBooleanProperty seems not to work as
        // expected, probably because we don't have full jEdit here.

        // if(jEdit.getBooleanProperty("print.color"))
        // #trac 636
        Chromaticity cc = (Chromaticity) format.get(Chromaticity.class);
        if (cc != null) {
          jEdit.setBooleanProperty(
              "print.color", //$NON-NLS-1$
              cc.getValue() == Chromaticity.COLOR.getValue());
        } else {
          // default if no value was set before.
          jEdit.setBooleanProperty("print.color", true); // $NON-NLS-1$
        }
        // no need to always keep the same job label for every printout.
        format.add(new JobName(jobName, null));
      }
    }

    return job;
  } // }}}
Example #3
0
  // {{{ savePrintSpec() method
  private static void savePrintSpec() {
    String settings = jEdit.getSettingsDirectory();
    if (settings == null) return;

    String printSpecPath = MiscUtilities.constructPath(settings, "printspec");
    File filePrintSpec = new File(printSpecPath);

    try {
      FileOutputStream fileOut = new FileOutputStream(filePrintSpec);
      ObjectOutputStream obOut = new ObjectOutputStream(fileOut);
      obOut.writeObject(format);
      // for backwards compatibility, the color variable is stored also as a property
      Chromaticity cc = (Chromaticity) format.get(Chromaticity.class);
      if (cc != null)
        jEdit.setBooleanProperty("print.color", cc.getValue() == Chromaticity.COLOR.getValue());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }