20 package net.sf.gridarta.gui.dialog.plugin;
22 import java.awt.BorderLayout;
23 import java.awt.Component;
24 import java.awt.Container;
25 import java.awt.FlowLayout;
27 import java.awt.GridBagConstraints;
28 import java.awt.GridBagLayout;
29 import java.awt.Insets;
30 import java.awt.event.FocusEvent;
31 import java.awt.event.FocusListener;
32 import java.awt.event.MouseEvent;
33 import java.awt.event.MouseListener;
34 import java.util.IdentityHashMap;
36 import javax.swing.JButton;
37 import javax.swing.JCheckBox;
38 import javax.swing.JLabel;
39 import javax.swing.JOptionPane;
40 import javax.swing.JPanel;
41 import javax.swing.JScrollPane;
42 import javax.swing.JTabbedPane;
43 import javax.swing.SwingConstants;
44 import javax.swing.event.DocumentEvent;
45 import javax.swing.event.DocumentListener;
56 import net.
sf.japi.swing.action.ActionBuilder;
57 import net.
sf.japi.swing.action.ActionBuilderFactory;
58 import net.
sf.japi.swing.action.ActionMethod;
59 import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
60 import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
61 import org.fife.ui.rtextarea.RTextScrollPane;
62 import org.jetbrains.annotations.NotNull;
70 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
79 private final Container
panel =
new JPanel(
new BorderLayout());
102 public void mouseClicked(@NotNull
final MouseEvent e) {
107 public void mouseEntered(@NotNull
final MouseEvent e) {
111 public void mouseExited(@NotNull
final MouseEvent e) {
115 public void mousePressed(@NotNull
final MouseEvent e) {
120 public void mouseReleased(@NotNull
final MouseEvent e) {
129 public void focusGained(@NotNull
final FocusEvent e) {
134 public void focusLost(@NotNull
final FocusEvent e) {
144 public PluginEditor(@NotNull
final Plugin<G, A, R> plugin, @NotNull
final PluginController<G, A, R> pluginController, @NotNull
final PluginModel<G, A, R> pluginModel, @NotNull
final PluginParameterViewFactory<G, A, R> pluginParameterViewFactory, @NotNull
final ResourceIcons resourceIcons) {
150 final JTabbedPane tabs =
new JTabbedPane();
159 final Container optionsTab =
new JPanel(
new GridBagLayout());
160 final GridBagConstraints gbc =
new GridBagConstraints();
162 final Container parameterButtons =
new JPanel();
164 parameterButtons.add(
new JButton(ACTION_BUILDER.createAction(
false,
"pluginEditorReRegister",
this)));
165 parameterButtons.add(
new JButton(ACTION_BUILDER.createAction(
false,
"pluginEditorExport",
this)));
167 gbc.fill = GridBagConstraints.HORIZONTAL;
172 gbc.anchor = GridBagConstraints.CENTER;
178 gbc.anchor = GridBagConstraints.CENTER;
190 gbc.anchor = GridBagConstraints.WEST;
193 optionsTab.add(
new JCheckBox(ACTION_BUILDER.createToggle(
false,
"pluginEditorIsAutoRun",
this)), gbc);
195 optionsTab.add(
new JCheckBox(ACTION_BUILDER.createToggle(
false,
"pluginEditorIsFilter",
this)), gbc);
197 optionsTab.add(
new JCheckBox(ACTION_BUILDER.createToggle(
false,
"pluginEditorIsScript",
this)), gbc);
202 gbc.anchor = GridBagConstraints.WEST;
203 gbc.fill = GridBagConstraints.NONE;
206 optionsTab.add(parameterButtons, gbc);
213 gbc.fill = GridBagConstraints.BOTH;
214 optionsTab.add(
new JPanel(), gbc);
223 final Container parameterButtons =
new JPanel();
225 parameterButtons.add(
new JButton(ACTION_BUILDER.createAction(
false,
"pluginEditorAddParameter",
this)));
226 parameterButtons.add(
new JButton(ACTION_BUILDER.createAction(
false,
"pluginEditorRemoveParameter",
this)));
228 final GridBagConstraints gbc =
new GridBagConstraints();
234 gbc.fill = GridBagConstraints.HORIZONTAL;
235 gbc.anchor = GridBagConstraints.WEST;
237 final Container parameterTab =
new JPanel(
new GridBagLayout());
238 parameterTab.add(
new JScrollPane(parameterTable), gbc);
240 parameterTab.add(parameterButtons, gbc);
243 gbc.fill = GridBagConstraints.BOTH;
244 parameterTab.add(
new JPanel(), gbc);
252 final RSyntaxTextArea code =
new RSyntaxTextArea();
253 code.setText(plugin.
getCode());
254 code.setCaretPosition(0);
255 code.setFont(
new Font(
"Monospaced", Font.PLAIN, 14));
256 code.getDocument().addDocumentListener(
new DocumentListener() {
259 public void changedUpdate(
final DocumentEvent e) {
260 plugin.
setCode(code.getText());
264 public void insertUpdate(
final DocumentEvent e) {
265 plugin.
setCode(code.getText());
269 public void removeUpdate(
final DocumentEvent e) {
270 plugin.
setCode(code.getText());
273 code.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
275 return new RTextScrollPane(code);
280 final Container codeBottom =
new JPanel(
new FlowLayout());
281 codeBottom.add(
new JButton(ACTION_BUILDER.createAction(
false,
"pluginEditorRunScript",
this)));
283 final Container codePanel =
new JPanel(
new BorderLayout());
284 codePanel.add(
createCode(), BorderLayout.CENTER);
285 codePanel.add(codeBottom, BorderLayout.SOUTH);
291 final GridBagLayout l = (GridBagLayout) parameterTable.getLayout();
292 final GridBagConstraints gbc = l.getConstraints(c);
294 selectedRow = gbc.gridy - 1;
299 final GridBagConstraints gbc =
new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 5, 0);
300 parameterTable.removeAll();
338 if (existingRow != null) {
343 rows.put(parameter, row);
441 if (selectedRow < 0) {
451 final String name = parameter.
getName();
453 final String message =
ActionBuilderUtils.
format(ACTION_BUILDER,
"pluginEditorRemoveParameterConfirm.message", name);
454 if (JOptionPane.showConfirmDialog(panel, message, title, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
void pluginEditorRunScript()
Action method to execute the selected plugin script.
boolean isPluginIsScript()
Action method for option to add an editor script to the plugins menu.
static final ActionBuilder ACTION_BUILDER
Action Builder.
Component getParameterDescriptionEditor()
Returns the editor component for editing the parameter's description.
final JPanel parameterTable
void selectTableComponent(@NotNull final Component c)
Graphical User Interface of Gridarta.
final PluginParameterViewFactory< G, A, R > pluginParameterViewFactory
boolean isScript()
Returns whether this plugin is a stand-alone plugin.
Component getParameterTypeEditor()
Returns the editor component for editing the parameter's type.
Component createCodePanel()
void setScript(final boolean script)
Sets whether this plugin is a stand-alone plugin.
void setAutoBoot(final boolean autoBoot)
Sets whether this plugin is run whenever the editor starts.
boolean isAutoBoot()
Returns whether this plugin is run whenever the editor starts.
void pluginEditorExport()
Action method to export the current plugin as an XML file.
boolean isFilter()
Returns whether this plugin is a filter.
int getParameter(@NotNull final String parameterName)
Returns the index for a plugin parameter name.
final FocusListener cellFocusListener
void setPluginIsScript(final boolean script)
Action method for option to add the script to the plugins menu.
Component getComponent()
Returns the Component for this plugin editor.
Component createOptionsTab(@NotNull final ResourceIcons resourceIcons)
final PluginController< G, A, R > pluginController
The associated PluginController instance.
void pluginEditorAddParameter()
Action method to add a parameter to the current plugin script.
static final String RUN_PLUGIN_SMALL_ICON
final MouseListener cellMouseListener
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
boolean isPluginEditorIsAutoRun()
Action method for option to run the editor script automatically.
PluginEditorRow getOrCreateRow(@NotNull final PluginParameter< G, A, R, ?> parameter)
Returns the PluginEditorRow instance for a PluginParameter.
Base package of all Gridarta classes.
final Map< PluginParameter< G, A, R, ?>, PluginEditorRow > rows
Reflects a game object (object on a map).
void pluginEditorReRegister()
Action method to re-register the current plugin.
void setPluginIsEditorFilter(final boolean filter)
Action method for option to run the editor script automatically.
GameObjects are the objects based on Archetypes found on maps.
final PluginModel< G, A, R > pluginModel
Component createParameterTab()
String getCode()
Returns the executable code of this plugin.
Thrown if a parameter does not exist.
A layoutManager which stacks components one on top of the other, regardless of their size...
void newParameter()
Creates a new plugin parameter.
Component getConfigComponent()
Returns the editor component for editing the parameter's configuration parameters.
Utility class for ActionBuilder related functions.
A set of components for editing a PluginParameter and its configuration.
final Plugin< G, A, R > plugin
Component getParameterNameEditor()
Returns the editor component for editing the parameter's name.
Component getValueComponent()
Returns the editor component for editing the parameter's value.
void runPlugin(@NotNull final Plugin< G, A, R > plugin)
Creates ImageIcon instances from resources.
void pluginEditorRemoveParameter()
Action method to remove the selected parameter from the current plugin script.
String getName()
The name of the parameter.
static final String AUTO_RUN_SMALL_ICON
void reRegister(@NotNull final Plugin< G, A, R > plugin)
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
void setPluginEditorIsAutoRun(final boolean autoRun)
Action method for option to run the editor script automatically.
static String format(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final Object... args)
Returns the value of a key.
Factory for creating PluginParameterView instances.
boolean savePluginAs(@NotNull final Plugin< G, A, R > plugin, final boolean updatePluginFile)
Prompts the user for a file name to save a plugin.
void setFilter(final boolean filter)
Sets whether this plugin is a filter.
boolean isPluginIsEditorFilter()
Action method for option to make an editor script a map filter.
void setCode(@NotNull final String code)
Sets the executable code of this plugin.
Interface for MapArchObjects.
PluginEditor(@NotNull final Plugin< G, A, R > plugin, @NotNull final PluginController< G, A, R > pluginController, @NotNull final PluginModel< G, A, R > pluginModel, @NotNull final PluginParameterViewFactory< G, A, R > pluginParameterViewFactory, @NotNull final ResourceIcons resourceIcons)
Create a visual JComponent used to edit the given script.
static final String FILTER_SMALL_ICON
void addPluginListener(@NotNull final PluginListener listener)
Adds a PluginListener to be notified about changes.
void removeParameter(final int index)
Removes a plugin parameter.