Huge refactoring of codebase to support latest version of Java PureMVC (v2.2)

This commit is contained in:
fgnm
2020-09-01 15:08:17 +02:00
parent b22a3f0bba
commit fe8b376008
153 changed files with 2935 additions and 3182 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,80 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.core;
import com.puremvc.patterns.command.Command;
import com.puremvc.patterns.observer.Notification;
/**
* The interface definition for a PureMVC Controller.
* <p>
* <p>
* In PureMVC, an <code>IController</code> implementor follows the 'Command
* and Controller' strategy, and assumes these responsibilities:
* <UL>
* <LI> Remembering which <code>ICommand</code>s are intended to handle which
* <code>INotifications</code>.</LI>
* <LI> Registering itself as an <code>IObserver</code> with the
* <code>View</code> for each <code>INotification</code> that it has an
* <code>ICommand</code> mapping for.</LI>
* <LI> Creating a new instance of the proper <code>ICommand</code> to handle
* a given <code>INotification</code> when notified by the <code>View</code>.</LI>
* <LI> Calling the <code>ICommand</code>'s <code>execute</code> method,
* passing in the <code>INotification</code>.</LI>
* </UL>
*
* @see com.puremvc.patterns.observer Notification
* @see com.puremvc.patterns.command Command
*/
public interface Controller {
/**
* Register a particular <code>ICommand</code> class as the handler for a
* particular <code>INotification</code>.
*
* @param notificationName the name of the <code>INotification</code>
* @param command the Class of the <code>ICommand</code>
*/
void registerCommand(String notificationName, Class<? extends Command> command);
/**
* Execute the <code>ICommand</code> previously registered as the handler
* for <code>INotification</code>s with the given notification name.
*
* @param notification the <code>INotification</code> to execute the associated
* <code>ICommand</code> for
*/
void executeCommand(Notification notification);
/**
* Remove a previously registered <code>ICommand</code> to
* <code>INotification</code> mapping.
*
* @param notificationName the name of the <code>INotification</code> to remove the
* <code>ICommand</code> mapping for
*/
void removeCommand(String notificationName);
/**
* Check if a Command is registered for a given Notification
*
* @param notificationName
* @return whether a Command is currently registered for the given <code>notificationName</code>.
*/
boolean hasCommand(String notificationName);
}
@@ -1,200 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.core;
import java.util.HashMap;
import java.util.Map;
import com.puremvc.patterns.command.Command;
import com.puremvc.patterns.observer.BaseObserver;
import com.puremvc.patterns.observer.Notification;
/**
* A Singleton <code>Controller</code> implementation.
* <p>
* <p>
* In PureMVC, the <code>Controller</code> class follows the
* 'Command and Controller' strategy, and assumes these
* responsibilities:
* <UL>
* <LI> Remembering which <code>ICommand</code>s
* are intended to handle which <code>INotifications</code>.</LI>
* <LI> Registering itself as an <code>IObserver</code> with
* the <code>View</code> for each <code>INotification</code>
* that it has an <code>ICommand</code> mapping for.</LI>
* <LI> Creating a new instance of the proper <code>ICommand</code>
* to handle a given <code>INotification</code> when notified by the <code>View</code>.</LI>
* <LI> Calling the <code>ICommand</code>'s <code>execute</code>
* method, passing in the <code>INotification</code>.</LI>
* </UL>
* <p>
* <p>
* Your application must register <code>ICommands</code> with the
* Controller.
* <p>
* The simplest way is to subclass </code>Facade</code>,
* and use its <code>initializeController</code> method to add your
* registrations.
*
* @see CoreView View
* @see BaseObserver Observer
* @see com.puremvc.patterns.observer.Notification Notification
* @see com.puremvc.patterns.command.SimpleCommand SimpleCommand
* @see com.puremvc.patterns.command.MacroCommand MacroCommand
*/
public class CoreController implements Controller {
/**
* Reference to the singleton instance
*/
protected static CoreController instance;
/**
* Mapping of Notification names to Command Class references
*/
protected Map<String, Class<? extends Command>> commandMap;
/**
* Local reference to View
*/
protected CoreView view;
/**
* Constructor.
* <p>
* <p>
* This <code>IController</code> implementation is a Singleton, so you
* should not call the constructor directly, but instead call the static
* Singleton Factory method <code>Controller.getInstance()</code>
*/
protected CoreController() {
instance = this;
commandMap = new HashMap<>();
initializeController();
}
/**
* <code>Controller</code> Singleton Factory method.
*
* @return the Singleton instance of <code>Controller</code>
*/
public synchronized static CoreController getInstance() {
if (instance == null) {
instance = new CoreController();
}
return instance;
}
/**
* Initialize the Singleton <code>Controller</code> instance.
* <p>
* <P>Called automatically by the constructor.</P>
* <p>
* <P>Note that if you are using a subclass of <code>View</code>
* in your application, you should <i>also</i> subclass <code>Controller</code>
* and override the <code>initializeController</code> method in the
* following way:</P>
* <p>
* <listing>
* // ensure that the Controller is talking to my IView implementation
* override public function initializeController( ) : void
* {
* view = MyView.getInstance();
* }
* </listing>
*/
protected void initializeController() {
view = CoreView.getInstance();
}
/**
* If an <code>ICommand</code> has previously been registered to handle a
* the given <code>INotification</code>, then it is executed.
*
* @param note The notification to send associated with the command to call.
*/
public void executeCommand(Notification note) {
//No reflexion in GWT
Class<? extends Command> commandClass = commandMap.get(note.getName());
if (commandClass != null) {
Command command;
try {
command = commandClass.newInstance();
command.execute(note);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
/**
* Register a particular <code>ICommand</code> class as the handler for a
* particular <code>INotification</code>.
* <p>
* <p>
* If an <code>ICommand</code> has already been registered to handle
* <code>INotification</code>s with this name, it is no longer used, the
* new <code>ICommand</code> is used instead.
* </P>
* <p>
* The Observer for the new ICommand is only created if this the
* first time an ICommand has been regisered for this Notification name.
*
* @param notificationName the name of the <code>Notification</code>
* @param command an instance of <code>Command</code>
*/
public void registerCommand(String notificationName, Class<? extends Command> command) {
if (null != commandMap.put(notificationName, command)) {
return;
}
view.registerObserver
(
notificationName,
new BaseObserver(this::executeCommand, this)
);
}
/**
* Remove a previously registered <code>ICommand</code> to
* <code>INotification</code> mapping.
*
* @param notificationName the name of the <code>INotification</code> to remove the
* <code>ICommand</code> mapping for
*/
public void removeCommand(String notificationName) {
// if the Command is registered...
if (hasCommand(notificationName)) {
// remove the observer
view.removeObserver(notificationName, this);
commandMap.remove(notificationName);
}
}
/**
* Check if a Command is registered for a given Notification
*
* @param notificationName The name of the command to check for existance.
* @return whether a Command is currently registered for the given <code>notificationName</code>.
*/
public boolean hasCommand(String notificationName) {
return commandMap.containsKey(notificationName);
}
}
@@ -1,153 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.core;
import java.util.HashMap;
import java.util.Map;
import com.puremvc.patterns.proxy.Proxy;
/**
* A Singleton <code>IModel</code> implementation.
* <p>
* <P>
* In PureMVC, the <code>Model</code> class provides
* access to model objects (Proxies) by named lookup.
* <p>
* <P>
* The <code>Model</code> assumes these responsibilities:</P>
* <p>
* <UL>
* <LI>Maintain a cache of <code>IProxy</code> instances.</LI>
* <LI>Provide methods for registering, retrieving, and removing
* <code>IProxy</code> instances.</LI>
* </UL>
* <p>
* <P>
* Your application must register <code>IProxy</code> instances
* with the <code>Model</code>. Typically, you use an
* <code>ICommand</code> to create and register <code>IProxy</code>
* instances once the <code>Facade</code> has initialized the Core
* actors.</p>
*
* @see com.puremvc.patterns.proxy.BaseProxy BaseProxy
* @see com.puremvc.patterns.proxy.Proxy Proxy
*/
public class CoreModel implements Model {
/**
* Singleton instance
*/
protected static CoreModel instance;
/**
* Mapping of proxyNames to IProxy instances
*/
protected Map<String, Proxy> proxyMap;
/**
* Constructor.
* <p>
* <p>
* This <code>IModel</code> implementation is a Multiton,
* so you should not call the constructor
* directly, but instead call the static Multiton
* Factory method <code>Model.getInstance( multitonKey )</code>
*
* @throws Error Error if instance for this Multiton key instance has already been constructed
*/
protected CoreModel() {
instance = this;
proxyMap = new HashMap<>();
initializeModel();
}
/**
* <code>Model</code> Multiton Factory method.
*
* @return the instance for this Multiton key
*/
public synchronized static CoreModel getInstance() {
if (instance == null) {
instance = new CoreModel();
}
return instance;
}
/**
* Initialize the Singleton <code>Model</code> instance.
* <p>
* <p>
* Called automatically by the constructor, this is your opportunity to
* initialize the Singleton instance in your subclass without overriding the
* constructor.
* </P>
*/
protected void initializeModel() {
}
/**
* Register an <code>Proxy</code> with the <code>Model</code>.
*
* @param proxy an <code>Proxy</code> to be held by the <code>Model</code>.
*/
public void registerProxy(Proxy proxy) {
proxyMap.put(proxy.getProxyName(), proxy);
proxy.onRegister();
}
/**
* Remove an <code>Proxy</code> from the <code>Model</code>.
*
* @param proxyName Name of the <code>Proxy</code> instance to be removed.
* @return The <code>IProxy</code> that was removed from the <code>Model</code>
*/
public Proxy removeProxy(String proxyName) {
Proxy proxy = proxyMap.get(proxyName);
if (proxy != null) {
proxyMap.remove(proxyName);
proxy.onRemove();
}
return proxy;
}
/**
* Retrieve an <code>Proxy</code> from the <code>Model</code>.
*
* @param proxy
* @return the <code>Proxy</code> instance previously registered with the
* given <code>proxyName</code>.
*/
public <T extends Proxy> T retrieveProxy(String proxy) {
return (T) proxyMap.get(proxy);
}
/**
* Check if a Proxy is registered
*
* @param proxyName Name of the <code>Proxy</code> object to check for existance.
* @return Whether a Proxy is currently registered with the given <code>proxyName</code>.
*/
public boolean hasProxy(String proxyName) {
return proxyMap.containsKey(proxyName);
}
}
@@ -1,271 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.core;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.puremvc.patterns.mediator.Mediator;
import com.puremvc.patterns.observer.BaseObserver;
import com.puremvc.patterns.observer.Notification;
import com.puremvc.patterns.observer.Observer;
/**
* A Singleton <code>IView</code> implementation.
* <p>
* <p>
* In PureMVC, the <code>View</code> class assumes these responsibilities:
* <UL>
* <LI>Maintain a cache of <code>IMediator</code> instances.</LI>
* <LI>Provide methods for registering, retrieving, and removing
* <code>IMediators</code>.</LI>
* <LI>Managing the observer lists for each <code>INotification</code> in the
* application.</LI>
* <LI>Providing a method for attaching <code>IObservers</code> to an
* <code>INotification</code>'s observer list.</LI>
* <LI>Providing a method for broadcasting an <code>INotification</code>.</LI>
* <LI>Notifying the <code>IObservers</code> of a given
* <code>INotification</code> when it broadcast.</LI>
* </UL>
*
* @see com.puremvc.patterns.mediator.Mediator Mediator
* @see com.puremvc.patterns.observer.Observer Observer
* @see com.puremvc.patterns.observer.Notification Notification
*/
public class CoreView implements View {
// Singleton instance
private static CoreView instance;
// Mapping of Mediator names to Mediator instances
// Mapping of Notification names to Observer lists
private HashMap<String, List<Observer>> observerMap;
private HashMap<String, Mediator> mediatorMap;
/**
* Constructor.
* <p>
* <p>
* This <code>IView</code> implementation is a Singleton, so you should
* not call the constructor directly, but instead call the static Singleton
* Factory method <code>View.getInstance()</code>
*
* @throws Error Error if Singleton instance has already been constructed
*/
protected CoreView() {
instance = this;
this.mediatorMap = new HashMap<>();
this.observerMap = new HashMap<>();
initializeView();
}
/**
* View Singleton Factory method.
*
* @return The Singleton instance of <code>View</code>
*/
public synchronized static CoreView getInstance() {
if (instance == null)
instance = new CoreView();
return instance;
}
/**
* Initialize the Singleton View instance.
* <p>
* <p>
* Called automatically by the constructor, this is your opportunity to
* initialize the Singleton instance in your subclass without overriding
* the constructor.
* </P>
*/
protected void initializeView() {
}
/**
* Notify the <code>Observers</code> for a particular
* <code>Notification</code>.
* <p>
* <p>
* All previously attached <code>Observers</code> for this
* <code>Notification</code>'s list are notified and are passed a
* reference to the <code>Notification</code> in the order in which they
* were registered.
* </P>
*
* @param note the <code>Notification</code> to notify
* <code>Observers</code> of.
*/
public void notifyObservers(Notification note) {
List<Observer> observerList = observerMap.get(note.getName());
if (observerList != null) {
// Copy observers from reference array to working array,
// since the reference array may change during the
//notification loop
Observer[] observers = observerList.toArray(new Observer[observerList.size()]);
// Notify Observers from the working array
for (Observer observer : observers) {
observer.notifyObserver(note);
}
}
}
/**
* Remove the observer for a given notifyContext from an observer list for a given Notification name.
*
* @param notificationName Which observer list to remove from
* @param notifyContext Remove the observer with this object as its notifyContext
*/
public void removeObserver(String notificationName, Object notifyContext) {
// the observer list for the notification under inspection
List<Observer> observers = observerMap.get(notificationName);
if (observers != null) {
// find the observer for the notifyContext
for (int i = 0; i < observers.size(); i++) {
BaseObserver observer = (BaseObserver) observers.get(i);
if (observer.compareNotifyContext(notifyContext)) {
observers.remove(observer);
}
}
// Also, when a Notification's Observer list length falls to
// zero, delete the notification key from the observer map
if (observers.size() == 0) {
observerMap.remove(notificationName);
}
}
}
/**
* Register an <code>Mediator</code> instance with the <code>View</code>.
* <p>
* <P>
* Registers the <code>Mediator</code> so that it can be retrieved by
* name, and further interrogates the <code>Mediator</code> for its
* <code>Notification</code> interests.
* </P>
* <P>
* If the <code>Mediator</code> returns any <code>Notification</code>
* names to be notified about, an <code>Observer</code> is created
* encapsulating the <code>Mediator</code> instance's
* <code>handleNotification</code> method and registering it as an
* <code>Observer</code> for all <code>Notifications</code> the
* <code>Mediator</code> is interested in.
* </p>
*
* @param mediator the name to associate with this <code>IMediator</code>
* instance
*/
public void registerMediator(final Mediator mediator) {
if (mediatorMap.containsKey(mediator.getMediatorName())) {
return;
}
// Register the Mediator for retrieval by name
mediatorMap.put(mediator.getMediatorName(), mediator);
// Get Notification interests, if any.
String[] noteInterests = mediator.listNotificationInterests();
if (noteInterests.length != 0) {
// Create Observer
BaseObserver observer = new BaseObserver(mediator::handleNotification, mediator);
// Register Mediator as Observer for its list of Notification
// interests
for (String noteInterest : noteInterests) {
registerObserver(noteInterest, observer);
}
}
// alert the mediator that it has been registered
mediator.onRegister();
}
/**
* Register an <code>Observer</code> to be notified of
* <code>INotifications</code> with a given name.
*
* @param notificationName the name of the <code>Notifications</code> to notify this
* <code>Observer</code> of
* @param observer the <code>Observer</code> to register
*/
public void registerObserver(String notificationName, Observer observer) {
if (observerMap.get(notificationName) == null) {
observerMap.put(notificationName, new ArrayList<>());
}
List<Observer> observers = observerMap.get(notificationName);
observers.add(observer);
}
/**
* Remove an <code>Mediator</code> from the <code>View</code>.
*
* @param mediatorName name of the <code>Mediator</code> instance to be removed.
*/
public Mediator removeMediator(String mediatorName) {
// Retrieve the named mediator
Mediator mediator = mediatorMap.get(mediatorName);
if (mediator != null) {
// for every notification this mediator is interested in...
String[] interests = mediator.listNotificationInterests();
for (String interest : interests) {
// remove the observer linking the mediator
// to the notification interest
removeObserver(interest, mediator);
}
// remove the mediator from the map
mediatorMap.remove(mediatorName);
// alert the mediator that it has been removed
mediator.onRemove();
}
return mediator;
}
/**
* Retrieve an <code>Mediator</code> from the <code>View</code>.
*
* @param mediatorName the name of the <code>Mediator</code> instance to
* retrieve.
* @return the <code>Mediator</code> instance previously registered with
* the given <code>mediatorName</code>.
*/
public <T extends Mediator> T retrieveMediator(String mediatorName) {
return (T) mediatorMap.get(mediatorName);
}
/**
* Check if a Mediator is registered or not
*
* @param mediatorName
* @return whether a Mediator is registered with the given <code>mediatorName</code>.
*/
public boolean hasMediator(String mediatorName) {
return mediatorMap.containsKey(mediatorName);
}
}
@@ -1,72 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.core;
import com.puremvc.patterns.proxy.Proxy;
/**
* The interface definition for a PureMVC Model.
* <p>
* <p>
* In PureMVC, <code>Model</code> implementors provide access to
* <code>Proxy</code> objects by named lookup.
* </P>
* <p>
* <p>
* An <code>Model</code> assumes these responsibilities:
* </P>
* <p>
* <UL>
* <LI>Maintain a cache of <code>Proxy</code> instances</LI>
* <LI>Provide methods for registering, retrieving, and removing
* <code>Proxy</code> instances</LI>
* </UL>
*/
public interface Model {
/**
* Register an <code>Proxy</code> instance with the <code>Model</code>.
*
* @param proxy an object reference to be held by the <code>Model</code>.
*/
void registerProxy(Proxy proxy);
/**
* Retrieve an <code>Proxy</code> instance from the Model.
*
* @param proxy
* @return the <code>Proxy</code> instance previously registered with the
* given <code>proxyName</code>.
*/
<T extends Proxy> T retrieveProxy(String proxy);
/**
* Remove an <code>Proxy</code> instance from the Model.
*
* @param proxy name of the <code>Proxy</code> instance to be removed.
*/
Proxy removeProxy(String proxy);
/**
* Check if a Proxy is registered
*
* @param proxyName
* @return whether a Proxy is currently registered with the given <code>proxyName</code>.
*/
boolean hasProxy(String proxyName);
}
@@ -1,122 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.core;
import com.puremvc.patterns.mediator.Mediator;
import com.puremvc.patterns.observer.Notification;
import com.puremvc.patterns.observer.Observer;
/**
* The interface definition for a PureMVC View.
* <p>
* <p>
* In PureMVC, <code>View</code> implementors assume these responsibilities:
* </P>
* <p>
* <p>
* In PureMVC, the <code>CoreView</code> class assumes these responsibilities:
* <UL>
* <LI>Maintain a cache of <code>Mediator</code> instances.</LI>
* <LI>Provide methods for registering, retrieving, and removing
* <code>Mediators</code>.</LI>
* <LI>Managing the observer lists for each <code>Notification</code> in the
* application.</LI>
* <LI>Providing a method for attaching <code>Observers</code> to an
* <code>Notification</code>'s observer list.</LI>
* <LI>Providing a method for broadcasting an <code>Notification</code>.</LI>
* <LI>Notifying the <code>Observers</code> of a given
* <code>Notification</code> when it broadcast.</LI>
* </UL>
*
* @see com.puremvc.patterns.mediator.Mediator Mediator
* @see com.puremvc.patterns.observer.Observer Observer
* @see com.puremvc.patterns.observer.Notification Notification
*/
public interface View {
/**
* Register an <code>IObserver</code> to be notified of
* <code>INotifications</code> with a given name.
*
* @param noteName the name of the <code>INotifications</code> to notify this
* <code>IObserver</code> of
* @param observer the <code>IObserver</code> to register
*/
void registerObserver(String noteName, Observer observer);
/**
* Notify the <code>IObservers</code> for a particular
* <code>INotification</code>.
* <p>
* <p>
* All previously attached <code>IObservers</code> for this
* <code>INotification</code>'s list are notified and are passed a
* reference to the <code>INotification</code> in the order in which they
* were registered.
* </P>
*
* @param note the <code>INotification</code> to notify
* <code>IObservers</code> of.
*/
void notifyObservers(Notification note);
/**
* Register an <code>IMediator</code> instance with the <code>View</code>.
* <p>
* <P>
* Registers the <code>IMediator</code> so that it can be retrieved by
* name, and further interrogates the <code>IMediator</code> for its
* <code>INotification</code> interests.
* </P>
* <P>
* If the <code>IMediator</code> returns any <code>INotification</code>
* names to be notified about, an <code>Observer</code> is created
* encapsulating the <code>IMediator</code> instance's
* <code>handleNotification</code> method and registering it as an
* <code>Observer</code> for all <code>INotifications</code> the
* <code>IMediator</code> is interested in.
* </p>
*
* @param mediator a reference to the <code>IMediator</code> instance
*/
void registerMediator(Mediator mediator);
/**
* Retrieve an <code>IMediator</code> from the <code>View</code>.
*
* @param mediatorName the name of the <code>IMediator</code> instance to retrieve.
* @return the <code>IMediator</code> instance previously registered with
* the given <code>mediatorName</code>.
*/
<T extends Mediator> T retrieveMediator(String mediatorName);
/**
* Remove an <code>IMediator</code> from the <code>View</code>.
*
* @param mediatorName name of the <code>IMediator</code> instance to be removed.
*/
Mediator removeMediator(String mediatorName);
/**
* Check if a Mediator is registered or not
*
* @param mediatorName
* @return whether a Mediator is registered with the given <code>mediatorName</code>.
*/
boolean hasMediator(String mediatorName);
}
@@ -1,37 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.command;
import com.puremvc.patterns.observer.Notification;
import com.puremvc.patterns.observer.Notifier;
/**
* The interface definition for a PureMVC Command.
*
* @see com.puremvc.patterns.observer Notification
*/
public interface Command extends Notifier {
/**
* Execute the <code>Command</code>'s logic to handle a given
* <code>Notification</code>.
*
* @param notification an <code>Notification</code> to handle.
*/
void execute(Notification notification);
}
@@ -1,138 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.command;
import java.util.Collection;
import java.util.Vector;
import com.puremvc.patterns.observer.BaseNotifier;
import com.puremvc.patterns.observer.Notification;
/**
* A base <code>ICommand</code> implementation that executes other
* <code>ICommand</code>s.
* <p>
* <p>
* A <code>MacroCommand</code> maintains an list of <code>ICommand</code>
* Class references called <i>SubCommands</i>.
* </P>
* <p>
* <p>
* When <code>execute</code> is called, the <code>MacroCommand</code>
* instantiates and calls <code>execute</code> on each of its <i>SubCommands</i>
* turn. Each <i>SubCommand</i> will be passed a reference to the original
* <code>INotification</code> that was passed to the <code>MacroCommand</code>'s
* <code>execute</code> method.
* </P>
* <p>
* <p>
* Unlike <code>SimpleCommand</code>, your subclass should not override
* <code>execute</code>, but instead, should override the
* <code>initializeMacroCommand</code> method, calling
* <code>addSubCommand</code> once for each <i>SubCommand</i> to be executed.
* </P>
* <p>
* <p>
*
* @see com.puremvc.core.Controller Controller
* @see com.puremvc.patterns.observer.Notification Notification
* @see com.puremvc.patterns.command.SimpleCommand SimpleCommand
*/
public class MacroCommand extends BaseNotifier implements Command {
private Collection<Class<? extends Command>> subCommands = null;
/**
* Constructor.
* <p>
* <p>
* You should not need to define a constructor, instead, override the
* <code>initializeMacroCommand</code> method.
* </P>
* <p>
* <p>
* If your subclass does define a constructor, be sure to call
* <code>super()</code>.
* </P>
*/
public MacroCommand() {
subCommands = new Vector<>();
initializeMacroCommand();
}
/**
* Initialize the <code>MacroCommand</code>.
* <p>
* <p>
* In your subclass, override this method to initialize the
* <code>MacroCommand</code>'s <i>SubCommand</i> list with
* <code>ICommand</code> class references like this:
* </P>
* <p>
* <listing> // Initialize MyMacroCommand override protected function
* initializeMacroCommand( ) : void { addSubCommand(
* com.me.myapp.controller.FirstCommand ); addSubCommand(
* com.me.myapp.controller.SecondCommand ); addSubCommand(
* com.me.myapp.controller.ThirdCommand ); } </listing>
* <p>
* <p>
* Note that <i>SubCommand</i>s may be any <code>ICommand</code>
* implementor, <code>MacroCommand</code>s or <code>SimpleCommands</code>
* are both acceptable.
*/
protected void initializeMacroCommand() {
}
/**
* Add a <i>SubCommand</i>.
* <p>
* <p>
* The <i>SubCommands</i> will be called in First In/First Out (FIFO)
* order.
* </P>
*
* @param commandClassRef a reference to the <code>Class</code> of the
* <code>ICommand</code>.
*/
protected void addSubCommand(Class<? extends Command> commandClassRef) {
subCommands.add(commandClassRef);
}
/**
* Execute this <code>MacroCommand</code>'s <i>SubCommands</i>.
* <p>
* <p>
* The <i>SubCommands</i> will be called in First In/First Out (FIFO)
* order.
*
* @param notification the <code>INotification</code> object to be passsed to each
* <i>SubCommand</i>.
*/
public void execute(Notification notification) {
for (Class<? extends Command> commandClass : subCommands) {
try {
Command command = commandClass.newInstance();
command.execute(notification);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
@@ -1,53 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.command;
import com.puremvc.patterns.observer.BaseNotifier;
import com.puremvc.patterns.observer.Notification;
/**
* A base <code>ICommand</code> implementation.
* <p>
* <p>
* Your subclass should override the <code>execute</code> method where your
* business logic will handle the <code>INotification</code>.
* </P>
*
* @see com.puremvc.core.Controller Controller
* @see com.puremvc.patterns.observer.Notification Notification
* @see com.puremvc.patterns.command.MacroCommand MacroCommand
*/
public class SimpleCommand extends BaseNotifier implements Command {
/**
* Fulfill the use-case initiated by the given <code>INotification</code>.
* <p>
* <p>
* In the Command Pattern, an application use-case typically begins with
* some user action, which results in an <code>INotification</code> being
* broadcast, which is handled by business logic in the <code>execute</code>
* method of an <code>ICommand</code>.
* </P>
*
* @param notification the <code>INotification</code> to handle.
*/
public void execute(Notification notification) {
}
}
@@ -1,144 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.facade;
import com.puremvc.patterns.command.Command;
import com.puremvc.patterns.mediator.Mediator;
import com.puremvc.patterns.observer.Notification;
import com.puremvc.patterns.observer.Notifier;
import com.puremvc.patterns.proxy.Proxy;
/**
* The interface definition for a PureMVC Facade.
* <p>
* <p>
* The Facade Pattern suggests providing a single class to act as a central
* point of communication for a subsystem.
* </P>
* <p>
* <p>
* In PureMVC, the Facade acts as an interface between the core MVC actors
* (Model, View, Controller) and the rest of your application.
* </P>
*
* @see com.puremvc.core.Model Model
* @see com.puremvc.core.View View
* @see com.puremvc.core.Controller Controller
* @see com.puremvc.patterns.command.Command Command
* @see com.puremvc.patterns.observer.Notification Notification
*/
public interface Facade extends Notifier {
/**
* Notify <code>Observer</code>s of an <code>INotification</code>.
*
* @param note the <code>INotification</code> to have the <code>View</code>
* notify observers of.
*/
void notifyObservers(Notification note);
/**
* Register an <code>IProxy</code> with the <code>Model</code> by name.
*
* @param proxy the <code>IProxy</code> to be registered with the
* <code>Model</code>.
*/
void registerProxy(Proxy proxy);
/**
* Retrieve a <code>IProxy</code> from the <code>Model</code> by name.
*
* @param proxyName the name of the <code>IProxy</code> instance to be
* retrieved.
* @return the <code>IProxy</code> previously regisetered by
* <code>proxyName</code> with the <code>Model</code>.
*/
<T extends Proxy> T retrieveProxy(String proxyName);
/**
* Remove an <code>IProxy</code> instance from the <code>Model</code> by
* name.
*
* @param proxyName the <code>IProxy</code> to remove from the
* <code>Model</code>.
*/
<T extends Proxy> T removeProxy(String proxyName);
/**
* Check if a Proxy is registered
*
* @param proxyName
* @return whether a Proxy is currently registered with the given <code>proxyName</code>.
*/
boolean hasProxy(String proxyName);
/**
* Register an <code>ICommand</code> with the <code>Controller</code>.
*
* @param noteName the name of the <code>INotification</code> to associate the
* <code>ICommand</code> with.
* @param commandClassRef a reference to the <code>Class</code> of the
* <code>ICommand</code>.
*/
void registerCommand(String noteName, Class<? extends Command> commandClassRef);
/**
* Remove a previously registered <code>ICommand</code> to <code>INotification</code> mapping from the Controller.
*
* @param notificationName the name of the <code>INotification</code> to remove the <code>ICommand</code> mapping for
*/
void removeCommand(String notificationName);
/**
* Check if a Command is registered for a given Notification
*
* @param notificationName
* @return whether a Command is currently registered for the given <code>notificationName</code>.
*/
boolean hasCommand(String notificationName);
/**
* Register an <code>IMediator</code> instance with the <code>View</code>.
*
* @param mediator a reference to the <code>IMediator</code> instance
*/
void registerMediator(Mediator mediator);
/**
* Retrieve an <code>IMediator</code> instance from the <code>View</code>.
*
* @param mediatorName the name of the <code>IMediator</code> instance to retrievve
* @return the <code>IMediator</code> previously registered with the given
* <code>mediatorName</code>.
*/
<T extends Mediator> T retrieveMediator(String mediatorName);
/**
* Check if a Mediator is registered or not
*
* @param mediatorName
* @return whether a Mediator is registered with the given <code>mediatorName</code>.
*/
boolean hasMediator(String mediatorName);
/**
* Remove a <code>IMediator</code> instance from the <code>View</code>.
*
* @param mediatorName name of the <code>IMediator</code> instance to be removed.
*/
Mediator removeMediator(String mediatorName);
}
@@ -1,364 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.facade;
import com.puremvc.core.CoreController;
import com.puremvc.core.CoreModel;
import com.puremvc.core.CoreView;
import com.puremvc.patterns.command.Command;
import com.puremvc.patterns.mediator.Mediator;
import com.puremvc.patterns.observer.BaseNotification;
import com.puremvc.patterns.observer.Notification;
import com.puremvc.patterns.proxy.Proxy;
/**
* A base Singleton <code>Facade</code> implementation.
*
* @see CoreModel Model
* @see CoreView View
* @see CoreController Controller
*/
public class SimpleFacade implements Facade {
/**
* The Singleton instance of the Facade
*/
protected static SimpleFacade instance = null;
/**
* Reference to the Controller
*/
protected CoreController controller = null;
/**
* Reference to the Model
*/
protected CoreModel model = null;
/**
* Reference to the View
*/
protected CoreView view = null;
/**
* Constructor.
* <p>
* <p>
* This <code>IFacade</code> implementation is a Singleton, so you should
* not call the constructor directly, but instead call the static Singleton
* Factory method <code>Facade.getInstance()</code>
*/
protected SimpleFacade() {
initializeFacade();
}
/**
* Facade Singleton Factory method
*
* @return The Singleton instance of the Facade
*/
public synchronized static SimpleFacade getInstance() {
if (instance == null) {
instance = new SimpleFacade();
}
return instance;
}
/**
* Initialize the Multiton <code>Facade</code> instance.
* <p>
* <p>
* Called automatically by the constructor. Override in your
* subclass to do any subclass specific initializations. Be
* sure to call <code>super.initializeFacade()</code>, though.</P>
*/
protected void initializeFacade() {
initializeModel();
initializeController();
initializeView();
}
/**
* Initialize the <code>Controller</code>.
* <p>
* <p>
* Called by the <code>initializeFacade</code> method. Override this
* method in your subclass of <code>Facade</code> if one or both of the
* following are true:
* <UL>
* <LI> You wish to initialize a different <code>IController</code>.</LI>
* <LI> You have <code>Commands</code> to register with the
* <code>Controller</code> at startup.</code>. </LI>
* </UL>
* If you don't want to initialize a different <code>IController</code>,
* call <code>super.initializeController()</code> at the beginning of your
* method, then register <code>Command</code>s.
* </P>
*/
protected void initializeController() {
if (controller != null) {
return;
}
controller = CoreController.getInstance();
}
/**
* Initialize the <code>Model</code>.
* <p>
* <p>
* Called by the <code>initializeFacade</code> method. Override this
* method in your subclass of <code>Facade</code> if one or both of the
* following are true:
* <UL>
* <LI> You wish to initialize a different <code>IModel</code>.</LI>
* <LI> You have <code>Proxy</code>s to register with the Model that do
* not retrieve a reference to the Facade at construction time.</code></LI>
* </UL>
* If you don't want to initialize a different <code>IModel</code>, call
* <code>super.initializeModel()</code> at the beginning of your method,
* then register <code>Proxy</code>s.
* <p>
* Note: This method is <i>rarely</i> overridden; in practice you are more
* likely to use a <code>Command</code> to create and register <code>Proxy</code>s
* with the <code>Model</code>, since <code>Proxy</code>s with mutable
* tools will likely need to send <code>INotification</code>s and thus
* will likely want to fetch a reference to the <code>Facade</code> during
* their construction.
* </P>
*/
protected void initializeModel() {
if (model != null) {
return;
}
model = CoreModel.getInstance();
}
/**
* Initialize the <code>View</code>.
* <p>
* <p>
* Called by the <code>initializeFacade</code> method. Override this
* method in your subclass of <code>Facade</code> if one or both of the
* following are true:
* <UL>
* <LI> You wish to initialize a different <code>IView</code>.</LI>
* <LI> You have <code>Observers</code> to register with the
* <code>View</code></LI>
* </UL>
* If you don't want to initialize a different <code>IView</code>, call
* <code>super.initializeView()</code> at the beginning of your method,
* then register <code>IMediator</code> instances.
* <p>
* Note: This method is <i>rarely</i> overridden; in practice you are more
* likely to use a <code>Command</code> to create and register
* <code>Mediator</code>s with the <code>View</code>, since
* <code>IMediator</code> instances will need to send
* <code>INotification</code>s and thus will likely want to fetch a
* reference to the <code>Facade</code> during their construction.
* </P>
*/
protected void initializeView() {
if (view != null) {
return;
}
view = CoreView.getInstance();
}
/**
* Register an <code>ICommand</code> with the <code>Controller</code> by
* Notification name.
*
* @param noteName the name of the <code>INotification</code> to associate the
* <code>ICommand</code> with
* @param command an instance of the <code>ICommand</code>
*/
public void registerCommand(String noteName, Class<? extends Command> command) {
controller.registerCommand(noteName, command);
}
/**
* Remove a previously registered <code>ICommand</code> to <code>INotification</code> mapping from the Controller.
*
* @param notificationName the name of the <code>INotification</code> to remove the <code>ICommand</code> mapping for
*/
public void removeCommand(String notificationName) {
controller.removeCommand(notificationName);
}
/**
* Check if a Command is registered for a given Notification
*
* @param notificationName
* @return whether a Command is currently registered for the given <code>notificationName</code>.
*/
public boolean hasCommand(String notificationName) {
return controller.hasCommand(notificationName);
}
/**
* Register a <code>IMediator</code> with the <code>View</code>.
*
* @param mediator the name to associate with this <code>IMediator</code>
*/
public void registerMediator(Mediator mediator) {
if (view != null) {
view.registerMediator(mediator);
}
}
/**
* Register an <code>IProxy</code> with the <code>Model</code> by name.
*
* @param proxy the name of the <code>IProxy</code> instance to be
* registered with the <code>Model</code>.
*/
public void registerProxy(Proxy proxy) {
model.registerProxy(proxy);
}
/**
* Remove an <code>IMediator</code> from the <code>View</code>.
*
* @param mediatorName name of the <code>IMediator</code> to be removed.
* @return the <code>IMediator</code> that was removed from the <code>View</code>
*/
public Mediator removeMediator(String mediatorName) {
if (this.view != null) {
return this.view.removeMediator(mediatorName);
}
return null;
}
/**
* Remove an <code>IProxy</code> from the <code>Model</code> by name.
*
* @param proxyName the <code>IProxy</code> to remove from the
* <code>Model</code>.
* @return the <code>IProxy</code> that was removed from the <code>Model</code>
*/
public Proxy removeProxy(String proxyName) {
if (model != null) {
return model.removeProxy(proxyName);
}
return null;
}
/**
* Check if a Proxy is registered
*
* @param proxyName
* @return whether a Proxy is currently registered with the given <code>proxyName</code>.
*/
public boolean hasProxy(String proxyName) {
return model.hasProxy(proxyName);
}
/**
* Check if a Mediator is registered or not
*
* @param mediatorName
* @return whether a Mediator is registered with the given <code>mediatorName</code>.
*/
public boolean hasMediator(String mediatorName) {
return view.hasMediator(mediatorName);
}
/**
* Retrieve an <code>IMediator</code> from the <code>View</code>.
*
* @param mediatorName
* @return the <code>IMediator</code> previously registered with the given
* <code>mediatorName</code>.
*/
public <T extends Mediator> T retrieveMediator(String mediatorName) {
return this.view.retrieveMediator(mediatorName);
}
/**
* Retrieve an <code>IProxy</code> from the <code>Model</code> by name.
*
* @param proxyName the name of the proxy to be retrieved.
* @return the <code>IProxy</code> instance previously registered with the
* given <code>proxyName</code>.
*/
@Override
public <T extends Proxy> T retrieveProxy(String proxyName) {
return this.model.retrieveProxy(proxyName);
}
/**
* Create and send an <code>INotification</code>.
* <p>
* <p>
* Keeps us from having to construct new notification
* instances in our implementation code.
*
* @param notificationName the name of the notification to send
* @param body the body of the notification (optional)
* @param type the type of the notification (optional)
*/
public void sendNotification(String notificationName, Object body, String type) {
notifyObservers(new BaseNotification(notificationName, body, type));
}
/**
* Create and send an <code>INotification</code>.
* <p>
* <p>
* Keeps us from having to construct new notification
* instances in our implementation code.
*
* @param notificationName the name of the notification to send
* @param body the body of the notification (optional)
*/
public void sendNotification(String notificationName, Object body) {
sendNotification(notificationName, body, null);
}
/**
* Create and send an <code>INotification</code>.
* <p>
* <p>
* Keeps us from having to construct new notification
* instances in our implementation code.
*
* @param notificationName the name of the notification to send
*/
public void sendNotification(String notificationName) {
sendNotification(notificationName, null, null);
}
/**
* Notify <code>Observer</code>s of an <code>INotification</code>.
*
* @param note the <code>INotification</code> to have the <code>View</code>
* notify observers of.
*/
public void notifyObservers(Notification note) {
if (view != null) {
view.notifyObservers(note);
}
}
}
@@ -1,143 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.mediator;
import com.puremvc.patterns.observer.Notification;
import com.puremvc.patterns.observer.Notifier;
/**
* The interface definition for a PureMVC Mediator.
* <p>
* <p>
* In PureMVC, <code>IMediator</code> implementors assume these
* responsibilities:
* </P>
* <UL>
* <LI>Implement a common method which returns a list of all
* <code>INotification</code>s the <code>IMediator</code> has interest in.</LI>
* <LI>Implement a common notification (callback) method.</LI>
* </UL>
* <p>
* Additionally, <code>IMediator</code>s typically:
* <UL>
* <LI>Act as an intermediary between one or more view components such as text
* panels or list controls, maintaining references and coordinating their
* behavior.</LI>
* <LI>In Flash-based apps, this is often the place where event listeners are
* added to view components, and their handlers implemented.</LI>
* <LI>Respond to and generate <code>INotifications</code>, interacting with
* of the rest of the PureMVC app.
* </UL>
* </P>
* <p>
* When an <code>IMediator</code> is registered with the <code>IView</code>,
* the <code>IView</code> will call the <code>IMediator</code>'s
* <code>listNotificationInterests</code> method. The <code>IMediator</code>
* will return an <code>Array</code> of <code>INotification</code> names
* which it wishes to be notified about.
* </P>
* <p>
* <p>
* The <code>IView</code> will then create an <code>Observer</code> object
* encapsulating that <code>IMediator</code>'s (<code>handleNotification</code>)
* method and register it as an Observer for each <code>INotification</code>
* name returned by <code>listNotificationInterests</code>.
* </P>
* <p>
* <p>
* A concrete IMediator implementor usually looks something like this:
* </P>
* <p>
* <listing> import org.puremvc.patterns.mediator.~~; import
* org.puremvc.patterns.observer.~~; import org.puremvc.core.view.~~;
* <p>
* import com.me.myapp.model.~~; import com.me.myapp.view.~~; import
* com.me.myapp.controller.~~;
* <p>
* import mx.controls.ComboBox; import mx.events.ListEvent;
* <p>
* public class MyMediator extends Mediator implements IMediator {
* <p>
* public function MyComboMediator( viewComponent:Object ) { super(
* viewComponent ); combo.addEventListener( Event.CHANGE, onChange ); }
* <p>
* public function listNotificationInterests():Array { return [
* MyFacade.SET_SELECTION, MyFacade.SET_DATAPROVIDER ]; }
* <p>
* public function handleNotification( notification:INotification ):void {
* switch ( notification.getName() ) { case MyFacade.SET_SELECTION:
* setSelection(notification); break; case MyFacade.SET_DATAPROVIDER:
* setDataProvider(notification); break; } } // Set the tools provider of the
* combo box private function setDataProvider( notification:INotification ):void {
* combo.dataProvider = notification.getBody() as Array; } // Invoked when the
* combo box dispatches a change event, we send a // notification with the
* private function onChange(event:ListEvent):void { sendNotification(
* MyFacade.MYCOMBO_CHANGED, this ); } // A private getter for accessing the
* view object by class private function get combo():ComboBox { return view as
* ComboBox; } } </listing>
*
* @see com.puremvc.patterns.observer.Notification Notification
*/
public interface Mediator<V> extends Notifier {
/**
* Get the <code>IMediator</code> instance name
*
* @return the <code>IMediator</code> instance name
*/
String getMediatorName();
/**
* Get the <code>IMediator</code>'s view component.
*
* @return Object the view component
*/
V getViewComponent();
/**
* Set the <code>IMediator</code>'s view component.
*
* @param viewComponent The view component
*/
void setViewComponent(V viewComponent);
/**
* List <code>INotification</code> interests.
*
* @return an <code>Array</code> of the <code>INotification</code> names
* this <code>IMediator</code> has an interest in.
*/
String[] listNotificationInterests();
/**
* Handle an <code>INotification</code>.
*
* @param notification the <code>INotification</code> to be handled
*/
void handleNotification(Notification notification);
/**
* Called by the View when the Mediator is registered
*/
void onRegister();
/**
* Called by the View when the Mediator is removed
*/
void onRemove();
}
@@ -1,127 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.mediator;
import com.puremvc.patterns.observer.BaseNotifier;
import com.puremvc.patterns.observer.Notification;
import com.puremvc.patterns.observer.Notifier;
/**
* A base <code>Mediator</code> implementation.
*
* @see com.puremvc.core.View View
*/
public class SimpleMediator<V> extends BaseNotifier implements Mediator<V>, Notifier {
/**
* The default name of the <code>SimpleMediator</code>.
*/
public static final String NAME = "SimpleMediator";
/**
* The name of the <code>Mediator</code>.
*/
protected String mediatorName = null;
/**
* The view component
*/
protected V viewComponent = null;
/**
* Constructor.
*
* @param mediatorName
* @param viewComponent
*/
public SimpleMediator(String mediatorName, V viewComponent) {
this.mediatorName = (mediatorName != null) ? mediatorName : NAME;
this.viewComponent = viewComponent;
}
/**
* Get the name of the <code>Mediator</code>.
*
* @return the name
*/
public final String getMediatorName() {
return mediatorName;
}
/**
* Get the <code>Mediator</code>'s view component.
* <p>
* <p>
* Additionally, an implicit getter will usually be defined in the subclass
* that casts the view object to a type, like this:
* </P>
* <p>
* <listing> private function get comboBox : mx.controls.ComboBox { return
* viewComponent as mx.controls.ComboBox; } </listing>
*
* @return the view component
*/
public V getViewComponent() {
return viewComponent;
}
/**
* Set the <code>IMediator</code>'s view component.
*
* @param viewComponent The view component
*/
public void setViewComponent(V viewComponent) {
this.viewComponent = viewComponent;
}
/**
* Handle <code>INotification</code>s.
* <p>
* <p>
* Typically this will be handled in a switch statement, with one 'case'
* entry per <code>INotification</code> the <code>Mediator</code> is
* interested in.
*
* @param notification
*/
public void handleNotification(Notification notification) {
}
/**
* List the <code>INotification</code> names this <code>Mediator</code>
* is interested in being notified of.
*
* @return String[] the list of <code>INotification</code> names
*/
public String[] listNotificationInterests() {
return new String[]{};
}
/**
* Called by the View when the Mediator is registered
*/
public void onRegister() {
}
/**
* Called by the View when the Mediator is removed
*/
public void onRemove() {
}
}
@@ -1,169 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.observer;
/**
* A base <code>Notification</code> implementation.
* <p>
* <p>
* PureMVC does not rely upon underlying event models such as the one provided
* with Flash, and ActionScript 3 does not have an inherent event model.
* </P>
* <p>
* <p>
* The Observer Pattern as implemented within PureMVC exists to support
* event-driven communication between the application and the actors of the MVC
* triad.
* </P>
* <p>
* <p>
* Notifications are not meant to be a replacement for Events in
* Flex/Flash/Apollo. Generally, <code>IMediator</code> implementors place
* event listeners on their view components, which they then handle in the usual
* way. This may lead to the broadcast of <code>Notification</code>s to
* trigger <code>ICommand</code>s or to communicate with other
* <code>IMediators</code>. <code>IProxy</code> and <code>ICommand</code>
* instances communicate with each other and <code>IMediator</code>s by
* broadcasting <code>INotification</code>s.
* </P>
* <p>
* <p>
* A key difference between Flash <code>Event</code>s and PureMVC
* <code>Notification</code>s is that <code>Event</code>s follow the
* 'Chain of Responsibility' pattern, 'bubbling' up the display hierarchy until
* some parent component handles the <code>Event</code>, while PureMVC
* <code>Notification</code>s follow a 'Publish/Subscribe' pattern. PureMVC
* classes need not be related to each other in a parent/child relationship in
* order to communicate with one another using <code>Notification</code>s.
*
* @see com.puremvc.patterns.observer Observer
*/
public class BaseNotification implements Notification {
// the name of the notification instance
// the type of the notification instance
protected String name = null;
protected String type = null;
// the body of the notification instance
protected Object body = null;
/**
* Constructor.
*
* @param name name of the <code>Notification</code> instance. (required)
* @param body the <code>Notification</code> body. (optional)
* @param type the type of the <code>Notification</code> (optional)
*/
public BaseNotification(String name, Object body, String type) {
this.name = name;
this.body = body;
this.type = type;
}
/**
* Constructor.
*
* @param name name of the <code>Notification</code> instance. (required)
*/
public BaseNotification(String name) {
this.name = name;
body = null;
type = null;
}
/**
* Constructor.
*
* @param name name of the <code>Notification</code> instance. (required)
* @param body the <code>Notification</code> body. (optional)
*/
public BaseNotification(String name, Object body) {
this.name = name;
this.body = body;
type = null;
}
/**
* Get the body of the <code>Notification</code> instance.
*
* @return the body object.
*/
public <T> T getBody() {
return (T) body;
}
/**
* Set the body of the <code>Notification</code> instance.
*
* @param body
*/
public <T> void setBody(T body) {
this.body = body;
}
/**
* Get the name of the <code>Notification</code> instance.
*
* @return the name of the <code>Notification</code> instance.
*/
public String getName() {
return name;
}
/**
* Get the type of the <code>Notification</code> instance.
*
* @return the type
*/
public String getType() {
return type;
}
/**
* Set the type of the <code>Notification</code> instance.
*
* @param type
*/
public void setType(String type) {
this.type = type;
}
/**
* Get the string representation of the <code>Notification</code>
* instance.
*
* @return the string representation of the <code>Notification</code>
* instance.
*/
public String toString() {
String result = "Notification Name: " + getName() + " Body:";
if (body != null)
result += body.toString() + " Type:";
else
result += "null Type:";
if (type != null)
result += type;
else
result += "null ";
return result;
}
}
@@ -1,103 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.observer;
import com.puremvc.patterns.facade.SimpleFacade;
/**
* A Base <code>Notifier</code> implementation.
* <p>
* <p>
* <code>MacroCommand, Command, Mediator</code> and <code>Proxy</code> all
* have a need to send <code>Notifications</code>.
* <p>
* <p>
* The <code>INotifier</code> interface provides a common method called
* <code>sendNotification</code> that relieves implementation code of the
* necessity to actually construct <code>Notifications</code>.
* </P>
* <p>
* <p>
* The <code>Notifier</code> class, which all of the above mentioned classes
* extend, provides an initialized reference to the <code>Facade</code>
* Singleton, which is required for the convienience method for sending
* <code>Notifications</code>, but also eases implementation as these classes
* have frequent <code>Facade</code> interactions and usually require access
* to the facade anyway.
* </P>
*
* @see com.puremvc.patterns.facade.Facade Facade
* @see com.puremvc.patterns.mediator.Mediator Mediator
* @see com.puremvc.patterns.proxy Proxy
* @see com.puremvc.patterns.command.SimpleCommand SimpleCommand
* @see com.puremvc.patterns.command.MacroCommand MacroCommand
*/
public class BaseNotifier {
// The Multiton Key for this app
/**
* Local reference to the Facade Singleton
*/
protected SimpleFacade facade;
/**
* Send an <code>Notification</code>s.
* <p>
* <p>
* Keeps us from having to construct new notification instances in our
* implementation code.
*
* @param notificationName the name of the notiification to send
* @param body the body of the notification (optional)
* @param type the type of the notification (optional)
*/
public void sendNotification(String notificationName, Object body, String type) {
facade.sendNotification(notificationName, body, type);
}
/**
* Send an <code>INotification</code>s.
* <p>
* <p>
* Keeps us from having to construct new notification instances in our
* implementation code.
*
* @param notificationName the name of the notiification to send
* @param body the body of the notification (optional)
*/
public void sendNotification(String notificationName, Object body) {
facade.sendNotification(notificationName, body);
}
/**
* Send an <code>INotification</code>s.
* <p>
* <p>
* Keeps us from having to construct new notification instances in our
* implementation code.
*
* @param notificationName the name of the notiification to send
*/
public void sendNotification(String notificationName) {
facade.sendNotification(notificationName);
}
}
@@ -1,127 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.observer;
/**
* A base <code>IObserver</code> implementation.
* <p>
* <p>
* An <code>Observer</code> is an object that encapsulates information about
* an interested object with a method that should be called when a particular
* <code>INotification</code> is broadcast.
* </P>
* <p>
* <p>
* In PureMVC, the <code>Observer</code> class assumes these responsibilities:
* <UL>
* <LI>Encapsulate the notification (callback) method of the interested object.</LI>
* <LI>Encapsulate the notification context (this) of the interested object.</LI>
* <LI>Provide methods for setting the notification method and context.</LI>
* <LI>Provide a method for notifying the interested object.</LI>
* </UL>
*
* @see com.puremvc.core.View View
* @see com.puremvc.patterns.observer.Notification Notification
*/
public class BaseObserver implements Observer {
private Object context;
private Function notify;
/**
* Constructor.
* <p>
* <p>
* The notification method on the interested object should take one
* parameter of type <code>INotification</code>
* </P>
*
* @param notify the notification method of the interested object
* @param context the notification context of the interested object
*/
public BaseObserver(Function notify, Object context) {
setNotifyContext(context);
setNotifyMethod(notify);
}
/**
* Compare an object to the notification context.
*
* @param object the object to compare
* @return boolean indicating if the object and the notification context are
* the same
*/
public boolean compareNotifyContext(Object object) {
return context == object;
}
/**
* Notify the interested object.
*
* @param notification the <code>INotification</code> to pass to the interested
* object's notification method.
*/
public void notifyObserver(Notification notification) {
getNotifyMethod().onNotification(notification);
}
/**
* Get the notification method.
*
* @return the notification (callback) method of the interested object.
*/
public Function getNotifyMethod() {
return notify;
}
/**
* Set the notification method.
* <p>
* <p>
* The notification method should take one parameter of type
* <code>INotification</code>.
* </P>
*
* @param notifyMethod the notification (callback) method of the interested object.
*/
public void setNotifyMethod(Function notifyMethod) {
notify = notifyMethod;
}
/**
* Get the notification context.
*
* @return the notification context (<code>this</code>) of the
* interested object.
*/
public Object getNotifyContext() {
return context;
}
/**
* Set the notification context.
*
* @param notifyContext the notification context (this) of the interested object.
*/
public void setNotifyContext(Object notifyContext) {
context = notifyContext;
}
}
@@ -1,103 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.observer;
/**
* The interface definition for a PureMVC Notification.
* <p>
* <p>
* PureMVC does not rely upon underlying event models such as the one provided
* with Flash, and ActionScript 3 does not have an inherent event model.
* </P>
* <p>
* <p>
* The Observer Pattern as implemented within PureMVC exists to support
* event-driven communication between the application and the actors of the MVC
* triad.
* </P>
* <p>
* <p>
* Notifications are not meant to be a replacement for Events in
* Flex/Flash/Apollo. Generally, <code>IMediator</code> implementors place
* event listeners on their view components, which they then handle in the usual
* way. This may lead to the broadcast of <code>Notification</code>s to
* trigger <code>ICommand</code>s or to communicate with other
* <code>IMediators</code>. <code>IProxy</code> and <code>ICommand</code>
* instances communicate with each other and <code>IMediator</code>s by
* broadcasting <code>INotification</code>s.
* </P>
* <p>
* <p>
* A key difference between Flash <code>Event</code>s and PureMVC
* <code>Notification</code>s is that <code>Event</code>s follow the
* 'Chain of Responsibility' pattern, 'bubbling' up the display hierarchy until
* some parent component handles the <code>Event</code>, while PureMVC
* <code>Notification</code>s follow a 'Publish/Subscribe' pattern. PureMVC
* classes need not be related to each other in a parent/child relationship in
* order to communicate with one another using <code>Notification</code>s.
*
* @see com.puremvc.core.View View
* @see com.puremvc.patterns.observer.Observer Observer
*/
public interface Notification {
/**
* Get the name of the <code>INotification</code> instance. No setter,
* should be set by constructor only
*
* @return the name
*/
String getName();
/**
* Get the body of the <code>INotification</code> instance
*
* @return the body
*/
<T> T getBody();
/**
* Set the body of the <code>INotification</code> instance
*
* @param body
*/
<T> void setBody(T body);
/**
* Get the type of the <code>INotification</code> instance
*
* @return the type
*/
String getType();
/**
* Set the type of the <code>Notification</code> instance
*
* @param type the type
*/
void setType(String type);
/**
* Get the string representation of the <code>INotification</code>
* instance
*
* @return the string representation of the <code>INotification</code>
* instance
*/
String toString();
}
@@ -1,86 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.observer;
/**
* The interface definition for a PureMVC Notifier.
* <p>
* <p>
* <code>MacroCommand, Command, Mediator</code> and <code>Proxy</code> all
* have a need to send <code>Notifications</code>.
* </P>
* <p>
* <p>
* The <code>INotifier</code> interface provides a common method called
* <code>sendNotification</code> that relieves implementation code of the
* necessity to actually construct <code>Notifications</code>.
* </P>
* <p>
* <p>
* The <code>Notifier</code> class, which all of the above mentioned classes
* extend, also provides an initialized reference to the <code>Facade</code>
* Singleton, which is required for the convienience method for sending
* <code>Notifications</code>, but also eases implementation as these classes
* have frequent <code>Facade</code> interactions and usually require access
* to the facade anyway.
* </P>
*
* @see com.puremvc.patterns.facade.Facade Facade
* @see com.puremvc.patterns.observer.Notification Notification
*/
public interface Notifier {
/**
* Send a <code>INotification</code>.
* <p>
* <p>
* Convenience method to prevent having to construct new notification
* instances in our implementation code.
* </P>
*
* @param notificationName the name of the notification to send
* @param body the body of the notification (optional)
* @param type the type of the notification (optional)
*/
void sendNotification(String notificationName, Object body, String type);
/**
* Send a <code>INotification</code>.
* <p>
* <p>
* Convenience method to prevent having to construct new notification
* instances in our implementation code.
* </P>
*
* @param notificationName the name of the notification to send
* @param body the body of the notification (optional)
*/
void sendNotification(String notificationName, Object body);
/**
* Send a <code>INotification</code>.
* <p>
* <p>
* Convenience method to prevent having to construct new notification
* instances in our implementation code.
* </P>
*
* @param notificationName the name of the notification to send
*/
void sendNotification(String notificationName);
}
@@ -1,108 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.observer;
/**
* The interface definition for a PureMVC Observer.
* <p>
* <p>
* In PureMVC, <code>IObserver</code> implementors assume these
* responsibilities:
* <UL>
* <LI>Encapsulate the notification (callback) method of the interested object.</LI>
* <LI>Encapsulate the notification context (this) of the interested object.</LI>
* <LI>Provide methods for setting the interested object' notification method
* and context.</LI>
* <LI>Provide a method for notifying the interested object.</LI>
* </UL>
* <p>
* <p>
* PureMVC does not rely upon underlying event models such as the one provided
* with Flash, and ActionScript 3 does not have an inherent event model.
* </P>
* <p>
* <p>
* The Observer Pattern as implemented within PureMVC exists to support event
* driven communication between the application and the actors of the MVC triad.
* </P>
* <p>
* <p>
* An Observer is an object that encapsulates information about an interested
* object with a notification method that should be called when an </code>INotification</code>
* is broadcast. The Observer then acts as a proxy for notifying the interested
* object.
* <p>
* <p>
* Observers can receive <code>Notification</code>s by having their <code>notifyObserver</code>
* method invoked, passing in an object implementing the <code>INotification</code>
* interface, such as a subclass of <code>Notification</code>.
* </P>
*
* @see com.puremvc.core.View View
* @see com.puremvc.patterns.observer.Notification Notification
*/
public interface Observer {
/**
* Set the notification method.
* <p>
* <p>
* The notification method should take one parameter of type
* <code>INotification</code>
* </P>
*
* @param notifyMethod the notification (callback) method of the interested object
*/
void setNotifyMethod(BaseObserver.Function notifyMethod);
/**
* Set the notification context.
*
* @param notifyContext the notification context (this) of the interested object
*/
void setNotifyContext(Object notifyContext);
/**
* Notify the interested object.
*
* @param notification the <code>INotification</code> to pass to the interested
* object's notification method
*/
void notifyObserver(Notification notification);
/**
* Compare the given object to the notificaiton context object.
*
* @param object the object to compare.
* @return boolean indicating if the notification context and the object are
* the same.
*/
boolean compareNotifyContext(Object object);
/**
* This interface must be implemented by all classes that want to be notified of
* a notification.
*/
interface Function {
/**
* @param notification
*/
void onNotification(Notification notification);
}
}
@@ -1,120 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.proxy;
import com.puremvc.patterns.observer.BaseNotifier;
/**
* A base <code>IProxy</code> implementation.
* <p>
* <p>
* In PureMVC, <code>Proxy</code> classes are used to manage parts of the
* application's tools model.
* </P>
* <p>
* <p>
* A <code>Proxy</code> might simply manage a reference to a local tools
* object, in which case interacting with it might involve setting and getting
* of its tools in synchronous fashion.
* </P>
* <p>
* <p>
* <code>Proxy</code> classes are also used to encapsulate the application's
* interaction with remote services to save or retrieve tools, in which case, we
* adopt an asyncronous idiom; setting tools (or calling a method) on the
* <code>Proxy</code> and listening for a <code>Notification</code> to be
* sent when the <code>Proxy</code> has retrieved the tools from the service.
* </P>
*
* @see com.puremvc.core.Model Model
*/
public class BaseProxy extends BaseNotifier implements Proxy {
// the proxy name
protected String proxyName = "BaseProxy";
// the tools object
protected Object data = null;
/**
* Constructor
*
* @param proxyName
* @param data
*/
public BaseProxy(String proxyName, Object data) {
if (proxyName != null) {
this.proxyName = proxyName;
}
if (data != null) {
this.data = data;
}
}
/**
* Constructor
*
* @param proxyName Name of the <code>Proxy</code>
*/
public BaseProxy(String proxyName) {
if (proxyName != null) {
this.proxyName = proxyName;
}
}
/**
* Get the proxy name
*
* @return the proxy name
*/
public String getProxyName() {
return proxyName;
}
/**
* Get the tools object
*
* @return the tools object
*/
public Object getData() {
return data;
}
/**
* Set the tools object
*
* @param data
*/
public void setData(Object data) {
this.data = data;
}
/**
* Called by the Model when the Proxy is registered
*/
public void onRegister() {
}
/**
* Called by the Model when the Proxy is removed
*/
public void onRemove() {
}
}
@@ -1,76 +0,0 @@
/*
* ******************************************************************************
* * Copyright 2015 See AUTHORS file.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *****************************************************************************
*/
package com.puremvc.patterns.proxy;
import com.puremvc.patterns.observer.Notifier;
/**
* The interface definition for a PureMVC Proxy.
* <p>
* <p>
* In PureMVC, <code>Iroxy</code> implementors assume these responsibilities:
* </P>
* <UL>
* <LI>Implement a common method which returns the name of the Proxy.</LI>
* </UL>
* <p>
* Additionally, <code>IProxy</code>s typically:
* </P>
* <UL>
* <LI>Maintain references to one or more pieces of model tools.</LI>
* <LI>Provide methods for manipulating that tools.</LI>
* <LI>Generate <code>INotifications</code> when their model tools changes.</LI>
* <LI>Expose their name as a <code>public static const</code> called <code>NAME</code>, if they are not instantiated multiple times.</LI>
* <LI>Encapsulate interaction with local or remote services used to fetch and
* persist model tools.</LI>
* </UL>
*/
public interface Proxy extends Notifier {
/**
* Get the Proxy name
*
* @return the Proxy instance name
*/
String getProxyName();
/**
* Get the tools object
*
* @return the tools as type Object
*/
Object getData();
/**
* Set the tools object
*
* @param data the tools object
*/
void setData(Object data);
/**
* Called by the Model when the Proxy is registered
*/
void onRegister();
/**
* Called by the Model when the Proxy is removed
*/
void onRemove();
}
@@ -19,8 +19,8 @@
package games.rednblack.h2d.common.plugins;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.utils.Array;
import com.puremvc.patterns.facade.Facade;
import net.mountainblade.modular.Module;
import org.puremvc.java.interfaces.IFacade;
import java.util.HashMap;
import java.util.Map;
@@ -31,7 +31,7 @@ import java.util.Set;
*/
public abstract class H2DPluginAdapter implements H2DPlugin, Module {
public Facade facade;
public IFacade facade;
protected PluginAPI pluginAPI;
protected String name;
@@ -27,10 +27,10 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
import games.rednblack.h2d.common.IItemCommand;
import games.rednblack.h2d.common.view.tools.Tool;
import com.kotcrab.vis.ui.widget.VisImageButton;
import com.puremvc.patterns.facade.Facade;
import games.rednblack.editor.renderer.SceneLoader;
import games.rednblack.h2d.common.vo.CursorData;
import games.rednblack.h2d.common.vo.EditorConfigVO;
import org.puremvc.java.interfaces.IFacade;
import java.util.HashMap;
import java.util.HashSet;
@@ -50,7 +50,7 @@ public interface PluginAPI {
* Returns MVC facade, to send notifications or commands, and register mediators
* @return Facade
*/
Facade getFacade();
IFacade getFacade();
/**
* Returns Ashley engine of main scene where all entities are located
@@ -23,14 +23,14 @@ import com.badlogic.gdx.graphics.Cursor;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.h2d.common.view.ui.Cursors;
import games.rednblack.h2d.common.vo.CursorData;
import org.puremvc.java.patterns.proxy.Proxy;
/**
* Created by azakhary on 5/15/2015.
*/
public class CursorManager extends BaseProxy {
public class CursorManager extends Proxy {
private static final String TAG = CursorManager.class.getCanonicalName();
public static final String NAME = TAG;
@@ -1,15 +1,15 @@
package games.rednblack.h2d.common.view;
import com.kotcrab.vis.ui.widget.VisTable;
import com.puremvc.patterns.facade.Facade;
import org.puremvc.java.interfaces.IFacade;
public abstract class SettingsNodeValue<T> {
private final VisTable contentTable = new VisTable();
private T settings;
private final String name;
protected Facade facade;
protected IFacade facade;
public SettingsNodeValue(String name, Facade facade) {
public SettingsNodeValue(String name, IFacade facade) {
this.name = name;
contentTable.top().left();
this.facade = facade;
@@ -19,7 +19,7 @@
package games.rednblack.h2d.common.view.tools;
import com.badlogic.ashley.core.Entity;
import com.puremvc.patterns.observer.Notification;
import org.puremvc.java.interfaces.INotification;
/**
* Created by azakhary on 4/30/2015.
@@ -38,7 +38,7 @@ public interface Tool {
String getName();
String getTitle();
String getShortcut();
void handleNotification(Notification notification);
void handleNotification(INotification notification);
void keyDown(Entity entity, int keycode);
void keyUp(Entity entity, int keycode);
}
@@ -31,18 +31,18 @@ import com.kotcrab.vis.ui.util.InputValidator;
import com.kotcrab.vis.ui.widget.*;
import com.kotcrab.vis.ui.widget.spinner.IntSpinnerModel;
import com.kotcrab.vis.ui.widget.spinner.Spinner;
import com.puremvc.patterns.facade.Facade;
import games.rednblack.h2d.common.view.ui.listener.CursorListener;
import games.rednblack.h2d.common.view.ui.listener.ScrollFocusListener;
import games.rednblack.h2d.common.view.ui.widget.TintButton;
import org.puremvc.java.interfaces.IFacade;
/**
* Creates standard widgets like labels or text fields with provided standard HyperLap2D specific visual style.
*/
public class StandardWidgetsFactory {
private static Facade facade;
public static void init(Facade f) {
private static IFacade facade;
public static void init(IFacade f) {
facade = f;
}
@@ -21,15 +21,15 @@ package games.rednblack.h2d.common.view.ui.listener;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.puremvc.patterns.facade.Facade;
import games.rednblack.h2d.common.proxy.CursorManager;
import games.rednblack.h2d.common.vo.CursorData;
import org.puremvc.java.interfaces.IFacade;
public class CursorListener extends InputListener {
private final CursorData cursor;
private final CursorManager cursorManager;
public CursorListener(CursorData cursor, Facade facade) {
public CursorListener(CursorData cursor, IFacade facade) {
this.cursor = cursor;
cursorManager = facade.retrieveProxy(CursorManager.NAME);
}
@@ -0,0 +1,11 @@
* PureMVC Standard Framework for Java - Copyright © 2019 [Saad Shams](https://www.linkedin.com/in/muizz)
* PureMVC - Copyright © 2017 [Futurescale, Inc](http://futurescale.com).
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Futurescale, Inc., PureMVC.org, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,12 @@
## License
* PureMVC Standard Framework for Java - Copyright © 2019 [Saad Shams](https://www.linkedin.com/in/muizz/)
* PureMVC - Copyright © 2019 [Futurescale, Inc](http://futurescale.com)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Futurescale, Inc., PureMVC.org, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,176 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.core;
import org.puremvc.java.interfaces.ICommand;
import org.puremvc.java.interfaces.IController;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.interfaces.IView;
import org.puremvc.java.patterns.observer.Observer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;
/**
* A Singleton <code>IController</code> implementation.
*
*
* <P>In PureMVC, the <code>Controller</code> class follows the
* 'Command and Controller' strategy, and assumes these
* responsibilities:</P>
*
* <UL>
* <LI> Remembering which <code>ICommand</code>s
* are intended to handle which <code>INotifications</code>.</LI>
* <LI> Registering itself as an <code>IObserver</code> with
* the <code>View</code> for each <code>INotification</code>
* that it has an <code>ICommand</code> mapping for.</LI>
* <LI> Creating a new instance of the proper <code>ICommand</code>
* to handle a given <code>INotification</code> when notified by the <code>View</code>.</LI>
* <LI> Calling the <code>ICommand</code>'s <code>execute</code>
* method, passing in the <code>INotification</code>.</LI>
* </UL>
*
*
* <P>Your application must register <code>ICommands</code> with the
* Controller.</P>
*
* <P>The simplest way is to subclass <code>Facade</code>,
* and use its <code>initializeController</code> method to add your
* registrations.</P>
*
* @see View View
* @see org.puremvc.java.patterns.observer.Observer Observer
* @see org.puremvc.java.patterns.observer.Notification Notification
* @see org.puremvc.java.patterns.command.SimpleCommand SimpleCommand
* @see org.puremvc.java.patterns.command.MacroCommand MacroCommand
*/
public class Controller implements IController {
// Local reference to View
protected IView view;
// Mapping of Notification names to Command Supplier Functions
protected ConcurrentMap<String, Supplier<ICommand>> commandMap;
// Singleton instance
protected static IController instance;
// Message Constants
protected final String SINGLETON_MSG = "Controller Singleton already constructed!";
/**
* Constructor.
*
* <P>This <code>IController</code> implementation is a Singleton,
* so you should not call the constructor
* directly, but instead call the static Singleton
* Factory method <code>Controller.getInstance()</code></P>
*
* @throws Error Error if Singleton instance has already been constructed
*
*/
public Controller() {
if(instance != null) throw new Error(SINGLETON_MSG);
instance = this;
commandMap = new ConcurrentHashMap<>();
initializeController();
}
/**
* <P>Initialize the Singleton <code>Controller</code> instance.</P>
*
* <P>Called automatically by the constructor.</P>
*
* <P>Note that if you are using a subclass of <code>View</code>
* in your application, you should <i>also</i> subclass <code>Controller</code>
* and override the <code>initializeController</code> method in the
* following way:</P>
*
* <PRE>
* {@code // ensure that the Controller is talking to my IView implementation
* override public function initializeController( ) : void
* {
* view = MyView.getInstance(() -> new MyView());
* }
* }
* </PRE>
*/
public void initializeController() {
view = View.getInstance(() -> new View());
}
/**
* <P><code>Controller</code> Singleton Factory method.</P>
*
* @param factory controller supplier function
* @return the Singleton instance of <code>Controller</code>
*/
public synchronized static IController getInstance(Supplier<IController> factory) {
if(instance == null) instance = factory.get();
return instance;
}
/**
* <P>If an <code>ICommand</code> has previously been registered
* to handle a the given <code>INotification</code>, then it is executed.</P>
*
* @param notification an <code>INotification</code>
*/
public void executeCommand(INotification notification) {
Supplier<ICommand> commandSupplier = commandMap.get(notification.getName());
if(commandSupplier == null) return;
ICommand commandInstance = commandSupplier.get();
commandInstance.execute(notification);
}
/**
* <P>Register a particular <code>ICommand</code> class as the handler
* for a particular <code>INotification</code>.</P>
*
* <P>If an <code>ICommand</code> has already been registered to
* handle <code>INotification</code>s with this name, it is no longer
* used, the new <code>ICommand</code> is used instead.</P>
*
* <P>The Observer for the new ICommand is only created if this the
* first time an ICommand has been regisered for this Notification name.</P>
*
* @param notificationName the name of the <code>INotification</code>
* @param commandSupplier the <code>Class</code> of the <code>ICommand</code>
*/
public void registerCommand(String notificationName, Supplier<ICommand> commandSupplier) {
if(commandMap.get(notificationName) == null) {
view.registerObserver(notificationName, new Observer(this::executeCommand, this));
}
commandMap.put(notificationName, commandSupplier);
}
/**
* <P>Remove a previously registered <code>ICommand</code> to <code>INotification</code> mapping.</P>
*
* @param notificationName the name of the <code>INotification</code> to remove the <code>ICommand</code> mapping for
*/
public void removeCommand(String notificationName) {
if(hasCommand(notificationName)) {
view.removeObserver(notificationName, this);
commandMap.remove(notificationName);
}
}
/**
* <P>Check if a Command is registered for a given Notification</P>
*
* @param notificationName notification name
* @return whether a Command is currently registered for the given <code>notificationName</code>.
*/
public boolean hasCommand(String notificationName) {
return commandMap.get(notificationName) != null;
}
}
@@ -0,0 +1,137 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.core;
import org.puremvc.java.interfaces.IModel;
import org.puremvc.java.interfaces.IProxy;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;
/**
* <P>A Singleton <code>IModel</code> implementation.</P>
*
* <P>In PureMVC, the <code>Model</code> class provides
* access to model objects (Proxies) by named lookup.</P>
*
* <P>The <code>Model</code> assumes these responsibilities:</P>
*
* <UL>
* <LI>Maintain a cache of <code>IProxy</code> instances.</LI>
* <LI>Provide methods for registering, retrieving, and removing
* <code>IProxy</code> instances.</LI>
* </UL>
*
* <P>Your application must register <code>IProxy</code> instances
* with the <code>Model</code>. Typically, you use an
* <code>ICommand</code> to create and register <code>IProxy</code>
* instances once the <code>Facade</code> has initialized the Core
* actors.</P>
*
* @see org.puremvc.java.patterns.proxy.Proxy Proxy
* @see org.puremvc.java.interfaces.IProxy IProxy
*/
public class Model implements IModel {
// Mapping of proxyNames to IProxy instances
protected ConcurrentMap<String, IProxy> proxyMap;
// Singleton instance
protected static IModel instance;
// Message Constants
protected final String SINGLETON_MSG = "Model Singleton already constructed!";
/**
* <P>Constructor.</P>
*
* <P>This <code>IModel</code> implementation is a Singleton,
* so you should not call the constructor
* directly, but instead call the static Singleton
* Factory method <code>Model.getInstance()</code></P>
*
* @throws Error Error if Singleton instance has already been constructed
*
*/
public Model() {
if(instance != null) throw new Error(SINGLETON_MSG);
instance = this;
proxyMap = new ConcurrentHashMap<>();
initializeModel();
}
/**
* <P>Initialize the Singleton <code>Model</code> instance.</P>
*
* <P>Called automatically by the constructor, this
* is your opportunity to initialize the Singleton
* instance in your subclass without overriding the
* constructor.</P>
*
*/
protected void initializeModel() {
}
/**
* <P><code>Model</code> Singleton Factory method.</P>
*
* @param factory model supplier function
* @return the Singleton instance
*/
public synchronized static IModel getInstance(Supplier<IModel> factory) {
if(instance == null) instance = factory.get();
return instance;
}
/**
* <P>Register an <code>IProxy</code> with the <code>Model</code>.</P>
*
* @param proxy an <code>IProxy</code> to be held by the <code>Model</code>.
*/
public void registerProxy(IProxy proxy) {
proxyMap.put(proxy.getProxyName(), proxy);
proxy.onRegister();
}
/**
* <P>Retrieve an <code>IProxy</code> from the <code>Model</code>.</P>
*
* @param proxyName proxy name
* @return the <code>IProxy</code> instance previously registered with the given <code>proxyName</code>.
*/
public IProxy retrieveProxy(String proxyName) {
return proxyMap.get(proxyName);
}
/**
* <P>Check if a Proxy is registered</P>
*
* @param proxyName proxy name
* @return whether a Proxy is currently registered with the given <code>proxyName</code>.
*/
public boolean hasProxy(String proxyName) {
return proxyMap.containsKey(proxyName);
}
/**
* <P>Remove an <code>IProxy</code> from the <code>Model</code>.</P>
*
* @param proxyName name of the <code>IProxy</code> instance to be removed.
* @return the <code>IProxy</code> that was removed from the <code>Model</code>
*/
public IProxy removeProxy(String proxyName) {
IProxy proxy = proxyMap.get(proxyName);
if(proxy != null) {
proxyMap.remove(proxyName);
proxy.onRemove();
}
return proxy;
}
}
@@ -0,0 +1,251 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.core;
import org.puremvc.java.interfaces.IMediator;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.interfaces.IObserver;
import org.puremvc.java.interfaces.IView;
import org.puremvc.java.patterns.observer.Observer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;
/**
* <P>A Singleton <code>IView</code> implementation.</P>
*
* <P>In PureMVC, the <code>View</code> class assumes these responsibilities:</P>
*
* <UL>
* <LI>Maintain a cache of <code>IMediator</code> instances.</LI>
* <LI>Provide methods for registering, retrieving, and removing <code>IMediators</code>.</LI>
* <LI>Notifiying <code>IMediators</code> when they are registered or removed.</LI>
* <LI>Managing the observer lists for each <code>INotification</code> in the application.</LI>
* <LI>Providing a method for attaching <code>IObservers</code> to an <code>INotification</code>'s observer list.</LI>
* <LI>Providing a method for broadcasting an <code>INotification</code>.</LI>
* <LI>Notifying the <code>IObservers</code> of a given <code>INotification</code> when it broadcast.</LI>
* </UL>
*
* @see org.puremvc.java.patterns.mediator.Mediator Mediator
* @see org.puremvc.java.patterns.observer.Observer Observer
* @see org.puremvc.java.patterns.observer.Notification Notification
*/
public class View implements IView {
// Mapping of Mediator names to Mediator instances
protected ConcurrentMap<String, IMediator> mediatorMap;
// Mapping of Notification names to Observer lists
protected ConcurrentMap<String, List<IObserver>> observerMap;
// Singleton instance
protected static IView instance;
// Message Constants
protected final String SINGLETON_MSG = "View Singleton already constructed!";
/**
* <P>Constructor.</P>
*
* <P>This <code>IView</code> implementation is a Singleton,
* so you should not call the constructor
* directly, but instead call the static Singleton
* Factory method <code>View.getInstance()</code></P>
*
* @throws Error Error if Singleton instance has already been constructed
*
*/
public View() {
if(instance != null) new Error(SINGLETON_MSG);
instance = this;
mediatorMap = new ConcurrentHashMap<>();
observerMap = new ConcurrentHashMap<>();
initializeView();
}
/**
* <P>View Singleton Factory method.</P>
*
* @param factory view supplier function
* @return the Singleton instance of <code>View</code>
*/
public synchronized static IView getInstance(Supplier<IView> factory) {
if(instance == null) instance = factory.get();
return instance;
}
/**
* <P>Initialize the Singleton View instance.</P>
*
* <P>Called automatically by the constructor, this
* is your opportunity to initialize the Singleton
* instance in your subclass without overriding the
* constructor.</P>
*/
protected void initializeView() {
}
/**
* <P>Register an <code>IObserver</code> to be notified
* of <code>INotifications</code> with a given name.</P>
*
* @param notificationName the name of the <code>INotifications</code> to notify this <code>IObserver</code> of
* @param observer the <code>IObserver</code> to register
*/
public void registerObserver(String notificationName, IObserver observer) {
if(observerMap.get(notificationName) != null) {
observerMap.get(notificationName).add(observer);
} else {
observerMap.put(notificationName, new ArrayList<>(Arrays.asList(observer)));
}
}
/**
* <P>Notify the <code>IObservers</code> for a particular <code>INotification</code>.</P>
*
* <P>All previously attached <code>IObservers</code> for this <code>INotification</code>'s
* list are notified and are passed a reference to the <code>INotification</code> in
* the order in which they were registered.</P>
*
* @param notification the <code>INotification</code> to notify <code>IObservers</code> of.
*/
public void notifyObservers(INotification notification) {
if(observerMap.get(notification.getName()) != null) {
// Get a reference to the observers list for this notification name
List<IObserver> observers_ref = observerMap.get(notification.getName());
// Copy observers from reference array to working array,
// since the reference array may change during the notification loop
List<IObserver> observers = new ArrayList<>(observers_ref);
// Notify Observers from the working array
observers.forEach(observer -> observer.notifyObserver(notification));
}
}
/**
* <P>Remove the observer for a given notifyContext from an observer list for a given Notification name.</P>
*
* @param notificationName which observer list to remove from
* @param notifyContext remove the observer with this object as its notifyContext
*/
public void removeObserver(String notificationName, Object notifyContext) {
// the observer list for the notification under inspection
List<IObserver> observers = observerMap.get(notificationName);
// find the observer for the notifyContext
for(int i=0; i<observers.size(); i++) {
if(observers.get(i).compareNotifyContext(notifyContext) == true) {
// there can only be one Observer for a given notifyContext
// in any given Observer list, so remove it and break
observers.remove(i);
break;
}
}
// Also, when a Notification's Observer list length falls to
// zero, delete the notification key from the observer map
if(observers.size() == 0) {
observerMap.remove(notificationName);
}
}
/**
* <P>Register an <code>IMediator</code> instance with the <code>View</code>.</P>
*
* <P>Registers the <code>IMediator</code> so that it can be retrieved by name,
* and further interrogates the <code>IMediator</code> for its
* <code>INotification</code> interests.</P>
*
* <P>If the <code>IMediator</code> returns any <code>INotification</code>
* names to be notified about, an <code>Observer</code> is created encapsulating
* the <code>IMediator</code> instance's <code>handleNotification</code> method
* and registering it as an <code>Observer</code> for all <code>INotifications</code> the
* <code>IMediator</code> is interested in.</P>
*
* @param mediator a reference to the <code>IMediator</code> instance
*/
public void registerMediator(IMediator mediator) {
// do not allow re-registration (you must to removeMediator fist)
if(mediatorMap.get(mediator.getMediatorName()) != null) return;
// Register the Mediator for retrieval by name
mediatorMap.put(mediator.getMediatorName(), mediator);
// Get Notification interests, if any.
String[] interests = mediator.listNotificationInterests();
// Register Mediator as an observer for each of its notification interests
if(interests.length > 0) {
// Create Observer referencing this mediator's handlNotification method
IObserver observer = new Observer(mediator::handleNotification, mediator);
// Register Mediator as Observer for its list of Notification interests
for(int i=0; i<interests.length; i++) {
registerObserver(interests[i], observer);
}
}
// alert the mediator that it has been registered
mediator.onRegister();
}
/**
* <P>Retrieve an <code>IMediator</code> from the <code>View</code>.</P>
*
* @param mediatorName the name of the <code>IMediator</code> instance to retrieve.
* @return the <code>IMediator</code> instance previously registered with the given <code>mediatorName</code>.
*/
public IMediator retrieveMediator(String mediatorName) {
return mediatorMap.get(mediatorName);
}
/**
* <P>Remove an <code>IMediator</code> from the <code>View</code>.</P>
*
* @param mediatorName name of the <code>IMediator</code> instance to be removed.
* @return the <code>IMediator</code> that was removed from the <code>View</code>
*/
public IMediator removeMediator(String mediatorName) {
// Retrieve the named mediator
IMediator mediator = mediatorMap.get(mediatorName);
if(mediator != null) {
// for every notification this mediator is interested in...
String[] interests = mediator.listNotificationInterests();
for(int i=0; i<interests.length; i++) {
// remove the observer linking the mediator
// to the notification interest
removeObserver(interests[i], mediator);
}
// remove the mediator from the map
mediatorMap.remove(mediatorName);
// alert the mediator that it has been removed
mediator.onRemove();
}
return mediator;
}
/**
* <P>Check if a Mediator is registered or not</P>
*
* @param mediatorName mediator name
* @return whether a Mediator is registered with the given <code>mediatorName</code>.
*/
public boolean hasMediator(String mediatorName) {
return mediatorMap.containsKey(mediatorName);
}
}
@@ -0,0 +1,24 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
/**
* The interface definition for a PureMVC Command.
*
* @see org.puremvc.java.interfaces INotification
*/
public interface ICommand extends INotifier {
/**
* <P>Execute the <code>ICommand</code>'s logic to handle a given <code>INotification</code>.</P>
*
* @param notification an <code>INotification</code> to handle.
*/
void execute(INotification notification);
}
@@ -0,0 +1,67 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
import java.util.function.Supplier;
/**
* <P>The interface definition for a PureMVC Controller.</P>
*
* <P>In PureMVC, an <code>IController</code> implementor
* follows the 'Command and Controller' strategy, and
* assumes these responsibilities:</P>
*
* <UL>
* <LI> Remembering which <code>ICommand</code>s
* are intended to handle which <code>INotifications</code>.</LI>
* <LI> Registering itself as an <code>IObserver</code> with
* the <code>View</code> for each <code>INotification</code>
* that it has an <code>ICommand</code> mapping for.</LI>
* <LI> Creating a new instance of the proper <code>ICommand</code>
* to handle a given <code>INotification</code> when notified by the <code>View</code>.</LI>
* <LI> Calling the <code>ICommand</code>'s <code>execute</code>
* method, passing in the <code>INotification</code>.</LI>
* </UL>
*
* @see org.puremvc.java.interfaces INotification
* @see org.puremvc.java.interfaces ICommand
*/
public interface IController {
/**
* <P>Register a particular <code>ICommand</code> class as the handler
* for a particular <code>INotification</code>.</P>
*
* @param notificationName the name of the <code>INotification</code>
* @param commandSupplier the Supplier Function of the <code>ICommand</code>
*/
void registerCommand(String notificationName, Supplier<ICommand> commandSupplier);
/**
* <P>Execute the <code>ICommand</code> previously registered as the
* handler for <code>INotification</code>s with the given notification name.</P>
*
* @param notification the <code>INotification</code> to execute the associated <code>ICommand</code> for
*/
void executeCommand(INotification notification);
/**
* <P>Remove a previously registered <code>ICommand</code> to <code>INotification</code> mapping.</P>
*
* @param notificationName the name of the <code>INotification</code> to remove the <code>ICommand</code> mapping for
*/
void removeCommand(String notificationName);
/**
* <P>Check if a Command is registered for a given Notification</P>
*
* @param notificationName notification name
* @return whether a Command is currently registered for the given <code>notificationName</code>.
*/
boolean hasCommand(String notificationName);
}
@@ -0,0 +1,130 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
import java.util.function.Supplier;
/**
* <P>The interface definition for a PureMVC Facade.</P>
*
* <P>The Facade Pattern suggests providing a single
* class to act as a central point of communication
* for a subsystem.</P>
*
* <P>In PureMVC, the Facade acts as an interface between
* the core MVC actors (Model, View, Controller) and
* the rest of your application.</P>
*
* @see IModel IModel
* @see IView IView
* @see org.puremvc.java.interfaces.IController IController
* @see org.puremvc.java.interfaces.ICommand ICommand
* @see org.puremvc.java.interfaces.INotification INotification
*/
public interface IFacade extends INotifier {
/**
* <P>Register an <code>IProxy</code> with the <code>Model</code> by name.</P>
*
* @param proxy the <code>IProxy</code> to be registered with the <code>Model</code>.
*/
void registerProxy(IProxy proxy);
/**
* <P>Retrieve a <code>IProxy</code> from the <code>Model</code> by name.</P>
*
* @param proxyName the name of the <code>IProxy</code> instance to be retrieved.
* @return the <code>IProxy</code> previously regisetered by <code>proxyName</code> with the <code>Model</code>.
*/
<T extends IProxy> T retrieveProxy(String proxyName);
/**
* <P>Remove an <code>IProxy</code> instance from the <code>Model</code> by name.</P>
*
* @param proxyName the <code>IProxy</code> to remove from the <code>Model</code>.
* @return the <code>IProxy</code> that was removed from the <code>Model</code>
*/
<T extends IProxy> T removeProxy(String proxyName);
/**
* <P>Check if a Proxy is registered</P>
*
* @param proxyName proxy name
* @return whether a Proxy is currently registered with the given <code>proxyName</code>.
*/
boolean hasProxy(String proxyName);
/**
* <P>Register an <code>ICommand</code> with the <code>Controller</code>.</P>
*
* @param notificationName the name of the <code>INotification</code> to associate the <code>ICommand</code> with.
* @param commandSupplier a reference to the Command Supplier Function of the <code>ICommand</code>.
*/
void registerCommand(String notificationName, Supplier<ICommand> commandSupplier);
/**
* <P>Remove a previously registered <code>ICommand</code> to <code>INotification</code> mapping from the Controller.</P>
*
* @param notificationName the name of the <code>INotification</code> to remove the <code>ICommand</code> mapping for
*/
void removeCommand(String notificationName);
/**
* <P>Check if a Command is registered for a given Notification</P>
*
* @param notificationName notification name
* @return whether a Command is currently registered for the given <code>notificationName</code>.
*/
boolean hasCommand(String notificationName);
/**
* <P>Register an <code>IMediator</code> instance with the <code>View</code>.</P>
*
* @param mediator a reference to the <code>IMediator</code> instance
*/
void registerMediator(IMediator mediator);
/**
* <P>Retrieve an <code>IMediator</code> instance from the <code>View</code>.</P>
*
* @param mediatorName the name of the <code>IMediator</code> instance to retrievve
* @return the <code>IMediator</code> previously registered with the given <code>mediatorName</code>.
*/
<T extends IMediator> T retrieveMediator(String mediatorName);
/**
* <P>Remove a <code>IMediator</code> instance from the <code>View</code>.</P>
*
* @param mediatorName name of the <code>IMediator</code> instance to be removed.
* @return the <code>IMediator</code> instance previously registered with the given <code>mediatorName</code>.
*/
<T extends IMediator> T removeMediator(String mediatorName);
/**
* <P>Check if a Mediator is registered or not</P>
*
* @param mediatorName mediator name
* @return whether a Mediator is registered with the given <code>mediatorName</code>.
*/
boolean hasMediator(String mediatorName);
/**
* <P>Notify the <code>IObservers</code> for a particular <code>INotification</code>.</P>
*
* <P>All previously attached <code>IObservers</code> for this <code>INotification</code>'s
* list are notified and are passed a reference to the <code>INotification</code> in
* the order in which they were registered.</P>
*
* <P>NOTE: Use this method only if you are sending custom Notifications. Otherwise
* use the sendNotification method which does not require you to create the
* Notification instance.</P>
*
* @param notification the <code>INotification</code> to notify <code>IObservers</code> of.
*/
void notifyObservers(INotification notification);
}
@@ -0,0 +1,149 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
/**
* <P>The interface definition for a PureMVC Mediator.</P>
*
* <P>In PureMVC, <code>IMediator</code> implementors assume these responsibilities:</P>
*
* <UL>
* <LI>Implement a common method which returns a list of all <code>INotification</code>s
* the <code>IMediator</code> has interest in.</LI>
* <LI>Implement a notification callback method.</LI>
* <LI>Implement methods that are called when the IMediator is registered or removed from the View.</LI>
* </UL>
*
* <P>Additionally, <code>IMediator</code>s typically:</P>
*
* <UL>
* <LI>Act as an intermediary between one or more view components such as text boxes or
* list controls, maintaining references and coordinating their behavior.</LI>
* <LI>In Flash-based apps, this is often the place where event listeners are
* added to view components, and their handlers implemented.</LI>
* <LI>Respond to and generate <code>INotifications</code>, interacting with of
* the rest of the PureMVC app.</LI>
* </UL>
*
* <P>When an <code>IMediator</code> is registered with the <code>IView</code>,
* the <code>IView</code> will call the <code>IMediator</code>'s
* <code>listNotificationInterests</code> method. The <code>IMediator</code> will
* return an <code>Array</code> of <code>INotification</code> names which
* it wishes to be notified about.</P>
*
* <P>The <code>IView</code> will then create an <code>Observer</code> object
* encapsulating that <code>IMediator</code>'s (<code>handleNotification</code>) method
* and register it as an Observer for each <code>INotification</code> name returned by
* <code>listNotificationInterests</code>.</P>
*
* <P>A concrete IMediator implementor usually looks something like this:</P>
*
* <pre>
* {@code import org.puremvc.as3.multicore.patterns.mediator.*;
* import org.puremvc.as3.multicore.patterns.observer.*;
* import org.puremvc.as3.multicore.core.view.*;
*
* import com.me.myapp.model.*;
* import com.me.myapp.view.*;
* import com.me.myapp.controller.*;
*
* import javax.swing.JComboBox;
* import java.awt.event.ActionListener;
*
* public class MyMediator extends Mediator implements IMediator, ActionListener {
*
* public MyMediator( Object viewComponent ) {
* super( viewComponent );
* combo.addActionListener( this );
* }
*
* public String[] listNotificationInterests() {
* return [ MyFacade.SET_SELECTION,
* MyFacade.SET_DATAPROVIDER ];
* }
*
* public void handleNotification( INotification notification ) {
* switch ( notification.getName() ) {
* case MyFacade.SET_SELECTION:
* setSelection(notification);
* break;
* case MyFacade.SET_DATAPROVIDER:
* setDataProvider(notification);
* break;
* }
* }
*
* // Set the data provider of the combo box
* protected void setDataProvider( INotification notification ) {
* combo.setModel(ComboBoxModel<String>(notification.getBody()));
* }
*
* // Invoked when the combo box dispatches a change event, we send a
* // notification with the
* public void actionPerformed(ActionEvent event) {
* sendNotification( MyFacade.MYCOMBO_CHANGED, this );
* }
*
* // A private getter for accessing the view object by class
* protected JComboBox getViewComponent() {
* return viewComponent;
* }
*
* }
* }
* </pre>
*
* @see org.puremvc.java.interfaces.INotification INotification
*/
public interface IMediator<V> extends INotifier {
/**
* <P>Get the <code>IMediator</code> instance name</P>
*
* @return the <code>IMediator</code> instance name
*/
String getMediatorName();
/**
* <P>Get the <code>IMediator</code>'s view component.</P>
*
* @return Object the view component
*/
V getViewComponent();
/**
* <P>Set the <code>IMediator</code>'s view component.</P>
*
* @param viewComponent the view component
*/
void setViewComponent(V viewComponent);
/**
* <P>List <code>INotification</code> interests.</P>
*
* @return an <code>Array</code> of the <code>INotification</code> names this <code>IMediator</code> has an interest in.
*/
String[] listNotificationInterests();
/**
* <P>Handle an <code>INotification</code>.</P>
*
* @param notification the <code>INotification</code> to be handled
*/
void handleNotification(INotification notification);
/**
* <P>Called by the View when the Mediator is registered</P>
*/
void onRegister();
/**
* <P>Called by the View when the Mediator is removed</P>
*/
void onRemove();
}
@@ -0,0 +1,55 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
/**
* <P>The interface definition for a PureMVC Model.</P>
*
* <P>In PureMVC, <code>IModel</code> implementors provide
* access to <code>IProxy</code> objects by named lookup. </P>
*
* <P>An <code>IModel</code> assumes these responsibilities:</P>
*
* <UL>
* <LI>Maintain a cache of <code>IProxy</code> instances</LI>
* <LI>Provide methods for registering, retrieving, and removing <code>IProxy</code> instances</LI>
* </UL>
*/
public interface IModel {
/**
* <P>Register an <code>IProxy</code> instance with the <code>Model</code>.</P>
*
* @param proxy an object reference to be held by the <code>Model</code>.
*/
void registerProxy(IProxy proxy);
/**
* <P>Retrieve an <code>IProxy</code> instance from the Model.</P>
*
* @param proxyName proxy name
* @return the <code>IProxy</code> instance previously registered with the given <code>proxyName</code>.
*/
<T extends IProxy> T retrieveProxy(String proxyName);
/**
* <P>Remove an <code>IProxy</code> instance from the Model.</P>
*
* @param proxyName name of the <code>IProxy</code> instance to be removed.
* @return the <code>IProxy</code> that was removed from the <code>Model</code>
*/
<T extends IProxy> T removeProxy(String proxyName);
/**
* <P>Check if a Proxy is registered</P>
*
* @param proxyName proxy name
* @return whether a Proxy is currently registered with the given <code>proxyName</code>.
*/
boolean hasProxy(String proxyName);
}
@@ -0,0 +1,86 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
/**
* <P>The interface definition for a PureMVC Notification.</P>
*
* <P>PureMVC does not rely upon underlying event models such
* as the one provided with Flash, and ActionScript 3 does
* not have an inherent event model.</P>
*
* <P>The Observer Pattern as implemented within PureMVC exists
* to support event-driven communication between the
* application and the actors of the MVC triad.</P>
*
* <P>Notifications are not meant to be a replacement for Events
* in Flex/Flash/AIR. Generally, <code>IMediator</code> implementors
* place event listeners on their view components, which they
* then handle in the usual way. This may lead to the broadcast of <code>Notification</code>s to
* trigger <code>ICommand</code>s or to communicate with other <code>IMediators</code>. <code>IProxy</code> and <code>ICommand</code>
* instances communicate with each other and <code>IMediator</code>s
* by broadcasting <code>INotification</code>s.</P>
*
* <P>A key difference between Flash <code>Event</code>s and PureMVC
* <code>Notification</code>s is that <code>Event</code>s follow the
* 'Chain of Responsibility' pattern, 'bubbling' up the display hierarchy
* until some parent component handles the <code>Event</code>, while
* PureMVC <code>Notification</code>s follow a 'Publish/Subscribe'
* pattern. PureMVC classes need not be related to each other in a
* parent/child relationship in order to communicate with one another
* using <code>Notification</code>s.</P>
*
* @see IView IView
* @see IObserver IObserver
*/
public interface INotification {
/**
* <P>Get the name of the <code>INotification</code> instance.
* No setter, should be set by constructor only</P>
*
* @return notification name
*/
String getName();
/**
* <P>Set the body of the <code>INotification</code> instance</P>
*
* @param body notification body
*/
void setBody(Object body);
/**
* <P>Get the body of the <code>INotification</code> instance</P>
*
* @return notification body
*/
<T> T getBody();
/**
* <P>Set the type of the <code>INotification</code> instance</P>
*
* @param type notification type
*/
void setType(String type);
/**
* <P>Get the type of the <code>INotification</code> instance</P>
*
* @return notification type
*/
String getType();
/**
* <P>Get the string representation of the <code>INotification</code> instance</P>
*
* @return string representation of <code>INotification</code>
*/
String toString();
}
@@ -0,0 +1,64 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
/**
* <P>The interface definition for a PureMVC Notifier.</P>
*
* <P><code>MacroCommand, Command, Mediator</code> and <code>Proxy</code>
* all have a need to send <code>Notifications</code>.</P>
*
* <P>The <code>INotifier</code> interface provides a common method called
* <code>sendNotification</code> that relieves implementation code of
* the necessity to actually construct <code>Notifications</code>.</P>
*
* <P>The <code>Notifier</code> class, which all of the above mentioned classes
* extend, also provides an initialized reference to the <code>Facade</code>
* Singleton, which is required for the convienience method
* for sending <code>Notifications</code>, but also eases implementation as these
* classes have frequent <code>Facade</code> interactions and usually require
* access to the facade anyway.</P>
*
* @see IFacade IFacade
* @see org.puremvc.java.interfaces.INotification INotification
*/
public interface INotifier {
/**
* <P>Send a <code>INotification</code>.</P>
*
* <P>Convenience method to prevent having to construct new
* notification instances in our implementation code.</P>
*
* @param notificationName the name of the notification to send
* @param body the body of the notification
* @param type the type of the notification
*/
void sendNotification(String notificationName, Object body, String type);
/**
* <P>Send a <code>INotification</code>.</P>
*
* <P>Convenience method to prevent having to construct new
* notification instances in our implementation code.</P>
*
* @param notificationName the name of the notification to send
* @param body the body of the notification
*/
void sendNotification(String notificationName, Object body);
/**
* <P>Send a <code>INotification</code>.</P>
*
* <P>Convenience method to prevent having to construct new
* notification instances in our implementation code.</P>
*
* @param notificationName the name of the notification to send
*/
void sendNotification(String notificationName);
}
@@ -0,0 +1,81 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
import java.util.function.Consumer;
/**
* <P>The interface definition for a PureMVC Observer.</P>
*
* <P>In PureMVC, <code>IObserver</code> implementors assume these responsibilities:</P>
*
* <UL>
* <LI>Encapsulate the notification (callback) method of the interested object.</LI>
* <LI>Encapsulate the notification context (this) of the interested object.</LI>
* <LI>Provide methods for setting the interested object' notification method and context.</LI>
* <LI>Provide a method for notifying the interested object.</LI>
* </UL>
*
* <P>PureMVC does not rely upon underlying event
* models such as the one provided with Flash,
* and ActionScript 3 does not have an inherent
* event model.</P>
*
* <P>The Observer Pattern as implemented within
* PureMVC exists to support event driven communication
* between the application and the actors of the
* MVC triad.</P>
*
* <P>An Observer is an object that encapsulates information
* about an interested object with a notification method that
* should be called when an <code>INotification</code> is broadcast. The Observer then
* acts as a proxy for notifying the interested object.</P>
*
* <P>Observers can receive <code>Notification</code>s by having their
* <code>notifyObserver</code> method invoked, passing
* in an object implementing the <code>INotification</code> interface, such
* as a subclass of <code>Notification</code>.</P>
*
* @see IView IView
* @see org.puremvc.java.interfaces.INotification INotification
*/
public interface IObserver {
/**
* <P>Set the notification method.</P>
*
* <P>The notification method should take one parameter of type <code>INotification</code></P>
*
* @param notifyMethod the notification (callback) method of the interested object
*/
void setNotifyMethod(Consumer<INotification> notifyMethod);
/**
* <P>Set the notification context.</P>
*
* @param notifyContext the notification context (this) of the interested object
*/
void setNotifyContext(Object notifyContext);
/**
* <P>Notify the interested object.</P>
*
* @param notification the <code>INotification</code> to pass to the interested object's notification method
*/
void notifyObserver(INotification notification);
/**
* <P>Compare the given object to the notification context object.</P>
*
* @param object the object to compare.
* @return boolean indicating if the notification context and the object are the same.
*/
boolean compareNotifyContext(Object object);
}
@@ -0,0 +1,62 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
/**
* <P>The interface definition for a PureMVC Proxy.</P>
*
* <P>In PureMVC, <code>IProxy</code> implementors assume these responsibilities:</P>
*
* <UL>
* <LI>Implement a common method which returns the name of the Proxy.</LI>
* <LI>Provide methods for setting and getting the data object.</LI>
* </UL>
*
* <P>Additionally, <code>IProxy</code>s typically:</P>
*
* <UL>
* <LI>Maintain references to one or more pieces of model data.</LI>
* <LI>Provide methods for manipulating that data.</LI>
* <LI>Generate <code>INotifications</code> when their model data changes.</LI>
* <LI>Expose their name as a <code>public static const</code> called <code>NAME</code>, if they are not instantiated multiple times.</LI>
* <LI>Encapsulate interaction with local or remote services used to fetch and persist model data.</LI>
* </UL>
*/
public interface IProxy extends INotifier {
/**
* <P>Get the Proxy name</P>
*
* @return the Proxy instance name
*/
String getProxyName();
/**
* <P>Set the data object</P>
*
* @param data the data object
*/
void setData(Object data);
/**
* <P>Get the data object</P>
*
* @return the data as type Object
*/
Object getData();
/**
* <P>Called by the Model when the Proxy is registered</P>
*/
void onRegister();
/**
* <P>Called by the Model when the Proxy is removed</P>
*/
void onRemove();
}
@@ -0,0 +1,100 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.interfaces;
/**
* <P>The interface definition for a PureMVC View.</P>
*
* <P>In PureMVC, <code>IView</code> implementors assume these responsibilities:</P>
*
* <P>In PureMVC, the <code>View</code> class assumes these responsibilities:</P>
*
* <UL>
* <LI>Maintain a cache of <code>IMediator</code> instances.</LI>
* <LI>Provide methods for registering, retrieving, and removing <code>IMediators</code>.</LI>
* <LI>Managing the observer lists for each <code>INotification</code> in the application.</LI>
* <LI>Providing a method for attaching <code>IObservers</code> to an <code>INotification</code>'s observer list.</LI>
* <LI>Providing a method for broadcasting an <code>INotification</code>.</LI>
* <LI>Notifying the <code>IObservers</code> of a given <code>INotification</code> when it broadcast.</LI>
* </UL>
*
* @see org.puremvc.java.interfaces.IMediator IMediator
* @see org.puremvc.java.interfaces.IObserver IObserver
* @see org.puremvc.java.interfaces.INotification INotification
*/
public interface IView {
/**
* <P>Register an <code>IObserver</code> to be notified
* of <code>INotifications</code> with a given name.</P>
*
* @param notificationName the name of the <code>INotifications</code> to notify this <code>IObserver</code> of
* @param observer the <code>IObserver</code> to register
*/
void registerObserver(String notificationName, IObserver observer);
/**
* <P>Remove a group of observers from the observer list for a given Notification name.</P>
*
* @param notificationName which observer list to remove from
* @param notifyContext removed the observers with this object as their notifyContext
*/
void removeObserver(String notificationName, Object notifyContext);
/**
* <P>Notify the <code>IObservers</code> for a particular <code>INotification</code>.</P>
*
* <P>All previously attached <code>IObservers</code> for this <code>INotification</code>'s
* list are notified and are passed a reference to the <code>INotification</code> in
* the order in which they were registered.</P>
*
* @param notification the <code>INotification</code> to notify <code>IObservers</code> of.
*/
void notifyObservers(INotification notification);
/**
* <P>Register an <code>IMediator</code> instance with the <code>View</code>.</P>
*
* <P>Registers the <code>IMediator</code> so that it can be retrieved by name,
* and further interrogates the <code>IMediator</code> for its
* <code>INotification</code> interests.</P>
*
* <P>If the <code>IMediator</code> returns any <code>INotification</code>
* names to be notified about, an <code>Observer</code> is created encapsulating
* the <code>IMediator</code> instance's <code>handleNotification</code> method
* and registering it as an <code>Observer</code> for all <code>INotifications</code> the
* <code>IMediator</code> is interested in.</p>
*
* @param mediator a reference to the <code>IMediator</code> instance
*/
void registerMediator(IMediator mediator);
/**
* <P>Retrieve an <code>IMediator</code> from the <code>View</code>.</P>
*
* @param mediatorName the name of the <code>IMediator</code> instance to retrieve.
* @return the <code>IMediator</code> instance previously registered with the given <code>mediatorName</code>.
*/
<T extends IMediator> T retrieveMediator(String mediatorName);
/**
* <P>Remove an <code>IMediator</code> from the <code>View</code>.</P>
*
* @param mediatorName name of the <code>IMediator</code> instance to be removed.
* @return the <code>IMediator</code> that was removed from the <code>View</code>
*/
<T extends IMediator> T removeMediator(String mediatorName);
/**
* <P>Check if a Mediator is registered or not</P>
*
* @param mediatorName mediator name
* @return whether a Mediator is registered with the given <code>mediatorName</code>.
*/
boolean hasMediator(String mediatorName);
}
@@ -0,0 +1,111 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.patterns.command;
import org.puremvc.java.interfaces.ICommand;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.observer.Notifier;
import java.util.Vector;
import java.util.function.Supplier;
/**
* <P>A base <code>ICommand</code> implementation that executes other <code>ICommand</code>s.</P>
*
* <P>A <code>MacroCommand</code> maintains an list of
* <code>ICommand</code> Class references called <i>SubCommands</i>.</P>
*
* <P>When <code>execute</code> is called, the <code>MacroCommand</code>
* instantiates and calls <code>execute</code> on each of its <i>SubCommands</i> turn.
* Each <i>SubCommand</i> will be passed a reference to the original
* <code>INotification</code> that was passed to the <code>MacroCommand</code>'s
* <code>execute</code> method.</P>
*
* <P>Unlike <code>SimpleCommand</code>, your subclass
* should not override <code>execute</code>, but instead, should
* override the <code>initializeMacroCommand</code> method,
* calling <code>addSubCommand</code> once for each <i>SubCommand</i>
* to be executed.</P>
*
* @see org.puremvc.java.core.Controller Controller
* @see org.puremvc.java.patterns.observer.Notification Notification
* @see org.puremvc.java.patterns.command.SimpleCommand SimpleCommand
*/
public class MacroCommand extends Notifier implements ICommand {
private Vector<Supplier<ICommand>> subCommands;
/**
* <P>Constructor.</P>
*
* <P>You should not need to define a constructor,
* instead, override the <code>initializeMacroCommand</code>
* method.</P>
*
* <P>If your subclass does define a constructor, be
* sure to call <code>super()</code>.</P>
*/
public MacroCommand() {
subCommands = new Vector<Supplier<ICommand>>();
initializeMacroCommand();
}
/**
* <P>Initialize the <code>MacroCommand</code>.</P>
*
* <P>In your subclass, override this method to
* initialize the <code>MacroCommand</code>'s <i>SubCommand</i>
* list with <code>ICommand</code> class references like
* this:</P>
*
* <pre>
* {@code
* // Initialize MyMacroCommand
* protected void initializeMacroCommand( )
* {
* addSubCommand( () -> new com.me.myapp.controller.FirstCommand() );
* addSubCommand( () -> new com.me.myapp.controller.SecondCommand() );
* addSubCommand( () -> new com.me.myapp.controller.ThirdCommand() );
* }
* }
* </pre>
*
* <P>Note that <i>SubCommand</i>s may be any <code>ICommand</code> implementor,
* <code>MacroCommand</code>s or <code>SimpleCommands</code> are both acceptable.</P>
*/
protected void initializeMacroCommand() {
}
/**
* <P>Add a <i>SubCommand</i>.</P>
*
* <P>The <i>SubCommands</i> will be called in First In/First Out (FIFO)
* order.</P>
*
* @param factory a reference to the factory of the <code>ICommand</code>.
*/
protected void addSubCommand(Supplier<ICommand> factory) {
subCommands.add(factory);
}
/**
* <P>Execute this <code>MacroCommand</code>'s <i>SubCommands</i>.</P>
*
* <P>The <i>SubCommands</i> will be called in First In/First Out (FIFO)
* order.</P>
*
* @param notification the <code>INotification</code> object to be passsed to each <i>SubCommand</i>.
*/
public void execute(INotification notification) {
while(!subCommands.isEmpty()) {
Supplier<ICommand> commandSupplier = subCommands.remove(0);
ICommand command = commandSupplier.get();
command.execute(notification);
}
}
}
@@ -0,0 +1,38 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.patterns.command;
import org.puremvc.java.interfaces.ICommand;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.observer.Notifier;
/**
* <P>A base <code>ICommand</code> implementation.</P>
*
* <P>Your subclass should override the <code>execute</code>
* method where your business logic will handle the <code>INotification</code>.</P>
*
* @see org.puremvc.java.core.Controller Controller
* @see org.puremvc.java.patterns.observer.Notification Notification
* @see MacroCommand MacroCommand
*/
public class SimpleCommand extends Notifier implements ICommand {
/**
* <P>Fulfill the use-case initiated by the given <code>INotification</code>.</P>
*
* <P>In the Command Pattern, an application use-case typically
* begins with some user action, which results in an <code>INotification</code> being broadcast, which
* is handled by business logic in the <code>execute</code> method of an
* <code>ICommand</code>.</P>
*
* @param notification the <code>INotification</code> to handle.
*/
public void execute(INotification notification) {
}
}
@@ -0,0 +1,431 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.patterns.facade;
import org.puremvc.java.core.Controller;
import org.puremvc.java.core.Model;
import org.puremvc.java.core.View;
import org.puremvc.java.interfaces.*;
import org.puremvc.java.patterns.observer.Notification;
import java.util.function.Supplier;
/**
* <P>A base Singleton <code>IFacade</code> implementation.</P>
*
* <P>In PureMVC, the <code>Facade</code> class assumes these
* responsibilities:</P>
*
* <UL>
* <LI>Initializing the <code>Model</code>, <code>View</code>
* and <code>Controller</code> Singletons.</LI>
* <LI>Providing all the methods defined by the <code>IModel,
* IView, &amp; IController</code> interfaces.</LI>
* <LI>Providing the ability to override the specific <code>Model</code>,
* <code>View</code> and <code>Controller</code> Singletons created.</LI>
* <LI>Providing a single point of contact to the application for
* registering <code>Commands</code> and notifying <code>Observers</code></LI>
* </UL>
*
* <P>Example usage:</P>
* <pre>
* {@code
* import org.puremvc.as3.patterns.facade.Facade;
*
* import com.me.myapp.model.*;
* import com.me.myapp.view.*;
* import com.me.myapp.controller.*;
*
* public class MyFacade extends Facade
* {
* // Notification constants. The Facade is the ideal
* // location for these constants, since any part
* // of the application participating in PureMVC
* // Observer Notification will know the Facade.
* public static final String GO_COMMAND = "go";
*
* // Override Singleton Factory method
* public synchronized static IFacade getInstance(Supplier<IFacade> facadeSupplier) {
* if(instance == null) instance = facadeSupplier.get();
* return instance;
* }
*
* // optional initialization hook for Facade
* public void initializeFacade() {
* super.initializeFacade();
* // do any special subclass initialization here
* }
*
* // optional initialization hook for Controller
* public void initializeController() {
* // call super to use the PureMVC Controller Singleton.
* super.initializeController();
*
* // Otherwise, if you're implmenting your own
* // IController, then instead do:
* // if ( controller != null ) return;
* // controller = MyAppController.getInstance(() -> new MyAppController());
*
* // do any special subclass initialization here
* // such as registering Commands
* registerCommand( GO_COMMAND, () -> new com.me.myapp.controller.GoCommand() )
* }
*
* // optional initialization hook for Model
* public void initializeModel() {
* // call super to use the PureMVC Model Singleton.
* super.initializeModel();
*
* // Otherwise, if you're implmenting your own
* // IModel, then instead do:
* // if ( model != null ) return;
* // model = MyAppModel.getInstance(() -> new MyAppModel());
*
* // do any special subclass initialization here
* // such as creating and registering Model proxys
* // that don't require a facade reference at
* // construction time, such as fixed type lists
* // that never need to send Notifications.
* registerProxy( new USStateNamesProxy() );
*
* // CAREFUL: Can't reference Facade instance in constructor
* // of new Proxys from here, since this step is part of
* // Facade construction! Usually, Proxys needing to send
* // notifications are registered elsewhere in the app
* // for this reason.
* }
*
* // optional initialization hook for View
* public void initializeView() {
* // call super to use the PureMVC View Singleton.
* super.initializeView();
*
* // Otherwise, if you're implmenting your own
* // IView, then instead do:
* // if ( view != null ) return;
* // view = MyAppView.getInstance(() -> new MyAppView());
*
* // do any special subclass initialization here
* // such as creating and registering Mediators
* // that do not need a Facade reference at construction
* // time.
* registerMediator( new LoginMediator() );
*
* // CAREFUL: Can't reference Facade instance in constructor
* // of new Mediators from here, since this is a step
* // in Facade construction! Usually, all Mediators need
* // receive notifications, and are registered elsewhere in
* // the app for this reason.
* }
* }
* }
* </pre>
*
* @see Model Model
* @see View View
* @see Controller Controller
* @see org.puremvc.java.patterns.observer.Notification Notification
* @see org.puremvc.java.patterns.mediator.Mediator Mediator
* @see org.puremvc.java.patterns.proxy.Proxy Proxy
* @see org.puremvc.java.patterns.command.SimpleCommand SimpleCommand
* @see org.puremvc.java.patterns.command.MacroCommand MacroCommand
*/
public class Facade implements IFacade {
// Private references to Model, View and Controlle
protected IController controller;
protected IModel model;
protected IView view;
// The Singleton Facade instance.
protected static IFacade instance;
// Message Constants
protected final String SINGLETON_MSG = "Facade Singleton already constructed!";
/**
* <P>Constructor.</P>
*
* <P>This <code>IFacade</code> implementation is a Singleton,
* so you should not call the constructor
* directly, but instead call the static Singleton
* Factory method <code>Facade.getInstance()</code></P>
*
* @throws Error Error if Singleton instance has already been constructed
*
*/
public Facade() {
if(instance != null) throw new Error(SINGLETON_MSG);
instance = this;
initializeFacade();
}
/**
* <P>Initialize the Singleton <code>Facade</code> instance.</P>
*
* <P>Called automatically by the constructor. Override in your
* subclass to do any subclass specific initializations. Be
* sure to call <code>super.initializeFacade()</code>, though.</P>
*/
protected void initializeFacade() {
initializeModel();
initializeController();
initializeView();
}
/**
* <P>Facade Singleton Factory method</P>
*
* @param factory facade Supplier Function
* @return the Singleton instance of the Facade
*/
public synchronized static IFacade getInstance(Supplier<IFacade> factory) {
if(instance == null) instance = factory.get();
return instance;
}
/**
* <P>Initialize the <code>Controller</code>.</P>
*
* <P>Called by the <code>initializeFacade</code> method.
* Override this method in your subclass of <code>Facade</code>
* if one or both of the following are true:</P>
*
* <UL>
* <LI> You wish to initialize a different <code>IController</code>.</LI>
* <LI> You have <code>Commands</code> to register with the <code>Controller</code> at startup.</LI>
* </UL>
*
* <P>If you don't want to initialize a different <code>IController</code>,
* call <code>super.initializeController()</code> at the beginning of your
* method, then register <code>Command</code>s.</P>
*/
protected void initializeController() {
if(controller != null) return;
controller = Controller.getInstance(() -> new Controller());
}
/**
* <P>Initialize the <code>Model</code>.</P>
*
* <P>Called by the <code>initializeFacade</code> method.
* Override this method in your subclass of <code>Facade</code>
* if one or both of the following are true:</P>
*
* <UL>
* <LI> You wish to initialize a different <code>IModel</code>.</LI>
* <LI> You have <code>Proxy</code>s to register with the Model that do not
* retrieve a reference to the Facade at construction time.</LI>
* </UL>
*
* <P>If you don't want to initialize a different <code>IModel</code>,
* call <code>super.initializeModel()</code> at the beginning of your
* method, then register <code>Proxy</code>s.</P>
*
* <P>Note: This method is <i>rarely</i> overridden; in practice you are more
* likely to use a <code>Command</code> to create and register <code>Proxy</code>s
* with the <code>Model</code>, since <code>Proxy</code>s with mutable data will likely
* need to send <code>INotification</code>s and thus will likely want to fetch a reference to
* the <code>Facade</code> during their construction.</P>
*/
protected void initializeModel() {
if(model != null) return;
model = Model.getInstance(() -> new Model());
}
/**
* <P>Initialize the <code>View</code>.</P>
*
* <P>Called by the <code>initializeFacade</code> method.
* Override this method in your subclass of <code>Facade</code>
* if one or both of the following are true:</P>
*
* <UL>
* <LI> You wish to initialize a different <code>IView</code>.</LI>
* <LI> You have <code>Observers</code> to register with the <code>View</code></LI>
* </UL>
*
* <P>If you don't want to initialize a different <code>IView</code>,
* call <code>super.initializeView()</code> at the beginning of your
* method, then register <code>IMediator</code> instances.</P>
*
* <P>Note: This method is <i>rarely</i> overridden; in practice you are more
* likely to use a <code>Command</code> to create and register <code>Mediator</code>s
* with the <code>View</code>, since <code>IMediator</code> instances will need to send
* <code>INotification</code>s and thus will likely want to fetch a reference
* to the <code>Facade</code> during their construction.</P>
*/
protected void initializeView() {
if(view != null) return;
view = View.getInstance(() -> new View());
}
/**
* <P>Register an <code>ICommand</code> with the <code>Controller</code> by Notification name.</P>
*
* @param notificationName the name of the <code>INotification</code> to associate the <code>ICommand</code> with
* @param commandSupplier a reference to the Supplier Function of the <code>ICommand</code>
*/
public void registerCommand(String notificationName, Supplier<ICommand> commandSupplier) {
controller.registerCommand(notificationName, commandSupplier);
}
/**
* <P>Remove a previously registered <code>ICommand</code> to <code>INotification</code> mapping from the Controller.</P>
*
* @param notificationName the name of the <code>INotification</code> to remove the <code>ICommand</code> mapping for
*/
public void removeCommand(String notificationName) {
controller.removeCommand(notificationName);
}
/**
* <P>Check if a Command is registered for a given Notification</P>
*
* @param notificationName notification name
* @return whether a Command is currently registered for the given <code>notificationName</code>.
*/
public boolean hasCommand(String notificationName) {
return controller.hasCommand(notificationName);
}
/**
* <P>Register an <code>IProxy</code> with the <code>Model</code> by name.</P>
*
* @param proxy the <code>IProxy</code> instance to be registered with the <code>Model</code>.
*/
public void registerProxy(IProxy proxy) {
model.registerProxy(proxy);
}
/**
* <P>Retrieve an <code>IProxy</code> from the <code>Model</code> by name.</P>
*
* @param proxyName the name of the proxy to be retrieved.
* @return the <code>IProxy</code> instance previously registered with the given <code>proxyName</code>.
*/
public <T extends IProxy> T retrieveProxy(String proxyName) {
return model.retrieveProxy(proxyName);
}
/**
* <P>Remove an <code>IProxy</code> from the <code>Model</code> by name.</P>
*
* @param proxyName the <code>IProxy</code> to remove from the <code>Model</code>.
* @return the <code>IProxy</code> that was removed from the <code>Model</code>
*/
public <T extends IProxy> T removeProxy(String proxyName) {
return model.removeProxy(proxyName);
}
/**
* <P>Check if a Proxy is registered</P>
*
* @param proxyName proxy name
* @return whether a Proxy is currently registered with the given <code>proxyName</code>.
*/
public boolean hasProxy(String proxyName) {
return model.hasProxy(proxyName);
}
/**
* <P>Register a <code>IMediator</code> with the <code>View</code>.</P>
*
* @param mediator a reference to the <code>IMediator</code>
*/
public void registerMediator(IMediator mediator) {
view.registerMediator(mediator);
}
/**
* <P>Retrieve an <code>IMediator</code> from the <code>View</code>.</P>
*
* @param mediatorName mediator name
* @return the <code>IMediator</code> previously registered with the given <code>mediatorName</code>.
*/
public <T extends IMediator> T retrieveMediator(String mediatorName) {
return view.retrieveMediator(mediatorName);
}
/**
* <P>Remove an <code>IMediator</code> from the <code>View</code>.</P>
*
* @param mediatorName name of the <code>IMediator</code> to be removed.
* @return the <code>IMediator</code> that was removed from the <code>View</code>
*/
public <T extends IMediator> T removeMediator(String mediatorName) {
return view.removeMediator(mediatorName);
}
/**
* <P>Check if a Mediator is registered or not</P>
*
* @param mediatorName mediator name
* @return whether a Mediator is registered with the given <code>mediatorName</code>.
*/
public boolean hasMediator(String mediatorName) {
return view.hasMediator(mediatorName);
}
/**
* <P>Create and send an <code>INotification</code>.</P>
*
* <P>Keeps us from having to construct new notification
* instances in our implementation code.</P>
*
* @param notificationName the name of the notiification to send
* @param body the body of the notification
* @param type the type of the notification
*/
public void sendNotification(String notificationName, Object body, String type) {
notifyObservers(new Notification(notificationName, body, type));
}
/**
* <P>Create and send an <code>INotification</code>.</P>
*
* <P>Keeps us from having to construct new notification
* instances in our implementation code.</P>
*
* @param notificationName the name of the notiification to send
* @param body the body of the notification
*/
public void sendNotification(String notificationName, Object body) {
sendNotification(notificationName, body, null);
}
/**
* <P>Create and send an <code>INotification</code>.</P>
*
* <P>Keeps us from having to construct new notification
* instances in our implementation code.</P>
*
* @param notificationName the name of the notiification to send
*/
public void sendNotification(String notificationName) {
sendNotification(notificationName, null, null);
}
/**
* <P>Notify <code>Observer</code>s.</P>
*
* <P>This method is left public mostly for backward
* compatibility, and to allow you to send custom
* notification classes using the facade.</P>
*
* <P>Usually you should just call sendNotification
* and pass the parameters, never having to
* construct the notification yourself.</P>
*
* @param notification the <code>INotification</code> to have the <code>View</code> notify <code>Observers</code> of.
*/
public void notifyObservers(INotification notification) {
view.notifyObservers(notification);
}
}
@@ -0,0 +1,136 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.patterns.mediator;
import org.puremvc.java.interfaces.IMediator;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.observer.Notifier;
/**
* <P>A base <code>IMediator</code> implementation.</P>
*
* @see org.puremvc.java.core.View View
*/
public class Mediator<V> extends Notifier implements IMediator<V> {
/**
* <P>The name of the <code>Mediator</code>.</P>
*
* <P>Typically, a <code>Mediator</code> will be written to serve
* one specific control or group controls and so,
* will not have a need to be dynamically named.</P>
*/
public static final String NAME = "Mediator";
// the mediator name
protected String mediatorName;
// The view component
protected V viewComponent;
/**
* <P>Constructor.</P>
*
* @param mediatorName mediator name
* @param viewComponent view component
*/
public Mediator(String mediatorName, V viewComponent) {
this.mediatorName = mediatorName != null ? mediatorName : NAME;
this.viewComponent = viewComponent;
}
/**
* <P>Constructor.</P>
*
* @param mediatorName mediator name
*/
public Mediator(String mediatorName) {
this(mediatorName, null);
}
/**
* <P>Constructor.</P>
*/
public Mediator() {
this(null, null);
}
/**
* <P>List the <code>INotification</code> names this
* <code>Mediator</code> is interested in being notified of.</P>
*
* @return Array the list of <code>INotification</code> names
*/
public String[] listNotificationInterests() {
return new String[0];
}
/**
* <P>Handle <code>INotification</code>s.</P>
*
* <P>Typically this will be handled in a switch statement,
* with one 'case' entry per <code>INotification</code>
* the <code>Mediator</code> is interested in.</P>
*/
public void handleNotification(INotification notification) {
}
/**
* <P>Called by the View when the Mediator is registered</P>
*/
public void onRegister() {
}
/**
* <P>Called by the View when the Mediator is removed</P>
*/
public void onRemove() {
}
/**
* <P>Get the name of the <code>Mediator</code>.</P>
*
* @return the Mediator name
*/
public String getMediatorName() {
return mediatorName;
}
/**
* <P>Get the <code>Mediator</code>'s view component.</P>
*
* <P>Additionally, an implicit getter will usually
* be defined in the subclass that casts the view
* object to a type, like this:</P>
*
* {@code
* public javax.swing.JComboBox getViewComponent()
* {
* return viewComponent;
* }
*}
*
* @return the view component
*/
public V getViewComponent() {
return viewComponent;
}
/**
* <P>Set the <code>IMediator</code>'s view component.</P>
*
* @param viewComponent the view component
*/
public void setViewComponent(V viewComponent) {
this.viewComponent = viewComponent;
}
}
@@ -0,0 +1,138 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.patterns.observer;
import org.puremvc.java.interfaces.INotification;
/**
* <P>A base <code>INotification</code> implementation.</P>
*
* <P>PureMVC does not rely upon underlying event models such
* as the one provided with Flash, and ActionScript 3 does
* not have an inherent event model.</P>
*
* <P>The Observer Pattern as implemented within PureMVC exists
* to support event-driven communication between the
* application and the actors of the MVC triad.</P>
*
* <P>Notifications are not meant to be a replacement for Events
* in Flex/Flash/Apollo. Generally, <code>IMediator</code> implementors
* place event listeners on their view components, which they
* then handle in the usual way. This may lead to the broadcast of <code>Notification</code>s to
* trigger <code>ICommand</code>s or to communicate with other <code>IMediators</code>. <code>IProxy</code> and <code>ICommand</code>
* instances communicate with each other and <code>IMediator</code>s
* by broadcasting <code>INotification</code>s.</P>
*
* <P>A key difference between Flash <code>Event</code>s and PureMVC
* <code>Notification</code>s is that <code>Event</code>s follow the
* 'Chain of Responsibility' pattern, 'bubbling' up the display hierarchy
* until some parent component handles the <code>Event</code>, while
* PureMVC <code>Notification</code>s follow a 'Publish/Subscribe'
* pattern. PureMVC classes need not be related to each other in a
* parent/child relationship in order to communicate with one another
* using <code>Notification</code>s.</P>
*
* @see Observer Observer
*
*/
public class Notification implements INotification {
// the name of the notification instance
private String name;
// the type of the notification instance
private String type;
// the body of the notification instance
private Object body;
/**
* <P>Constructor.</P>
*
* @param name name of the <code>Notification</code> instance. (required)
* @param body the <code>Notification</code> body.
* @param type the type of the <code>Notification</code>
*/
public Notification(String name, Object body, String type) {
this.name = name;
this.body = body;
this.type = type;
}
/**
* <P>Constructor.</P>
*
* @param name name of the <code>Notification</code> instance.
* @param body the <code>Notification</code> body.
*/
public Notification(String name, Object body) {
this(name, body, null);
}
/**
* <P>Constructor.</P>
*
* @param name name of the <code>Notification</code> instance.
*/
public Notification(String name) {
this(name, null, null);
}
/**
* <P>Get the name of the <code>Notification</code> instance.</P>
*
* @return the name of the <code>Notification</code> instance.
*/
public String getName() {
return name;
}
/**
* <P>Set the body of the <code>Notification</code> instance.</P>
*/
public void setBody(Object body) {
this.body = body;
}
/**
* <P>Get the body of the <code>Notification</code> instance.</P>
*
* @return the body object.
*/
public Object getBody() {
return body;
}
/**
* <P>Set the type of the <code>Notification</code> instance.</P>
*/
public void setType(String type) {
this.type = type;
}
/**
* <P>Get the type of the <code>Notification</code> instance.</P>
*
* @return the type
*/
public String getType() {
return type;
}
/**
* <P>Get the string representation of the <code>Notification</code> instance.</P>
*
* @return the string representation of the <code>Notification</code> instance.
*/
public String toString() {
return new StringBuilder("Notification Name: " + getName())
.append("\nBody:" + ((body == null) ? "null" : body.toString()))
.append("\nType:" + ((type == null) ? "null" : type))
.toString();
}
}
@@ -0,0 +1,83 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.patterns.observer;
import org.puremvc.java.interfaces.IFacade;
import org.puremvc.java.interfaces.INotifier;
import org.puremvc.java.patterns.facade.Facade;
/**
* <P>A Base <code>INotifier</code> implementation.</P>
*
* <P><code>MacroCommand, Command, Mediator</code> and <code>Proxy</code> all
* have a need to send <code>Notifications</code>.</P>
*
* <P>The <code>INotifier</code> interface provides a common method called
* <code>sendNotification</code> that relieves implementation code of the
* necessity to actually construct <code>Notifications</code>.</P>
*
* <P>The <code>Notifier</code> class, which all of the above mentioned classes
* extend, provides an initialized reference to the <code>Facade</code>
* Singleton, which is required for the convienience method for sending
* <code>Notifications</code>, but also eases implementation as these classes
* have frequent <code>Facade</code> interactions and usually require access
* to the facade anyway.</P>
*
* @see Facade Facade
* @see org.puremvc.java.patterns.mediator.Mediator Mediator
* @see org.puremvc.java.patterns.proxy.Proxy Proxy
* @see org.puremvc.java.patterns.command.SimpleCommand SimpleCommand
* @see org.puremvc.java.patterns.command.MacroCommand MacroCommand
*/
public class Notifier implements INotifier {
/**
* <P>Local reference to the Facade Singleton</P>
*/
protected IFacade facade = Facade.getInstance(()-> new Facade());
/**
* <P>Send an <code>INotification</code>s.</P>
*
* <P>Keeps us from having to construct new notification instances in our
* implementation code.</P>
*
* @param notificationName the name of the notiification to send
* @param body the body of the notification
* @param type the type of the notification
*/
public void sendNotification(String notificationName, Object body, String type) {
facade.sendNotification(notificationName, body, type);
}
/**
* <P>Send an <code>INotification</code>s.</P>
*
* <P>Keeps us from having to construct new notification instances in our
* implementation code.</P>
*
* @param notificationName the name of the notiification to send
* @param body the body of the notification
*/
public void sendNotification(String notificationName, Object body) {
facade.sendNotification(notificationName, body);
}
/**
* <P>Send an <code>INotification</code>s.</P>
*
* <P>Keeps us from having to construct new notification instances in our
* implementation code.</P>
*
* @param notificationName the name of the notiification to send
*/
public void sendNotification(String notificationName) {
facade.sendNotification(notificationName);
}
}
@@ -0,0 +1,115 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.patterns.observer;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.interfaces.IObserver;
import java.util.function.Consumer;
/**
* <P>A base <code>IObserver</code> implementation.</P>
*
* <P>An <code>Observer</code> is an object that encapsulates information
* about an interested object with a method that should
* be called when a particular <code>INotification</code> is broadcast.</P>
*
* <P>In PureMVC, the <code>Observer</code> class assumes these responsibilities:</P>
*
* <UL>
* <LI>Encapsulate the notification (callback) method of the interested object.</LI>
* <LI>Encapsulate the notification context (this) of the interested object.</LI>
* <LI>Provide methods for setting the notification method and context.</LI>
* <LI>Provide a method for notifying the interested object.</LI>
* </UL>
*
* @see org.puremvc.java.core.View View
* @see org.puremvc.java.patterns.observer.Notification Notification
*/
public class Observer implements IObserver {
private Object notifyContext;
private Consumer<INotification> notifyMethod;
/**
* <P>Constructor.</P>
*
* <P>The notification method on the interested object should take one
* parameter of type <code>INotification</code></P>
*
* @param notifyMethod the notification method of the interested object
* @param notifyContext the notification context of the interested object
*/
public Observer(Consumer<INotification> notifyMethod, Object notifyContext) {
this.notifyMethod = notifyMethod;
this.notifyContext = notifyContext;
}
/**
* <P>Compare an object to the notification context.</P>
*
* @param object the object to compare
* @return boolean indicating if the object and the notification context are
* the same
*/
public boolean compareNotifyContext(Object object) {
return object == this.notifyContext;
}
/**
* <P>Notify the interested object.</P>
*
* @param notification the <code>INotification</code> to pass to the interested
* object's notification method.
*/
public void notifyObserver(INotification notification) {
notifyMethod.accept(notification);
}
/**
* <P>Get the notification context.</P>
*
* @return the notification context (<code>this</code>) of the
* interested object.
*/
protected Object getNotifyContext() {
return notifyContext;
}
/**
* <P>Set the notification context.</P>
*
* @param notifyContext the notification context (this) of the interested object.
*/
public void setNotifyContext(Object notifyContext) {
this.notifyContext = notifyContext;
}
/**
* <P>Get the notification method.</P>
*
* @return the notification (callback) consumer function of the interested object.
*/
protected Consumer<INotification> getNotifyMethod() {
return notifyMethod;
}
/**
* <P>Set the notification method.</P>
*
* <P>The notification method should take one parameter of type
* <code>INotification</code>.</P>
*
* @param notifyMethod the notification (callback) consumer function of the interested object.
*/
public void setNotifyMethod(Consumer<INotification> notifyMethod) {
this.notifyMethod = notifyMethod;
}
}
@@ -0,0 +1,110 @@
//
// PureMVC Java Standard
//
// Copyright(c) 2019 Saad Shams <saad.shams@puremvc.org>
// Your reuse is governed by the Creative Commons Attribution 3.0 License
//
package org.puremvc.java.patterns.proxy;
import org.puremvc.java.interfaces.IProxy;
import org.puremvc.java.patterns.observer.Notifier;
/**
* <P>A base <code>IProxy</code> implementation.</P>
*
* <P>In PureMVC, <code>Proxy</code> classes are used to manage parts of the
* application's data model.</P>
*
* <P>A <code>Proxy</code> might simply manage a reference to a local data
* object, in which case interacting with it might involve setting and getting
* of its data in synchronous fashion.</P>
*
* <P><code>Proxy</code> classes are also used to encapsulate the application's
* interaction with remote services to save or retrieve data, in which case, we
* adopt an asyncronous idiom; setting data (or calling a method) on the
* <code>Proxy</code> and listening for a <code>Notification</code> to be
* sent when the <code>Proxy</code> has retrieved the data from the service.</P>
*
* @see org.puremvc.java.core.Model Model
*/
public class Proxy extends Notifier implements IProxy {
// the proxy name
public static final String NAME = "Proxy";
// the data object
protected String proxyName;
// the data object
protected Object data;
/**
* <P>Constructor</P>
*
* @param proxyName proxy name
* @param data data object
*/
public Proxy(String proxyName, Object data) {
this.proxyName = (proxyName != null) ? proxyName : NAME;
if(data != null) setData(data);
}
/**
* <P>Constructor</P>
*
* @param proxyName Name of the <code>Proxy</code>
*/
public Proxy(String proxyName) {
this(proxyName, null);
}
/**
* <P>Constructor</P>
*/
public Proxy(){
this(null, null);
}
/**
* <P>Called by the Model when the Proxy is registered</P>
*/
public void onRegister() {
}
/**
* <P>Called by the Model when the Proxy is removed</P>
*/
public void onRemove() {
}
/**
* <P>Get the proxy name</P>
*
* @return the proxy name
*/
public String getProxyName() {
return proxyName;
}
/**
* <P>Get the data object</P>
*
* @return the data object
*/
public Object getData() {
return data;
}
/**
* <P>Set the data object</P>
*
* @param data data object
*/
public void setData(Object data) {
this.data = data;
}
}
@@ -10,8 +10,8 @@ import com.badlogic.gdx.utils.Align;
import com.kotcrab.vis.ui.widget.VisLabel;
import com.kotcrab.vis.ui.widget.VisTable;
import com.kotcrab.vis.ui.widget.VisTextButton;
import com.puremvc.patterns.facade.SimpleFacade;
import games.rednblack.h2d.common.H2DDialog;
import org.puremvc.java.interfaces.IFacade;
/**
* Created by azakhary on 8/18/2015.
@@ -21,7 +21,7 @@ public class MainPanel extends H2DDialog {
public static final String SAVE_CLICKED = CLASS_NAME + ".SAVE_CLICKED";
private SimpleFacade facade;
private IFacade facade;
private VisTable mainTable;
private TextureRegion texture;
@@ -32,11 +32,11 @@ public class MainPanel extends H2DDialog {
private EditingZone editingZone;
private PreviewWidget previewWidget;
public MainPanel() {
public MainPanel(IFacade facade) {
super("Nine Patch");
addCloseButton();
facade = SimpleFacade.getInstance();
this.facade = facade;
mainTable = new VisTable();
add(mainTable).width(520).height(310).padBottom(7);
@@ -5,13 +5,13 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.renderer.components.MainItemComponent;
import games.rednblack.editor.renderer.components.NinePatchComponent;
import games.rednblack.editor.renderer.components.TextureRegionComponent;
import games.rednblack.editor.renderer.factory.EntityFactory;
import games.rednblack.editor.renderer.utils.ComponentRetriever;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
@@ -22,7 +22,7 @@ import java.io.IOException;
/**
* Created by azakhary on 8/18/2015.
*/
public class MainPanelMediator extends SimpleMediator<MainPanel> {
public class MainPanelMediator extends Mediator<MainPanel> {
private static final String TAG = MainPanelMediator.class.getCanonicalName();
public static final String NAME = TAG;
@@ -31,7 +31,7 @@ public class MainPanelMediator extends SimpleMediator<MainPanel> {
private ImageUtils imageUtils = new ImageUtils();
public MainPanelMediator(NinePatchPlugin plugin) {
super(NAME, new MainPanel());
super(NAME, new MainPanel(plugin.facade));
this.plugin = plugin;
}
@@ -45,7 +45,7 @@ public class MainPanelMediator extends SimpleMediator<MainPanel> {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
super.handleNotification(notification);
switch (notification.getName()) {
case NinePatchPlugin.EDIT_NINE_PATCH:
@@ -27,11 +27,11 @@ public class NinePatchPlugin extends H2DPluginAdapter {
public NinePatchPlugin() {
super(CLASS_NAME);
performancePanelMediator = new MainPanelMediator(this);
}
@Override
public void initPlugin() {
performancePanelMediator = new MainPanelMediator(this);
facade.registerMediator(performancePanelMediator);
pluginAPI.setDropDownItemName(EDIT_NINE_PATCH, "Edit NinePatch");
pluginAPI.setDropDownItemName(CONVERT_TO_NINE_PATCH, "Convert to NinePatch");
@@ -4,13 +4,10 @@ import com.badlogic.ashley.core.Engine;
import com.badlogic.gdx.Gdx;
import com.kotcrab.vis.ui.widget.VisLabel;
import com.kotcrab.vis.ui.widget.VisTable;
import com.puremvc.patterns.facade.SimpleFacade;
import games.rednblack.h2d.common.UIDraggablePanel;
public class PerformancePanel extends UIDraggablePanel {
private SimpleFacade facade;
private VisTable mainTable;
private VisLabel entitiesCount;
@@ -22,8 +19,6 @@ public class PerformancePanel extends UIDraggablePanel {
super("Performance");
addCloseButton();
facade = SimpleFacade.getInstance();
mainTable = new VisTable();
getContentTable().add(mainTable).left().width(150).pad(5);
@@ -1,10 +1,10 @@
package games.rednblack.editor.plugin.performance;
import com.badlogic.ashley.core.Engine;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
public class PerformancePanelMediator extends SimpleMediator<PerformancePanel> {
public class PerformancePanelMediator extends Mediator<PerformancePanel> {
private static final String TAG = PerformancePanelMediator.class.getCanonicalName();
public static final String NAME = TAG;
@@ -32,7 +32,7 @@ public class PerformancePanelMediator extends SimpleMediator<PerformancePanel> {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
super.handleNotification(notification);
switch (notification.getName()) {
case SCENE_LOADED:
@@ -2,17 +2,17 @@ package games.rednblack.editor.plugin.skincomposer;
import com.badlogic.gdx.utils.Json;
import com.kotcrab.vis.ui.util.dialog.Dialogs;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.h2d.common.MsgAPI;
import org.apache.commons.io.FileUtils;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SkinComposerMediator extends SimpleMediator<DownloadingDialog> {
public class SkinComposerMediator extends Mediator<DownloadingDialog> {
private static final String TAG = SkinComposerMediator.class.getCanonicalName();
public static final String NAME = TAG;
@@ -33,7 +33,7 @@ public class SkinComposerMediator extends SimpleMediator<DownloadingDialog> {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
super.handleNotification(notification);
pluginPath = plugin.getAPI().getCacheDir();
@@ -1,11 +1,11 @@
package games.rednblack.editor.plugin.skincomposer;
import com.kotcrab.vis.ui.widget.VisCheckBox;
import com.puremvc.patterns.facade.Facade;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.h2d.common.plugins.H2DPluginAdapter;
import games.rednblack.h2d.common.view.SettingsNodeValue;
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
import org.puremvc.java.interfaces.IFacade;
public class SkinComposerSettings extends SettingsNodeValue<SkinComposerVO> {
@@ -13,7 +13,7 @@ public class SkinComposerSettings extends SettingsNodeValue<SkinComposerVO> {
private final H2DPluginAdapter plugin;
private boolean loaded = false;
public SkinComposerSettings(Facade facade, H2DPluginAdapter plugin) {
public SkinComposerSettings(IFacade facade, H2DPluginAdapter plugin) {
super("Skin Composer", facade);
this.plugin = plugin;
@@ -29,13 +29,12 @@ import com.kotcrab.vis.ui.widget.VisTextButton;
import com.kotcrab.vis.ui.widget.tabbedpane.Tab;
import com.kotcrab.vis.ui.widget.tabbedpane.TabbedPane;
import com.kotcrab.vis.ui.widget.tabbedpane.TabbedPaneListener;
import com.puremvc.patterns.facade.Facade;
import com.puremvc.patterns.facade.SimpleFacade;
import games.rednblack.editor.plugin.tiled.data.TileVO;
import games.rednblack.editor.plugin.tiled.manager.ResourcesManager;
import games.rednblack.editor.plugin.tiled.view.tabs.GridTilesTab;
import games.rednblack.editor.plugin.tiled.view.tabs.SettingsTab;
import games.rednblack.h2d.common.UIDraggablePanel;
import org.puremvc.java.interfaces.IFacade;
/**
* Created by mariam on 2/2/2016.
@@ -52,7 +51,7 @@ public class TiledPanel extends UIDraggablePanel {
public static final float BOTTOM_BAR_DELTA_Y = 6f;
public TiledPlugin tiledPlugin;
public Facade facade;
private IFacade facade;
protected TabbedPane tabbedPane;
protected VisTable tabTable; //table inside of each tab
@@ -69,7 +68,7 @@ public class TiledPanel extends UIDraggablePanel {
super("Tiles");
this.tiledPlugin = tiledPlugin;
facade = SimpleFacade.getInstance();
facade = tiledPlugin.facade;
mainTable = new VisTable();
add(mainTable)
@@ -230,4 +229,8 @@ public class TiledPanel extends UIDraggablePanel {
public void setEngine(Engine engine) {
this.engine = engine;
}
public IFacade getFacade() {
return facade;
}
}
@@ -22,8 +22,6 @@ import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.h2d.common.vo.CursorData;
import games.rednblack.editor.plugin.tiled.data.TileVO;
import games.rednblack.editor.plugin.tiled.tools.DeleteTileTool;
@@ -34,13 +32,15 @@ import games.rednblack.editor.renderer.components.MainItemComponent;
import games.rednblack.editor.renderer.utils.ComponentRetriever;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.h2d.common.ResourcePayloadObject;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
import java.util.HashMap;
/**
* Created by mariam on 2/2/2016.
*/
public class TiledPanelMediator extends SimpleMediator<TiledPanel> {
public class TiledPanelMediator extends Mediator<TiledPanel> {
private static final String TAG = TiledPanelMediator.class.getCanonicalName();
public static final String NAME = TAG;
@@ -74,7 +74,7 @@ public class TiledPanelMediator extends SimpleMediator<TiledPanel> {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
super.handleNotification(notification);
String tileName;
@@ -1,14 +1,14 @@
package games.rednblack.editor.plugin.tiled.offset;
import com.badlogic.gdx.math.Vector2;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.plugin.tiled.TiledPlugin;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
/**
* Created by mariam on 5/12/16.
*/
public class OffsetPanelMediator extends SimpleMediator<OffsetPanel> {
public class OffsetPanelMediator extends Mediator<OffsetPanel> {
private static final String TAG = OffsetPanelMediator.class.getCanonicalName();
public static final String NAME = TAG;
@@ -32,7 +32,7 @@ public class OffsetPanelMediator extends SimpleMediator<OffsetPanel> {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
super.handleNotification(notification);
switch (notification.getName()) {
@@ -2,10 +2,10 @@ package games.rednblack.editor.plugin.tiled.tools;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.Input;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.plugin.tiled.TiledPlugin;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.h2d.common.view.tools.Tool;
import org.puremvc.java.interfaces.INotification;
/**
* Created by mariam on 4/5/16.
@@ -87,7 +87,7 @@ public class DeleteTileTool implements Tool {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
}
@@ -4,7 +4,6 @@ import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.plugin.tiled.TiledPlugin;
import games.rednblack.editor.renderer.components.DimensionsComponent;
import games.rednblack.editor.renderer.components.MainItemComponent;
@@ -13,6 +12,7 @@ import games.rednblack.editor.renderer.components.TransformComponent;
import games.rednblack.editor.renderer.data.ProjectInfoVO;
import games.rednblack.editor.renderer.utils.ComponentRetriever;
import games.rednblack.h2d.common.view.tools.Tool;
import org.puremvc.java.interfaces.INotification;
/**
* Created by mariam on 3/29/16.
@@ -121,7 +121,7 @@ public class DrawTileTool implements Tool {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
}
@@ -60,7 +60,7 @@ public class SettingsTab extends DefaultTab {
currentParameters.gridWidth = grid.getAttributeVO("Width: ").value;
currentParameters.gridHeight = grid.getAttributeVO("Height: ").value;
panel.facade.sendNotification(OK_BTN_CLICKED, currentParameters);
panel.getFacade().sendNotification(OK_BTN_CLICKED, currentParameters);
}
});
}
@@ -31,21 +31,21 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.ObjectMap;
import com.puremvc.patterns.observer.BaseNotification;
import games.rednblack.editor.proxy.CommandManager;
import games.rednblack.editor.splash.SplashScreenAdapter;
import games.rednblack.editor.view.frame.FileDropListener;
import games.rednblack.editor.view.ui.panel.ImportPanel;
import games.rednblack.h2d.common.MsgAPI;
import com.kotcrab.vis.ui.VisUI;
import com.puremvc.patterns.proxy.Proxy;
import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.puremvc.java.interfaces.IProxy;
import org.puremvc.java.patterns.observer.Notification;
import java.nio.IntBuffer;
public class HyperLap2D implements Proxy, ApplicationListener, Lwjgl3WindowListener {
public class HyperLap2D implements IProxy, ApplicationListener, Lwjgl3WindowListener {
private static final String TAG = HyperLap2D.class.getCanonicalName();
public static final String NAME = TAG;
@@ -53,7 +53,7 @@ public class HyperLap2D implements Proxy, ApplicationListener, Lwjgl3WindowListe
private Object data;
private AssetManager assetManager;
private final BaseNotification renderNotification;
private final Notification renderNotification;
public HyperLap2DFacade getFacade() {
return facade;
@@ -62,7 +62,7 @@ public class HyperLap2D implements Proxy, ApplicationListener, Lwjgl3WindowListe
private final Sync sync = new Sync();
public HyperLap2D() {
renderNotification = new BaseNotification(MsgAPI.RENDER, null, null);
renderNotification = new Notification(MsgAPI.RENDER, null, null);
}
@Override
@@ -18,16 +18,16 @@
package games.rednblack.editor;
import com.puremvc.patterns.facade.SimpleFacade;
import com.puremvc.patterns.observer.BaseNotification;
import games.rednblack.editor.controller.StartupCommand;
import games.rednblack.editor.splash.SplashMediator;
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
import org.puremvc.java.patterns.facade.Facade;
import org.puremvc.java.patterns.observer.Notification;
/**
* Created by sargis on 3/30/15.
*/
public class HyperLap2DFacade extends SimpleFacade {
public class HyperLap2DFacade extends Facade {
public static final String STARTUP = "startup";
private static HyperLap2DFacade instance = null;
private HyperLap2D hyperlap2D;
@@ -51,7 +51,7 @@ public class HyperLap2DFacade extends SimpleFacade {
public void startup(HyperLap2D hyperlap2D) {
this.hyperlap2D = hyperlap2D;
notifyObservers(new BaseNotification(STARTUP, null, null));
notifyObservers(new Notification(STARTUP, null, null));
}
@Override
@@ -62,7 +62,7 @@ public class HyperLap2DFacade extends SimpleFacade {
@Override
protected void initializeController() {
super.initializeController();
registerCommand(STARTUP, StartupCommand.class);
registerCommand(STARTUP, StartupCommand::new);
}
@Override
@@ -21,85 +21,85 @@ package games.rednblack.editor.controller;
import games.rednblack.editor.controller.commands.component.*;
import games.rednblack.editor.splash.SplashScreenAdapter;
import games.rednblack.h2d.common.MsgAPI;
import com.puremvc.patterns.command.SimpleCommand;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.controller.commands.*;
import games.rednblack.editor.controller.commands.resource.*;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.command.SimpleCommand;
/**
* Created by azakhary on 4/28/2015.
*/
public class BootstrapCommand extends SimpleCommand {
public void execute(Notification notification) {
public void execute(INotification notification) {
super.execute(notification);
facade = HyperLap2DFacade.getInstance();
facade.sendNotification(SplashScreenAdapter.UPDATE_SPLASH, "Loading Commands...");
facade.registerCommand(MsgAPI.ACTION_CUT, CutItemsCommand.class);
facade.registerCommand(MsgAPI.ACTION_COPY, CopyItemsCommand.class);
facade.registerCommand(MsgAPI.ACTION_PASTE, PasteItemsCommand.class);
facade.registerCommand(MsgAPI.ACTION_DELETE, DeleteItemsCommand.class);
facade.registerCommand(MsgAPI.ACTION_CREATE_ITEM, CreateItemCommand.class);
facade.registerCommand(MsgAPI.ACTION_CAMERA_CHANGE_COMPOSITE, CompositeCameraChangeCommand.class);
facade.registerCommand(MsgAPI.ACTION_CREATE_PRIMITIVE, CreatePrimitiveCommand.class);
facade.registerCommand(MsgAPI.ACTION_CUT, CutItemsCommand::new);
facade.registerCommand(MsgAPI.ACTION_COPY, CopyItemsCommand::new);
facade.registerCommand(MsgAPI.ACTION_PASTE, PasteItemsCommand::new);
facade.registerCommand(MsgAPI.ACTION_DELETE, DeleteItemsCommand::new);
facade.registerCommand(MsgAPI.ACTION_CREATE_ITEM, CreateItemCommand::new);
facade.registerCommand(MsgAPI.ACTION_CAMERA_CHANGE_COMPOSITE, CompositeCameraChangeCommand::new);
facade.registerCommand(MsgAPI.ACTION_CREATE_PRIMITIVE, CreatePrimitiveCommand::new);
facade.registerCommand(MsgAPI.ACTION_DELETE_LAYER, DeleteLayerCommand.class);
facade.registerCommand(MsgAPI.ACTION_NEW_LAYER, NewLayerCommand.class);
facade.registerCommand(MsgAPI.ACTION_SWAP_LAYERS, LayerSwapCommand.class);
facade.registerCommand(MsgAPI.ACTION_RENAME_LAYER, RenameLayerCommand.class);
facade.registerCommand(MsgAPI.ACTION_DELETE_LAYER, DeleteLayerCommand::new);
facade.registerCommand(MsgAPI.ACTION_NEW_LAYER, NewLayerCommand::new);
facade.registerCommand(MsgAPI.ACTION_SWAP_LAYERS, LayerSwapCommand::new);
facade.registerCommand(MsgAPI.ACTION_RENAME_LAYER, RenameLayerCommand::new);
facade.registerCommand(MsgAPI.ACTION_ADD_COMPONENT, AddComponentToItemCommand.class);
facade.registerCommand(MsgAPI.ACTION_REMOVE_COMPONENT, RemoveComponentFromItemCommand.class);
facade.registerCommand(MsgAPI.CUSTOM_VARIABLE_MODIFY, CustomVariableModifyCommand.class);
facade.registerCommand(MsgAPI.ACTION_ADD_COMPONENT, AddComponentToItemCommand::new);
facade.registerCommand(MsgAPI.ACTION_REMOVE_COMPONENT, RemoveComponentFromItemCommand::new);
facade.registerCommand(MsgAPI.CUSTOM_VARIABLE_MODIFY, CustomVariableModifyCommand::new);
facade.registerCommand(MsgAPI.ACTION_ITEMS_MOVE_TO, ItemsMoveCommand.class);
facade.registerCommand(MsgAPI.ACTION_ITEMS_MOVE_TO, ItemsMoveCommand::new);
facade.registerCommand(MsgAPI.ACTION_ITEM_AND_CHILDREN_TO, ItemChildrenTransformCommand.class);
facade.registerCommand(MsgAPI.ACTION_ITEM_AND_CHILDREN_TO, ItemChildrenTransformCommand::new);
facade.registerCommand(MsgAPI.ACTION_ITEM_TRANSFORM_TO, ItemTransformCommand.class);
facade.registerCommand(MsgAPI.ACTION_ADD_TO_LIBRARY, AddToLibraryCommand.class);
facade.registerCommand(MsgAPI.ACTION_CONVERT_TO_BUTTON, ConvertToButtonCommand.class);
facade.registerCommand(MsgAPI.ACTION_GROUP_ITEMS, ConvertToCompositeCommand.class);
facade.registerCommand(MsgAPI.ACTION_ITEM_TRANSFORM_TO, ItemTransformCommand::new);
facade.registerCommand(MsgAPI.ACTION_ADD_TO_LIBRARY, AddToLibraryCommand::new);
facade.registerCommand(MsgAPI.ACTION_CONVERT_TO_BUTTON, ConvertToButtonCommand::new);
facade.registerCommand(MsgAPI.ACTION_GROUP_ITEMS, ConvertToCompositeCommand::new);
facade.registerCommand(MsgAPI.ACTION_SET_SELECTION, SetSelectionCommand.class);
facade.registerCommand(MsgAPI.ACTION_ADD_SELECTION, AddSelectionCommand.class);
facade.registerCommand(MsgAPI.ACTION_RELEASE_SELECTION, ReleaseSelectionCommand.class);
facade.registerCommand(MsgAPI.ACTION_SET_SELECTION, SetSelectionCommand::new);
facade.registerCommand(MsgAPI.ACTION_ADD_SELECTION, AddSelectionCommand::new);
facade.registerCommand(MsgAPI.ACTION_RELEASE_SELECTION, ReleaseSelectionCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_RULER_POSITION, ChangeRulerPositionCommand.class);
facade.registerCommand(MsgAPI.ACTION_CHANGE_POLYGON_VERTEX_POSITION, ChangePolygonVertexPositionCommand.class);
facade.registerCommand(MsgAPI.ACTION_DELETE_POLYGON_VERTEX, DeletePolygonVertexCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_RULER_POSITION, ChangeRulerPositionCommand::new);
facade.registerCommand(MsgAPI.ACTION_CHANGE_POLYGON_VERTEX_POSITION, ChangePolygonVertexPositionCommand::new);
facade.registerCommand(MsgAPI.ACTION_DELETE_POLYGON_VERTEX, DeletePolygonVertexCommand::new);
// DATA MODIFY by components
facade.registerCommand(MsgAPI.ACTION_UPDATE_SCENE_DATA, UpdateSceneDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_ITEM_DATA, UpdateEntityComponentsCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_LABEL_DATA, UpdateLabelDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_LIGHT_DATA, UpdateLightDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_COMPOSITE_DATA, UpdateCompositeDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_BODY_LIGHT_DATA, UpdateLightBodyDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_PHYSICS_BODY_DATA, UpdatePhysicsDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_SHADER_DATA, UpdateShaderDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_IMAGE_ITEM_DATA, UpdateImageItemDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_SPRITE_ANIMATION_DATA, UpdateSpriteAnimationDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_SPINE_ANIMATION_DATA, UpdateSpineDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_SCENE_DATA, UpdateSceneDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_ITEM_DATA, UpdateEntityComponentsCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_LABEL_DATA, UpdateLabelDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_LIGHT_DATA, UpdateLightDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_COMPOSITE_DATA, UpdateCompositeDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_BODY_LIGHT_DATA, UpdateLightBodyDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_PHYSICS_BODY_DATA, UpdatePhysicsDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_SHADER_DATA, UpdateShaderDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_IMAGE_ITEM_DATA, UpdateImageItemDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_SPRITE_ANIMATION_DATA, UpdateSpriteAnimationDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_SPINE_ANIMATION_DATA, UpdateSpineDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_UPDATE_MESH_DATA, UpdatePolygonDataCommand.class);
facade.registerCommand(MsgAPI.ACTION_UPDATE_MESH_DATA, UpdatePolygonDataCommand::new);
facade.registerCommand(MsgAPI.ACTION_EXPORT_PROJECT, ExportProjectCommand.class);
facade.registerCommand(MsgAPI.SAVE_EXPORT_PATH, SaveExportPathCommand.class);
facade.registerCommand(MsgAPI.ACTION_EXPORT_PROJECT, ExportProjectCommand::new);
facade.registerCommand(MsgAPI.SAVE_EXPORT_PATH, SaveExportPathCommand::new);
facade.registerCommand(MsgAPI.ACTION_PLUGIN_PROXY_COMMAND, PluginItemCommand.class);
facade.registerCommand(MsgAPI.ACTION_PLUGIN_PROXY_COMMAND, PluginItemCommand::new);
// Resources
facade.registerCommand(MsgAPI.ACTION_DELETE_IMAGE_RESOURCE, DeleteImageResource.class);
facade.registerCommand(MsgAPI.ACTION_DELETE_LIBRARY_ITEM, DeleteLibraryItem.class);
facade.registerCommand(MsgAPI.ACTION_EXPORT_LIBRARY_ITEM, ExportLibraryItemCommand.class);
facade.registerCommand(MsgAPI.ACTION_DELETE_PARTICLE_EFFECT, DeleteParticleEffect.class);
facade.registerCommand(MsgAPI.ACTION_DELETE_SPINE_ANIMATION_RESOURCE, DeleteSpineAnimation.class);
facade.registerCommand(MsgAPI.ACTION_DELETE_SPRITE_ANIMATION_RESOURCE, DeleteSpriteAnimation.class);
facade.registerCommand(MsgAPI.ACTION_DELETE_SPRITER_ANIMATION_RESOURCE, DeleteSpriterAnimation.class);
facade.registerCommand(MsgAPI.ACTION_DELETE_IMAGE_RESOURCE, DeleteImageResource::new);
facade.registerCommand(MsgAPI.ACTION_DELETE_LIBRARY_ITEM, DeleteLibraryItem::new);
facade.registerCommand(MsgAPI.ACTION_EXPORT_LIBRARY_ITEM, ExportLibraryItemCommand::new);
facade.registerCommand(MsgAPI.ACTION_DELETE_PARTICLE_EFFECT, DeleteParticleEffect::new);
facade.registerCommand(MsgAPI.ACTION_DELETE_SPINE_ANIMATION_RESOURCE, DeleteSpineAnimation::new);
facade.registerCommand(MsgAPI.ACTION_DELETE_SPRITE_ANIMATION_RESOURCE, DeleteSpriteAnimation::new);
facade.registerCommand(MsgAPI.ACTION_DELETE_SPRITER_ANIMATION_RESOURCE, DeleteSpriterAnimation::new);
facade.registerCommand(MsgAPI.SHOW_NOTIFICATION, ShowNotificationCommand.class);
facade.registerCommand(MsgAPI.SHOW_NOTIFICATION, ShowNotificationCommand::new);
}
}
@@ -21,13 +21,13 @@ package games.rednblack.editor.controller;
import games.rednblack.editor.proxy.SettingsManager;
import games.rednblack.editor.splash.SplashScreenAdapter;
import games.rednblack.h2d.common.plugins.H2DPlugin;
import com.puremvc.patterns.command.SimpleCommand;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.proxy.PluginManager;
import net.mountainblade.modular.Module;
import net.mountainblade.modular.ModuleManager;
import net.mountainblade.modular.impl.DefaultModuleManager;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.command.SimpleCommand;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
@@ -35,7 +35,7 @@ import java.util.Collection;
public class BootstrapPlugins extends SimpleCommand {
public void execute(Notification notification) {
public void execute(INotification notification) {
super.execute(notification);
facade = HyperLap2DFacade.getInstance();
@@ -18,19 +18,19 @@
package games.rednblack.editor.controller;
import com.puremvc.patterns.command.SimpleCommand;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.proxy.*;
import games.rednblack.editor.splash.SplashScreenAdapter;
import games.rednblack.h2d.common.proxy.CursorManager;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.command.SimpleCommand;
/**
* Created by sargis on 4/1/15.
*/
public class BootstrapProxyCommand extends SimpleCommand {
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
super.execute(notification);
facade = HyperLap2DFacade.getInstance();
facade.sendNotification(SplashScreenAdapter.UPDATE_SPLASH, "Loading Proxies...");
@@ -18,8 +18,6 @@
package games.rednblack.editor.controller;
import com.puremvc.patterns.command.SimpleCommand;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.splash.SplashScreenAdapter;
import games.rednblack.editor.view.ui.FollowersUIMediator;
@@ -35,13 +33,15 @@ import games.rednblack.editor.view.ui.panel.CustomVariablesPanelMediator;
import games.rednblack.editor.view.ui.panel.EditSpriteAnimationPanelMediator;
import games.rednblack.editor.view.ui.panel.ImportPanelMediator;
import games.rednblack.editor.view.ui.panel.TagsPanelMediator;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.command.SimpleCommand;
/**
* Created by sargis on 4/1/15.
*/
public class BootstrapViewCommand extends SimpleCommand {
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
super.execute(notification);
facade = HyperLap2DFacade.getInstance();
facade.sendNotification(SplashScreenAdapter.UPDATE_SPLASH, "Loading Views...");
@@ -18,9 +18,9 @@
package games.rednblack.editor.controller;
import com.puremvc.patterns.command.SimpleCommand;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.editor.HyperLap2DFacade;
import org.puremvc.java.patterns.command.SimpleCommand;
/**
* Created by azakhary on 4/28/2015.
@@ -18,7 +18,8 @@
package games.rednblack.editor.controller;
import com.puremvc.patterns.command.MacroCommand;
import org.puremvc.java.patterns.command.MacroCommand;
/**
* Created by sargis on 3/30/15.
@@ -28,9 +29,9 @@ public class StartupCommand extends MacroCommand {
protected void initializeMacroCommand() {
super.initializeMacroCommand();
addSubCommand(BootstrapProxyCommand.class);
addSubCommand(BootstrapViewCommand.class);
addSubCommand(BootstrapCommand.class);
addSubCommand(BootstrapPlugins.class);
addSubCommand(BootstrapProxyCommand::new);
addSubCommand(BootstrapViewCommand::new);
addSubCommand(BootstrapCommand::new);
addSubCommand(BootstrapPlugins::new);
}
}
@@ -2,7 +2,6 @@ package games.rednblack.editor.controller.commands;
import com.badlogic.gdx.math.Vector2;
import com.kotcrab.vis.ui.util.InputValidator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.controller.SandboxCommand;
import games.rednblack.editor.controller.commands.component.UpdatePolygonDataCommand;
@@ -13,6 +12,7 @@ import games.rednblack.editor.view.ui.followers.PolygonFollower;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.h2d.common.view.ui.dialog.MultipleInputDialog;
import games.rednblack.h2d.common.view.ui.listener.MultipleInputDialogListener;
import org.puremvc.java.interfaces.INotification;
import java.util.Collections;
@@ -21,7 +21,7 @@ public class ChangePolygonVertexPositionCommand extends SandboxCommand {
private Object[] currentCommandPayload;
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
super.execute(notification);
Object[] payload = notification.getBody();
@@ -2,7 +2,6 @@ package games.rednblack.editor.controller.commands;
import com.badlogic.gdx.math.Vector2;
import com.kotcrab.vis.ui.util.dialog.Dialogs;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.controller.SandboxCommand;
import games.rednblack.editor.controller.commands.component.UpdatePolygonDataCommand;
@@ -11,11 +10,12 @@ import games.rednblack.editor.renderer.utils.ComponentRetriever;
import games.rednblack.editor.utils.poly.PolygonUtils;
import games.rednblack.editor.view.ui.followers.PolygonFollower;
import games.rednblack.h2d.common.MsgAPI;
import org.puremvc.java.interfaces.INotification;
public class DeletePolygonVertexCommand extends SandboxCommand {
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
super.execute(notification);
Dialogs.showConfirmDialog(sandbox.getUIStage(), "Delete Vertex",
@@ -26,7 +26,7 @@ public class DeletePolygonVertexCommand extends SandboxCommand {
}).padBottom(20).pack();
}
private void callDoAction(Notification notification) {
private void callDoAction(INotification notification) {
Object[] payload = notification.getBody();
PolygonFollower follower = (PolygonFollower) payload[0];
int anchor = (int) payload[1];
@@ -18,15 +18,15 @@
package games.rednblack.editor.controller.commands;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.controller.SandboxCommand;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.h2d.common.MsgAPI;
import org.puremvc.java.interfaces.INotification;
public class ExportProjectCommand extends SandboxCommand {
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
projectManager.exportProject();
@@ -1,12 +1,12 @@
package games.rednblack.editor.controller.commands;
import com.kotcrab.vis.ui.util.dialog.Dialogs;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.controller.SandboxCommand;
import games.rednblack.editor.proxy.CommandManager;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.editor.proxy.SettingsManager;
import games.rednblack.editor.renderer.data.CompositeItemVO;
import org.puremvc.java.interfaces.INotification;
import java.util.HashMap;
@@ -16,7 +16,7 @@ import java.util.HashMap;
public abstract class NonRevertibleCommand extends SandboxCommand {
protected CommandManager commandManager;
protected Notification notification;
protected INotification notification;
protected boolean showConfirmDialog = true;
protected boolean isCancelled = false;
@@ -31,7 +31,7 @@ public abstract class NonRevertibleCommand extends SandboxCommand {
}
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
commandManager = facade.retrieveProxy(CommandManager.NAME);
this.notification = notification;
if (showConfirmDialog) {
@@ -18,20 +18,20 @@
package games.rednblack.editor.controller.commands;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.controller.SandboxCommand;
import games.rednblack.editor.proxy.CommandManager;
import org.puremvc.java.interfaces.INotification;
public abstract class RevertibleCommand extends SandboxCommand {
protected CommandManager commandManager;
protected Notification notification;
protected INotification notification;
protected boolean isCancelled = false;
protected boolean stateDone = false;
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
commandManager = facade.retrieveProxy(CommandManager.NAME);
this.notification = notification;
callDoAction();
@@ -50,7 +50,7 @@ public abstract class RevertibleCommand extends SandboxCommand {
undoAction();
}
public Notification getNotification() {
public INotification getNotification() {
return notification;
}
@@ -18,9 +18,9 @@
package games.rednblack.editor.controller.commands;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.controller.SandboxCommand;
import games.rednblack.editor.proxy.ProjectManager;
import org.puremvc.java.interfaces.INotification;
/**
* Created by azakhary on 11/12/2015.
@@ -28,7 +28,7 @@ import games.rednblack.editor.proxy.ProjectManager;
public class SaveExportPathCommand extends SandboxCommand {
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
String path = notification.getBody();
ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
@@ -1,13 +1,13 @@
package games.rednblack.editor.controller.commands;
import com.kotcrab.vis.ui.widget.toast.MessageToast;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.controller.SandboxCommand;
import org.puremvc.java.interfaces.INotification;
public class ShowNotificationCommand extends SandboxCommand {
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
String text = notification.getBody();
final MessageToast messageToast = new MessageToast(text);
messageToast.pad(10);
@@ -1,7 +1,7 @@
package games.rednblack.editor.controller.commands;
import com.badlogic.gdx.utils.Array;
import com.puremvc.patterns.observer.Notification;
import org.puremvc.java.interfaces.INotification;
/**
* Created by CyberJoe on 7/25/2015.
@@ -11,7 +11,7 @@ public abstract class TransactiveCommand extends RevertibleCommand {
protected Array<RevertibleCommand> commands = new Array();
@Override
public void execute(Notification notification) {
public void execute(INotification notification) {
this.notification = notification;
transaction();
super.execute(notification);
@@ -7,7 +7,6 @@ import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.puremvc.patterns.facade.Facade;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.editor.proxy.ResolutionManager;
@@ -15,6 +14,7 @@ import games.rednblack.editor.proxy.ResourceManager;
import games.rednblack.editor.renderer.SceneLoader;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.h2d.extention.spine.SpineItemType;
import org.puremvc.java.interfaces.IFacade;
public class LivePreviewScreen extends ScreenAdapter {
private Viewport viewport;
@@ -23,7 +23,7 @@ public class LivePreviewScreen extends ScreenAdapter {
private final ProjectManager projectManager;
private final Box2DDebugRenderer mBox2DDebugRenderer;
private final Facade facade = HyperLap2DFacade.getInstance();
private final IFacade facade = HyperLap2DFacade.getInstance();
private final Color bgColor;
public LivePreviewScreen() {
@@ -20,14 +20,14 @@ package games.rednblack.editor.proxy;
import java.util.ArrayList;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand;
import games.rednblack.editor.controller.commands.RevertibleCommand;
import games.rednblack.editor.controller.commands.TransactiveCommand;
import games.rednblack.editor.view.menu.FileMenu;
import org.puremvc.java.patterns.proxy.Proxy;
public class CommandManager extends BaseProxy {
public class CommandManager extends Proxy {
private static final String TAG = CommandManager.class.getCanonicalName();
public static final String NAME = TAG;
@@ -22,12 +22,12 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.renderer.utils.MySkin;
import org.puremvc.java.patterns.proxy.Proxy;
public class EditorTextureManager extends BaseProxy {
public class EditorTextureManager extends Proxy {
private static final String TAG = EditorTextureManager.class.getCanonicalName();
public static final String NAME = TAG;
@@ -21,13 +21,13 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.editor.HyperLap2DFacade;
import org.puremvc.java.patterns.proxy.Proxy;
/**
* Created by azakhary on 4/24/2015.
*/
public class FontManager extends BaseProxy {
public class FontManager extends Proxy {
private static final String TAG = FontManager.class.getCanonicalName();
public static final String NAME = TAG;
@@ -33,8 +33,6 @@ import games.rednblack.h2d.common.plugins.PluginAPI;
import games.rednblack.h2d.common.proxy.CursorManager;
import games.rednblack.h2d.common.view.tools.Tool;
import com.kotcrab.vis.ui.widget.VisImageButton;
import com.puremvc.patterns.facade.Facade;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.controller.commands.PluginItemCommand;
import games.rednblack.editor.factory.ItemFactory;
@@ -52,13 +50,15 @@ import games.rednblack.editor.view.ui.box.UILayerBoxMediator;
import games.rednblack.editor.view.ui.box.UIToolBoxMediator;
import games.rednblack.h2d.common.vo.CursorData;
import games.rednblack.h2d.common.vo.EditorConfigVO;
import org.puremvc.java.interfaces.IFacade;
import org.puremvc.java.patterns.proxy.Proxy;
import java.util.*;
/**
* Created by azakhary on 7/24/2015.
*/
public class PluginManager extends BaseProxy implements PluginAPI {
public class PluginManager extends Proxy implements PluginAPI {
private static final String TAG = PluginManager.class.getCanonicalName();
public static final String NAME = TAG;
@@ -205,7 +205,7 @@ public class PluginManager extends BaseProxy implements PluginAPI {
}
@Override
public Facade getFacade() {
public IFacade getFacade() {
return facade;
}
@@ -25,7 +25,6 @@ import com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Json;
import com.kotcrab.vis.ui.util.dialog.Dialogs;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.data.manager.PreferencesManager;
import games.rednblack.editor.data.migrations.ProjectVersionMigrator;
@@ -43,6 +42,7 @@ import games.rednblack.h2d.common.ProgressHandler;
import games.rednblack.h2d.common.vo.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.puremvc.java.patterns.proxy.Proxy;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
@@ -59,7 +59,7 @@ import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ProjectManager extends BaseProxy {
public class ProjectManager extends Proxy {
private static final String TAG = ProjectManager.class.getCanonicalName();
public static final String NAME = TAG;
private static final String EVENT_PREFIX = "games.rednblack.editor.proxy.ProjectManager";
@@ -33,13 +33,11 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.tools.texturepacker.TexturePacker;
import com.badlogic.gdx.tools.texturepacker.TextureUnpacker;
import com.badlogic.gdx.utils.Array;
import com.mortennobel.imagescaling.ResampleOp;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.h2d.common.ProgressHandler;
import games.rednblack.editor.HyperLap2DFacade;
@@ -47,8 +45,9 @@ import games.rednblack.editor.renderer.data.ProjectInfoVO;
import games.rednblack.editor.renderer.data.ResolutionEntryVO;
import games.rednblack.editor.utils.NinePatchUtils;
import games.rednblack.editor.utils.HyperLap2DUtils;
import org.puremvc.java.patterns.proxy.Proxy;
public class ResolutionManager extends BaseProxy {
public class ResolutionManager extends Proxy {
private static final String TAG = ResolutionManager.class.getCanonicalName();
public static final String NAME = TAG;
@@ -28,17 +28,17 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.utils.Json;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.editor.data.SpineAnimData;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.renderer.resources.FontSizePair;
import games.rednblack.editor.renderer.resources.IResourceRetriever;
import games.rednblack.editor.renderer.utils.MySkin;
import org.puremvc.java.patterns.proxy.Proxy;
/**
* Created by azakhary on 4/26/2015.
*/
public class ResourceManager extends BaseProxy implements IResourceRetriever {
public class ResourceManager extends Proxy implements IResourceRetriever {
public String packResolutionName = "orig";
@@ -20,10 +20,10 @@ package games.rednblack.editor.proxy;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.renderer.data.SceneVO;
import org.apache.commons.io.FileUtils;
import org.puremvc.java.patterns.proxy.Proxy;
import java.io.File;
import java.io.IOException;
@@ -32,7 +32,7 @@ import java.util.ArrayList;
/**
* Created by sargis on 3/23/15.
*/
public class SceneDataManager extends BaseProxy {
public class SceneDataManager extends Proxy {
private static final String TAG = SceneDataManager.class.getCanonicalName();
public static final String NAME = TAG;
@@ -3,18 +3,18 @@ package games.rednblack.editor.proxy;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Json;
import com.puremvc.patterns.proxy.BaseProxy;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.Main;
import games.rednblack.editor.utils.HyperLap2DUtils;
import games.rednblack.h2d.common.vo.EditorConfigVO;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.puremvc.java.patterns.proxy.Proxy;
import java.io.File;
import java.io.IOException;
public class SettingsManager extends BaseProxy {
public class SettingsManager extends Proxy {
private static final String TAG = SettingsManager.class.getCanonicalName();
public static final String NAME = TAG;
@@ -1,14 +1,11 @@
package games.rednblack.editor.splash;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DApp;
import games.rednblack.editor.HyperLap2DFacade;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SplashMediator extends SimpleMediator<Object> {
public class SplashMediator extends Mediator<Object> {
private static final String TAG = SplashMediator.class.getCanonicalName();
private static final String NAME = TAG;
@@ -32,7 +29,7 @@ public class SplashMediator extends SimpleMediator<Object> {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
super.handleNotification(notification);
System.out.println(notification.getBody().toString());
@@ -19,20 +19,19 @@
package games.rednblack.editor.view;
import com.badlogic.ashley.core.Engine;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.editor.proxy.SettingsManager;
import games.rednblack.h2d.common.MsgAPI;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.renderer.systems.render.HyperLap2dRenderer;
import games.rednblack.editor.view.stage.SandboxMediator;
import games.rednblack.editor.view.ui.widget.actors.basic.SandboxBackUI;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
/**
* Created by sargis on 3/30/15.
*/
public class HyperLap2DScreenMediator extends SimpleMediator<HyperLap2DScreen> {
public class HyperLap2DScreenMediator extends Mediator<HyperLap2DScreen> {
private static final String TAG = HyperLap2DScreenMediator.class.getCanonicalName();
public static final String NAME = TAG;
@@ -55,7 +54,7 @@ public class HyperLap2DScreenMediator extends SimpleMediator<HyperLap2DScreen> {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
super.handleNotification(notification);
switch (notification.getName()) {
case MsgAPI.CREATE:
@@ -27,19 +27,19 @@ import games.rednblack.h2d.common.view.ui.widget.HyperLapFileChooser;
import games.rednblack.h2d.common.MsgAPI;
import com.kotcrab.vis.ui.widget.file.FileChooser;
import com.kotcrab.vis.ui.widget.file.FileChooserAdapter;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.data.manager.PreferencesManager;
import games.rednblack.editor.proxy.CommandManager;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.editor.renderer.data.SceneVO;
import games.rednblack.editor.view.stage.Sandbox;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
/**
* Created by sargis on 3/25/15.
*/
public class HyperLap2DMenuBarMediator extends SimpleMediator<HyperLap2DMenuBar> {
public class HyperLap2DMenuBarMediator extends Mediator<HyperLap2DMenuBar> {
private static final String TAG = HyperLap2DMenuBarMediator.class.getCanonicalName();
public static final String NAME = TAG;
private ProjectManager projectManager;
@@ -81,7 +81,7 @@ public class HyperLap2DMenuBarMediator extends SimpleMediator<HyperLap2DMenuBar>
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
super.handleNotification(notification);
String type = notification.getType();
@@ -106,7 +106,7 @@ public class HyperLap2DMenuBarMediator extends SimpleMediator<HyperLap2DMenuBar>
}
}
private void handleGeneralNotification(Notification notification) {
private void handleGeneralNotification(INotification notification) {
switch (notification.getName()) {
case ProjectManager.PROJECT_OPENED:
onProjectOpened();
@@ -114,7 +114,7 @@ public class HyperLap2DMenuBarMediator extends SimpleMediator<HyperLap2DMenuBar>
}
}
private void handleEditMenuNotification(Notification notification) {
private void handleEditMenuNotification(INotification notification) {
Sandbox sandbox = Sandbox.getInstance();
switch (notification.getName()) {
case EditMenu.CUT:
@@ -137,7 +137,7 @@ public class HyperLap2DMenuBarMediator extends SimpleMediator<HyperLap2DMenuBar>
}
}
private void handleFileMenuNotification(Notification notification) {
private void handleFileMenuNotification(INotification notification) {
Sandbox sandbox = Sandbox.getInstance();
switch (notification.getName()) {
case FileMenu.NEW_PROJECT:
@@ -28,8 +28,6 @@ import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.SnapshotArray;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.h2d.common.view.tools.Tool;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.controller.commands.AddComponentToItemCommand;
import games.rednblack.editor.controller.commands.CompositeCameraChangeCommand;
@@ -42,6 +40,8 @@ import games.rednblack.editor.view.stage.input.EntityClickListener;
import games.rednblack.editor.view.stage.input.InputListenerComponent;
import games.rednblack.editor.view.stage.tools.*;
import games.rednblack.editor.view.ui.box.UIToolBoxMediator;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
import java.util.HashMap;
@@ -50,7 +50,7 @@ import static games.rednblack.editor.view.ui.box.UIToolBox.TOOL_CLICKED;
/**
* Created by sargis on 4/20/15.
*/
public class SandboxMediator extends SimpleMediator<Sandbox> {
public class SandboxMediator extends Mediator<Sandbox> {
private static final String TAG = SandboxMediator.class.getCanonicalName();
public static final String NAME = TAG;
@@ -110,7 +110,7 @@ public class SandboxMediator extends SimpleMediator<Sandbox> {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
super.handleNotification(notification);
switch (notification.getName()) {
case MsgAPI.SCENE_LOADED:
@@ -136,7 +136,7 @@ public class SandboxMediator extends SimpleMediator<Sandbox> {
}
}
private void handleSceneLoaded(Notification notification) {
private void handleSceneLoaded(INotification notification) {
initItemListeners();
setCurrentTool(SelectionTool.NAME);
@@ -22,14 +22,14 @@ import com.badlogic.ashley.core.Entity;
import games.rednblack.h2d.common.MsgAPI;
import com.kotcrab.vis.ui.util.dialog.Dialogs;
import com.kotcrab.vis.ui.util.dialog.InputDialogListener;
import com.puremvc.patterns.mediator.SimpleMediator;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
/**
* Created by sargis on 4/20/15.
*/
public class UIStageMediator extends SimpleMediator<UIStage> {
public class UIStageMediator extends Mediator<UIStage> {
private static final String TAG = UIStageMediator.class.getCanonicalName();
public static final String NAME = TAG;
@@ -51,7 +51,7 @@ public class UIStageMediator extends SimpleMediator<UIStage> {
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
switch (notification.getName()) {
case MsgAPI.SHOW_ADD_LIBRARY_DIALOG:
Sandbox sandbox = Sandbox.getInstance();
@@ -23,20 +23,19 @@ import com.badlogic.gdx.Input;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Vector2;
import games.rednblack.h2d.common.MsgAPI;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.controller.commands.AddComponentToItemCommand;
import games.rednblack.editor.controller.commands.RemoveComponentFromItemCommand;
import games.rednblack.editor.controller.commands.component.UpdatePolygonDataCommand;
import games.rednblack.editor.renderer.components.PolygonComponent;
import games.rednblack.editor.renderer.utils.ComponentRetriever;
import games.rednblack.editor.utils.poly.Clipper;
import games.rednblack.editor.utils.poly.PolygonUtils;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.editor.view.ui.FollowersUIMediator;
import games.rednblack.editor.view.ui.followers.BasicFollower;
import games.rednblack.editor.view.ui.followers.PolygonFollower;
import games.rednblack.editor.view.ui.followers.PolygonTransformationListener;
import org.puremvc.java.interfaces.INotification;
import java.util.Collections;
import java.util.HashSet;
@@ -85,7 +84,7 @@ public class PolygonTool extends SelectionTool implements PolygonTransformationL
}
@Override
public void handleNotification(Notification notification) {
public void handleNotification(INotification notification) {
switch (notification.getName()) {
case AddComponentToItemCommand.DONE:
updateSubFollowerList();

Some files were not shown because too many files have changed in this diff Show More