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

« back to all changes in this revision

Viewing changes to TuxGuitar-oss/src/org/herac/tuxguitar/player/impl/midiport/oss/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.midiport.oss;
 
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.Label;
 
12
import org.eclipse.swt.widgets.Shell;
 
13
import org.eclipse.swt.widgets.Text;
 
14
import org.herac.tuxguitar.gui.TuxGuitar;
 
15
import org.herac.tuxguitar.gui.system.config.TGConfigManager;
 
16
import org.herac.tuxguitar.gui.system.plugins.TGPluginConfigManager;
 
17
import org.herac.tuxguitar.gui.util.DialogUtils;
 
18
 
 
19
public class MidiConfigUtils {
 
20
        
 
21
        public static final String DEVICE_KEY = "oss.device";
 
22
        
 
23
        public static final String DEVICE_DEFAULT = "/dev/sequencer";
 
24
        
 
25
        public static TGConfigManager getConfig(){
 
26
                TGConfigManager config = new TGPluginConfigManager("tuxguitar-oss");
 
27
                config.init();
 
28
                return config;
 
29
        }
 
30
        
 
31
        public static String getDevice(){
 
32
                return getDevice(getConfig());
 
33
        }
 
34
        
 
35
        public static String getDevice(final TGConfigManager config){
 
36
                return config.getStringConfigValue(DEVICE_KEY,DEVICE_DEFAULT);
 
37
        }
 
38
        
 
39
        public static void setupDialog(Shell parent,final MidiPortProviderImpl provider) {
 
40
                setupDialog(parent,provider,getConfig());
 
41
        }
 
42
        
 
43
        public static void setupDialog(Shell parent,final MidiPortProviderImpl provider,final TGConfigManager config) {
 
44
                final String device = getDevice(config);
 
45
                
 
46
                final Shell dialog = DialogUtils.newDialog(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
47
                dialog.setLayout(new GridLayout());
 
48
                dialog.setText("Configuration");
 
49
                
 
50
                //------------------DEVICE-----------------------
 
51
                Group group = new Group(dialog,SWT.SHADOW_ETCHED_IN);
 
52
                group.setLayout(new GridLayout(2,false));
 
53
                group.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
54
                group.setText("Device Configuration");
 
55
                
 
56
                final Label deviceLabel = new Label(group,SWT.LEFT);
 
57
                deviceLabel.setText("Device:");
 
58
                
 
59
                final Text deviceValue = new Text(group,SWT.BORDER);
 
60
                deviceValue.setLayoutData(new GridData(250,SWT.DEFAULT));
 
61
                deviceValue.setText( (device == null ? new String() : device) );
 
62
                
 
63
                //------------------BUTTONS--------------------------
 
64
                Composite buttons = new Composite(dialog, SWT.NONE);
 
65
                buttons.setLayout(new GridLayout(2,false));
 
66
                buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
 
67
                
 
68
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
 
69
                data.minimumWidth = 80;
 
70
                data.minimumHeight = 25;
 
71
                
 
72
                final Button buttonOK = new Button(buttons, SWT.PUSH);
 
73
                buttonOK.setText(TuxGuitar.getProperty("ok"));
 
74
                buttonOK.setLayoutData(data);
 
75
                buttonOK.addSelectionListener(new SelectionAdapter() {
 
76
                        public void widgetSelected(SelectionEvent arg0) {
 
77
                                String selection = deviceValue.getText();
 
78
                                
 
79
                                String value1 = (device == null ? new String() : device);
 
80
                                String value2 = (selection == null ? new String() : selection);
 
81
                                if(!value1.equals(value2)){
 
82
                                        if(selection != null){
 
83
                                                config.setProperty(DEVICE_KEY,selection);
 
84
                                        }else{
 
85
                                                config.removeProperty(DEVICE_KEY);
 
86
                                        }
 
87
                                        config.save();
 
88
                                        provider.updateDevice(selection);
 
89
                                }
 
90
                                dialog.dispose();
 
91
                        }
 
92
                });
 
93
                
 
94
                Button buttonCancel = new Button(buttons, SWT.PUSH);
 
95
                buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
96
                buttonCancel.setLayoutData(data);
 
97
                buttonCancel.addSelectionListener(new SelectionAdapter() {
 
98
                        public void widgetSelected(SelectionEvent arg0) {
 
99
                                dialog.dispose();
 
100
                        }
 
101
                });
 
102
                
 
103
                dialog.setDefaultButton( buttonOK );
 
104
                
 
105
                DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
 
106
        }
 
107
}