Back to index

wims  3.65+svn20090927
MainApplet.java
Go to the documentation of this file.
00001 /*
00002   J.M. Evers 5/2009
00003   trying to produce an applet from a opensource spreadsheet java application.
00004 */
00005 
00006 package SharpTools;
00007 
00008 import java.io.*;
00009 import java.awt.*;
00010 import java.awt.event.*;
00011 import java.util.*;
00012 import javax.swing.*;
00013 import java.net.*;
00014 
00015 
00016 public class MainApplet extends JApplet  {
00017   SharpTools sharptools=null;
00018   public String visible="TRUE";
00019   public static boolean inapplet=true;
00020   public boolean matrix=true;
00021   // instead of a configfile, a tunable paramlist;
00022   public static int ROWS;
00023   public static int COLUMNS;
00024   public static int FIRSTCOLUMNWIDTH;
00025   public static int COLUMNWIDTH;
00026   public static boolean SAVEWINDOW=false;
00027   public static int X;
00028   public static int Y;
00029   public static int WIDTH;
00030   public static int HEIGHT;
00031   public static int HISTOGRAMWIDTH;
00032   public static int HISTOGRAMHEIGHT;
00033   public static boolean TOOLBAR_NEW=false;
00034   public static boolean TOOLBAR_OPEN=false;
00035   public static boolean TOOLBAR_SAVE=false;
00036   public static boolean TOOLBAR_PASSWORD=false;
00037   public static boolean TOOLBAR_PRINT=true;
00038   public static boolean TOOLBAR_UNDO=true;
00039   public static boolean TOOLBAR_REDO=true;
00040   public static boolean TOOLBAR_CUT=true;
00041   public static boolean TOOLBAR_COPY=true;
00042   public static boolean TOOLBAR_PASTE=true;
00043   public static boolean TOOLBAR_FIND=true;
00044   public static boolean TOOLBAR_INSERTROW=true;
00045   public static boolean TOOLBAR_INSERTCOLUMN=true;
00046   public static boolean TOOLBAR_DELETEROW=true;
00047   public static boolean TOOLBAR_DELETECOLUMN=true;
00048   public static boolean TOOLBAR_SORTCOLUMN=true;
00049   public static boolean TOOLBAR_HISTOGRAM=true;
00050   public static boolean TOOLBAR_HELP=true;
00051   public static boolean TOOLBAR_FUNCTIONS=true;
00052   public static int NUMCONNECTIONS=5;
00053   public static String CONNECTION1NAME="";
00054   public static String CONNECTION1USERNAME="";
00055   public static String CONNECTION1PASSWORD="";
00056   public static String CONNECTION1URL="";
00057   public static String CONNECTION1DRIVER="";
00058   public static int RECENTFILELIST=8;
00059   public static String RECENTFILE0="";
00060   public static String RECENTFILE1="";
00061   public static String RECENTFILE2="";
00062   public static String RECENTFILE3="";
00063   public static String RECENTFILE4="";
00064   public static String RECENTFILE5="";
00065   public static String RECENTFILE6="";
00066   public static String RECENTFILE7="";
00067   public static String AppletReply="";
00068   public String language="en";
00069   Font defaultFont = new Font( "Helvetica", Font.BOLD, 14 );
00070   Color green=new Color(0,255,0);                                                      
00071   Color red=new Color(255,0,0);
00072   Color current_color=new Color(0,255,0);
00073   
00074   private Container container;
00075   private JButton OpenButton;
00076   private JButton CloseButton;
00077   ImageIcon OpenIcon=new ImageIcon(getClass().getResource("/images/start.gif"));
00078   ImageIcon CloseIcon=new ImageIcon(getClass().getResource("/images/close.gif"));
00079   String Tooltip_open="Open spreadsheet";
00080   String Tooltip_close="Close spreadsheet";
00081   
00082   
00083   
00084   
00085   
00086   
00087   public void init(){
00088     container = this.getContentPane();                                                        
00089     container.setLayout(new BorderLayout());
00090     OpenButton = new JButton(OpenIcon);
00091     OpenButton.setToolTipText(Tooltip_open);
00092     CloseButton = new JButton(CloseIcon);
00093     CloseButton.setToolTipText(Tooltip_close);
00094     container.add(OpenButton,BorderLayout.EAST);
00095     container.add(CloseButton,BorderLayout.WEST);
00096     container.validate();
00097     
00098     OpenButton.addActionListener (new ActionListener(){                                                                              
00099             public void actionPerformed (ActionEvent evt){
00100               visible="TRUE";
00101               ShowSpreadSheet(visible);
00102            }                                                                                                                          
00103        }
00104     ); 
00105 
00106     CloseButton.addActionListener (new ActionListener(){                                                                              
00107             public void actionPerformed (ActionEvent evt){
00108               visible="FALSE";
00109               ShowSpreadSheet(visible);
00110            }                                                                                                                          
00111        }
00112     ); 
00113     
00114     String c;
00115     c=getParameter("language");
00116     String nee="no";
00117     if(c.equalsIgnoreCase("en") || c.equalsIgnoreCase("nl") || c.equalsIgnoreCase("fr") ){
00118        language=c.toLowerCase(); 
00119        if(language.equals("nl")){ nee = "nee";}
00120        else
00121        if(language.equals("fr")){ nee = "non";}
00122        else
00123        if(language.equals("de")){ nee = "nein";}
00124     }
00125     else
00126     {
00127         language="en";
00128     }
00129 
00130     //c=getParameter("TOOLBAR_OPEN") cannot be set: it's an applet
00131     //c=getParameter("TOOLBAR_SAVE")  cannot be set: it's an applet
00132     //c=getParameter("TOOLBAR_PASSWORD") cannot be set: it's an applet
00133     c=getParameter("show_applet_on_start");   
00134     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){visible="FALSE";}}
00135     c=getParameter("matrix_format");   
00136     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){matrix=false;}}
00137 
00138     c=getParameter("COLUMNS");   
00139     if(c != null && c.length()>0){COLUMNS = Integer.parseInt(c,10);}else{ COLUMNS = 10;}
00140     c=getParameter("ROWS");    
00141     if(c != null && c.length()>0){ROWS = Integer.parseInt(c,10);}else{ ROWS = 10;}
00142     c=getParameter("COLUMNWIDTH");
00143     if(c != null && c.length()>0){COLUMNWIDTH = Integer.parseInt(c,10);}else{ COLUMNWIDTH = 80;}
00144     c=getParameter("FIRSTCOLUMNWIDTH");
00145     if(c != null && c.length()>0){FIRSTCOLUMNWIDTH = Integer.parseInt(c,10);}else{ FIRSTCOLUMNWIDTH = 25;}
00146     c=getParameter("X");    
00147     if(c != null && c.length()>0){X = Integer.parseInt(c,10);}else{ X=640;}
00148     c=getParameter("Y");    
00149     if(c != null && c.length()>0){Y = Integer.parseInt(c,10);}else{ Y=420;}
00150     c=getParameter("WIDTH");    
00151     if(c != null && c.length()>0){WIDTH = Integer.parseInt(c,10);}else{ WIDTH = 760;}
00152     c=getParameter("HEIGHT");    
00153     if(c != null && c.length()>0){HEIGHT = Integer.parseInt(c,10);}else{ HEIGHT = 484;}
00154     c=getParameter("HISTOGRAMWIDTH");    
00155     if(c != null && c.length()>0){HISTOGRAMWIDTH = Integer.parseInt(c,10);}else{ HISTOGRAMWIDTH = 500;}
00156     c=getParameter("HISTOGRAMHEIGHT");    
00157     if(c != null && c.length()>0){HISTOGRAMHEIGHT = Integer.parseInt(c,10);}else{ HISTOGRAMHEIGHT = 400;}
00158     c=getParameter("TOOLBAR_NEW");
00159     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_NEW=false;}}
00160     c=getParameter("TOOLBAR_PRINT");
00161     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_PRINT=false;}}
00162     c=getParameter("TOOLBAR_UNDO");
00163     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_UNDO=false;}}
00164     c=getParameter("TOOLBAR_REDO");
00165     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_REDO=false;}}
00166     c=getParameter("TOOLBAR_CUT");
00167     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_CUT=false;}}
00168     c=getParameter("TOOLBAR_COPY");
00169     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_COPY=false;}} 
00170     c=getParameter("TOOLBAR_PASTE");
00171     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_PASTE=false;}} 
00172     c=getParameter("TOOLBAR_FIND");
00173     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_FIND=false;}}
00174     c=getParameter("TOOLBAR_INSERTROW");
00175     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_INSERTROW=false;}}
00176     c=getParameter("TOOLBAR_INSERTCOLUMN");
00177     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_INSERTCOLUMN=false;}} 
00178     c=getParameter("TOOLBAR_DELETEROW");
00179     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_DELETEROW=false;}}
00180     c=getParameter("TOOLBAR_DELETECOLUMN");
00181     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_DELETECOLUMN=false;}}
00182     c=getParameter("TOOLBAR_SORTCOLUMN");
00183     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_SORTCOLUMN=false;}}
00184     c=getParameter("TOOLBAR_HISTOGRAM");
00185     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_HISTOGRAM=false;}}
00186     c=getParameter("TOOLBAR_HELP");
00187     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_HELP=false;}}
00188     c=getParameter("TOOLBAR_FUNCTIONS");
00189     if(c != null && c.length()>0){if(c.equals("0") || c.equalsIgnoreCase(nee) || c.equalsIgnoreCase("FALSE")){TOOLBAR_FUNCTIONS=false;}}
00190 
00191     sharptools=new SharpTools(inapplet,language);
00192     sharptools.setVisible(false);
00193     repaint();
00194 
00195   }
00196   
00197   public void stop(){}
00198   public void destroy(){}
00199   public void run(){}
00200   public void start(){}
00201   
00202   public String ReadRawApplet(){//send data in tab-separated format to Javascript
00203        AppletReply=sharptools.ReadRawSpreadSheet();
00204        return AppletReply;
00205   }
00206   
00207   public String ReadApplet(){//send data in tab-separated or matrix format to Javascript
00208        // default [1,2,3;4,5,6]
00209        AppletReply=sharptools.ReadSpreadSheet(matrix);
00210        return AppletReply;
00211   }
00212   
00213   public void ShowSpreadSheet(String start){
00214        if(start.equalsIgnoreCase("start") || start.equalsIgnoreCase("true") || start.equalsIgnoreCase("show") ){
00215            sharptools.setVisible(true);
00216        }
00217        if(start.equalsIgnoreCase("stop") || start.equalsIgnoreCase("false") || start.equalsIgnoreCase("hide")){
00218            sharptools.setVisible(false);
00219        }
00220     repaint();
00221   }
00222 }
00223 
00224 
00225 /*
00226   public static byte [] loadURL(URL url) throws IOException {
00227   // jm.evers :handy functions !!! not mine :(
00228   int bufSize = 1024 * 2;
00229        byte [] buf = new byte[bufSize];
00230        ByteArrayOutputStream bout = new ByteArrayOutputStream();
00231        BufferedInputStream in = new BufferedInputStream(url.openStream());
00232        int n;
00233        while ((n = in.read(buf)) > 0) {
00234          bout.write(buf, 0, n);
00235        }
00236        try 
00237        { in.close(); } catch (Exception ignored) { }
00238        return bout.toByteArray();
00239   }
00240 
00241   public static String loadFile(String fname) throws IOException {
00242   // jm.evers :handy functions !!! not mine :(
00243        byte[] bytes = loadURL(new URL("file:" + fname));
00244        return new String(bytes);
00245   }
00246   
00247   public static String load(String fileOrURL) throws IOException {
00248   // jm.evers :handy functions !!! not mine :(
00249        try {
00250          URL url = new URL(fileOrURL);
00251          return new String(loadURL(url));
00252        } catch (Exception e) {
00253        return loadFile(fileOrURL);
00254        }
00255   }
00256 */