Gridarta Editor
TreeChooseAction.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.utils;
21 
22 import java.awt.event.ActionEvent;
23 import javax.swing.AbstractAction;
24 import javax.swing.text.JTextComponent;
29 import org.jetbrains.annotations.NotNull;
30 
35 public class TreeChooseAction extends AbstractAction {
36 
40  private static final long serialVersionUID = 1L;
41 
45  @NotNull
46  private final JTextComponent textComponent;
47 
51  @NotNull
53 
57  @NotNull
59 
70  protected TreeChooseAction(@NotNull final String text, @NotNull final JTextComponent textComponent, @NotNull final NamedObjects<? extends NamedObject> namedObjects, @NotNull final FaceObjectProviders faceObjectProviders) {
71  super(text);
72  this.textComponent = textComponent;
73  this.namedObjects = namedObjects;
74  this.faceObjectProviders = faceObjectProviders;
75  }
76 
77  @Override
78  public void actionPerformed(@NotNull final ActionEvent e) {
79  String initial = textComponent.getText();
80  final NamedObject selected = namedObjects.get(initial);
81  if (selected != null) {
82  initial = selected.getPath();
83  }
85  if (newValue != null) {
86  textComponent.setText(newValue);
87  }
88  }
89 
94  @NotNull
95  protected String getFaceName() {
96  return textComponent.getText();
97  }
98 
99  @NotNull
100  @Override
101  protected TreeChooseAction clone() {
102  try {
103  return (TreeChooseAction) super.clone();
104  } catch (final CloneNotSupportedException ex) {
105  throw new AssertionError(ex);
106  }
107  }
108 
109 }
net.sf.gridarta.gui.utils.TreeChooseAction.clone
TreeChooseAction clone()
Definition: TreeChooseAction.java:101
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.utils.TreeChooseAction
Action for choosing a face or animation.
Definition: TreeChooseAction.java:35
net.sf.gridarta.gui.utils.TreeChooseAction.TreeChooseAction
TreeChooseAction(@NotNull final String text, @NotNull final JTextComponent textComponent, @NotNull final NamedObjects<? extends NamedObject > namedObjects, @NotNull final FaceObjectProviders faceObjectProviders)
Creates a new instance.
Definition: TreeChooseAction.java:70
net.sf.gridarta.gui.utils.TreeChooseAction.getFaceName
String getFaceName()
Returns the current face name.
Definition: TreeChooseAction.java:95
net.sf
net.sf.gridarta.gui.utils.TreeChooseAction.actionPerformed
void actionPerformed(@NotNull final ActionEvent e)
Definition: TreeChooseAction.java:78
net.sf.gridarta.model.face.FaceObjectProviders
Provider for faces of GameObjects and Archetypes.
Definition: FaceObjectProviders.java:46
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.model.data.NamedObject
An.
Definition: NamedObject.java:32
net
net.sf.gridarta.gui.data.NamedObjectsUtils
Utility class for NamedObjects related functions.
Definition: NamedObjectsUtils.java:46
net.sf.gridarta.gui.utils.TreeChooseAction.textComponent
final JTextComponent textComponent
The JTextComponent that holds the current face/animation name.
Definition: TreeChooseAction.java:46
net.sf.gridarta.gui.data
Definition: NamedNodeTreeCellRenderer.java:20
net.sf.gridarta.model.data
Classes for handling data that is organized in a tree.
Definition: AbstractNamedObject.java:20
net.sf.gridarta.gui.data.NamedObjectsUtils.showNodeChooserDialog
static< E extends NamedObject > String showNodeChooserDialog(@NotNull final Component parentComponent, @NotNull final String initial, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final NamedObjects< E > namedObjects)
Show a dialog for choosing from the object tree.
Definition: NamedObjectsUtils.java:71
net.sf.gridarta.gui.utils.TreeChooseAction.faceObjectProviders
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
Definition: TreeChooseAction.java:58
net.sf.gridarta.gui.utils.TreeChooseAction.namedObjects
final NamedObjects<? extends NamedObject > namedObjects
The NamedObjects providing the face/animation names tree.
Definition: TreeChooseAction.java:52
net.sf.gridarta.model
net.sf.gridarta.model.face
The face is the appearance of an object.
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.model.data.NamedObject.getPath
String getPath()
Get the path of this AbstractNamedObject.
net.sf.gridarta.gui.utils.TreeChooseAction.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: TreeChooseAction.java:40
net.sf.gridarta.model.data.NamedObjects
This class manages NamedObjects, managing their tree as well as providing a method for showing a dial...
Definition: NamedObjects.java:33