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

« back to all changes in this revision

Viewing changes to TuxGuitar-converter/src/org/herac/tuxguitar/gui/tools/custom/converter/DestinationFileTypeCombo.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.gui.tools.custom.converter;
 
2
 
 
3
import java.util.Iterator;
 
4
 
 
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;
 
11
 
 
12
public class DestinationFileTypeCombo {
 
13
        
 
14
        /** the combo box of available output formats */
 
15
        protected Combo comboBox = null;
 
16
        
 
17
        /** index of the last OutputStream plugin, the rest are exporters and treated differently */
 
18
        protected int lastOutputStreamIndex = -1;
 
19
        
 
20
        /** instantiates a combo */
 
21
        public DestinationFileTypeCombo(Composite parent) {
 
22
                
 
23
                this.comboBox = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
 
24
                this.init();
 
25
                
 
26
        }
 
27
        
 
28
        /** initializes combo box */
 
29
        private void init() {
 
30
                
 
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++;
 
36
                }
 
37
                
 
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());
 
43
                }
 
44
                
 
45
                if (this.lastOutputStreamIndex!=-1) // first one is default
 
46
                        this.comboBox.select(0);
 
47
                
 
48
        }
 
49
        
 
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(";");
 
55
                if (index == -1) 
 
56
                        index = extension.length();
 
57
                
 
58
                // remove * and multiple extensions (first is good enough)
 
59
                extension = extension.substring(extension.indexOf("."), index );
 
60
                return extension;
 
61
        }
 
62
        
 
63
        public void setLayoutData(Object layoutData){
 
64
                this.comboBox.setLayoutData( layoutData );
 
65
        }
 
66
}