@Override
public void saveData() {
boolean flag=false;
UserConfiguration uc=UserConfiguration.getInstance();
ApplicationContext ctx=ApplicationContext.getInstance();
try {
this.midiOutIndex=midiOutBox.getSelectedIndex();
uc.putProperty(MIDI_OUT_DEVICE, midiOutIndex);
MidiDevice.Info outInfo=(MidiDevice.Info)midiOutBox.getSelectedItem();
this.metronomeIndex=metronomeOutBox.getSelectedIndex();
uc.putProperty(MIDI_METRONOME_DEVICE, metronomeIndex);
MidiDevice.Info metronomeInfo=null;
if (metronomeIndex>0) {
metronomeInfo=(MidiDevice.Info)metronomeOutBox.getSelectedItem();
}
this.keyInIndex=keyboardInBox.getSelectedIndex();
uc.putProperty(KEYBOARD_IN_DEVICE, keyInIndex);
MidiDevice.Info keyInfo=(MidiDevice.Info)keyboardInBox.getSelectedItem();
MidiDevice metroDev=null;
if (metronomeInfo!=null) {
metroDev=MidiSystem.getMidiDevice(metronomeInfo);
if (metroDev.getMaxReceivers()==0) {
JOptionPane.showMessageDialog(ctx.getDefaultDialogOwner(),
ResourceFactory.getString(MESSAGE_NO_RECEIVER),
ResourceFactory.getString(TITLE_MIDI_INIT_FAILED),
JOptionPane.ERROR_MESSAGE);
}
}
MidiDevice outDev=MidiSystem.getMidiDevice(outInfo);
if (outDev.getMaxReceivers()==0) {
JOptionPane.showMessageDialog(ctx.getDefaultDialogOwner(),
ResourceFactory.getString(MESSAGE_NO_RECEIVER),
ResourceFactory.getString(TITLE_MIDI_INIT_FAILED),
JOptionPane.ERROR_MESSAGE);
}
MidiDevice keyDev=MidiSystem.getMidiDevice(keyInfo);
if (keyDev.getMaxTransmitters()==0) {
JOptionPane.showMessageDialog(ctx.getDefaultDialogOwner(),
ResourceFactory.getString(MESSAGE_NO_TRANSMITTER),
ResourceFactory.getString(TITLE_MIDI_INIT_FAILED),
JOptionPane.ERROR_MESSAGE);
}
flag=MidiThread.getInstance().init(keyDev, outDev, metroDev);
} catch (Exception ex) {
log.error("failed to init midi thread", ex);
}
if (flag) {
ctx.setMidiStatus(ApplicationContext.MidiStatus.ON);
} else {
ctx.setMidiStatus(ApplicationContext.MidiStatus.OFF);
JOptionPane.showMessageDialog(ctx.getDefaultDialogOwner(),
ResourceFactory.getString(MESSAGE_MIDI_INIT_FAILED),
ResourceFactory.getString(TITLE_MIDI_INIT_FAILED),
JOptionPane.ERROR_MESSAGE);
}
}