1
package org.herac.tuxguitar.player.impl.jsa.utils;
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.events.SelectionAdapter;
5
import org.eclipse.swt.events.SelectionEvent;
6
import org.eclipse.swt.layout.GridData;
7
import org.eclipse.swt.layout.GridLayout;
8
import org.eclipse.swt.widgets.Button;
9
import org.eclipse.swt.widgets.Composite;
10
import org.eclipse.swt.widgets.Group;
11
import org.eclipse.swt.widgets.Shell;
12
import org.eclipse.swt.widgets.Text;
13
import org.herac.tuxguitar.gui.TuxGuitar;
14
import org.herac.tuxguitar.gui.system.config.TGConfigManager;
15
import org.herac.tuxguitar.gui.system.plugins.TGPluginConfigManager;
16
import org.herac.tuxguitar.gui.util.DialogUtils;
17
import org.herac.tuxguitar.gui.util.FileChooser;
18
import org.herac.tuxguitar.gui.util.MessageDialog;
20
public class MidiConfigUtils {
22
public static final String SOUNDBANK_KEY = "soundbank.custom.path";
24
public static TGConfigManager getConfig(){
25
TGConfigManager config = new TGPluginConfigManager("tuxguitar-jsa");
30
public static String getSoundbankPath(){
31
return getSoundbankPath(getConfig());
34
public static String getSoundbankPath(final TGConfigManager config){
35
return config.getStringConfigValue(SOUNDBANK_KEY);
38
public static void setupDialog(Shell parent) {
39
setupDialog(parent,getConfig());
42
public static void setupDialog(Shell parent,final TGConfigManager config) {
43
final String soundbank = getSoundbankPath(config);
45
final Shell dialog = DialogUtils.newDialog(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
46
dialog.setLayout(new GridLayout());
47
dialog.setText(TuxGuitar.getProperty("jsa.settings.title"));
49
//------------------SOUNDBANK-----------------------
51
Group group = new Group(dialog,SWT.SHADOW_ETCHED_IN);
52
group.setLayout(new GridLayout());
53
group.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
54
group.setText(TuxGuitar.getProperty("jsa.settings.soundbank.tip"));
56
final Button sbDefault = new Button(group,SWT.RADIO);
57
sbDefault.setText(TuxGuitar.getProperty("jsa.settings.soundbank.default"));
58
sbDefault.setSelection( (soundbank == null) );
60
final Button sbCustom = new Button(group,SWT.RADIO);
61
sbCustom.setText(TuxGuitar.getProperty("jsa.settings.soundbank.custom"));
62
sbCustom.setSelection( (soundbank != null) );
64
Composite chooser = new Composite(group,SWT.NONE);
65
chooser.setLayout(new GridLayout(2,false));
67
final Text sbCustomPath = new Text(chooser,SWT.BORDER);
68
sbCustomPath.setLayoutData(new GridData(350,SWT.DEFAULT));
69
sbCustomPath.setText( (soundbank == null ? new String() : soundbank) );
71
final Button sbCustomChooser = new Button(chooser,SWT.PUSH);
72
sbCustomChooser.setImage(TuxGuitar.instance().getIconManager().getFileOpen());
73
sbCustomChooser.addSelectionListener(new SelectionAdapter() {
74
public void widgetSelected(SelectionEvent e) {
75
String fileName = FileChooser.instance().open(dialog,FileChooser.ALL_FORMATS);
77
sbCustomPath.setText(fileName);
82
//------------------BUTTONS--------------------------
83
Composite buttons = new Composite(dialog, SWT.NONE);
84
buttons.setLayout(new GridLayout(2,false));
85
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
87
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
88
data.minimumWidth = 80;
89
data.minimumHeight = 25;
91
final Button buttonOK = new Button(buttons, SWT.PUSH);
92
buttonOK.setText(TuxGuitar.getProperty("ok"));
93
buttonOK.setLayoutData(data);
94
buttonOK.addSelectionListener(new SelectionAdapter() {
95
public void widgetSelected(SelectionEvent arg0) {
96
String selection = ( sbCustom.getSelection() ? sbCustomPath.getText() : null);
98
boolean changed = false;
99
changed = (selection == null && soundbank != null);
100
changed = changed || (selection != null && soundbank == null);
101
changed = changed || (selection != null && !selection.equals(soundbank) ) ;
103
if(selection != null){
104
config.setProperty(SOUNDBANK_KEY,selection);
106
config.removeProperty(SOUNDBANK_KEY);
110
MessageDialog.infoMessage(TuxGuitar.getProperty("warning"), TuxGuitar.getProperty("jsa.settings.soundbank-restart-message"));
116
Button buttonCancel = new Button(buttons, SWT.PUSH);
117
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
118
buttonCancel.setLayoutData(data);
119
buttonCancel.addSelectionListener(new SelectionAdapter() {
120
public void widgetSelected(SelectionEvent arg0) {
125
dialog.setDefaultButton( buttonOK );
127
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);