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);
764 if (errors !=
null) {