~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar-jsa/src/org/herac/tuxguitar/player/impl/jsa/utils/MidiConfigUtils.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.player.impl.jsa.utils;
 
2
 
 
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;
 
19
 
 
20
public class MidiConfigUtils {
 
21
        
 
22
        public static final String SOUNDBANK_KEY = "soundbank.custom.path";
 
23
        
 
24
        public static TGConfigManager getConfig(){
 
25
                TGConfigManager config = new TGPluginConfigManager("tuxguitar-jsa");
 
26
                config.init();
 
27
                return config;
 
28
        }
 
29
        
 
30
        public static String getSoundbankPath(){
 
31
                return getSoundbankPath(getConfig());
 
32
        }
 
33
        
 
34
        public static String getSoundbankPath(final TGConfigManager config){
 
35
                return config.getStringConfigValue(SOUNDBANK_KEY);
 
36
        }
 
37
        
 
38
        public static void setupDialog(Shell parent) {
 
39
                setupDialog(parent,getConfig());
 
40
        }
 
41
        
 
42
        public static void setupDialog(Shell parent,final TGConfigManager config) {
 
43
                final String soundbank = getSoundbankPath(config);
 
44
                
 
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"));
 
48
                
 
49
                //------------------SOUNDBANK-----------------------
 
50
                
 
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"));
 
55
                
 
56
                final Button sbDefault = new Button(group,SWT.RADIO);
 
57
                sbDefault.setText(TuxGuitar.getProperty("jsa.settings.soundbank.default"));
 
58
                sbDefault.setSelection( (soundbank == null) );
 
59
                
 
60
                final Button sbCustom = new Button(group,SWT.RADIO);
 
61
                sbCustom.setText(TuxGuitar.getProperty("jsa.settings.soundbank.custom"));
 
62
                sbCustom.setSelection( (soundbank != null) );
 
63
                
 
64
                Composite chooser = new Composite(group,SWT.NONE);
 
65
                chooser.setLayout(new GridLayout(2,false));
 
66
                
 
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)  );
 
70
                
 
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);
 
76
                                if(fileName != null){
 
77
                                        sbCustomPath.setText(fileName);
 
78
                                }
 
79
                        }
 
80
                });
 
81
                
 
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));
 
86
                
 
87
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
 
88
                data.minimumWidth = 80;
 
89
                data.minimumHeight = 25;
 
90
                
 
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);
 
97
                                
 
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) ) ;
 
102
                                if(changed){
 
103
                                        if(selection != null){
 
104
                                                config.setProperty(SOUNDBANK_KEY,selection);
 
105
                                        }else{
 
106
                                                config.removeProperty(SOUNDBANK_KEY);
 
107
                                        }
 
108
                                        config.save();
 
109
                                        
 
110
                                        MessageDialog.infoMessage(TuxGuitar.getProperty("warning"), TuxGuitar.getProperty("jsa.settings.soundbank-restart-message"));
 
111
                                }
 
112
                                dialog.dispose();
 
113
                        }
 
114
                });
 
115
                
 
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) {
 
121
                                dialog.dispose();
 
122
                        }
 
123
                });
 
124
                
 
125
                dialog.setDefaultButton( buttonOK );
 
126
                
 
127
                DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
 
128
        }
 
129
}