Gridarta Editor
AbstractPathParameter.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.plugin.parameter;
21 
22 import java.io.File;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29 
35 public abstract class AbstractPathParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractStringPluginParameter<G, A, R, File> {
36 
40  @NotNull
41  private final File baseDir;
42 
47  protected AbstractPathParameter(@NotNull final File baseDir) {
48  super("");
49  this.baseDir = baseDir;
50  }
51 
56  @NotNull
57  public File getBaseDir() {
58  return baseDir;
59  }
60 
65  public void setFile(@NotNull final File file) {
67  }
68 
69  @NotNull
70  @Override
71  public File getValue() throws InvalidValueException {
72  final String stringValue = getStringValue();
73  if (stringValue.isEmpty()) {
74  throw new InvalidValueException("not value specified");
75  }
76  final File file = new File(stringValue);
77  if (!file.exists()) {
78  throw new InvalidValueException("file does not exist: " + stringValue);
79  }
80  return file;
81  }
82 
83  @Nullable
84  @Override
85  public File getValueOrNull() {
86  try {
87  return getValue();
88  } catch (final InvalidValueException ignored) {
89  return null;
90  }
91  }
92 
93 }
Reading and writing of maps, handling of paths.
Abstract base class for PluginParameter implementations for which the value is calculated from the st...
void setFile(@NotNull final File file)
Sets the current File.
Utility class for converting relative map paths to absolute map paths and vice versa.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
GameObjects are the objects based on Archetypes found on maps.
Base class for PluginParameters that hold a File value.
static String getMapPath(@NotNull final File file, @NotNull final File baseDir)
Returns a relative path path for a File.
An exception that is thrown if the string representation of value in a PluginParameter cannot be conv...
boolean setStringValue( @NotNull final String stringValue)
Updates the parameter value.
AbstractPathParameter(@NotNull final File baseDir)
Creates a new instance.