Picture Purpose
I am customizing an Java App for personal use. This App can make many midi files in Java. I would like to SAVE many files at the same time from Jlist. I already could select many files in one time.
(I already changed below)
public interface ListSelectionModel { int MULTIPLE_INTERVAL_SELECTION
> = 2; }
Problems I can’t save many files at the same time from list (JList).
My idea I am afraid I don’t have good idea. I am not good at Java. I researched this problem in Google and books. I expect i need to use code as below.
idea(1)
File[] files = getSelectedFiles();
idea(2)
Zip system
(Original cord)
/**
* Save File Dialog
*/
private class MidiFileChooser extends JFileChooser {
{
setFileFilter(new FileNameExtensionFilter("MIDI sequence (*.mid)", "mid"));
}
/**
* Save File Action
*/
public Action saveMidiFileAction = getModel().new SelectedSequenceAction(
"Save",
"Save selected MIDI sequence to file - Save Midi to File"
) {
@Override
public void actionPerformed(ActionEvent event) {
PlaylistTableModel playlistModel = getModel();
SequenceTrackListTableModel sequenceModel = playlistModel.getSelectedSequenceModel();
String fn = sequenceModel.getFilename();
if( fn != null && ! fn.isEmpty() ) setSelectedFile(new File(fn));
if( showSaveDialog((Component)event.getSource()) != JFileChooser.APPROVE_OPTION ) return;
File f = getSelectedFile();
if( f.exists() ) {
fn = f.getName();
if( ! confirm("Overwrite " + fn + " ?\n" + fn + " is OK?") ) return;
}
try ( FileOutputStream out = new FileOutputStream(f) ) {
out.write(sequenceModel.getMIDIdata());
sequenceModel.setModified(false);
playlistModel.fireSequenceModified(sequenceModel, false);
}
catch( IOException ex ) {
ex.printStackTrace();
showError( ex.getMessage() );
}
}
};