pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1693855 - in /pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools: PDFDebugger.java pdfdebugger/streampane/StreamTextView.java pdfdebugger/ui/textsearcher/SearchPanel.java pdfdebugger/ui/textsearcher/Searcher.java
Date Mon, 03 Aug 2015 04:26:53 GMT
Author: jahewson
Date: Mon Aug  3 04:26:52 2015
New Revision: 1693855

URL: http://svn.apache.org/r1693855
Log:
PDFBOX-2530: Clean up Find menu UI

Modified:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamTextView.java
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/SearchPanel.java
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/Searcher.java

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java?rev=1693855&r1=1693854&r2=1693855&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java Mon Aug  3 04:26:52
2015
@@ -25,6 +25,7 @@ import java.awt.datatransfer.Transferabl
 import java.awt.datatransfer.UnsupportedFlavorException;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.InputEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.WindowEvent;
 import java.io.ByteArrayOutputStream;
@@ -41,6 +42,7 @@ import java.util.Set;
 import javax.swing.AbstractAction;
 import javax.swing.Action;
 import javax.swing.JComponent;
+import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
@@ -90,33 +92,69 @@ import org.apache.pdfbox.tools.util.File
 import org.apache.pdfbox.tools.util.RecentFiles;
 
 /**
- *
+ * PDF Debugger.
+ * 
  * @author wurtz
  * @author Ben Litchfield
  */
-public class PDFDebugger extends javax.swing.JFrame
+public class PDFDebugger extends JFrame
 {
-    private TreeStatusPane statusPane;
-    private RecentFiles recentFiles;
-    private boolean isPageMode;
-
-    private PDDocument document;
-    private String currentFilePath;
-
     private static final Set<COSName> SPECIALCOLORSPACES =
-            new HashSet(Arrays.asList(COSName.INDEXED, COSName.SEPARATION, COSName.DEVICEN));
+            new HashSet<COSName>(Arrays.asList(COSName.INDEXED, COSName.SEPARATION,
COSName.DEVICEN));
 
     private static final Set<COSName> OTHERCOLORSPACES =
-            new HashSet(Arrays.asList(COSName.ICCBASED, COSName.PATTERN, COSName.CALGRAY,
COSName.CALRGB, COSName.LAB));
+            new HashSet<COSName>(Arrays.asList(COSName.ICCBASED, COSName.PATTERN, COSName.CALGRAY,
+                                 COSName.CALRGB, COSName.LAB));
 
     private static final String PASSWORD = "-password";
 
     private static final int SHORCUT_KEY_MASK =
             Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
     
+    private TreeStatusPane statusPane;
+    private RecentFiles recentFiles;
+    private boolean isPageMode;
+
+    private PDDocument document;
+    private String currentFilePath;
+    
     private static final String OS_NAME = System.getProperty("os.name").toLowerCase();
     private static final boolean IS_MAC_OS = OS_NAME.startsWith("mac os x");
     
+    private JScrollPane jScrollPane1;
+    private JScrollPane jScrollPane2;
+    private javax.swing.JSplitPane jSplitPane1;
+    private javax.swing.JTextPane jTextPane1;
+    private Tree tree;
+    private final JPanel documentPanel = new JPanel();
+    private javax.swing.JMenuBar menuBar;
+    
+    // file menu
+    private JMenu fileMenu;
+    private JMenuItem openMenuItem;
+    private JMenuItem openUrlMenuItem;
+    private JMenuItem saveAsMenuItem;
+    private JMenuItem saveMenuItem;
+    private JMenu recentFilesMenu;
+    private JMenuItem exitMenuItem;
+
+    // edit menu
+    private JMenu editMenu;
+    private JMenuItem copyMenuItem;
+    private JMenuItem pasteMenuItem;
+    private JMenuItem cutMenuItem;
+    private JMenuItem deleteMenuItem;
+
+    // edit > find meu
+    private JMenu findMenu;
+    private JMenuItem findMenuItem;
+    private JMenuItem findNextMenuItem;
+    private JMenuItem findPreviousMenuItem;
+
+    // view menu
+    private JMenu viewMenu;
+    private JMenuItem viewModeItem;
+    
     /**
      * Constructor.
      */
@@ -139,26 +177,9 @@ public class PDFDebugger extends javax.s
         jScrollPane2 = new JScrollPane();
         jTextPane1 = new javax.swing.JTextPane();
         menuBar = new javax.swing.JMenuBar();
-        fileMenu = new JMenu();
-        openMenuItem = new JMenuItem();
-        openUrlMenuItem = new JMenuItem();
-        saveMenuItem = new JMenuItem();
-        saveAsMenuItem = new JMenuItem();
-        recentFilesMenu = new JMenu();
-        exitMenuItem = new JMenuItem();
-        editMenu = new JMenu();
-        cutMenuItem = new JMenuItem();
-        copyMenuItem = new JMenuItem();
-        pasteMenuItem = new JMenuItem();
-        deleteMenuItem = new JMenuItem();
-        viewMenu = new JMenu();
-        viewModeItem = new JMenuItem();
-        helpMenu = new JMenu();
-        contentsMenuItem = new JMenuItem();
-        aboutMenuItem = new JMenuItem();
-
-        tree.setCellRenderer( new PDFTreeCellRenderer() );
-        tree.setModel( null );
+        
+        tree.setCellRenderer(new PDFTreeCellRenderer());
+        tree.setModel(null);
 
         setTitle("PDFBox Debugger");
 
@@ -170,7 +191,7 @@ public class PDFDebugger extends javax.s
                 tree.requestFocusInWindow();
                 super.windowOpened(windowEvent);
             }
-            
+
             @Override
             public void windowClosing(WindowEvent evt)
             {
@@ -200,16 +221,82 @@ public class PDFDebugger extends javax.s
         jSplitPane1.setLeftComponent(jScrollPane1);
 
         JScrollPane documentScroller = new JScrollPane();
-        documentScroller.setViewportView( documentPanel );
+        documentScroller.setViewportView(documentPanel);
 
         statusPane = new TreeStatusPane(tree);
         statusPane.getPanel().setBorder(new BevelBorder(BevelBorder.RAISED));
         statusPane.getPanel().setPreferredSize(new Dimension(300, 25));
         getContentPane().add(statusPane.getPanel(), BorderLayout.PAGE_START);
 
-        getContentPane().add( jSplitPane1, BorderLayout.CENTER );
+        getContentPane().add(jSplitPane1, BorderLayout.CENTER);
+
+        // create menus
+        menuBar.add(createFileMenu());
+        menuBar.add(createEditMenu());
+        menuBar.add(createViewMenu());
+        setJMenuBar(menuBar);
+
+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        setBounds((screenSize.width-700)/2, (screenSize.height-600)/2, 700, 600);
 
+        // drag and drop to open files
+        setTransferHandler(new TransferHandler()
+        {
+            @Override
+            public boolean canImport(TransferSupport transferSupport)
+            {
+                return transferSupport.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
+            }
+
+            @Override
+            @SuppressWarnings("unchecked")
+            public boolean importData(TransferSupport transferSupport)
+            {
+                try
+                {
+                    Transferable transferable = transferSupport.getTransferable();
+                    List<File> files = (List<File>) transferable.getTransferData(
+                            DataFlavor.javaFileListFlavor);
+                    readPDFFile(files.get(0), "");
+                    return true;
+                }
+                catch (IOException e)
+                {
+                    throw new RuntimeException(e);
+                }
+                catch (UnsupportedFlavorException e)
+                {
+                    throw new RuntimeException(e);
+                }
+            }
+        });
+
+        // Mac OS X file open/quit handler
+        if (IS_MAC_OS)
+        {
+            try
+            {
+                Method osxOpenFiles = getClass().getDeclaredMethod("osxOpenFiles", String.class);
+                osxOpenFiles.setAccessible(true);
+                OSXAdapter.setFileHandler(this, osxOpenFiles);
+
+                Method osxQuit = getClass().getDeclaredMethod("osxQuit");
+                osxQuit.setAccessible(true);
+                OSXAdapter.setQuitHandler(this, osxQuit);
+            }
+            catch (NoSuchMethodException e)
+            {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+    
+    private JMenu createFileMenu()
+    {
+        fileMenu = new JMenu();
         fileMenu.setText("File");
+        
+        openMenuItem = new JMenuItem();
         openMenuItem.setText("Open...");
         openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORCUT_KEY_MASK));
         openMenuItem.addActionListener(new ActionListener()
@@ -222,7 +309,8 @@ public class PDFDebugger extends javax.s
         });
 
         fileMenu.add(openMenuItem);
-        
+
+        openUrlMenuItem = new JMenuItem();
         openUrlMenuItem.setText("Open URL...");
         openUrlMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, SHORCUT_KEY_MASK));
         openUrlMenuItem.addActionListener(new ActionListener()
@@ -243,10 +331,6 @@ public class PDFDebugger extends javax.s
         });
         fileMenu.add(openUrlMenuItem);
 
-        saveMenuItem.setText("Save");
-
-        saveAsMenuItem.setText("Save As ...");
-
         try
         {
             recentFiles = new RecentFiles(this.getClass(), 5);
@@ -256,11 +340,13 @@ public class PDFDebugger extends javax.s
             throw new RuntimeException(e);
         }
 
+        recentFilesMenu = new JMenu();
         recentFilesMenu.setText("Open Recent");
         recentFilesMenu.setEnabled(false);
         addRecentFileItems();
         fileMenu.add(recentFilesMenu);
 
+        exitMenuItem = new JMenuItem();
         exitMenuItem.setText("Exit");
         exitMenuItem.setAccelerator(KeyStroke.getKeyStroke("alt F4"));
         exitMenuItem.addActionListener(new ActionListener()
@@ -274,26 +360,49 @@ public class PDFDebugger extends javax.s
 
         if (!IS_MAC_OS)
         {
+            fileMenu.addSeparator();
             fileMenu.add(exitMenuItem);
         }
-
-        menuBar.add(fileMenu);
-
+        
+        return fileMenu;
+    }
+    
+    private JMenu createEditMenu()
+    {
+        editMenu = new JMenu();
         editMenu.setText("Edit");
+        
+        cutMenuItem = new JMenuItem();
         cutMenuItem.setText("Cut");
+        cutMenuItem.setEnabled(false);
         editMenu.add(cutMenuItem);
 
+        copyMenuItem = new JMenuItem();
         copyMenuItem.setText("Copy");
+        copyMenuItem.setEnabled(false);
         editMenu.add(copyMenuItem);
 
+        pasteMenuItem = new JMenuItem();
         pasteMenuItem.setText("Paste");
+        pasteMenuItem.setEnabled(false);
         editMenu.add(pasteMenuItem);
 
+        deleteMenuItem = new JMenuItem();
         deleteMenuItem.setText("Delete");
+        deleteMenuItem.setEnabled(false);
         editMenu.add(deleteMenuItem);
-
+        editMenu.addSeparator();
+        editMenu.add(createFindMenu());
+        
+        return editMenu;
+    }
+    
+    private JMenu createViewMenu()
+    {
+        viewMenu = new JMenu();
         viewMenu.setText("View");
 
+        viewModeItem = new JMenuItem();
         viewModeItem.setText("Show Pages");
         viewModeItem.addActionListener(new ActionListener()
         {
@@ -313,18 +422,8 @@ public class PDFDebugger extends javax.s
                 initTree();
             }
         });
-
         viewMenu.add(viewModeItem);
 
-        menuBar.add(viewMenu);
-
-        helpMenu.setText("Help");
-        contentsMenuItem.setText("Contents");
-        helpMenu.add(contentsMenuItem);
-
-        aboutMenuItem.setText("About");
-        helpMenu.add(aboutMenuItem);
-        
         ZoomMenu zoomMenu = ZoomMenu.getInstance();
         zoomMenu.setEnableMenu(false);
         viewMenu.add(zoomMenu.getMenu());
@@ -332,65 +431,84 @@ public class PDFDebugger extends javax.s
         RotationMenu rotationMenu = RotationMenu.getInstance();
         rotationMenu.setEnableMenu(false);
         viewMenu.add(rotationMenu.getMenu());
-
-        setJMenuBar(menuBar);
-
-        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
-        setBounds((screenSize.width-700)/2, (screenSize.height-600)/2, 700, 600);
-
-        // drag and drop to open files
-        setTransferHandler(new TransferHandler()
+        
+        return viewMenu;
+    }
+    
+    private JMenu createFindMenu()
+    {
+        findMenu = new JMenu("Find");
+        findMenu.setEnabled(false);
+        
+        findMenuItem = new JMenuItem();
+        findMenuItem.setActionCommand("find");
+        findMenuItem.setText("Find...");
+        findMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, SHORCUT_KEY_MASK));
+        
+        findNextMenuItem = new JMenuItem();
+        findNextMenuItem.setText("Find Next");
+        if (IS_MAC_OS)
         {
-            @Override
-            public boolean canImport(TransferSupport transferSupport)
-            {
-                return transferSupport.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
-            }
-
-            @Override
-            @SuppressWarnings("unchecked")
-            public boolean importData(TransferSupport transferSupport)
-            {
-                try
-                {
-                    Transferable transferable = transferSupport.getTransferable();
-                    List<File> files = (List<File>) transferable.getTransferData(
-                            DataFlavor.javaFileListFlavor);
-                    readPDFFile(files.get(0), "");
-                    return true;
-                }
-                catch (IOException e)
-                {
-                    throw new RuntimeException(e);
-                }
-                catch (UnsupportedFlavorException e)
-                {
-                    throw new RuntimeException(e);
-                }
-            }
-        });
+            findNextMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, SHORCUT_KEY_MASK));
+        }
+        else
+        {
+            findNextMenuItem.setAccelerator(KeyStroke.getKeyStroke("F3"));
+        }
 
-        // Mac OS X file open/quit handler
+        findPreviousMenuItem = new JMenuItem();
+        findPreviousMenuItem.setText("Find Previous");
         if (IS_MAC_OS)
         {
-            try
-            {
-                Method osxOpenFiles = getClass().getDeclaredMethod("osxOpenFiles", String.class);
-                osxOpenFiles.setAccessible(true);
-                OSXAdapter.setFileHandler(this, osxOpenFiles);
-
-                Method osxQuit = getClass().getDeclaredMethod("osxQuit");
-                osxQuit.setAccessible(true);
-                OSXAdapter.setQuitHandler(this, osxQuit);
-            }
-            catch (NoSuchMethodException e)
-            {
-                throw new RuntimeException(e);
-            }
+            findPreviousMenuItem.setAccelerator(KeyStroke.getKeyStroke(
+                    KeyEvent.VK_G, SHORCUT_KEY_MASK | InputEvent.SHIFT_DOWN_MASK));
+        }
+        else
+        {
+            findPreviousMenuItem.setAccelerator(KeyStroke.getKeyStroke(
+                    KeyEvent.VK_F3, InputEvent.SHIFT_DOWN_MASK));
         }
-    }//GEN-END:initComponents
+        
+        findMenu.add(findMenuItem);
+        findMenu.add(findNextMenuItem);
+        findMenu.add(findPreviousMenuItem);
+        
+        return findMenu;
+    }
 
     /**
+     * Returns the File menu.
+     */
+    public JMenu getFindMenu()
+    {
+        return findMenu;
+    }
+
+    /**
+     * Returns the Edit > Find > Find menu item.
+     */
+    public JMenuItem getFindMenuItem()
+    {
+        return findMenuItem;
+    }
+
+    /**
+     * Returns the Edit > Find > Find Next menu item.
+     */
+    public JMenuItem getFindNextMenuItem()
+    {
+        return findNextMenuItem;
+    }
+
+    /**
+     * Returns the Edit > Find > Find Previous menu item.
+     */
+    public JMenuItem getFindPreviousMenuItem()
+    {
+        return findPreviousMenuItem;
+    }
+    
+    /**
      * This method is called via reflection on Mac OS X.
      */
     private void osxOpenFiles(String filename)
@@ -451,7 +569,7 @@ public class PDFDebugger extends javax.s
         {
             throw new RuntimeException(e);
         }
-    }//GEN-LAST:event_openMenuItemActionPerformed
+    }
 
     private void jTree1ValueChanged(TreeSelectionEvent evt)
     {
@@ -502,7 +620,7 @@ public class PDFDebugger extends javax.s
                 throw new RuntimeException(e);
             }
         }
-    }//GEN-LAST:event_jTree1ValueChanged
+    }
 
     private boolean isSpecialColorSpace(Object selectedNode)
     {
@@ -901,14 +1019,12 @@ public class PDFDebugger extends javax.s
                     sb.append('\n');
                     sb.append(element);
                 }
-                JOptionPane.showMessageDialog(null, "Error: " + sb.toString(),"Error",
+                JOptionPane.showMessageDialog(null, "Error: " + sb.toString(), "Error",
                         JOptionPane.ERROR_MESSAGE);
             }
         });
         
         final PDFDebugger viewer = new PDFDebugger();
-
-        
         
         // open file, if any
         String filename = null;
@@ -1071,7 +1187,6 @@ public class PDFDebugger extends javax.s
         }
     }
 
-
     /**
      * This will print out a message telling how to use this utility.
      */
@@ -1083,32 +1198,4 @@ public class PDFDebugger extends javax.s
                         "  <input-file>              The PDF document to be loaded\n"
         );
     }
-
-    // Variables declaration - do not modify//GEN-BEGIN:variables
-    private JMenuItem aboutMenuItem;
-    private JMenuItem contentsMenuItem;
-    private JMenuItem copyMenuItem;
-    private JMenuItem cutMenuItem;
-    private JMenuItem deleteMenuItem;
-    private JMenu editMenu;
-    private JMenuItem exitMenuItem;
-    private JMenu fileMenu;
-    private JMenu helpMenu;
-    private JMenu recentFilesMenu;
-    private JMenu viewMenu;
-    private JMenuItem viewModeItem;
-    private JScrollPane jScrollPane1;
-    private JScrollPane jScrollPane2;
-    private javax.swing.JSplitPane jSplitPane1;
-    private javax.swing.JTextPane jTextPane1;
-    private Tree tree;
-    private javax.swing.JMenuBar menuBar;
-    private JMenuItem openMenuItem;
-    private JMenuItem openUrlMenuItem;
-    private JMenuItem pasteMenuItem;
-    private JMenuItem saveAsMenuItem;
-    private JMenuItem saveMenuItem;
-    private final JPanel documentPanel = new JPanel();
-    // End of variables declaration//GEN-END:variables
-
 }

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamTextView.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamTextView.java?rev=1693855&r1=1693854&r2=1693855&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamTextView.java
(original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamTextView.java
Mon Aug  3 04:26:52 2015
@@ -18,20 +18,18 @@
 package org.apache.pdfbox.tools.pdfdebugger.streampane;
 
 import java.awt.Font;
-import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseMotionListener;
 import javax.swing.BoxLayout;
 import javax.swing.JComponent;
-import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTextPane;
-import javax.swing.KeyStroke;
 import javax.swing.SwingUtilities;
 import javax.swing.event.AncestorEvent;
 import javax.swing.event.AncestorListener;
 import javax.swing.text.StyledDocument;
+import org.apache.pdfbox.tools.PDFDebugger;
 import org.apache.pdfbox.tools.pdfdebugger.streampane.tooltip.ToolTipController;
 import org.apache.pdfbox.tools.pdfdebugger.ui.textsearcher.Searcher;
 
@@ -77,8 +75,6 @@ class StreamTextView implements MouseMot
         mainPanel.add(scrollPane);
 
         searcher.getSearchPanel().setVisible(false);
-        searcher.setFindStroke(mainPanel, KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK));
-        searcher.setCloseStroke(mainPanel, KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK
| KeyEvent.SHIFT_DOWN_MASK));
 
         mainPanel.addAncestorListener(this);
 
@@ -109,9 +105,9 @@ class StreamTextView implements MouseMot
     {
         if (ancestorEvent.getAncestor().equals(mainPanel))
         {
-            JFrame frame = (JFrame) SwingUtilities.getRoot(mainPanel);
-            frame.getJMenuBar().add(searcher.getMenu());
-            SwingUtilities.updateComponentTreeUI(frame.getJMenuBar());
+            PDFDebugger debugger = (PDFDebugger) SwingUtilities.getRoot(mainPanel);
+            debugger.getFindMenu().setEnabled(true);
+            searcher.addMenuListeners(debugger);
         }
     }
 
@@ -120,15 +116,14 @@ class StreamTextView implements MouseMot
     {
         if (ancestorEvent.getAncestor().equals(mainPanel))
         {
-            JFrame frame = (JFrame) SwingUtilities.getRoot(mainPanel);
-            frame.getJMenuBar().remove(searcher.getMenu());
-            SwingUtilities.updateComponentTreeUI(frame.getJMenuBar());
+            PDFDebugger debugger = (PDFDebugger) SwingUtilities.getRoot(mainPanel);
+            debugger.getFindMenu().setEnabled(false);
+            searcher.removeMenuListeners(debugger);
         }
     }
 
     @Override
     public void ancestorMoved(AncestorEvent ancestorEvent)
     {
-
     }
-}
\ No newline at end of file
+}

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/SearchPanel.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/SearchPanel.java?rev=1693855&r1=1693854&r2=1693855&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/SearchPanel.java
(original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/SearchPanel.java
Mon Aug  3 04:26:52 2015
@@ -17,25 +17,26 @@
 
 package org.apache.pdfbox.tools.pdfdebugger.ui.textsearcher;
 
-import java.awt.Font;
+import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ComponentListener;
-import java.awt.event.InputEvent;
 import java.awt.event.KeyEvent;
 import javax.swing.AbstractAction;
 import javax.swing.Action;
+import javax.swing.BorderFactory;
+import javax.swing.Box;
 import javax.swing.BoxLayout;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComponent;
 import javax.swing.JLabel;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 import javax.swing.KeyStroke;
 import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentListener;
+import org.apache.pdfbox.tools.PDFDebugger;
 
 /**
  * @author Khyrul Bashar
@@ -49,11 +50,7 @@ class SearchPanel
     private JTextField searchField;
     private JLabel counterLabel;
     private JPanel panel;
-    private JMenu searchMenu;
-    private KeyStroke findStroke;
-    private KeyStroke closeStroke;
-    private KeyStroke nextStroke;
-    private KeyStroke previousStroke;
+    
     private Action closeAction = new AbstractAction()
     {
         @Override
@@ -61,8 +58,10 @@ class SearchPanel
         {
             panel.setVisible(false);
             closeAction.setEnabled(false);
+            panel.getParent().transferFocus();
         }
     };
+    
     private final Action findAction = new AbstractAction()
     {
         @Override
@@ -78,7 +77,6 @@ class SearchPanel
         }
     };
 
-
     /**
      * Constructor.
      * @param documentListener DocumentListener instance.
@@ -103,17 +101,14 @@ class SearchPanel
 
         counterLabel = new JLabel();
         counterLabel.setVisible(false);
-        counterLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 13));
 
         JButton nextButton = new JButton();
         nextButton.setAction(nextAction);
         nextButton.setText("Next");
-        nextButton.setToolTipText("Find next");
 
         JButton previousButton = new JButton();
         previousButton.setAction(previousAction);
         previousButton.setText("Previous");
-        previousButton.setToolTipText("Find previous");
 
         caseSensitive = new JCheckBox("Match case");
         caseSensitive.setSelected(false);
@@ -122,26 +117,27 @@ class SearchPanel
 
         JButton crossButton = new JButton();
         crossButton.setAction(closeAction);
+        crossButton.setText("Done");
         closeAction.setEnabled(false);
-        crossButton.setHideActionText(true);
-        crossButton.setText("X");
-        crossButton.setToolTipText("Close");
-
-
+        
         panel = new JPanel();
+        panel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
+        panel.setBackground(new Color(230, 230, 230));
         panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
 
+        panel.add(Box.createHorizontalGlue());
         panel.add(searchField);
         panel.add(counterLabel);
-        panel.add(nextButton);
         panel.add(previousButton);
+        panel.add(nextButton);
         panel.add(caseSensitive);
+        panel.add(Box.createRigidArea(new Dimension(5, 0)));
         panel.add(crossButton);
 
         panel.addComponentListener(compListener);
 
-        setNextFindStroke(KeyStroke.getKeyStroke("F3"));
-        setPreviousStroke(KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_DOWN_MASK));
+        searchField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
+                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), closeAction);
     }
 
     boolean isCaseSensitive()
@@ -190,92 +186,19 @@ class SearchPanel
         closeAction.setEnabled(true);
     }
 
-    private JMenu createSearchMenu()
-    {
-        JMenuItem findMenuItem = new JMenuItem();
-        findMenuItem.setAction(findAction);
-        findMenuItem.setText("Find");
-        findMenuItem.setAccelerator(findStroke);
-
-        JMenuItem closeMenuItem = new JMenuItem();
-        closeMenuItem.setAction(closeAction);
-        closeMenuItem.setText("Close");
-        closeMenuItem.setAccelerator(closeStroke);
-
-        JMenuItem nextFindMenuItem = new JMenuItem();
-        nextFindMenuItem.setAction(nextAction);
-        nextFindMenuItem.setText("Find next");
-        nextFindMenuItem.setAccelerator(nextStroke);
-
-        JMenuItem previousMenuItem = new JMenuItem();
-        previousMenuItem.setAction(previousAction);
-        previousMenuItem.setText("Find previous");
-        previousMenuItem.setAccelerator(previousStroke);
-
-        JMenu menu = new JMenu("Search");
-
-        menu.add(findMenuItem);
-        menu.addSeparator();
-        menu.add(nextFindMenuItem);
-        menu.add(previousMenuItem);
-        menu.addSeparator();
-        menu.add(closeMenuItem);
-
-        return menu;
-    }
-
-    JMenu getSearchMenu()
-    {
-        if (searchMenu == null)
-        {
-            searchMenu = createSearchMenu();
-        }
-        return searchMenu;
-    }
-
-    void setFindStroke(JComponent parent, KeyStroke keyStroke)
+    public void addMenuListeners(PDFDebugger frame)
     {
-        if (findStroke != null)
-        {
-            parent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(findStroke);
-        }
-        findStroke = keyStroke;
-        addActionToInput(parent, "showPanle", JComponent.WHEN_IN_FOCUSED_WINDOW, findStroke,
findAction);
-    }
-
-    void setCloseStroke(JComponent parent, KeyStroke keyStroke)
-    {
-        if (closeStroke != null)
-        {
-            parent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(closeStroke);
-        }
-        closeStroke = keyStroke;
-        addActionToInput(parent, "closePanel", JComponent.WHEN_IN_FOCUSED_WINDOW, closeStroke,
closeAction);
-    }
-
-    void setNextFindStroke(KeyStroke keyStroke)
-    {
-        if (nextStroke != null)
-        {
-            panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(nextStroke);
-        }
-        nextStroke = keyStroke;
-        addActionToInput(panel, "nextFind", JComponent.WHEN_IN_FOCUSED_WINDOW, nextStroke,
nextAction);
-    }
-
-    void setPreviousStroke(KeyStroke keyStroke)
-    {
-        if (previousStroke != null)
-        {
-            panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(previousStroke);
-        }
-        previousStroke = keyStroke;
-        addActionToInput(panel, "previousFind", JComponent.WHEN_IN_FOCUSED_WINDOW, previousStroke,
previousAction);
+        frame.getFindMenu().setEnabled(true);
+        frame.getFindMenuItem().addActionListener(findAction);
+        frame.getFindNextMenuItem().addActionListener(nextAction);
+        frame.getFindPreviousMenuItem().addActionListener(previousAction);
     }
 
-    private void addActionToInput(JComponent component, Object key, int state, KeyStroke
keyStroke, Action action)
+    public void removeMenuListeners(PDFDebugger frame)
     {
-        component.getInputMap(state).put(keyStroke, key);
-        component.getActionMap().put(key, action);
+        frame.getFindMenu().setEnabled(false);
+        frame.getFindMenuItem().removeActionListener(findAction);
+        frame.getFindNextMenuItem().removeActionListener(nextAction);
+        frame.getFindPreviousMenuItem().removeActionListener(previousAction);
     }
 }

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/Searcher.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/Searcher.java?rev=1693855&r1=1693854&r2=1693855&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/Searcher.java
(original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/textsearcher/Searcher.java
Mon Aug  3 04:26:52 2015
@@ -25,10 +25,7 @@ import java.util.List;
 import javax.swing.AbstractAction;
 import javax.swing.Action;
 import javax.swing.JCheckBox;
-import javax.swing.JComponent;
-import javax.swing.JMenu;
 import javax.swing.JPanel;
-import javax.swing.KeyStroke;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
@@ -37,6 +34,7 @@ import javax.swing.text.BadLocationExcep
 import javax.swing.text.DefaultHighlighter;
 import javax.swing.text.Highlighter;
 import javax.swing.text.JTextComponent;
+import org.apache.pdfbox.tools.PDFDebugger;
 
 /**
  * @author Khyrul Bashar
@@ -256,18 +254,13 @@ public class Searcher implements Documen
         textComponent.getHighlighter().removeAllHighlights();
     }
 
-    public JMenu getMenu()
+    public void addMenuListeners(PDFDebugger frame)
     {
-        return searchPanel.getSearchMenu();
+        searchPanel.addMenuListeners(frame);
     }
 
-    public void setFindStroke(JComponent parent, KeyStroke keyStroke)
+    public void removeMenuListeners(PDFDebugger frame)
     {
-        searchPanel.setFindStroke(parent, keyStroke);
-    }
-
-    public void setCloseStroke(JComponent parent, KeyStroke keyStroke)
-    {
-        searchPanel.setCloseStroke(parent, keyStroke);
+        searchPanel.removeMenuListeners(frame);
     }
 }



Mime
View raw message