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;
39 import javax.swing.event.ListSelectionEvent;
40 import javax.swing.event.ListSelectionListener;
50 import net.
sf.japi.swing.action.ActionBuilder;
51 import net.
sf.japi.swing.action.ActionBuilderFactory;
52 import net.
sf.japi.swing.action.ActionMethod;
53 import org.jetbrains.annotations.NotNull;
54 import org.jetbrains.annotations.Nullable;
62 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
68 private final JList<Plugin<G, A, R>>
scripts;
74 private final Container
scriptPanel =
new JPanel(scriptLayout);
103 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) {
108 frame.getContentPane().setLayout(
new BorderLayout());
109 final ListModel<Plugin<G, A, R>> listModel =
new AbstractListModel<Plugin<G, A, R>>() {
114 private static final long serialVersionUID = 1L;
138 public void pluginUnregistered(@NotNull
final Plugin<G, A, R> plugin) {
155 public int getSize() {
160 scripts =
new JList<>(listModel);
161 scripts.addListSelectionListener(
new ListSelectionListener() {
164 public void valueChanged(
final ListSelectionEvent e) {
165 if (!e.getValueIsAdjusting()) {
170 scripts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
171 scripts.setBorder(
new LineBorder(Color.black, 1));
172 scripts.setSelectedIndex(0);
174 final Container bottomLeft =
new JPanel(
new GridLayout(2, 1));
175 bottomLeft.add(
new JButton(ACTION_BUILDER.createAction(
false,
"pluginManagerNewScript",
this)));
176 bottomLeft.add(
new JButton(ACTION_BUILDER.createAction(
false,
"pluginManagerRemoveScript",
this)));
178 final Container left =
new JPanel(
new BorderLayout());
179 left.add(scripts, BorderLayout.CENTER);
180 left.add(bottomLeft, BorderLayout.SOUTH);
182 frame.getContentPane().add(left, BorderLayout.WEST);
183 frame.getContentPane().add(scriptPanel, BorderLayout.CENTER);
185 frame.setLocationRelativeTo(parent);
196 if (plugin == null) {
201 if (pluginEditor == null) {
203 components.put(plugin, pluginEditor);
204 scriptPanel.add(pluginEditor.
getComponent(), Integer.toString(pluginEditor.hashCode()));
206 scriptLayout.show(scriptPanel, Integer.toString(pluginEditor.hashCode()));
211 if (scriptEditor != null) {
212 components.remove(plugin);
221 frame.setVisible(
true);
229 final String name = JOptionPane.showInputDialog(scripts,
ActionBuilderUtils.
getString(ACTION_BUILDER,
"pluginManagerNewScriptTitle"));
235 if (plugin == null) {
238 JOptionPane.showMessageDialog(scripts, message, title, JOptionPane.WARNING_MESSAGE);
251 if (plugin == null) {
257 if (JOptionPane.showConfirmDialog(scripts, message, title, JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
262 scripts.setSelectedIndex(0);
Graphical User Interface of Gridarta.
final PluginController< G, A, R > pluginController
Plugin< G, A, R > getPlugin(@NotNull final String name)
void removePlugin(@NotNull final Plugin< G, A, R > plugin)
Listener interface for scripting related events.
final CardLayout scriptLayout
final PluginModel< G, A, R > pluginModel
final JList< Plugin< G, A, R > > scripts
Component getComponent()
Returns the Component for this plugin editor.
void pluginManagerNewScript()
Action method to create a new plugin script.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
String getName()
Returns the name of this plugin.
GameObjects are the objects based on Archetypes found on maps.
void showScript(@Nullable final Plugin< G, A, R > plugin)
final ResourceIcons resourceIcons
The ResourceIcons for creating icons.
void addPluginModelListener(@NotNull final PluginModelListener< G, A, R > listener)
Adds a listener to be informed of changes.
void pluginManagerRemoveScript()
Action method to remove the selected plugin script.
void show()
Shows the plugin manager window.
Utility class for ActionBuilder related functions.
final Map< Plugin< G, A, R >, PluginEditor< G, A, R > > components
Creates ImageIcon instances from resources.
Plugin< G, A, R > newPlugin(@NotNull final String name, @NotNull final String code)
void removeScript(@NotNull final Plugin< G, A, R > plugin)
static final ActionBuilder ACTION_BUILDER
Action Builder to create Actions.
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.
final PluginParameterViewFactory< G, A, R > pluginParameterViewFactory
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
Interface for MapArchObjects.