001: /**
002: * Copyright (c) 2003-2006, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdfviewer;
031:
032: import java.awt.Dimension;
033: import java.awt.event.MouseEvent;
034: import java.awt.event.MouseMotionListener;
035: import java.io.IOException;
036:
037: import javax.swing.JPanel;
038:
039: import org.pdfbox.PDFReader;
040: import org.pdfbox.pdmodel.PDPage;
041:
042: /**
043: * A class to handle some prettyness around a single PDF page.
044: *
045: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
046: * @version $Revision: 1.5 $
047: */
048: public class PageWrapper implements MouseMotionListener {
049: private JPanel pageWrapper = new JPanel();
050: private PDFPagePanel pagePanel = null;
051: private PDFReader reader = null;
052:
053: private static final int SPACE_AROUND_DOCUMENT = 20;
054:
055: /**
056: * Constructor.
057: *
058: * @param aReader The reader application that holds this page.
059: *
060: * @throws IOException If there is an error creating the page drawing objects.
061: */
062: public PageWrapper(PDFReader aReader) throws IOException {
063: reader = aReader;
064: pagePanel = new PDFPagePanel();
065: pageWrapper.setLayout(null);
066: pageWrapper.add(pagePanel);
067: pagePanel.setLocation(SPACE_AROUND_DOCUMENT,
068: SPACE_AROUND_DOCUMENT);
069: pageWrapper.setBorder(javax.swing.border.LineBorder
070: .createBlackLineBorder());
071: pagePanel.addMouseMotionListener(this );
072: }
073:
074: /**
075: * This will display the PDF page in this component.
076: *
077: * @param page The PDF page to display.
078: */
079: public void displayPage(PDPage page) {
080: pagePanel.setPage(page);
081: pagePanel.setPreferredSize(pagePanel.getSize());
082: Dimension d = pagePanel.getSize();
083: d.width += (SPACE_AROUND_DOCUMENT * 2);
084: d.height += (SPACE_AROUND_DOCUMENT * 2);
085:
086: pageWrapper.setPreferredSize(d);
087: pageWrapper.validate();
088: }
089:
090: /**
091: * This will get the JPanel that can be displayed.
092: *
093: * @return The panel with the displayed PDF page.
094: */
095: public JPanel getPanel() {
096: return pageWrapper;
097: }
098:
099: /**
100: * {@inheritDoc}
101: */
102: public void mouseDragged(MouseEvent e) {
103: //do nothing when mouse moves.
104: }
105:
106: /**
107: * {@inheritDoc}
108: */
109: public void mouseMoved(MouseEvent e) {
110: //reader.getBottomStatusPanel().getStatusLabel().setText( e.getX() + "," + (pagePanel.getHeight() - e.getY()) );
111: reader.getBottomStatusPanel().getStatusLabel().setText(
112: e.getX() + "," + e.getY());
113: }
114: }
|