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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/io/base/TGFileFormatManager.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.io.base;
 
2
 
 
3
import java.util.ArrayList;
 
4
import java.util.Iterator;
 
5
import java.util.List;
 
6
 
 
7
import org.herac.tuxguitar.io.tg.TGInputStream;
 
8
import org.herac.tuxguitar.io.tg.TGOutputStream;
 
9
import org.herac.tuxguitar.io.tg.TGStream;
 
10
 
 
11
public class TGFileFormatManager {
 
12
        
 
13
        public static final String DEFAULT_EXTENSION = TGStream.TG_FORMAT_EXTENSION;
 
14
        
 
15
        private static TGFileFormatManager instance;
 
16
        
 
17
        private TGSongLoader loader;
 
18
        private TGSongWriter writer;
 
19
        private List inputStreams;
 
20
        private List outputStreams;
 
21
        private List exporters;
 
22
        private List importers;
 
23
        
 
24
        private TGFileFormatManager(){
 
25
                this.loader = new TGSongLoader();
 
26
                this.writer = new TGSongWriter();
 
27
                this.inputStreams = new ArrayList();
 
28
                this.outputStreams = new ArrayList();
 
29
                this.exporters = new ArrayList();
 
30
                this.importers = new ArrayList();
 
31
                this.addDefatultStreams();
 
32
        }
 
33
        
 
34
        public static TGFileFormatManager instance(){
 
35
                if(instance == null){
 
36
                        instance = new TGFileFormatManager();
 
37
                }
 
38
                return instance;
 
39
        }
 
40
        
 
41
        public TGSongLoader getLoader(){
 
42
                return this.loader;
 
43
        }
 
44
        
 
45
        public TGSongWriter getWriter(){
 
46
                return this.writer;
 
47
        }
 
48
        
 
49
        public void addInputStream(TGInputStreamBase stream){
 
50
                this.inputStreams.add(stream);
 
51
        }
 
52
        
 
53
        public void removeInputStream(TGInputStreamBase stream){
 
54
                this.inputStreams.remove(stream);
 
55
        }
 
56
        
 
57
        public void addOutputStream(TGOutputStreamBase stream){
 
58
                this.outputStreams.add(stream);
 
59
        }
 
60
        
 
61
        public void removeOutputStream(TGOutputStreamBase stream){
 
62
                this.outputStreams.remove(stream);
 
63
        }
 
64
        
 
65
        public void addImporter(TGSongImporter importer){
 
66
                this.importers.add(importer);
 
67
        }
 
68
        
 
69
        public void removeImporter(TGSongImporter importer){
 
70
                this.importers.remove(importer);
 
71
        }
 
72
        
 
73
        public void addExporter(TGSongExporter exporter){
 
74
                this.exporters.add(exporter);
 
75
        }
 
76
        
 
77
        public void removeExporter(TGSongExporter exporter){
 
78
                this.exporters.remove(exporter);
 
79
        }
 
80
        
 
81
        public Iterator getInputStreams(){
 
82
                return this.inputStreams.iterator();
 
83
        }
 
84
        
 
85
        public Iterator getOutputStreams(){
 
86
                return this.outputStreams.iterator();
 
87
        }
 
88
        
 
89
        public Iterator getImporters(){
 
90
                return this.importers.iterator();
 
91
        }
 
92
        
 
93
        public Iterator getExporters(){
 
94
                return this.exporters.iterator();
 
95
        }
 
96
        
 
97
        public List getInputFormats(){
 
98
                List formats = new ArrayList();
 
99
                Iterator it = getInputStreams();
 
100
                while(it.hasNext()){
 
101
                        TGInputStreamBase stream = (TGInputStreamBase)it.next();
 
102
                        TGFileFormat format = stream.getFileFormat();
 
103
                        if(!existsFormat(format, formats)){
 
104
                                formats.add(format);
 
105
                        }
 
106
                }
 
107
                return formats;
 
108
        }
 
109
        
 
110
        public List getOutputFormats(){
 
111
                List formats = new ArrayList();
 
112
                Iterator it = getOutputStreams();
 
113
                while(it.hasNext()){
 
114
                        TGOutputStreamBase stream = (TGOutputStreamBase)it.next();
 
115
                        TGFileFormat format = stream.getFileFormat();
 
116
                        if(!existsFormat(format, formats)){
 
117
                                formats.add(format);
 
118
                        }
 
119
                }
 
120
                return formats;
 
121
        }
 
122
        
 
123
        private boolean existsFormat(TGFileFormat format,List formats){
 
124
                Iterator it = formats.iterator();
 
125
                while(it.hasNext()){
 
126
                        TGFileFormat comparator = (TGFileFormat)it.next();
 
127
                        if(comparator.getName().equals(format.getName()) || comparator.getSupportedFormats().equals(format.getSupportedFormats())){
 
128
                                return true;
 
129
                        }
 
130
                }
 
131
                return false;
 
132
        }
 
133
        
 
134
        private void addDefatultStreams(){
 
135
                this.addInputStream(new TGInputStream());
 
136
                this.addOutputStream(new TGOutputStream());
 
137
        }
 
138
}