@Override
    public void actionPerformed(ActionEvent e){
        //System.out.println(e.getActionCommand());
        if (e.getActionCommand().compareTo("Copy")==0 ||
                e.getActionCommand().compareTo("Copy_Mac")==0){
            StringBuilder sbf =new StringBuilder();
            // Check to ensure we have selected only a contiguous block of
            // cells
            int numcols=jTable1.getSelectedColumnCount();
            int nrows = jTable1.getRowCount();
            int numrows=jTable1.getSelectedRowCount();
            int[] rowsselected=jTable1.getSelectedRows();
            int[] colsselected=jTable1.getSelectedColumns();
            /*
            if (!((numrows-1==rowsselected[rowsselected.length-1]-rowsselected[0] &&
                numrows==rowsselected.length) &&
            (numcols-1==colsselected[colsselected.length-1]-colsselected[0] &&
                numcols==colsselected.length))){
                JOptionPane.showMessageDialog(this, "Invalid Copy Selection",
                                              "Invalid Copy Selection",
                                              JOptionPane.ERROR_MESSAGE);
                return;
            }*/
            String names[] = new String[numcols];
            for (int j=0;j<numcols;j++){
                names[j] = jTable1.getColumnName(colsselected[j]);
                sbf.append(names[j]);
                if (j<numcols-1) sbf.append("\t");
            }
            sbf.append("\n");

            for (int i=0;i<nrows;i++){
                for (int j=0;j<numcols;j++){
                    //sbf.append(jTable1.getValueAt(i,colsselected[j]));
                    Element el = dataFrame.get(names[j]).get(i);
                    if(el != null){
                        if(el instanceof Numeric){
                            Numeric elnum = (Numeric)el;
                            sbf.append(Double.toString(elnum.getValue()));
                        }else
                            sbf.append(dataFrame.get(names[j]).get(i).toString());
                    }else{
                        sbf.append("");
                    }
                    if (j<numcols-1) sbf.append("\t");
                }
                sbf.append("\n");
            }
            stsel  = new StringSelection(sbf.toString());
            system = Toolkit.getDefaultToolkit().getSystemClipboard();
            system.setContents(stsel, stsel);
        }
        /*
        if (e.getActionCommand().compareTo("Paste")==0){
            //System.out.println("Trying to Paste");
            int startRow=(jTable1.getSelectedRows())[0];
            int startCol=(jTable1.getSelectedColumns())[0];
            try{
                String trstring= (String)(system.getContents(this).getTransferData(DataFlavor.stringFlavor));
                //System.out.println("String is:"+trstring);
                StringTokenizer st1=new StringTokenizer(trstring,"\n");
                for(int i=0;st1.hasMoreTokens();i++){
                    rowstring=st1.nextToken();
                    StringTokenizer st2=new StringTokenizer(rowstring,"\t");
                    for(int j=0;st2.hasMoreTokens();j++){
                        value = st2.nextToken();
                        if (startRow+i< jTable1.getRowCount()  &&
                           startCol+j< jTable1.getColumnCount())
                            jTable1.setValueAt(value,startRow+i,startCol+j);
                        //System.out.println("Putting "+ value+"atrow="+startRow+i+"column="+startCol+j);
                    }
                }
            }catch(Exception ex){ex.printStackTrace();}
        }
         */
    }