if (table.getRowCount ()>0) { PatchEdit.saveAction.setEnabled (true); PatchEdit.menuSaveAs.setEnabled (true); PatchEdit.searchAction.setEnabled (true); } if (table.getRowCount ()>1) { PatchEdit.sortAction.setEnabled (true); PatchEdit.dupAction.setEnabled (true); } if (table.getSelectedRowCount ()>0) { PatchEdit.extractAction.setEnabled (true); PatchEdit.sendAction.setEnabled (true); PatchEdit.playAction.setEnabled (true); PatchEdit.storeAction.setEnabled (true); PatchEdit.editAction.setEnabled (true); PatchEdit.cutAction.setEnabled (true); PatchEdit.copyAction.setEnabled (true); PatchEdit.deleteAction.setEnabled (true); PatchEdit.exportAction.setEnabled (true); }   } public void internalFrameClosed (InternalFrameEvent e) {}  public void internalFrameDeactivated (InternalFrameEvent e) { PatchEdit.receiveAction.setEnabled (false); PatchEdit.extractAction.setEnabled (false); PatchEdit.sendAction.setEnabled (false); PatchEdit.playAction.setEnabled (false); PatchEdit.storeAction.setEnabled (false); PatchEdit.editAction.setEnabled (false); PatchEdit.saveAction.setEnabled (false); PatchEdit.menuSaveAs.setEnabled (false); PatchEdit.sortAction.setEnabled (false); PatchEdit.searchAction.setEnabled (false); PatchEdit.dupAction.setEnabled (false); PatchEdit.cutAction.setEnabled (false); PatchEdit.copyAction.setEnabled (false); PatchEdit.pasteAction.setEnabled (false); PatchEdit.deleteAction.setEnabled (false); PatchEdit.importAction.setEnabled (false); PatchEdit.importAllAction.setEnabled (false); PatchEdit.exportAction.setEnabled (false);
if (table.getRowCount()>0) { PatchEdit.saveAction.setEnabled(true); PatchEdit.menuSaveAs.setEnabled(true); PatchEdit.searchAction.setEnabled(true); }  if (table.getRowCount()>1) { PatchEdit.sortAction.setEnabled(true); PatchEdit.dupAction.setEnabled(true); }  if (table.getSelectedRowCount()>0) { PatchEdit.extractAction.setEnabled(true); PatchEdit.sendAction.setEnabled(true); PatchEdit.playAction.setEnabled(true); PatchEdit.storeAction.setEnabled(true);  Patch myPatch=((Patch)myModel.PatchList.get(table.getSelectedRow())); try{  myPatch.getDriver().getClass().getDeclaredMethod("editPatch", new Class[]{myPatch.getClass()});  PatchEdit.editAction.setEnabled(true); } catch(NoSuchMethodException ex) {  if (myPatch.getDriver() instanceof BankDriver) {  PatchEdit.editAction.setEnabled(true); } else {  PatchEdit.editAction.setEnabled(false); } };  PatchEdit.cutAction.setEnabled(true); PatchEdit.copyAction.setEnabled(true); PatchEdit.deleteAction.setEnabled(true); PatchEdit.exportAction.setEnabled(true); }    }  public void internalFrameClosed(InternalFrameEvent e) {}  public void internalFrameDeactivated(InternalFrameEvent e) { PatchEdit.receiveAction.setEnabled(false); PatchEdit.extractAction.setEnabled(false); PatchEdit.sendAction.setEnabled(false); PatchEdit.playAction.setEnabled(false); PatchEdit.storeAction.setEnabled(false); PatchEdit.editAction.setEnabled(false); PatchEdit.saveAction.setEnabled(false); PatchEdit.menuSaveAs.setEnabled(false); PatchEdit.sortAction.setEnabled(false); PatchEdit.searchAction.setEnabled(false); PatchEdit.dupAction.setEnabled(false); PatchEdit.cutAction.setEnabled(false); PatchEdit.copyAction.setEnabled(false); PatchEdit.pasteAction.setEnabled(false); PatchEdit.deleteAction.setEnabled(false); PatchEdit.importAction.setEnabled(false); PatchEdit.importAllAction.setEnabled(false); PatchEdit.exportAction.setEnabled(false);
    protected void InitLibraryFrame ()    {        //...Create the GUI and put it in the window...        addInternalFrameListener (new InternalFrameListener ()        {            public void internalFrameClosing (InternalFrameEvent e)            {               	        if (!changed) return;                int i;	        JInternalFrame[] jList =PatchEdit.desktop.getAllFrames ();  	        for (int j=0;j<jList.length;j++)		 {	               if (jList[j] instanceof BankEditorFrame) 		     {    		        for (i=0;i<myModel.PatchList.size();i++)	                     if (((BankEditorFrame)(jList[j])).bankData==((Patch)(myModel.PatchList.get(i))))			     { jList[j].moveToFront();			     try{jList[j].setSelected(true);			     jList[j].setClosed(true); }catch (Exception e1){}			       break;}		     }		    		    if (jList[j] instanceof PatchEditorFrame) 		     {    		        for (i=0;i<myModel.PatchList.size();i++)	                     if (((PatchEditorFrame)(jList[j])).p==((Patch)(myModel.PatchList.get(i))))			     { jList[j].moveToFront();			     try{jList[j].setSelected(true);			     jList[j].setClosed(true); }catch (Exception e1){}			       break;}		     }		 }	                      if (JOptionPane.showConfirmDialog (null,"This Library may contain unsaved data.\nSave before closing?","Delete Duplicate Patches",JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return;                if (getTitle ().startsWith ("Unsaved Library"))                {                    JFileChooser fc2=new JFileChooser ();                    javax.swing.filechooser.FileFilter type1 = new ExtensionFilter ("PatchEdit Library Files",".patchlib");                    fc2.addChoosableFileFilter (type1);                    fc2.setFileFilter (type1);                    int returnVal = fc2.showSaveDialog (null);                    if (returnVal == JFileChooser.APPROVE_OPTION)                    {                        File file = fc2.getSelectedFile ();                        try                        {                            if (!file.getName ().toUpperCase ().endsWith (".PATCHLIB"))                                file=new File (file.getPath ()+".patchlib");                            if (file.isDirectory ())                            { ErrorMsg.reportError ("Error", "Can not save over a directory");                              return;                            }                            if (file.exists ())                                if (JOptionPane.showConfirmDialog (null,"Are you sure?","File Exists",JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return;                                                        save (file);                        } catch (Exception ex)                        {                            ErrorMsg.reportError ("Error", "Error saving File",ex);                        }                                            }                    return;                }                                try                {                    save ();                } catch (Exception ex)                {};            }            public void internalFrameOpened (InternalFrameEvent e)            {}            public void internalFrameActivated (InternalFrameEvent e)            {                PatchEdit.receiveAction.setEnabled (true);                PatchEdit.pasteAction.setEnabled (true);                PatchEdit.importAction.setEnabled (true);                PatchEdit.importAllAction.setEnabled (true);                PatchEdit.newPatchAction.setEnabled(true);                PatchEdit.crossBreedAction.setEnabled(true);                                             if (table.getRowCount ()>0)                {                    PatchEdit.saveAction.setEnabled (true);                    PatchEdit.menuSaveAs.setEnabled (true);                    PatchEdit.searchAction.setEnabled (true);                }                if (table.getRowCount ()>1)                {                    PatchEdit.sortAction.setEnabled (true);                    PatchEdit.dupAction.setEnabled (true);                }                if (table.getSelectedRowCount ()>0)                {                    PatchEdit.extractAction.setEnabled (true);                    PatchEdit.sendAction.setEnabled (true);                    PatchEdit.playAction.setEnabled (true);                    PatchEdit.storeAction.setEnabled (true);                    PatchEdit.editAction.setEnabled (true);                    PatchEdit.cutAction.setEnabled (true);                    PatchEdit.copyAction.setEnabled (true);                    PatchEdit.deleteAction.setEnabled (true);                    PatchEdit.exportAction.setEnabled (true);                }                //                System.out.println ("Frame activated"+table.getSelectedRowCount ());            }            public void internalFrameClosed (InternalFrameEvent e)            {}                        public void internalFrameDeactivated (InternalFrameEvent e)            {                PatchEdit.receiveAction.setEnabled (false);		PatchEdit.extractAction.setEnabled (false);                PatchEdit.sendAction.setEnabled (false);                PatchEdit.playAction.setEnabled (false);                PatchEdit.storeAction.setEnabled (false);                PatchEdit.editAction.setEnabled (false);                PatchEdit.saveAction.setEnabled (false);                PatchEdit.menuSaveAs.setEnabled (false);                PatchEdit.sortAction.setEnabled (false);                PatchEdit.searchAction.setEnabled (false);                PatchEdit.dupAction.setEnabled (false);                PatchEdit.cutAction.setEnabled (false);                PatchEdit.copyAction.setEnabled (false);                PatchEdit.pasteAction.setEnabled (false);                PatchEdit.deleteAction.setEnabled (false);                PatchEdit.importAction.setEnabled (false);                PatchEdit.importAllAction.setEnabled (false);                PatchEdit.exportAction.setEnabled (false);                PatchEdit.newPatchAction.setEnabled(false);                PatchEdit.crossBreedAction.setEnabled(false);                //                System.out.println ("Frame deactivated");            }            public void internalFrameDeiconified (InternalFrameEvent e)            {}            public void internalFrameIconified (InternalFrameEvent e)            {}                    });                                myModel = new PatchListModel (changed);        table = new DNDLibraryTable (myModel);        table2=table;        table.setPreferredScrollableViewportSize (new Dimension (500, 70));        table.addMouseListener (new MouseAdapter ()        {            public void mousePressed (MouseEvent e)            {                                if(e.isPopupTrigger ())                {                    PatchEdit.menuPatchPopup.show (table2, e.getX (), e.getY ());                    table2.setRowSelectionInterval (                    table2.rowAtPoint (new Point (e.getX (),e.getY ())),                    table2.rowAtPoint (new Point (e.getX (),e.getY ()))                    );                                    }            }            public void mouseReleased (MouseEvent e)            {                if(e.isPopupTrigger ())                {                    PatchEdit.menuPatchPopup.show (table2, e.getX (), e.getY ());                    table2.setRowSelectionInterval (                    table2.rowAtPoint (new Point (e.getX (),e.getY ())),                    table2.rowAtPoint (new Point (e.getX (),e.getY ()))                    );                                    }            }            public void mouseClicked (MouseEvent e)            {                if(e.getClickCount ()==2)                {                    PlaySelectedPatch ();                }            }        });                //Create the scroll  pane and add the table to it.        JScrollPane scrollPane = new JScrollPane (table);                scrollPane.getVerticalScrollBar ().addMouseListener (new MouseAdapter ()        {            public void mousePressed (MouseEvent e)            {}            public void mouseReleased (MouseEvent e)            {                myModel.fireTableDataChanged ();            }        });                        //Add the scroll pane to this window.        JPanel statusPanel=new JPanel ();        statusBar=new JLabel (myModel.PatchList.size ()+" Patches");        statusPanel.add (statusBar);                getContentPane ().add (scrollPane, BorderLayout.CENTER);        getContentPane ().add (statusPanel, BorderLayout.SOUTH);                      TableColumn column = null;        column = table.getColumnModel ().getColumn (0);        column.setPreferredWidth (50);        column = table.getColumnModel ().getColumn (1);        column.setPreferredWidth (50);        column = table.getColumnModel ().getColumn (2);        column.setPreferredWidth (100);        column = table.getColumnModel ().getColumn (3);        column.setPreferredWidth (50);        column = table.getColumnModel ().getColumn (4);        column.setPreferredWidth (50);        column = table.getColumnModel ().getColumn (5);        column.setPreferredWidth (200);                //...Then set the window size or call pack...        setSize (600,300);                //Set the window's location.        setLocation (xOffset*openFrameCount, yOffset*openFrameCount);                this.addFocusListener (new FocusListener ()        {            public void focusGained (FocusEvent e)            {               // System.out.println ("Focus Gained");            }            public void focusLost (FocusEvent e)            {                //System.out.println ("Focus Lost");            }        });                table.getModel ().addTableModelListener ( new TableModelListener ()        {            public void tableChanged (TableModelEvent e)            {                if (((PatchListModel)e.getSource ()).getRowCount ()>0)                {                    PatchEdit.saveAction.setEnabled (true);                    PatchEdit.menuSaveAs.setEnabled (true);                    PatchEdit.searchAction.setEnabled (true);		    PatchEdit.exportAction.setEnabled (true);		                    }                if (((PatchListModel)e.getSource ()).getRowCount ()>1)                {                    PatchEdit.sortAction.setEnabled (true);                    PatchEdit.dupAction.setEnabled (true);                    PatchEdit.crossBreedAction.setEnabled(true);                              }            }        }        );                table.getSelectionModel ().addListSelectionListener (new ListSelectionListener ()        {            public void valueChanged (ListSelectionEvent e)            {                //System.out.println ("ValueChanged"+((ListSelectionModel)e.getSource ()).getMaxSelectionIndex ());                if (((ListSelectionModel)e.getSource ()).getMaxSelectionIndex ()>=0)                {                    PatchEdit.extractAction.setEnabled (true);                    PatchEdit.sendAction.setEnabled (true);                    PatchEdit.playAction.setEnabled (true);                    PatchEdit.storeAction.setEnabled (true);                    PatchEdit.editAction.setEnabled (true);                    PatchEdit.copyAction.setEnabled (true);                    PatchEdit.cutAction.setEnabled (true);                    PatchEdit.deleteAction.setEnabled (true);                    PatchEdit.exportAction.setEnabled (true);                                    }                else                {                    PatchEdit.extractAction.setEnabled (false);                    PatchEdit.sendAction.setEnabled (false);                    PatchEdit.playAction.setEnabled (false);                    PatchEdit.storeAction.setEnabled (false);                    PatchEdit.editAction.setEnabled (false);                    PatchEdit.copyAction.setEnabled (false);                    PatchEdit.cutAction.setEnabled (false);                    PatchEdit.deleteAction.setEnabled (false);                                    }            }        });    }