KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdfviewer > PageWrapper


1 /**
2  * Copyright (c) 2003-2006, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdfviewer;
32
33 import java.awt.Dimension JavaDoc;
34 import java.awt.event.MouseEvent JavaDoc;
35 import java.awt.event.MouseMotionListener JavaDoc;
36 import java.io.IOException JavaDoc;
37
38 import javax.swing.JPanel JavaDoc;
39
40 import org.pdfbox.PDFReader;
41 import org.pdfbox.pdmodel.PDPage;
42
43 /**
44  * A class to handle some prettyness around a single PDF page.
45  *
46  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
47  * @version $Revision: 1.5 $
48  */

49 public class PageWrapper implements MouseMotionListener JavaDoc
50 {
51     private JPanel JavaDoc pageWrapper = new JPanel JavaDoc();
52     private PDFPagePanel pagePanel = null;
53     private PDFReader reader = null;
54
55     private static final int SPACE_AROUND_DOCUMENT = 20;
56
57     /**
58      * Constructor.
59      *
60      * @param aReader The reader application that holds this page.
61      *
62      * @throws IOException If there is an error creating the page drawing objects.
63      */

64     public PageWrapper( PDFReader aReader ) throws IOException JavaDoc
65     {
66         reader = aReader;
67         pagePanel = new PDFPagePanel();
68         pageWrapper.setLayout( null );
69         pageWrapper.add( pagePanel );
70         pagePanel.setLocation( SPACE_AROUND_DOCUMENT, SPACE_AROUND_DOCUMENT );
71         pageWrapper.setBorder( javax.swing.border.LineBorder.createBlackLineBorder() );
72         pagePanel.addMouseMotionListener( this );
73     }
74
75     /**
76      * This will display the PDF page in this component.
77      *
78      * @param page The PDF page to display.
79      */

80     public void displayPage( PDPage page )
81     {
82         pagePanel.setPage( page );
83         pagePanel.setPreferredSize( pagePanel.getSize() );
84         Dimension JavaDoc d = pagePanel.getSize();
85         d.width+=(SPACE_AROUND_DOCUMENT*2);
86         d.height+=(SPACE_AROUND_DOCUMENT*2);
87
88         pageWrapper.setPreferredSize( d );
89         pageWrapper.validate();
90     }
91
92     /**
93      * This will get the JPanel that can be displayed.
94      *
95      * @return The panel with the displayed PDF page.
96      */

97     public JPanel JavaDoc getPanel()
98     {
99         return pageWrapper;
100     }
101     
102     /**
103      * {@inheritDoc}
104      */

105     public void mouseDragged(MouseEvent JavaDoc e)
106     {
107         //do nothing when mouse moves.
108
}
109
110     /**
111      * {@inheritDoc}
112      */

113     public void mouseMoved(MouseEvent JavaDoc e)
114     {
115         //reader.getBottomStatusPanel().getStatusLabel().setText( e.getX() + "," + (pagePanel.getHeight() - e.getY()) );
116
reader.getBottomStatusPanel().getStatusLabel().setText( e.getX() + "," + e.getY() );
117     }
118 }
Popular Tags