|
From: <tre...@us...> - 2007-12-10 22:50:33
|
Revision: 623
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=623&view=rev
Author: trevorolio
Date: 2007-12-10 14:50:35 -0800 (Mon, 10 Dec 2007)
Log Message:
-----------
Fixed a couple of bugs in CometProto so it no longer throws NullPointerExceptions in routine failure cases seen in tests. Added mutable background colors to spaces.
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClient.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Space.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometClient.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/UIConstants.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/SpaceDocument.java
maven/trunk/ogoglio-common/src/test/java/com/ogoglio/xml/test/XMLTest.java
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java 2007-12-10 22:50:26 UTC (rev 622)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java 2007-12-10 22:50:35 UTC (rev 623)
@@ -23,6 +23,7 @@
import java.util.zip.ZipInputStream;
import javax.media.j3d.Transform3D;
+import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import com.ogoglio.client.model.BodyConfiguration;
@@ -108,7 +109,9 @@
}
SpaceDocument spaceDoc = webClient.getSpaceDocument(spaceID, true);
- space = new Space(this, spaceDoc.getSpaceID(), spaceDoc.getDisplayName(), spaceDoc.getOwnerUsername(), spaceDoc.getDisplaySea(), spaceDoc.getSeaLevel());
+ float[] bgColor = spaceDoc.getBackgroundColor();
+ Color3f backgroundColor = new Color3f(bgColor[0], bgColor[1], bgColor[2]);
+ space = new Space(this, spaceDoc.getSpaceID(), spaceDoc.getDisplayName(), spaceDoc.getOwnerUsername(), spaceDoc.getDisplaySea(), spaceDoc.getSeaLevel(), backgroundColor);
//create the event channel and start queuing events
messageChannel = new TCPChannel(AsyncProtoFactory.getDefaultClient(descriptor, true), messenger, true, new ChannelListener(), true, "space-client");
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClient.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClient.java 2007-12-10 22:50:26 UTC (rev 622)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClient.java 2007-12-10 22:50:35 UTC (rev 623)
@@ -28,6 +28,7 @@
import com.ogoglio.util.ArgumentUtils;
import com.ogoglio.util.Log;
import com.ogoglio.util.StreamUtils;
+import com.ogoglio.util.UIConstants;
import com.ogoglio.xml.AccountDocument;
import com.ogoglio.xml.AuthDocument;
import com.ogoglio.xml.BodyConfigurationDocument;
@@ -71,7 +72,7 @@
}
public SpaceDocument createSpace(String spaceName) {
- SpaceDocument spaceDoc = new SpaceDocument(-1, spaceName, authenticator.getUsername(), false, 0, false, 0, -1, null);
+ SpaceDocument spaceDoc = new SpaceDocument(-1, spaceName, authenticator.getUsername(), false, 0, false, 0, -1, null, UIConstants.SKY_COLOR_ARRAY);
try {
return new SpaceDocument(wire.sendAuthenticatedXML(descriptor.getSpacesURI(), spaceDoc.toString(), "POST", authenticator.getAuthCookie()));
} catch (IOException e) {
@@ -204,6 +205,12 @@
wire.postAuthenticatedXML(descriptor.getSpaceURI(spaceID), spaceDoc.toString(), authenticator.getAuthCookie());
}
+ public void setSpaceBackgroundColor(long spaceID, float[] backgroundColor) throws IOException {
+ SpaceDocument spaceDoc = new SpaceDocument(wire.fetchAuthenticatedXML(descriptor.getSpaceURI(spaceID), authenticator.getAuthCookie()));
+ spaceDoc.setBackgroundColor(backgroundColor[0], backgroundColor[1], backgroundColor[2]);
+ wire.postAuthenticatedXML(descriptor.getSpaceURI(spaceID), spaceDoc.toString(), authenticator.getAuthCookie());
+ }
+
public void setSpaceMaxGuests(long spaceID, int maxGuests) throws IOException {
if (maxGuests < 0 || maxGuests > 100) {
throw new IllegalArgumentException("Cannot have less than 0 or more than 100 guests: " + maxGuests);
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Space.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Space.java 2007-12-10 22:50:26 UTC (rev 622)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Space.java 2007-12-10 22:50:35 UTC (rev 623)
@@ -22,6 +22,7 @@
import java.util.Vector;
import javax.media.j3d.Transform3D;
+import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
@@ -58,7 +59,9 @@
private Context spaceContext = null;
- public Space(Context spaceContext, long spaceID, String displayName, String ownerUsername, boolean displaySea, double seaLevel) {
+ private Color3f backgroundColor = null;
+
+ public Space(Context spaceContext, long spaceID, String displayName, String ownerUsername, boolean displaySea, double seaLevel, Color3f backgroundColor) {
ArgumentUtils.assertNotNull(spaceContext);
this.spaceContext = spaceContext;
ArgumentUtils.assertNotNegative(spaceID);
@@ -72,7 +75,14 @@
this.displaySea = displaySea;
this.seaLevel = seaLevel;
+
+ ArgumentUtils.assertNotNull(backgroundColor);
+ this.backgroundColor = backgroundColor;
}
+
+ public Color3f getBackgroundColor(){
+ return backgroundColor;
+ }
public boolean shouldDisplaySea() {
return displaySea;
@@ -535,4 +545,5 @@
listeners[i].userStood(user, seat);
}
}
+
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometClient.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometClient.java 2007-12-10 22:50:26 UTC (rev 622)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/message/proto/CometClient.java 2007-12-10 22:50:35 UTC (rev 623)
@@ -112,7 +112,13 @@
public static int pullOutCommandPart(StringBuffer buff) {
String command=buff.substring(0,buff.indexOf("$"));
+ if(command == null){
+ return BAD_CMD;
+ }
String msg=buff.substring(buff.indexOf("$")+1);
+ if(msg == null){
+ return BAD_CMD;
+ }
String lenPart=command.substring(Command.MESSAGE.length()+1);
int len=-1;
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/UIConstants.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/UIConstants.java 2007-12-10 22:50:26 UTC (rev 622)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/UIConstants.java 2007-12-10 22:50:35 UTC (rev 623)
@@ -46,6 +46,8 @@
public static Color3f LIGHT_BLUE = new Color3f(0.1015f, 0.5976f, 0.8476f);
+ public static float[] SKY_COLOR_ARRAY = new float[]{ LIGHT_BLUE.x, LIGHT_BLUE.y, LIGHT_BLUE.z };
+
public static Color3f BROWN = new Color3f(0.5468f, 0.3867f, 0.0664f);
public static Color3f ORANGE = new Color3f(0.8476f, 0.4726f, 0.1015f);
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java 2007-12-10 22:50:26 UTC (rev 622)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java 2007-12-10 22:50:35 UTC (rev 623)
@@ -202,7 +202,7 @@
directional3.setInfluencingBounds(DEFAULT_SPACE_BOUNDS);
sceneRoot.addChild(directional3);
- background = new Background(UIConstants.LIGHT_BLUE);
+ background = new Background(getSpace().getBackgroundColor());
background.setCapability(Background.ALLOW_COLOR_WRITE);
background.setApplicationBounds(DEFAULT_SPACE_BOUNDS);
sceneRoot.addChild(background);
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/SpaceDocument.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/SpaceDocument.java 2007-12-10 22:50:26 UTC (rev 622)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/SpaceDocument.java 2007-12-10 22:50:35 UTC (rev 623)
@@ -13,11 +13,12 @@
limitations under the License. */
package com.ogoglio.xml;
-import java.text.ParseException;
+import java.awt.Color;
import nanoxml.XMLElement;
import com.ogoglio.util.ArgumentUtils;
+import com.ogoglio.util.UIConstants;
public class SpaceDocument {
@@ -39,13 +40,19 @@
public static final String SIM_ID = "simid";
- public static final String LAST_MODIFIED="lastmodified";
+ public static final String LAST_MODIFIED = "lastmodified";
+ public static final String BACKGROUND_COLOR_RED = "bgred";
+
+ public static final String BACKGROUND_COLOR_GREEN = "bggreen";
+
+ public static final String BACKGROUND_COLOR_BLUE = "bgblue";
+
public static final int MAX_SETTING_VALUE_SIZE = 10240;
- XMLElement data = null;
+ private XMLElement data = null;
- public SpaceDocument(long spaceID, String displayName, String ownerUsername, boolean published, int maxGuests, boolean displaySea, double seaLevel, long simID, String lastModifiedGMT) {
+ public SpaceDocument(long spaceID, String displayName, String ownerUsername, boolean published, int maxGuests, boolean displaySea, double seaLevel, long simID, String lastModifiedGMT, float[] backgroundColor) {
data = new XMLElement(NAME);
if (spaceID != -1) {
@@ -67,13 +74,17 @@
data.setAttribute(DISPLAY_SEA, displaySea);
data.setAttribute(SEA_LEVEL, seaLevel);
- if (lastModifiedGMT!=null) {
+ if (lastModifiedGMT != null) {
data.setAttribute(LAST_MODIFIED, lastModifiedGMT);
}
-
+
if (simID != -1) {
data.setAttribute(SIM_ID, simID);
}
+
+ data.setAttribute(BACKGROUND_COLOR_RED, backgroundColor[0]);
+ data.setAttribute(BACKGROUND_COLOR_GREEN, backgroundColor[1]);
+ data.setAttribute(BACKGROUND_COLOR_BLUE, backgroundColor[2]);
}
public SpaceDocument(XMLElement data) {
@@ -117,13 +128,13 @@
public TemplateDocument getTemplateDocument(long templateID) {
TemplateDocument[] docs = getTemplateDocuments();
for (int i = 0; i < docs.length; i++) {
- if(docs[i].getTemplateID() == templateID) {
+ if (docs[i].getTemplateID() == templateID) {
return docs[i];
}
}
return null;
}
-
+
public TemplateDocument[] getTemplateDocuments() {
XMLElement[] elements = data.getChildren(TemplateDocument.NAME);
TemplateDocument[] results = new TemplateDocument[elements.length];
@@ -232,6 +243,31 @@
}
public String getLastModifiedAsUTC() {
- return data.getStringAttribute(LAST_MODIFIED,null);
+ return data.getStringAttribute(LAST_MODIFIED, null);
}
+
+ public void setBackgroundColor(float red, float green, float blue) {
+ if (!isValidColor(red) || !isValidColor(green) || !isValidColor(blue)) {
+ throw new IllegalArgumentException("Bad background rgb: " + red + "," + green + "," + blue);
+ }
+ data.setAttribute(BACKGROUND_COLOR_RED, red);
+ data.setAttribute(BACKGROUND_COLOR_GREEN, green);
+ data.setAttribute(BACKGROUND_COLOR_BLUE, blue);
+ }
+
+ public float[] getBackgroundColor() {
+ float red = data.getFloatAttribute(BACKGROUND_COLOR_RED);
+ float green = data.getFloatAttribute(BACKGROUND_COLOR_GREEN);
+ float blue = data.getFloatAttribute(BACKGROUND_COLOR_BLUE);
+ if (!isValidColor(red) || !isValidColor(green) || !isValidColor(blue)) {
+ float[] result = { UIConstants.LIGHT_BLUE.x, UIConstants.LIGHT_BLUE.y, UIConstants.LIGHT_BLUE.z };
+ return result;
+ }
+ float[] result = { red, green, blue };
+ return result;
+ }
+
+ public static boolean isValidColor(float color) {
+ return color >= 0 && color <= 1;
+ }
}
\ No newline at end of file
Modified: maven/trunk/ogoglio-common/src/test/java/com/ogoglio/xml/test/XMLTest.java
===================================================================
--- maven/trunk/ogoglio-common/src/test/java/com/ogoglio/xml/test/XMLTest.java 2007-12-10 22:50:26 UTC (rev 622)
+++ maven/trunk/ogoglio-common/src/test/java/com/ogoglio/xml/test/XMLTest.java 2007-12-10 22:50:35 UTC (rev 623)
@@ -13,6 +13,7 @@
import nanoxml.XMLElement;
import com.ogoglio.client.model.SplinePath;
+import com.ogoglio.util.UIConstants;
import com.ogoglio.viewer.j3d.J3DSplineKeyFrame;
import com.ogoglio.viewer.j3d.J3DSplinePath;
import com.ogoglio.xml.AccountDocument;
@@ -224,7 +225,7 @@
Date now=new Date();
Date aSecondAgo=new Date(now.getTime()-1000);
- SpaceDocument doc1 = new SpaceDocument(spaceID1, displayName1, ownerUsername1, true, 23, false, 0, 44, fmt.format(aSecondAgo));
+ SpaceDocument doc1 = new SpaceDocument(spaceID1, displayName1, ownerUsername1, true, 23, false, 0, 44, fmt.format(aSecondAgo), UIConstants.SKY_COLOR_ARRAY);
assertEquals(spaceID1, doc1.getSpaceID());
assertEquals(displayName1, doc1.getDisplayName());
assertEquals(ownerUsername1, doc1.getOwnerUsername());
@@ -244,7 +245,7 @@
assertEquals(0, doc2.getSeaLevel(), 0.001);
assertEquals(44, doc2.getSimID());
- SpaceDocument doc3 = new SpaceDocument(spaceID1, displayName1, ownerUsername1, true, 23, true, -2, 44, null);
+ SpaceDocument doc3 = new SpaceDocument(spaceID1, displayName1, ownerUsername1, true, 23, true, -2, 44, null, UIConstants.SKY_COLOR_ARRAY);
assertTrue(doc3.getDisplaySea());
assertEquals(-2, doc3.getSeaLevel(), 0.00001);
SpaceDocument doc4 = new SpaceDocument(XMLElement.parseElementFromString(doc3.toElement().toString()));
@@ -252,14 +253,14 @@
assertEquals(-2, doc4.getSeaLevel(), 0.00001);
try {
- new SpaceDocument(spaceID1, displayName1, null, true, 4, true, 0, -1,null);
+ new SpaceDocument(spaceID1, displayName1, null, true, 4, true, 0, -1,null, UIConstants.SKY_COLOR_ARRAY);
fail("Should not allow null ownerURI");
} catch (IllegalArgumentException e) {
//this should happen
}
try {
- new SpaceDocument(spaceID1, null, ownerUsername1, true, 0, true, 0, -1,null);
+ new SpaceDocument(spaceID1, null, ownerUsername1, true, 0, true, 0, -1,null, UIConstants.SKY_COLOR_ARRAY);
fail("Should not allow null display name");
} catch (IllegalArgumentException e) {
//this should happen
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|