20 package net.sf.gridarta.gui.panel.gameobjecttexteditor;
22 import java.awt.BorderLayout;
23 import java.awt.Color;
24 import java.awt.Component;
25 import java.util.Arrays;
26 import java.util.Collection;
27 import java.util.HashSet;
28 import javax.swing.JPanel;
29 import javax.swing.JScrollPane;
30 import javax.swing.JTextPane;
31 import javax.swing.JViewport;
32 import javax.swing.ScrollPaneConstants;
33 import javax.swing.text.BadLocationException;
34 import javax.swing.text.Document;
35 import javax.swing.text.MutableAttributeSet;
36 import javax.swing.text.StyleConstants;
37 import javax.swing.text.StyleContext;
45 import org.jetbrains.annotations.NotNull;
46 import org.jetbrains.annotations.Nullable;
83 super(
new BorderLayout());
85 final JScrollPane scrollPane =
new JScrollPane();
86 add(scrollPane, BorderLayout.CENTER);
87 scrollPane.setViewportView(archEdit);
88 scrollPane.setBackground(archEdit.getBackground());
89 scrollPane.getViewport().add(archEdit);
90 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
91 scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
92 scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
100 return !archEdit.getText().equals(defaultArchEditValue);
119 archEdit.setEnabled(gameObject != null);
120 archEdit.setText(
"");
122 if (gameObject != null) {
123 final MutableAttributeSet currentAttributes = archEdit.getStyle(StyleContext.DEFAULT_STYLE);
125 final Document document = archEdit.getDocument();
130 final String objectText = gameObject.getObjectText();
131 if (errorText == null) {
132 StyleConstants.setForeground(currentAttributes, Color.blue);
133 document.insertString(document.getLength(), objectText, currentAttributes);
134 if (!objectText.isEmpty()) {
140 StyleConstants.setForeground(currentAttributes, Color.red);
141 document.insertString(document.getLength(), errorText, currentAttributes);
143 final Collection<String> errors =
new HashSet<>();
145 StyleConstants.setForeground(currentAttributes, Color.blue);
147 if (!errors.contains(line)) {
148 document.insertString(document.getLength(), line +
'\n', currentAttributes);
153 StyleConstants.setForeground(currentAttributes, Color.black);
155 }
catch (
final BadLocationException ex) {
156 throw new AssertionError(ex);
159 archEdit.setCaretPosition(0);
160 defaultArchEditValue = archEdit.getText();
177 archEdit.requestFocusInWindow();
178 final Document document = archEdit.getDocument();
179 if (document != null) {
180 archEdit.setCaretPosition(document.getLength());
Component getTextPane()
Returns the text input pane.
Utility class for string manipulation.
Graphical User Interface of Gridarta.
Reading and writing of maps, handling of paths.
Manages ArchetypeType instances, list, and bitmask definitions.
static String getSyntaxErrors(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final ArchetypeType type)
This method checks the objectText for syntax errors.
ArchetypeType getArchetypeTypeByBaseObject(@NotNull final BaseObject<?, ?, ?, ?> baseObject)
Returns the ArchetypeType for the given BaseObject.
void applyChanges(@NotNull final GameObject<?, ?, ?> gameObject)
Updates a GameObject's attributes from the input field.
Contains the data of one Gridarta Object-Type.
Severity refreshDisplay(@Nullable final GameObject<?, ?, ?> gameObject)
Refreshes the input field to show the attributes of a GameObject.
MODIFIED
The tab contents are modified from defaults.
static final long serialVersionUID
The serial version UID.
void activate()
Activates this component.
Base package of all Gridarta classes.
boolean canApplyChanges()
Returns whether the current text field differs from the initial value.
Reflects a game object (object on a map).
GameObjects are the objects based on Archetypes found on maps.
Utility class for GameObject related functions.
Utility class for archetype attribute related functions.
String defaultArchEditValue
The initial value of archEdit.
ERROR
The tab contents are invalid.
final JTextPane archEdit
The JTextPane that contains the attributes of the game object.
Severity levels for colors of tabs.
A JTextPane that always extends horizontally.
static final Pattern PATTERN_END_OF_LINE
The pattern to match end of line characters separating lines.
static String diffArchTextKeys(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final BaseObject<?, ?, ?, ?> archetype)
Returns all attributes from the given game object that don't exist in an archetype.
DEFAULT
The tab contents are unchanged from defaults.
Implements the "Game Object Text Editor".
GameObjectTextEditor(@NotNull final ArchetypeTypeSet archetypeTypeSet)
Creates a new instance.
Defines types of GameObjects with corresponding attributes.
static String diffArchTextValues(@NotNull final BaseObject<?, ?, ?, ?> archetype, @NotNull final CharSequence attributes)
Returns all entries from the given attributes that don't exist in an archetype.
final ArchetypeTypeSet archetypeTypeSet
The ArchetypeTypeSet.