Revision: 462 http://skycastle.svn.sourceforge.net/skycastle/?rev=462&view=rev Author: zzorn Date: 2008-04-17 11:19:22 -0700 (Thu, 17 Apr 2008) Log Message: ----------- Now there is an UI button too, which calls the target game object. Modified Paths: -------------- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionMetadata.java trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/Action.java trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionFacadeImpl.java trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionImpl.java trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReference.java trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReferenceImpl.java trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReferenceListener.java trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReferenceImpl.java trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/TextFieldUi.java trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/example/UiDemo.java trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/uiidentity/UiMetadataImpl.java trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/view2d/renderer/SolidColorRenderer2D.java Added Paths: ----------- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionMetadataImpl.java trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ButtonUi.java trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/example/SayAct.java Removed Paths: ------------- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionButtonUi.java Modified: trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionMetadata.java =================================================================== --- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionMetadata.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionMetadata.java 2008-04-17 18:19:22 UTC (rev 462) @@ -1,16 +1,33 @@ package org.skycastle.core; +import org.skycastle.core.acting.Action; import org.skycastle.util.parameters.ParameterSetMetadata; import org.skycastle.util.uiidentity.UiMetadata; +import java.io.Serializable; + /** + * Metadata about an {@link Action} that a {@link GameObject} can have.. + * * @author Hans Haggstrom */ public interface ActionMetadata + extends Serializable { + + /** + * @return identifier of the action, used to call it with in the {@link GameObject} it is in. + */ String getIdentifier(); + /** + * @return metadata about the action itself, such as a description and icon for it. + */ UiMetadata getUiMetadata(); + /** + * @return metadata about the parameters of the action. + */ ParameterSetMetadata getParameterMetadata(); + } Added: trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionMetadataImpl.java =================================================================== --- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionMetadataImpl.java (rev 0) +++ trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionMetadataImpl.java 2008-04-17 18:19:22 UTC (rev 462) @@ -0,0 +1,83 @@ +package org.skycastle.core; + +import org.skycastle.util.ParameterChecker; +import org.skycastle.util.parameters.ParameterSetMetadata; +import org.skycastle.util.parameters.ParameterSetMetadataImpl; +import org.skycastle.util.uiidentity.UiMetadata; + +/** + * @author Hans Haggstrom + */ +public class ActionMetadataImpl + implements ActionMetadata +{ + + //====================================================================== + // Private Fields + + private final String myIdentifier; + private final UiMetadata myUiMetadata; + private final ParameterSetMetadata myParameterMetadata; + + //====================================================================== + // Private Constants + + private static final long serialVersionUID = 1L; + + //====================================================================== + // Public Methods + + //---------------------------------------------------------------------- + // Constructors + + /** + * Creates a new {@link ActionMetadata}, for an action with no parameters. + * + * @param identifier identifier of the action, used to call it with in the {@link GameObject} it is in. + * @param uiMetadata metadata about the action itself, such as a description and icon for it. + */ + public ActionMetadataImpl( final String identifier, + final UiMetadata uiMetadata ) + { + this( identifier, uiMetadata, new ParameterSetMetadataImpl() ); + } + + /** + * Creates a new {@link ActionMetadata}. + * + * @param identifier identifier of the action, used to call it with in the {@link GameObject} it is in. + * @param uiMetadata metadata about the action itself, such as a description and icon for it. + * @param parameterMetadata metadata about the parameters of the action. + */ + public ActionMetadataImpl( final String identifier, + final UiMetadata uiMetadata, + final ParameterSetMetadata parameterMetadata ) + { + ParameterChecker.checkNotNull( identifier, "identifier" ); + ParameterChecker.checkNotNull( uiMetadata, "uiMetadata" ); + ParameterChecker.checkNotNull( parameterMetadata, "parameterMetadata" ); + + myIdentifier = identifier; + myUiMetadata = uiMetadata; + myParameterMetadata = parameterMetadata; + } + + //---------------------------------------------------------------------- + // ActionMetadata Implementation + + public String getIdentifier() + { + return myIdentifier; + } + + public UiMetadata getUiMetadata() + { + return myUiMetadata; + } + + public ParameterSetMetadata getParameterMetadata() + { + return myParameterMetadata; + } + +} Modified: trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/Action.java =================================================================== --- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/Action.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/Action.java 2008-04-17 18:19:22 UTC (rev 462) @@ -1,10 +1,10 @@ package org.skycastle.core.acting; import com.sun.sgs.app.ManagedObject; +import org.skycastle.core.ActionMetadata; import org.skycastle.core.GameObject; import org.skycastle.util.parameters.ParameterSet; import org.skycastle.util.parameters.ParameterSetMetadata; -import org.skycastle.util.uiidentity.UiMetadata; /** * Something that a {@link GameObject} can do. Takes some number of parameters with some values (can be @@ -37,28 +37,10 @@ // DECISION: For now, lets go the route of one Action instance for each action for each game object. // The metadata can still be shared. This allows adding state getters, such as isEanbled, and getCooldown, to the Action. public interface Action - extends UiMetadata, ManagedObject + extends ManagedObject { //---------------------------------------------------------------------- - // UiMetadata Implementation - - /** - * @return A user readable name for this action. Typically similar to the identifier. - */ - String getUserReadableName(); - - /** - * @return an user readable description / tooltip for the action, null if no description is available. - */ - String getDescription(); - - /** - * @return a path to the icon for this action in the media directory, null if no icon is specified. - */ - String getIconPath(); - - //---------------------------------------------------------------------- // Other Public Methods /** @@ -88,4 +70,8 @@ */ ParameterSet getConfigurationParameters(); + /** + * @return Metadata about this action. + */ + ActionMetadata getMetadata(); } Modified: trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionFacadeImpl.java =================================================================== --- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionFacadeImpl.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionFacadeImpl.java 2008-04-17 18:19:22 UTC (rev 462) @@ -96,7 +96,16 @@ public ActionMetadata getActionMetadata( final String actionIdentifier ) { - throw new UnsupportedOperationException( "This method has not yet been implemented." ); // IMPLEMENT + final Action action = myActions.get( actionIdentifier ); + + if ( action != null ) + { + return action.getMetadata(); + } + else + { + return null; + } } @@ -344,7 +353,8 @@ * * @return the act event that should be invoked later if needed. */ - private ActEvent startAct( Act act, Action action, InvokeActionMessage invokeActionMessage ) throws ActionInvocationException + private ActEvent startAct( Act act, Action action, InvokeActionMessage invokeActionMessage ) + throws ActionInvocationException { ParameterSet parameters = invokeActionMessage.getParameters(); long actId = invokeActionMessage.getActId(); Modified: trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionImpl.java =================================================================== --- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionImpl.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionImpl.java 2008-04-17 18:19:22 UTC (rev 462) @@ -1,10 +1,13 @@ package org.skycastle.core.acting; +import org.skycastle.core.ActionMetadata; +import org.skycastle.core.ActionMetadataImpl; import org.skycastle.core.GameObject; import org.skycastle.util.ParameterChecker; import org.skycastle.util.StringUtilities; import org.skycastle.util.parameters.ParameterSet; import org.skycastle.util.parameters.ParameterSetMetadata; +import org.skycastle.util.uiidentity.UiMetadata; import org.skycastle.util.uiidentity.UiMetadataImpl; import java.util.logging.Level; @@ -18,7 +21,6 @@ * @author Hans Häggström */ public final class ActionImpl - extends UiMetadataImpl implements Action { @@ -30,6 +32,8 @@ private final String myActClassName; private final ParameterSet myConfigurationParameters; private final boolean myStoppable; + private final ActionMetadata myActionMetadata; + private final UiMetadata myUiMetadata; private volatile Class<? extends Act> myActClass = null; @@ -99,8 +103,6 @@ final boolean stoppable ) { - super( userReadableName, description, iconPath ); - ParameterChecker.checkIsIdentifier( identifier, "identifier" ); ParameterChecker.checkNotNull( parameterMetadata, "parameterMetadata" ); ParameterChecker.checkNotNull( userReadableName, "userReadableName" ); @@ -116,6 +118,9 @@ myParameterMetadata = parameterMetadata; myConfigurationParameters = configurationParameters; myStoppable = stoppable; + + myUiMetadata = new UiMetadataImpl( userReadableName, description, iconPath ); + myActionMetadata = new ActionMetadataImpl( myIdentifier, myUiMetadata, myParameterMetadata ); } //---------------------------------------------------------------------- @@ -144,6 +149,11 @@ return myConfigurationParameters; } + public ActionMetadata getMetadata() + { + return myActionMetadata; + } + //---------------------------------------------------------------------- // Other Public Methods Deleted: trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionButtonUi.java =================================================================== --- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionButtonUi.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionButtonUi.java 2008-04-17 18:19:22 UTC (rev 462) @@ -1,107 +0,0 @@ -package org.skycastle.ui; - -import org.skycastle.core.ActionMetadata; -import org.skycastle.util.parameters.ParameterSet; -import org.skycastle.util.parameters.ParameterSetImpl; - -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** - * An UI object that shows a button, which will invoke a specified action when pressed. - * - * @author Hans Haggstrom - */ -// TODO: Option for wether this action button UI should be a toolbutton or full button? Maybe automatially resizing based on availabel space / importance / user preference / layout? -public class ActionButtonUi - extends UiObject -{ - - //====================================================================== - // Private Fields - - private final ActionReference myActionReference = new ActionReferenceImpl(); - - private JButton myButton = null; - private ParameterSet myParameters = new ParameterSetImpl(); - - //====================================================================== - // Private Constants - - private static final long serialVersionUID = 1L; - - //====================================================================== - // Protected Methods - - @Override - protected JComponent createUi() - { - myButton = new JButton(); - - updateAction(); - - myActionReference.addActionReferenceListener( new ActionReferenceListener() - { - - public void onActionMetadataChanged( final ActionReference actionReference ) - { - updateAction(); - } - - - public void onActionDisappeared( final ActionReference actionReference ) - { - updateAction(); - } - - - public void onActionAppeared( final ActionReference actionReference ) - { - updateAction(); - } - - } ); - - myButton.addActionListener( new ActionListener() - { - - public void actionPerformed( final ActionEvent e ) - { - if ( myActionReference.isAvailable() ) - { - myActionReference.invokeAction( myParameters ); - } - } - - } ); - - return myButton; - } - - //====================================================================== - // Private Methods - - private void updateAction() - { - if ( myActionReference.isAvailable() ) - { - myButton.setEnabled( true ); - final ActionMetadata actionMetadata = myActionReference.getMetadata(); - - myButton.setText( actionMetadata.getUiMetadata().getUserReadableName() ); - myButton.setToolTipText( actionMetadata.getUiMetadata().getDescription() ); - - // TODO: Set icon based on the icon metadata - } - else - { - myButton.setEnabled( false ); - - myButton.setText( "" ); - myButton.setToolTipText( null ); - myButton.setIcon( null ); - } - } - -} Modified: trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReference.java =================================================================== --- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReference.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReference.java 2008-04-17 18:19:22 UTC (rev 462) @@ -1,6 +1,7 @@ package org.skycastle.ui; import org.skycastle.core.ActionMetadata; +import org.skycastle.core.GameObjectId; import org.skycastle.util.parameters.ParameterSet; import java.io.Serializable; @@ -21,6 +22,14 @@ ActionMetadata getMetadata(); - void invokeAction( ParameterSet parameters ); + void invokeAction( GameObjectId caller, ParameterSet parameters ); + /** + * Removes the specified ActionReferenceListener. + * + * @param listener should not be null, and should be present. + */ + void removeActionReferenceListener( ActionReferenceListener listener ); + + void setReference( final GameObjectId gameObjectId, final String actionIdentifier ); } Modified: trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReferenceImpl.java =================================================================== --- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReferenceImpl.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReferenceImpl.java 2008-04-17 18:19:22 UTC (rev 462) @@ -1,8 +1,17 @@ package org.skycastle.ui; import org.skycastle.core.ActionMetadata; +import org.skycastle.core.GameContext; +import org.skycastle.core.GameObject; +import org.skycastle.core.GameObjectId; +import org.skycastle.messaging.modifications.action.InvokeActionMessage; +import org.skycastle.util.ParameterChecker; import org.skycastle.util.parameters.ParameterSet; +import java.util.HashSet; +import java.util.Random; +import java.util.Set; + /** * @author Hans Haggstrom */ @@ -11,6 +20,16 @@ { //====================================================================== + // Private Fields + + private final Set<ActionReferenceListener> myActionReferenceListeners = new HashSet<ActionReferenceListener>( 5 ); + + private GameObjectId myGameObjectId; + private String myActionIdentifier; + + private transient Random myRandom = null; + + //====================================================================== // Private Constants private static final long serialVersionUID = 1L; @@ -19,26 +38,128 @@ // Public Methods //---------------------------------------------------------------------- + // Constructors + + public ActionReferenceImpl() + { + } + + public ActionReferenceImpl( final GameObjectId gameObjectId, final String actionIdentifier ) + { + myGameObjectId = gameObjectId; + myActionIdentifier = actionIdentifier; + } + + //---------------------------------------------------------------------- // ActionReference Implementation - public void addActionReferenceListener( final ActionReferenceListener listener ) + public void addActionReferenceListener( ActionReferenceListener listener ) { - throw new UnsupportedOperationException( "This method has not yet been implemented." ); // IMPLEMENT + ParameterChecker.checkNotNull( listener, "listener" ); + ParameterChecker.checkNotAlreadyContained( listener, myActionReferenceListeners, "myActionReferenceListeners" ); + + myActionReferenceListeners.add( listener ); } + public boolean isAvailable() { - throw new UnsupportedOperationException( "This method has not yet been implemented." ); // IMPLEMENT + final GameObject gameObject = GameContext.getGameObjectContext().getGameObjectById( myGameObjectId, + false ); + + if ( gameObject != null ) + { + return gameObject.hasAction( myActionIdentifier ); + } + else + { + return false; + } } public ActionMetadata getMetadata() { - throw new UnsupportedOperationException( "This method has not yet been implemented." ); // IMPLEMENT + final GameObject gameObject = GameContext.getGameObjectContext().getGameObjectById( myGameObjectId, + false ); + + if ( gameObject != null ) + { + return gameObject.getActionMetadata( myActionIdentifier ); + } + else + { + return null; + } } - public void invokeAction( final ParameterSet parameters ) + public void invokeAction( GameObjectId caller, final ParameterSet parameters ) { - throw new UnsupportedOperationException( "This method has not yet been implemented." ); // IMPLEMENT + final GameObject gameObject = GameContext.getGameObjectContext().getGameObjectById( myGameObjectId, false ); + + if ( gameObject != null ) + { + final long actId = getNextActId(); + + gameObject.startAction( new InvokeActionMessage( caller, + myGameObjectId, + myActionIdentifier, + actId, + parameters ) ); + + // TODO: Store list of invoked act ID:s, so we can know which ones returned act updates belong to. + } } + public void removeActionReferenceListener( ActionReferenceListener listener ) + { + ParameterChecker.checkNotNull( listener, "removedActionReferenceListener" ); + ParameterChecker.checkContained( listener, myActionReferenceListeners, "myActionReferenceListeners" ); + + myActionReferenceListeners.remove( listener ); + } + + //---------------------------------------------------------------------- + // Other Public Methods + + public GameObjectId getGameObjectId() + { + return myGameObjectId; + } + + + public void setReference( final GameObjectId gameObjectId, final String actionIdentifier ) + { + myGameObjectId = gameObjectId; + myActionIdentifier = actionIdentifier; + + notifyActionChanged(); + } + + + public void clearReference() + { + setReference( null, null ); + } + + //====================================================================== + // Private Methods + + private void notifyActionChanged() + { + for ( ActionReferenceListener listener : myActionReferenceListeners ) + { + listener.onActionChanged( this ); + } + } + + private long getNextActId() + { + if ( myRandom == null ) + { + myRandom = new Random(); + } + + return myRandom.nextLong(); + } + } Modified: trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReferenceListener.java =================================================================== --- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReferenceListener.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ActionReferenceListener.java 2008-04-17 18:19:22 UTC (rev 462) @@ -6,11 +6,7 @@ public interface ActionReferenceListener { - void onActionMetadataChanged( ActionReference actionReference ); + void onActionChanged( ActionReference actionReference ); - void onActionDisappeared( ActionReference actionReference ); - - void onActionAppeared( ActionReference actionReference ); - } Added: trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ButtonUi.java =================================================================== --- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ButtonUi.java (rev 0) +++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/ButtonUi.java 2008-04-17 18:19:22 UTC (rev 462) @@ -0,0 +1,134 @@ +package org.skycastle.ui; + +import org.skycastle.core.ActionMetadata; +import org.skycastle.core.GameObjectId; +import org.skycastle.util.parameters.ParameterSet; +import org.skycastle.util.parameters.ParameterSetImpl; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + + +/** + * An button UI element that invokes a specified action with the specified parameters when pressed. + * + * @author Hans Haggstrom + */ +// TODO: Option for wether this action button UI should be a toolbutton or full button? Maybe automatially resizing based on availabel space / importance / user preference / layout? +public final class ButtonUi + extends UiObject +{ + + //====================================================================== + // Private Fields + + private final ActionReference myActionReference = new ActionReferenceImpl(); + + private JButton myButton = null; + private ParameterSet myParameters = new ParameterSetImpl(); + + //====================================================================== + // Private Constants + + private static final long serialVersionUID = 1L; + + //====================================================================== + // Public Methods + + //---------------------------------------------------------------------- + // Constructors + + public ButtonUi( GameObjectId gameObjectId, String actionIdentifier ) + { + myActionReference.setReference( gameObjectId, actionIdentifier ); + } + + //---------------------------------------------------------------------- + // Other Public Methods + + public ActionReference getActionReference() + { + return myActionReference; + } + + + public ParameterSet getParameters() + { + return myParameters; + } + + + public void setParameters( final ParameterSet parameters ) + { + myParameters = parameters; + } + + //====================================================================== + // Protected Methods + + @Override + protected JComponent createUi() + { + myButton = new JButton(); + + updateUiFromModel(); + + myActionReference.addActionReferenceListener( new ActionReferenceListener() + { + + public void onActionChanged( final ActionReference actionReference ) + { + updateUiFromModel(); + } + + } ); + + myButton.addActionListener( new ActionListener() + { + + public void actionPerformed( final ActionEvent e ) + { + if ( myActionReference.isAvailable() ) + { + myActionReference.invokeAction( getId(), myParameters ); + } + } + + } ); + + return myButton; + } + + //====================================================================== + // Private Methods + + private void updateUiFromModel() + { + if ( myButton != null ) + { + if ( myActionReference != null && + myActionReference.getMetadata() != null ) + { + final ActionMetadata actionMetadata = myActionReference.getMetadata(); + myButton.setText( actionMetadata.getUiMetadata().getUserReadableName() ); + myButton.setToolTipText( actionMetadata.getUiMetadata().getDescription() ); + // TODO: Set icon + } + else + { + myButton.setText( "" ); + myButton.setToolTipText( null ); + } + + myButton.setEnabled( isEnabled() ); + } + } + + private boolean isEnabled() + { + return myActionReference != null && + myActionReference.isAvailable(); + } + +} Modified: trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReferenceImpl.java =================================================================== --- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReferenceImpl.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReferenceImpl.java 2008-04-17 18:19:22 UTC (rev 462) @@ -39,13 +39,13 @@ public GameObjectId getGameObjectId() { - throw new UnsupportedOperationException( "This method has not yet been implemented." ); // IMPLEMENT + return myGameObjectId; } public String getPropertyIdentifier() { - throw new UnsupportedOperationException( "This method has not yet been implemented." ); // IMPLEMENT + return myPropertyIdentifier; } @@ -60,7 +60,7 @@ public void clearReference() { - throw new UnsupportedOperationException( "This method has not yet been implemented." ); // IMPLEMENT + setReference( null, null ); } Modified: trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/TextFieldUi.java =================================================================== --- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/TextFieldUi.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/TextFieldUi.java 2008-04-17 18:19:22 UTC (rev 462) @@ -109,7 +109,13 @@ @Override protected void updateValue( final Object propertyValue ) { - myTextField.setText( propertyValue.toString() ); + String value = ""; + if ( propertyValue != null ) + { + value = propertyValue.toString(); + } + + myTextField.setText( value ); } } Added: trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/example/SayAct.java =================================================================== --- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/example/SayAct.java (rev 0) +++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/example/SayAct.java 2008-04-17 18:19:22 UTC (rev 462) @@ -0,0 +1,59 @@ +package org.skycastle.ui.example; + +import org.skycastle.core.GameObject; +import org.skycastle.core.acting.Act; +import org.skycastle.messaging.MessageListener; +import org.skycastle.util.parameters.ParameterSet; + +/** + * A demo version of a say act. + * + * @author Hans Haggstrom + */ +public class SayAct + implements Act +{ + + //====================================================================== + // Private Constants + + private static final long serialVersionUID = 1L; + + //====================================================================== + // Public Methods + + //---------------------------------------------------------------------- + // Act Implementation + + public long start( final GameObject hostObject, + final MessageListener messageHandler, + final ParameterSet actParameters, + final ParameterSet configurationParameters ) + throws Exception + { + System.out.println( "'" + hostObject.getId() + "' says: " + actParameters.getString( "message", "" ) ); + + return -1; + } + + public long doStep( final GameObject hostObject, + final MessageListener messageHandler, + final ParameterSet parameters, + final ParameterSet configurationParameters, + final long timeSinceLastCall_ms ) + throws Exception + { + throw new UnsupportedOperationException( "This method is not supported." ); + } + + public void stop( final GameObject hostObject, + final MessageListener messageHandler, + final ParameterSet parameters, + final ParameterSet configurationParameters, + final long timeSinceLastCall_ms ) + throws Exception + { + // Nothing to do + } + +} Modified: trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/example/UiDemo.java =================================================================== --- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/example/UiDemo.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/example/UiDemo.java 2008-04-17 18:19:22 UTC (rev 462) @@ -1,11 +1,14 @@ package org.skycastle.ui.example; import org.skycastle.core.*; +import org.skycastle.core.acting.ActionImpl; import org.skycastle.messaging.Message; import org.skycastle.messaging.MessageListener; import org.skycastle.messaging.updates.property.PropertyChangedMessage; import org.skycastle.ui.*; import org.skycastle.util.parameters.ParameterMetadataImpl; +import org.skycastle.util.parameters.ParameterSetImpl; +import org.skycastle.util.parameters.ParameterSetMetadataImpl; import org.skycastle.util.parameters.ParameterValidationException; import org.skycastle.util.uiidentity.UiMetadataImpl; @@ -51,11 +54,17 @@ final TextFieldUi mana = new TextFieldUi( exampleGameObject.getId(), "mana" ); final ListUi inventory = new ListUi( exampleGameObject.getId(), "inventory" ); + final TextFieldUi message = new TextFieldUi( exampleGameObject.getId(), "message" ); + final ButtonUi say = new ButtonUi( exampleGameObject.getId(), "say" ); + say.setParameters( new ParameterSetImpl( "message", "Boo!" ) ); + final PanelUi panelUi = new PanelUi(); panelUi.addUi( hp ); panelUi.addUi( mana ); panelUi.addUi( inventory ); + panelUi.addUi( message ); + panelUi.addUi( say ); return panelUi; } @@ -84,6 +93,14 @@ gameObject.addPropertyElement( "inventory", "A strange looking device with a soft rubber button" ); gameObject.addPropertyElement( "inventory", "Blueprints titled 'EXPERIMENTAL - Do not build!'" ); + + + gameObject.addProperty( "message", "", "Somethign to say" ); + + + final ParameterSetMetadataImpl sayActionMetadata = new ParameterSetMetadataImpl(); + sayActionMetadata.setMetadata( "message", new ParameterMetadataImpl( String.class, true ) ); + gameObject.addAction( new ActionImpl( "say", sayActionMetadata, SayAct.class, "Say", "say something", null, null, false ) ); } catch ( ParameterValidationException e ) { Modified: trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/uiidentity/UiMetadataImpl.java =================================================================== --- trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/uiidentity/UiMetadataImpl.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/uiidentity/UiMetadataImpl.java 2008-04-17 18:19:22 UTC (rev 462) @@ -1,10 +1,12 @@ package org.skycastle.util.uiidentity; +import java.io.Serializable; + /** * {@inheritDoc} */ public class UiMetadataImpl - implements UiMetadata + implements UiMetadata, Serializable { //====================================================================== @@ -17,6 +19,11 @@ private final String myIconPath; //====================================================================== + // Private Constants + + private static final long serialVersionUID = 1L; + + //====================================================================== // Public Methods //---------------------------------------------------------------------- Modified: trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/view2d/renderer/SolidColorRenderer2D.java =================================================================== --- trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/view2d/renderer/SolidColorRenderer2D.java 2008-04-14 18:52:29 UTC (rev 461) +++ trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/view2d/renderer/SolidColorRenderer2D.java 2008-04-17 18:19:22 UTC (rev 462) @@ -103,8 +103,7 @@ final ParameterSetMetadataImpl metadata = new ParameterSetMetadataImpl(); - metadata.setMetadata( "color", - new ParameterMetadataImpl( Color.class, false, new UiMetadataImpl( "Color", "The solid color to render" ) ) ); + metadata.setMetadata( "color", new ParameterMetadataImpl( Color.class, false, new UiMetadataImpl( "Color", "The solid color to render" ) ) ); return metadata; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.