Skip to content

Commit

Permalink
Removed plugin support getInstance() and instead use Display.getPlugi…
Browse files Browse the repository at this point in the history
…nSupport() to obtain singleton reference.
  • Loading branch information
shannah committed Oct 30, 2023
1 parent e5b69be commit 8ab1b9e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 49 deletions.
21 changes: 0 additions & 21 deletions CodenameOne/src/com/codename1/plugin/PluginSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,6 @@
public class PluginSupport {
private final List<Plugin> plugins = new ArrayList<Plugin>();

private static PluginSupport instance;

private static final Object instanceLock = new Object();

/**
* Gets shared instance of PluginSupport class.
*
* @return Singleton instance
*/
public static PluginSupport getInstance() {
if (instance == null) {
synchronized (instanceLock){
if (instance == null) {
instance = new PluginSupport();
}
}
}

return instance;
}

/**
* Registers a plugin with the Codename One runtime.
* @param plugin The plugin to register.
Expand Down
31 changes: 4 additions & 27 deletions CodenameOne/src/com/codename1/ui/CN.java
Original file line number Diff line number Diff line change
Expand Up @@ -1629,34 +1629,11 @@ public static BrowserComponent getSharedJavascriptContext() {
}

/**
* Registers a plugin with the runtime so that specific functionality can be overridden by the plugin.
* @param plugin The plugin to register.
* Returns the plugin support object for the current platform. Use this object for registering plugins.
* @return The plugin support object.
* @since 8.0
* @see PluginSupport#registerPlugin(Plugin)
*/
public static void registerPlugin(Plugin plugin) {
PluginSupport.getInstance().registerPlugin(plugin);
public static PluginSupport getPluginSupport() {
return Display.INSTANCE.getPluginSupport();
}

/**
* Deregisters a plugin from the runtime.
* @param plugin The plugin to deregister
* @see PluginSupport#deregisterPlugin(Plugin)
* @since 8.0
*/
public static void deregisterPlugin(Plugin plugin) {
PluginSupport.getInstance().deregisterPlugin(plugin);
}

/**
* Fires a plugin event to all registered plugins to give them an opportunity to handle the event.
*
* @param event The event to fire.
* @see PluginSupport#firePluginEvent(PluginEvent)
* @since 8.0
*/
public static <T extends PluginEvent> T firePluginEvent(T event) {
return PluginSupport.getInstance().firePluginEvent(event);
}

}
11 changes: 10 additions & 1 deletion CodenameOne/src/com/codename1/ui/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ private Display() {
public static void init(Object m) {
if(!INSTANCE.codenameOneRunning) {
INSTANCE.codenameOneRunning = true;
INSTANCE.pluginSupport = PluginSupport.getInstance();
INSTANCE.pluginSupport = new PluginSupport();
INSTANCE.displayInitTime = System.currentTimeMillis();

//restore menu state from previous run if exists
Expand Down Expand Up @@ -613,6 +613,15 @@ public static Display getInstance(){
return INSTANCE;
}

/**
* Gets reference to plugin support object.
* @return The plugin support object.
* @since 8.0
*/
public PluginSupport getPluginSupport() {
return pluginSupport;
}

/**
* This method allows us to manipulate the drag started detection logic.
* If the pointer was dragged for more than this percentage of the display size it
Expand Down

0 comments on commit 8ab1b9e

Please sign in to comment.