1
package org.herac.tuxguitar.player.impl.midiport.fluidsynth;
3
import java.util.ArrayList;
4
import java.util.Iterator;
7
import org.eclipse.swt.SWT;
8
import org.eclipse.swt.events.SelectionAdapter;
9
import org.eclipse.swt.events.SelectionEvent;
10
import org.eclipse.swt.layout.GridData;
11
import org.eclipse.swt.layout.GridLayout;
12
import org.eclipse.swt.widgets.Button;
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.FileDialog;
15
import org.eclipse.swt.widgets.Shell;
16
import org.eclipse.swt.widgets.Table;
17
import org.eclipse.swt.widgets.TableColumn;
18
import org.eclipse.swt.widgets.TableItem;
19
import org.herac.tuxguitar.gui.TuxGuitar;
20
import org.herac.tuxguitar.gui.system.config.TGConfigManager;
21
import org.herac.tuxguitar.gui.system.plugins.TGPluginConfigManager;
22
import org.herac.tuxguitar.gui.util.DialogUtils;
24
public class MidiPortSettings {
26
private static final int TABLE_WIDTH = 350;
27
private static final int TABLE_HEIGHT = 200;
29
public MidiPortSettings(){
33
public static TGConfigManager getConfig(){
34
TGConfigManager config = new TGPluginConfigManager("tuxguitar-fluidsynth");
39
public List getSoundfonts(){
40
List ports = new ArrayList();
41
TGConfigManager config = getConfig();
43
int count = config.getIntConfigValue("soundfont.count");
44
for(int i = 0; i < count;i ++){
45
String path = config.getStringConfigValue("soundfont.path" + i);
46
if(path != null && path.length() > 0 ){
53
public void setSoundfonts(List soundfonts){
54
TGConfigManager config = getConfig();
55
config.setProperty("soundfont.count", soundfonts.size() );
56
for( int i = 0 ; i < soundfonts.size() ; i ++ ){
57
String path = (String)soundfonts.get( i );
58
config.setProperty("soundfont.path" + i, path );
63
public void configure(Shell parent) {
64
final Shell dialog = DialogUtils.newDialog(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
65
dialog.setText(TuxGuitar.getProperty("fluidsynth.settings"));
66
dialog.setLayout(new GridLayout(2,false));
67
dialog.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
68
// ----------------------------------------------------------------------
69
Composite compositeTable = new Composite(dialog, SWT.NONE);
70
compositeTable.setLayout(new GridLayout());
71
compositeTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
73
final Table table = new Table(compositeTable, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
74
table.setLayoutData(new GridData(TABLE_WIDTH,TABLE_HEIGHT));
75
table.setHeaderVisible(true);
77
TableColumn column = new TableColumn(table, SWT.NONE);
78
column.setWidth(TABLE_WIDTH);
79
column.setText(TuxGuitar.getProperty("fluidsynth.settings.soundfont-list"));
81
// ------------------BUTTONS--------------------------
82
Composite compositeButtons = new Composite(dialog, SWT.NONE);
83
compositeButtons.setLayout(new GridLayout());
84
compositeButtons.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
86
Button buttonAdd = new Button(compositeButtons, SWT.PUSH);
87
buttonAdd.setLayoutData(getButtonData(SWT.FILL,SWT.TOP, true,false));
88
buttonAdd.setText(TuxGuitar.getProperty("add"));
89
buttonAdd.addSelectionListener(new SelectionAdapter() {
90
public void widgetSelected(SelectionEvent e) {
95
Button buttonDelete = new Button(compositeButtons, SWT.PUSH);
96
buttonDelete.setText(TuxGuitar.getProperty("remove"));
97
buttonDelete.setLayoutData(getButtonData(SWT.FILL,SWT.TOP, true,false));
98
buttonDelete.addSelectionListener(new SelectionAdapter() {
99
public void widgetSelected(SelectionEvent arg0) {
100
removeMidiPort(table);
104
final Button buttonOK = new Button(compositeButtons, SWT.PUSH);
105
buttonOK.setText(TuxGuitar.getProperty("ok"));
106
buttonOK.setLayoutData(getButtonData(SWT.FILL,SWT.BOTTOM,true, true));
107
buttonOK.addSelectionListener(new SelectionAdapter() {
108
public void widgetSelected(SelectionEvent arg0) {
109
updateMidiPorts( table );
114
Button buttonCancel = new Button(compositeButtons, SWT.PUSH);
115
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
116
buttonCancel.setLayoutData(getButtonData(SWT.FILL,SWT.BOTTOM,true, false));
117
buttonCancel.addSelectionListener(new SelectionAdapter() {
118
public void widgetSelected(SelectionEvent arg0) {
123
this.addMidiPorts(table);
125
dialog.setDefaultButton( buttonOK );
127
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
130
protected GridData getButtonData(int hAlignment,int vAlignment,boolean grabExcessHSpace,boolean grabExcessVSpace){
131
GridData data = new GridData(hAlignment,vAlignment,grabExcessHSpace,grabExcessVSpace);
132
data.minimumWidth = 80;
133
data.minimumHeight = 25;
137
protected void addMidiPorts(Table table){
138
Iterator it = getSoundfonts().iterator();
140
String path = (String)it.next();
141
this.addMidiPort(table, path );
145
protected void updateMidiPorts(Table table){
146
List ports = new ArrayList();
147
int count = table.getItemCount();
148
for( int i = 0 ; i < count; i ++ ){
149
TableItem item = table.getItem( i );
150
if( item.getData() instanceof String ){
151
ports.add( item.getData() );
154
this.setSoundfonts(ports);
157
protected void addMidiPort(Table table, String path){
158
TableItem item = new TableItem(table, SWT.NONE);
159
item.setText( path );
160
item.setData( path );
163
protected void removeMidiPort(Table table){
164
int index = table.getSelectionIndex();
165
if(index >= 0 && index < table.getItemCount()){
166
table.remove( index );
170
public void addMidiPort(final Table table) {
171
FileDialog chooser = new FileDialog(table.getShell());
172
String path = chooser.open();
173
if(path != null && path.length() > 0){
174
addMidiPort(table, path);