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-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.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 
57  @NotNull
58  private final JComponent config = new JPanel();
59 
67  public MapPathParameterView(@NotNull final Component parent, @NotNull final MapPathParameter<G, A, R> parameter, @NotNull final PathManager pathManager) {
68  final MapFile mapFile = pathManager.getMapFile(MapPathUtils.newAbsoluteMapPath("/" + parameter.getValue()));
69  value = new JFileField(parent, "mapPathPluginParameter", mapFile.getMapsDir(), mapFile.getFile(), JFileChooser.FILES_AND_DIRECTORIES);
70  value.addDocumentListener(new DocumentListener() {
71 
72  @Override
73  public void insertUpdate(final DocumentEvent e) {
74  setFile();
75  }
76 
77  @Override
78  public void removeUpdate(final DocumentEvent e) {
79  setFile();
80  }
81 
82  @Override
83  public void changedUpdate(final DocumentEvent e) {
84  setFile();
85  }
86 
90  private void setFile() {
91  try {
92  parameter.setFile(value.getFile());
93  } catch (final InvalidValueException ex) {
94  JOptionPane.showMessageDialog(parent, "Invalid file: " + ex.getMessage());
95  }
96  }
97 
98  });
99  }
100 
101  @NotNull
102  @Override
103  public JComponent getValueComponent() {
104  return value;
105  }
106 
107  @NotNull
108  @Override
109  public JComponent getConfigComponent() {
110  return config;
111  }
112 
113 }
void addDocumentListener(@NotNull final DocumentListener documentListener)
Adds a DocumentListener to the text input field.
This class contains methods for converting relative map paths to absolute map paths and vice versa...
Graphical User Interface of Gridarta.
Reading and writing of maps, handling of paths.
A component for selecting files.
Definition: JFileField.java:45
Interface for views that display plugin parameters.
static AbsoluteMapPath newAbsoluteMapPath(@NotNull final String string)
Creates an AbsoluteMapPath instance from string representation.
MapPathParameterView(@NotNull final Component parent, @NotNull final MapPathParameter< G, A, R > parameter, @NotNull final PathManager pathManager)
Creates a new instance.
Base package of all Gridarta classes.
JComponent getValueComponent()
Returns a JComponent for editing the parameter value.
Reflects a game object (object on a map).
Definition: GameObject.java:36
JComponent getConfigComponent()
Returns a JComponent for editing the parameter configuration.
GameObjects are the objects based on Archetypes found on maps.
Utility class for MapPath related functions.
File getMapsDir()
Returns the base directory this map file is part of.
Definition: MapFile.java:84
final JFileField value
The component for editing the parameter&#39;s value.
File getFile()
Returns a File for this map file.
Definition: MapFile.java:102
An exception that is thrown if the string representation of value in a PluginParameter cannot be conv...
A PluginParameterView that displays a MapPathParameter.
File getFile()
Returns the currently selected file.
A PluginParameter that holds a path with in the maps directory.
The location of a map file with a map directory.
Definition: MapFile.java:31
final JComponent config
The component for editing the parameter&#39;s configuration.