Gridarta Editor
MapPathParameter.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;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
35 public class MapPathParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractStringPluginParameter<G, A, R, String> {
36 
40  @NotNull
41  public static final String PARAMETER_TYPE = "MapPathParameter";
42 
47  @NotNull
48  private final PathManager pathManager;
49 
53  @NotNull
55 
62  public MapPathParameter(@NotNull final PathManager pathManager, @NotNull final ProjectSettings projectSettings) {
63  super("");
64  this.pathManager = pathManager;
65  this.projectSettings = projectSettings;
66  }
67 
68  @NotNull
69  @Override
70  public String getParameterType() {
71  return PARAMETER_TYPE;
72  }
73 
74  @NotNull
75  @Override
76  public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) {
77  return visitor.visit(this);
78  }
79 
80  @NotNull
81  @Override
82  public String getValue() {
83  return getStringValue();
84  }
85 
86  @Nullable
87  @Override
88  public String getValueOrNull() {
89  return getValue();
90  }
91 
97  public void setFile(@NotNull final File file) throws InvalidValueException {
98  final MapFile mapFile = pathManager.getMapFile(file);
99  if (!mapFile.getMapsDir().equals(projectSettings.getMapsDirectory())) {
100  throw new InvalidValueException("the selected file " + mapFile + " must be within the maps directory " + projectSettings.getMapsDirectory());
101  }
102  setStringValue("/" + mapFile.getMapPath().getPath());
103  }
104 
105 }
String getPath()
Returns the map path information.
static final String PARAMETER_TYPE
The string representation of this parameter type.
This class contains methods for converting relative map paths to absolute map paths and vice versa...
void setFile(@NotNull final File file)
Sets the value from a File instance.
Reading and writing of maps, handling of paths.
Settings that apply to a project.
Abstract base class for PluginParameter implementations for which the value is calculated from the st...
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
Definition: MapFile.java:93
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
final ProjectSettings projectSettings
The ProjectSettings instance.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
MapPathParameter(@NotNull final PathManager pathManager, @NotNull final ProjectSettings projectSettings)
Creates a new instance.
GameObjects are the objects based on Archetypes found on maps.
Interface for visitors of PluginParameter instances.
File getMapsDir()
Returns the base directory this map file is part of.
Definition: MapFile.java:84
An exception that is thrown if the string representation of value in a PluginParameter cannot be conv...
File getMapsDirectory()
Returns the default maps directory.
boolean setStringValue( @NotNull final String stringValue)
Updates the parameter value.
A PluginParameter that holds a path with in the maps directory.
final PathManager pathManager
The PathManager instance for converting Files into path names.
The location of a map file with a map directory.
Definition: MapFile.java:31