 |
Gridarta Editor
|
Go to the documentation of this file.
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());
240 parameterTab.add(parameterButtons, gbc);
243 gbc.fill = GridBagConstraints.BOTH;
244 parameterTab.add(
new JPanel(), gbc);
252 final RSyntaxTextArea code =
new RSyntaxTextArea();
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) {
264 public void insertUpdate(
final DocumentEvent e) {
269 public void removeUpdate(
final DocumentEvent e) {
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);
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);
338 if (existingRow !=
null) {
343 rows.put(parameter, row);
454 if (JOptionPane.showConfirmDialog(
panel, message, title, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
boolean isPluginIsEditorFilter()
Action method for option to make an editor script a map filter.
static final String RUN_PLUGIN_SMALL_ICON
final PluginParameterViewFactory< G, A, R > pluginParameterViewFactory
Component createCodePanel()
Component getValueComponent()
Returns the editor component for editing the parameter's value.
final FocusListener cellFocusListener
Component getParameterDescriptionEditor()
Returns the editor component for editing the parameter's description.
Base package of all Gridarta classes.
A set of components for editing a PluginParameter and its configuration.
void setScript(final boolean script)
Sets whether this plugin is a stand-alone plugin.
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)
Creates a visual JComponent used to edit the given script.
Component getComponent()
Returns the Component for this plugin editor.
int getParameter(@NotNull final String parameterName)
Returns the index for a plugin parameter name.
void newParameter()
Creates a new plugin parameter.
final JPanel parameterTable
static final String AUTO_RUN_SMALL_ICON
void pluginEditorReRegister()
Action method to re-register the current plugin.
void setCode(@NotNull final String code)
Sets the executable code of this plugin.
void pluginEditorExport()
Action method to export the current plugin as an XML file.
Reflects a game object (object on a map).
void pluginEditorAddParameter()
Action method to add a parameter to the current plugin script.
void addPluginListener(@NotNull final PluginListener listener)
Adds a PluginListener to be notified about changes.
boolean isPluginEditorIsAutoRun()
Action method for option to run the editor script automatically.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
Component getParameterTypeEditor()
Returns the editor component for editing the parameter's type.
Graphical User Interface of Gridarta.
Thrown if a parameter does not exist.
GameObjects are the objects based on Archetypes found on maps.
Component createParameterTab()
final Map< PluginParameter< G, A, R, ?>, PluginEditorRow > rows
A layoutManager which stacks components one on top of the other, regardless of their size.
void setPluginIsScript(final boolean script)
Action method for option to add the script to the plugins menu.
final MouseListener cellMouseListener
final PluginController< G, A, R > pluginController
The associated PluginController instance.
void reRegister(@NotNull final Plugin< G, A, R > plugin)
Component createOptionsTab(@NotNull final ResourceIcons resourceIcons)
Interface for MapArchObjects.
boolean isScript()
Returns whether this plugin is a stand-alone plugin.
void setAutoBoot(final boolean autoBoot)
Sets whether this plugin is run whenever the editor starts.
Component getConfigComponent()
Returns the editor component for editing the parameter's configuration parameters.
PluginEditorRow getOrCreateRow(@NotNull final PluginParameter< G, A, R, ?> parameter)
Returns the PluginEditorRow instance for a {}.
static final String FILTER_SMALL_ICON
void setPluginIsEditorFilter(final boolean filter)
Action method for option to run the editor script automatically.
String getName()
The name of the parameter.
static String format(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final Object... args)
Returns the value of a key.
boolean isFilter()
Returns whether this plugin is a filter.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Component getParameterNameEditor()
Returns the editor component for editing the parameter's name.
void setFilter(final boolean filter)
Sets whether this plugin is a filter.
void removeParameter(final int index)
Removes a plugin parameter.
final Plugin< G, A, R > plugin
Factory for creating PluginParameterView instances.
void pluginEditorRemoveParameter()
Action method to remove the selected parameter from the current plugin script.
final PluginModel< G, A, R > pluginModel
void setPluginEditorIsAutoRun(final boolean autoRun)
Action method for option to run the editor script automatically.
boolean savePluginAs(@NotNull final Plugin< G, A, R > plugin, final boolean updatePluginFile)
Prompts the user for a file name to save a plugin.
Utility class for ActionBuilder related functions.
boolean isAutoBoot()
Returns whether this plugin is run whenever the editor starts.
Creates ImageIcon instances from resources.
boolean isPluginIsScript()
Action method for option to add an editor script to the plugins menu.
static final ActionBuilder ACTION_BUILDER
Action Builder.
void pluginEditorRunScript()
Action method to execute the selected plugin script.
String getCode()
Returns the executable code of this plugin.
void runPlugin(@NotNull final Plugin< G, A, R > plugin)
void selectTableComponent(@NotNull final Component c)