PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/print/BufferPrinter1_3.java

#
Java | 113 lines | 67 code | 15 blank | 31 comment | 5 complexity | 0acc45e943564843ffb50ad67c82b1d4 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * BufferPrinter1_3.java - Main class that controls printing
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2001 Slava Pestov
  7. * Portions copyright (C) 2002 Thomas Dilts
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. package org.gjt.sp.jedit.print;
  24. //{{{ Imports
  25. import java.awt.print.*;
  26. import java.awt.*;
  27. import org.gjt.sp.jedit.*;
  28. //}}}
  29. public class BufferPrinter1_3
  30. {
  31. //{{{ getPrintJob() method
  32. private static PrinterJob getPrintJob()
  33. {
  34. job = PrinterJob.getPrinterJob();
  35. int orientation = jEdit.getIntegerProperty("print.orientation",PageFormat.PORTRAIT);
  36. double width = jEdit.getDoubleProperty("print.width",0);
  37. double height = jEdit.getDoubleProperty("print.height",0);
  38. double x = jEdit.getDoubleProperty("print.x",0);
  39. double y = jEdit.getDoubleProperty("print.y",0);
  40. double pagewidth = jEdit.getDoubleProperty("print.pagewidth",0);
  41. double pageheight = jEdit.getDoubleProperty("print.pageheight",0);
  42. format = job.defaultPage();
  43. //format.setOrientation(PageFormat.PORTRAIT);
  44. if(width!=0 && height!=0 )
  45. {
  46. Paper pap = format.getPaper();
  47. pap.setImageableArea(x,y,width,height);
  48. pap.setSize(pagewidth,pageheight);
  49. format.setPaper(pap);
  50. }
  51. format.setOrientation(orientation);
  52. return job;
  53. }//}}}
  54. //{{{ pageSetup() method
  55. public static void pageSetup(View view)
  56. {
  57. job = getPrintJob();
  58. PageFormat newFormat = job.pageDialog(format);
  59. if(newFormat != null)
  60. {
  61. format = newFormat;
  62. jEdit.setIntegerProperty("print.orientation",format.getOrientation());
  63. Paper paper=format.getPaper();
  64. jEdit.setDoubleProperty("print.width",paper.getImageableWidth());
  65. jEdit.setDoubleProperty("print.height",paper.getImageableHeight());
  66. jEdit.setDoubleProperty("print.x",paper.getImageableX());
  67. jEdit.setDoubleProperty("print.y",paper.getImageableY());
  68. jEdit.setDoubleProperty("print.pagewidth",paper.getWidth());
  69. jEdit.setDoubleProperty("print.pageheight",paper.getHeight());
  70. }
  71. } //}}}
  72. //{{{ print() method
  73. public static void print(final View view, final Buffer buffer, boolean selection)
  74. {
  75. job = getPrintJob();
  76. job.setJobName(buffer.getPath());
  77. boolean header = jEdit.getBooleanProperty("print.header");
  78. boolean footer = jEdit.getBooleanProperty("print.footer");
  79. boolean lineNumbers = jEdit.getBooleanProperty("print.lineNumbers");
  80. boolean color = jEdit.getBooleanProperty("print.color");
  81. Font font = jEdit.getFontProperty("print.font");
  82. BufferPrintable printable = new BufferPrintable(job,null,view,
  83. buffer,font,header,footer,lineNumbers,color);
  84. job.setPrintable(printable,format);
  85. if(!job.printDialog())
  86. return;
  87. printable.print();
  88. } //}}}
  89. //{{{ getPageFormat() method
  90. public static PageFormat getPageFormat()
  91. {
  92. return format;
  93. } //}}}
  94. //{{{ Private members
  95. private static PageFormat format;
  96. private static PrinterJob job;
  97. //}}}
  98. }