 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.dialog.replace;
22 import java.awt.Component;
23 import java.awt.Container;
24 import java.awt.FlowLayout;
25 import java.awt.event.ItemEvent;
26 import java.awt.event.ItemListener;
27 import java.util.ArrayList;
28 import java.util.List;
29 import javax.swing.BorderFactory;
30 import javax.swing.Box;
31 import javax.swing.BoxLayout;
32 import javax.swing.Icon;
33 import javax.swing.JButton;
34 import javax.swing.JComboBox;
35 import javax.swing.JDialog;
36 import javax.swing.JLabel;
37 import javax.swing.JOptionPane;
38 import javax.swing.JPanel;
39 import javax.swing.JTextField;
40 import javax.swing.WindowConstants;
41 import javax.swing.text.JTextComponent;
57 import net.
sf.japi.swing.action.ActionBuilder;
58 import net.
sf.japi.swing.action.ActionBuilderFactory;
59 import net.
sf.japi.swing.action.ActionMethod;
60 import org.jetbrains.annotations.NotNull;
61 import org.jetbrains.annotations.Nullable;
79 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
210 public void pickmapActiveChanged(
final boolean pickmapActive) {
228 public void facesReloaded() {
243 public ReplaceDialog(@NotNull
final Component
parent, @NotNull
final CopyBuffer<G, A, R> copyBuffer, @NotNull
final ObjectChooser<G, A, R> objectChooser, @NotNull
final FaceObjectProviders faceObjectProviders, @NotNull
final InsertionModeSet<G, A, R> insertionModeSet) {
247 dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
291 final JPanel mainPanel =
new JPanel();
292 mainPanel.setLayout(
new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
293 mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5));
296 final Container line1 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
298 line1.add(Box.createVerticalStrut(3));
303 line1.add(Box.createVerticalStrut(3));
306 mainPanel.add(line1);
309 final Container line2 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
311 line2.add(Box.createVerticalStrut(5));
317 line2.add(Box.createVerticalStrut(5));
322 mainPanel.add(line2);
325 final Container line3 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
327 line3.add(Box.createVerticalStrut(5));
346 line3.add(Box.createVerticalStrut(5));
349 mainPanel.add(line3);
352 final Container line4 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
354 line4.add(Box.createVerticalStrut(5));
359 mainPanel.add(line4);
361 final JButton okButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"replaceOk",
this));
362 final JButton applyButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"replaceApply",
this));
363 final JButton cancelButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"replaceCancel",
this));
365 setMessage(mainPanel);
366 setOptions(
new Object[] { okButton, applyButton, cancelButton });
367 dialog.getRootPane().setDefaultButton(okButton);
385 if (newArch ==
null) {
390 final Icon oldIcon =
iconLabel.getIcon();
393 rfArchName.setText(
" " + newArch.getBestName());
397 if (alwaysPack || (oldIcon ==
null &&
iconLabel.getIcon() !=
null) || (oldIcon !=
null &&
iconLabel.getIcon() ==
null) || (oldIcon !=
iconLabel.getIcon() && oldIcon !=
null && oldIcon.getIconHeight() !=
iconLabel.getIcon().getIconHeight())) {
410 private static <T> List<T>
newList(@NotNull
final T element) {
411 final List<T>
list =
new ArrayList<>(1);
424 if (e.getStateChange() == ItemEvent.SELECTED &&
lastSelectedIndex != selectedIndex) {
426 switch (selectedIndex) {
505 final int replaceDensity;
508 }
catch (
final NumberFormatException ignored) {
512 if (replaceDensity < 1 || replaceDensity > 100) {
517 @Nullable
final List<? extends BaseObject<G, A, R, ?>> replaceList;
536 if (replaceCount <= 0) {
541 if (replaceCount == 1) {
544 ACTION_BUILDER.showMessageDialog(
this,
"replacedMany", replaceCount);
static< G extends GameObject< G, A, R > A extends R extends Archetype< G, A, R > int replace(@NotNull final MatchCriteria< G, A, R > matchCriteria, final boolean entireMap, final boolean deleteOnly, final int replaceDensity, @NotNull final MapView< G, A, R > mapView, @NotNull final InsertionModeSet< G, A, R > insertionModeSet, @Nullable final List<? extends BaseObject< G, A, R, ?>> replaceList)
static final long serialVersionUID
Serial Version UID.
MapGrid getMapGrid()
Returns the MapGrid of this view.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
void replaceCancel()
Action method for Cancel button.
static final int REPLACE_ON_MAP
Index for replaceEntireBox: replace map.
Criteria for game object matchers.
static final int REPLACE_WITH_COPY_BUFFER
Index for replaceWithBox: replace with copy buffer contents.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
final ObjectChooser< G, A, R > objectChooser
The object chooser to use.
static final ActionBuilder ACTION_BUILDER
Action Builder.
Base package of all Gridarta classes.
void addObjectChooserListener(@NotNull ObjectChooserListener< G, A, R > listener)
Adds a listener to be notified.
boolean doReplace()
Executes one replace operation.
BaseObject< G, A, R, ?> getCursorSelection()
Returns the selected archetype (if the archetype chooser is active) or the game object selected by th...
List<? extends BaseObject< G, A, R, ?> > replacePickmap
static final int REPLACE_ON_SELECTION
Index for replaceEntireBox: replace selection.
A MatchCriteria that matches by archetype name.
void itemStateChanged(@NotNull final ItemEvent e)
Rectangle getSelectedRec()
Returns the smallest rectangle containing selection.
boolean isBuilt
Whether this replace dialog has been displayed.
ReplaceDialog(@NotNull final Component parent, @NotNull final CopyBuffer< G, A, R > copyBuffer, @NotNull final ObjectChooser< G, A, R > objectChooser, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet< G, A, R > insertionModeSet)
Creates a new instance.
final ObjectChooserListener< G, A, R > objectChooserListener
The ObjectChooserListener for tracking the selection.
static final int REPLACE_WITH_PICKMAP
Index for replaceWithBox: replace with pickmap contents.
Provider for faces of GameObjects and Archetypes.
Reflects a game object (object on a map).
String getBestName()
Returns the name which is best appropriate to describe this GameObject.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
JComboBox< String > replaceEntireBox
List< G > getAllGameObjects()
Returns all game objects.
final FaceObjectProvidersListener faceObjectProvidersListener
The FaceObjectProvidersListener for detecting reloaded faces.
void addFaceObjectProvidersListener(@NotNull final FaceObjectProvidersListener listener)
Adds a FaceObjectProvidersListener to be notified about changes.
Graphical User Interface of Gridarta.
static final int REPLACE_WITH_NOTHING
Index for replaceWithBox: delete matching game objects.
This dialog manages the replace action.
List< G > replaceCopyBuffer
GameObjects are the objects based on Archetypes found on maps.
List<? extends BaseObject< G, A, R, ?> > getSelections()
Returns the selected arches in the left-side panel.
JComboBox< String > replaceCriteria
JComboBox< String > replaceWithBox
BaseObject< G, A, R, ?> replaceArch
Objects will be replaced with this game object.
void dispose(@NotNull final MapView< G, A, R > mapView)
Disposes the replace dialog.
static final int REPLACE_WITH_OBJECT_CHOOSER
Index for replaceWithBox: replace with object chooser selection.
This document describes some hints and requirements for general development on the CrossfireEditor If you plan to make changes to the editor code or setup please read the following and keep it in derived from a basic editor application called Gridder by Pasi Ker�nen so please communicate with best through the cf devel mailing list
Interface for MapArchObjects.
final JDialog dialog
The dialog instance.
A map view consists of a map grid and a map cursor, and is attached to a map control.
BaseObject< G, A, R, ?> getSelection()
Returns the active arch in the left-side panel.
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.
Common base implementation of CopyBuffer.
void display(@NotNull final MapView< G, A, R > mapView)
Replace objects on the map.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Common base interface for ObjectChoosers.
JTextComponent replaceDensityInput
Input field for replace density value.
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
Item-listener for the "replace with"-selection box.
void replaceApply()
Action method for Apply button.
Base classes for rendering maps.
A MatchCriteria that matches by object name.
Utility class to replace objects in a map.
Interface for listeners interested in FaceObjectProviders related events.
The face is the appearance of an object.
final InsertionModeSet< G, A, R > insertionModeSet
The InsertionModeSet to use.
Utility class for ActionBuilder related functions.
MapModel< G, A, R > getMapModel()
Returns the map model.
List< MapSquare< G, A, R > > getSelectedSquares()
Returns the selected squares.
final Component parent
The parent component for dialogs.
JTextComponent replaceInput1
final CopyBuffer< G, A, R > copyBuffer
The CopyBuffer.
static< T > List< T > newList(@NotNull final T element)
Creates a new list containing one element.
MapView< G, A, R > mapView
The MapView to operate on.
void replaceOk()
Action method for Ok button.
void updateArchSelection(@Nullable final BaseObject< G, A, R, ?> newArch, final boolean alwaysPack)
Update which arch is displayed as replace object.
Interface for listener interested in ObjectChooser events.