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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/editors/chord/CustomChordManager.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.editors.chord;
2
 
 
3
 
import java.io.File;
4
 
import java.util.List;
5
 
 
6
 
import org.herac.tuxguitar.gui.editors.chord.xml.ChordReader;
7
 
import org.herac.tuxguitar.gui.editors.chord.xml.ChordWriter;
8
 
import org.herac.tuxguitar.gui.util.TuxGuitarFileUtils;
9
 
import org.herac.tuxguitar.song.models.Chord;
10
 
 
11
 
public class CustomChordManager {
12
 
        private long lastEdit;
13
 
        private List chords;
14
 
        
15
 
        public CustomChordManager(){
16
 
                this.chords = ChordReader.getChords(getUserFileName());
17
 
                this.setLastEdit();
18
 
        }       
19
 
 
20
 
        public int countChords(){
21
 
                return this.chords.size();
22
 
        }
23
 
 
24
 
        public Chord getChord(int index){
25
 
                if(index >= 0 && index < countChords()){
26
 
                        return ((Chord)((Chord)this.chords.get(index)).clone());
27
 
                }
28
 
                return null;
29
 
        }
30
 
        
31
 
        public void addChord(Chord chord){
32
 
                this.chords.add(chord);
33
 
                this.setLastEdit();
34
 
        }
35
 
        
36
 
        public void removeChord(int index){
37
 
                if(index >= 0 && index < countChords()){
38
 
                        this.chords.remove(index);
39
 
                        this.setLastEdit();
40
 
                }
41
 
        }
42
 
        
43
 
        public void renameChord(int index,String name){
44
 
                if(index >= 0 && index < countChords()){
45
 
                        ((Chord)this.chords.get(index)).setName(name);
46
 
                        this.setLastEdit();
47
 
                }
48
 
        }
49
 
        
50
 
        public boolean existOtherEqualCustomChord(String name,int index){
51
 
                for(int i = 0;i < countChords();i ++){
52
 
                        Chord chord = getChord(i);
53
 
                        if(chord.getName().equals(name) && index != i){
54
 
                                return true;
55
 
                        }
56
 
                }               
57
 
                return false;
58
 
        }
59
 
                                
60
 
        public void write(){            
61
 
                ChordWriter.setChords(chords,getUserFileName());        
62
 
        }
63
 
        
64
 
    private static String getUserFileName(){
65
 
        return TuxGuitarFileUtils.USER_CONFIG_PREFIX + File.separator + "customchords.xml";
66
 
    }
67
 
    
68
 
    private void setLastEdit(){
69
 
        this.lastEdit = System.currentTimeMillis();
70
 
    }
71
 
    
72
 
    public long getLastEdit(){
73
 
        return this.lastEdit;
74
 
    }
75
 
}