remove DocumentPrinter.java from svn
authorgregor herrmann <gregoa@debian.org>
Sun, 17 Jan 2010 13:37:49 +0000 (13:37 -0000)
committergregor herrmann <gregoa@debian.org>
Sun, 17 Jan 2010 13:37:49 +0000 (13:37 -0000)
src/java/net/sf/jabref/util/DocumentPrinter.java [deleted file]

diff --git a/src/java/net/sf/jabref/util/DocumentPrinter.java b/src/java/net/sf/jabref/util/DocumentPrinter.java
deleted file mode 100644 (file)
index 0428ec8..0000000
+++ /dev/null
@@ -1,348 +0,0 @@
-package net.sf.jabref.util;\r
-\r
-import java.awt.Graphics;\r
-import java.awt.Graphics2D;\r
-import java.awt.Rectangle;\r
-import java.awt.Shape;\r
-import java.awt.print.PageFormat;\r
-import java.awt.print.Printable;\r
-import java.awt.print.PrinterException;\r
-import java.awt.print.PrinterJob;\r
-\r
-import javax.swing.JEditorPane;\r
-import javax.swing.text.View;\r
-\r
-/**\r
- * DocumentPrinter prints objects of type Document. Text attributes, including\r
- * fonts, color, and small icons, will be rendered to a printed page.\r
- * DocumentPrinter computes line breaks, paginates, and performs other\r
- * formatting.\r
- * \r
- * An HTMLDocument is printed by sending it as an argument to the\r
- * print(HTMLDocument) method. A PlainDocument is printed the same way. Other\r
- * types of documents must be sent in a JEditorPane as an argument to the\r
- * print(JEditorPane) method. Printing Documents in this way will automatically\r
- * display a print dialog.\r
- * \r
- * As objects which implement the Printable Interface, instances of the\r
- * DocumentPrinter class can also be used as the argument in the setPrintable\r
- * method of the PrinterJob class. Instead of using the print() methods detailed\r
- * above, a programmer may gain access to the formatting capabilities of this\r
- * class without using its print dialog by creating an instance of\r
- * DocumentPrinter and setting the document to be printed with the setDocument()\r
- * or setJEditorPane(). The Document may then be printed by setting the instance\r
- * of DocumentPrinter in any PrinterJob.\r
- * \r
- * This class is based on "How to print HTML from a jEditorPane - faq269-5935"\r
- * \r
- * http://www.tek-tips.com/faqs.cfm?fid=5935\r
- * \r
- * and was originally called DocumentPrinter.\r
- * \r
- * Copyright 2002 Kei G. Gauthier Suite 301 77 Winsor Street Ludlow, MA 01056\r
- * \r
- * Originally attributed by Kei to\r
- * \r
- * http://www.fawcette.com/javapro/2002_12/online/print_kgauthier_12_10_02/default_pf.aspx\r
- * \r
- * @author Christopher Oezbek\r
- * \r
- * I stripped the class of all the boilerplate I could find (protected and\r
- * such).\r
- * \r
- */\r
-public class DocumentPrinter {\r
-\r
-       /**\r
-        * Note that pFormat is not the variable name used by the print method of\r
-        * the DocumentPrintable. Although it would always be expected to reference\r
-        * the pFormat object, the print method gets its PageFormat as an argument.\r
-        */\r
-       PageFormat pFormat;\r
-\r
-       /**\r
-        * Global job used by this DocumentPrinter. Initialized upon calling the\r
-        * constructor.\r
-        */\r
-       PrinterJob pJob;\r
-\r
-       /**\r
-        * The constructor initializes the pFormat and PJob variables.\r
-        * \r
-        * Caution calling PrinterJob.getPrinterJob() is done here which is\r
-        * resource-intensive.\r
-        */\r
-       public DocumentPrinter() {\r
-               pFormat = new PageFormat();\r
-               pJob = PrinterJob.getPrinterJob();\r
-       }\r
-\r
-       /**\r
-        * pageDialog() displays a page setup dialog. Typically this is called by\r
-        * "File -> Print Setup"\r
-        */\r
-       public void pageDialog() {\r
-               pFormat = pJob.pageDialog(pFormat);\r
-       }\r
-\r
-       /**\r
-        * print(JEditorPane) prints a Document contained within a JEditorPane if\r
-        * the user confirms it using the printer dialog shown upon this call.\r
-        * \r
-        * This method is useful when Java does not provide direct access to a\r
-        * particular Document type, such as a Rich Text Format document. With this\r
-        * method such a document can be sent to the DocumentPrinter class enclosed\r
-        * in a JEditorPane.\r
-        * \r
-        * To pass a HTMLDocument call this method with an editorPane that contains\r
-        * the document\r
-        * \r
-        * <pre>\r
-        * JEditorPane pane = new JEditorPane();\r
-        * pane.setContentType(&quot;text/html&quot;);\r
-        * pane.setDocument(htmlDocument);\r
-        * </pre>\r
-        * \r
-        * This method is not thread-safe, if that matters to anybody, since it only\r
-        * uses a single PrinterJob.\r
-        * \r
-        * @param jobName\r
-        *            (may be null) The print-job will get this attribute set, which\r
-        *            for instance is used by the Adobe PDF writer to determine an\r
-        *            initial guess for a filename or which is displayed in the\r
-        *            printer spooler.\r
-        * @param jedPane\r
-        *            The pane which to print. This is done by copying document and\r
-        *            content type. The original jedPane is not modified.\r
-        * @return The method will return false if the user canceled the operation,\r
-        *         true if the pages where send to the printing system successfully\r
-        *         and will throw an PrinterException to show to the user if an\r
-        *         error occurred.\r
-        * \r
-        * @throws PrinterException\r
-        *             Show this exception to the user.\r
-        */\r
-       public boolean print(String jobName, JEditorPane jedPane)\r
-               throws PrinterException {\r
-\r
-               if (!pJob.printDialog())\r
-                       return false;\r
-\r
-               if (jobName != null)\r
-                       pJob.setJobName(jobName);\r
-\r
-               JEditorPane pane = new JEditorPane();\r
-               pane.setContentType(jedPane.getContentType());\r
-               pane.setDocument(jedPane.getDocument());\r
-\r
-               pJob.setPrintable(new DocumentPrintable(pane), pFormat);\r
-\r
-               pJob.print();\r
-\r
-               return true;\r
-       }\r
-\r
-       /**\r
-        * Class that actually does the printing.\r
-        * \r
-        */\r
-       class DocumentPrintable implements Printable {\r
-\r
-               /**\r
-                * boolean to allow control over whether pages too wide to fit on a page\r
-                * will be scaled.\r
-                */\r
-               boolean scaleWidthToFit = true;\r
-\r
-               /**\r
-                * Used to keep track of when the page to print changes.\r
-                */\r
-               int currentPage = -1;\r
-\r
-               /**\r
-                * Location of the current page end.\r
-                */\r
-               double pageEndY = 0;\r
-\r
-               /**\r
-                * Location of the current page start.\r
-                */\r
-               double pageStartY = 0;\r
-\r
-               /**\r
-                * Stores the JEditorPane that is being printed.\r
-                */\r
-               JEditorPane pane;\r
-\r
-               public DocumentPrintable(JEditorPane pane) {\r
-                       this.pane = pane;\r
-               }\r
-\r
-               /**\r
-                * The print method implements the Printable interface. Although\r
-                * Printables may be called to render a page more than once, each page\r
-                * is painted in order. We may, therefore, keep track of changes in the\r
-                * page being rendered by setting the currentPage variable to equal the\r
-                * pageIndex, and then comparing these variables on subsequent calls to\r
-                * this method. When the two variables match, it means that the page is\r
-                * being rendered for the second or third time. When the currentPage\r
-                * differs from the pageIndex, a new page is being requested.\r
-                * \r
-                * The highlights of the process used print a page are as follows:\r
-                * \r
-                * I. The Graphics object is cast to a Graphics2D object to allow for\r
-                * scaling. II. The JEditorPane is laid out using the width of a\r
-                * printable page. This will handle line breaks. If the JEditorPane\r
-                * cannot be sized at the width of the graphics clip, scaling will be\r
-                * allowed. III. The root view of the JEditorPane is obtained. By\r
-                * examining this root view and all of its children, printView will be\r
-                * able to determine the location of each printable element of the\r
-                * document. IV. If the scaleWidthToFit option is chosen, a scaling\r
-                * ratio is determined, and the graphics2D object is scaled. V. The\r
-                * Graphics2D object is clipped to the size of the printable page. VI.\r
-                * currentPage is checked to see if this is a new page to render. If so,\r
-                * pageStartY and pageEndY are reset. VII. To match the coordinates of\r
-                * the printable clip of graphics2D and the allocation rectangle which\r
-                * will be used to lay out the views, graphics2D is translated to begin\r
-                * at the printable X and Y coordinates of the graphics clip. VIII. An\r
-                * allocation Rectangle is created to represent the layout of the Views.\r
-                * \r
-                * The Printable Interface always prints the area indexed by reference\r
-                * to the Graphics object. For instance, with a standard 8.5 x 11 inch\r
-                * page with 1 inch margins the rectangle X = 72, Y = 72, Width = 468,\r
-                * and Height = 648, the area 72, 72, 468, 648 will be painted\r
-                * regardless of which page is actually being printed.\r
-                * \r
-                * To align the allocation Rectangle with the graphics2D object two\r
-                * things are done. The first step is to translate the X and Y\r
-                * coordinates of the graphics2D object to begin at the X and Y\r
-                * coordinates of the printable clip, see step VII. Next, when printing\r
-                * other than the first page, the allocation rectangle must start laying\r
-                * out in coordinates represented by negative numbers. After page one,\r
-                * the beginning of the allocation is started at minus the page end of\r
-                * the prior page. This moves the part which has already been rendered\r
-                * to before the printable clip of the graphics2D object.\r
-                * \r
-                * X. The printView method is called to paint the page. Its return value\r
-                * will indicate if a page has been rendered.\r
-                * \r
-                * Although public, print should not ordinarily be called by programs\r
-                * other than PrinterJob.\r
-                */\r
-               public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {\r
-                       double scale = 1.0;\r
-                       Graphics2D graphics2D;\r
-                       View rootView;\r
-                       // I\r
-                       graphics2D = (Graphics2D) graphics;\r
-                       // II\r
-                       pane.setSize((int) pageFormat.getImageableWidth(),\r
-                               Integer.MAX_VALUE);\r
-                       pane.validate();\r
-                       // III\r
-                       rootView = pane.getUI().getRootView(pane);\r
-                       // IV\r
-                       if ((scaleWidthToFit)\r
-                               && (pane.getMinimumSize().getWidth() > pageFormat\r
-                                       .getImageableWidth())) {\r
-                               scale = pageFormat.getImageableWidth()\r
-                                       / pane.getMinimumSize().getWidth();\r
-                               graphics2D.scale(scale, scale);\r
-                       }\r
-                       // V\r
-                       graphics2D.setClip((int) (pageFormat.getImageableX() / scale),\r
-                               (int) (pageFormat.getImageableY() / scale), (int) (pageFormat\r
-                                       .getImageableWidth() / scale), (int) (pageFormat\r
-                                       .getImageableHeight() / scale));\r
-                       // VI\r
-                       if (pageIndex > currentPage) {\r
-                               currentPage = pageIndex;\r
-                               pageStartY += pageEndY;\r
-                               pageEndY = graphics2D.getClipBounds().getHeight();\r
-                       }\r
-                       // VII\r
-                       graphics2D.translate(graphics2D.getClipBounds().getX(), graphics2D\r
-                               .getClipBounds().getY());\r
-                       // VIII\r
-                       Rectangle allocation = new Rectangle(0, (int) -pageStartY,\r
-                               (int) (pane.getMinimumSize().getWidth()), (int) (pane\r
-                                       .getPreferredSize().getHeight()));\r
-                       // X\r
-                       if (printView(graphics2D, allocation, rootView)) {\r
-                               return Printable.PAGE_EXISTS;\r
-                       } else {\r
-                               pageStartY = 0;\r
-                               pageEndY = 0;\r
-                               currentPage = -1;\r
-                               return Printable.NO_SUCH_PAGE;\r
-                       }\r
-               }\r
-\r
-               /**\r
-                * printView is a recursive method which iterates through the tree\r
-                * structure of the view sent to it. If the view sent to printView is a\r
-                * branch view, that is one with children, the method calls itself on\r
-                * each of these children. If the view is a leaf view, that is a view\r
-                * without children which represents an actual piece of text to be\r
-                * painted, printView attempts to render the view to the Graphics2D\r
-                * object.\r
-                * \r
-                * I. When any view starts after the beginning of the current printable\r
-                * page, this means that there are pages to print and the method sets\r
-                * pageExists to true. II. When a leaf view is taller than the printable\r
-                * area of a page, it cannot, of course, be broken down to fit a single\r
-                * page. Such a View will be printed whenever it intersects with the\r
-                * Graphics2D clip. III. If a leaf view intersects the printable area of\r
-                * the graphics clip and fits vertically within the printable area, it\r
-                * will be rendered. IV. If a leaf view does not exceed the printable\r
-                * area of a page but does not fit vertically within the Graphics2D clip\r
-                * of the current page, the method records that this page should end at\r
-                * the start of the view. This information is stored in pageEndY.\r
-                */\r
-               boolean printView(Graphics2D graphics2D, Shape allocation, View view) {\r
-                       boolean pageExists = false;\r
-                       Rectangle clipRectangle = graphics2D.getClipBounds();\r
-                       Shape childAllocation;\r
-                       View childView;\r
-\r
-                       if (view.getViewCount() > 0\r
-                               && !view.getElement().getName().equalsIgnoreCase("td")) {\r
-                               for (int i = 0; i < view.getViewCount(); i++) {\r
-                                       childAllocation = view.getChildAllocation(i, allocation);\r
-                                       if (childAllocation != null) {\r
-                                               childView = view.getView(i);\r
-                                               if (printView(graphics2D, childAllocation, childView)) {\r
-                                                       pageExists = true;\r
-                                               }\r
-                                       }\r
-                               }\r
-                       } else {\r
-                               // I\r
-                               if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {\r
-                                       pageExists = true;\r
-                                       // II\r
-                                       if ((allocation.getBounds().getHeight() > clipRectangle\r
-                                               .getHeight())\r
-                                               && (allocation.intersects(clipRectangle))) {\r
-                                               view.paint(graphics2D, allocation);\r
-                                       } else {\r
-                                               // III\r
-                                               if (allocation.getBounds().getY() >= clipRectangle\r
-                                                       .getY()) {\r
-                                                       if (allocation.getBounds().getMaxY() <= clipRectangle\r
-                                                               .getMaxY()) {\r
-                                                               view.paint(graphics2D, allocation);\r
-                                                       } else {\r
-                                                               // IV\r
-                                                               if (allocation.getBounds().getY() < pageEndY) {\r
-                                                                       pageEndY = allocation.getBounds().getY();\r
-                                                               }\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-                       return pageExists;\r
-               }\r
-       }\r
-}
\ No newline at end of file