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-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.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  public 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  }
84  final String newValue = NamedObjectsUtils.showNodeChooserDialog(textComponent, initial, faceObjectProviders, namedObjects);
85  if (newValue != null) {
86  textComponent.setText(newValue);
87  }
88  }
89 
94  @NotNull
95  public String getFaceName() {
96  return textComponent.getText();
97  }
98 
99  @NotNull
100  @Override
101  protected Object clone() {
102  try {
103  return super.clone();
104  } catch (final CloneNotSupportedException ex) {
105  throw new AssertionError(ex);
106  }
107  }
108 
109 }
final NamedObjects<? extends NamedObject > namedObjects
The NamedObjects providing the face/animation names tree.
The data package contains classes for handling data that is organized in a tree.
Graphical User Interface of Gridarta.
String getFaceName()
Returns the current face name.
static final long serialVersionUID
The serial version UID.
This class manages NamedObjects, managing their tree as well as providing a method for showing a dial...
final JTextComponent textComponent
The JTextComponent that holds the current face/animation name.
Utility class for NamedObjects related functions.
Base package of all Gridarta classes.
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.
E get(@NotNull String objectName)
Gets a AbstractNamedObject.
String getPath()
Get the path of this AbstractNamedObject.
Action for choosing a face or animation.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
TreeChooseAction(@NotNull final String text, @NotNull final JTextComponent textComponent, @NotNull final NamedObjects<? extends NamedObject > namedObjects, @NotNull final FaceObjectProviders faceObjectProviders)
Create a TreeChooseAction.
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
void actionPerformed(@NotNull final ActionEvent e)