|
From: <tre...@us...> - 2007-09-01 17:12:21
|
Revision: 322
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=322&view=rev
Author: trevorolio
Date: 2007-09-01 10:12:22 -0700 (Sat, 01 Sep 2007)
Log Message:
-----------
Added a move menu item to thing context menus which, when selected, whos the thingPopup page in the infoPanel.
Modified Paths:
--------------
maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ViewerApplet.java
Modified: maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ViewerApplet.java
===================================================================
--- maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ViewerApplet.java 2007-09-01 16:19:36 UTC (rev 321)
+++ maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ViewerApplet.java 2007-09-01 17:12:22 UTC (rev 322)
@@ -43,6 +43,8 @@
import com.ogoglio.viewer.render.Renderer;
public class ViewerApplet extends Applet {
+
+ public static final String MOVE_NONCE = "move";
private SplashPanel splashPanel = new SplashPanel();
@@ -87,12 +89,12 @@
float ry = getFloatParameter("ry", 0);
float rz = getFloatParameter("rz", 0);
boolean movable = !"false".equals(getParameter("movable"));
-
+
try {
serviceURI = new URI(getParameter("serviceURI"));
long spaceID = Long.parseLong(getParameter("spaceID"));
spaceClient = new SpaceClient(spaceID, serviceURI, authCookie, spaceClientListener);
- if(x != 0 || y != 0 || z != 0 || rx != 0 || ry != 0 || rz != 0) {
+ if (x != 0 || y != 0 || z != 0 || rx != 0 || ry != 0 || rz != 0) {
Transform3D transform = new Transform3D();
transform.setEuler(new Vector3d(rx, ry, rz));
transform.setTranslation(new Vector3d(x, y, z));
@@ -101,7 +103,7 @@
}
renderer = new J3DRenderer(spaceClient, false);
renderer.setMovable(movable);
-
+
removeAll();
validate();
renderer.getCanvas().setSize(getWidth(), getHeight());
@@ -170,29 +172,26 @@
e.printStackTrace();
}
}
-
-
- private void showPopup(Thing thing, int x, int y, long nonce) {
- ThingGeneratedPopup popup=new ThingGeneratedPopup(thing,nonce);
- popup.show(this,x,y);
- popupMap.put(new Long(nonce),popup);
+
+ private void showPopup(Thing thing, int x, int y, long nonce) {
+ ThingGeneratedPopup popup = new ThingGeneratedPopup(thing, nonce);
+ popup.show(this, x, y);
+ popupMap.put(new Long(nonce), popup);
}
-
- private void sendServerSelectionMessage(Thing thing, long nonce,String id) {
- spaceClient.mouseContextItemChosen(thing,nonce,id);
+
+ private void sendServerSelectionMessage(Thing thing, long nonce, String id) {
+ spaceClient.mouseContextItemChosen(thing, nonce, id);
}
-
-
public void populatePopup(long nonce, String errorIfAny, Vector contextMenu) {
if (!popupMap.containsKey(new Long(nonce))) {
- System.err.println("[Internal Error] context menu data ("+nonce+") couldn't be matched to a menu!");
+ System.err.println("[Internal Error] context menu data (" + nonce + ") couldn't be matched to a menu!");
return;
}
- if (errorIfAny!=null) {
- System.err.println("[Javascript Error]:"+errorIfAny);
+ if (errorIfAny != null) {
+ System.err.println("[Javascript Error]:" + errorIfAny);
} else {
- ThingGeneratedPopup popup = (ThingGeneratedPopup)popupMap.get(new Long(nonce));
+ ThingGeneratedPopup popup = (ThingGeneratedPopup) popupMap.get(new Long(nonce));
popup.populate(contextMenu);
}
popupMap.remove(new Long(nonce));
@@ -208,7 +207,7 @@
String[] args = { displayName, link };
win.call("displayLink", args); // Call a JavaScript function
} catch (Exception e) {
- if(!printedLiveConnectErrorMessage) {
+ if (!printedLiveConnectErrorMessage) {
System.err.println("Could not use LiveConnect (ignoring future errors): " + e);
printedLiveConnectErrorMessage = true;
}
@@ -225,7 +224,7 @@
String[] args = { sourceThingID + "", nonce };
win.call("addInfoPanel", args); // Call a JavaScript function
} catch (Exception e) {
- if(!printedLiveConnectErrorMessage) {
+ if (!printedLiveConnectErrorMessage) {
System.err.println("Could not use LiveConnect (ignoring future errors): " + e);
printedLiveConnectErrorMessage = true;
}
@@ -233,6 +232,7 @@
}
boolean printedLiveConnectErrorMessage = false;
+
private void messageBrowser(long sourceThingID, String message) {
try {
JSObject win = JSObject.getWindow(this); // get handle to a window.
@@ -243,7 +243,7 @@
String[] args = { "" + sourceThingID, message };
win.call("handleBrowserMessage", args); // Call a JavaScript function
} catch (Exception e) {
- if(!printedLiveConnectErrorMessage) {
+ if (!printedLiveConnectErrorMessage) {
System.err.println("Could not use LiveConnect (ignoring future errors): " + e);
printedLiveConnectErrorMessage = true;
}
@@ -271,7 +271,7 @@
public String getUsername() {
return spaceClient.getUsername();
}
-
+
public void destroy() {
renderer.stopRenderer();
spaceClient.cleanup();
@@ -291,9 +291,9 @@
//add(new ErrorPanel("Unfortunately, I lost the connection to the server."), BorderLayout.CENTER);
//validate();
}
-
+
public void receivedChatMessage(String username, String message) {
- addChatMessage(username + ":" + message);
+ addChatMessage(username + ":" + message);
}
public void receivedSpaceTransfer(URI link) {
@@ -321,11 +321,11 @@
}
public void receivedContextMenuRequest(Thing thing, String shapeName, int x, int y, long nonce) {
- showPopup(thing,x, y, nonce);
+ showPopup(thing, x, y, nonce);
}
public void receivedContextMenuData(long nonce, String errorIfAny, Vector contextMenu) {
- populatePopup(nonce,errorIfAny,contextMenu);
+ populatePopup(nonce, errorIfAny, contextMenu);
}
public void contextItemChosen(Thing thing, long nonce, String id) {
@@ -337,17 +337,30 @@
}
private class ThingGeneratedPopup extends JPopupMenu {
-
- JMenuItem waitingItem;
- Thing thing;
+ JMenuItem waitingItem = null;
+
+ JMenuItem moveItem = null;
+
+ Thing thing = null;
+
long startTime;
+
long nonce;
-
+
public ThingGeneratedPopup(Thing theThing, long theNonce) {
- waitingItem=add("Retreiving menu...");
- thing=theThing;
- nonce=theNonce;
- startTime=System.currentTimeMillis();
+ thing = theThing;
+ nonce = theNonce;
+ startTime = System.currentTimeMillis();
+
+ moveItem = add("Move");
+ moveItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ showInfoPanel(thing.getThingID(), MOVE_NONCE);
+ }
+ });
+ addSeparator();
+
+ waitingItem = add("Retreiving menu...");
}
public boolean populate(final Vector items) {
@@ -355,30 +368,30 @@
return false;
}
remove(waitingItem);
- for (int i=0; i<items.size();++i) {
- ContextMenuInfo info = (ContextMenuInfo)items.get(i);
- JMenuItem item=new JMenuItem(info.getUserVisibleString());
+ for (int i = 0; i < items.size(); ++i) {
+ ContextMenuInfo info = (ContextMenuInfo) items.get(i);
+ JMenuItem item = new JMenuItem(info.getUserVisibleString());
item.setEnabled(info.getEnabled());
add(item);
- final String id=info.getId();
+ validate();
+ final String id = info.getId();
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sendSelection(id);
- }
+ }
});
}
- //IES: I have no idea why this causes a relayout that works properle. ugh. totally broken.
- this.setVisible(false);
- this.setVisible(true);
+ setVisible(false);
+ setVisible(true);
return true;
}
-
+
public void sendSelection(String id) {
- sendServerSelectionMessage(thing,nonce,id);
+ sendServerSelectionMessage(thing, nonce, id);
}
}
-
+
//TODO make the error panel less ugly
private class ErrorPanel extends Panel {
public ErrorPanel(String errorMessage) {
@@ -401,5 +414,4 @@
}
}
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|