2
* Created on 08-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.helper;
10
import java.io.FileInputStream;
11
import java.io.FileNotFoundException;
12
import java.io.FileOutputStream;
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.util.ArrayList;
16
import java.util.List;
17
import java.util.Properties;
19
import org.herac.tuxguitar.gui.TuxGuitar;
20
import org.herac.tuxguitar.gui.system.config.ConfigKeys;
21
import org.herac.tuxguitar.gui.util.TuxGuitarFileUtils;
26
* TODO To change the template for this generated type comment go to
27
* Window - Preferences - Java - Code Style - Code Templates
29
public class FileHistory {
30
private static final int PATH_LIMIT = TuxGuitar.instance().getConfig().getIntConfigValue(ConfigKeys.MAX_HISTORY_FILES);
31
private boolean pathChanges;
32
private boolean isNewFile;
40
public void clearFile() {
41
this.isNewFile = true;
44
public String getFileName() {
45
if(!this.isNewFile() && !this.paths.isEmpty()){
46
return new File((String)paths.get(0)).getName();
48
return "Untitled.gp4";
51
public String getFilePath() {
52
if(!this.paths.isEmpty()){
53
return new File((String)paths.get(0)).getParent();
58
public boolean isNewFile(){
62
public void setFile(String fileName) {
63
this.isNewFile = false;
64
this.addPath(fileName);
67
public void addPath(String path){
68
if(path != null && path.length() > 0){
77
public List getPaths(){
81
private void checkLimit(){
82
while(paths.size() > PATH_LIMIT){
83
paths.remove(paths.size() - 1);
87
private void removePath(String path){
88
for(int i = 0; i < paths.size(); i++){
89
String old = (String)paths.get(i);
97
public boolean hasPathChanges() {
101
public void setPathChanges(boolean pathChanges) {
102
this.pathChanges = pathChanges;
105
public void loadHistory() {
107
this.paths = new ArrayList();
108
if(new File(getHistoryFileName()).exists()){
109
InputStream inputStream = new FileInputStream(getHistoryFileName());
110
Properties properties = new Properties();
111
properties.load(inputStream);
113
int count = Integer.parseInt((String)properties.get("history.count"));
114
for(int i = 0; i < count;i ++){
115
String path = (String)properties.get("history." + i);
116
if(PATH_LIMIT > i && path != null && path.length() > 0){
117
paths.add((String)properties.get("history." + i));
120
setPathChanges(true);
124
} catch (Exception e) {
129
public void saveHistory(){
131
Properties properties = new Properties();
133
int count = paths.size();
134
for(int i = 0;i < count;i ++){
135
properties.put("history." + i,paths.get(i));
137
properties.put("history.count",Integer.toString(count));
139
properties.store(new FileOutputStream(getHistoryFileName()),"History Files");
140
} catch (FileNotFoundException e1) {
141
e1.printStackTrace();
142
} catch (IOException e1) {
143
e1.printStackTrace();
147
private String getHistoryFileName(){
148
return TuxGuitarFileUtils.USER_CONFIG_PREFIX + File.separator + "history.properties";