You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2021/09/06 15:51:06 UTC

svn commit: r1892990 - in /pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger: PDFDebugger.java ui/PrintDpiMenu.java

Author: tilman
Date: Mon Sep  6 15:51:06 2021
New Revision: 1892990

URL: http://svn.apache.org/viewvc?rev=1892990&view=rev
Log:
PDFBOX-5277: add print dpi menu

Added:
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PrintDpiMenu.java   (with props)
Modified:
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1892990&r1=1892989&r2=1892990&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java (original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java Mon Sep  6 15:51:06 2021
@@ -103,6 +103,7 @@ import org.apache.pdfbox.debugger.ui.OSX
 import org.apache.pdfbox.debugger.ui.PDFTreeCellRenderer;
 import org.apache.pdfbox.debugger.ui.PDFTreeModel;
 import org.apache.pdfbox.debugger.ui.PageEntry;
+import org.apache.pdfbox.debugger.ui.PrintDpiMenu;
 import org.apache.pdfbox.debugger.ui.ReaderBottomPanel;
 import org.apache.pdfbox.debugger.ui.RecentFiles;
 import org.apache.pdfbox.debugger.ui.RenderDestinationMenu;
@@ -120,6 +121,7 @@ import org.apache.pdfbox.pdmodel.font.PD
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 import org.apache.pdfbox.pdmodel.interactive.viewerpreferences.PDViewerPreferences;
+import org.apache.pdfbox.printing.Orientation;
 import org.apache.pdfbox.printing.PDFPageable;
 
 /**
@@ -169,6 +171,7 @@ public class PDFDebugger extends JFrame
     private JMenuItem saveMenuItem;
     private JMenu recentFilesMenu;
     private JMenuItem printMenuItem;
+    private JMenu printDpiMenu;
     private JMenuItem reopenMenuItem;
     
     // edit > find menu
@@ -437,6 +440,10 @@ public class PDFDebugger extends JFrame
         fileMenu.addSeparator();
         fileMenu.add(printMenuItem);
 
+        printDpiMenu = PrintDpiMenu.getInstance().getMenu();
+        printDpiMenu.setEnabled(false);
+        fileMenu.add(printDpiMenu);
+
         if (!IS_MAC_OS)
         {
             JMenuItem exitMenuItem = new JMenuItem("Exit");
@@ -1155,7 +1162,7 @@ public class PDFDebugger extends JFrame
         try
         {
             PrinterJob job = PrinterJob.getPrinterJob();
-            job.setPageable(new PDFPageable(document));
+            job.setPageable(new PDFPageable(document, Orientation.AUTO, false, PrintDpiMenu.getDpiSelection()));
             PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
             PDViewerPreferences vp = document.getDocumentCatalog().getViewerPreferences();
             if (vp != null && vp.getDuplex() != null)
@@ -1303,6 +1310,7 @@ public class PDFDebugger extends JFrame
         };
         document = documentOpener.parse();
         printMenuItem.setEnabled(true);
+        printDpiMenu.setEnabled(true);
         reopenMenuItem.setEnabled(true);
         
         initTree();

Added: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PrintDpiMenu.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PrintDpiMenu.java?rev=1892990&view=auto
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PrintDpiMenu.java (added)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PrintDpiMenu.java Mon Sep  6 15:51:06 2021
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.debugger.ui;
+
+import java.awt.Component;
+import javax.swing.ButtonGroup;
+import javax.swing.JMenu;
+import javax.swing.JRadioButtonMenuItem;
+
+/**
+ * @author Tilman Hausherr
+ *
+ * A singleton class that provides the print dpi menu.
+ */
+public final class PrintDpiMenu extends MenuBase
+{
+    @SuppressWarnings("squid:MaximumInheritanceDepth")
+    private static class PrintDpiMenuItem extends JRadioButtonMenuItem
+    {
+        private final int dpi;
+
+        PrintDpiMenuItem(String text, int dpi)
+        {
+            super(text);
+            this.dpi = dpi;
+        }
+    }
+
+    private static final int[] DPIS = new int[] { 0, 100, 200, 300, 600, 1200 };
+
+    private static PrintDpiMenu instance;
+    private final JMenu menu;
+
+    /**
+     * Constructor.
+     */
+    private PrintDpiMenu()
+    {
+        menu = new JMenu("Print dpi");
+        ButtonGroup bg = new ButtonGroup();
+        for (int dpi : DPIS)
+        {
+            PrintDpiMenuItem printDpiMenuItem = new PrintDpiMenuItem(dpi == 0 ? "auto" : "" + dpi, dpi);
+            bg.add(printDpiMenuItem);
+            menu.add(printDpiMenuItem);
+        }
+        changeDpiSelection(0);
+        setMenu(menu);
+    }
+
+    /**
+     * Provides the DpiMenu instance.
+     *
+     * @return DpiMenu instance.
+     */
+    public static PrintDpiMenu getInstance()
+    {
+        if (instance == null)
+        {
+            instance = new PrintDpiMenu();
+        }
+        return instance;
+    }
+
+    /**
+     * Set the dpi selection.
+     *
+     * @param selection
+     * @throws IllegalArgumentException if the parameter doesn't belong to a dpi menu item.
+     */
+    public void changeDpiSelection(int selection)
+    {
+        for (Component comp : menu.getMenuComponents())
+        {
+            PrintDpiMenuItem menuItem = (PrintDpiMenuItem) comp;
+            if (menuItem.dpi == selection)
+            {
+                menuItem.setSelected(true);
+                return;
+            }
+        }
+        throw new IllegalArgumentException("no dpi menu item found for: " + selection);
+    }
+
+    /**
+     * Tell the current dpi scale.
+     *
+     * @return the current dpi scale.
+     * @throws IllegalStateException if no dpi menu item is selected.
+     */
+    public static int getDpiSelection()
+    {
+        for (Component comp : instance.menu.getMenuComponents())
+        {
+            PrintDpiMenuItem menuItem = (PrintDpiMenuItem) comp;
+            if (menuItem.isSelected())
+            {
+                return menuItem.dpi;
+            }
+        }
+        throw new IllegalStateException("no dpi menu item is selected");
+    }
+}
\ No newline at end of file

Propchange: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PrintDpiMenu.java
------------------------------------------------------------------------------
    svn:eol-style = native