From 67a48817be82fa38da2f31ffd0434114408c1056 Mon Sep 17 00:00:00 2001 From: "laa%sparc.spb.su" Date: Tue, 7 Mar 2000 08:33:54 +0000 Subject: [PATCH] Cleaned up pluglet examples sources (bug ID 17316). Reviewed by idk@eng.sun.com --- .../examples/MediaPlayer/JMPlayer.java | 39 +---------- java/plugins/examples/pdf/PDFView.java | 28 ++++---- java/plugins/examples/rtf/JView.java | 11 +-- java/plugins/examples/zip/ZipView.java | 69 +++++++------------ 4 files changed, 40 insertions(+), 107 deletions(-) diff --git a/java/plugins/examples/MediaPlayer/JMPlayer.java b/java/plugins/examples/MediaPlayer/JMPlayer.java index ebfcff0768d..cabac0ba166 100644 --- a/java/plugins/examples/MediaPlayer/JMPlayer.java +++ b/java/plugins/examples/MediaPlayer/JMPlayer.java @@ -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; } diff --git a/java/plugins/examples/pdf/PDFView.java b/java/plugins/examples/pdf/PDFView.java index 5aa97c51b16..9a458934c7a 100644 --- a/java/plugins/examples/pdf/PDFView.java +++ b/java/plugins/examples/pdf/PDFView.java @@ -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=streamInfo.getLength()) { + if (total >= streamInfo.getLength()) { input.close(); viewer.displayPDF(bb); } } catch(Exception e) { - System.out.println(e.toString()); } } diff --git a/java/plugins/examples/rtf/JView.java b/java/plugins/examples/rtf/JView.java index 506050cf28e..a08cae7fcb6 100644 --- a/java/plugins/examples/rtf/JView.java +++ b/java/plugins/examples/rtf/JView.java @@ -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) { diff --git a/java/plugins/examples/zip/ZipView.java b/java/plugins/examples/zip/ZipView.java index b19b04af738..19dc8dd97bc 100644 --- a/java/plugins/examples/zip/ZipView.java +++ b/java/plugins/examples/zip/ZipView.java @@ -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(t0) { + 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=streamInfo.getLength()) { + if (total >= streamInfo.getLength()) { input.close(); zip.processData(bb, fname); } } catch(Exception e) { - System.out.println(e.toString()); } }