You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2018/03/17 22:00:04 UTC
svn commit: r1827110 - in
/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger:
PDFDebugger.java pagepane/PagePane.java ui/ViewMenu.java
Author: msahyoun
Date: Sat Mar 17 22:00:04 2018
New Revision: 1827110
URL: http://svn.apache.org/viewvc?rev=1827110&view=rev
Log:
PDFBOX-2941: factor out view menu into own class
Added:
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ViewMenu.java (with props)
Modified:
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1827110&r1=1827109&r2=1827110&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java Sat Mar 17 22:00:04 2018
@@ -106,6 +106,7 @@ import org.apache.pdfbox.debugger.ui.Rea
import org.apache.pdfbox.debugger.ui.RecentFiles;
import org.apache.pdfbox.debugger.ui.RotationMenu;
import org.apache.pdfbox.debugger.ui.Tree;
+import org.apache.pdfbox.debugger.ui.ViewMenu;
import org.apache.pdfbox.debugger.ui.ZoomMenu;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
@@ -166,14 +167,6 @@ public class PDFDebugger extends JFrame
private JMenuItem findMenuItem;
private JMenuItem findNextMenuItem;
private JMenuItem findPreviousMenuItem;
-
- // view menu
- private JMenuItem viewModeItem;
- public static JCheckBoxMenuItem showTextStripper;
- public static JCheckBoxMenuItem showTextStripperBeads;
- public static JCheckBoxMenuItem showFontBBox;
- public static JCheckBoxMenuItem showGlyphBounds;
- public static JCheckBoxMenuItem allowSubsampling;
// configuration
public static Properties configuration = new Properties();
@@ -283,6 +276,21 @@ public class PDFDebugger extends JFrame
viewer.setVisible(true);
}
+ public boolean isPageMode()
+ {
+ return this.isPageMode;
+ }
+
+ public void setPageMode(boolean isPageMode)
+ {
+ this.isPageMode = isPageMode;
+ }
+
+ public boolean hasDocument()
+ {
+ return document != null;
+ }
+
/**
* This will print out a message telling how to use this utility.
*/
@@ -390,7 +398,9 @@ public class PDFDebugger extends JFrame
JMenuBar menuBar = new JMenuBar();
menuBar.add(createFileMenu());
menuBar.add(createEditMenu());
- menuBar.add(createViewMenu());
+
+ ViewMenu viewMenu = ViewMenu.getInstance(this);
+ menuBar.add(viewMenu.getMenu());
setJMenuBar(menuBar);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
@@ -598,76 +608,6 @@ public class PDFDebugger extends JFrame
return editMenu;
}
- private JMenu createViewMenu()
- {
- JMenu viewMenu = new JMenu("View");
- viewMenu.setMnemonic('V');
- if (isPageMode)
- {
- viewModeItem = new JMenuItem("Show Internal Structure");
- }
- else
- {
- viewModeItem = new JMenuItem("Show Pages");
- }
- viewModeItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- if (isPageMode)
- {
- viewModeItem.setText("Show Pages");
- isPageMode = false;
- }
- else
- {
- viewModeItem.setText("Show Internal Structure");
- isPageMode = true;
- }
- if (document != null)
- {
- initTree();
- }
- }
- });
- viewMenu.add(viewModeItem);
-
- ZoomMenu zoomMenu = ZoomMenu.getInstance();
- zoomMenu.setEnableMenu(false);
- viewMenu.add(zoomMenu.getMenu());
-
- RotationMenu rotationMenu = RotationMenu.getInstance();
- rotationMenu.setEnableMenu(false);
- viewMenu.add(rotationMenu.getMenu());
-
- viewMenu.addSeparator();
-
- showTextStripper = new JCheckBoxMenuItem("Show TextStripper TextPositions");
- showTextStripper.setEnabled(false);
- viewMenu.add(showTextStripper);
-
- showTextStripperBeads = new JCheckBoxMenuItem("Show TextStripper Beads");
- showTextStripperBeads.setEnabled(false);
- viewMenu.add(showTextStripperBeads);
-
- showFontBBox = new JCheckBoxMenuItem("Show Approximate Text Bounds");
- showFontBBox.setEnabled(false);
- viewMenu.add(showFontBBox);
-
- showGlyphBounds = new JCheckBoxMenuItem("Show Glyph Bounds");
- showGlyphBounds.setEnabled(false);
- viewMenu.add(showGlyphBounds);
-
- viewMenu.addSeparator();
-
- allowSubsampling = new JCheckBoxMenuItem("Allow subsampling");
- allowSubsampling.setEnabled(false);
- viewMenu.add(allowSubsampling);
-
- return viewMenu;
- }
-
private JMenu createFindMenu()
{
findMenu = new JMenu("Find");
@@ -1375,7 +1315,7 @@ public class PDFDebugger extends JFrame
addRecentFileItems();
}
- private void initTree()
+ public void initTree()
{
TreeStatus treeStatus = new TreeStatus(document.getDocument().getTrailer());
statusPane.updateTreeStatus(treeStatus);
Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java?rev=1827110&r1=1827109&r2=1827110&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java Sat Mar 17 22:00:04 2018
@@ -21,6 +21,7 @@ import org.apache.pdfbox.cos.COSDictiona
import org.apache.pdfbox.debugger.PDFDebugger;
import org.apache.pdfbox.debugger.ui.ImageUtil;
import org.apache.pdfbox.debugger.ui.RotationMenu;
+import org.apache.pdfbox.debugger.ui.ViewMenu;
import org.apache.pdfbox.debugger.ui.ZoomMenu;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
@@ -29,6 +30,8 @@ import org.apache.pdfbox.rendering.PDFRe
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
import javax.swing.event.AncestorEvent;
@@ -64,6 +67,7 @@ public class PagePane implements ActionL
private JLabel label;
private ZoomMenu zoomMenu;
private RotationMenu rotationMenu;
+ private ViewMenu viewMenu;
public PagePane(PDDocument document, COSDictionary pageDict, JLabel statuslabel)
{
@@ -120,13 +124,10 @@ public class PagePane implements ActionL
public void actionPerformed(ActionEvent actionEvent)
{
String actionCommand = actionEvent.getActionCommand();
+
if (ZoomMenu.isZoomMenu(actionCommand) ||
RotationMenu.isRotationMenu(actionCommand) ||
- actionEvent.getSource() == PDFDebugger.showTextStripper ||
- actionEvent.getSource() == PDFDebugger.showTextStripperBeads ||
- actionEvent.getSource() == PDFDebugger.showFontBBox ||
- actionEvent.getSource() == PDFDebugger.showGlyphBounds ||
- actionEvent.getSource() == PDFDebugger.allowSubsampling)
+ ViewMenu.isRenderingOptions(actionCommand))
{
startRendering();
}
@@ -138,11 +139,11 @@ public class PagePane implements ActionL
// the fact that PDDocument is not officially thread safe
new RenderWorker(ZoomMenu.getZoomScale(),
RotationMenu.getRotationDegrees(),
- PDFDebugger.showTextStripper.isSelected(),
- PDFDebugger.showTextStripperBeads.isSelected(),
- PDFDebugger.showFontBBox.isSelected(),
- PDFDebugger.showGlyphBounds.isSelected(),
- PDFDebugger.allowSubsampling.isSelected()
+ ViewMenu.isShowTextStripper(),
+ ViewMenu.isShowTextStripperBeads(),
+ ViewMenu.isShowFontBBox(),
+ ViewMenu.isShowGlyphBounds(),
+ ViewMenu.isAllowSubsampling()
).execute();
zoomMenu.setPageZoomScale(ZoomMenu.getZoomScale());
}
@@ -156,39 +157,50 @@ public class PagePane implements ActionL
rotationMenu = RotationMenu.getInstance();
rotationMenu.addMenuListeners(this);
rotationMenu.setEnableMenu(true);
+
+ viewMenu = ViewMenu.getInstance(null);
- PDFDebugger.showTextStripper.setEnabled(true);
- PDFDebugger.showTextStripper.addActionListener(this);
-
- PDFDebugger.showTextStripperBeads.setEnabled(true);
- PDFDebugger.showTextStripperBeads.addActionListener(this);
-
- PDFDebugger.showFontBBox.setEnabled(true);
- PDFDebugger.showFontBBox.addActionListener(this);
-
- PDFDebugger.showGlyphBounds.setEnabled(true);
- PDFDebugger.showGlyphBounds.addActionListener(this);
-
- PDFDebugger.allowSubsampling.setEnabled(true);
- PDFDebugger.allowSubsampling.addActionListener(this);
+ JMenu menuInstance = viewMenu.getMenu();
+ int itemCount = menuInstance.getItemCount();
+
+ for (int i = 0; i< itemCount; i++)
+ {
+ JMenuItem item = menuInstance.getItem(i);
+ if (item != null)
+ {
+ item.setEnabled(true);
+ item.addActionListener(this);
+ }
+ }
}
@Override
public void ancestorRemoved(AncestorEvent ancestorEvent)
{
+ boolean isFirstEntrySkipped = false;
zoomMenu.setEnableMenu(false);
rotationMenu.setEnableMenu(false);
- PDFDebugger.showTextStripper.setEnabled(false);
- PDFDebugger.showTextStripper.removeActionListener(this);
- PDFDebugger.showTextStripperBeads.setEnabled(false);
- PDFDebugger.showTextStripperBeads.removeActionListener(this);
- PDFDebugger.showFontBBox.setEnabled(false);
- PDFDebugger.showFontBBox.removeActionListener(this);
- PDFDebugger.showGlyphBounds.setEnabled(false);
- PDFDebugger.showGlyphBounds.removeActionListener(this);
- PDFDebugger.allowSubsampling.setEnabled(false);
- PDFDebugger.allowSubsampling.removeActionListener(this);
+ JMenu menuInstance = viewMenu.getMenu();
+ int itemCount = menuInstance.getItemCount();
+
+ for (int i = 0; i< itemCount; i++)
+ {
+ JMenuItem item = menuInstance.getItem(i);
+ // skip the first JMenuItem as this shall always be shown
+ if (item != null)
+ {
+ if (!isFirstEntrySkipped)
+ {
+ isFirstEntrySkipped = true;
+ }
+ else
+ {
+ item.setEnabled(false);
+ item.removeActionListener(this);
+ }
+ }
+ }
}
@Override
Added: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ViewMenu.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ViewMenu.java?rev=1827110&view=auto
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ViewMenu.java (added)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ViewMenu.java Sat Mar 17 22:00:04 2018
@@ -0,0 +1,205 @@
+/*
+ * 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.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+import org.apache.pdfbox.debugger.PDFDebugger;
+
+public class ViewMenu extends MenuBase
+{
+ private static ViewMenu instance;
+
+ private static final String SHOW_TEXT_STRIPPER = "Show TextStripper TextPositions";
+ private static final String SHOW_TEXT_STRIPPER_BEADS = "Show TextStripper Beads";
+ private static final String SHOW_FONT_BBOX = "Show Approximate Text Bounds";
+ private static final String SHOW_GLYPH_BOUNDS = "Show Glyph Bounds";
+ private static final String ALLOW_SUBSAMPLING = "Allow subsampling";
+
+ private JMenuItem viewModeItem;
+ private JCheckBoxMenuItem showTextStripper;
+ private JCheckBoxMenuItem showTextStripperBeads;
+ private JCheckBoxMenuItem showFontBBox;
+ private JCheckBoxMenuItem showGlyphBounds;
+ private JCheckBoxMenuItem allowSubsampling;
+
+ private PDFDebugger pdfDebugger;
+
+ /**
+ * Constructor.
+ */
+ private ViewMenu(PDFDebugger pdfDebugger)
+ {
+ this.pdfDebugger = pdfDebugger;
+ setMenu(createViewMenu());
+ }
+
+ /**
+ * Provides the ViewMenu instance.
+ *
+ * @return ViewMenu instance.
+ */
+ public static ViewMenu getInstance(PDFDebugger pdfDebugger)
+ {
+ if (instance == null)
+ {
+ instance = new ViewMenu(pdfDebugger);
+ }
+ return instance;
+ }
+
+ /**
+ * Test if the one of the rendering options has been selected
+ *
+ * @param actionCommand the actioCommand of the menu event
+ * @return true if the actionCommand matches one of the rendering options
+ */
+ public static boolean isRenderingOptions(String actionCommand)
+ {
+ return SHOW_TEXT_STRIPPER.equals(actionCommand) ||
+ SHOW_TEXT_STRIPPER_BEADS.equals(actionCommand) ||
+ SHOW_FONT_BBOX.equals(actionCommand) ||
+ SHOW_GLYPH_BOUNDS.equals(actionCommand) ||
+ ALLOW_SUBSAMPLING.equals(actionCommand);
+ }
+
+ /**
+ * State if the TextStripper TextPositions shall be shown.
+ *
+ * @return the selection state
+ */
+ public static boolean isShowTextStripper()
+ {
+ return instance.showTextStripper.isSelected();
+ }
+
+ /**
+ * State if the article beads shall be shown.
+ *
+ * @return the selection state
+ */
+ public static boolean isShowTextStripperBeads()
+ {
+ return instance.showTextStripperBeads.isSelected();
+ }
+
+ /**
+ * State if the fonts bounding box shall be shown.
+ *
+ * @return the selection state
+ */
+ public static boolean isShowFontBBox()
+ {
+ return instance.showFontBBox.isSelected();
+ }
+
+ /**
+ * State if the bounds of individual glyphs shall be shown.
+ *
+ * @return the selection state
+ */
+ public static boolean isShowGlyphBounds()
+ {
+ return instance.showGlyphBounds.isSelected();
+ }
+
+ /**
+ * State if subsampling for image rendering shall be used.
+ *
+ * @return the selection state
+ */
+ public static boolean isAllowSubsampling()
+ {
+ return instance.allowSubsampling.isSelected();
+ }
+
+ private JMenu createViewMenu()
+ {
+ JMenu viewMenu = new JMenu("View");
+ viewMenu.setMnemonic('V');
+
+ if (pdfDebugger.isPageMode())
+ {
+ viewModeItem = new JMenuItem("Show Internal Structure");
+ }
+ else
+ {
+ viewModeItem = new JMenuItem("Show Pages");
+ }
+ viewModeItem.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ if (pdfDebugger.isPageMode())
+ {
+ viewModeItem.setText("Show Pages");
+ pdfDebugger.setPageMode(false);
+ }
+ else
+ {
+ viewModeItem.setText("Show Internal Structure");
+ pdfDebugger.setPageMode(true);
+ }
+ if (pdfDebugger.hasDocument())
+ {
+ pdfDebugger.initTree();
+ }
+ }
+ });
+ viewMenu.add(viewModeItem);
+
+ ZoomMenu zoomMenu = ZoomMenu.getInstance();
+ zoomMenu.setEnableMenu(false);
+ viewMenu.add(zoomMenu.getMenu());
+
+ RotationMenu rotationMenu = RotationMenu.getInstance();
+ rotationMenu.setEnableMenu(false);
+ viewMenu.add(rotationMenu.getMenu());
+
+ viewMenu.addSeparator();
+
+ showTextStripper = new JCheckBoxMenuItem(SHOW_TEXT_STRIPPER);
+ showTextStripper.setEnabled(false);
+ viewMenu.add(showTextStripper);
+
+ showTextStripperBeads = new JCheckBoxMenuItem(SHOW_TEXT_STRIPPER_BEADS);
+ showTextStripperBeads.setEnabled(false);
+ viewMenu.add(showTextStripperBeads);
+
+ showFontBBox = new JCheckBoxMenuItem(SHOW_FONT_BBOX);
+ showFontBBox.setEnabled(false);
+ viewMenu.add(showFontBBox);
+
+ showGlyphBounds = new JCheckBoxMenuItem(SHOW_GLYPH_BOUNDS);
+ showGlyphBounds.setEnabled(false);
+ viewMenu.add(showGlyphBounds);
+
+ viewMenu.addSeparator();
+
+ allowSubsampling = new JCheckBoxMenuItem(ALLOW_SUBSAMPLING);
+ allowSubsampling.setEnabled(false);
+ viewMenu.add(allowSubsampling);
+
+ return viewMenu;
+ }
+}
Propchange: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ViewMenu.java
------------------------------------------------------------------------------
svn:eol-style = native