public Iterator getStreamKeys(){ // We do nothing. return null; } /** * System parameters. */ static Hashtable systemParam = new Hashtable(); static { systemParam.put("codebase", "codebase"); systemParam.put("code", "code"); systemParam.put("alt", "alt"); systemParam.put("width", "width"); systemParam.put("height", "height"); systemParam.put("align", "align"); systemParam.put("vspace", "vspace"); systemParam.put("hspace", "hspace"); } /** * Print the HTML tag. */ public static void printTag(PrintStream out, Hashtable atts) { out.print("<applet"); String v = (String)atts.get("codebase"); if (v != null) { out.print(" codebase=\"" + v + "\""); } v = (String)atts.get("code"); if (v == null) { v = "applet.class"; } out.print(" code=\"" + v + "\""); v = (String)atts.get("width"); if (v == null) { v = "150"; } out.print(" width=" + v); v = (String)atts.get("height"); if (v == null) { v = "100"; } out.print(" height=" + v); v = (String)atts.get("name"); if (v != null) { out.print(" name=\"" + v + "\""); } out.println(">"); // A very slow sorting algorithm int len = atts.size(); String params[] = new String[len]; len = 0; for (Enumeration e = atts.keys() ; e.hasMoreElements() ;) { String param = (String)e.nextElement(); int i = 0; for (; i < len ; i++) { if (params[i].compareTo(param) >= 0) { break; } } System.arraycopy(params, i, params, i + 1, len - i); params[i] = param; len++; } for (int i = 0 ; i < len ; i++) { String param = params[i]; if (systemParam.get(param) == null) { out.println("<param name=" + param + " value=\"" + atts.get(param) + "\">"); } } out.println("</applet>"); } /** * Make sure the atrributes are uptodate. */ public void updateAtts() { Dimension d = panel.size(); Insets in = panel.insets(); panel.atts.put("width", Integer.toString(d.width - (in.left + in.right))); panel.atts.put("height", Integer.toString(d.height - (in.top + in.bottom))); } /** * Restart the applet. */ void appletRestart() { panel.sendEvent(AppletPanel.APPLET_STOP); panel.sendEvent(AppletPanel.APPLET_DESTROY); panel.sendEvent(AppletPanel.APPLET_INIT); panel.sendEvent(AppletPanel.APPLET_START); } /** * Reload the applet. */ void appletReload() { panel.sendEvent(AppletPanel.APPLET_STOP); panel.sendEvent(AppletPanel.APPLET_DESTROY); panel.sendEvent(AppletPanel.APPLET_DISPOSE); /** * Fixed #4501142: Classlaoder sharing policy doesn't * take "archive" into account. This will be overridden * by Java Plug-in. [stanleyh] */ AppletPanel.flushClassLoader(panel.getClassLoaderCacheKey()); /* * Make sure we don't have two threads running through the event queue * at the same time. */ try { panel.joinAppletThread(); panel.release(); } catch (InterruptedException e) { return; // abort the reload } panel.createAppletThread(); panel.sendEvent(AppletPanel.APPLET_LOAD); panel.sendEvent(AppletPanel.APPLET_INIT); panel.sendEvent(AppletPanel.APPLET_START); } /** * Save the applet to a well known file (for now) as a serialized object */ void appletSave() { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { // XXX: this privileged block should be made smaller // by initializing a private static variable with "user.dir" // Applet needs to be stopped for serialization to succeed. // Since panel.sendEvent only queues the event, there is a // chance that the event will not be processed before // serialization begins. However, by sending the event before // FileDialog is created, enough time is given such that this // situation is unlikely to ever occur. panel.sendEvent(AppletPanel.APPLET_STOP); FileDialog fd = new FileDialog(AppletViewer.this, amh.getMessage("appletsave.filedialogtitle"), FileDialog.SAVE); // needed for a bug under Solaris... fd.setDirectory(System.getProperty("user.dir")); fd.setFile(defaultSaveFile); fd.show(); String fname = fd.getFile(); if (fname == null) { // Restart applet if Save is cancelled. panel.sendEvent(AppletPanel.APPLET_START); return null; // cancelled } String dname = fd.getDirectory(); File file = new File(dname, fname); try { BufferedOutputStream s = new BufferedOutputStream(new FileOutputStream(file)); ObjectOutputStream os = new ObjectOutputStream(s); showStatus(amh.getMessage("appletsave.err1", panel.applet.toString(), file.toString())); os.writeObject(panel.applet); } catch (IOException ex) { System.err.println(amh.getMessage("appletsave.err2", ex)); } finally { panel.sendEvent(AppletPanel.APPLET_START); } return null; } }); } /** * Clone the viewer and the applet. */ void appletClone() { Point p = location(); updateAtts(); factory.createAppletViewer(p.x + XDELTA, p.y + YDELTA, panel.documentURL, (Hashtable)panel.atts.clone()); } /** * Show the applet tag. */ void appletTag() { ByteArrayOutputStream out = new ByteArrayOutputStream(); updateAtts(); printTag(new PrintStream(out), panel.atts); showStatus(amh.getMessage("applettag")); Point p = location(); new TextFrame(p.x + XDELTA, p.y + YDELTA, amh.getMessage("applettag.textframe"), out.toString()); } /** * Show the applet info. */ void appletInfo() { String str = panel.applet.getAppletInfo(); if (str == null) { str = amh.getMessage("appletinfo.applet"); } str += "\n\n"; String atts[][] = panel.applet.getParameterInfo(); if (atts != null) { for (int i = 0 ; i < atts.length ; i++) { str += atts[i][0] + " -- " + atts[i][1] + " -- " + atts[i][2] + "\n"; } } else { str += amh.getMessage("appletinfo.param"); } Point p = location(); new TextFrame(p.x + XDELTA, p.y + YDELTA, amh.getMessage("appletinfo.textframe"), str); } /** * Show character encoding type */ void appletCharacterEncoding() { showStatus(amh.getMessage("appletencoding", encoding)); } /** * Edit the applet. */ void appletEdit() { } /** * Print the applet. */ void appletPrint() { PrinterJob pj = PrinterJob.getPrinterJob(); if (pj != null) { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); if (pj.printDialog(aset)) { pj.setPrintable(this); try { pj.print(aset); statusMsgStream.println(amh.getMessage("appletprint.finish")); } catch (PrinterException e) { statusMsgStream.println(amh.getMessage("appletprint.fail")); } } else { statusMsgStream.println(amh.getMessage("appletprint.cancel")); } } else { statusMsgStream.println(amh.getMessage("appletprint.fail")); } } public int print(Graphics graphics, PageFormat pf, int pageIndex) { if (pageIndex > 0) { return Printable.NO_SUCH_PAGE; } else { Graphics2D g2d = (Graphics2D)graphics; g2d.translate(pf.getImageableX(), pf.getImageableY()); panel.applet.printAll(graphics); return Printable.PAGE_EXISTS; } } /** * Properties. */ static AppletProps props; public static synchronized void networkProperties() { if (props == null) { props = new AppletProps(); } props.addNotify(); props.setVisible(true); } /** * Start the applet. */ void appletStart() { panel.sendEvent(AppletPanel.APPLET_START); } /** * Stop the applet. */ void appletStop() { panel.sendEvent(AppletPanel.APPLET_STOP); } /** * Shutdown a viewer. * Stop, Destroy, Dispose and Quit a viewer */ private void appletShutdown(AppletPanel p) { p.sendEvent(AppletPanel.APPLET_STOP); p.sendEvent(AppletPanel.APPLET_DESTROY); p.sendEvent(AppletPanel.APPLET_DISPOSE); p.sendEvent(AppletPanel.APPLET_QUIT); } /** * Close this viewer. * Stop, Destroy, Dispose and Quit an AppletView, then * reclaim resources and exit the program if this is * the last applet. */ void appletClose() { // The caller thread is event dispatch thread, so // spawn a new thread to avoid blocking the event queue // when calling appletShutdown. // final AppletPanel p = panel; new Thread(new Runnable() { public void run() { appletShutdown(p); appletPanels.removeElement(p); dispose(); if (countApplets() == 0) { appletSystemExit(); } } }).start(); } /** * Exit the program. * Exit from the program (if not stand alone) - do no clean-up */ private void appletSystemExit() { if (factory.isStandalone()) System.exit(0); } /** * Quit all viewers. * Shutdown all viewers properly then * exit from the program (if not stand alone) */ protected void appletQuit() { // The caller thread is event dispatch thread, so // spawn a new thread to avoid blocking the event queue // when calling appletShutdown. // new Thread(new Runnable() { public void run() { for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { AppletPanel p = (AppletPanel)e.nextElement(); appletShutdown(p); } appletSystemExit(); } }).start(); } /** * Handle events. */ public void processUserAction(ActionEvent evt) { String label = ((MenuItem)evt.getSource()).getLabel(); if (amh.getMessage("menuitem.restart").equals(label)) { appletRestart(); return; } if (amh.getMessage("menuitem.reload").equals(label)) { appletReload(); return; } if (amh.getMessage("menuitem.clone").equals(label)) { appletClone(); return; } if (amh.getMessage("menuitem.stop").equals(label)) { appletStop(); return; } if (amh.getMessage("menuitem.save").equals(label)) { appletSave(); return; } if (amh.getMessage("menuitem.start").equals(label)) { appletStart(); return; } if (amh.getMessage("menuitem.tag").equals(label)) { appletTag(); return; } if (amh.getMessage("menuitem.info").equals(label)) { appletInfo(); return; } if (amh.getMessage("menuitem.encoding").equals(label)) { appletCharacterEncoding(); return; } if (amh.getMessage("menuitem.edit").equals(label)) { appletEdit(); return; } if (amh.getMessage("menuitem.print").equals(label)) { appletPrint(); return; } if (amh.getMessage("menuitem.props").equals(label)) { networkProperties(); return; } if (amh.getMessage("menuitem.close").equals(label)) { appletClose(); return; } if (factory.isStandalone() && amh.getMessage("menuitem.quit").equals(label)) { appletQuit(); return; } //statusMsgStream.println("evt = " + evt); } /** * How many applets are running? */ public static int countApplets() { return appletPanels.size(); } /** * The current character. */ static int c; /** * Scan spaces. */ public static void skipSpace(Reader in) throws IOException { while ((c >= 0) && ((c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'))) { c = in.read(); } } /** * Scan identifier */ public static String scanIdentifier(Reader in) throws IOException { StringBuffer buf = new StringBuffer(); while (true) { if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_')) { buf.append((char)c); c = in.read(); } else { return buf.toString(); } } } Lines 501–1000 of 1278. Previous lines Load more
public Iterator getStreamKeys(){ // We do nothing. return null; } /** * System parameters. */ static Hashtable systemParam = new Hashtable(); static { systemParam.put("codebase", "codebase"); systemParam.put("code", "code"); systemParam.put("alt", "alt"); systemParam.put("width", "width"); systemParam.put("height", "height"); systemParam.put("align", "align"); systemParam.put("vspace", "vspace"); systemParam.put("hspace", "hspace"); } /** * Print the HTML tag. */ public static void printTag(PrintStream out, Hashtable atts) { out.print("<applet"); String v = (String)atts.get("codebase"); if (v != null) { out.print(" codebase=\"" + v + "\""); } v = (String)atts.get("code"); if (v == null) { v = "applet.class"; } out.print(" code=\"" + v + "\""); v = (String)atts.get("width"); if (v == null) { v = "150"; } out.print(" width=" + v); v = (String)atts.get("height"); if (v == null) { v = "100"; } out.print(" height=" + v); v = (String)atts.get("name"); if (v != null) { out.print(" name=\"" + v + "\""); } out.println(">"); // A very slow sorting algorithm int len = atts.size(); String params[] = new String[len]; len = 0; for (Enumeration e = atts.keys() ; e.hasMoreElements() ;) { String param = (String)e.nextElement(); int i = 0; for (; i < len ; i++) { if (params[i].compareTo(param) >= 0) { break; } } System.arraycopy(params, i, params, i + 1, len - i); params[i] = param; len++; } for (int i = 0 ; i < len ; i++) { String param = params[i]; if (systemParam.get(param) == null) { out.println("<param name=" + param + " value=\"" + atts.get(param) + "\">"); } } out.println("</applet>"); } /** * Make sure the atrributes are uptodate. */ public void updateAtts() { Dimension d = panel.size(); Insets in = panel.insets(); panel.atts.put("width", Integer.toString(d.width - (in.left + in.right))); panel.atts.put("height", Integer.toString(d.height - (in.top + in.bottom))); } /** * Restart the applet. */ void appletRestart() { panel.sendEvent(AppletPanel.APPLET_STOP); panel.sendEvent(AppletPanel.APPLET_DESTROY); panel.sendEvent(AppletPanel.APPLET_INIT); panel.sendEvent(AppletPanel.APPLET_START); } /** * Reload the applet. */ void appletReload() { panel.sendEvent(AppletPanel.APPLET_STOP); panel.sendEvent(AppletPanel.APPLET_DESTROY); panel.sendEvent(AppletPanel.APPLET_DISPOSE); /** * Fixed #4501142: Classlaoder sharing policy doesn't * take "archive" into account. This will be overridden * by Java Plug-in. [stanleyh] */ AppletPanel.flushClassLoader(panel.getClassLoaderCacheKey()); /* * Make sure we don't have two threads running through the event queue * at the same time. */ try { panel.joinAppletThread(); panel.release(); } catch (InterruptedException e) { return; // abort the reload } panel.createAppletThread(); panel.sendEvent(AppletPanel.APPLET_LOAD); panel.sendEvent(AppletPanel.APPLET_INIT); panel.sendEvent(AppletPanel.APPLET_START); } /** * Save the applet to a well known file (for now) as a serialized object */ void appletSave() { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { // XXX: this privileged block should be made smaller // by initializing a private static variable with "user.dir" // Applet needs to be stopped for serialization to succeed. // Since panel.sendEvent only queues the event, there is a // chance that the event will not be processed before // serialization begins. However, by sending the event before // FileDialog is created, enough time is given such that this // situation is unlikely to ever occur. panel.sendEvent(AppletPanel.APPLET_STOP); FileDialog fd = new FileDialog(AppletViewer.this, amh.getMessage("appletsave.filedialogtitle"), FileDialog.SAVE); // needed for a bug under Solaris... fd.setDirectory(System.getProperty("user.dir")); fd.setFile(defaultSaveFile); fd.show(); String fname = fd.getFile(); if (fname == null) { // Restart applet if Save is cancelled. panel.sendEvent(AppletPanel.APPLET_START); return null; // cancelled } String dname = fd.getDirectory(); File file = new File(dname, fname); try { BufferedOutputStream s = new BufferedOutputStream(new FileOutputStream(file)); ObjectOutputStream os = new ObjectOutputStream(s); showStatus(amh.getMessage("appletsave.err1", panel.applet.toString(), file.toString())); os.writeObject(panel.applet); } catch (IOException ex) { System.err.println(amh.getMessage("appletsave.err2", ex)); } finally { panel.sendEvent(AppletPanel.APPLET_START); } return null; } }); } /** * Clone the viewer and the applet. */ void appletClone() { Point p = location(); updateAtts(); factory.createAppletViewer(p.x + XDELTA, p.y + YDELTA, panel.documentURL, (Hashtable)panel.atts.clone()); } /** * Show the applet tag. */ void appletTag() { ByteArrayOutputStream out = new ByteArrayOutputStream(); updateAtts(); printTag(new PrintStream(out), panel.atts); showStatus(amh.getMessage("applettag")); Point p = location(); new TextFrame(p.x + XDELTA, p.y + YDELTA, amh.getMessage("applettag.textframe"), out.toString()); } /** * Show the applet info. */ void appletInfo() { String str = panel.applet.getAppletInfo(); if (str == null) { str = amh.getMessage("appletinfo.applet"); } str += "\n\n"; String atts[][] = panel.applet.getParameterInfo(); if (atts != null) { for (int i = 0 ; i < atts.length ; i++) { str += atts[i][0] + " -- " + atts[i][1] + " -- " + atts[i][2] + "\n"; } } else { str += amh.getMessage("appletinfo.param"); } Point p = location(); new TextFrame(p.x + XDELTA, p.y + YDELTA, amh.getMessage("appletinfo.textframe"), str); } /** * Show character encoding type */ void appletCharacterEncoding() { showStatus(amh.getMessage("appletencoding", encoding)); } /** * Edit the applet. */ void appletEdit() { } /** * Print the applet. */ void appletPrint() { PrinterJob pj = PrinterJob.getPrinterJob(); if (pj != null) { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); if (pj.printDialog(aset)) { pj.setPrintable(this); try { pj.print(aset); statusMsgStream.println(amh.getMessage("appletprint.finish")); } catch (PrinterException e) { statusMsgStream.println(amh.getMessage("appletprint.fail")); } } else { statusMsgStream.println(amh.getMessage("appletprint.cancel")); } } else { statusMsgStream.println(amh.getMessage("appletprint.fail")); } } public int print(Graphics graphics, PageFormat pf, int pageIndex) { if (pageIndex > 0) { return Printable.NO_SUCH_PAGE; } else { Graphics2D g2d = (Graphics2D)graphics; g2d.translate(pf.getImageableX(), pf.getImageableY()); panel.applet.printAll(graphics); return Printable.PAGE_EXISTS; } } /** * Properties. */ static AppletProps props; public static synchronized void networkProperties() { if (props == null) { props = new AppletProps(); } props.addNotify(); props.setVisible(true); } /** * Start the applet. */ void appletStart() { panel.sendEvent(AppletPanel.APPLET_START); } /** * Stop the applet. */ void appletStop() { panel.sendEvent(AppletPanel.APPLET_STOP); } /** * Shutdown a viewer. * Stop, Destroy, Dispose and Quit a viewer */ private void appletShutdown(AppletPanel p) { p.sendEvent(AppletPanel.APPLET_STOP); p.sendEvent(AppletPanel.APPLET_DESTROY); p.sendEvent(AppletPanel.APPLET_DISPOSE); p.sendEvent(AppletPanel.APPLET_QUIT); } /** * Close this viewer. * Stop, Destroy, Dispose and Quit an AppletView, then * reclaim resources and exit the program if this is * the last applet. */ void appletClose() { // The caller thread is event dispatch thread, so // spawn a new thread to avoid blocking the event queue // when calling appletShutdown. // final AppletPanel p = panel; new Thread(new Runnable() { public void run() { appletShutdown(p); appletPanels.removeElement(p); dispose(); if (countApplets() == 0) { appletSystemExit(); } } }).start(); } /** * Exit the program. * Exit from the program (if not stand alone) - do no clean-up */ private void appletSystemExit() { if (factory.isStandalone()) System.exit(0); } /** * Quit all viewers. * Shutdown all viewers properly then * exit from the program (if not stand alone) */ protected void appletQuit() { // The caller thread is event dispatch thread, so // spawn a new thread to avoid blocking the event queue // when calling appletShutdown. // new Thread(new Runnable() { public void run() { for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { AppletPanel p = (AppletPanel)e.nextElement(); appletShutdown(p); } appletSystemExit(); } }).start(); } /** * Handle events. */ public void processUserAction(ActionEvent evt) { String label = ((MenuItem)evt.getSource()).getLabel(); if (amh.getMessage("menuitem.restart").equals(label)) { appletRestart(); return; } if (amh.getMessage("menuitem.reload").equals(label)) { appletReload(); return; } if (amh.getMessage("menuitem.clone").equals(label)) { appletClone(); return; } if (amh.getMessage("menuitem.stop").equals(label)) { appletStop(); return; } if (amh.getMessage("menuitem.save").equals(label)) { appletSave(); return; } if (amh.getMessage("menuitem.start").equals(label)) { appletStart(); return; } if (amh.getMessage("menuitem.tag").equals(label)) { appletTag(); return; } if (amh.getMessage("menuitem.info").equals(label)) { appletInfo(); return; } if (amh.getMessage("menuitem.encoding").equals(label)) { appletCharacterEncoding(); return; } if (amh.getMessage("menuitem.edit").equals(label)) { appletEdit(); return; } if (amh.getMessage("menuitem.print").equals(label)) { appletPrint(); return; } if (amh.getMessage("menuitem.props").equals(label)) { networkProperties(); return; } if (amh.getMessage("menuitem.close").equals(label)) { appletClose(); return; } if (factory.isStandalone() && amh.getMessage("menuitem.quit").equals(label)) { appletQuit(); return; } //statusMsgStream.println("evt = " + evt); } /** * How many applets are running? */ public static int countApplets() { return appletPanels.size(); } /** * The current character. */ static int c; /** * Scan spaces. */ public static void skipSpace(Reader in) throws IOException { while ((c >= 0) && ((c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'))) { c = in.read(); } } /** * Scan identifier */ public static String scanIdentifier(Reader in) throws IOException { StringBuffer buf = new StringBuffer(); while (true) { if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_')) { buf.append((char)c); c = in.read(); } else { return buf.toString(); } } }