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.Collection;
29 import java.util.Iterator;
30 import java.util.List;
31 import javax.swing.BorderFactory;
32 import javax.swing.Box;
33 import javax.swing.BoxLayout;
34 import javax.swing.Icon;
35 import javax.swing.JButton;
36 import javax.swing.JComboBox;
37 import javax.swing.JDialog;
38 import javax.swing.JLabel;
39 import javax.swing.JOptionPane;
40 import javax.swing.JPanel;
41 import javax.swing.JTextField;
42 import javax.swing.WindowConstants;
43 import javax.swing.text.JTextComponent;
63 import net.
sf.japi.swing.action.ActionBuilder;
64 import net.
sf.japi.swing.action.ActionBuilderFactory;
65 import net.
sf.japi.swing.action.ActionMethod;
66 import org.jetbrains.annotations.NotNull;
67 import org.jetbrains.annotations.Nullable;
85 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
216 public void pickmapActiveChanged(
final boolean pickmapActive) {
234 public void facesReloaded() {
249 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) {
253 dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
297 final JPanel mainPanel =
new JPanel();
298 mainPanel.setLayout(
new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
299 mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5));
302 final Container line1 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
304 line1.add(Box.createVerticalStrut(3));
309 line1.add(Box.createVerticalStrut(3));
312 mainPanel.add(line1);
315 final Container line2 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
317 line2.add(Box.createVerticalStrut(5));
323 line2.add(Box.createVerticalStrut(5));
328 mainPanel.add(line2);
331 final Container line3 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
333 line3.add(Box.createVerticalStrut(5));
352 line3.add(Box.createVerticalStrut(5));
355 mainPanel.add(line3);
358 final Container line4 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
360 line4.add(Box.createVerticalStrut(5));
365 mainPanel.add(line4);
367 final JButton okButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"replaceOk",
this));
368 final JButton applyButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"replaceApply",
this));
369 final JButton cancelButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"replaceCancel",
this));
371 setMessage(mainPanel);
372 setOptions(
new Object[] { okButton, applyButton, cancelButton });
373 dialog.getRootPane().setDefaultButton(okButton);
391 if (newArch ==
null) {
396 final Icon oldIcon =
iconLabel.getIcon();
399 rfArchName.setText(
" " + newArch.getBestName());
403 if (alwaysPack || (oldIcon ==
null &&
iconLabel.getIcon() !=
null) || (oldIcon !=
null &&
iconLabel.getIcon() ==
null) || (oldIcon !=
iconLabel.getIcon() && oldIcon !=
null && oldIcon.getIconHeight() !=
iconLabel.getIcon().getIconHeight())) {
421 @Nullable
final List<? extends BaseObject<G, A, R, ?>> replaceList;
439 final int replaceListSize = replaceList ==
null ? 0 : replaceList.size();
444 int replaceCount = 0;
445 final Collection<G> objectsToReplace =
new ArrayList<>();
450 objectsToReplace.clear();
451 for (
final G node : square) {
452 if (node.isHead() && matchCriteria.matches(node)) {
454 objectsToReplace.add(node);
460 for (
final G objectToReplace : objectsToReplace) {
461 final Iterator<G> it = square.iterator();
464 while (it.hasNext()) {
467 if (node == objectToReplace) {
478 if (replaceListSize > 0 && !deleteOnly) {
502 private static <T> List<T>
newList(@NotNull
final T element) {
503 final List<T> list =
new ArrayList<>(1);
516 if (e.getStateChange() == ItemEvent.SELECTED &&
lastSelectedIndex != selectedIndex) {
518 switch (selectedIndex) {
597 final int replaceDensity;
600 }
catch (
final NumberFormatException ignored) {
604 if (replaceDensity < 1 || replaceDensity > 100) {
609 final int replaceCount =
doReplace(matchCriteria, entireMap, deleteOnly, replaceDensity);
610 if (replaceCount <= 0) {
615 if (replaceCount == 1) {
618 ACTION_BUILDER.showMessageDialog(
this,
"replacedMany", replaceCount);