1 18 19 package de.gulden.framework.amoda.generic.core; 20 21 import de.gulden.framework.amoda.generic.metadata.*; 22 import de.gulden.framework.amoda.generic.option.*; 23 import de.gulden.framework.amoda.model.core.*; 24 import de.gulden.framework.amoda.model.core.RecentFilesList; 25 import java.io.*; 26 import java.net.*; 27 import java.util.*; 28 import java.util.ArrayList ; 29 30 36 public class GenericRecentFilesList extends ArrayList implements RecentFilesList { 37 38 42 protected Application application; 43 44 protected int max; 45 46 47 51 public void init(Application application) { 52 this.application=application; 53 optionsToList(); 54 hasBeenChanged(); 55 } 56 57 public void putFirst(File file) { 58 if (this.indexOf(file)!=0) { this.remove(file); this.add(0,file); 61 if (this.size()>max) { 62 this.remove(max); 63 } 64 hasBeenChanged(); 65 } 66 } 67 68 public void putFirst(URL url) { 69 if (this.indexOf(url)!=0) { this.remove(url); this.add(0,url); 72 if (this.size()>max) { 73 this.remove(max); 74 } 75 hasBeenChanged(); 76 } 77 } 78 79 public Application getApplication() { 80 return application; 81 } 82 83 public void setApplication(Application _application) { 84 application = _application; 85 } 86 87 public void hasBeenChanged() { 88 listToOptions(); 90 ((de.gulden.framework.amoda.generic.option.GenericOptions)application.getOptions()).saveGlobalProperties(); 92 } 93 94 public int getMax() { 95 return max; 96 } 97 98 public void setMax(int _max) { 99 max = _max; 100 } 101 102 protected void optionsToList() { 103 max=application.getOptions().getInt("recent-files-max"); 104 this.clear(); 105 for (int i=0;i<max;i++) { 106 String recent=application.getOptions().getString("recent-file-"+i); 107 if (recent==null) { 108 return; 109 } 110 if (recent.indexOf(':')!=-1) { try { 112 java.net.URL url=new java.net.URL (recent); 113 this.add(url); 114 } catch (java.net.MalformedURLException mue) { 115 } 117 } else { java.io.File file=new java.io.File (recent); 119 if (file.isFile()&&file.exists()) { 120 this.add(file); 121 } 122 } 123 } 124 } 125 126 protected void listToOptions() { 127 for (int i=0;i<size();i++) { 128 Object value=this.get(i); 129 String s=null; 130 if (value instanceof java.io.File ) { 131 s=((java.io.File )value).getAbsolutePath(); 132 } else if (value instanceof java.net.URL ) { 133 s=((java.net.URL )value).toExternalForm(); 134 } 135 de.gulden.framework.amoda.model.option.OptionEntry entry=application.getOptions().getOptionEntry("recent-file-"+i); 136 ((de.gulden.framework.amoda.generic.data.GenericValue)entry.getValue(entry.STATE_CURRENT)).set(s); 137 } 138 } 139 140 } | Popular Tags |