1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.pdfbox.pdfviewer; 18 19 import java.awt.Dimension; 20 import java.awt.event.MouseEvent; 21 import java.awt.event.MouseMotionListener; 22 import java.io.IOException; 23 24 import javax.swing.JPanel; 25 26 import org.apache.pdfbox.PDFReader; 27 import org.apache.pdfbox.pdmodel.PDPage; 28 29 /** 30 * A class to handle some prettyness around a single PDF page. 31 * 32 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 33 * @version $Revision: 1.5 $ 34 */ 35 public class PageWrapper implements MouseMotionListener 36 { 37 private JPanel pageWrapper = new JPanel(); 38 private PDFPagePanel pagePanel = null; 39 private PDFReader reader = null; 40 41 private static final int SPACE_AROUND_DOCUMENT = 20; 42 43 /** 44 * Constructor. 45 * 46 * @param aReader The reader application that holds this page. 47 * 48 * @throws IOException If there is an error creating the page drawing objects. 49 */ 50 public PageWrapper( PDFReader aReader ) throws IOException 51 { 52 reader = aReader; 53 pagePanel = new PDFPagePanel(); 54 pageWrapper.setLayout( null ); 55 pageWrapper.add( pagePanel ); 56 pagePanel.setLocation( SPACE_AROUND_DOCUMENT, SPACE_AROUND_DOCUMENT ); 57 pageWrapper.setBorder( javax.swing.border.LineBorder.createBlackLineBorder() ); 58 pagePanel.addMouseMotionListener( this ); 59 } 60 61 /** 62 * This will display the PDF page in this component. 63 * 64 * @param page The PDF page to display. 65 */ 66 public void displayPage( PDPage page ) 67 { 68 pagePanel.setPage( page ); 69 pagePanel.setPreferredSize( pagePanel.getSize() ); 70 Dimension d = pagePanel.getSize(); 71 d.width+=(SPACE_AROUND_DOCUMENT*2); 72 d.height+=(SPACE_AROUND_DOCUMENT*2); 73 74 pageWrapper.setPreferredSize( d ); 75 pageWrapper.validate(); 76 } 77 78 /** 79 * This will get the JPanel that can be displayed. 80 * 81 * @return The panel with the displayed PDF page. 82 */ 83 public JPanel getPanel() 84 { 85 return pageWrapper; 86 } 87 88 /** 89 * {@inheritDoc} 90 */ 91 public void mouseDragged(MouseEvent e) 92 { 93 //do nothing when mouse moves. 94 } 95 96 /** 97 * {@inheritDoc} 98 */ 99 public void mouseMoved(MouseEvent e) 100 { 101 //reader.getBottomStatusPanel().getStatusLabel().setText( e.getX() + "," + (pagePanel.getHeight() - e.getY()) ); 102 reader.getBottomStatusPanel().getStatusLabel().setText( e.getX() + "," + e.getY() ); 103 } 104 }