20 package net.sf.gridarta.gui.mapmenu;
23 import java.io.IOException;
24 import java.util.prefs.Preferences;
27 import org.apache.log4j.Category;
28 import org.apache.log4j.Logger;
29 import org.jetbrains.annotations.NotNull;
71 private final String
key;
85 if (LOG.isDebugEnabled()) {
87 LOG.debug(System.identityHashCode(
this) +
" new " +
key);
98 final int result = preferences.getInt(key +
"Num", 0);
99 if (LOG.isDebugEnabled()) {
100 LOG.debug(System.identityHashCode(
this) +
" loadNumEntries=" + result);
110 if (LOG.isDebugEnabled()) {
111 LOG.debug(System.identityHashCode(
this) +
" saveNumEntries(" + num +
")");
113 preferences.putInt(key +
"Num", num);
124 final String suffix =
"[" + index +
"]";
125 final String title = preferences.get(key +
"Title" + suffix,
"");
126 final String filename = preferences.get(key +
"Filename" + suffix,
"");
127 final String directory = preferences.get(key +
"Directory" + suffix,
"");
128 final String typeString = preferences.get(key +
"Type" + suffix,
Type.
MAP.toString());
131 type =
Type.valueOf(typeString);
132 }
catch (
final IllegalArgumentException ex) {
133 if (LOG.isDebugEnabled()) {
134 LOG.debug(System.identityHashCode(
this) +
" loadEntry(" + index +
")=invalid type: " + typeString +
" [" + ex.getMessage() +
"]");
136 throw new IOException(
"invalid type: " + typeString, ex);
143 }
catch (
final IllegalArgumentException ex) {
144 if (LOG.isDebugEnabled()) {
145 LOG.debug(System.identityHashCode(
this) +
" loadEntry(" + index +
")=invalid directory name: " + title +
" [" + ex.getMessage() +
"]");
147 throw new IOException(
"invalid directory name: " + title, ex);
149 final Result resultDir =
new Result(directory, mapMenuEntryDir);
150 if (LOG.isDebugEnabled()) {
151 LOG.debug(System.identityHashCode(
this) +
" loadEntry(" + index +
")=DIR[" + resultDir +
"]");
156 if (filename.isEmpty()) {
157 if (LOG.isDebugEnabled()) {
158 LOG.debug(System.identityHashCode(
this) +
" loadEntry(" + index +
")=empty filename: " + title);
160 throw new IOException(
"bookmark without file name: " + title);
164 final Result resultMap =
new Result(directory, mapMenuEntryMap);
165 if (LOG.isDebugEnabled()) {
166 LOG.debug(System.identityHashCode(
this) +
" loadEntry(" + index +
")=MAP[" + resultMap +
"]");
171 if (LOG.isDebugEnabled()) {
172 LOG.debug(System.identityHashCode(
this) +
" loadEntry(" + index +
")=invalid type: " + type);
174 throw new IOException(
"invalid type: " + type);
186 public void saveEntry(
final int index, @NotNull
final String title, @NotNull
final String filename, @NotNull
final String directory, @NotNull
final Type type) {
187 if (LOG.isDebugEnabled()) {
188 LOG.debug(System.identityHashCode(
this) +
" saveEntry(title=" + title +
", filename=" + filename +
", directory=" + directory +
", type=" + type +
")");
190 final String suffix =
"[" + index +
"]";
191 preferences.put(key +
"Title" + suffix, title);
192 preferences.put(key +
"Filename" + suffix, filename);
193 if (directory.isEmpty()) {
194 preferences.remove(key +
"Directory" + suffix);
196 preferences.put(key +
"Directory" + suffix, directory);
199 preferences.remove(key +
"Type" + suffix);
201 preferences.put(key +
"Type" + suffix, type.toString());
210 if (LOG.isDebugEnabled()) {
211 LOG.debug(System.identityHashCode(
this) +
" removeEntry(" + index +
")");
213 final String suffix =
"[" + index +
"]";
214 preferences.remove(key +
"Title" + suffix);
215 preferences.remove(key +
"Filename" + suffix);
216 preferences.remove(key +
"Directory" + suffix);
217 preferences.remove(key +
"Type" + suffix);
270 return "directory=" + directory +
",mapMenuEntry=" +
mapMenuEntry;
This class contains methods for converting relative map paths to absolute map paths and vice versa...
Reading and writing of maps, handling of paths.
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
Base package of all Gridarta classes.
Interface used as preferences location.