| Author |
Message |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 16/02/2010 04:30:50
|
mwildam
Joined: 11/05/2009 00:00:00
Messages: 12
Offline
|
I tried to create an applet for showing a PDF first trying the sample. As that did not refresh the view (panel shown empty) I tried a little different way as I used for a Swing application that worked fine. However, the panel does not refresh and I don't get anything displayed in the applet.
Here is my code:Code:
package pdfviewer;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
public class PDFViewer extends javax.swing.JApplet {
private SwingController iceController = null;
private SwingViewBuilder iceFactory = null;
private JPanel icePanel = null;
/** Initializes the applet PDFViewer */
@Override
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
initViewer();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void start()
{
super.start();
// Open a url if available
URL documentURL = null;
String url = getParameter("url");
if (url == null) url = "default.pdf";
if (url.length() > 0)
{
try
{
documentURL = new URL(url);
}
catch (MalformedURLException ex)
{
Logger.getLogger(PDFViewer.class.getName()).log(Level.SEVERE, null, ex);
}
}
// Now that the GUI is all in place, we can try openning a PDF
if (documentURL != null)
iceController.openDocument(documentURL);
else
iceController.closeDocument();
iceController.updateDocumentView();
}
@Override
public void destroy()
{
// dispose the viewer component
if (iceController != null)
{
iceController.dispose();
iceController = null;
}
getContentPane().removeAll();
super.destroy();
}
private void initViewer()
{
System.setProperty("org.icepdf.core.awtFontLoading", "false");
iceController = new SwingController();
iceFactory = new SwingViewBuilder(iceController);
icePanel = iceFactory.buildViewerPanel();
icePanel.setName("Preview");
icePanel.setMinimumSize(getSize());
icePanel.setPreferredSize(getSize());
viewerPanel.add(icePanel);
// add interactive mouse link annotation support via callback
iceController.getDocumentViewController().setAnnotationCallback(
new org.icepdf.ri.common.MyAnnotationCallback(
iceController.getDocumentViewController()));
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
viewerPanel = new javax.swing.JPanel();
javax.swing.GroupLayout viewerPanelLayout = new javax.swing.GroupLayout(viewerPanel);
viewerPanel.setLayout(viewerPanelLayout);
viewerPanelLayout.setHorizontalGroup(
viewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
viewerPanelLayout.setVerticalGroup(
viewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(viewerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(viewerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JPanel viewerPanel;
// End of variables declaration
}
It seems that just the refresh is not working when the PDF panel is added dynamically. What is missing here?
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 16/02/2010 04:48:37
|
patrick.corless
Joined: 26/10/2004 00:00:00
Messages: 1097
Offline
|
Generally speaking if the panel is empty there was some problem loading the file from the URL. The Applet example that comes with the bundles works fine if you are using the Java Applet Viewer. If you are deploying the example to a web server and viewer the applet with a web browser then you will need to sign the jars. If the jars aren't signed there will be a security exception that will prevent the PDF from being loaded.
There is a little bit more information here, http://wiki.icefaces.org/display/PDF/Applet+Example
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 16/02/2010 04:52:25
|
mwildam
Joined: 11/05/2009 00:00:00
Messages: 12
Offline
|
I did only try the applet Viewer in NetBeans 6.8 (did not deploy yet).
The interesting thing is: If I change the PDF to something invalid (or non-existing file) I immediately get an error popup. So I don't think it is a problem with loading the PDF - even because it can be loaded in the Swing application where I integrated the Viewer.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 17/02/2010 11:28:28
|
patrick.corless
Joined: 26/10/2004 00:00:00
Messages: 1097
Offline
|
You might want to try launching the AppletViewer from the command line. I'm wondering if Nebeans .policy file isn't allowing external url's from loading.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 01/03/2010 09:42:01
|
mwildam
Joined: 11/05/2009 00:00:00
Messages: 12
Offline
|
What commandline tool should be used then?
Sorry, I am not that familiar with applets.
As policy file - I only find those from the tomcat and glassfish application server in my .netbeans folder.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 08/03/2010 06:49:20
|
patrick.corless
Joined: 26/10/2004 00:00:00
Messages: 1097
Offline
|
You can read a little more about the applet viewer here, http://java.sun.com/j2se/1.3/docs/tooldocs/win32/appletviewer.html.
|
|
|
 |
|
|