1 package me.felinewith.lang_toolkit.library;
2
3 import javax.swing.JButton;
4 import javax.swing.JInternalFrame;
5 import javax.swing.JPanel;
6 import javax.swing.JToolBar;
7 import org.apache.commons.configuration2.Configuration;
8 import org.apache.logging.log4j.LogManager;
9 import org.apache.logging.log4j.Logger;
10
11 /**
12 * Plug-in interface for a bootstrapped app.
13 * @author jlhawkwell
14 */
15 public abstract class IStrappedPlugin {
16
17 protected Logger log;
18 protected Configuration config;
19
20 protected JButton jButton;
21 protected JToolBar jToolBar;
22 protected JPanel jPanel;
23
24 public IStrappedPlugin() {}
25
26 /**
27 * Initializer for the plug-in. Must be overridden, there are three
28 * class variables in the plug-in which you may populate here if your
29 * plug-in should only have a single instance of each.
30 *
31 * The three local variables are:
32 * <ul>
33 * <li>{@link JButton} {@code jButton}</li>
34 * <li>{@link JToolBar} {@code jToolBar}</li>
35 * <li>{@link JInternalFrame} {@code jInternalFrame}</li>
36 * </ul>
37 */
38 public abstract void init();
39
40 /**
41 * First-time initializer for the plug-in.
42 * @param configuration Commons Configuration object for settings storage
43 */
44 public final void init(Configuration configuration) {
45 if ( configuration == null ) { throw new NullPointerException("Configuration object cannot be null!"); }
46 if ( config != null ) { return; }
47
48 config = configuration;
49 log = LogManager.getLogger();
50 }
51
52 /**
53 * The name of the plug-in. This is only used in referencing and will not be shown to the user.
54 * @return Name of plug-in.
55 */
56 public abstract String getName();
57
58 /**
59 * The display name of the plug-in. This is shown to the user.
60 * @return Display name of plug-in.
61 */
62 public abstract String getDisplayName();
63
64 /**
65 * Determines if the object has a {@link JButton}
66 * @return {@code true} if {@code jButton} is not {@code null}
67 */
68 public boolean hasButton() { return (jButton != null); }
69 /**
70 * Determines if the object has a {@link JToolBar}
71 * @return {@code true} if {@code jToolBar } is not {@code null}
72 */
73 public boolean hasToolBar() { return (jToolBar != null); }
74 /**
75 * Determines if the object has a {@link JPanel}
76 * @return {@code true} if {@code jPanel} is not {@code null}
77 */
78 public boolean hasWindow() { return (jPanel != null); }
79
80 /**
81 * By default, this provides the {@link JButton} created in the constructor.
82 * It may be overridden if a new {@link JButton} should be created on every call.
83 * @return The stored or created (if overridden) {@link JButton}
84 */
85 public JButton getButton() { return jButton; }
86 /**
87 * By default, this provides the {@link JToolBar} created in the constructor.
88 * It may be overridden if a new {@link JToolBar} should be created on every call.
89 * @return The stored or created (if overridden) {@link JToolBar}
90 */
91 public JToolBar getToolBar() { return jToolBar; }
92 /**
93 * By default, this provides the {@link JPanel} created in the constructor.
94 * It may be overridden if a new {@link JPanel} should be created on every call.
95 * @return The stored or created (if overridden) {@link JPanel}
96 */
97 public JPanel getPanel() { return jPanel; }
98
99 /**
100 * Allows you to receive events from your JButton.
101 */
102 public void getActionCommand(String command) {}
103 }