/**
* ===========================================
* Java Pdf Extraction Decoding Access Library
* ===========================================
*
* Project Info: http://www.jpedal.org
* (C) Copyright 1997-2010, IDRsolutions and Contributors.
*
* This file is part of JPedal
*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ---------------
* PageFlowPanel.java
* ---------------
*/
package org.jpedal.examples.jpaneldemo;
import org.jpedal.PageFlow3D;
import org.jpedal.PdfDecoder;
import org.jpedal.utils.Java3DHelper;
import org.jpedal.utils.Messages;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
public class PageFlowPanel {
private JFrame frame;
private String filename;
public PageFlowPanel(String path) {
if (!Java3DHelper.isJava3DAvailable()) {
JOptionPane.showMessageDialog(null,"Java 3D 1.4 or later required!");
System.exit(0);
}
//Store filename
filename = path.substring(path.lastIndexOf("/")+1);
//Create decoder and open file
PdfDecoder pdf = new PdfDecoder();
try {
pdf.openPdfFile(path);
} catch(Exception e) {
e.printStackTrace();
}
//Create PageFlow
PageFlow3D pageflow = new PageFlow3D(1, pdf);
//Detect when page changed
pageflow.setPageListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
frame.setTitle("PageFlow3D - "+filename+" page "+e.getActionCommand());
}
});
//Set message bundle
Messages.setBundle(ResourceBundle.getBundle("org.jpedal.international.messages"));
//Pick up any messages
pageflow.setMessageListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame, e.getActionCommand());
}
});
//Load cursors
Toolkit t = Toolkit.getDefaultToolkit();
try {
Image grab = t.getImage(getClass().getResource("/org/jpedal/examples/simpleviewer/res/grab32.png"));
Image grabbing = t.getImage(getClass().getResource("/org/jpedal/examples/simpleviewer/res/grabbing32.png"));
pageflow.setCursors(t.createCustomCursor(grab, new Point(8,8),"grab"),
t.createCustomCursor(grabbing, new Point(8,8),"grabbing"),
Cursor.getDefaultCursor());
} catch (Exception e) {
e.printStackTrace();
}
//Setup frame
frame = new JFrame("PageFlow3D - "+filename+" page 1");
frame.setContentPane(pageflow);
frame.setSize(800,600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
PageFlowPanel t = new PageFlowPanel(args[0]);
}
}
|