public void actionPerformed(ActionEvent inEvent) { String actionCommand = inEvent.getActionCommand(); if (actionCommand.equalsIgnoreCase("KEYBOARD_CLOSE_ACTION")) { setVisible(false); if (!isVisible()) { dispose(); } } else if (actionCommand.equalsIgnoreCase("SAVE") || actionCommand.equalsIgnoreCase("SAVE_AS")) { boolean askForFile = false; if (actionCommand.equalsIgnoreCase("SAVE_AS")) { askForFile = true; } else { if (this.file == null) { askForFile = true; } } saveBank(askForFile); } else if (actionCommand.equalsIgnoreCase("SEND_BANK")) { int response = ControlWindow.getInstance() .showConfirmDialog("Transmit", "OK to overwrite bank in Prophet?"); if (response == JOptionPane.YES_OPTION) { try { ControlWindow.getInstance().sendMidiMessage(Machine.makeBankDumpMessage(this.bank)); // this bank is now in the Prophet setBankInProphet(true); } catch (Exception inException) { ControlWindow.getInstance().showErrorDialog("Error", inException); } } } else if (actionCommand.equalsIgnoreCase("SEND_PATCH")) { int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to send."); } else { int patchNumber = (row * kTableColumnCount) + column; Patch patch = this.bank.getPatch(patchNumber); StringBuffer buffer = new StringBuffer(); buffer.append("OK to overwrite patch "); buffer.append(patch.getPatchNumber()); buffer.append(" in Prophet?"); int response = ControlWindow.getInstance().showConfirmDialog("Transmit", buffer.toString()); if (response == JOptionPane.YES_OPTION) { try { ControlWindow.getInstance().sendMidiMessage(Machine.makePatchDumpMessage(patch)); } catch (Exception inException) { ControlWindow.getInstance().showErrorDialog("Error", inException); } } } } else if (actionCommand.equalsIgnoreCase("VARY")) { int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to vary."); } else { int patchNumber = (row * kTableColumnCount) + column; Patch patch = this.bank.getPatchCopy(patchNumber); VaryWindow varyWindow = new VaryWindow(patch); varyWindow.setLocationRelativeTo(null); varyWindow.setVisible(true); } } else if (actionCommand.equalsIgnoreCase("COPY")) { int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to copy."); } else { int patchNumber = (row * kTableColumnCount) + column; Patch patch = this.bank.getPatchCopy(patchNumber); TransferablePatch transferable = new TransferablePatch(patch); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, this); } } else if (actionCommand.equalsIgnoreCase("PASTE")) { int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to paste."); } else { int patchNumber = (row * kTableColumnCount) + column; Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable transferable = clipboard.getContents(this); if (transferable != null) { DataFlavor flavour = new DataFlavor(Patch.class, "Prophet VS Patch"); try { Object data = transferable.getTransferData(flavour); if (data != null && data instanceof Patch) { Patch patch = (Patch) data; // copy the patch! // it might get pasted twice and this is only a reference Patch copy = new Patch(patch); // override the patch number in the patch // so it goes in the right place copy.setPatchNumber(patchNumber); setPatch(copy); } } catch (Exception inException) { System.err.println(inException); } } } } else if (actionCommand.equalsIgnoreCase("SWAP_PASTE")) { // this is a nondestructive paste which swaps the selection & paste buffer int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to swap paste."); } else { int patchNumber = (row * kTableColumnCount) + column; Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable transferable = clipboard.getContents(this); if (transferable != null) { DataFlavor flavour = new DataFlavor(Patch.class, "Prophet VS Patch"); try { Object data = transferable.getTransferData(flavour); if (data != null && data instanceof Patch) { Patch pastePatch = (Patch) data; // ok now copy the selection into the clipboard Patch copyPatch = this.bank.getPatchCopy(patchNumber); transferable = new TransferablePatch(copyPatch); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, this); // and now paste the saved patch into place // override the patch number in the patch // so it goes in the right place pastePatch.setPatchNumber(patchNumber); setPatch(pastePatch); } } catch (Exception inException) { System.err.println(inException); } } } } }