 |
Gridarta Editor
|
Go to the documentation of this file.
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) {
284 public void mapSizeChanged(@NotNull
final Size2D newSize) {
285 if (
gameObject.getMapSquareOptional() ==
null) {
298 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
299 if (
gameObject.getMapSquareOptional() ==
null) {
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) {
358 public void facesReloaded() {
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) {
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) {
466 attributesPaneBuilder =
new AttributesPaneBuilder<>(
gameObject,
optionPane,
archetypeTypeSet, treasureListTree,
faceObjectProviders, animationObjects, projectSettings, mapFileFilter, scriptFileFilter, faceObjects, gameObjectSpells, numberSpells, undefinedSpellIndex, treasureTree, noFaceSquareIcon, unknownSquareIcon, textAreaDefaults);
472 summaryTextPane.setBorder(BorderFactory.createEmptyBorder(3, 15, 0, 0));
474 final Dimension size =
centerPanel.getPreferredSize();
479 final Container contentPanel =
new JPanel(
new GridBagLayout());
480 final GridBagConstraints gbc =
new GridBagConstraints();
482 gbc.fill = GridBagConstraints.BOTH;
483 gbc.gridwidth = GridBagConstraints.REMAINDER;
485 contentPanel.add(leftPane, gbc);
506 dialog.getRootPane().setDefaultButton(
okButton);
507 dialog.setResizable(
true);
508 dialog.setModal(
false);
509 dialog.setVisible(
true);
525 final JComboBox<?> typeComboBox =
new JComboBox<>(model);
528 typeComboBox.setName(
"Types");
551 final JComponent header =
new JPanel(
new GridBagLayout());
552 final GridBagConstraints gbc =
new GridBagConstraints();
553 gbc.fill = GridBagConstraints.BOTH;
554 gbc.insets =
new Insets(2, 2, 2, 2);
561 faceLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
565 gbc.fill = GridBagConstraints.HORIZONTAL;
579 final JTextComponent nameTextField;
580 final String objName =
gameObject.getObjName();
581 if (objName.isEmpty()) {
582 final String archObjName =
archetype.getObjName();
584 nameTextField =
new JTextField(nameText, 16);
586 nameTextField =
new JTextField(objName, 16);
588 nameTextField.setEditable(
false);
589 header.add(nameTextField, gbc);
594 archetypeTextField.setEditable(
false);
595 header.add(archetypeTextField, gbc);
609 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, };
658 if (doc.getLength() > 0) {
659 doc.remove(0, doc.getLength());
666 }
catch (
final BadLocationException e) {
667 LOG.error(
"toggleSummary: Bad Location in Document!", e);
708 final StringBuilder newArchText =
new StringBuilder();
709 final String[] newMsg =
new String[1];
715 JOptionPane.showMessageDialog(
optionPane, ex.getMessage(),
"Input Error", JOptionPane.ERROR_MESSAGE);
718 if (!text.isEmpty()) {
719 newArchText.append(text).append(
"\n");
728 final String defaultValue =
archetype.getAttributeString(archetypeAttribute.getArchetypeAttributeName());
729 if (defaultValue.isEmpty() || (
gameObject.getTypeNo() !=
archetype.getTypeNo() && !defaultValue.equalsIgnoreCase(archetypeAttribute.getAttributeName()))) {
735 newArchText.append(archetypeAttribute.getArchetypeAttributeName()).append(
" ").append(archetypeAttribute.getAttributeName()).append(
"\n");
747 gameObject.setObjectText(newArchText.toString());
750 if (newMsg[0] ==
null) {
751 final String archetypeMsgText =
archetype.getMsgText(
false);
752 gameObject.setMsgText(archetypeMsgText !=
null && !archetypeMsgText.isEmpty() ?
"" :
null);
756 final String archetypeMsgText =
archetype.getMsgText(
false);
757 gameObject.setMsgText(msgText.equals(archetypeMsgText ==
null ?
"" : archetypeMsgText) ?
null : msgText);
Defines types of GameObjects with corresponding attributes.
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.
Encapsulates default settings for a text area.
A MapModel reflects the data of a map.
JDialog createDialog()
Creates a new JDialog instance for this dialog.
String getArchetypeName()
Returns the name of this archetype.
final Action editAction
The Action for switching to the edit.
final MapManagerListener< G, A, R > mapManagerListener
The MapManagerListener to detect closed maps.
A MapManager manages all opened maps.
final MapModelListener< G, A, R > mapModelListener
Tracks mapModel's map for changes: when the gameObject is removed, cancels this dialog.
void buildAttribute(@NotNull final Attributes attributes, @NotNull final Iterable< ArchetypeAttributeSection > archetypeType)
Constructs the central part of the attribute dialog, containing the object's attributes.
Point getMapLocation()
Returns the coordinate on the map.
void attribSummary()
Action method for summary.
This package contains the other part of the script editor.
final AttributesPaneBuilder< G, A, R > attributesPaneBuilder
/he AttributesPaneBuilder for creating (and re-creating) the attribute tabs.
void removeMapManagerListener(@NotNull MapManagerListener< G, A, R > listener)
Removes a MapManagerListener to be notified.
Base package of all Gridarta classes.
AbstractButton cancelButton
The Button for cancel.
Indicates that an attribute cannot be encoded.
final JTextPane summaryTextPane
The text pane where the summary is displayed.
void endTransaction()
End a transaction.
AnimationObjects is a container for AnimationObjects.
Utility class for displaying a dialog to keep or dump invalid attributes of a game object.
Describes a numbered in-game spell.
String getTypeName()
Returns the type name (artificial).
String getUse()
Returns the usage notes.
void beginTransaction(@NotNull String name)
Starts a new transaction.
Common base class for game object attributes dialogs.
Interface for listeners listening to MapManager changes.
boolean applySettings()
This method is called when the "apply"-button has been pressed.
final Style summaryTextStyle
void addMapManagerListener(@NotNull MapManagerListener< G, A, R > listener)
Adds a MapManagerListener to be notified.
A ListCellRenderer implementation that displays ArchetypeTypes.
final Frame parent
The parent frame for showing dialog boxes.
Provider for faces of GameObjects and Archetypes.
Reflects a game object (object on a map).
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
void attribApply()
Action method for apply.
Manages ArchetypeType instances, list, and bitmask definitions.
Implements the Help Window is a separate frame with html content.
boolean applySettings2()
This method is called when the "apply"-button has been pressed.
void addFaceObjectProvidersListener(@NotNull final FaceObjectProvidersListener listener)
Adds a FaceObjectProvidersListener to be notified about changes.
Graphical User Interface of Gridarta.
Component getTabbedPane()
Returns the JTabbedPane that contains all attribute tabs.
final Action summaryAction
The Action for switching to the summary.
Component buildTypesBox()
Constructs the combo box of the available archetypes.
JLabel faceLabel
The panel for object's face (png).
void attribOk()
Action method for ok.
A single Attribute, combining an ArchetypeAttribute with its input component(s).
GameObjects are the objects based on Archetypes found on maps.
void removeFaceObjectProvidersListener(@NotNull final FaceObjectProvidersListener listener)
Removes a FaceObjectProvidersListener to be notified about changes.
final CardLayout cardLayout
The CardLayout for toggling between edit and summary.
final MapManager< G, A, R > mapManager
The MapManager instance.
ArchetypeType getArchetypeTypeByBaseObject(@NotNull final BaseObject<?, ?, ?, ?> baseObject)
Returns the ArchetypeType for the given BaseObject.
This Class contains the data of one archetype attribute.
Stores all defined treasure lists.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
static final Category LOG
The Logger for printing log messages.
Interface for MapArchObjects.
Describes a numbered in-game spell.
AbstractButton summaryEditButton
The Button for toggling the summary.
final MapModel< G, A, R > mapModel
gameObject's initial map.
String getDescription()
Returns the description.
void attribHelp()
Action method for help.
Object[] buildOptions()
Constructs the dialog options: help, default, okay, apply, cancel.
JComponent buildHeader()
Constructs the upper left part of the attribute dialog, containing name, type, archetype name and fac...
FaceObjects is a container for FaceObjects.
An interface for classes that collect errors.
void attribEdit()
Turns the summary off.
The online help system for the Gridarta editor.
public< G extends GameObject< G, A, R >, A extends MapArchObject< A >, R extends Archetype< G, A, R > > ImageIcon getFace(@NotNull final BaseObject< G, A, R, ?> baseObject)
Returns the face of a BaseObject as an ImageIcon.
static String format(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final Object... args)
Returns the value of a key.
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.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
void attribCancel()
Action method for cancel.
Utility class for string manipulation.
The location of a map file with a map directory.
Settings that apply to a project.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory
The associated factory.
final G gameObject
The game object being modified.
final FaceObjectProvidersListener faceObjectProvidersListener
The FaceObjectProvidersListener for detecting reloaded faces.
Interface for listeners listening on MapModel events.
final ArchetypeTypeSet archetypeTypeSet
Reference to the ArchetypeTypeSet.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
A set of ArchetypeAttributes.
JButton okButton
The Button for ok.
ImageIcon getFace(@NotNull final BaseObject< G, A, R, ?> gameObject)
Returns the face for a GameObject.
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.
boolean isFallbackArchetypeType(@NotNull final ArchetypeType archetypeType)
Returns whether a given ArchetypeType is the fallback archetype type used for game objects not matchi...
static final ActionBuilder ACTION_BUILDER
Action Builder.
Interface for listeners interested in FaceObjectProviders related events.
The face is the appearance of an object.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
Iterable< DialogAttribute< G, A, R, ?> > getDialogAttributes()
Returns all DialogAttributes in the dialog.
An ArchetypeAttribute displaying a fixed string.
Currently nothing more than a marker interface for unification.
final Archetype< G, A, R > archetype
gameObject's archetype.
Utility class for ActionBuilder related functions.
Contains the data of one Gridarta Object-Type.
Utility class for GameObject related functions.
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
int getTypeNo()
Returns the type number.
String TYPE
The attribute name of the object's type.
final Container centerPanel
The central pane, this is the parent component of above tabbed pane.
static String removeTrailingWhitespaceFromLines(@NotNull final CharSequence str)
Removes trailing whitespace from all lines of a string.
Common base class for spells and spell lists.
ArchetypeType archetypeType
The ArchetypeType of gameObject.
final ItemListener typesBoxItemListener
ItemListener for the type-selection box on the attribute dialog.
The class Size2D represents a 2d rectangular area.
final JOptionPane optionPane
The CFTreasureListTree class fully manages treasurelists.
void hideAttributeDialog(@NotNull final G gameObject)
Hides the game object attributes dialog for a given GameObject instance.
final Point mapPos
The position of the game object.
int getArchetypeTypeCount()
Returns the number of ArchetypeTypes in the list.