View Javadoc
1 //{{{imports 2 package net.sf.plb4jedit.filelocator; 3 import java.util.Enumeration; 4 import java.util.Vector; 5 6 import org.gjt.sp.jedit.jEdit; 7 //}}} 8 9 /*** 10 * Encapsulates storing of options in jEdit properties. 11 * 12 * @created 03.05.2002 13 * @author Bernhard Krickl 14 * 15 * V.0.01 $Log: FileLocatorOptions.java,v $ 16 * V.0.01 Revision 1.2 2003/11/07 16:57:27 schaefep 17 * V.0.01 initial ps 18 * V.0.01 19 * V.0.01 Revision 1.1 2003/11/04 17:40:31 skopp 20 * V.0.01 checked in subprojects + sources 21 * V.0.01 22 * V.0.01 Revision 1.1 2002/05/08 15:03:28 krickl 23 * V.0.01 Encapsulates storing of options in jEdit properties. 24 * V.0.01 25 */ 26 public class FileLocatorOptions { 27 28 /*** 29 * Vector of MapConfig objects 30 */ 31 private Vector mapConfigs; 32 33 private static final String OPTION_PREFIX = "options.filelocator"; 34 private static final String CONFIGPARAM_OPTIONPANECAPTION = OPTION_PREFIX + ".caption"; 35 private static final String CONFIGPARAM_MAPNAME = "options.filelocator.maps.name"; 36 private static final String CONFIGPARAM_MAPDIRECTORY = "options.filelocator.maps.directory"; 37 private static final String CONFIGPARAM_MAPEXTENSION = "options.filelocator.maps.extension"; 38 39 private static FileLocatorOptions INSTANCE = new FileLocatorOptions(); 40 /*** 41 * load all options 42 */ 43 private FileLocatorOptions() { 44 loadMapConfigs(); 45 } 46 47 /*** 48 * get the singletion intance of FileLocatorOptions 49 */ 50 public static FileLocatorOptions getInstance() { 51 return INSTANCE; 52 } 53 54 /*** 55 * get the caption for the option pane. 56 * if not configured, a default caption is set. 57 */ 58 public String getOptionPaneCaption() { 59 String caption; 60 caption = jEdit.getProperty(CONFIGPARAM_OPTIONPANECAPTION); 61 if (caption == null) { 62 caption = "File Locator Options"; 63 jEdit.setProperty(CONFIGPARAM_OPTIONPANECAPTION, caption); 64 } 65 return caption; 66 } 67 68 public Vector getMapConfigs() { 69 return this.mapConfigs; 70 } 71 72 /*** 73 * save all changeable options. 74 */ 75 public void save() { 76 saveMapConfigs(); 77 } 78 79 /* 80 * private methods 81 */ 82 83 private void setMapConfigs(Vector newMapConfigs) { 84 this.mapConfigs = newMapConfigs; 85 } 86 87 private void loadMapConfigs() { 88 Vector mapConfigs = new Vector(); 89 int i = 0; 90 String mapName = jEdit.getProperty(CONFIGPARAM_MAPNAME + "." + i); 91 while (mapName != null) { 92 String mapDirectory = jEdit.getProperty(CONFIGPARAM_MAPDIRECTORY + "." + i); 93 String mapExtension = jEdit.getProperty(CONFIGPARAM_MAPEXTENSION + "." + i); 94 MapConfig mapConfig = new MapConfig(mapName, mapDirectory, mapExtension); 95 mapConfigs.addElement(mapConfig); 96 i++; 97 mapName = jEdit.getProperty(CONFIGPARAM_MAPNAME + "." + i); 98 } 99 setMapConfigs(mapConfigs); 100 } 101 102 /*** 103 * save all sane map configs. 104 * saves all sane map configs currently in memory. 105 * subsequent map configs found in jEdit properties are deleted. 106 */ 107 private void saveMapConfigs() { 108 Vector mapConfigs = getMapConfigs(); 109 Enumeration mapConfigsEnum = mapConfigs.elements(); 110 int i = 0; 111 while (mapConfigsEnum.hasMoreElements()) { 112 MapConfig mapConfig = (MapConfig)mapConfigsEnum.nextElement(); 113 if (mapConfig.isSane()) { 114 String mapName = mapConfig.getName(); 115 jEdit.setProperty(CONFIGPARAM_MAPNAME + "." + i, mapName); 116 String mapDirectory = mapConfig.getDirectory(); 117 jEdit.setProperty(CONFIGPARAM_MAPDIRECTORY + "." + i, mapDirectory); 118 String mapExtension = mapConfig.getExtension(); 119 jEdit.setProperty(CONFIGPARAM_MAPEXTENSION + "." + i, mapExtension); 120 i++; 121 } 122 } 123 // clean up remaining mapConfigs in properties 124 String mapName = jEdit.getProperty(CONFIGPARAM_MAPNAME + "." + i); 125 while (mapName != null) { 126 jEdit.unsetProperty(CONFIGPARAM_MAPNAME + "." + i); 127 jEdit.unsetProperty(CONFIGPARAM_MAPDIRECTORY + "." + i); 128 jEdit.unsetProperty(CONFIGPARAM_MAPEXTENSION + "." + i); 129 i++; 130 mapName = jEdit.getProperty(CONFIGPARAM_MAPNAME + "." + i); 131 } 132 } 133 134 }

This page was automatically generated by Maven