 |
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.CardLayout;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Container;
27 import java.awt.GridLayout;
28 import java.util.HashMap;
30 import javax.swing.AbstractListModel;
31 import javax.swing.JButton;
32 import javax.swing.JFrame;
33 import javax.swing.JList;
34 import javax.swing.JOptionPane;
35 import javax.swing.JPanel;
36 import javax.swing.ListModel;
37 import javax.swing.ListSelectionModel;
38 import javax.swing.border.LineBorder;
48 import net.
sf.japi.swing.action.ActionBuilder;
49 import net.
sf.japi.swing.action.ActionBuilderFactory;
50 import net.
sf.japi.swing.action.ActionMethod;
51 import org.jetbrains.annotations.NotNull;
52 import org.jetbrains.annotations.Nullable;
60 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
66 private final JList<Plugin<G, A, R>>
scripts;
101 public PluginManager(@NotNull
final Component parent, @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) {
106 frame.getContentPane().setLayout(
new BorderLayout());
107 final ListModel<Plugin<G, A, R>> listModel =
new AbstractListModel<Plugin<G, A, R>>() {
112 private static final long serialVersionUID = 1L;
136 public void pluginUnregistered(@NotNull
final Plugin<G, A, R> plugin) {
153 public int getSize() {
158 scripts =
new JList<>(listModel);
159 scripts.addListSelectionListener(e -> {
160 if (!e.getValueIsAdjusting()) {
161 showScript(scripts.getSelectedValue());
164 scripts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
165 scripts.setBorder(
new LineBorder(Color.black, 1));
168 final Container bottomLeft =
new JPanel(
new GridLayout(2, 1));
169 bottomLeft.add(
new JButton(
ACTION_BUILDER.createAction(
false,
"pluginManagerNewScript",
this)));
170 bottomLeft.add(
new JButton(
ACTION_BUILDER.createAction(
false,
"pluginManagerRemoveScript",
this)));
172 final Container left =
new JPanel(
new BorderLayout());
173 left.add(
scripts, BorderLayout.CENTER);
174 left.add(bottomLeft, BorderLayout.SOUTH);
176 frame.getContentPane().add(left, BorderLayout.WEST);
179 frame.setLocationRelativeTo(parent);
190 if (plugin ==
null) {
195 if (pluginEditor ==
null) {
205 if (scriptEditor !=
null) {
215 frame.setVisible(
true);
229 if (plugin ==
null) {
232 JOptionPane.showMessageDialog(
scripts, message, title, JOptionPane.WARNING_MESSAGE);
245 if (plugin ==
null) {
251 if (JOptionPane.showConfirmDialog(
scripts, message, title, JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
final PluginController< G, A, R > pluginController
Plugin< G, A, R > newPlugin(@NotNull final String name, @NotNull final String code)
Base package of all Gridarta classes.
void addPluginModelListener(@NotNull final PluginModelListener< G, A, R > listener)
Adds a listener to be informed of changes.
void removePlugin(@NotNull final Plugin< G, A, R > plugin)
Listener interface for scripting related events.
String getName()
Returns the name of this plugin.
Component getComponent()
Returns the Component for this plugin editor.
final PluginModel< G, A, R > pluginModel
final JList< Plugin< G, A, R > > scripts
Reflects a game object (object on a map).
void pluginManagerNewScript()
Action method to create a new plugin script.
final CardLayout scriptLayout
Graphical User Interface of Gridarta.
GameObjects are the objects based on Archetypes found on maps.
final ResourceIcons resourceIcons
The ResourceIcons for creating icons.
Interface for MapArchObjects.
Plugin< G, A, R > getPlugin(@NotNull final String name)
void showScript(@Nullable final Plugin< G, A, R > plugin)
static String format(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final Object... args)
Returns the value of a key.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
void pluginManagerRemoveScript()
Action method to remove the selected plugin script.
final Map< Plugin< G, A, R >, PluginEditor< G, A, R > > components
Factory for creating PluginParameterView instances.
void show()
Shows the plugin manager window.
void removeScript(@NotNull final Plugin< G, A, R > plugin)
Utility class for ActionBuilder related functions.
final PluginParameterViewFactory< G, A, R > pluginParameterViewFactory
Creates ImageIcon instances from resources.
static final ActionBuilder ACTION_BUILDER
Action Builder to create Actions.
PluginManager(@NotNull final Component parent, @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 PluginManager.
final Container scriptPanel