001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/pdfdoctools/DocPanel.java,v 1.1 2005/04/20 21:04:37 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is Java 3D(tm) Fly Through.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dfly.pdfdoctools;
019:
020: import java.io.File;
021: import java.io.IOException;
022: import java.net.URL;
023:
024: import org.jdesktop.j3dfly.event.EventProcessor;
025: import org.jdesktop.j3dfly.event.FileLoadEvent;
026: import org.jdesktop.j3dfly.event.ObjectPickEvent;
027: import org.jdesktop.j3dfly.event.FlyEventListener;
028: import org.jdesktop.j3dfly.J3dFlyContext;
029:
030: import com.adobe.acrobat.Viewer;
031:
032: /**
033: *
034: * @author paulby
035: * @version
036: */
037: public class DocPanel extends javax.swing.JPanel implements
038: FlyEventListener {
039:
040: private DocManager docManager;
041: private Viewer pdfViewer;
042: private J3dFlyContext context;
043:
044: /** Creates new form DocPanel */
045: public DocPanel(J3dFlyContext context) {
046: this .context = context;
047: initComponents();
048:
049: try {
050: pdfViewer = new Viewer();
051: } catch (Exception e) {
052: System.out.println("ERROR Construction PDF Viewer");
053: return;
054: }
055:
056: this .add(pdfViewer, java.awt.BorderLayout.CENTER);
057:
058: try {
059: pdfViewer.activate();
060: } catch (Exception e) {
061: System.out.println("ERROR Activating PDF Viewer");
062: return;
063: }
064:
065: docManager = new DocManager(this );
066:
067: try {
068: pdfViewer
069: .setDocumentURL("file:///home/paulby/code/J3dFly_2.0_ws/src/geometry/doc-data/excalibur/excalibur.pdf");
070: pdfViewer
071: .execMenuItem(com.adobe.acrobat.ViewerCommand.ShowBookmarks_K);
072: } catch (Exception e) {
073: System.out.println("ERROR Loading PDF Document");
074: return;
075: }
076:
077: }
078:
079: /**
080: * Return the Context for this Panel
081: */
082: J3dFlyContext getJ3dFlyContext() {
083: return context;
084: }
085:
086: /** This method is called from within the constructor to
087: * initialize the form.
088: * WARNING: Do NOT modify this code. The content of this method is
089: * always regenerated by the FormEditor.
090: */
091: private void initComponents() {//GEN-BEGIN:initComponents
092: setLayout(new java.awt.BorderLayout());
093: }//GEN-END:initComponents
094:
095: /**
096: * Called by EventProcessor when an event occurs for which this
097: * listener has registered interest
098: */
099: public void processFlyEvent(
100: final org.jdesktop.j3dfly.event.FlyEvent evt) {
101: if (evt instanceof FileLoadEvent)
102: loadDocIndex((FileLoadEvent) evt);
103: else if (evt instanceof ObjectPickEvent)
104: processObjectPick((ObjectPickEvent) evt);
105: }
106:
107: /**
108: * Load the Document index for the file that triggered the load event
109: */
110: private void loadDocIndex(FileLoadEvent evt) {
111: System.out.println(evt.getFile().getName());
112: String indexName = evt.getFile().getPath();
113: indexName = indexName.substring(0, indexName.lastIndexOf('.'));
114: indexName += ".pdfidx";
115: System.out.println("Index " + indexName);
116:
117: File file = new File(indexName);
118: if (!file.exists()) {
119: System.out
120: .println("ERROR Can't open PDF document index file "
121: + indexName);
122: return;
123: }
124:
125: docManager.loadIndex(file);
126: context.getEventProcessor().addListener(this ,
127: ObjectPickEvent.class);
128: }
129:
130: /**
131: * Show the PDF Document specified by the url (string)
132: */
133: void setDocument(String url) throws IOException {
134: try {
135: pdfViewer.setDocumentURL(url);
136: } catch (Exception e) {
137: System.out.println("ERROR Loading PDF Document " + url);
138: }
139: }
140:
141: private void processObjectPick(ObjectPickEvent evt) {
142: String bookmark = docManager.getBookmark(evt.getNode());
143:
144: System.out.println("PDF got pick event ");
145:
146: try {
147: pdfViewer.gotoNamedDest(bookmark);
148: } catch (Exception e) {
149: System.out.println("ERROR Unable to goto PDF destination "
150: + bookmark);
151: }
152:
153: }
154:
155: // Variables declaration - do not modify//GEN-BEGIN:variables
156: // End of variables declaration//GEN-END:variables
157:
158: }
|