 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.dialog.find;
22 import java.awt.Component;
23 import java.awt.Container;
24 import java.awt.FlowLayout;
25 import java.awt.Point;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
29 import javax.swing.AbstractButton;
30 import javax.swing.BorderFactory;
31 import javax.swing.Box;
32 import javax.swing.BoxLayout;
33 import javax.swing.JButton;
34 import javax.swing.JCheckBox;
35 import javax.swing.JDialog;
36 import javax.swing.JOptionPane;
37 import javax.swing.JPanel;
38 import javax.swing.JTextField;
39 import javax.swing.WindowConstants;
40 import javax.swing.text.JTextComponent;
58 import net.
sf.japi.swing.action.ActionBuilder;
59 import net.
sf.japi.swing.action.ActionBuilderFactory;
60 import net.
sf.japi.swing.action.ActionMethod;
61 import org.jetbrains.annotations.NotNull;
78 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
107 private final JTextComponent
findInput =
new JTextField(20);
152 dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
170 final JPanel mainPanel =
new JPanel();
171 mainPanel.setLayout(
new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
172 mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5));
174 final Container lineFind =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
176 lineFind.add(Box.createVerticalStrut(3));
178 lineFind.add(Box.createVerticalStrut(3));
179 mainPanel.add(lineFind);
181 final Container lineWhere =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
183 lineWhere.add(Box.createVerticalStrut(5));
185 final JPanel panelWhere =
new JPanel();
186 panelWhere.setLayout(
new BoxLayout(panelWhere, BoxLayout.Y_AXIS));
193 lineWhere.add(panelWhere);
194 mainPanel.add(lineWhere);
196 final JButton okButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"findOk",
this));
197 final JButton cancelButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"findCancel",
this));
203 setMessage(mainPanel);
204 setOptions(
new Object[] { okButton, cancelButton });
205 dialog.getRootPane().setDefaultButton(okButton);
258 private boolean doFind(
final boolean forward) {
259 final String findString =
findInput.getText().trim();
260 final Collection<MatchCriteria<G, A, R>> matchCriterias =
new ArrayList<>();
280 return !matchCriterias.isEmpty() &&
doFind(matchCriterias, forward) > 0;
291 final List<G> matchingGameObjects =
new ArrayList<>();
292 final Collection<MapSquare<G, A, R>> matchingMapSquares =
new ArrayList<>();
296 boolean matchesMapSquare =
false;
297 for (
final G gameObject : mapSquare.recursive()) {
299 if (matchCriteria.matches(gameObject)) {
300 matchingGameObjects.add(gameObject);
301 matchesMapSquare =
true;
305 if (matchesMapSquare) {
306 matchingMapSquares.add(mapSquare);
311 return matchingGameObjects.size();
321 final Point p =
new Point();
323 p.x = mapSquare.getMapX();
324 p.y = mapSquare.getMapY();
335 private void setMapCursor(
final boolean forward, @NotNull
final List<G> gameObjects) {
336 if (gameObjects.isEmpty()) {
343 if (selectedGameObject ==
null) {
346 final int selectedIndex = gameObjects.indexOf(selectedGameObject);
347 if (selectedIndex == -1) {
349 }
else if (forward) {
350 index = selectedIndex + 1 < gameObjects.size() ? selectedIndex + 1 : 0;
352 index = (selectedIndex > 0 ? selectedIndex : gameObjects.size()) - 1;
A MapModel reflects the data of a map.
void findOk()
Action method for Ok button.
MapGrid getMapGrid()
Returns the MapGrid of this view.
boolean findAgain(@NotNull final MapView< G, A, R > mapView, final boolean forward, final boolean performAction)
Re-executes the previous find operation.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
void display(@NotNull final MapView< G, A, R > mapView)
Replace objects on the map.
Criteria for game object matchers.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
final JTextComponent findInput
The text input field for the string to find.
Base package of all Gridarta classes.
final AbstractButton findArchCheckbox
The checkbox for matching archetype names.
A MatchCriteria that matches attribute values of all but a set of attributes.
G getGameObject()
Returns the selected GameObject.
final Component parent
The parent component for dialogs.
A MatchCriteria that matches by archetype name.
boolean isBuilt
Whether this find dialog has been displayed.
final AbstractButton findNameCheckbox
The checkbox for matching 'name' attributes.
Reflects a game object (object on a map).
void dispose(@NotNull final MapView< G, A, R > mapView)
Disposes the find dialog.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
A MatchCriteria that matches an attribute value.
MapView< G, A, R > mapView
The MapView to operate on.
void setGameObject(@Nullable final G gameObject)
Sets the selected GameObject.
Graphical User Interface of Gridarta.
int doFind(@NotNull final Iterable< MatchCriteria< G, A, R >> matchCriterias, final boolean forward)
This method performs the actual find action on a map.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
GameObjects are the objects based on Archetypes found on maps.
final AbstractButton findOtherCheckbox
The checkbox for matching all other attributes.
Interface for MapArchObjects.
void findCancel()
Action method for Cancel button.
This dialog manages the find action.
A map view consists of a map grid and a map cursor, and is attached to a map control.
Modes that describe how squares get selected.
static String format(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final Object... args)
Returns the value of a key.
MapCursor provides methods to move and drag on map.
void select(@NotNull final Point pos, @NotNull final SelectionMode selectionMode)
Selects or deselects a single square.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
static final long serialVersionUID
Serial Version UID.
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
ADD
All squares that are preselected get selected.
final JDialog dialog
The dialog instance.
final AbstractButton findSlayingCheckbox
The checkbox for matching 'slaying' attributes.
static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent)
Selects all text of a JTextComponent when the component gains the focus.
void selectMapSquares(@NotNull final Iterable< MapSquare< G, A, R >> mapSquares)
Selects a set of MapSquares on the map.
Base classes for rendering maps.
A MatchCriteria that matches by object name.
final AbstractButton findFaceCheckbox
The checkbox for matching 'face' or 'animation' attributes.
void setMapCursor(final boolean forward, @NotNull final List< G > gameObjects)
Moves the cursor to the next or previous matching game object.
final AbstractButton findMsgCheckbox
The checkbox for matching 'msg' attributes.
Currently nothing more than a marker interface for unification.
FindDialog(@NotNull final Component parent)
Creates a new instance.
Utility class for ActionBuilder related functions.
MapModel< G, A, R > getMapModel()
Returns the map model.
static final ActionBuilder ACTION_BUILDER
Action Builder.
Utility class for JTextComponent related functions.
boolean doFind(final boolean forward)
Executes one find operation.
void unSelect()
Clears all selection and pre-selection flags from the grid.