Gridarta Editor
BooleanParameterView.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.dialog.plugin.parameter;
21 
22 import java.awt.Component;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import javax.swing.AbstractButton;
26 import javax.swing.JButton;
27 import javax.swing.JCheckBox;
28 import javax.swing.JComponent;
29 import javax.swing.JOptionPane;
34 import org.jetbrains.annotations.NotNull;
35 
39 public class BooleanParameterView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements PluginParameterView {
40 
44  @NotNull
45  private final AbstractButton value = new JCheckBox();
46 
50  @NotNull
51  private final AbstractButton config = new JButton("...");
52 
58  public BooleanParameterView(@NotNull final Component parent, @NotNull final BooleanParameter<G, A, R> parameter) {
59  value.addActionListener(new ActionListener() {
60 
61  @Override
62  public void actionPerformed(@NotNull final ActionEvent e) {
63  if (value.isSelected()) {
64  parameter.setValue(Boolean.TRUE);
65  value.setText(parameter.getTrueText());
66  } else {
67  parameter.setValue(Boolean.FALSE);
68  value.setText(parameter.getFalseText());
69  }
70  }
71 
72  });
73 
74  config.setBorderPainted(false);
75  config.addActionListener(new ActionListener() {
76 
77  @Override
78  public void actionPerformed(@NotNull final ActionEvent e) {
79  final String yes = JOptionPane.showInputDialog(parent, "Checked text", parameter.getTrueText());
80  if (yes == null) {
81  return;
82  }
83  parameter.setTrueText(yes);
84 
85  final String no = JOptionPane.showInputDialog(parent, "Unchecked text", parameter.getFalseText());
86  if (no == null) {
87  return;
88  }
89  parameter.setFalseText(no);
90  }
91 
92  });
93  }
94 
95  @NotNull
96  @Override
97  public JComponent getConfigComponent() {
98  return config;
99  }
100 
101  @NotNull
102  @Override
103  public JComponent getValueComponent() {
104  return value;
105  }
106 
107 }
Interface for views that display plugin parameters.
final AbstractButton config
The component for editing the parameter&#39;s configuration.
Base package of all Gridarta classes.
A PluginParameter that holds a boolean value.
Reflects a game object (object on a map).
Definition: GameObject.java:36
BooleanParameterView(@NotNull final Component parent, @NotNull final BooleanParameter< G, A, R > parameter)
Creates a new instance.
GameObjects are the objects based on Archetypes found on maps.
final AbstractButton value
The component for editing the parameter&#39;s value.
JComponent getConfigComponent()
Returns a JComponent for editing the parameter configuration.
JComponent getValueComponent()
Returns a JComponent for editing the parameter value.