Back to index

wims  3.65+svn20090927
FileOp.java
Go to the documentation of this file.
00001 
00002 /*
00003  * @(#)FileOp.java
00004  *
00005  * $Id: FileOp.java,v 1.84 2002/08/08 05:15:03 huaz Exp $
00006  *
00007  * Created on November 16, 2000, 12:00 AM
00008  *
00009  */
00010 package SharpTools;
00011 import javax.swing.*;
00012 import javax.swing.table.*;
00013 import javax.swing.filechooser.*;
00014 import java.awt.*;
00015 import java.awt.event.*;
00016 import java.io.*;
00017 import java.util.*;
00018 import java.awt.print.*;
00019 import java.sql.*;
00020 
00029 public class FileOp implements ActionListener, Printable {
00030 
00031     final static private int UNNAMED = 0;
00032     final static private int FILE = 1;
00033     final static private int DATABASE = 2;
00034 
00035     private int openType = UNNAMED;
00036     
00037     private int maxNumPage = 1;
00038     private boolean columnOverflow;
00039 
00040     private StringTokenizer tokenizer;
00041     private PrintStream out;
00042     private BufferedReader in;
00043 
00044     private SharpTools sharp;
00045     private JTable table;
00046     private SharpTableModel tableModel;
00047     
00048     private File file;
00049     private String password;
00050     //Create a file chooser
00051     private JFileChooser fileChooser;
00052     private static SharpFileFilter filter;
00053     final ImageIcon newIcon=new ImageIcon(getClass().getResource("/images/new32.gif"));                                                    
00054     final ImageIcon openIcon=new ImageIcon(getClass().getResource("/images/open.gif"));                                                    
00055     final ImageIcon saveIcon=new ImageIcon(getClass().getResource("/images/save32.gif"));
00056     //final private static ImageIcon newIcon = SharpTools.getImageIcon("new32.gif");
00057     //final private static ImageIcon openIcon = SharpTools.getImageIcon("open.gif");
00058     //final private static ImageIcon saveIcon = SharpTools.getImageIcon("save32.gif");
00059     final private static String extname = ".csv";
00060 
00061     class SharpFileFilter extends javax.swing.filechooser.FileFilter {
00062     
00063        public boolean accept(File file) {
00064            if (file.isDirectory())
00065               return true;
00066 
00067            return file.getName().endsWith(extname);
00068        }
00069 
00070        public String getDescription() {
00071            return SharpTools.translation.getProperty("Sharp_Tools_Spreadsheet");
00072        }
00073     }
00080     public FileOp(SharpTools gui) {
00081        sharp = gui;
00082        table = gui.getTable();
00083        tableModel = gui.getTableModel();
00084        fileChooser = new JFileChooser(new File("."));
00085        filter = new SharpFileFilter();
00086        fileChooser.addChoosableFileFilter(filter);
00087        sharp.setTitle(SharpTools.translation.getProperty("Untitled_-_Sharp_Tools_Spreadsheet"));
00088 
00089         columnOverflow = false;
00090 
00091        // below define key shortcuts
00092 
00093        table.registerKeyboardAction
00094            (this,SharpTools.translation.getProperty("New"),
00095             KeyStroke.getKeyStroke
00096             (KeyEvent.VK_N,ActionEvent.CTRL_MASK,false),
00097             JComponent.WHEN_FOCUSED);
00098        
00099        table.registerKeyboardAction
00100            (this,SharpTools.translation.getProperty("OpenFile"),
00101             KeyStroke.getKeyStroke
00102             (KeyEvent.VK_O,ActionEvent.CTRL_MASK,false),
00103             JComponent.WHEN_FOCUSED);
00104 
00105        table.registerKeyboardAction
00106            (this,SharpTools.translation.getProperty("OpenDb"),
00107             KeyStroke.getKeyStroke
00108             (KeyEvent.VK_D,ActionEvent.CTRL_MASK,false),
00109             JComponent.WHEN_FOCUSED);
00110        
00111        table.registerKeyboardAction
00112            (this,SharpTools.translation.getProperty("Save"),
00113             KeyStroke.getKeyStroke
00114             (KeyEvent.VK_S,ActionEvent.CTRL_MASK,false),
00115             JComponent.WHEN_FOCUSED);
00116 
00117        table.registerKeyboardAction
00118            (this,SharpTools.translation.getProperty("Print"),
00119             KeyStroke.getKeyStroke
00120             (KeyEvent.VK_P,ActionEvent.CTRL_MASK,false),
00121             JComponent.WHEN_FOCUSED);
00122        
00123        table.registerKeyboardAction
00124            (this,SharpTools.translation.getProperty("Exit"),
00125             KeyStroke.getKeyStroke
00126             (KeyEvent.VK_E,ActionEvent.CTRL_MASK,false),
00127             JComponent.WHEN_FOCUSED);          
00128     }
00129 
00136     public int queryForSave() {
00137        // show confirm dialog box from static JOptionPane method
00138        String filename = "Untitled";
00139        if (file != null)
00140            filename = file.getName();
00141        
00142        int choice =
00143            SharpOptionPane.showOptionDialog
00144            (sharp,
00145             "Do you want to save the changes you made to \""+filename+"\"?",
00146             "Save",
00147             JOptionPane.YES_NO_CANCEL_OPTION,
00148             JOptionPane.QUESTION_MESSAGE,
00149             saveIcon);
00150        // return user's choice
00151        return choice;
00152     }
00153 
00159     public void newFile() {
00160        int choice;
00161 
00162         // pop up querySave box (yes, no, cancel) and save choice
00163        // if table modified state is modified, else set choice
00164        // to JOptionPane.NO_OPTION which clears cells without
00165        if(tableModel.isModified())
00166            choice = queryForSave();
00167        else
00168            choice = JOptionPane.NO_OPTION;
00169        
00170        switch(choice) {
00171        case JOptionPane.YES_OPTION:
00172            // if user chooses yes in dialog box, save document first
00173            // before executing clear range
00174            saveFile();
00175        case JOptionPane.NO_OPTION:
00176 
00177            Config config = sharp.getConfig();
00178 
00179            NewFileDialog dialog = new NewFileDialog(sharp,
00180                                                config.getInt("ROWS"),
00181                                                config.getInt("COLUMNS"));
00182            dialog.setLocationRelativeTo(sharp);
00183            dialog.setVisible(true);
00184 
00185            if (dialog.isCancelled())
00186               return;
00187 
00188            int row = dialog.getRows();
00189            int col = dialog.getColumns();
00190 
00191            // range of cells is cleared, the filename is set to untitled
00192            // and the modified state is set to unmodified.
00193            //     file = new File("Untitled");
00194            file = null;
00195            sharp.setTitle(SharpTools.translation.getProperty("Untitled_-_Sharp_Tools_Spreadsheet"));
00196            sharp.newTableModel(row, col);
00197            tableModel = sharp.getTableModel();
00198 
00199            // reset password
00200            setPasswordValue(password);
00201 
00202        default:
00203            // break out of loop for all choices.  action depends
00204            // on entry point.
00205            break;
00206        }
00207     }
00208 
00214     public void saveFile() {
00215        if(tableModel.isModified()) {
00216            //     if(file.getName().equals("Untitled")) {
00217            if (file == null) {
00218               saveAsFile();
00219            } else {
00220               saveTableModel();
00221            }
00222         }
00223     }
00224     
00230     public void saveAsFile() {
00231        // open save dialog and save user input
00232        int choice = fileChooser.showSaveDialog(sharp);
00233        
00234        // if user clicks ok, then procede with save, otherwise do nothing
00235        if(choice == JFileChooser.APPROVE_OPTION) {
00236            // get selected file to save to
00237            File selectedfile = fileChooser.getSelectedFile();
00238 
00239            fileChooser = new JFileChooser(selectedfile.getParentFile());
00240            fileChooser.addChoosableFileFilter(filter);
00241 
00242            // enforce the extension name
00243            String path;
00244 
00245            try {
00246               path = selectedfile.getCanonicalPath();
00247            }
00248            catch (IOException e) {
00249               fileOpError(SharpTools.translation.getProperty("Save"), SharpTools.translation.getProperty("Unexpected_error"));
00250               return;
00251            }
00252 
00253            if (!path.endsWith(extname))
00254               selectedfile = new File(path+extname);
00255 
00256            // check the existence of the file
00257            if (selectedfile.exists()) {
00258               choice =
00259                   SharpOptionPane.showOptionDialog
00260                   (sharp,
00261                    SharpTools.translation.getProperty("File_already_exists")+"  ("+selectedfile.getName()+")\n\n"+SharpTools.translation.getProperty("Do_you_want_to_overwrite_it"),
00262                    SharpTools.translation.getProperty("Save"),
00263                    JOptionPane.YES_NO_OPTION,
00264                    JOptionPane.WARNING_MESSAGE,
00265                    saveIcon, 1);
00266               if (choice != JOptionPane.YES_OPTION)
00267                   return;
00268            }
00269            
00270            saveTableModel(selectedfile);
00271        }
00272     }
00273 
00278     public void openFile() {
00279        int choice;
00280 
00281         // pop up querySave box (yes, no, cancel) and save choice
00282        // if table modified state is modified, else set choice
00283        // to JOptionPane.NO_OPTION which clears cells without
00284        if(tableModel.isModified())
00285            choice = queryForSave();
00286        else
00287            choice = JOptionPane.NO_OPTION;
00288        
00289        switch(choice) {
00290          case JOptionPane.YES_OPTION:
00291              // if user chooses yes in dialog box, save document first
00292              // before executing clear range
00293              saveFile();
00294          case JOptionPane.NO_OPTION:
00295              // open dialog from filechooser and save user choice
00296              int userChoice = fileChooser.showOpenDialog(sharp);
00297              // if user chooses file, call openTableModel on new
00298              // FileOperations object, else go to break in default
00299              if(userChoice == JFileChooser.APPROVE_OPTION) {
00300                 File selectedfile = fileChooser.getSelectedFile();
00301                 fileChooser = new JFileChooser(selectedfile.getParentFile());
00302                 fileChooser.addChoosableFileFilter(filter);
00303 
00304                 openTableModel(selectedfile);
00305 
00306              }
00307          default:
00308              // break out of loop for all choices.  action depends
00309              // on entry point.
00310              break;
00311        }
00312     }
00313 
00321     public boolean closeFile() {
00322        int choice;
00323        
00324        if(tableModel.isModified())
00325            choice = queryForSave();
00326        else
00327            choice = JOptionPane.NO_OPTION;
00328        
00329        switch(choice) {
00330        case JOptionPane.CANCEL_OPTION:
00331            return false;
00332        case JOptionPane.YES_OPTION:
00333            // if user chooses yes in dialog box, save document first
00334            // before exiting.
00335            saveFile();
00336        default:
00337            //     System.exit( 0 );
00338            return true;
00339        }
00340     }
00341     
00342     
00349     public void saveTableModel(File aFile) {
00350 
00351        try {
00352            
00353            // initialize output
00354 
00355            out = new PrintStream(new FileOutputStream(aFile));
00356            
00357            int rowCount = tableModel.getRowCount();
00358            int colCount = tableModel.getColumnCount();
00359            // print out number of columns and rows
00360            //     out.println(rowCount+"\t"+colCount);
00361            if (password != null && password.length() > 0)
00362               out.println("Password: "+password);
00363            
00364            out.print(tableModel.toString());
00365            out.flush();
00366            
00367            file = aFile;
00368            // set modified to false
00369            tableModel.setPasswordModified(false);
00370            tableModel.setModified(false);
00371 
00372            // update recent files
00373            addRecentFile(file);
00374            
00375            String title = file.getName();
00376            if (title.endsWith(extname))
00377               title = title.substring(0, title.length()-4);
00378            sharp.setTitle(title+"   "+SharpTools.translation.getProperty("Sharp_Tools_Spreadsheet"));
00379        } catch (FileNotFoundException e) {
00380            fileOpError(SharpTools.translation.getProperty("Save"), SharpTools.translation.getProperty("File_cannot_be_created")+"  : "+aFile.getName());
00381        } catch (IOException e) {
00382            fileOpError(SharpTools.translation.getProperty("Save"), SharpTools.translation.getProperty("IO_error_in_saving"+"  : "+aFile.getName()+" !"));
00383        }
00384     }
00385     
00389     public void saveTableModel() {
00390        saveTableModel(file);
00391     }
00392 
00398     public void openTableModel(File aFile) {
00399 
00400        StringBuffer textBuf = new StringBuffer();
00401        String line;
00402        String password = null;
00403        try {
00404            in =  new BufferedReader(new FileReader(aFile));
00405            line = in.readLine();
00406            if (line.indexOf('\t') == -1 &&
00407               line.startsWith("Password: ")) {
00408               // password defined
00409               password = line.substring(10);
00410               if (!verifyPassword(password)) {
00411                   return;
00412               }
00413            }
00414            else {
00415               textBuf.append(line);
00416               textBuf.append("\n");
00417            }
00418               
00419            while ((line = in.readLine()) != null) {
00420               textBuf.append(line);
00421               textBuf.append("\n");
00422            }
00423 
00424            // reset password
00425            setPasswordValue(password);
00426 
00427            String text = textBuf.toString();
00428            // create new table model
00429            CellPoint size = SharpTableModel.getSize(text);
00430            //     System.out.println(size);
00431            sharp.newTableModel(size.getRow(), size.getCol());
00432            tableModel = sharp.getTableModel();
00433            tableModel.fromString(text, 0, 0,
00434                               new CellRange(SharpTools.baseRow,
00435                                           size.getRow(),
00436                                           SharpTools.baseCol,
00437                                           size.getCol()));
00438            file = aFile;
00439            //     tableModel.setModified(false);
00440            // set new title for spreadsheet
00441            String title = file.getName();
00442            if (title.endsWith(extname))
00443               title = title.substring(0, title.length()-4);
00444 
00445            sharp.setTitle(title+" - "+SharpTools.translation.getProperty("Sharp_Tools_Spreadsheet"));
00446 
00447            // update recent files
00448            addRecentFile(file);
00449            
00450        } catch (FileNotFoundException e) {
00451            fileOpError(SharpTools.translation.getProperty("Open"),SharpTools.translation.getProperty("File_not_found")+" : "+aFile.getName());
00452        } catch (IOException e) {
00453            fileOpError(SharpTools.translation.getProperty("Open"), SharpTools.translation.getProperty("IO_error_in_opening")+" : "+aFile.getName());
00454        } catch (Exception e) {
00455             e.printStackTrace();
00456        }
00457     }
00458 
00465     private String getRecentFile(int index) {
00466        Config config = SharpTools.getConfig();
00467        return config.get("RECENTFILE"+String.valueOf(index));
00468     }
00469 
00476     private void setRecentFile(int index, String s) {
00477        Config config = SharpTools.getConfig();   
00478        config.set("RECENTFILE"+String.valueOf(index), s);
00479     }
00480 
00486     private void moveToFront(int index) {
00487        if (index <= 0)
00488            return;
00489        
00490        String frontName = getRecentFile(index);
00491        for (int i = index; i >0; i--)
00492            setRecentFile(i, getRecentFile(i-1));
00493        
00494        setRecentFile(0, frontName);
00495     }
00496 
00497     private void addRecentFile(File file) {
00498        try {
00499            String filename = file.getCanonicalPath();
00500            int total = SharpTools.getConfig().getInt("RECENTFILELIST");
00501            for (int i = 0; i < total; i++) {
00502               if (filename.equals(getRecentFile(i))) {
00503                   moveToFront(i);
00504                   return;
00505               }
00506            }
00507            
00508            // now we push it
00509            setRecentFile(total-1, filename);
00510            moveToFront(total-1);
00511        }
00512        catch (Exception e) {
00513        }
00514     }
00515 
00516     
00522     public void createRecentFilesMenu(JMenu menu) {
00523         Config config = SharpTools.getConfig();
00524        menu.removeAll();
00525        
00526        try {
00527            for (int i = 0; i < config.getInt("RECENTFILELIST"); i++) {
00528               String filename = getRecentFile(i);
00529               if (filename.length() > 0) {
00530                   File file = new File(filename);
00531                   JMenuItem item = new JMenuItem(file.getName(), openIcon);
00532                   item.addActionListener(new RecentFileListener(file, this));
00533                   menu.add(item);
00534               }
00535            }
00536            
00537        }
00538        catch (Exception e) {}
00539 
00540     }    
00541     
00542     /*
00543      * Set password and do some extra stuff - always use this function
00544      * to change password value!
00545      */
00546     private void setPasswordValue(String newPassword) {
00547        password = newPassword;
00548        sharp.checkPasswordState();
00549     }
00550     
00551     /*
00552      * Initiates print job by creating a <code>PrintJob</code> object,
00553      * and assigning the current <code>FileOp</code> object to it.
00554      * It then calls up the Print Dialog, and then if user clicks print
00555      * on the dialog, print() is called on the PrintJob object.  This call
00556      * also calls the print method for the FileOp object, which takes
00557      * care of the creation of a printable table
00558      */
00559     public void printData() {
00560        
00561        // create temporary object that contains this FileOp object
00562        // and reset columnOverflow to false
00563        FileOp fileOp = this;
00564        columnOverflow = false;
00565 
00566        try {
00567            PrinterJob prnJob = PrinterJob.getPrinterJob();
00568 
00569            prnJob.setPrintable(fileOp);
00570            
00571            // opens print dialog, and if user doesn't cancel the dialog
00572            // it calls print()
00573            if (!prnJob.printDialog())
00574               return;
00575            maxNumPage = 1;
00576 
00577            prnJob.print();
00578        }
00579        catch (PrinterException e) {
00580            e.printStackTrace();
00581            fileOpError(SharpTools.translation.getProperty("Print"), SharpTools.translation.getProperty("Printing_error")+" : "+e.toString());
00582        }
00583     }
00584     
00585     /*
00586      * Main print method of FileOp that performs calculations for
00587      * dimensions of printed table, and writes the strings out to
00588      * the <code>Graphics</code> object that is responsible for 
00589      * holding the printed data.  All parameters are called by Java
00590      * classes, specifically <code>PrintJob</code>, not explicitly in
00591      * our code
00592      *
00593      * @param pg Graphics object that holds the printed information
00594      * @param pageFormat PageFormat object that holds print dimensions
00595      * @param pageIndex number of current Page
00596      *
00597      * @return status of current call of print method
00598      */
00599     public int print(Graphics pg, PageFormat pageFormat, 
00600                    int pageIndex) throws PrinterException {
00601        // if pageIndex is beyond maximum page number, then
00602        // don't return
00603        if (pageIndex >= maxNumPage)
00604            return NO_SUCH_PAGE;
00605 
00606        // set Graphics object to printed cartesian origin
00607        pg.translate((int)pageFormat.getImageableX(), 
00608                    (int)pageFormat.getImageableY());
00609 
00610        // get printable width and height of page
00611        int wPage = 0;
00612        int hPage = 0;
00613        if (pageFormat.getOrientation() == pageFormat.PORTRAIT) {
00614            wPage = (int)pageFormat.getImageableWidth();
00615            hPage = (int)pageFormat.getImageableHeight();
00616 
00617            wPage = 550;
00618            hPage = 950;
00619        }
00620        else {
00621            wPage = (int)pageFormat.getImageableWidth();
00622            wPage += wPage/2;
00623            hPage = (int)pageFormat.getImageableHeight();
00624            
00625            wPage = 950;
00626            hPage = 550;
00627 
00628            pg.setClip(0,0,wPage,hPage);
00629        }
00630 
00631        // testcode
00632        //     Debug.println(wPage);
00633        //     Debug.println(hPage);
00634 
00635        // create int to keep track of vertical distance
00636        int y = 0;
00637 
00638        // set particular font and color for printing title of file
00639        pg.setColor(Color.black);
00640        Font fn = pg.getFont().deriveFont(Font.BOLD);
00641        FontMetrics fm = pg.getFontMetrics();
00642 
00643        // increment height for title
00644        y += fm.getAscent();
00645 
00646        // if file has no name, then print hard coded string
00647        if(getFile() == null)
00648            pg.drawString("Untitled File", 0, y);
00649        else
00650            pg.drawString(getFile().getName(), 0, y);
00651 
00652        y += 20; // space between title and table headers
00653 
00654 //     Font headerFont = table.getFont().deriveFont(Font.BOLD);
00655 //     pg.setFont(headerFont);
00656 //     fm = pg.getFontMetrics();
00657 
00658        TableColumnModel colModel = table.getColumnModel();
00659        int nColumns = colModel.getColumnCount();
00660        int x[] = new int[nColumns];
00661        x[0] = 0;
00662         
00663        int h = fm.getAscent();
00664        y += h; // add ascent of header font because of baseline
00665        // positioning (see figure 2.10)
00666  
00667        int nRow, nCol;
00668 
00669        // define widths of each column
00670        for (nCol=1; nCol<nColumns; nCol++) {
00671            TableColumn tk = colModel.getColumn(nCol);
00672            int width = tk.getWidth();
00673            // check if table width is within print width
00674            if (x[nCol] + width > wPage) {
00675               nColumns = nCol;
00676               
00677               // show error one time if table width exceeds print width
00678               if(!columnOverflow) {
00679                   fileOpError(SharpTools.translation.getProperty("Print"), SharpTools.translation.getProperty("Table_width_exceeds_printed_width"));
00680                   columnOverflow = true;
00681               }
00682 
00683               break;
00684            }
00685            if (nCol+1<nColumns)
00686               x[nCol+1] = x[nCol] + width;
00687            String title = (String)tk.getIdentifier();
00688            //pg.drawString(title, x[nCol], y);
00689        }
00690        pg.setFont(table.getFont());
00691        fm = pg.getFontMetrics();
00692         
00693        // find out number of rows that can be printed on current page
00694        int header = y;
00695        h = fm.getHeight();
00696        int rowH = Math.max((int)(h*1.5), 10);
00697        int rowPerPage = (hPage-header)/rowH;
00698        maxNumPage = Math.max((int)Math.ceil(table.getRowCount()/
00699                                         (double)rowPerPage), 1);
00700 
00701        // calculate initial and final rows for current page
00702        int iniRow = pageIndex*rowPerPage;
00703        int endRow = Math.min(table.getRowCount(), 
00704                            iniRow+rowPerPage);
00705         
00706        // iterate through each rows for this page
00707        for (nRow=iniRow+1; nRow<endRow; nRow++) {
00708 
00709            y += h; // space between each row
00710 
00711            // iterate through each column on the row, getting data of each
00712            // cell and calling drawString with the data
00713            for (nCol=1; nCol<nColumns; nCol++) {
00714               int col = table.getColumnModel().getColumn(nCol).getModelIndex();
00715               String str = tableModel.getCellAt(nRow, nCol).getValue().toString();
00716               // testcode
00717 //            System.out.println(str);
00718               
00719               pg.setColor(Color.black);
00720               pg.drawString(str, x[nCol], y);
00721            }
00722        }
00723        
00724        // explicit call on garbage collector to flush all temporary data
00725        // used, such as graphics objects
00726        System.gc();
00727        return PAGE_EXISTS;
00728     }
00729 
00730 
00736     public File getFile() {
00737        return file;
00738     }
00739 
00745     public boolean hasPassword() {
00746        return password != null && password.length() > 0;
00747     }
00748     
00752     public void setPassword() {
00753        PasswordDialog passwordDialog = new PasswordDialog(sharp, null);
00754        passwordDialog.setVisible(true);
00755        String text = passwordDialog.getValidatedText();
00756        if (text != null) {
00757            setPasswordValue(text);
00758            tableModel.setPasswordModified(true);
00759        }
00760        table.requestFocus();
00761     }
00762 
00766     private boolean verifyPassword(String password) {
00767 
00768        PasswordDialog passwordDialog = new PasswordDialog(sharp, password);
00769        passwordDialog.pack();
00770        passwordDialog.setLocationRelativeTo(sharp);
00771        passwordDialog.setVisible(true);
00772        String text = passwordDialog.getValidatedText();
00773        table.requestFocus();
00774        return text != null;
00775     }
00776     
00783     private void fileOpError(String op, String error) {    
00784         SharpOptionPane.showMessageDialog(sharp, error, op,
00785                                      JOptionPane.ERROR_MESSAGE, null);
00786        table.requestFocus();
00787     }
00788 
00799     public void actionPerformed(ActionEvent e) {
00800 
00801        if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("New"))==0) {
00802            newFile();
00803        }
00804        else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("OpenFile"))==0) {
00805            openFile();
00806        }
00807        else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("OpenDb"))==0) {
00808            openDb();
00809        }      
00810        else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Save"))==0) {
00811            saveFile();
00812        }      
00813        else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Print"))==0) {
00814            printData();
00815        }
00816        else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Exit"))==0) {
00817            sharp.exit();
00818        }
00819     }
00820 
00827     public void openDb ()
00828     {
00829        int choice;
00830 
00831        // pop up querySave box (yes, no, cancel) and save choice
00832        // if table modified state is modified, else set choice
00833        // to JOptionPane.NO_OPTION which clears cells without
00834        if (tableModel.isModified ())
00835            choice = queryForSave ();
00836        else
00837            choice = JOptionPane.NO_OPTION;
00838        
00839        switch (choice) {
00840        case JOptionPane.YES_OPTION:
00841            // if user chooses yes in dialog box, save document first
00842            // before executing clear range
00843            saveFile ();
00844        case JOptionPane.NO_OPTION:
00845            Database db = new Database(sharp);
00846            db.connectDb();
00847                              
00848        default:
00849            // break out of loop for all choices.  action depends
00850            // on entry point.
00851            break;
00852        }
00853     }        
00854 }
00855 
00861 class RecentFileListener implements ActionListener {
00862     File file;
00863     FileOp fileOp;
00864     
00865     RecentFileListener(File file, FileOp fileOp) {
00866        this.file = file;
00867        this.fileOp = fileOp;
00868     }
00869 
00870     public void actionPerformed(ActionEvent evt) {
00871        fileOp.openTableModel(file);
00872     }
00873 }
00874 
00875 
00876 
00877 
00878 
00879