20 package net.sf.gridarta.gui.dialog.gameobjectattributes;
22 import java.awt.CardLayout;
23 import java.awt.Color;
24 import java.awt.Component;
25 import java.awt.Container;
26 import java.awt.Dimension;
27 import java.awt.Frame;
28 import java.awt.GridBagConstraints;
29 import java.awt.GridBagLayout;
30 import java.awt.Insets;
31 import java.awt.Point;
32 import java.awt.event.ItemEvent;
33 import java.awt.event.ItemListener;
35 import javax.swing.AbstractButton;
36 import javax.swing.Action;
37 import javax.swing.BorderFactory;
38 import javax.swing.Box;
39 import javax.swing.ImageIcon;
40 import javax.swing.JButton;
41 import javax.swing.JComboBox;
42 import javax.swing.JComponent;
43 import javax.swing.JDialog;
44 import javax.swing.JLabel;
45 import javax.swing.JOptionPane;
46 import javax.swing.JPanel;
47 import javax.swing.JScrollPane;
48 import javax.swing.JTextField;
49 import javax.swing.JTextPane;
50 import javax.swing.filechooser.FileFilter;
51 import javax.swing.text.BadLocationException;
52 import javax.swing.text.Document;
53 import javax.swing.text.JTextComponent;
54 import javax.swing.text.Style;
55 import javax.swing.text.StyleConstants;
56 import javax.swing.text.StyleContext;
90 import net.
sf.japi.swing.action.ActionBuilder;
91 import net.
sf.japi.swing.action.ActionBuilderFactory;
92 import net.
sf.japi.swing.action.ActionMethod;
93 import org.apache.log4j.Category;
94 import org.apache.log4j.Logger;
95 import org.jetbrains.annotations.NotNull;
96 import org.jetbrains.annotations.Nullable;
115 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
154 private static final long serialVersionUID = 1;
157 public void setValue(@Nullable
final Object newValue) {
158 super.setValue(newValue);
159 if (newValue != UNINITIALIZED_VALUE) {
223 private final Action
summaryAction = ACTION_BUILDER.createAction(
false,
"attribSummary",
this);
230 private final Action
editAction = ACTION_BUILDER.createAction(
false,
"attribEdit",
this);
284 public void mapSizeChanged(@NotNull
final Size2D newSize) {
285 if (gameObject.getMapSquare() == null) {
286 optionPane.setValue(cancelButton);
292 if (gameObject.getMapSquare() != mapModel.
getMapSquare(mapPos)) {
293 optionPane.setValue(cancelButton);
298 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
299 if (gameObject.getMapSquare() == null) {
300 optionPane.setValue(cancelButton);
310 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
315 public void modifiedChanged() {
333 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
344 if (mapControl.getMapModel() ==
mapModel) {
345 optionPane.setValue(cancelButton);
358 public void facesReloaded() {
359 faceLabel.setIcon(
getFace(gameObject));
379 private boolean ignoreEvent;
382 public void itemStateChanged(@NotNull
final ItemEvent e) {
387 if (e.getStateChange() == ItemEvent.DESELECTED) {
389 }
else if (e.getStateChange() == ItemEvent.SELECTED && !e.getItem().equals(deselected)) {
392 final JComboBox<?> typeComboBox = (JComboBox<?>) e.getSource();
394 typeComboBox.hidePopup();
396 if (deselected == null) {
399 if (JOptionPane.showConfirmDialog(optionPane,
ActionBuilderUtils.
format(ACTION_BUILDER,
"attribConfirmTypeChange", deselected.getTypeName(), newType.
getTypeName()),
ActionBuilderUtils.
getString(ACTION_BUILDER,
"attribConfirmTypeChangeTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) {
400 archetypeType = newType;
413 typeComboBox.setSelectedItem(archetypeType);
446 public GameObjectAttributesDialog(@NotNull
final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory,
final ArchetypeTypeSet archetypeTypeSet, @NotNull
final G gameObject, @NotNull
final Frame parent, @NotNull
final CFTreasureListTree treasureListTree, @NotNull
final FaceObjectProviders faceObjectProviders, @NotNull
final AnimationObjects animationObjects, @NotNull
final ProjectSettings projectSettings, @NotNull
final FileFilter mapFileFilter, @NotNull
final FileFilter scriptFileFilter, @NotNull
final FaceObjects faceObjects, @NotNull
final Spells<
GameObjectSpell<G, A, R>> gameObjectSpells, @NotNull
final Spells<NumberSpell> numberSpells,
final int undefinedSpellIndex, @NotNull
final TreasureTree treasureTree, @NotNull
final ImageIcon noFaceSquareIcon, @NotNull
final ImageIcon unknownSquareIcon, @NotNull
final TextAreaDefaults textAreaDefaults, @NotNull
final MapManager<G, A, R> mapManager) {
456 if (mapSquare == null) {
457 throw new IllegalArgumentException();
462 mapManager.addMapManagerListener(mapManagerListener);
469 attributesPaneBuilder =
new AttributesPaneBuilder<>(
gameObject,
optionPane,
archetypeTypeSet, treasureListTree,
faceObjectProviders, animationObjects, projectSettings, mapFileFilter, scriptFileFilter, faceObjects, gameObjectSpells, numberSpells, undefinedSpellIndex, treasureTree, noFaceSquareIcon, unknownSquareIcon, textAreaDefaults);
471 centerPanel =
new JPanel(cardLayout);
472 centerPanel.add(
"edit", attributesPaneBuilder.
getTabbedPane());
473 summaryTextPane =
new JTextPane();
474 summaryTextPane.setEditable(
false);
475 summaryTextPane.setBorder(BorderFactory.createEmptyBorder(3, 15, 0, 0));
476 centerPanel.add(
"summary",
new JScrollPane(summaryTextPane));
477 final Dimension size = centerPanel.getPreferredSize();
479 centerPanel.setMinimumSize(size);
480 centerPanel.setPreferredSize(size);
482 final Container contentPanel =
new JPanel(
new GridBagLayout());
483 final GridBagConstraints gbc =
new GridBagConstraints();
485 gbc.fill = GridBagConstraints.BOTH;
486 gbc.gridwidth = GridBagConstraints.REMAINDER;
488 contentPanel.add(leftPane, gbc);
490 contentPanel.add(centerPanel, gbc);
494 summaryTextStyle = summaryTextPane.getStyle(StyleContext.DEFAULT_STYLE);
495 StyleConstants.setForeground(summaryTextStyle, Color.black);
497 faceObjectProviders.addFaceObjectProvidersListener(faceObjectProvidersListener);
499 optionPane.setMessage(contentPanel);
509 dialog.getRootPane().setDefaultButton(okButton);
510 dialog.setResizable(
true);
511 dialog.setModal(
false);
512 dialog.setVisible(
true);
528 final JComboBox<?> typeComboBox =
new JComboBox<>(model);
529 typeComboBox.setSelectedItem(archetypeType);
531 typeComboBox.setName(
"Types");
532 typeComboBox.addItemListener(typesBoxItemListener);
543 return faceObjectProviders.getFace(gameObject);
554 final JComponent header =
new JPanel(
new GridBagLayout());
555 final GridBagConstraints gbc =
new GridBagConstraints();
556 gbc.fill = GridBagConstraints.BOTH;
557 gbc.insets =
new Insets(2, 2, 2, 2);
563 faceLabel =
new JLabel(
getFace(gameObject));
564 faceLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
565 header.add(faceLabel, gbc);
568 gbc.fill = GridBagConstraints.HORIZONTAL;
582 final JTextComponent nameTextField;
583 final String objName = gameObject.getObjName();
584 if (objName.isEmpty()) {
585 final String archObjName = archetype.
getObjName();
586 final String nameText = !archObjName.isEmpty() ? archObjName : archetype.
getArchetypeName();
587 nameTextField =
new JTextField(nameText, 16);
589 nameTextField =
new JTextField(objName, 16);
591 nameTextField.setEditable(
false);
592 header.add(nameTextField, gbc);
596 final JTextComponent archetypeTextField =
new JTextField(archetype.
getArchetypeName(), 16);
597 archetypeTextField.setEditable(
false);
598 header.add(archetypeTextField, gbc);
609 summaryEditButton =
new JButton(summaryAction);
610 okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"attribOk",
this));
611 cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"attribCancel",
this));
612 return new Object[] {
new JButton(ACTION_BUILDER.createAction(
false,
"attribHelp",
this)), summaryEditButton, Box.createHorizontalStrut(32),
okButton,
new JButton(ACTION_BUILDER.createAction(
false,
"attribApply",
this)), cancelButton, };
621 new Help( parent, helpText).setVisible(
true);
630 optionPane.setValue(okButton);
647 optionPane.setValue(cancelButton);
657 final Document doc = summaryTextPane.getDocument();
661 if (doc.getLength() > 0) {
662 doc.remove(0, doc.getLength());
667 dialogAttribute.appendSummary(doc, summaryTextStyle);
669 }
catch (
final BadLocationException e) {
670 LOG.error(
"toggleSummary: Bad Location in Document!", e);
673 summaryTextPane.setCaretPosition(0);
674 summaryEditButton.setAction(editAction);
675 cardLayout.show(centerPanel,
"summary");
684 summaryEditButton.setAction(summaryAction);
685 cardLayout.show(centerPanel,
"edit");
695 assert mapSquare != null;
713 final StringBuilder newArchText =
new StringBuilder();
714 final String[] newMsg =
new String[1];
718 text = dialogAttribute.getObjectText(gameObject, archetype, newMsg, tmpArchetypeType);
720 JOptionPane.showMessageDialog(optionPane, ex.getMessage(),
"Input Error", JOptionPane.ERROR_MESSAGE);
723 if (!text.isEmpty()) {
724 newArchText.append(text).append(
"\n");
733 final String defaultValue = archetype.
getAttributeString(archetypeAttribute.getArchetypeAttributeName());
734 if (defaultValue.isEmpty() || (gameObject.getTypeNo() != archetype.
getTypeNo() && !defaultValue.equalsIgnoreCase(archetypeAttribute.getAttributeName()))) {
740 newArchText.append(archetypeAttribute.getArchetypeAttributeName()).append(
" ").append(archetypeAttribute.getAttributeName()).append(
"\n");
751 final int typeNo = gameObject.getTypeNo();
752 gameObject.setObjectText(newArchText.toString());
755 if (newMsg[0] != null) {
758 final String archetypeMsgText = archetype.
getMsgText();
759 gameObject.setMsgText(msgText.equals(archetypeMsgText == null ?
"" : archetypeMsgText) ? null : msgText);
761 final String archetypeMsgText = archetype.
getMsgText();
762 gameObject.setMsgText(archetypeMsgText != null && !archetypeMsgText.isEmpty() ?
"" : null);
766 faceLabel.setIcon(
getFace(gameObject));
769 if (errors != null) {
776 gameObject.addObjectText(errors.trim());
final JOptionPane optionPane
void removeMapManagerListener(@NotNull MapManagerListener< G, A, R > listener)
Removes a MapManagerListener to be notified.
Utility class for displaying a dialog to keep or dump invalid attributes of a game object...
JComponent buildHeader()
Constructs the upper left part of the attribute dialog, containing name, type, archetype name and fac...
Utility class for string manipulation.
MapSquare< G, A, R > getMapSquare()
A MapModel reflects the data of a map.
String getObjName()
Returns the name of the object as shown to the player.
A MapManager manages all opened maps.
Graphical User Interface of Gridarta.
void attribCancel()
Action method for cancel.
Settings that apply to a project.
static final ActionBuilder ACTION_BUILDER
Action Builder.
JDialog createDialog()
Creates a new JDialog instance for this dialog.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
Manages ArchetypeType instances, list, and bitmask definitions.
This Class contains the data of one archetype attribute.
static String getSyntaxErrors(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final ArchetypeType type)
This method checks the objectText for syntax errors.
This package contains the framework for validating maps.
void endTransaction()
End a transaction.
final MapModel< G, A, R > mapModel
gameObject's initial map.
void attribEdit()
Turns the summary off.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
ArchetypeType getArchetypeTypeByBaseObject(@NotNull final BaseObject<?, ?, ?, ?> baseObject)
Returns the ArchetypeType for the given BaseObject.
final MapManager< G, A, R > mapManager
The MapManager instance.
Component getTabbedPane()
Returns the JTabbedPane that contains all attribute tabs.
Contains the data of one Gridarta Object-Type.
Interface for listeners listening on MapModel events.
This packages implements the online help system for the Gridarta editor.
An ArchetypeAttribute displaying a fixed string.
static boolean askConfirmErrors(@NotNull final String errors, @NotNull final Component parent)
Open a popup dialog and ask the user to confirm (or modify) the encountered syntax errors...
JButton okButton
The Button for ok.
boolean isFallbackArchetypeType(@NotNull final ArchetypeType archetypeType)
Returns whether a given ArchetypeType is the fallback archetype type used for game objects not matchi...
String getArchetypeName()
Returns the name of this archetype.
Describes a numbered in-game spell.
static final Category LOG
The Logger for printing log messages.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
void attribOk()
Action method for ok.
void buildAttribute(@NotNull final Attributes attributes, @NotNull final Iterable< ArchetypeAttributeSection > archetypeType)
Constructs the central part of the attribute dialog, containing the object's attributes.
final JTextPane summaryTextPane
The text pane where the summary is displayed.
String getAttributeString(@NotNull String attributeName, boolean queryArchetype)
Returns the requested attribute value of this GameObject as String.
String TYPE
The attribute name of the object's type.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
static String removeTrailingWhitespaceFromLines(@NotNull final CharSequence str)
Removes trailing whitespace from all lines of a string.
Base package of all Gridarta classes.
Common base class for spells and spell lists.
final MapModelListener< G, A, R > mapModelListener
Tracks mapModel's map for changes: when the gameObject is removed, cancels this dialog.
Reflects a game object (object on a map).
void hideAttributeDialog(@NotNull final G gameObject)
Hides the game object attributes dialog for a given GameObject instance.
Iterable< DialogAttribute< G, A, R, ?> > getDialogAttributes()
Returns all DialogAttributes in the dialog.
A set of ArchetypeAttributes.
Component buildTypesBox()
Constructs the combo box of the available archetypes.
A ListCellRenderer implementation that displays ArchetypeTypes.
Interface for listeners listening to MapManager changes.
final MapManagerListener< G, A, R > mapManagerListener
The MapManagerListener to detect closed maps.
ImageIcon getFace(@NotNull final BaseObject< G, A, R, ?> gameObject)
Returns the face for a GameObject.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
AnimationObjects is a container for AnimationObjects.
GameObjects are the objects based on Archetypes found on maps.
final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory
The associated factory.
final Style summaryTextStyle
int getTypeNo()
Returns the type number.
Point getMapLocation()
Returns the coordinate on the map.
Utility class for GameObject related functions.
The CFTreasureListTree class fully manages treasurelists.
void attribHelp()
Action method for help.
Object [] buildOptions()
Constructs the dialog options: help, default, okay, apply, cancel.
AbstractButton cancelButton
The Button for cancel.
Implements the Help Window is a separate frame with html content.
String getDescription()
Returns the description.
ArchetypeType archetypeType
The ArchetypeType of gameObject.
final G gameObject
The game object being modified.
final ArchetypeTypeSet archetypeTypeSet
Reference to the ArchetypeTypeSet.
Describes a numbered in-game spell.
This package contains the other part of the script editor.
Common base class for game object attributes dialogs.
FaceObjects is a container for FaceObjects.
void removeFaceObjectProvidersListener(@NotNull final FaceObjectProvidersListener listener)
Removes a FaceObjectProvidersListener to be notified about changes.
String getMsgText()
Returns the message bound to this object.
Indicates that an attribute cannot be encoded.
int getArchetypeTypeCount()
Returns the number of ArchetypeTypes in the list.
final Container centerPanel
The central pane, this is the parent component of above tabbed pane.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
R getArchetype()
Returns the Archetype this GameObject is based on.
A single Attribute, combining an ArchetypeAttribute with its input component(s).
AbstractButton summaryEditButton
The Button for toggling the summary.
Utility class for ActionBuilder related functions.
Stores all defined treasure lists.
Interface for listeners interested in FaceObjectProviders related events.
Provider for faces of GameObjects and Archetypes.
final Frame parent
The parent frame for showing dialog boxes.
The face is the appearance of an object.
Currently nothing more than a marker interface for unification.
final AttributesPaneBuilder< G, A, R > attributesPaneBuilder
/he AttributesPaneBuilder for creating (and re-creating) the attribute tabs.
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
An interface for classes that collect errors.
final ItemListener typesBoxItemListener
ItemListener for the type-selection box on the attribute dialog.
final Archetype< G, A, R > archetype
gameObject's archetype.
final FaceObjectProvidersListener faceObjectProvidersListener
The FaceObjectProvidersListener for detecting reloaded faces.
void attribSummary()
Action method for summary.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
final Action summaryAction
The Action for switching to the summary.
void beginTransaction(@NotNull String name)
Starts a new transaction.
boolean applySettings()
This method is called when the "apply"-button has been pressed.
static String format(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final Object... args)
Returns the value of a key.
JLabel faceLabel
The panel for object's face (png).
Defines types of GameObjects with corresponding attributes.
final Action editAction
The Action for switching to the edit.
GameObjectAttributesDialog(@NotNull final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory, final ArchetypeTypeSet archetypeTypeSet, @NotNull final G gameObject, @NotNull final Frame parent, @NotNull final CFTreasureListTree treasureListTree, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects, @NotNull final ProjectSettings projectSettings, @NotNull final FileFilter mapFileFilter, @NotNull final FileFilter scriptFileFilter, @NotNull final FaceObjects faceObjects, @NotNull final Spells< GameObjectSpell< G, A, R >> gameObjectSpells, @NotNull final Spells< NumberSpell > numberSpells, final int undefinedSpellIndex, @NotNull final TreasureTree treasureTree, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon, @NotNull final TextAreaDefaults textAreaDefaults, @NotNull final MapManager< G, A, R > mapManager)
Creates a new instance.
void attribApply()
Action method for apply.
boolean applySettings2()
This method is called when the "apply"-button has been pressed.
final Point mapPos
The position of the game object.
The location of a map file with a map directory.
String getTypeName()
Returns the type name (artificial).
Interface for MapArchObjects.
final CardLayout cardLayout
The CardLayout for toggling between edit and summary.
String getUse()
Returns the usage notes.
Encapsulates default settings for a text area.
int getTypeNo()
Returns the type number of this Archetype.
The class Size2D represents a 2d rectangular area.