[skycastle-commits] SF.net SVN: skycastle: [449] trunk/skycastle/modules

  • From: zzorn@xxxxxxxxxxxxxxxxxxxxx
  • To: skycastle-commits@xxxxxxxxxxxxx
  • Date: Tue, 08 Apr 2008 01:39:57 -0700

Revision: 449
          http://skycastle.svn.sourceforge.net/skycastle/?rev=449&view=rev
Author:   zzorn
Date:     2008-04-08 01:39:57 -0700 (Tue, 08 Apr 2008)

Log Message:
-----------
Started sketching out the UI code

Modified Paths:
--------------
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DynamicGameObject.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/pojo/PojoGameObject.java
    trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/UiObject.java

Added Paths:
-----------
    
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyListener.java
    
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReference.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

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
        2008-04-06 03:04:12 UTC (rev 448)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
        2008-04-08 08:39:57 UTC (rev 449)
@@ -60,57 +60,57 @@
     //----------------------------------------------------------------------
     // ActionFacade Implementation
 
-    public void startAction( final InvokeActionMessage invokeActionMessage )
+    public final void startAction( final InvokeActionMessage 
invokeActionMessage )
     {
         myActionFacade.startAction( invokeActionMessage );
     }
 
 
-    public long startAction( final GameObjectId callerId, final String 
actionIdentifier )
+    public final long startAction( final GameObjectId callerId, final String 
actionIdentifier )
     {
         return myActionFacade.startAction( callerId, actionIdentifier );
     }
 
 
-    public long startAction( final GameObjectId callerId,
-                             final String actionIdentifier,
-                             final Object... parameters )
+    public final long startAction( final GameObjectId callerId,
+                                   final String actionIdentifier,
+                                   final Object... parameters )
     {
         return myActionFacade.startAction( callerId, actionIdentifier, 
parameters );
     }
 
 
-    public void stopAction( final String actionIdentifier, final long actId )
+    public final void stopAction( final String actionIdentifier, final long 
actId )
     {
         myActionFacade.stopAction( actionIdentifier, actId );
     }
 
 
-    public ActionMetadata getActionMetadata( final String actionIdentifier )
+    public final ActionMetadata getActionMetadata( final String 
actionIdentifier )
     {
         return myActionFacade.getActionMetadata( actionIdentifier );
     }
 
 
-    public void addAction( final Action action )
+    public final void addAction( final Action action )
     {
         myActionFacade.addAction( action );
     }
 
 
-    public void removeAction( final String actionIdentifier )
+    public final void removeAction( final String actionIdentifier )
     {
         myActionFacade.removeAction( actionIdentifier );
     }
 
 
-    public boolean hasAction( final String actionIdentifier )
+    public final boolean hasAction( final String actionIdentifier )
     {
         return myActionFacade.hasAction( actionIdentifier );
     }
 
 
-    public Set<String> getActionIdentifiers()
+    public final Set<String> getActionIdentifiers()
     {
         return myActionFacade.getActionIdentifiers();
     }
@@ -140,33 +140,33 @@
     //----------------------------------------------------------------------
     // MessagingFacade Implementation
 
-    public void addIndirectUpdateListener( final UpdateListenerFilter filter, 
final GameObjectId observerId )
+    public final void addIndirectUpdateListener( final UpdateListenerFilter 
filter, final GameObjectId observerId )
     {
         myMessagingFacade.addIndirectUpdateListener( filter, observerId );
     }
 
 
-    public void removeIndirectUpdateListener( final UpdateListenerFilter 
filter,
-                                              final GameObjectId observerId )
+    public final void removeIndirectUpdateListener( final UpdateListenerFilter 
filter,
+                                                    final GameObjectId 
observerId )
     {
         myMessagingFacade.removeIndirectUpdateListener( filter, observerId );
     }
 
 
-    public void addDirectUpdateListener( final UpdateListenerFilter filter, 
final MessageListener listener )
+    public final void addDirectUpdateListener( final UpdateListenerFilter 
filter, final MessageListener listener )
     {
         myMessagingFacade.addDirectUpdateListener( filter, listener );
     }
 
 
-    public void removeDirectUpdateListener( final UpdateListenerFilter filter,
-                                            final MessageListener 
messageListener )
+    public final void removeDirectUpdateListener( final UpdateListenerFilter 
filter,
+                                                  final MessageListener 
messageListener )
     {
         myMessagingFacade.removeDirectUpdateListener( filter, messageListener 
);
     }
 
 
-    public void sendUpdateToObservers( final UpdateMessage updateMessage )
+    public final void sendUpdateToObservers( final UpdateMessage updateMessage 
)
     {
         myMessagingFacade.sendUpdateToObservers( updateMessage );
     }
@@ -174,75 +174,75 @@
     //----------------------------------------------------------------------
     // PropertyFacade Implementation
 
-    public <T> T getPropertyValue( final String propertyIdentifier, final T 
defaultValue )
+    public final <T> T getPropertyValue( final String propertyIdentifier, 
final T defaultValue )
     {
         return myPropertyFacade.getPropertyValue( propertyIdentifier, 
defaultValue );
     }
 
 
-    public void setPropertyValue( final String propertyIdentifier, final 
Serializable value )
+    public final void setPropertyValue( final String propertyIdentifier, final 
Serializable value )
             throws ParameterValidationException
     {
         myPropertyFacade.setPropertyValue( propertyIdentifier, value );
     }
 
 
-    public boolean hasProperty( final String propertyIdentifier )
+    public final boolean hasProperty( final String propertyIdentifier )
     {
         return myPropertyFacade.hasProperty( propertyIdentifier );
     }
 
 
-    public Set<String> getPropertyIdentifiers()
+    public final Set<String> getPropertyIdentifiers()
     {
         return myPropertyFacade.getPropertyIdentifiers();
     }
 
 
-    public ParameterMetadata getPropertyMetadata( final String 
propertyIdentifier )
+    public final ParameterMetadata getPropertyMetadata( final String 
propertyIdentifier )
     {
         return myPropertyFacade.getPropertyMetadata( propertyIdentifier );
     }
 
 
-    public void addProperty( final String propertyIdentifier, final 
Serializable initialValue )
+    public final void addProperty( final String propertyIdentifier, final 
Serializable initialValue )
             throws ParameterValidationException
     {
         myPropertyFacade.addProperty( propertyIdentifier, initialValue );
     }
 
 
-    public void addProperty( final String propertyIdentifier,
-                             final Serializable initialValue,
-                             final ParameterMetadata propertyMetadata )
+    public final void addProperty( final String propertyIdentifier,
+                                   final Serializable initialValue,
+                                   final ParameterMetadata propertyMetadata )
             throws ParameterValidationException
     {
         myPropertyFacade.addProperty( propertyIdentifier, initialValue, 
propertyMetadata );
     }
 
 
-    public void addProperty( final String propertyIdentifier,
-                             final Serializable initialValue,
-                             final String description,
-                             final ParameterValidator... validators )
+    public final void addProperty( final String propertyIdentifier,
+                                   final Serializable initialValue,
+                                   final String description,
+                                   final ParameterValidator... validators )
             throws ParameterValidationException
     {
         myPropertyFacade.addProperty( propertyIdentifier, initialValue, 
description, validators );
     }
 
 
-    public <T extends Serializable> void addProperty( final String 
propertyIdentifier,
-                                                      final T initialValue,
-                                                      final Class<T> type,
-                                                      final String description,
-                                                      final 
ParameterValidator... validators )
+    public final <T extends Serializable> void addProperty( final String 
propertyIdentifier,
+                                                            final T 
initialValue,
+                                                            final Class<T> 
type,
+                                                            final String 
description,
+                                                            final 
ParameterValidator... validators )
             throws ParameterValidationException
     {
         myPropertyFacade.addProperty( propertyIdentifier, initialValue, type, 
description, validators );
     }
 
 
-    public void removeProperty( final String propertyIdentifier )
+    public final void removeProperty( final String propertyIdentifier )
             throws ParameterValidationException
     {
         myPropertyFacade.removeProperty( propertyIdentifier );
@@ -251,10 +251,9 @@
     //----------------------------------------------------------------------
     // Task Implementation
 
-//----------------------------------------------------------------------
-    // Task Implementation
 
-    public void run() throws Exception
+    public final void run()
+            throws Exception
     {
         myActionFacade.runScheduledActs( 
getGameObjectContext().getCurrentGameTime_ms() );
     }

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DynamicGameObject.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DynamicGameObject.java
        2008-04-06 03:04:12 UTC (rev 448)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DynamicGameObject.java
        2008-04-08 08:39:57 UTC (rev 449)
@@ -5,6 +5,7 @@
  * members.
  *
  * @author Hans Häggström
+ * @deprecated DefaultGameObject does this.
  */
 public class DynamicGameObject
         extends DefaultGameObject

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/pojo/PojoGameObject.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/pojo/PojoGameObject.java
      2008-04-06 03:04:12 UTC (rev 448)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/pojo/PojoGameObject.java
      2008-04-08 08:39:57 UTC (rev 449)
@@ -1,7 +1,6 @@
 package org.skycastle.core.pojo;
 
-import com.sun.sgs.app.ManagedObject;
-import org.skycastle.core.DynamicGameObject;
+import org.skycastle.core.DefaultGameObject;
 import org.skycastle.core.GameObject;
 
 /**
@@ -12,15 +11,16 @@
  * with the right annotations, listener addition and removal methods can be 
converted to sensors, and so on.
  */
 public abstract class PojoGameObject
-        extends DynamicGameObject
-        implements ManagedObject
+        extends DefaultGameObject
 {
+    protected PojoGameObject()
+    {
+        // Scan geters and setters of this object, register them as properties 
if they are annotated as such
 
-    //======================================================================
-    // Public Methods
+        // Scan methods of this object, and register them as actions if they 
are annotated as such
 
-    //----------------------------------------------------------------------
-    // MessageListener Implementation
+        // Listen to field updates, and notify listeners
 
 
+    }
 }

Added: 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyListener.java
===================================================================
--- 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyListener.java 
                            (rev 0)
+++ 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyListener.java 
    2008-04-08 08:39:57 UTC (rev 449)
@@ -0,0 +1,25 @@
+package org.skycastle.ui;
+
+import org.skycastle.util.parameters.ParameterMetadata;
+
+/**
+ * A listener that is notified of property value changes.
+ *
+ * @author Hans Haggstrom
+ */
+public interface PropertyListener
+{
+    void onPropertyValueChange( Object newValue );
+
+    void onPropertyMetadataChanged( ParameterMetadata newMetadata );
+
+    /**
+     * Called when the property is no longer available.
+     */
+    void onPropertyDissappeared();
+
+    /**
+     * Called when a new property is available.
+     */
+    void onPropertyAppeared( ParameterMetadata parameterMetadata, Object 
parameterValue, boolean editable );
+}

Added: 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReference.java
===================================================================
--- 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReference.java
                            (rev 0)
+++ 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReference.java
    2008-04-08 08:39:57 UTC (rev 449)
@@ -0,0 +1,90 @@
+package org.skycastle.ui;
+
+import org.skycastle.core.GameObject;
+import org.skycastle.core.GameObjectId;
+import org.skycastle.util.parameters.ParameterMetadata;
+import org.skycastle.util.parameters.ParameterValidationException;
+
+import java.io.Serializable;
+
+/**
+ * A reference to some property of some game object.
+ *
+ * @author Hans Haggstrom
+ */
+public interface PropertyReference
+        extends Serializable
+{
+
+    /**
+     * @return the ID of the {@link GameObject} that the referenced property 
is in.
+     */
+    GameObjectId getGameObjectId();
+
+    /**
+     * @return the identifier of the property in the specified {@link 
GameObject}
+     */
+    String getPropertyIdentifier();
+
+    /**
+     * Change the property that this reference refers to.
+     *
+     * @param gameObjectId       the ID of the {@link GameObject} that the 
property is in.
+     * @param propertyIdentifier the identifier of the property in the {@link 
GameObject}.
+     */
+    void setReference( GameObjectId gameObjectId, String propertyIdentifier );
+
+    /**
+     * Makes this reference refer to no property.
+     */
+    void clearReference();
+
+
+    /**
+     * @return true if there actually is some refered property, false if it is 
not found.
+     */
+    boolean isReferenceExisting();
+
+    /**
+     * @return metadata for the property.
+     */
+    ParameterMetadata getPropertyMetadata();
+
+    /**
+     * Sets a new value to the property.
+     *
+     * @param caller the ID of the {@link GameObject} that wants to set the 
property.  Used for access rights checking.
+     * @param value  the new value to apply.
+     *
+     * @throws ParameterValidationException if the parameter did not validate 
against the metadata.
+     */
+    void setProperty( GameObjectId caller, Object value )
+            throws ParameterValidationException;
+
+    /**
+     * Gets the value of the property.
+     *
+     * @param caller       the ID of the {@link GameObject} that wants to get 
the property.  Used for access rights checking.
+     * @param defaultValue the value to use if the parameter is not available.
+     * @param expectedType the type that the property is assumed to be.
+     *
+     * @return the requested proeprt value, or the default value if the 
property is not available
+     */
+    <T> T getProperty( GameObjectId caller, Class<T> expectedType, T 
defaultValue );
+
+
+    /**
+     * @param listener a listener that is notified when the value changes.
+     */
+    void addChangeListener( PropertyListener listener );
+
+    /**
+     * @param listener listener to remove.
+     */
+    void removeChangeListener( PropertyListener listener );
+
+    /**
+     * @return true if the property is editable.
+     */
+    boolean isEditable();
+}

Added: 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReferenceImpl.java
===================================================================
--- 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReferenceImpl.java
                                (rev 0)
+++ 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/PropertyReferenceImpl.java
        2008-04-08 08:39:57 UTC (rev 449)
@@ -0,0 +1,68 @@
+package org.skycastle.ui;
+
+import org.skycastle.core.GameObjectId;
+import org.skycastle.util.parameters.ParameterMetadata;
+import org.skycastle.util.parameters.ParameterValidationException;
+
+/**
+ * @author Hans Haggstrom
+ */
+public class PropertyReferenceImpl
+        implements PropertyReference
+{
+    public GameObjectId getGameObjectId()
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public String getPropertyIdentifier()
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public void setReference( final GameObjectId gameObjectId, final String 
propertyIdentifier )
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public void clearReference()
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public boolean isReferenceExisting()
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public ParameterMetadata getPropertyMetadata()
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public void setProperty( final GameObjectId caller, final Object value )
+            throws ParameterValidationException
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public <T> T getProperty( final GameObjectId caller, final Class<T> 
expectedType, final T defaultValue )
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public void addChangeListener( final PropertyListener listener )
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public void removeChangeListener( final PropertyListener listener )
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public boolean isEditable()
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+}

Added: 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/TextFieldUi.java
===================================================================
--- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/TextFieldUi.java  
                        (rev 0)
+++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/TextFieldUi.java  
2008-04-08 08:39:57 UTC (rev 449)
@@ -0,0 +1,113 @@
+package org.skycastle.ui;
+
+import org.skycastle.util.parameters.ParameterMetadata;
+import org.skycastle.util.parameters.ParameterValidationException;
+import org.skycastle.util.parameters.ValidationError;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.List;
+
+/**
+ * Shows and edits a specified property as text.
+ *
+ * @author Hans Haggstrom
+ */
+public class TextFieldUi
+        extends UiObject
+{
+    private final PropertyReference myPropertyReference = new 
PropertyReferenceImpl();
+    private JTextField myTextField;
+
+    public TextFieldUi()
+    {
+    }
+
+    @Override
+    protected JComponent createUi()
+    {
+        myTextField = new JTextField();
+
+        myPropertyReference.addChangeListener( new PropertyListener()
+        {
+            public void onPropertyValueChange( final Object newValue )
+            {
+                // TODO: Only update the text field if it is not currently 
being actively edited?
+
+                updateValue( newValue );
+            }
+
+            public void onPropertyMetadataChanged( final ParameterMetadata 
newMetadata )
+            {
+                updateDescription( newMetadata );
+            }
+
+            public void onPropertyDissappeared()
+            {
+                myTextField.setEditable( false );
+                myTextField.setEnabled( false );
+
+                updateValue( null );
+                updateDescription( null );
+            }
+
+            public void onPropertyAppeared( final ParameterMetadata 
parameterMetadata, final Object parameterValue, final boolean editable )
+            {
+                myTextField.setEditable( editable );
+                myTextField.setEnabled( true );
+
+                updateValue( parameterValue );
+                updateDescription( parameterMetadata );
+            }
+        } );
+
+        // TODO: Check for correctness while the field is being edited
+
+        myTextField.addActionListener( new ActionListener()
+        {
+            public void actionPerformed( final ActionEvent e )
+            {
+                try
+                {
+                    myPropertyReference.setProperty( getId(), 
myTextField.getText() );
+                }
+                catch ( ParameterValidationException e1 )
+                {
+                    final Object value = myPropertyReference.getProperty( 
getId(), Object.class, "" );
+                    myTextField.setText( value.toString() );
+
+                    // Show errors as tooltip, or on other error indicator?
+                    final List<ValidationError> validationErrors = 
e1.getValidationErrors();
+                }
+            }
+        } );
+
+
+        return myTextField;
+    }
+
+    private void updateDescription( final ParameterMetadata parameterMetadata )
+    {
+        if ( parameterMetadata != null )
+        {
+            myTextField.setToolTipText( 
parameterMetadata.getUiMetadata().getDescription() );
+        }
+        else
+        {
+            myTextField.setToolTipText( "" );
+        }
+    }
+
+    private void updateValue( final Object parameterValue )
+    {
+        if ( parameterValue != null )
+        {
+            myTextField.setText( parameterValue.toString() );
+        }
+        else
+        {
+            myTextField.setText( "" );
+        }
+    }
+}

Modified: 
trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/UiObject.java
===================================================================
--- trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/UiObject.java     
2008-04-06 03:04:12 UTC (rev 448)
+++ trunk/skycastle/modules/ui/src/main/java/org/skycastle/ui/UiObject.java     
2008-04-08 08:39:57 UTC (rev 449)
@@ -14,9 +14,6 @@
 public abstract class UiObject
         extends PojoGameObject
 {
-    protected UiObject()
-    {
-    }
 
     //======================================================================
     // Private Fields
@@ -24,8 +21,16 @@
     private JComponent myUi = null;
 
     //======================================================================
+    // Private Constants
+
+    private static final long serialVersionUID = 1L;
+
+    //======================================================================
     // Public Methods
 
+    //----------------------------------------------------------------------
+    // Other Public Methods
+
     /**
      * @return the Swing UI for this {@link UiObject}.
      */
@@ -43,6 +48,13 @@
     // Protected Methods
 
     //----------------------------------------------------------------------
+    // Protected Constructors
+
+    protected UiObject()
+    {
+    }
+
+    //----------------------------------------------------------------------
     // Abstract Protected Methods
 
     /**


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

Other related posts:

  • » [skycastle-commits] SF.net SVN: skycastle: [449] trunk/skycastle/modules