private boolean saveBank(boolean inAskForFile) { boolean saved = false; if (inAskForFile || this.file == null) { File tempFile = ControlWindow.getFileForSave(this, "Save", null); if (tempFile != null) { this.file = tempFile; } } if (this.file != null) { FileOutputStream fos = null; try { fos = new FileOutputStream(this.file); this.bank.write(fos); setBankModified(false); saved = true; } catch (Exception inException) { ControlWindow.getInstance().showErrorDialog("Error", inException); } finally { if (fos != null) { try { fos.close(); } catch (Exception inException) { } } } } return saved; }
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); } } } } }
public void mouseClicked(MouseEvent inEvent) { if (inEvent.getClickCount() == 2) { ControlWindow controlWindow = ControlWindow.getInstance(); if (controlWindow.getPatchWindow() != null) { // close the patch window - will confirm write if dirty PatchWindow patchWindow = controlWindow.getPatchWindow(); // this sets the control window's patch window to null // which we'll check for in a second patchWindow.setVisible(false); } if (controlWindow.getPatchWindow() == null) { if (!this.bankInProphet) { // allow the user to override our flag int response = ControlWindow.showConfirmDialog( "Confirm", "This bank is not in the Prophet. OK to open patch editing windows anyway?"); if (response == JOptionPane.YES_OPTION) { setBankInProphet(true); } } if (this.bankInProphet) { int row = this.table.rowAtPoint(inEvent.getPoint()); int column = this.table.columnAtPoint(inEvent.getPoint()); if (row != -1 && column != -1) { int patchNumber = (row * kTableColumnCount) + column; boolean openEditor = true; // send a program change to the selected patch try { // enable all MIDI parameter options ControlWindow.getInstance().sendMidiMessage(Machine.makeEnableParametersMessage()); // change to the right patch ControlWindow.getInstance().sendMidiProgramChange(patchNumber); } catch (Exception inException) { inException.printStackTrace(System.err); openEditor = false; } // if we had an error sending the midi, confirm the editor window open if (!openEditor) { int response = JOptionPane.showConfirmDialog( this, "Could not send program change to Prophet. OK to open editor window?", "Confirm", JOptionPane.YES_NO_OPTION); openEditor = (response == JOptionPane.YES_OPTION); } if (openEditor) { try { Patch patch = this.bank.getPatchCopy(patchNumber); PatchWindow patchWindow = new PatchWindow(this, this.document, patch); ControlWindow.getInstance().setPatchWindow(patchWindow); patchWindow.setLocationRelativeTo(null); patchWindow.setVisible(true); } catch (Exception inException) { inException.printStackTrace(System.err); ControlWindow.showErrorDialog("Error", inException); } } } } } } }
/** * Constructor. * * @param sto output marshaller */ public CurrentSavePanel(StarTableOutput sto) { super("Current Table", TableSaveChooser.makeFormatBoxModel(sto, false)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); final JList tablesList = ControlWindow.getInstance().getTablesList(); /* Ensure displayed table is always the TOPCAT current table. */ tablesList.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { setDisplayedTable((TopcatModel) tablesList.getSelectedValue()); } }); /* Ensure that current table characteristics are always up to date. */ tcListener_ = new TopcatListener() { public void modelChanged(TopcatEvent evt) { TopcatModel tcModel = evt.getModel(); assert tcModel == tcModel_; int code = evt.getCode(); if (code == TopcatEvent.LABEL) { updateNameField(tcModel); } else if (code == TopcatEvent.CURRENT_SUBSET) { updateRowsField(tcModel); updateSubsetField(tcModel); } else if (code == TopcatEvent.CURRENT_ORDER) { updateOrderField(tcModel); } } }; colListener_ = new TableColumnModelListener() { public void columnAdded(TableColumnModelEvent evt) { updateColsField(tcModel_); } public void columnRemoved(TableColumnModelEvent evt) { updateColsField(tcModel_); } public void columnMoved(TableColumnModelEvent evt) {} public void columnMarginChanged(ChangeEvent evt) {} public void columnSelectionChanged(ListSelectionEvent evt) {} }; /* Place components. */ setLayout(new BorderLayout()); LabelledComponentStack stack = new LabelledComponentStack(); Font inputFont = stack.getInputFont(); add(stack, BorderLayout.NORTH); nameField_ = new JLabel(); subsetField_ = new JLabel(); orderField_ = new JLabel(); colsField_ = new JLabel(); rowsField_ = new JLabel(); nameField_.setFont(inputFont); subsetField_.setFont(inputFont); orderField_.setFont(inputFont); colsField_.setFont(inputFont); rowsField_.setFont(inputFont); stack.addLine("Table", nameField_); stack.addLine("Current Subset", subsetField_); stack.addLine("Sort Order", orderField_); /* I thought this might be a good idea, but probably it's too much * information. */ if (false) { stack.addLine("Columns", colsField_); stack.addLine("Rows", rowsField_); } setDisplayedTable((TopcatModel) tablesList.getSelectedValue()); }