1
package org.herac.tuxguitar.gui.tools.custom.converter;
3
import java.util.Iterator;
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.widgets.Combo;
7
import org.eclipse.swt.widgets.Composite;
8
import org.herac.tuxguitar.io.base.TGFileFormat;
9
import org.herac.tuxguitar.io.base.TGFileFormatManager;
10
import org.herac.tuxguitar.io.base.TGSongExporter;
12
public class DestinationFileTypeCombo {
14
/** the combo box of available output formats */
15
protected Combo comboBox = null;
17
/** index of the last OutputStream plugin, the rest are exporters and treated differently */
18
protected int lastOutputStreamIndex = -1;
20
/** instantiates a combo */
21
public DestinationFileTypeCombo(Composite parent) {
23
this.comboBox = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
28
/** initializes combo box */
31
// fill in the combo with input streams and exporters
32
Iterator outputStreams = TGFileFormatManager.instance().getOutputFormats().iterator();
33
while (outputStreams.hasNext()) {
34
this.comboBox.add(((TGFileFormat)outputStreams.next()).getSupportedFormats());
35
this.lastOutputStreamIndex++;
38
Iterator exporters = TGFileFormatManager.instance().getExporters();
39
while (exporters.hasNext()) {
40
TGSongExporter curExporter = (TGSongExporter)exporters.next();
41
// curExporter.configure(true); -- still not supported by most plugins, and old tuxguitar
42
this.comboBox.add(curExporter.getFileFormat().getSupportedFormats());
45
if (this.lastOutputStreamIndex!=-1) // first one is default
46
this.comboBox.select(0);
50
/** Gets the destination file extension */
51
String getExtension() {
52
String extension = this.comboBox.getItem(this.comboBox.getSelectionIndex()).trim();
53
// check if the extension is multiple
54
int index = extension.indexOf(";");
56
index = extension.length();
58
// remove * and multiple extensions (first is good enough)
59
extension = extension.substring(extension.indexOf("."), index );
63
public void setLayoutData(Object layoutData){
64
this.comboBox.setLayoutData( layoutData );