Gridarta Editor
MapPathParameterView.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 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.gui.dialog.plugin.parameter;
21 
22 import java.awt.Component;
23 import javax.swing.JComponent;
24 import javax.swing.JFileChooser;
25 import javax.swing.JOptionPane;
26 import javax.swing.JPanel;
27 import javax.swing.event.DocumentEvent;
28 import javax.swing.event.DocumentListener;
38 import org.jetbrains.annotations.NotNull;
39 
44 public class MapPathParameterView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements PluginParameterView {
45 
49  @NotNull
50  private final JFileField value;
51 
56  @NotNull
57  private final JComponent config = new JPanel();
58 
65  public MapPathParameterView(@NotNull final Component parent, @NotNull final MapPathParameter<G, A, R> parameter, @NotNull final PathManager pathManager) {
66  final MapFile mapFile = pathManager.getMapFile(MapPathUtils.newAbsoluteMapPath("/" + parameter.getValue()));
67  value = new JFileField(parent, "mapPathPluginParameter", mapFile.getMapsDir(), mapFile.getFile(), JFileChooser.FILES_AND_DIRECTORIES);
68  value.addDocumentListener(new DocumentListener() {
69 
70  @Override
71  public void insertUpdate(final DocumentEvent e) {
72  setFile();
73  }
74 
75  @Override
76  public void removeUpdate(final DocumentEvent e) {
77  setFile();
78  }
79 
80  @Override
81  public void changedUpdate(final DocumentEvent e) {
82  setFile();
83  }
84 
88  private void setFile() {
89  try {
90  parameter.setFile(value.getFile());
91  } catch (final InvalidValueException ex) {
92  JOptionPane.showMessageDialog(parent, "Invalid file: " + ex.getMessage());
93  }
94  }
95 
96  });
97  }
98 
99  @NotNull
100  @Override
101  public JComponent getValueComponent() {
102  return value;
103  }
104 
105  @NotNull
106  @Override
107  public JComponent getConfigComponent() {
108  return config;
109  }
110 
111 }
net.sf.gridarta.plugin
Definition: BshRunnable.java:20
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.utils.JFileField.addDocumentListener
void addDocumentListener(@NotNull final DocumentListener documentListener)
Adds a DocumentListener to the text input field.
Definition: JFileField.java:152
net.sf
net.sf.gridarta.gui.dialog.plugin.parameter.MapPathParameterView.getValueComponent
JComponent getValueComponent()
Returns a JComponent for editing the parameter value.
Definition: MapPathParameterView.java:101
net.sf.gridarta.model.io.PathManager
This class contains methods for converting relative map paths to absolute map paths and vice versa.
Definition: PathManager.java:39
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.model.mapmodel.MapPathUtils
Utility class for MapPath related functions.
Definition: MapPathUtils.java:28
net.sf.gridarta.gui.dialog.plugin.parameter.MapPathParameterView.value
final JFileField value
The component for editing the parameter's value.
Definition: MapPathParameterView.java:50
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.gui.dialog.plugin.parameter.MapPathParameterView.getConfigComponent
JComponent getConfigComponent()
Returns a JComponent for editing the parameter configuration.
Definition: MapPathParameterView.java:107
net.sf.gridarta.model.mapmodel.MapFile.getMapsDir
File getMapsDir()
Returns the base directory this map file is part of.
Definition: MapFile.java:84
net.sf.gridarta.gui.utils.JFileField
A component for selecting files.
Definition: JFileField.java:45
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.model.mapmodel.MapPathUtils.newAbsoluteMapPath
static AbsoluteMapPath newAbsoluteMapPath(@NotNull final String string)
Creates an AbsoluteMapPath instance from string representation.
Definition: MapPathUtils.java:57
net.sf.gridarta.model.mapmodel.MapFile.getFile
File getFile()
Returns a File for this map file.
Definition: MapFile.java:102
net.sf.gridarta.gui.dialog.plugin.parameter.MapPathParameterView.MapPathParameterView
MapPathParameterView(@NotNull final Component parent, @NotNull final MapPathParameter< G, A, R > parameter, @NotNull final PathManager pathManager)
Creates a new instance.
Definition: MapPathParameterView.java:65
net.sf.gridarta.plugin.parameter.InvalidValueException
An exception that is thrown if the string representation of value in a {} cannot be converted to an o...
Definition: InvalidValueException.java:30
net.sf.gridarta.model.mapmodel.MapFile
The location of a map file with a map directory.
Definition: MapFile.java:31
net.sf.gridarta.model.io
Reading and writing of maps, handling of paths.
Definition: AbstractAnimationObjectsReader.java:20
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.dialog.plugin.parameter.MapPathParameterView.config
final JComponent config
The component for editing the parameter's configuration.
Definition: MapPathParameterView.java:57
net.sf.gridarta.plugin.parameter.MapPathParameter
A PluginParameter that holds a path with in the maps directory.
Definition: MapPathParameter.java:35
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.utils
Definition: AnimationComponent.java:20
net.sf.gridarta.gui.dialog.plugin.parameter.PluginParameterView
Interface for views that display plugin parameters.
Definition: PluginParameterView.java:29
net.sf.gridarta.gui.utils.JFileField.getFile
File getFile()
Returns the currently selected file.
Definition: JFileField.java:113
net.sf.gridarta.plugin.parameter
Definition: AbstractPathParameter.java:20
net.sf.gridarta.gui.dialog.plugin.parameter.MapPathParameterView
A PluginParameterView that displays a MapPathParameter.
Definition: MapPathParameterView.java:44