bugId 17316
Added 4 demo pluglets a = laa@sparc.spb.su r = idk@eng.sun.com git-svn-id: svn://10.0.0.236/trunk@51965 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
163
mozilla/java/plugins/examples/MediaPlayer/JMPlayer.java
Normal file
163
mozilla/java/plugins/examples/MediaPlayer/JMPlayer.java
Normal file
@@ -0,0 +1,163 @@
|
||||
import javax.media.*;
|
||||
import javax.media.util.*;
|
||||
import javax.media.format.*;
|
||||
import javax.media.bean.playerbean.*;
|
||||
import javax.media.control.*;
|
||||
|
||||
|
||||
import org.mozilla.pluglet.*;
|
||||
import org.mozilla.pluglet.mozilla.*;
|
||||
import org.mozilla.pluglet.mozilla.PlugletTagInfo2;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.print.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class JMPlayer implements Pluglet {
|
||||
public JMPlayer() {
|
||||
}
|
||||
|
||||
public PlugletInstance createPlugletInstance(String mimeType) {
|
||||
return new JMPlayerInstance();
|
||||
}
|
||||
|
||||
public void initialize(PlugletManager manager) {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
}
|
||||
}
|
||||
|
||||
class JMPlayerInstance implements PlugletInstance, ControllerListener {
|
||||
PlugletInstancePeer peer;
|
||||
Dimension defaultSize;
|
||||
Frame frm;
|
||||
int w, h;
|
||||
MediaPlayer player = null;
|
||||
|
||||
Panel panel;
|
||||
|
||||
public synchronized void controllerUpdate(ControllerEvent ce) {
|
||||
if(ce instanceof RealizeCompleteEvent) {
|
||||
player.prefetch();
|
||||
}
|
||||
if(ce instanceof PrefetchCompleteEvent) {
|
||||
Dimension dim = player.getPreferredSize();
|
||||
frm.pack();
|
||||
panel.setSize(dim);
|
||||
// player.setBounds(0, 0, w, h);
|
||||
frm.setSize(defaultSize);
|
||||
player.start();
|
||||
frm.show();
|
||||
}
|
||||
}
|
||||
|
||||
public JMPlayerInstance() {
|
||||
}
|
||||
|
||||
public void initialize(PlugletInstancePeer peer) {
|
||||
PlugletTagInfo2 info = (PlugletTagInfo2)peer.getTagInfo();
|
||||
w = info.getWidth();
|
||||
h = info.getHeight();
|
||||
defaultSize = new Dimension(w, h);
|
||||
this.peer = peer;
|
||||
}
|
||||
|
||||
public boolean playFile(String url) {
|
||||
player.setMediaLocator(new MediaLocator(url));
|
||||
if(player.getPlayer() == null) {
|
||||
return false;
|
||||
} else {
|
||||
player.addControllerListener(this);
|
||||
player.realize();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
player = new MediaPlayer();
|
||||
panel = new Panel();
|
||||
panel.add(player);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
(new Exception()).printStackTrace();
|
||||
player.stop();
|
||||
player.deallocate();
|
||||
player.close();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public PlugletStreamListener newStream() {
|
||||
org.mozilla.util.Debug.print("--TestInstance.newStream\n");
|
||||
JMPlayerStreamListener listener = new JMPlayerStreamListener();
|
||||
listener.setPlayer(this);
|
||||
return listener;
|
||||
}
|
||||
|
||||
public void setWindow(Frame frame) {
|
||||
if(frame == null) {
|
||||
return;
|
||||
}
|
||||
if(panel == null) {
|
||||
System.out.println("++ Initialize failed.");
|
||||
return;
|
||||
}
|
||||
// PlugletTagInfo2 info = (PlugletTagInfo2)peer.getTagInfo();
|
||||
// defaultSize = new Dimension(info.getWidth(), info.getHeight());
|
||||
frame.setSize(defaultSize);
|
||||
frame.setLayout(new BorderLayout());
|
||||
frame.add(panel);
|
||||
frm=frame;
|
||||
}
|
||||
|
||||
public void print(PrinterJob printerJob) {
|
||||
}
|
||||
}
|
||||
|
||||
class JMPlayerStreamListener implements PlugletStreamListener {
|
||||
JMPlayerInstance jmp;
|
||||
int total=0;
|
||||
|
||||
public JMPlayerStreamListener() {
|
||||
}
|
||||
|
||||
public void onStartBinding(PlugletStreamInfo streamInfo) {
|
||||
|
||||
|
||||
if(!jmp.playFile(streamInfo.getURL())) {
|
||||
System.out.println("++ Error starting player ");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setPlayer(JMPlayerInstance jmp) {
|
||||
this.jmp = jmp;
|
||||
}
|
||||
|
||||
public void onDataAvailable(PlugletStreamInfo streamInfo, InputStream input,int length) {
|
||||
}
|
||||
|
||||
public void onFileAvailable(PlugletStreamInfo plugletInfo, String fileName) {
|
||||
}
|
||||
|
||||
public void onStopBinding(PlugletStreamInfo plugletInfo,int status) {
|
||||
System.out.println("++ On stop binding.");
|
||||
}
|
||||
|
||||
public int getStreamType() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
43
mozilla/java/plugins/examples/MediaPlayer/README
Normal file
43
mozilla/java/plugins/examples/MediaPlayer/README
Normal file
@@ -0,0 +1,43 @@
|
||||
MediaPlayer Pluglet Example.
|
||||
================================
|
||||
|
||||
This directory contains the source code for MediaPlayer pluglet example.
|
||||
Pluglet is using Java Media Frameworks 2.0b MediaPlayer bean.
|
||||
|
||||
========================================================================
|
||||
Win32 Build Directions:
|
||||
========================================================================
|
||||
Requirements:
|
||||
|
||||
* built latest mozilla tree for WinNT4.0
|
||||
|
||||
* JDK1.3
|
||||
|
||||
* built Java-Implemented Plugins.
|
||||
|
||||
* JMF2.0b installed.
|
||||
|
||||
How To Build:
|
||||
|
||||
* add jmf.jar to classpath
|
||||
|
||||
* type "nmake /f makefile.win"
|
||||
|
||||
|
||||
How to Run:
|
||||
|
||||
* Follow the directions in ..\..\README
|
||||
|
||||
* Add jmf.jar to classpath
|
||||
|
||||
* Set PLUGLET environment to the directory you have JMPlayer.jar
|
||||
|
||||
* Run mozilla and load page play.html from this directory and you will see
|
||||
sample avi file. (In addition you need to download some avi file and
|
||||
name it test.avi.)
|
||||
|
||||
Warning: JMF MediaPlayer does not support all the video formats so you can
|
||||
see some errors from player when loading unsupported format file.
|
||||
|
||||
|
||||
|
||||
26
mozilla/java/plugins/examples/MediaPlayer/makefile.win
Normal file
26
mozilla/java/plugins/examples/MediaPlayer/makefile.win
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License
|
||||
# Version 1.0 (the "License"); you may not use this file except in
|
||||
# compliance with the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS"
|
||||
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
# the License for the specific language governing rights and limitations
|
||||
# under the License.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Sun Microsystems,
|
||||
# Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
|
||||
# Inc. All Rights Reserved.
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
.java.class:
|
||||
$(JDKHOME)\bin\javac -classpath "../../classes;$(CLASSPATH)" $<
|
||||
default: JMPlayer.jar
|
||||
JMPlayer.jar: JMPlayer.class manifest
|
||||
$(JDKHOME)\bin\jar cvfm JMPlayer.jar manifest *.class
|
||||
|
||||
clobber:
|
||||
-del *.class *.jar
|
||||
export: JMPlayer.jar
|
||||
copy *.jar $(PLUGLET)
|
||||
2
mozilla/java/plugins/examples/MediaPlayer/manifest
Normal file
2
mozilla/java/plugins/examples/MediaPlayer/manifest
Normal file
@@ -0,0 +1,2 @@
|
||||
MIMEDescription: video/mpeg;video/quicktime;video/avi:avi;mpg;mpeg;mov:Pluglet JMPlayer
|
||||
Pluglet-Class: JMPlayer
|
||||
5
mozilla/java/plugins/examples/MediaPlayer/play.html
Normal file
5
mozilla/java/plugins/examples/MediaPlayer/play.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<EMBED type="video/avi" name=JMPlayer SRC="test.avi" width=400 height=400>
|
||||
</body>
|
||||
</html>
|
||||
149
mozilla/java/plugins/examples/pdf/PDFView.java
Normal file
149
mozilla/java/plugins/examples/pdf/PDFView.java
Normal file
@@ -0,0 +1,149 @@
|
||||
import java.net.URL;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JEditorPane;
|
||||
import org.mozilla.pluglet.*;
|
||||
import org.mozilla.pluglet.mozilla.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.print.*;
|
||||
import java.io.*;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.adobe.acrobat.Viewer;
|
||||
|
||||
public class PDFView implements Pluglet {
|
||||
public PDFView() {
|
||||
}
|
||||
public PlugletInstance createPlugletInstance(String mimeType) {
|
||||
try {
|
||||
return new PDFViewInstance();
|
||||
} catch(Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void initialize(PlugletManager manager) {
|
||||
}
|
||||
public void shutdown() {
|
||||
}
|
||||
}
|
||||
|
||||
class PDFViewInstance extends Viewer implements PlugletInstance {
|
||||
JScrollPane view;
|
||||
com.adobe.acrobat.Viewer acr;
|
||||
Dimension defaultSize;
|
||||
JPanel panel;
|
||||
Frame frm;
|
||||
|
||||
public void displayPDF(byte[] b) {
|
||||
InputStream input = (InputStream)(new ByteArrayInputStream(b));
|
||||
frm.removeAll();
|
||||
try {
|
||||
acr = new com.adobe.acrobat.Viewer(false);
|
||||
acr.setDocumentInputStream(input);
|
||||
|
||||
// acr.zoomTo(1.0);
|
||||
acr.activate(); //WithoutBars()
|
||||
acr.execMenuItem(com.adobe.acrobat.ViewerCommand.OneColumn_K);
|
||||
acr.execMenuItem(com.adobe.acrobat.ViewerCommand.FitWidth_K);
|
||||
} catch(Exception e) {
|
||||
System.out.println("++ Error loading file.");
|
||||
}
|
||||
|
||||
acr.setSize(new Dimension(defaultSize.width, defaultSize.height));
|
||||
view.add(acr);
|
||||
view.setPreferredSize(defaultSize);
|
||||
frm.add(view);
|
||||
frm.pack();
|
||||
frm.show();
|
||||
}
|
||||
|
||||
|
||||
public PDFViewInstance() throws Exception {
|
||||
}
|
||||
|
||||
public void initialize(PlugletInstancePeer peer) {
|
||||
PlugletTagInfo2 info = (PlugletTagInfo2)peer.getTagInfo();
|
||||
defaultSize = new Dimension(info.getWidth(), info.getHeight());
|
||||
}
|
||||
public void start() {
|
||||
view = new JScrollPane();
|
||||
}
|
||||
public void stop() {
|
||||
frm.dispose();
|
||||
if(acr!=null) acr.deactivate();
|
||||
}
|
||||
public void destroy() {
|
||||
if(acr!=null) acr.destroy();
|
||||
}
|
||||
public PlugletStreamListener newStream() {
|
||||
PDFViewStreamListener listener = new PDFViewStreamListener();
|
||||
listener.setViewer(this);
|
||||
return listener;
|
||||
}
|
||||
public void setWindow(Frame frame) {
|
||||
if (frame == null) {
|
||||
return;
|
||||
}
|
||||
frm=frame;
|
||||
frm.setSize(defaultSize);
|
||||
}
|
||||
public void print(PrinterJob printerJob) {
|
||||
}
|
||||
}
|
||||
|
||||
class PDFViewStreamListener implements PlugletStreamListener {
|
||||
PDFViewInstance viewer;
|
||||
int total = 0, length = 0, first = 0;
|
||||
byte[] b, bb;
|
||||
Vector v = new Vector(20, 20);
|
||||
|
||||
public void setViewer(PDFViewInstance view) {
|
||||
viewer = view;
|
||||
}
|
||||
public PDFViewStreamListener() {
|
||||
}
|
||||
public void onStartBinding(PlugletStreamInfo streamInfo) {
|
||||
bb = new byte[streamInfo.getLength()];
|
||||
total = 0;
|
||||
first = 0;
|
||||
}
|
||||
|
||||
public void onDataAvailable(PlugletStreamInfo streamInfo, InputStream input,int length) {
|
||||
try {
|
||||
int size = input.available();
|
||||
int r = 0;
|
||||
b = new byte[size];
|
||||
|
||||
r=input.read(b);
|
||||
|
||||
for(int i=total;i<total+size;i++) {
|
||||
bb[i]=b[i-total];
|
||||
}
|
||||
total+=r;
|
||||
|
||||
if(total>=streamInfo.getLength()) {
|
||||
input.close();
|
||||
viewer.displayPDF(bb);
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onFileAvailable(PlugletStreamInfo streamInfo, String fileName) {
|
||||
}
|
||||
public void onStopBinding(PlugletStreamInfo streamInfo,int status) {
|
||||
}
|
||||
public int getStreamType() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
40
mozilla/java/plugins/examples/pdf/README
Normal file
40
mozilla/java/plugins/examples/pdf/README
Normal file
@@ -0,0 +1,40 @@
|
||||
MediaPlayer Pluglet Example.
|
||||
================================
|
||||
|
||||
This directory contains the source code for Pdf Viewer pluglet example.
|
||||
Pluglet is using Java "Acrobat Reader" bean.
|
||||
|
||||
========================================================================
|
||||
Win32 Build Directions:
|
||||
========================================================================
|
||||
Requirements:
|
||||
|
||||
* built latest mozilla tree for WinNT4.0
|
||||
|
||||
* JDK1.3
|
||||
|
||||
* built Java-Implemented Plugins.
|
||||
|
||||
* Java "Acrobat Reader" bean installed
|
||||
(http://beta1.adobe.com/acr_viewer/bean/bean.jar)
|
||||
|
||||
How To Build:
|
||||
|
||||
* add acrobat.jar to classpath
|
||||
|
||||
* type "nmake /f makefile.win"
|
||||
|
||||
|
||||
How to Run:
|
||||
|
||||
* Follow the directions in ..\..\README
|
||||
|
||||
* Add acrobat.jar to classpath
|
||||
|
||||
* Set PLUGLET environment to the directory you have PDFViewer.jar
|
||||
|
||||
* Run mozilla and load page pdf.html from this directory and you will see
|
||||
sample avi file. (In addition you need to download some pdf file and
|
||||
name it test.pdf)
|
||||
|
||||
|
||||
27
mozilla/java/plugins/examples/pdf/makefile.win
Normal file
27
mozilla/java/plugins/examples/pdf/makefile.win
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License
|
||||
# Version 1.0 (the "License"); you may not use this file except in
|
||||
# compliance with the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS"
|
||||
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
# the License for the specific language governing rights and limitations
|
||||
# under the License.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Sun Microsystems,
|
||||
# Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
|
||||
# Inc. All Rights Reserved.
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
.java.class:
|
||||
$(JDKHOME)\bin\javac -classpath "../../classes;$(CLASSPATH)" $<
|
||||
default: PDFView.jar
|
||||
PDFView.jar: PDFView.class manifest
|
||||
$(JDKHOME)\bin\jar cvfm PDFView.jar manifest *.class
|
||||
|
||||
clobber:
|
||||
-del *.class *.jar
|
||||
|
||||
export: PDFView.jar
|
||||
copy PDFView.jar $(PLUGLET)
|
||||
2
mozilla/java/plugins/examples/pdf/manifest
Normal file
2
mozilla/java/plugins/examples/pdf/manifest
Normal file
@@ -0,0 +1,2 @@
|
||||
MIMEDescription: application/pdf::Pluglet JView
|
||||
Pluglet-Class: PDFView
|
||||
5
mozilla/java/plugins/examples/pdf/pdf.html
Normal file
5
mozilla/java/plugins/examples/pdf/pdf.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<EMBED type="application/pdf" SRC="test.pdf" width=400 height=500>
|
||||
</body>
|
||||
</html>
|
||||
109
mozilla/java/plugins/examples/rtf/JView.java
Normal file
109
mozilla/java/plugins/examples/rtf/JView.java
Normal file
@@ -0,0 +1,109 @@
|
||||
import java.net.URL;
|
||||
import javax.swing.JPanel;
|
||||
//import javax.swing.JScrollPane;
|
||||
import javax.swing.JEditorPane;
|
||||
import org.mozilla.pluglet.*;
|
||||
import org.mozilla.pluglet.mozilla.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.print.*;
|
||||
import java.io.*;
|
||||
|
||||
public class JView implements Pluglet {
|
||||
public JView() {
|
||||
}
|
||||
public PlugletInstance createPlugletInstance(String mimeType) {
|
||||
return new JViewInstance();
|
||||
}
|
||||
public void initialize(PlugletManager manager) {
|
||||
}
|
||||
public void shutdown() {
|
||||
}
|
||||
}
|
||||
|
||||
class JViewInstance implements PlugletInstance {
|
||||
// JScrollPane view;
|
||||
ScrollPane view;
|
||||
JEditorPane viewPane;
|
||||
Dimension defaultSize;
|
||||
JPanel panel;
|
||||
Frame frm;
|
||||
|
||||
public void displayURL(String url) {
|
||||
frm.removeAll();
|
||||
try {
|
||||
url = url.replace('|', ':');
|
||||
viewPane.setPage(url);
|
||||
viewPane.setEditable(false);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error loading URL "+url);
|
||||
}
|
||||
view.add(viewPane);
|
||||
// viewPane.setPreferredSize(defaultSize);
|
||||
view.setSize(defaultSize);
|
||||
view.doLayout();
|
||||
frm.add(view, BorderLayout.CENTER);
|
||||
frm.pack();
|
||||
frm.setVisible(true);
|
||||
System.out.println("++ Showing");
|
||||
}
|
||||
|
||||
public JViewInstance() {
|
||||
}
|
||||
|
||||
public void initialize(PlugletInstancePeer peer) {
|
||||
PlugletTagInfo2 info = (PlugletTagInfo2)peer.getTagInfo();
|
||||
defaultSize = new Dimension(info.getWidth(), info.getHeight());
|
||||
}
|
||||
public void start() {
|
||||
view = new ScrollPane();
|
||||
viewPane = new JEditorPane();
|
||||
}
|
||||
public void stop() {
|
||||
frm.dispose();
|
||||
}
|
||||
public void destroy() {
|
||||
}
|
||||
public PlugletStreamListener newStream() {
|
||||
JViewStreamListener listener = new JViewStreamListener();
|
||||
listener.setViewer(this);
|
||||
return listener;
|
||||
}
|
||||
public void setWindow(Frame frame) {
|
||||
if (frame == null) {
|
||||
return;
|
||||
}
|
||||
frm=frame;
|
||||
frm.setSize(defaultSize);
|
||||
}
|
||||
public void print(PrinterJob printerJob) {
|
||||
}
|
||||
}
|
||||
|
||||
class JViewStreamListener implements PlugletStreamListener {
|
||||
JViewInstance viewer;
|
||||
|
||||
public void setViewer(JViewInstance view) {
|
||||
viewer = view;
|
||||
}
|
||||
public JViewStreamListener() {
|
||||
}
|
||||
public void onStartBinding(PlugletStreamInfo streamInfo) {
|
||||
viewer.displayURL(streamInfo.getURL());
|
||||
}
|
||||
public void onDataAvailable(PlugletStreamInfo streamInfo, InputStream input,int length) {
|
||||
}
|
||||
public void onFileAvailable(PlugletStreamInfo streamInfo, String fileName) {
|
||||
}
|
||||
public void onStopBinding(PlugletStreamInfo streamInfo,int status) {
|
||||
}
|
||||
public int getStreamType() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
33
mozilla/java/plugins/examples/rtf/README
Normal file
33
mozilla/java/plugins/examples/rtf/README
Normal file
@@ -0,0 +1,33 @@
|
||||
RTF viewer Pluglet Example.
|
||||
================================
|
||||
|
||||
This directory contains the source code for RTF files
|
||||
viewer pluglet example.
|
||||
|
||||
========================================================================
|
||||
Win32 Build Directions:
|
||||
========================================================================
|
||||
Requirements:
|
||||
|
||||
* built latest mozilla tree for WinNT4.0
|
||||
|
||||
* JDK1.3
|
||||
|
||||
* built Java-Implemented Plugins.
|
||||
|
||||
How To Build:
|
||||
|
||||
* type "nmake /f makefile.win"
|
||||
|
||||
|
||||
How to Run:
|
||||
|
||||
* Follow the directions in ..\..\README
|
||||
|
||||
* Set PLUGLET environment to the directory you have JView.jar
|
||||
|
||||
* Run mozilla and load page view.html from this directory and you will see
|
||||
this file in RTF format.
|
||||
|
||||
|
||||
|
||||
BIN
mozilla/java/plugins/examples/rtf/Readme.rtf
Normal file
BIN
mozilla/java/plugins/examples/rtf/Readme.rtf
Normal file
Binary file not shown.
26
mozilla/java/plugins/examples/rtf/makefile.win
Normal file
26
mozilla/java/plugins/examples/rtf/makefile.win
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License
|
||||
# Version 1.0 (the "License"); you may not use this file except in
|
||||
# compliance with the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS"
|
||||
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
# the License for the specific language governing rights and limitations
|
||||
# under the License.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Sun Microsystems,
|
||||
# Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
|
||||
# Inc. All Rights Reserved.
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
.java.class:
|
||||
$(JDKHOME)\bin\javac -classpath ../../classes $<
|
||||
default: JView.jar
|
||||
JView.jar: JView.class manifest
|
||||
$(JDKHOME)\bin\jar cvfm JView.jar manifest *.class
|
||||
|
||||
clobber:
|
||||
-del *.class *.jar
|
||||
export: JView.jar
|
||||
copy JView.jar $(PLUGLET)
|
||||
2
mozilla/java/plugins/examples/rtf/manifest
Normal file
2
mozilla/java/plugins/examples/rtf/manifest
Normal file
@@ -0,0 +1,2 @@
|
||||
MIMEDescription: application/rtf:rtf:Pluglet JView
|
||||
Pluglet-Class: JView
|
||||
5
mozilla/java/plugins/examples/rtf/view.html
Normal file
5
mozilla/java/plugins/examples/rtf/view.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<EMBED type="application/rtf" name=JView SRC="Readme.rtf" width=400 height=500>
|
||||
</body>
|
||||
</html>
|
||||
33
mozilla/java/plugins/examples/zip/README
Normal file
33
mozilla/java/plugins/examples/zip/README
Normal file
@@ -0,0 +1,33 @@
|
||||
ZipView Pluglet Example.
|
||||
================================
|
||||
|
||||
This directory contains the source code for zip compressed files
|
||||
viewer pluglet example.
|
||||
|
||||
========================================================================
|
||||
Win32 Build Directions:
|
||||
========================================================================
|
||||
Requirements:
|
||||
|
||||
* built latest mozilla tree for WinNT4.0
|
||||
|
||||
* JDK1.3
|
||||
|
||||
* built Java-Implemented Plugins.
|
||||
|
||||
How To Build:
|
||||
|
||||
* type "nmake /f makefile.win"
|
||||
|
||||
|
||||
How to Run:
|
||||
|
||||
* Follow the directions in ..\..\README
|
||||
|
||||
* Set PLUGLET environment to the directory you have ZipView.jar
|
||||
|
||||
* Run mozilla and load page zip.html from this directory and you will see
|
||||
the ZipView.jar contents.
|
||||
|
||||
|
||||
|
||||
381
mozilla/java/plugins/examples/zip/ZipView.java
Normal file
381
mozilla/java/plugins/examples/zip/ZipView.java
Normal file
@@ -0,0 +1,381 @@
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
|
||||
import org.mozilla.pluglet.*;
|
||||
import org.mozilla.pluglet.mozilla.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.print.*;
|
||||
import java.io.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
public class ZipView implements Pluglet {
|
||||
|
||||
public ZipView() {
|
||||
}
|
||||
|
||||
public PlugletInstance createPlugletInstance(String mimeType) {
|
||||
return new ZipInstance();
|
||||
}
|
||||
|
||||
public void initialize(PlugletManager manager) {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Node {
|
||||
public DefaultMutableTreeNode parent, name;
|
||||
|
||||
public Node(DefaultMutableTreeNode parent, DefaultMutableTreeNode name) {
|
||||
this.parent = parent;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
class ZipInstance implements PlugletInstance {
|
||||
Button extract;
|
||||
byte[] b;
|
||||
Frame frm;
|
||||
Panel panel;
|
||||
List contents;
|
||||
FileDialog fsd;
|
||||
boolean firstTime=true;
|
||||
JTree zipTree=null;
|
||||
Dimension defaultSize;
|
||||
String zname;
|
||||
|
||||
public ZipInstance() {
|
||||
|
||||
}
|
||||
|
||||
public void extractFileEntry(String name, String dir) {
|
||||
ZipInputStream zis = new ZipInputStream((InputStream)(new ByteArrayInputStream(b)));
|
||||
ZipEntry en;
|
||||
try {
|
||||
do {
|
||||
en = zis.getNextEntry();
|
||||
} while (!en.toString().equals(name));
|
||||
|
||||
int size=(int)en.getSize();
|
||||
byte[] buff = new byte[size];
|
||||
|
||||
String path=dir+name;
|
||||
int last = path.lastIndexOf('/');
|
||||
File dd=null, ff=null;
|
||||
if(last!=-1) {
|
||||
path=path.substring(0, last);
|
||||
dd = new File(path);
|
||||
dd.mkdirs();
|
||||
ff = new File(dir+name);
|
||||
} else {
|
||||
dd = new File(dir);
|
||||
dd.mkdirs();
|
||||
ff = new File(dir+name);
|
||||
}
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(ff);
|
||||
int r = 0;
|
||||
int t = 0;
|
||||
do {
|
||||
r = zis.read(buff, 0, size);
|
||||
fos.write(buff, 0, r);
|
||||
t+=r;
|
||||
} while(t<size);
|
||||
|
||||
fos.close();
|
||||
zis.close();
|
||||
|
||||
} catch(Exception e) {
|
||||
System.out.println("++ exception: "+e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void extractEntry(String name, String dir) {
|
||||
ZipInputStream zis = new ZipInputStream((InputStream)(new ByteArrayInputStream(b)));
|
||||
ZipEntry en;
|
||||
try {
|
||||
do {
|
||||
en = zis.getNextEntry();
|
||||
} while (!en.toString().equals(name));
|
||||
|
||||
if (!en.isDirectory()) {
|
||||
extractFileEntry(name, dir);
|
||||
return;
|
||||
}
|
||||
|
||||
en = zis.getNextEntry();
|
||||
while(en.toString().indexOf(name)==0) {
|
||||
if(!en.isDirectory())
|
||||
extractFileEntry(en.toString(), dir);
|
||||
en = zis.getNextEntry();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("++ Exception: "+e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void processData(byte[] bb, String fname) {
|
||||
this.zname = fname;
|
||||
this.b = bb;
|
||||
showTree();
|
||||
|
||||
extract.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
|
||||
if (zipTree == null) return;
|
||||
TreePath tp = zipTree.getSelectionPath();
|
||||
if (tp == null) return;
|
||||
Object[] elements = tp.getPath();
|
||||
|
||||
if (tp.getPathCount() == 1) return;
|
||||
String path=elements[1].toString()+'/';
|
||||
for(int i=2;i<tp.getPathCount();i++) {
|
||||
path+=elements[i].toString()+'/';
|
||||
}
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode)zipTree.getLastSelectedPathComponent();
|
||||
|
||||
if (node.isLeaf()) {
|
||||
path=path.substring(0, path.length()-1);
|
||||
}
|
||||
|
||||
|
||||
String dir;
|
||||
fsd = new FileDialog(frm, "Choose directory to extract", 1);
|
||||
fsd.setFile("ZipView");
|
||||
fsd.show();
|
||||
dir = fsd.getDirectory();
|
||||
if(dir==null) {
|
||||
return;
|
||||
}
|
||||
|
||||
extractEntry(path, dir);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void addElement(String name, Vector v) {
|
||||
Node nn, n;
|
||||
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(name);
|
||||
n = (Node)v.lastElement();
|
||||
nn = new Node(n.name, newNode);
|
||||
n.name.add(newNode);
|
||||
v.add(nn);
|
||||
|
||||
}
|
||||
|
||||
private void replaceElement(String name, Vector v, int depth) {
|
||||
Node n;
|
||||
int pos = 0;
|
||||
Enumeration e;
|
||||
|
||||
v.setSize(depth);
|
||||
|
||||
addElement(name, v);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void addNode(String path, Vector v) {
|
||||
String name=null;
|
||||
int start = 0, end = 0, depth = 1;
|
||||
Enumeration el;
|
||||
Node n, nn;
|
||||
boolean vacant=false;
|
||||
|
||||
el = v.elements();
|
||||
n = (Node)el.nextElement();
|
||||
|
||||
|
||||
do {
|
||||
end = path.indexOf('/', start);
|
||||
if (end>0) {
|
||||
name = path.substring(start, end);
|
||||
start = end+1;
|
||||
}
|
||||
else
|
||||
name = path.substring(start);
|
||||
|
||||
for(int i=1;i<=depth;i++) {
|
||||
if(!el.hasMoreElements()) {
|
||||
addElement(name, v);
|
||||
break;
|
||||
} else {
|
||||
n = (Node)el.nextElement();
|
||||
if(n.name.toString().equals(name)) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
replaceElement(name, v, depth);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
depth++;
|
||||
} while (end!=-1 && start<path.length());
|
||||
|
||||
}
|
||||
|
||||
private void createNodes(DefaultMutableTreeNode top) {
|
||||
DefaultMutableTreeNode category = null;
|
||||
DefaultMutableTreeNode book, book1 = null;
|
||||
String name=null;
|
||||
Vector v = new Vector(20, 20);
|
||||
int start=0, end = 0;
|
||||
|
||||
|
||||
ZipInputStream zis = new ZipInputStream((InputStream)(new ByteArrayInputStream(b)));
|
||||
ZipEntry en=null;
|
||||
|
||||
try {
|
||||
v.add(new Node(null, top));
|
||||
do {
|
||||
en = zis.getNextEntry();
|
||||
if(en!=null) {
|
||||
name = en.toString();
|
||||
addNode(name, v);
|
||||
}
|
||||
} while (zis.available()==1);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("++ Exception: "+e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void showTree() {
|
||||
DefaultMutableTreeNode top = new DefaultMutableTreeNode(zname);
|
||||
createNodes(top);
|
||||
|
||||
final JTree tree = new JTree(top);
|
||||
zipTree = tree;
|
||||
|
||||
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
|
||||
JScrollPane treePane = new JScrollPane(tree);
|
||||
treePane.setPreferredSize(defaultSize);
|
||||
panel.add(treePane);
|
||||
panel.setSize(treePane.getPreferredSize());
|
||||
frm.pack();
|
||||
frm.show();
|
||||
|
||||
}
|
||||
|
||||
public void initialize(PlugletInstancePeer peer) {
|
||||
PlugletTagInfo2 info = (PlugletTagInfo2)peer.getTagInfo();
|
||||
defaultSize = new Dimension(info.getWidth()-65, info.getHeight()-10);
|
||||
|
||||
}
|
||||
|
||||
public void start() {
|
||||
contents = new List(15, false);
|
||||
panel = new Panel();
|
||||
extract = new Button("Extract");
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
// panel.removeAll();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public PlugletStreamListener newStream() {
|
||||
ZipStreamListener listener = new ZipStreamListener();
|
||||
listener.setZip(this);
|
||||
return listener;
|
||||
}
|
||||
|
||||
public void setWindow(Frame frame) {
|
||||
if(frame == null) {
|
||||
return;
|
||||
}
|
||||
frame.setLayout(new BorderLayout());
|
||||
frame.setSize(defaultSize);
|
||||
frame.add(panel);
|
||||
panel.add(extract);
|
||||
frame.pack();
|
||||
frm=frame;
|
||||
}
|
||||
|
||||
public void print(PrinterJob printerJob) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ZipStreamListener implements PlugletStreamListener {
|
||||
int total = 0, length = 0, first = 0;
|
||||
ZipInstance zip;
|
||||
byte[] b, bb;
|
||||
Vector v = new Vector(20, 20);
|
||||
|
||||
public ZipStreamListener() {
|
||||
}
|
||||
|
||||
public void onStartBinding(PlugletStreamInfo streamInfo) {
|
||||
bb = new byte[streamInfo.getLength()];
|
||||
total = 0;
|
||||
first = 0;
|
||||
|
||||
}
|
||||
|
||||
public void setZip(ZipInstance zip) {
|
||||
this.zip=zip;
|
||||
}
|
||||
|
||||
public void onDataAvailable(PlugletStreamInfo streamInfo, InputStream input,int length) {
|
||||
String fname;
|
||||
fname = streamInfo.getURL();
|
||||
fname = fname.substring((fname.lastIndexOf('/'))+1);
|
||||
try {
|
||||
int size = input.available();
|
||||
int r = 0;
|
||||
b = new byte[size];
|
||||
|
||||
r=input.read(b);
|
||||
|
||||
for(int i=total;i<total+size;i++) {
|
||||
bb[i]=b[i-total];
|
||||
}
|
||||
total+=r;
|
||||
|
||||
if(total>=streamInfo.getLength()) {
|
||||
input.close();
|
||||
zip.processData(bb, fname);
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void onFileAvailable(PlugletStreamInfo streamInfo, String fileName) {
|
||||
}
|
||||
|
||||
public void onStopBinding(PlugletStreamInfo streamInfo,int status) {
|
||||
}
|
||||
|
||||
public int getStreamType() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
26
mozilla/java/plugins/examples/zip/makefile.win
Normal file
26
mozilla/java/plugins/examples/zip/makefile.win
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License
|
||||
# Version 1.0 (the "License"); you may not use this file except in
|
||||
# compliance with the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS"
|
||||
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
# the License for the specific language governing rights and limitations
|
||||
# under the License.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Sun Microsystems,
|
||||
# Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
|
||||
# Inc. All Rights Reserved.
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
.java.class:
|
||||
$(JDKHOME)\bin\javac -classpath ../../classes $<
|
||||
default: ZipView.jar
|
||||
ZipView.jar: ZipView.class manifest
|
||||
$(JDKHOME)\bin\jar cvfm ZipView.jar manifest *.class
|
||||
|
||||
clobber:
|
||||
-del *.class *.jar
|
||||
export: ZipView.jar
|
||||
copy ZipView.jar $(PLUGLET)
|
||||
2
mozilla/java/plugins/examples/zip/manifest
Normal file
2
mozilla/java/plugins/examples/zip/manifest
Normal file
@@ -0,0 +1,2 @@
|
||||
MIMEDescription: application/x-zip-compressed:zip:Pluglet ZipView
|
||||
Pluglet-Class: ZipView
|
||||
5
mozilla/java/plugins/examples/zip/zip.html
Normal file
5
mozilla/java/plugins/examples/zip/zip.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<EMBED type="application/x-zip-compressed" name=ZipView SRC="ZipView.jar" width=400 height=500>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user