/* * JDataGridBeanApplet.java * * Created on 2006Äê11ÔÂ11ÈÕ, ÏÂÎç8:18 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package com.zfqjava.swing; import java.awt.BorderLayout; import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JApplet; /** * JDataGridApplet provides a standard applet based * on the JDataGrid component. *

* JDataGridApplet support the following parameters: * * * * * * * * * * * * * * * * * * * * * * *
Parameter NameParameter ValueParameter Description
openUrlurlURL load data into datagrid
saveUrlurlURL save data from datagrid
saveFormatonew of xls, xml, txt, csv, html, htm, serThe file format to save
saveFileNamestringThe File name to save, the default is the file name of open url
downloadPathurlThe path to download the saved file, relative to current applet webpage
licenseUrlurlThe path to load the license data
* Note: *

* @author Administrator */ public class JDataGridBeanApplet extends JApplet { private static final Logger log = Logger.getLogger(JDataGridBeanApplet.class.getName()); private URL openUrl; private URL saveUrl; private URL downloadPath; private String saveFileName; private String saveFormat; private JDataGridBean bean; private URL licenseUrl; /** Creates a new instance of JDataGridBeanApplet */ public JDataGridBeanApplet() { } public void init() { fetchParameters(); readLicense(); getContentPane().setLayout(new BorderLayout()); bean = createDataGridBean(); getContentPane().add(bean, BorderLayout.CENTER); doOpen(); } protected JDataGridBean createDataGridBean() { JDataGridBean bean = new JDataGridBean(); return bean; } private void fetchParameters() { String openUrlString = getParameter("openUrl"); // openUrlString = "products/datagrid/applet/test.xls"; String saveUrlString = getParameter("saveUrl"); String saveFileNameString = getParameter("saveFileName"); String saveFormatString = getParameter("saveFormat"); String downloadPathString = getParameter("downloadPath"); String licenseUrlString = getParameter("licenseUrl"); URL url = this.getDocumentBase(); openUrl = AppletUtils.convertToAbsolute(url, openUrlString); saveUrl = AppletUtils.convertToAbsolute(url, saveUrlString); downloadPath = AppletUtils.convertToAbsoluteImpl(url, downloadPathString); licenseUrl = AppletUtils.convertToAbsolute(url, licenseUrlString); saveFileName = AppletUtils.getFileName(openUrl, saveFileNameString); saveFormat = AppletUtils.getFileFormat(saveFileName, saveFormatString); // saveFormat = checkSaveFormat(saveFormatString); // System.out.println("documentBase="+this.getDocumentBase()); // System.out.println("codeBase="+this.getCodeBase()); // System.out.println("openUrl="+openUrl); } private void readLicense() { try { AppletUtils.readLicense(licenseUrl); } catch (Exception ex) { if(log.isLoggable(Level.FINEST)) { log.log(Level.FINEST, "readLicense failed", ex); } } } public String[][] getParameterInfo() { String pinfo[][] = { {"openUrl", "url", "URL load data into datagrid, relative to current applet webpage"}, {"saveUrl", "url", "URL save data from datagrid, relative to current applet webpage"}, {"saveFormat", "xls, xml, txt, csv, html, htm, ser", "The file format to save, the default is the file format of open url"}, {"saveFileName", "string", "The File name to save, the default is the file name of open url"}, {"downloadPath", "url", "The path to download the saved file, relative to current applet webpage"}, {"licenseUrl", "url", "The path to load the license data"} }; return pinfo; } private void doOpen() { if(this.openUrl != null) { bean.doOpen(new URL[] {this.openUrl}); } } private void doSave() { if(!DataGridUtils.isFormatSupported(this.saveFormat)) { if(log.isLoggable(Level.FINER)) { log.log(Level.FINER, "the saveFormat is not supported: " + this.saveFormat); } return; } String fileName = AppletUtils.generateRandomFileName(this.saveFileName,this.saveFormat); if(fileName == null) { if(log.isLoggable(Level.FINER)) { log.log(Level.FINER, "fileName is null, cannot execute save operation"); } return; } URL urlObject = this.saveUrl; if(urlObject == null) { if(log.isLoggable(Level.FINER)) { log.log(Level.FINER, "saveUrl is null, cannot execute save operation"); } return; } URL downloadUrl = AppletUtils.getURLforBase(downloadPath, fileName); bean.doSaveImpl(urlObject, fileName, downloadUrl); } public void doDownload() { doSave(); } }