Cleaned up pluglet examples sources (bug ID 17316).

Reviewed by idk@eng.sun.com
This commit is contained in:
laa%sparc.spb.su 2000-03-07 08:33:54 +00:00
Родитель 7956d87f43
Коммит 67a48817be
4 изменённых файлов: 40 добавлений и 107 удалений

Просмотреть файл

@ -7,7 +7,6 @@ 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.*;
@ -18,25 +17,20 @@ import java.util.*;
public class JMPlayer implements PlugletFactory {
public JMPlayer() {
}
public Pluglet createPluglet(String mimeType) {
return new Player();
}
public void initialize(PlugletManager manager) {
}
public void shutdown() {
}
}
class Player implements Pluglet, ControllerListener {
PlugletPeer peer;
Dimension defaultSize;
Frame frm;
int w, h;
MediaPlayer player = null;
Panel panel;
public synchronized void controllerUpdate(ControllerEvent ce) {
@ -47,24 +41,19 @@ class Player implements Pluglet, ControllerListener {
Dimension dim = player.getPreferredSize();
frm.pack();
panel.setSize(dim);
// player.setBounds(0, 0, w, h);
frm.setSize(defaultSize);
player.start();
frm.show();
}
}
public Player() {
}
public void initialize(PlugletPeer 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) {
@ -75,80 +64,56 @@ class Player implements Pluglet, ControllerListener {
}
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() {
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;
frm = frame;
}
public void print(PrinterJob printerJob) {
}
}
class JMPlayerStreamListener implements PlugletStreamListener {
Player jmp;
int total=0;
public JMPlayerStreamListener() {
}
public void onStartBinding(PlugletStreamInfo streamInfo) {
if(!jmp.playFile(streamInfo.getURL())) {
System.out.println("++ Error starting player ");
System.out.println("Error starting player.");
return;
}
}
public void setPlayer(Player 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;
}

Просмотреть файл

@ -42,12 +42,10 @@ class AcrobatView extends Viewer implements Pluglet {
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));
@ -70,11 +68,14 @@ class AcrobatView extends Viewer implements Pluglet {
view = new JScrollPane();
}
public void stop() {
frm.dispose();
if(acr!=null) acr.deactivate();
if (acr != null) {
acr.deactivate();
}
}
public void destroy() {
if(acr!=null) acr.destroy();
if (acr != null) {
acr.destroy();
}
}
public PlugletStreamListener newStream() {
PDFViewStreamListener listener = new PDFViewStreamListener();
@ -85,7 +86,7 @@ class AcrobatView extends Viewer implements Pluglet {
if (frame == null) {
return;
}
frm=frame;
frm = frame;
frm.setSize(defaultSize);
}
public void print(PrinterJob printerJob) {
@ -94,9 +95,8 @@ class AcrobatView extends Viewer implements Pluglet {
class PDFViewStreamListener implements PlugletStreamListener {
AcrobatView viewer;
int total = 0, length = 0, first = 0;
int total = 0;
byte[] b, bb;
Vector v = new Vector(20, 20);
public void setViewer(AcrobatView view) {
viewer = view;
@ -106,7 +106,6 @@ class PDFViewStreamListener implements PlugletStreamListener {
public void onStartBinding(PlugletStreamInfo streamInfo) {
bb = new byte[streamInfo.getLength()];
total = 0;
first = 0;
}
public void onDataAvailable(PlugletStreamInfo streamInfo, InputStream input,int length) {
@ -115,20 +114,19 @@ class PDFViewStreamListener implements PlugletStreamListener {
int r = 0;
b = new byte[size];
r=input.read(b);
r = input.read(b);
for(int i=total;i<total+size;i++) {
bb[i]=b[i-total];
for (int i = total; i < total + size; i++) {
bb[i] = b[i-total];
}
total+=r;
total += r;
if(total>=streamInfo.getLength()) {
if (total >= streamInfo.getLength()) {
input.close();
viewer.displayPDF(bb);
}
} catch(Exception e) {
System.out.println(e.toString());
}
}

Просмотреть файл

@ -1,6 +1,4 @@
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.*;
@ -22,11 +20,9 @@ public class JView implements PlugletFactory {
}
class RTFView implements Pluglet {
// JScrollPane view;
ScrollPane view;
JEditorPane viewPane;
Dimension defaultSize;
JPanel panel;
Frame frm;
public void displayURL(String url) {
@ -39,18 +35,14 @@ class RTFView implements Pluglet {
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 RTFView() {
}
public void initialize(PlugletPeer peer) {
PlugletTagInfo2 info = (PlugletTagInfo2)peer.getTagInfo();
defaultSize = new Dimension(info.getWidth(), info.getHeight());
@ -60,7 +52,6 @@ class RTFView implements Pluglet {
viewPane = new JEditorPane();
}
public void stop() {
frm.dispose();
}
public void destroy() {
}
@ -73,7 +64,7 @@ class RTFView implements Pluglet {
if (frame == null) {
return;
}
frm=frame;
frm = frame;
frm.setSize(defaultSize);
}
public void print(PrinterJob printerJob) {

Просмотреть файл

@ -1,5 +1,4 @@
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
@ -48,9 +47,7 @@ class ZipDecoder implements Pluglet {
byte[] b;
Frame frm;
Panel panel;
List contents;
FileDialog fsd;
boolean firstTime=true;
JTree zipTree=null;
Dimension defaultSize;
String zname;
@ -72,8 +69,8 @@ class ZipDecoder implements Pluglet {
String path=dir+name;
int last = path.lastIndexOf('/');
File dd=null, ff=null;
if(last!=-1) {
File dd = null, ff = null;
if (last != -1) {
path=path.substring(0, last);
dd = new File(path);
dd.mkdirs();
@ -90,14 +87,13 @@ class ZipDecoder implements Pluglet {
do {
r = zis.read(buff, 0, size);
fos.write(buff, 0, r);
t+=r;
} while(t<size);
t += r;
} while (t < size);
fos.close();
zis.close();
} catch(Exception e) {
System.out.println("++ exception: "+e.toString());
}
}
@ -116,13 +112,12 @@ class ZipDecoder implements Pluglet {
}
en = zis.getNextEntry();
while(en.toString().indexOf(name)==0) {
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());
}
}
@ -141,14 +136,14 @@ class ZipDecoder implements Pluglet {
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()+'/';
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);
path = path.substring(0, path.length() - 1);
}
@ -157,7 +152,7 @@ class ZipDecoder implements Pluglet {
fsd.setFile("ZipView");
fsd.show();
dir = fsd.getDirectory();
if(dir==null) {
if (dir == null) {
return;
}
@ -179,15 +174,8 @@ class ZipDecoder implements Pluglet {
}
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) {
@ -203,15 +191,15 @@ class ZipDecoder implements Pluglet {
do {
end = path.indexOf('/', start);
if (end>0) {
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()) {
for (int i=1; i<=depth; i++) {
if (!el.hasMoreElements()) {
addElement(name, v);
break;
} else {
@ -226,34 +214,30 @@ class ZipDecoder implements Pluglet {
}
}
depth++;
} while (end!=-1 && start<path.length());
} while (end != -1 && start < path.length());
}
private void createNodes(DefaultMutableTreeNode top) {
DefaultMutableTreeNode category = null;
DefaultMutableTreeNode book, book1 = null;
String name=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;
ZipEntry en = null;
try {
v.add(new Node(null, top));
do {
en = zis.getNextEntry();
if(en!=null) {
if (en != null) {
name = en.toString();
addNode(name, v);
}
} while (zis.available()==1);
} while (zis.available() == 1);
} catch (Exception e) {
System.out.println("++ Exception: "+e.toString());
}
}
@ -282,13 +266,11 @@ class ZipDecoder implements Pluglet {
}
public void start() {
contents = new List(15, false);
panel = new Panel();
extract = new Button("Extract");
}
public void stop() {
// panel.removeAll();
}
public void destroy() {
@ -301,7 +283,7 @@ class ZipDecoder implements Pluglet {
}
public void setWindow(Frame frame) {
if(frame == null) {
if (frame == null) {
return;
}
frame.setLayout(new BorderLayout());
@ -318,7 +300,7 @@ class ZipDecoder implements Pluglet {
}
class ZipStreamListener implements PlugletStreamListener {
int total = 0, length = 0, first = 0;
int total = 0;
ZipDecoder zip;
byte[] b, bb;
Vector v = new Vector(20, 20);
@ -329,8 +311,6 @@ class ZipStreamListener implements PlugletStreamListener {
public void onStartBinding(PlugletStreamInfo streamInfo) {
bb = new byte[streamInfo.getLength()];
total = 0;
first = 0;
}
public void setZip(ZipDecoder zip) {
@ -348,18 +328,17 @@ class ZipStreamListener implements PlugletStreamListener {
r=input.read(b);
for(int i=total;i<total+size;i++) {
bb[i]=b[i-total];
for (int i = total; i < total + size; i++) {
bb[i] = b[i-total];
}
total+=r;
total += r;
if(total>=streamInfo.getLength()) {
if (total >= streamInfo.getLength()) {
input.close();
zip.processData(bb, fname);
}
} catch(Exception e) {
System.out.println(e.toString());
}
}