20 package net.sf.gridarta.gui.panel.gameobjectattributes;
22 import java.awt.BorderLayout;
23 import java.awt.Container;
24 import java.awt.Dimension;
25 import java.awt.Frame;
26 import java.awt.GridLayout;
27 import javax.swing.Action;
28 import javax.swing.DefaultListModel;
29 import javax.swing.JButton;
30 import javax.swing.JList;
31 import javax.swing.JPanel;
32 import javax.swing.JScrollPane;
33 import javax.swing.ListModel;
34 import javax.swing.ListSelectionModel;
35 import javax.swing.ScrollPaneConstants;
36 import javax.swing.border.EtchedBorder;
37 import javax.swing.event.ListSelectionEvent;
38 import javax.swing.event.ListSelectionListener;
51 import net.
sf.japi.swing.action.ActionBuilder;
52 import net.
sf.japi.swing.action.ActionBuilderFactory;
53 import net.
sf.japi.swing.action.ActionMethod;
54 import org.jetbrains.annotations.NotNull;
55 import org.jetbrains.annotations.Nullable;
68 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
110 private final JPanel
panel =
new JPanel();
122 private final Action
aEventAddNew = ACTION_BUILDER.createAction(
false,
"eventAddNew",
this);
128 private final Action
aEventEditData = ACTION_BUILDER.createAction(
false,
"eventEditData",
this);
134 private final Action
aEventEdit = ACTION_BUILDER.createAction(
false,
"eventEdit",
this);
140 private final Action
aEventRemove = ACTION_BUILDER.createAction(
false,
"eventRemove",
this);
165 public EventsTab(@NotNull
final Frame parent, @NotNull
final MapManager<G, A, R> mapManager, @NotNull
final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, @NotNull
final ScriptArchEditor<G, A, R> scriptArchEditor, @NotNull
final ScriptArchData<G, A, R> scriptArchData, @NotNull
final ScriptArchDataUtils<G, A, R> scriptArchDataUtils, @NotNull
final ScriptArchUtils scriptArchUtils) {
166 super(gameObjectAttributesModel);
174 scrollPane =
new JScrollPane(eventList);
175 scrollPane.setBorder(
new EtchedBorder());
176 scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
177 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
178 scrollPane.setPreferredSize(
new Dimension(80, 40));
180 final Container buttons =
new JPanel(
new GridLayout(4, 1));
181 buttons.add(
new JButton(aEventAddNew));
182 buttons.add(
new JButton(aEventEditData));
183 buttons.add(
new JButton(aEventEdit));
184 buttons.add(
new JButton(aEventRemove));
186 panel.setLayout(
new BorderLayout());
187 panel.add(scrollPane, BorderLayout.CENTER);
188 panel.add(buttons, BorderLayout.EAST);
189 panel.setPreferredSize(
new Dimension(100, 40));
191 eventList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
192 final ListSelectionListener listSelectionListener =
new ListSelectionListener() {
195 public void valueChanged(
final ListSelectionEvent e) {
200 eventList.addListSelectionListener(listSelectionListener);
201 refresh(gameObjectAttributesModel.getSelectedGameObject());
217 scrollPane.requestFocusInWindow();
221 protected final void refresh(@Nullable
final G gameObject) {
222 selectedGameObject = gameObject;
223 if (gameObject == null || !gameObject.isScripted()) {
225 final ListModel<?> listModel = eventList.getModel();
226 if (listModel != null && listModel.getSize() > 0) {
227 eventList.setModel(
new DefaultListModel<>());
231 eventList.removeAll();
248 protected void apply(@NotNull
final G gameObject) {
290 if (gameObject == null) {
295 final G selectedHead = gameObject.
getHead();
297 assert mapSquare != null;
301 scriptArchEditor.
addEventScript(selectedHead, scriptArchData, parent);
303 if (scriptArchData.
isEmpty(selectedHead)) {
328 if (gameObject == null) {
332 final ListModel<?> listModel = eventList.getModel();
333 if (listModel == null || listModel.getSize() <= 0) {
337 final int index = eventList.getSelectedIndex();
343 final G selectedHead = gameObject.
getHead();
345 assert mapSquare != null;
349 scriptArchDataUtils.
modifyEventScript(index, task, eventList, mapManager, parent, selectedHead);
350 if (scriptArchData.
isEmpty(selectedHead)) {
368 private void setEventPanelButtonState(
final boolean newButton,
final boolean modifyButton,
final boolean pathButton,
final boolean removeButton) {
369 aEventAddNew.setEnabled(newButton);
370 aEventEditData.setEnabled(pathButton);
371 aEventEdit.setEnabled(modifyButton);
372 aEventRemove.setEnabled(removeButton);
boolean isEmpty(@NotNull G gameObject)
Returns whether this ScriptArchData is empty (contains no events).
T getHead()
Return the head part of a multi-part object.
Stores and manages information about scripted events.
void modifyEventScript(final int eventIndex, final ScriptTask task, @NotNull final JList< String > panelList, @NotNull final MapManager<?, ?, ?> mapManager, @NotNull final Frame parent, @NotNull final Iterable< G > gameObject)
If there is a scripted event of the specified type, the script pad is opened and the appropriate scri...
Package with common types for event archetypes.
MapSquare< G, A, R > getMapSquare()
A MapModel reflects the data of a map.
A MapManager manages all opened maps.
Graphical User Interface of Gridarta.
void addEventsToJList(@NotNull JList< String > list, @NotNull Iterable<? extends GameObject<?, ?, ?>> gameObject)
Set all ScriptedEvents to appear in the given JList This method should be fast because it may be exec...
void apply(@NotNull final G gameObject)
void setEventPanelButtonState(final boolean newButton, final boolean modifyButton, final boolean pathButton, final boolean removeButton)
Sets the enable/disable states for the four buttons in the event panel.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
Parameter for operation to perform in ScriptTask, javax.swing.JList, net.sf.gridarta.model.mapmanager.MapManager, java.awt.Frame, Iterable).
void endTransaction()
End a transaction.
void eventEditData()
Action method for editing the data of an existing event.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
void eventAddNew()
Action method for creating a new event.
EVENT_EDIT_PATH
Opens a dialog to edit the script parameters.
MODIFIED
The tab contents are modified from defaults.
final MapManager< G, A, R > mapManager
The MapManager.
final void refresh(@Nullable final G gameObject)
Base package of all Gridarta classes.
Reflects a game object (object on a map).
final ScriptArchData< G, A, R > scriptArchData
The ScriptArchData instance to use.
GameObject< G, A, R > selectedGameObject
The currently selected game object.
GameObjects are the objects based on Archetypes found on maps.
The "Events" tab in the game object attributes panel.
final JList< String > eventList
The JList that shows all events.
EVENT_OPEN
Opens an editor for the script code.
void setTabSeverity( @NotNull final Severity tabSeverity)
Sets the tab severity.
final ScriptArchDataUtils< G, A, R > scriptArchDataUtils
The ScriptArchDataUtils to use.
void eventEdit()
Action method for editing an existing event.
final ScriptArchUtils scriptArchUtils
The ScriptArchUtils to use.
void addEventScript(@NotNull final G gameObject, @NotNull final ScriptArchData< G, A, R > scriptArchData, @NotNull final Frame parent)
A popup is opened and the user can create a new scripting event which gets attached to this gameObjec...
final Frame parent
The parent frame for dialog boxes.
net.sf.gridarta.model.scripts.ScriptArchData related functions.
Severity levels for colors of tabs.
final JScrollPane scrollPane
The JScrollPane displaying all event.s.
Dialog to create events linked to item scripting.
final Action aEventEdit
The action for "edit event code".
final ScriptArchEditor< G, A, R > scriptArchEditor
The ScriptArchEditor to use.
DEFAULT
The tab contents are unchanged from defaults.
boolean doAddNewEvent(final boolean performAction)
This method is invoked when the user pressed the "new event" button.
void eventRemove()
Action method for removing an existing event.
void beginTransaction(@NotNull String name)
Starts a new transaction.
final Action aEventRemove
The action for "remove event".
EventsTab(@NotNull final Frame parent, @NotNull final MapManager< G, A, R > mapManager, @NotNull final GameObjectAttributesModel< G, A, R > gameObjectAttributesModel, @NotNull final ScriptArchEditor< G, A, R > scriptArchEditor, @NotNull final ScriptArchData< G, A, R > scriptArchData, @NotNull final ScriptArchDataUtils< G, A, R > scriptArchDataUtils, @NotNull final ScriptArchUtils scriptArchUtils)
Creates a new instance.
final Action aEventEditData
The action for "edit event parameters".
final Action aEventAddNew
The action for "add new event".
boolean doEditEvent(@NotNull final ScriptTask task, final boolean performAction)
This method is invoked when the user pressed the "edit event"/"path"/"remove" button from the event p...
void updateActions()
Updates the enabled state of all actions.
Interface for MapArchObjects.
Base class for GameObjectAttributesTab implementations.
EVENT_REMOVE
Removes the event object.
final JPanel panel
The content panel.