Back to index

wims  3.65+svn20090927
SharpTools.java
Go to the documentation of this file.
00001 /*
00002  * @(#)SharpTools.java
00003  * 
00004  * $Id: SharpTools.java,v 1.178 2002/08/08 05:15:08 huaz Exp $
00005  * 
00006  * Created on October 10, 2000, 1:15 AM
00007  */
00008 package SharpTools;
00009 import javax.swing.*;
00010 import javax.swing.table.*;
00011 import javax.swing.border.*;
00012 import javax.swing.event.*;
00013 import java.awt.*;
00014 import java.awt.event.*;
00015 import java.util.*;
00016 import java.io.*;
00017 import java.net.*;
00018 
00031 final public class SharpTools extends JFrame implements ListSelectionListener {
00032     /* jm.evers */
00033     SharpTools spreadsheet;
00034     static boolean inapplet=false; 
00035     static String language="en";
00036     public static Properties translation=new Properties(); 
00037     protected int maxNumPage = 1;
00038 
00039     // the rest of the components
00040     private Container container;
00041     private JTable table;
00042     private JScrollPane scrollPane;
00043     private JToolBar toolBar;
00044     private JMenuBar menuBar;
00045     private JPanel barPanel;
00046     private History history;
00047     private Histogram histogram;
00048     public SharpOptionPane sharpoptionpane;
00049 
00050     static private Config config;
00051 
00052     private SharpTableModel tableModel;
00053     private ListSelectionModel rowSelectionModel;
00054     private ListSelectionModel columnSelectionModel;
00055 
00056     private URL url;
00057 
00058     // these are used to access our global objects
00059     static public Config getConfig() { return config; }    
00060     
00061     public History getHistory() { return history; }
00062     public JTable getTable() { return table; }
00063     public SharpTableModel getTableModel() { return tableModel; }
00064     public JToolBar getToolBar() { return toolBar; }
00065     //public JMenuBar getMenuBar() { return menuBar; }
00066     private FileOp fileOp;
00067     private EditOp editOp;
00068     private TableOp tableOp;
00069     //    private HelpOp helpOp;
00070 
00071     // initialize JMenu fields
00072     // menu headings
00073     private JMenu fileMenu;
00074     private JMenu openMenu;
00075     private JMenu recentMenu;
00076     private JMenu editMenu;
00077     private JMenu tableMenu;
00078     private JMenu chartMenu;
00079     private JMenu helpMenu;
00080        // submenu headings
00081     private JMenu insertMenu;
00082     private JMenu deleteMenu;
00083     private JMenu sortMenu;
00084     //    private JMenuItem menuItem;
00085     private JMenuItem saveMenuItem;
00086     private JCheckBoxMenuItem saveOnExitMenuItem;
00087     private JMenuItem undoMenuItem;
00088     private JMenuItem redoMenuItem;
00089     private JMenuItem findNextMenuItem;
00090     private JCheckBoxMenuItem showHistogramMenuItem;
00091     private JCheckBoxMenuItem showFunctionsMenuItem;
00092     
00093     private JButton exitButton;
00094     private JButton saveButton;
00095     private JButton passwordButton;
00096     private JButton undoButton;
00097     private JButton redoButton;
00098     private JComponent funcList;
00099     //    private JCheckBox showButton;
00100     ImageIcon newIcon=new ImageIcon(getClass().getResource("/images/new.gif"));
00101     ImageIcon openIcon=new ImageIcon(getClass().getResource("/images/open.gif"));
00102     ImageIcon saveIcon=new ImageIcon(getClass().getResource("/images/save.gif"));
00103     ImageIcon unlockedIcon=new ImageIcon(getClass().getResource("/images/unlocked.gif"));
00104     ImageIcon lockedIcon=new ImageIcon(getClass().getResource("/images/locked.gif"));
00105     ImageIcon printIcon=new ImageIcon(getClass().getResource("/images/print.gif"));
00106     ImageIcon undoIcon=new ImageIcon(getClass().getResource("/images/undo.gif"));
00107     ImageIcon redoIcon=new ImageIcon(getClass().getResource("/images/redo.gif"));
00108     ImageIcon cutIcon=new ImageIcon(getClass().getResource("/images/cut.gif"));
00109     ImageIcon copyIcon=new ImageIcon(getClass().getResource("/images/copy.gif"));
00110     ImageIcon pasteIcon=new ImageIcon(getClass().getResource("/images/paste.gif"));
00111     ImageIcon findIcon=new ImageIcon(getClass().getResource("/images/find.gif"));
00112     ImageIcon insertRowIcon=new ImageIcon(getClass().getResource("/images/insertrow.gif"));
00113     ImageIcon insertColumnIcon=new ImageIcon(getClass().getResource("/images/insertcolumn.gif"));
00114     ImageIcon deleteRowIcon=new ImageIcon(getClass().getResource("/images/deleterow.gif"));
00115     ImageIcon deleteColumnIcon=new ImageIcon(getClass().getResource("/images/deletecolumn.gif"));
00116     ImageIcon sortIcon=new ImageIcon(getClass().getResource("/images/sort.gif"));
00117     ImageIcon chartIcon=new ImageIcon(getClass().getResource("/images/chart.gif"));
00118     ImageIcon helpIcon=new ImageIcon(getClass().getResource("/images/help.gif"));
00119     ImageIcon exitIcon=new ImageIcon(getClass().getResource("/images/no.gif"));
00120     
00121     public static int baseRow = 0;
00122     public static int baseCol = 1;
00123     public int firstColWidth;
00124     private CellRange cellrange;
00126     public SharpTools(boolean is_this_the_applet,String lang) {       
00127         super("Sharp_Tools_Spreadsheet");
00128        //     setIconImage(Toolkit.getDefaultToolkit().getImage("tools.jpg")); 
00129        int x;
00130        int y;
00131        language=lang;
00132        System.out.println("in Sharptools.java the language="+language);
00133        
00134        if(is_this_the_applet){
00135            inapplet = true;
00136            x = MainApplet.X;                                                                                                                
00137             y = MainApplet.Y;
00138        }
00139        else
00140        {
00141            x = config.getInt("X");
00142            y = config.getInt("Y");
00143        }
00144        translation=loadProperties(language);
00145        Dimension scrdim = getToolkit().getScreenSize();
00146 
00147        // make sure the point is valid
00148        if (x>=0 && y>=0 &&
00149            x<(int)scrdim.getWidth() && y <(int)scrdim.getHeight())
00150            setLocation(x, y);
00151        
00152        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
00153         // get content pane
00154        container = this.getContentPane();
00155        container.setLayout(new BorderLayout());
00156 
00157        // create the table
00158        table = new JTable();
00159 
00160        // create the Functions combobox in the table
00161        funcList = HelpOp.createFunctionListComponent(this, table);
00162        
00163        // set up fileMenu
00164         fileMenu = new JMenu("File", true);
00165        fileMenu.setMnemonic(KeyEvent.VK_F); //used constructor instead
00166        // add fileMenu actions
00167        JMenuItem menuItem = new JMenuItem(translation.getProperty("New"));
00168        menuItem.setMnemonic(KeyEvent.VK_N);
00169         menuItem.setAccelerator(KeyStroke.getKeyStroke(
00170                             KeyEvent.VK_N, ActionEvent.CTRL_MASK));
00171        menuItem.addActionListener (new ActionListener () {
00172                 public void actionPerformed (ActionEvent evt) {
00173                   if(!inapplet){fileOp.newFile();}else{ReStart();}
00174               }
00175            });
00176        fileMenu.add(menuItem);
00177        if(!inapplet){
00178            // SJK Added
00179            openMenu = new JMenu (translation.getProperty("Open"));
00180            openMenu.setMnemonic (KeyEvent.VK_O);
00181            menuItem = new JMenuItem (translation.getProperty("File"));
00182            menuItem.setMnemonic (KeyEvent.VK_F);
00183            menuItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_O, ActionEvent.CTRL_MASK));
00184            menuItem.addActionListener (new ActionListener () {
00185               public void actionPerformed (ActionEvent evt) {
00186                   fileOp.openFile ();
00187               }
00188            } );
00189            openMenu.add (menuItem);
00190            menuItem = new JMenuItem (translation.getProperty("Database"));
00191            menuItem.setMnemonic (KeyEvent.VK_D);
00192            menuItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_D, ActionEvent.CTRL_MASK));
00193            menuItem.addActionListener (new ActionListener () {
00194               public void actionPerformed (ActionEvent evt) {
00195                   fileOp.openDb ();
00196               }
00197            } );
00198            openMenu.add (menuItem);
00199            fileMenu.add (openMenu);
00200            // use provate member for further reference
00201            saveMenuItem = new JMenuItem(translation.getProperty("Save"));
00202            saveMenuItem.setMnemonic(KeyEvent.VK_S);
00203            saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
00204            saveMenuItem.addActionListener (new ActionListener () {
00205                 public void actionPerformed (ActionEvent evt) {
00206                   fileOp.saveFile();
00207               }
00208            });
00209            fileMenu.add(saveMenuItem);
00210        
00211            menuItem = new JMenuItem(translation.getProperty("Save_As"));
00212            menuItem.setMnemonic(KeyEvent.VK_A);
00213            //        menuItem.setAccelerator(KeyStroke.getKeyStroke(
00214            //                      KeyEvent.VK_A, ActionEvent.CTRL_MASK));
00215            menuItem.addActionListener (new ActionListener () {
00216               public void actionPerformed (ActionEvent evt) {
00217                   fileOp.saveAsFile();
00218               }
00219            });
00220            fileMenu.add(menuItem);
00221            
00222            menuItem = new JMenuItem(translation.getProperty("Set_Password"));
00223            menuItem.setMnemonic(KeyEvent.VK_E);
00224            menuItem.addActionListener (new ActionListener () {
00225                 public void actionPerformed (ActionEvent evt) {
00226                   fileOp.setPassword();
00227                   checkPasswordState();
00228               }
00229            });
00230            fileMenu.add(menuItem);
00231            fileMenu.addSeparator();
00232            menuItem = new JMenuItem(translation.getProperty("Print"));
00233            menuItem.setMnemonic(KeyEvent.VK_P); //used constructor instead
00234            menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
00235            menuItem.addActionListener (new ActionListener () {
00236                 public void actionPerformed (ActionEvent evt) {
00237                   //notYetImplemented();         
00238                   Thread runner = new Thread() {
00239                          public void run() {
00240                             fileOp.printData();
00241                          }
00242                      };
00243                   runner.start(); 
00244               }
00245            });
00246            fileMenu.add(menuItem);
00247            fileMenu.addSeparator();
00248 
00249            recentMenu = new JMenu(translation.getProperty("Recent_Files"));
00250            recentMenu.setMnemonic(KeyEvent.VK_R); //used constructor instead
00251            recentMenu.addMenuListener(new MenuListener() {
00252               public void menuCanceled(MenuEvent e) {}
00253               public void menuDeselected(MenuEvent e) {}
00254               public void menuSelected(MenuEvent e) {
00255                   fileOp.createRecentFilesMenu(recentMenu);
00256               }
00257            });
00258        
00259            fileMenu.add(recentMenu);
00260        
00261            fileMenu.addSeparator();
00262 
00263            //set up Save Window on Exit
00264            saveOnExitMenuItem = new JCheckBoxMenuItem(translation.getProperty("Save_Window_on_Exit"));
00265            saveOnExitMenuItem.setMnemonic(KeyEvent.VK_W);
00266            saveOnExitMenuItem.addActionListener (new ActionListener () {
00267                 public void actionPerformed (ActionEvent evt) {
00268                   config.setBoolean("SAVEWINDOW", saveOnExitMenuItem.isSelected());
00269               }
00270            });
00271            // initialize
00272            saveOnExitMenuItem.setSelected(config.getBoolean("SAVEWINDOW"));
00273            fileMenu.add(saveOnExitMenuItem);
00274            fileMenu.addSeparator();
00275            menuItem = new JMenuItem(translation.getProperty("Exit"));
00276            menuItem.setMnemonic(KeyEvent.VK_X);
00277            menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
00278            menuItem.addActionListener (new ActionListener () {
00279                 public void actionPerformed (ActionEvent evt) {
00280                   //exitMenuActionPerformed(evt);
00281                   exit();
00282               }
00283            });
00284            fileMenu.add(menuItem);
00285        } // einde if(!inapplet){}
00286        
00287        //Set up Edit menu
00288        editMenu = new JMenu(translation.getProperty("Edit"), true);
00289        editMenu.setMnemonic(KeyEvent.VK_E);
00290 
00291         // Undo
00292         undoMenuItem = new JMenuItem(translation.getProperty("Undo"));
00293         undoMenuItem.setMnemonic(KeyEvent.VK_U);
00294         undoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
00295        undoMenuItem.addActionListener (new ActionListener () {
00296             public void actionPerformed (ActionEvent evt) {
00297               // save current selection
00298               history.undo(tableModel);
00299            }
00300        });
00301         editMenu.add(undoMenuItem);
00302 
00303        // Redo
00304        redoMenuItem = new JMenuItem(translation.getProperty("Redo"));
00305         redoMenuItem.setMnemonic(KeyEvent.VK_R);
00306         redoMenuItem.setAccelerator(KeyStroke.getKeyStroke(
00307                             KeyEvent.VK_Y, ActionEvent.CTRL_MASK));
00308        redoMenuItem.addActionListener (new ActionListener () {
00309                 public void actionPerformed (ActionEvent evt) {
00310                   history.redo(tableModel);
00311               }
00312            });
00313         editMenu.add(redoMenuItem);
00314        editMenu.addSeparator();
00315 
00316        // cut
00317        menuItem = new JMenuItem(translation.getProperty("Cut"));
00318        menuItem.setMnemonic(KeyEvent.VK_T); 
00319        menuItem.setAccelerator(KeyStroke.getKeyStroke(
00320                             KeyEvent.VK_X, ActionEvent.CTRL_MASK));
00321        menuItem.addActionListener (new ActionListener () {
00322                 public void actionPerformed (ActionEvent evt) {
00323                   editOp.cut();
00324                 }
00325             });
00326        editMenu.add(menuItem);
00327 
00328        // copy
00329        menuItem = new JMenuItem(translation.getProperty("Copy"));
00330         menuItem.setMnemonic(KeyEvent.VK_C); 
00331        menuItem.setAccelerator(KeyStroke.getKeyStroke(
00332                             KeyEvent.VK_C, ActionEvent.CTRL_MASK));
00333        menuItem.addActionListener (new ActionListener () {
00334                 public void actionPerformed (ActionEvent evt) {
00335                   editOp.copy();
00336               }
00337            });
00338        editMenu.add(menuItem);
00339 
00340        // paste
00341        menuItem = new JMenuItem(translation.getProperty("Paste"));
00342        menuItem.setMnemonic(KeyEvent.VK_P); 
00343        menuItem.setAccelerator(KeyStroke.getKeyStroke
00344                             (KeyEvent.VK_V, ActionEvent.CTRL_MASK));
00345        menuItem.addActionListener (new ActionListener () {
00346                 public void actionPerformed (ActionEvent evt) {
00347                   editOp.paste();
00348               }
00349            });
00350        editMenu.add(menuItem);
00351        editMenu.addSeparator();
00352 
00353        // Fill
00354        menuItem = new JMenuItem(translation.getProperty("Fill"));
00355        menuItem.setMnemonic(KeyEvent.VK_F);
00356         menuItem.setAccelerator(KeyStroke.getKeyStroke
00357                             (KeyEvent.VK_L, ActionEvent.CTRL_MASK));
00358        menuItem.addActionListener (new ActionListener () {
00359                 public void actionPerformed (ActionEvent evt) {
00360                 editOp.fill();
00361               }
00362            }); 
00363        editMenu.add(menuItem);
00364 
00365        // Clear
00366        menuItem = new JMenuItem(translation.getProperty("Clear"));
00367        menuItem.setMnemonic(KeyEvent.VK_L);
00368        menuItem.setAccelerator(KeyStroke.getKeyStroke
00369                             (KeyEvent.VK_DELETE, 0, true));
00370        menuItem.addActionListener (new ActionListener () {
00371                 public void actionPerformed (ActionEvent evt) {
00372                   editOp.clear();
00373               }
00374            });
00375        editMenu.add(menuItem);
00376        editMenu.addSeparator();
00377 
00378        // Find
00379        menuItem = new JMenuItem(translation.getProperty("Find"));
00380        menuItem.setMnemonic(KeyEvent.VK_F);
00381         menuItem.setAccelerator(KeyStroke.getKeyStroke
00382                             (KeyEvent.VK_F, ActionEvent.CTRL_MASK));
00383        menuItem.addActionListener (new ActionListener () {
00384                 public void actionPerformed (ActionEvent evt) {
00385                   editOp.find(true);
00386               }
00387            });
00388        editMenu.add(menuItem);
00389        
00390        findNextMenuItem = new JMenuItem(translation.getProperty("Find_Next"));
00391        findNextMenuItem.setMnemonic(KeyEvent.VK_N);
00392         findNextMenuItem.setAccelerator(KeyStroke.getKeyStroke
00393                                 (KeyEvent.VK_F3, 0));
00394        findNextMenuItem.addActionListener (new ActionListener () {
00395                 public void actionPerformed (ActionEvent evt) {
00396                   editOp.find(false);
00397               }
00398            });
00399        editMenu.add(findNextMenuItem);
00400        
00401        //set up tablemenu
00402        tableMenu = new JMenu(translation.getProperty("Table"), true);
00403        tableMenu.setMnemonic(KeyEvent.VK_T);
00404        //set up tableMenu actions
00405        insertMenu = new JMenu(translation.getProperty("Insert"));
00406        insertMenu.setMnemonic(KeyEvent.VK_I);
00407        
00408        menuItem = new JMenuItem(translation.getProperty("Row"));
00409        menuItem.setMnemonic(KeyEvent.VK_R);
00410         menuItem.setAccelerator(KeyStroke.getKeyStroke
00411                             (KeyEvent.VK_INSERT, ActionEvent.CTRL_MASK));
00412        menuItem.addActionListener (new ActionListener () {
00413                 public void actionPerformed (ActionEvent evt) {
00414                   tableOp.insert(true);
00415               }
00416               });
00417        insertMenu.add(menuItem);
00418        
00419        menuItem = new JMenuItem(translation.getProperty("Column"));
00420        menuItem.setMnemonic(KeyEvent.VK_C);
00421        menuItem.setAccelerator(KeyStroke.getKeyStroke
00422                             (KeyEvent.VK_INSERT,
00423                              ActionEvent.CTRL_MASK|
00424                              ActionEvent.SHIFT_MASK));  
00425        menuItem.addActionListener (new ActionListener () {
00426                 public void actionPerformed (ActionEvent evt) {
00427                   tableOp.insert(false);
00428               }
00429            });
00430        insertMenu.add(menuItem);
00431        tableMenu.add(insertMenu);
00432 
00433        //set up Delete actions
00434         deleteMenu = new JMenu(translation.getProperty("Delete"));
00435        deleteMenu.setMnemonic(KeyEvent.VK_D);
00436        menuItem = new JMenuItem(translation.getProperty("Row"));
00437        menuItem.setMnemonic(KeyEvent.VK_R);
00438        menuItem.setAccelerator(KeyStroke.getKeyStroke
00439                             (KeyEvent.VK_DELETE, ActionEvent.CTRL_MASK));
00440        menuItem.addActionListener (new ActionListener () {
00441                 public void actionPerformed (ActionEvent evt) {
00442                   //notYetImplemented();
00443                     tableOp.remove(true);
00444               }
00445            });
00446        deleteMenu.add(menuItem);
00447        menuItem = new JMenuItem(translation.getProperty("Column"));
00448        menuItem.setMnemonic(KeyEvent.VK_C);
00449        menuItem.setAccelerator(KeyStroke.getKeyStroke
00450                             (KeyEvent.VK_DELETE,
00451                              ActionEvent.CTRL_MASK|
00452                              ActionEvent.SHIFT_MASK));
00453        menuItem.addActionListener (new ActionListener () {
00454                 public void actionPerformed (ActionEvent evt) {
00455                   //notYetImplemented();
00456                     tableOp.remove(false);
00457               }
00458            });
00459        deleteMenu.add(menuItem);
00460        tableMenu.add(deleteMenu);
00461        
00462        tableMenu.addSeparator();
00463        //set up Sort actions
00464        sortMenu = new JMenu(translation.getProperty("Sort"));
00465        sortMenu.setMnemonic(KeyEvent.VK_S);
00466        menuItem = new JMenuItem(translation.getProperty("Row"));
00467        menuItem.setMnemonic(KeyEvent.VK_R);
00468        menuItem.addActionListener (new ActionListener () {
00469                 public void actionPerformed (ActionEvent evt) {
00470                     tableOp.sort(true);
00471               }
00472            });
00473        sortMenu.add(menuItem);
00474        menuItem = new JMenuItem(translation.getProperty("Column"));
00475        menuItem.setMnemonic(KeyEvent.VK_C);
00476        menuItem.addActionListener (new ActionListener () {
00477                 public void actionPerformed (ActionEvent evt) {
00478                   tableOp.sort(false);
00479               }
00480            });
00481        sortMenu.add(menuItem);
00482        tableMenu.add(sortMenu);
00483        tableMenu.addSeparator();
00484        
00485        menuItem = new JMenuItem(translation.getProperty("Set_Column_Width"));
00486        menuItem.setMnemonic(KeyEvent.VK_W);
00487        menuItem.addActionListener (new ActionListener () {
00488                 public void actionPerformed (ActionEvent evt) {
00489                   tableOp.setColumnWidth();
00490               }
00491            });
00492        tableMenu.add(menuItem);
00493        menuItem = new JMenuItem(translation.getProperty("Set_First_Column_Width"));
00494        menuItem.setMnemonic(KeyEvent.VK_W);
00495        menuItem.addActionListener (new ActionListener () {
00496                 public void actionPerformed (ActionEvent evt) {
00497                   tableOp.setFirstColumnWidth();
00498               }
00499            });
00500        tableMenu.add(menuItem);
00501        
00502        //set up Histogram menu
00503        chartMenu = new JMenu(translation.getProperty("Chart"), true);
00504        chartMenu.setMnemonic(KeyEvent.VK_C);
00505 
00506        chartMenu.addMenuListener (new MenuListener () {
00507                 public void menuSelected (MenuEvent e) {
00508                   checkShowHistogramState();
00509               }
00510               public void menuDeselected (MenuEvent e) { }
00511               public void menuCanceled (MenuEvent e) { }              
00512            });
00513 
00514 
00515        //set up Show Histogram actions
00516        showHistogramMenuItem = new JCheckBoxMenuItem(translation.getProperty("Show"));
00517        showHistogramMenuItem.setMnemonic(KeyEvent.VK_S);
00518         showHistogramMenuItem.setAccelerator(KeyStroke.getKeyStroke
00519                                     (KeyEvent.VK_F8, 0));
00520        showHistogramMenuItem.addActionListener (new ActionListener () {
00521                 public void actionPerformed (ActionEvent evt) {
00522                   histogram.toggle();
00523               }
00524            }); 
00525        chartMenu.add(showHistogramMenuItem);     
00526 
00527        //set up Add Histogram actions
00528        menuItem = new JMenuItem(translation.getProperty("Histogram"));
00529        menuItem.setMnemonic(KeyEvent.VK_H);
00530         menuItem.setAccelerator(KeyStroke.getKeyStroke
00531                             (KeyEvent.VK_H, ActionEvent.CTRL_MASK));
00532        menuItem.addActionListener (new ActionListener () {
00533                 public void actionPerformed (ActionEvent evt) {
00534                   histogram.addHistogram();
00535               }
00536            }); 
00537 
00538        chartMenu.add(menuItem);
00539        tableMenu.add(chartMenu);
00540 
00541 
00542        //set up Help menu
00543        helpMenu = new JMenu(translation.getProperty("Help"), true);
00544        helpMenu.setMnemonic(KeyEvent.VK_H);
00545 
00546        //set up Help actions        
00547        menuItem = new JMenuItem(translation.getProperty("Help_Topics"));
00548        menuItem.setMnemonic(KeyEvent.VK_H);
00549        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
00550 
00551        menuItem.addActionListener (new ActionListener () {
00552                 public void actionPerformed (ActionEvent evt) {
00553                   // testcode
00554                   try {
00555                      URL url = new URL("http://localhost/sharptools/");
00556                      new HelpOp(url);
00557                   } catch(MalformedURLException e) {
00558                      e.printStackTrace();
00559                      return;
00560                   }
00561               }
00562            });
00563        helpMenu.add(menuItem);
00564 
00565        showFunctionsMenuItem = new JCheckBoxMenuItem(translation.getProperty("Show_Functions"));
00566        showFunctionsMenuItem.setMnemonic(KeyEvent.VK_S);
00567        if(inapplet){
00568            showFunctionsMenuItem.setSelected(MainApplet.TOOLBAR_FUNCTIONS);
00569        }
00570        else
00571        {
00572            showFunctionsMenuItem.setSelected(config.getBoolean("TOOLBAR_FUNCTIONS"));
00573        }
00574        showFunctionsMenuItem.addActionListener (new ActionListener () {
00575                 public void actionPerformed (ActionEvent evt) {
00576                   boolean showFunc = showFunctionsMenuItem.isSelected();
00577                   if(!inapplet){
00578                      config.setBoolean("TOOLBAR_FUNCTIONS", showFunc);
00579                   }
00580                   funcList.setVisible(showFunc);            
00581                   // repaint
00582               }
00583             });
00584        
00585        helpMenu.add(showFunctionsMenuItem);
00586 
00587        helpMenu.addSeparator();
00588        menuItem = new JMenuItem(translation.getProperty("About_SharpTools"));
00589        menuItem.setMnemonic(KeyEvent.VK_A); 
00590        menuItem.addActionListener (new ActionListener () {
00591                 public void actionPerformed (ActionEvent evt) {
00592                   HelpOp.showAboutBox(SharpTools.this);
00593                   table.requestFocus();
00594               }
00595             });
00596        helpMenu.add(menuItem); 
00597        
00598         // set up menu bar and menus
00599         menuBar = new JMenuBar();
00600 
00601         menuBar.add(fileMenu);
00602         menuBar.add(editMenu);
00603         menuBar.add(tableMenu);
00604        menuBar.add(chartMenu);
00605         menuBar.add(helpMenu);
00606         
00607         // button initializations
00608         //JButton newButton = new JButton(newIcon);
00609         JButton newButton = new JButton(getImageIcon("images/new.gif"));
00610        JButton exitButton = new JButton(exitIcon);
00611        JButton openButton = new JButton(openIcon);
00612        JButton printButton = new JButton(printIcon);
00613        passwordButton = new JButton(unlockedIcon);
00614        saveButton = new JButton(saveIcon);
00615        if(inapplet){
00616            if(MainApplet.TOOLBAR_NEW){
00617               newButton = new JButton(newIcon);
00618               newButton.setToolTipText(translation.getProperty("New"));
00619               newButton.addActionListener (new ActionListener () {
00620                   public void actionPerformed (ActionEvent evt) {
00621                      MainApplet.AppletReply="";
00622                      ReStart();
00623                      table.requestFocus();
00624                   }
00625               });
00626               exitButton.setToolTipText(translation.getProperty("Close"));                                                                                            
00627               exitButton.addActionListener (new ActionListener () {                                                                          
00628                   public void actionPerformed (ActionEvent evt) {                                                                            
00629                      //System.out.println("clicked close");                                                                                   
00630                      setVisible( false );                                                                                                   
00631                      };                                                                                                                         
00632                   }                                                                                                                          
00633               ); 
00634            }
00635        }
00636        else
00637        {
00638        
00639            newButton.setToolTipText(translation.getProperty("New"));
00640            newButton.addActionListener (new ActionListener () {
00641                 public void actionPerformed (ActionEvent evt) {
00642                   fileOp.newFile();
00643                   table.requestFocus();
00644               }
00645            });
00646            openButton.setToolTipText(translation.getProperty("Open"));
00647            openButton.addActionListener (new ActionListener () {
00648                 public void actionPerformed (ActionEvent evt) {
00649                   fileOp.openFile();
00650                   table.requestFocus();
00651               }
00652            });
00653        
00654            // we save this button as private member for further reference
00655            saveButton.setToolTipText(translation.getProperty("Save"));
00656            saveButton.addActionListener (new ActionListener () {
00657                 public void actionPerformed (ActionEvent evt) {
00658                   fileOp.saveFile();
00659                   table.requestFocus();
00660               }
00661            });
00662        
00663            // we save this button as private member for further reference    
00664            passwordButton.setToolTipText(translation.getProperty("Set_Password"));
00665            passwordButton.addActionListener (new ActionListener () {
00666                 public void actionPerformed (ActionEvent evt) {
00667                   fileOp.setPassword();
00668                   table.requestFocus();
00669               }
00670            });
00671 
00672            printButton.setToolTipText(translation.getProperty("Print"));
00673            printButton.addActionListener (new ActionListener () {
00674                 public void actionPerformed (ActionEvent evt) {
00675                   Thread runner = new Thread() {
00676                          public void run() {
00677                             fileOp.printData();
00678                          }
00679                      };
00680                   runner.start();
00681                   table.requestFocus();
00682               }
00683            });
00684        }
00685        undoButton = new JButton(undoIcon);
00686        undoButton.setToolTipText(translation.getProperty("Undo"));
00687        undoButton.addActionListener (new ActionListener () {
00688                 public void actionPerformed (ActionEvent evt) {
00689                   history.undo(tableModel);
00690                   table.requestFocus();
00691               }
00692            });
00693 
00694        redoButton = new JButton(redoIcon);
00695        redoButton.setToolTipText(translation.getProperty("Redo"));
00696        redoButton.addActionListener (new ActionListener () {
00697                 public void actionPerformed (ActionEvent evt) {
00698                   history.redo(tableModel);
00699                   table.requestFocus();
00700               }
00701            });
00702        
00703         JButton cutButton = new JButton(cutIcon);
00704        cutButton.setToolTipText(translation.getProperty("Cut"));
00705        cutButton.addActionListener (new ActionListener () {
00706                 public void actionPerformed (ActionEvent evt) {
00707                   editOp.cut();
00708                   table.requestFocus();
00709               }
00710            });
00711         JButton copyButton = new JButton(copyIcon);
00712        copyButton.setToolTipText(translation.getProperty("Copy"));
00713        copyButton.addActionListener (new ActionListener () {
00714                 public void actionPerformed (ActionEvent evt) {
00715                   editOp.copy();
00716                   table.requestFocus();
00717               }
00718            });
00719        
00720         JButton pasteButton = new JButton(pasteIcon);
00721        pasteButton.setToolTipText(translation.getProperty("Paste"));
00722         pasteButton.addActionListener (new ActionListener () {
00723                 public void actionPerformed (ActionEvent evt) {
00724                   editOp.paste();
00725                   table.requestFocus();
00726               }
00727            });
00728 
00729         JButton findButton = new JButton(findIcon);
00730        findButton.setToolTipText(translation.getProperty("Find"));
00731         findButton.addActionListener (new ActionListener () {
00732                 public void actionPerformed (ActionEvent evt) {
00733                   editOp.find(true);
00734                   table.requestFocus();
00735               }
00736            });
00737 
00738        JButton sortButton = new JButton(sortIcon);
00739        sortButton.setToolTipText(translation.getProperty("Sort_by_Column"));
00740         sortButton.addActionListener (new ActionListener () {
00741                 public void actionPerformed (ActionEvent evt) {
00742                   tableOp.sort(false);
00743                   table.requestFocus();
00744               }
00745            });
00746 
00747        JButton insertRowButton = new JButton(insertRowIcon);
00748        insertRowButton.setToolTipText(translation.getProperty("Insert_Row"));
00749         insertRowButton.addActionListener (new ActionListener () {
00750                 public void actionPerformed (ActionEvent evt) {
00751                   tableOp.insert(true);
00752                   table.requestFocus();
00753               }
00754            });
00755 
00756        JButton insertColumnButton = new JButton(insertColumnIcon);
00757        insertColumnButton.setToolTipText(translation.getProperty("Insert_Column"));
00758         insertColumnButton.addActionListener (new ActionListener () {
00759                 public void actionPerformed (ActionEvent evt) {
00760                   tableOp.insert(false);
00761                   table.requestFocus();
00762               }
00763            });
00764 
00765        JButton deleteRowButton = new JButton(deleteRowIcon);
00766        deleteRowButton.setToolTipText(translation.getProperty("Delete_Row"));
00767         deleteRowButton.addActionListener (new ActionListener () {
00768                 public void actionPerformed (ActionEvent evt) {
00769                   tableOp.remove(true);
00770                   table.requestFocus();
00771               }
00772            });
00773 
00774        JButton deleteColumnButton = new JButton(deleteColumnIcon);
00775        deleteColumnButton.setToolTipText(translation.getProperty("Delete_Column"));
00776         deleteColumnButton.addActionListener (new ActionListener () {
00777                 public void actionPerformed (ActionEvent evt) {
00778                   tableOp.remove(false);
00779                   table.requestFocus();
00780               }
00781            });
00782 
00783         JButton chartButton = new JButton(chartIcon);
00784        chartButton.setToolTipText(translation.getProperty("Histogram"));
00785         chartButton.addActionListener (new ActionListener () {
00786                 public void actionPerformed (ActionEvent evt) {
00787                   histogram.addHistogram();
00788                   table.requestFocus();
00789               }
00790            });
00791        
00792        JButton helpButton = new JButton(helpIcon);
00793        helpButton.setToolTipText(translation.getProperty("Help"));
00794        helpButton.addActionListener (new ActionListener () {
00795                 public void actionPerformed (ActionEvent evt) {
00796                      try {
00797                          if(!inapplet){
00798                             String basePath = System.getProperty("user.dir");
00799                          }
00800                          url = new URL("http://localhost/sharptools/");
00801                          new HelpOp(url);
00802 
00803                      } catch(MalformedURLException e) {
00804                          e.printStackTrace();
00805                          return;
00806                      }
00807                   table.requestFocus();
00808               }
00809            });
00810 
00811         /*
00812         * Set up toolbar
00813         *
00814         * Toolbar can be customized in the configuration file.
00815         */
00816         toolBar = new JToolBar();
00817        toolBar.setFloatable(false);
00818        int w;int h;
00819        if(!inapplet){
00820            if (config.getBoolean("TOOLBAR_NEW")){toolBar.add(newButton);}
00821            if (config.getBoolean("TOOLBAR_OPEN")){toolBar.add(openButton);}
00822            if (config.getBoolean("TOOLBAR_SAVE")){toolBar.add(saveButton);}
00823            toolBar.addSeparator();
00824            if (config.getBoolean("TOOLBAR_PASSWORD")){toolBar.add(passwordButton);}
00825            if (config.getBoolean("TOOLBAR_PRINT")){toolBar.add(printButton);}
00826            toolBar.addSeparator();
00827            if (config.getBoolean("TOOLBAR_UNDO")){toolBar.add(undoButton);}
00828            if (config.getBoolean("TOOLBAR_REDO")){toolBar.add(redoButton);}
00829            if (config.getBoolean("TOOLBAR_CUT")){toolBar.add(cutButton);}
00830            if (config.getBoolean("TOOLBAR_COPY")){toolBar.add(copyButton);}
00831            if (config.getBoolean("TOOLBAR_PASTE")){toolBar.add(pasteButton);}
00832            if (config.getBoolean("TOOLBAR_FIND")){toolBar.add(findButton);}
00833            toolBar.addSeparator();
00834            if (config.getBoolean("TOOLBAR_INSERTROW")){toolBar.add(insertRowButton);}
00835            if (config.getBoolean("TOOLBAR_INSERTCOLUMN")){toolBar.add(insertColumnButton);}
00836            if (config.getBoolean("TOOLBAR_DELETEROW")){toolBar.add(deleteRowButton);}
00837            if (config.getBoolean("TOOLBAR_DELETECOLUMN")){toolBar.add(deleteColumnButton);}
00838            if (config.getBoolean("TOOLBAR_SORTCOLUMN")){toolBar.add(sortButton);}
00839            toolBar.addSeparator();
00840            if (config.getBoolean("TOOLBAR_HISTOGRAM")) {toolBar.add(chartButton);toolBar.addSeparator();}
00841            if (config.getBoolean("TOOLBAR_HELP")){toolBar.add(helpButton);}
00842            toolBar.addSeparator();
00843            toolBar.add(funcList);
00844            funcList.setVisible(config.getBoolean("TOOLBAR_FUNCTIONS"));
00845            newTableModel(config.getInt("ROWS"), config.getInt("COLUMNS"));
00846            // set window pos and size
00847            w = config.getInt("WIDTH");
00848            h = config.getInt("HEIGHT");   
00849        }
00850        else // inapplet ; we can't configure the sharptools.ini file...so we depend on params.
00851        {
00852            if (MainApplet.TOOLBAR_NEW){toolBar.add(newButton);}
00853            if (MainApplet.TOOLBAR_OPEN){toolBar.add(openButton);}
00854            if (MainApplet.TOOLBAR_SAVE){toolBar.add(saveButton);}
00855            toolBar.addSeparator();
00856            toolBar.add(exitButton);
00857            if (MainApplet.TOOLBAR_PASSWORD){toolBar.add(passwordButton);}
00858            if (MainApplet.TOOLBAR_PRINT){toolBar.add(printButton);}
00859            toolBar.addSeparator();
00860            if (MainApplet.TOOLBAR_UNDO){toolBar.add(undoButton);}
00861            if (MainApplet.TOOLBAR_REDO){toolBar.add(redoButton);}
00862            if (MainApplet.TOOLBAR_CUT){toolBar.add(cutButton);}
00863            if (MainApplet.TOOLBAR_COPY){toolBar.add(copyButton);}
00864            if (MainApplet.TOOLBAR_PASTE){toolBar.add(pasteButton);}
00865            if (MainApplet.TOOLBAR_FIND){toolBar.add(findButton);}
00866            toolBar.addSeparator();
00867            if (MainApplet.TOOLBAR_INSERTROW){toolBar.add(insertRowButton);}
00868            if (MainApplet.TOOLBAR_INSERTCOLUMN){toolBar.add(insertColumnButton);}
00869            if (MainApplet.TOOLBAR_DELETEROW){toolBar.add(deleteRowButton);}
00870            if (MainApplet.TOOLBAR_DELETECOLUMN){toolBar.add(deleteColumnButton);}
00871            if (MainApplet.TOOLBAR_SORTCOLUMN){toolBar.add(sortButton);}
00872            toolBar.addSeparator();
00873            if (MainApplet.TOOLBAR_HISTOGRAM) {toolBar.add(chartButton);toolBar.addSeparator();}
00874            if (MainApplet.TOOLBAR_HELP){toolBar.add(helpButton);}
00875            toolBar.addSeparator();
00876            toolBar.add(funcList);
00877            funcList.setVisible(MainApplet.TOOLBAR_FUNCTIONS);
00878            newTableModel(MainApplet.ROWS, MainApplet.COLUMNS);
00879            // set window pos and size
00880            w = MainApplet.WIDTH;
00881            h = MainApplet.HEIGHT;  
00882        }
00883        if (w >= 0 && h >= 0)
00884            table.setPreferredScrollableViewportSize(new Dimension(w, h));
00885 
00886        // init fileOp objects
00887        if(!inapplet){fileOp = new FileOp(this);}
00888 
00889        // clobber resizing of all columns
00890        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
00891         
00892         // set table editor and renderer to custom ones
00893        table.setDefaultRenderer(Cell.class, new SharpCellRenderer());
00894         table.setDefaultEditor(Cell.class, new SharpCellEditor(
00895                                             new JTextField()));
00896 
00897        // set selection mode for contiguous  intervals
00898         table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
00899         table.setCellSelectionEnabled(true);
00900 
00901        // we don't allow reordering
00902         table.getTableHeader().setReorderingAllowed(false);
00903        table.getTableHeader().addMouseListener(new HeaderMouseAdapter());
00904        
00905        // create selection models
00906        rowSelectionModel = table.getSelectionModel();
00907         columnSelectionModel = table.getColumnModel().getSelectionModel();
00908 
00909        // add selection listeners to the selection models
00910        rowSelectionModel.addListSelectionListener(this);
00911        columnSelectionModel.addListSelectionListener(this);
00912        
00913        // set menu bar
00914        setJMenuBar(menuBar);
00915        container.add(toolBar, BorderLayout.NORTH);      
00916        
00917        scrollPane = new JScrollPane(table,
00918                                  JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
00919                                  JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
00920        
00921         container.add(scrollPane, BorderLayout.CENTER);
00922         
00923         // add window exit listener
00924         addWindowListener (new WindowAdapter () {
00925               public void windowOpened (WindowEvent evt) {                
00926                   table.requestFocus();
00927               }
00928               
00929               public void windowClosing (WindowEvent evt) {
00930                   exit();
00931               }
00932            });
00933 
00934        // initial selection
00935        resetSelection();
00936        
00937        table.setRequestFocusEnabled(true);
00938        menuBar.setRequestFocusEnabled(false);
00939        toolBar.setRequestFocusEnabled(false);
00940        table.requestFocus();       
00941        
00942        pack();
00943        show();
00944     }
00945     public void setColumnWidth(int colWidth) {
00946        if (colWidth > 0){
00947            for (int i = baseCol; i < tableModel.getColumnCount(); i ++) {
00948               TableColumn column = table.getColumnModel().getColumn(i);
00949               column.setMinWidth(colWidth);
00950               column.setPreferredWidth(colWidth);
00951 
00952            }
00953        }
00954     }
00955     
00963     public void newTableModel(int rows, int cols) {
00964        tableModel = new SharpTableModel(this, rows, cols);
00965        table.setModel(tableModel);
00966 
00967        setBaseColumnWidth(0);
00968        if(!inapplet){setColumnWidth(config.getInt("COLUMNWIDTH"));} else {setColumnWidth(MainApplet.COLUMNWIDTH);}
00969        // update history with new one
00970        history = new History(this);
00971        tableModel.setHistory(history);    
00972 
00973        // inform tableModel that it's unmodified now
00974        tableModel.setPasswordModified(false);
00975        tableModel.setModified(false);
00976 
00977        // init op objects
00978        // we shouldn't init fileOp!
00979        
00980        if (editOp == null)
00981            editOp = new EditOp(this);
00982        else
00983            /* if we already have an object, we don't construct
00984               a new EditOp to keep the clipboard and findValue
00985               still valid.  This makes us be able to exchange
00986               data across files */
00987            editOp.init(this);
00988 
00989        tableOp = new TableOp(this);
00990        if(!inapplet){
00991            histogram = new Histogram(this, "Histograms",config.getInt("HISTOGRAMWIDTH"),config.getInt("HISTOGRAMHEIGHT"));
00992        }
00993        else
00994        {
00995            histogram = new Histogram(this, "Histograms",MainApplet.HISTOGRAMWIDTH,MainApplet.HISTOGRAMHEIGHT);
00996        }
00997        tableModel.setModified(false);
00998        
00999        resetSelection();
01000        
01001        // menubar/toolbar initial status
01002        checkUndoRedoState();
01003        
01004        table.requestFocus();
01005     }
01006     
01012     public void noCellsSelected(String s) {
01013         sharpoptionpane.showMessageDialog(this, s + ": No cells selected","Error", JOptionPane.ERROR_MESSAGE, null);
01014     }
01015 
01019     private void notYetImplemented(){
01020        sharpoptionpane.showMessageDialog(this,
01021                                      "Sorry, this function \n"+
01022                                      "is not yet implemented!\n"+
01023                                      "sharp@cs.columbia.edu",
01024                                      "Sharp Tools Spreadsheet",
01025                                      JOptionPane.WARNING_MESSAGE,
01026                                      null);
01027     }
01028 
01030     public void exit() {
01031        if(!inapplet){
01032            if (fileOp.closeFile()) {
01033               // save window position and size
01034               if (config.getBoolean("SAVEWINDOW")) {
01035                   config.setInt("X", getX());
01036                   config.setInt("Y", getY());
01037                   Dimension dim = scrollPane.getViewport().getExtentSize();
01038                   config.setInt("WIDTH", (int)dim.getWidth());
01039                   config.setInt("HEIGHT", (int)dim.getHeight());
01040               }
01041               config.save();           
01042                System.exit(0);
01043            }
01044        }
01045        else
01046        {
01047            System.exit(0);
01048        }
01049     }
01050     
01056     private void openInitFile(String filename) {
01057        if(!inapplet){
01058            fileOp.openTableModel(new File(filename));
01059        }
01060     }
01061 
01062 
01072     public void checkSaveState() {
01073        boolean modified = tableModel.isModified();
01074        if(!inapplet){
01075            saveMenuItem.setEnabled(modified);
01076            saveButton.setEnabled(modified);
01077        }
01078     }
01079 
01084     public void checkPasswordState() {
01085        if(!inapplet){
01086            if (fileOp.hasPassword())
01087               passwordButton.setIcon(lockedIcon);
01088            else
01089               passwordButton.setIcon(unlockedIcon);
01090        }
01091     }
01092 
01097     public void checkUndoRedoState() {
01098        boolean enable = history.isUndoable();
01099        undoMenuItem.setEnabled(enable);
01100        undoButton.setEnabled(enable);
01101        enable = history.isRedoable();
01102        redoMenuItem.setEnabled(enable);
01103        redoButton.setEnabled(enable);
01104     }
01105 
01110     public void checkFindNextState() {
01111        findNextMenuItem.setEnabled(editOp.hasFindValue());
01112     }
01113 
01118     public void checkShowHistogramState() {      
01119        showHistogramMenuItem.setState(histogram.isVisible());
01120        showHistogramMenuItem.setEnabled(histogram.hasChart()); 
01121     }
01122 
01123     public void setBaseColumnWidth(int width) {
01124        if(width == 0){
01125            // resize first column
01126            if (baseCol > 0) {
01127               TableColumn firstColumn = table.getColumnModel().getColumn(baseCol-1);
01128                int firstColWidth;
01129               if(!inapplet){firstColWidth = config.getInt("FIRSTCOLUMNWIDTH");}else{firstColWidth=MainApplet.FIRSTCOLUMNWIDTH;}
01130               if (firstColWidth>0) {
01131                   firstColumn.setMinWidth(firstColWidth);
01132                   firstColumn.setPreferredWidth(firstColWidth);
01133               }
01134            }
01135        }
01136        else
01137        {
01138            if(width>0){
01139               TableColumn firstColumn = table.getColumnModel().getColumn(baseCol-1);
01140               firstColumn.setMinWidth(width);
01141                firstColumn.setPreferredWidth(width);
01142            }
01143        
01144        }
01145     }
01146     
01148     public static void main(String args[]){
01149        if(!inapplet){
01150            // read configuration file
01151            config = new Config("sharptools.ini");
01152            // set default value
01153            config.setInt("ROWS", 20);
01154            config.setInt("COLUMNS", 10);
01155            // config.set("AUTORESIZE", "TRUE");
01156            config.setInt("HISTOGRAMWIDTH", 600);
01157            config.setInt("HISTOGRAMHEIGHT", 400);
01158            // read file
01159            config.load();
01160        
01161            // only change it when DEBUG is uncommented in the config file
01162            if (config.get("DEBUG") != null)
01163               Debug.setDebug(config.getBoolean("DEBUG"));
01164        }
01165        else
01166        {    config = new Config("sharptools.ini");
01167            // set default value
01168            config.setInt("ROWS", 20);
01169            config.setInt("COLUMNS", 10);
01170            // config.set("AUTORESIZE", "TRUE");
01171            config.setInt("HISTOGRAMWIDTH", 600);
01172            config.setInt("HISTOGRAMHEIGHT", 400);
01173            // read file
01174            config.load();
01175        }
01176        // initialize the function handler table object
01177        Formula.registerFunctions();
01178        
01179         SharpTools spreadsheet = new SharpTools(inapplet,language);
01180         spreadsheet.show();
01181        if (args.length>0){spreadsheet.openInitFile(args[0]);}
01182     }
01183 
01184     // this is a static function to help loading images
01185     public static ImageIcon getImageIcon(String name) {
01186        //URL imgurl = SharpTools.class.getResource(name);
01187        //URL imgurl = getClass().getResource(name);
01188        //URL imgurl = ClassLoader.getResourceAsStream(name);
01189        URL imgurl = ClassLoader.getSystemResource(name);
01190        //URL imgurl = ClassLoader.getResource(name);
01191        if (imgurl == null) {
01192            System.out.println("image "+name+" not found");
01193            return null;
01194        }
01195        return new ImageIcon(imgurl);
01196     }
01197 
01198     class HeaderMouseAdapter extends MouseAdapter {
01199 
01200        public void mouseClicked(MouseEvent e) {
01201            TableColumnModel colModel = 
01202               table.getColumnModel();
01203            int col = 
01204               colModel.getColumn(colModel.getColumnIndexAtX(e.getX())).getModelIndex();
01205            
01206            int rowCount = table.getRowCount();
01207            table.setRowSelectionInterval(baseRow, rowCount - 1);
01208 
01209            if (col < baseCol)
01210               table.setColumnSelectionInterval(baseCol, table.getColumnCount()-1);
01211            else
01212               table.setColumnSelectionInterval(col, col);
01213        }
01214     }
01215 
01216     // the ListSelectionListener interface
01217     public void valueChanged(ListSelectionEvent e) {
01218        table.requestFocus();
01219            
01220        // Ignore extra messages
01221        if (e.getValueIsAdjusting()) return;
01222        
01223        // Get event source
01224        ListSelectionModel lsm = (ListSelectionModel)e.getSource();
01225        
01226        if (lsm.isSelectionEmpty() && table.getColumnCount() > baseCol &&
01227            table.getRowCount() > baseRow) {
01228            // always set selection
01229            table.setRowSelectionInterval(baseRow, baseRow);
01230            table.setColumnSelectionInterval(baseCol, baseCol);
01231        }/* else {
01232            if (table.getSelectedColumn() < baseCol) {
01233               int columnCount = table.getColumnCount();
01234                 if (columnCount > baseCol) {
01235                     Debug.println("setColumnSelectionInterval "
01236                                   + String.valueOf(baseCol)
01237                                   + " " + String.valueOf(columnCount - 1));
01238                               
01239                     table.setColumnSelectionInterval(baseCol, columnCount - 1);
01240                     table.removeColumnSelectionInterval(baseRow,baseRow);
01241                 }
01242                 }
01243               }*/
01244     }
01245 
01246     public void resetSelection() {
01247        table.setRowSelectionInterval(baseRow, baseRow);
01248        table.setColumnSelectionInterval(baseCol, baseCol);
01249     }
01250     /* jm.evers */
01251     public void ReStart(){
01252         setVisible(false);
01253         SharpTools spreadsheet = new SharpTools(inapplet,language);
01254         spreadsheet.show();
01255     }
01256     
01257     public String ReadRawSpreadSheet(){
01258        // included raw functions like =SUM(1,2,3,4)
01259        String reply=tableModel.toString();
01260        return reply;
01261     }
01262 
01263     public String ReadSpreadSheet(boolean matrix){
01264        String reply=tableModel.toWIMS(matrix);
01265        return reply;
01266     }
01267 
01268 
01269     public Properties loadProperties (String lang){
01270        Properties P=new Properties();      
01271        // jm.evers : trying global properties file with translations        
01272        try{
01273            InputStream in = getClass().getResourceAsStream("/lang/SharpToolsProperties_"+lang+".properties");
01274            P.load(in);in.close();
01275            return P;
01276        }                
01277        catch (Exception e){ System.out.println("error reading lang/SharpToolsProperties_"+lang+".properties\n"+e);}    
01278         return null;             
01279     }                
01280   
01281 }
01282