001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/doctools/DocPanel.java,v 1.1 2005/04/20 21:04:24 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.doctools;
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: /**
031: *
032: * @author paulby
033: * @version
034: */
035: public class DocPanel extends javax.swing.JPanel implements
036: FlyEventListener {
037:
038: private DocManager docManager;
039: private J3dFlyContext context;
040:
041: /** Creates new form DocPanel */
042: public DocPanel(J3dFlyContext context) {
043: this .context = context;
044: initComponents();
045:
046: docManager = new DocManager(this );
047: docP.addHyperlinkListener(docManager);
048:
049: context.getEventProcessor().addListener(this ,
050: FileLoadEvent.class);
051: }
052:
053: /**
054: * Return the Context for this Panel
055: */
056: J3dFlyContext getJ3dFlyContext() {
057: return context;
058: }
059:
060: /** This method is called from within the constructor to
061: * initialize the form.
062: * WARNING: Do NOT modify this code. The content of this method is
063: * always regenerated by the FormEditor.
064: */
065: private void initComponents() {//GEN-BEGIN:initComponents
066: jScrollPane1 = new javax.swing.JScrollPane();
067: docP = new javax.swing.JEditorPane();
068: setLayout(new java.awt.BorderLayout());
069:
070: jScrollPane1.setPreferredSize(new java.awt.Dimension(200, 400));
071: jScrollPane1.setMinimumSize(new java.awt.Dimension(200, 400));
072:
073: docP.setEditable(false);
074: jScrollPane1.setViewportView(docP);
075:
076: add(jScrollPane1, java.awt.BorderLayout.CENTER);
077:
078: }//GEN-END:initComponents
079:
080: /**
081: * Called by EventProcessor when an event occurs for which this
082: * listener has registered interest
083: */
084: public void processFlyEvent(
085: final org.jdesktop.j3dfly.event.FlyEvent evt) {
086: if (evt instanceof FileLoadEvent)
087: loadDocIndex((FileLoadEvent) evt);
088: else if (evt instanceof ObjectPickEvent)
089: processObjectPick((ObjectPickEvent) evt);
090: }
091:
092: /**
093: * Load the Document index for the file that triggered the load event
094: */
095: private void loadDocIndex(FileLoadEvent evt) {
096: System.out.println(evt.getFile().getName());
097: String indexName = evt.getFile().getPath();
098: indexName = indexName.substring(0, indexName.lastIndexOf('.'));
099: indexName += ".idx";
100: System.out.println("Index " + indexName);
101:
102: File file = new File(indexName);
103: if (!file.exists()) {
104: System.out.println("ERROR Can't open document index file "
105: + indexName);
106: return;
107: }
108:
109: docManager.loadIndex(file);
110: context.getEventProcessor().addListener(this ,
111: ObjectPickEvent.class);
112:
113: try {
114: docP.setPage(docManager.getDoc(null));
115: } catch (IOException e) {
116: //e.printStackTrace();
117: }
118: }
119:
120: /**
121: * Show the HTML page at the URL
122: */
123: void showPage(URL url) throws IOException {
124: docP.setPage(url);
125: }
126:
127: private void processObjectPick(ObjectPickEvent evt) {
128: URL url = docManager.getDoc(evt.getNode());
129:
130: //System.out.println(evt+" "+url);
131: try {
132: if (url != null)
133: docP.setPage(url);
134: } catch (IOException e) {
135: e.printStackTrace();
136: }
137: }
138:
139: // Variables declaration - do not modify//GEN-BEGIN:variables
140: private javax.swing.JScrollPane jScrollPane1;
141: private javax.swing.JEditorPane docP;
142: // End of variables declaration//GEN-END:variables
143:
144: }
|