Gridarta Editor
FaceTreeChooseAction.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.AbstractButton;
24 import javax.swing.Icon;
25 import javax.swing.ImageIcon;
26 import javax.swing.text.JTextComponent;
31 import org.jetbrains.annotations.NotNull;
32 
37 public class FaceTreeChooseAction extends TreeChooseAction {
38 
42  private static final long serialVersionUID = 1L;
43 
47  @NotNull
48  private final AbstractButton icon;
49 
53  @NotNull
55 
59  @NotNull
60  private final ImageIcon noFaceSquareIcon;
61 
65  @NotNull
66  private final ImageIcon unknownSquareIcon;
67 
79  public FaceTreeChooseAction(@NotNull final String text, @NotNull final JTextComponent textComponent, @NotNull final AbstractButton icon, @NotNull final NamedObjects<? extends NamedObject> namedObjects, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon) {
81  this.icon = icon;
82  this.faceObjectProviders = faceObjectProviders;
83  this.noFaceSquareIcon = noFaceSquareIcon;
84  this.unknownSquareIcon = unknownSquareIcon;
85 
86  final FaceObjectProvidersListener faceObjectProvidersListener = this::updateIconLabel;
87  faceObjectProviders.addFaceObjectProvidersListener(faceObjectProvidersListener);
88 
90  }
91 
92  @Override
93  public void actionPerformed(@NotNull final ActionEvent e) {
94  super.actionPerformed(e);
96  }
97 
101  public final void updateIconLabel() {
102  final String faceName = getFaceName();
103  final Icon face;
104  if (faceName.isEmpty() || faceName.equals("NONE")) {
105  face = noFaceSquareIcon;
106  } else {
107  final Icon tmp = faceObjectProviders.getImageIconForFacename(faceName);
108  face = tmp == null ? unknownSquareIcon : tmp;
109  }
110  icon.setIcon(face);
111  }
112 
113  @NotNull
114  @Override
116  return (FaceTreeChooseAction) super.clone();
117  }
118 
119  @Override
120  public void setEnabled(final boolean newValue) {
121  super.setEnabled(newValue);
122  icon.setEnabled(newValue);
123  }
124 
125 }
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.utils.FaceTreeChooseAction
A TreeChooseAction that updates a face label.
Definition: FaceTreeChooseAction.java:37
net.sf.gridarta.gui.utils.TreeChooseAction
Action for choosing a face or animation.
Definition: TreeChooseAction.java:35
net.sf.gridarta.gui.utils.TreeChooseAction.getFaceName
String getFaceName()
Returns the current face name.
Definition: TreeChooseAction.java:95
net.sf
net.sf.gridarta.model.face.FaceObjectProviders
Provider for faces of GameObjects and Archetypes.
Definition: FaceObjectProviders.java:46
net.sf.gridarta.model.face.FaceObjectProviders.addFaceObjectProvidersListener
void addFaceObjectProvidersListener(@NotNull final FaceObjectProvidersListener listener)
Adds a FaceObjectProvidersListener to be notified about changes.
Definition: FaceObjectProviders.java:197
net.sf.gridarta.model.data.NamedObject
An.
Definition: NamedObject.java:32
net.sf.gridarta.gui.utils.FaceTreeChooseAction.noFaceSquareIcon
final ImageIcon noFaceSquareIcon
The ImageIcon for no animations.
Definition: FaceTreeChooseAction.java:60
net
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.model.data
Classes for handling data that is organized in a tree.
Definition: AbstractNamedObject.java:20
net.sf.gridarta.gui.utils.FaceTreeChooseAction.actionPerformed
void actionPerformed(@NotNull final ActionEvent e)
Definition: FaceTreeChooseAction.java:93
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.FaceObjectProvidersListener
Interface for listeners interested in FaceObjectProviders related events.
Definition: FaceObjectProvidersListener.java:29
net.sf.gridarta.model.face
The face is the appearance of an object.
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.gui.utils.FaceTreeChooseAction.unknownSquareIcon
final ImageIcon unknownSquareIcon
The ImageIcon for undefined animations.
Definition: FaceTreeChooseAction.java:66
net.sf.gridarta.gui.utils.FaceTreeChooseAction.setEnabled
void setEnabled(final boolean newValue)
Definition: FaceTreeChooseAction.java:120
net.sf.gridarta.gui.utils.FaceTreeChooseAction.faceObjectProviders
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
Definition: FaceTreeChooseAction.java:54
net.sf.gridarta.gui.utils.FaceTreeChooseAction.updateIconLabel
final void updateIconLabel()
Updates the icon of icon to reflect the current face name.
Definition: FaceTreeChooseAction.java:101
net.sf.gridarta.gui.utils.FaceTreeChooseAction.icon
final AbstractButton icon
The button showing the icon.
Definition: FaceTreeChooseAction.java:48
net.sf.gridarta.gui.utils.FaceTreeChooseAction.FaceTreeChooseAction
FaceTreeChooseAction(@NotNull final String text, @NotNull final JTextComponent textComponent, @NotNull final AbstractButton icon, @NotNull final NamedObjects<? extends NamedObject > namedObjects, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon)
Creates a new instance.
Definition: FaceTreeChooseAction.java:79
net.sf.gridarta.gui.utils.FaceTreeChooseAction.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: FaceTreeChooseAction.java:42
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
net.sf.gridarta.gui.utils.FaceTreeChooseAction.clone
FaceTreeChooseAction clone()
Definition: FaceTreeChooseAction.java:115
net.sf.gridarta.model.face.FaceObjectProviders.getImageIconForFacename
ImageIcon getImageIconForFacename(@NotNull final String faceObjName)
Returns the ImageIcon for a given face object name.
Definition: FaceObjectProviders.java:367