|
From: <tre...@us...> - 2007-11-21 17:16:54
|
Revision: 594
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=594&view=rev
Author: trevorolio
Date: 2007-11-21 09:16:32 -0800 (Wed, 21 Nov 2007)
Log Message:
-----------
Sadly, this breaks with idea of using the applet only for 3D view because browsers can't reliably pass focus between DOM text field and java panel, which we tried to make work for the movement/chat cycle but it failed and made it unacceptably slow to switch between the two actions. So, I added the chat history and command line to the applet and rewhacked all of the relevant HTML pages.
While moving in the 3D view press enter or / to move to the command line. Enter or escape will switch focus back to 3D view.
Also, fixed the bug in which losing focus while moving would make you lose control, endlessly walking or turning. Now the 3D view catched the focus change and stops any active movement.
Modified Paths:
--------------
maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ViewerApplet.java
Added Paths:
-----------
maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ChatPanel.java
Added: maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ChatPanel.java
===================================================================
--- maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ChatPanel.java (rev 0)
+++ maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ChatPanel.java 2007-11-21 17:16:32 UTC (rev 594)
@@ -0,0 +1,164 @@
+/* Copyright 2007 Transmutable (http://transmutable.com/)
+
+ 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.ogoglio.viewer.applet;
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Panel;
+import java.awt.TextArea;
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import com.ogoglio.util.ArgumentUtils;
+
+public class ChatPanel extends Panel {
+
+ private Dimension totalDimension = new Dimension(800, 150);
+
+ private HistoryPanel historyPanel = new HistoryPanel();
+
+ private CommandPanel commandPanel = new CommandPanel();
+
+ private Listener listener = null;
+
+ public ChatPanel(Listener listener) {
+ ArgumentUtils.assertNotNull(listener);
+ this.listener = listener;
+ setBackground(Color.white);
+ setPreferredSize(totalDimension);
+ setLayout(new BorderLayout());
+ add(historyPanel, BorderLayout.CENTER);
+ add(commandPanel, BorderLayout.SOUTH);
+ }
+
+ public interface Listener {
+ public void userSentMessage(String message);
+
+ public void userReleasedFocus();
+ }
+
+ public void displayMessage(String heading, String message) {
+ heading = heading == null ? "" : heading + ": ";
+ if (historyPanel.getText().length() != 0) {
+ historyPanel.append("\r\n");
+ }
+ historyPanel.append(heading + message);
+ }
+
+ public void focusOnCommandField(String preloadedText) {
+ commandPanel.commandField.requestFocus();
+ if (preloadedText != null) {
+ commandPanel.commandField.setText(preloadedText);
+ commandPanel.commandField.setCaretPosition(commandPanel.commandField.getText().length());
+ }
+ }
+
+ private void attemptMessageSend() {
+ String text = commandPanel.commandField.getText();
+ if (text == null || text.trim().length() == 0) {
+ return;
+ }
+ commandPanel.commandField.setText(null);
+ listener.userSentMessage(text.trim());
+ listener.userReleasedFocus();
+ }
+
+ private class HistoryPanel extends TextArea {
+ public HistoryPanel() {
+ super("", 5, 1, TextArea.SCROLLBARS_VERTICAL_ONLY);
+ }
+ }
+
+ private class CommandPanel extends Panel implements ActionListener, KeyListener {
+ Button sendButton = new Button("Send");
+
+ TextField commandField = new TextField();
+
+ public CommandPanel() {
+ setBackground(Color.white);
+ setLayout(new BorderLayout(10, 0));
+
+ commandField.setBackground(getBackground());
+ commandField.addActionListener(this);
+ commandField.addKeyListener(this);
+ add(commandField, BorderLayout.CENTER);
+
+ sendButton.setBackground(getBackground());
+ sendButton.addActionListener(this);
+ add(sendButton, BorderLayout.EAST);
+ }
+
+ public void actionPerformed(ActionEvent event) {
+ if (event.getSource() == sendButton) {
+ attemptMessageSend();
+ } else if (event.getSource() == commandField) {
+ attemptMessageSend();
+ }
+ }
+
+ public void keyPressed(KeyEvent event) {
+ if (event.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ listener.userReleasedFocus();
+ }
+ }
+
+ public void keyReleased(KeyEvent event) {
+ }
+
+ public void keyTyped(KeyEvent event) {
+ }
+ }
+}
+
+/*
+var emoteIconBase = appPath + "/icons/16x16/";
+
+var emotePatterns = new Array();
+var emoteImageNames = new Array();
+
+emotePatterns[emotePatterns.length] = "0:-)"; emoteImageNames[emoteImageNames.length] = "face-angel.png";
+emotePatterns[emotePatterns.length] = ":'("; emoteImageNames[emoteImageNames.length] = "face-crying.png";
+emotePatterns[emotePatterns.length] = ">:-)"; emoteImageNames[emoteImageNames.length] = "face-devil-grin.png";
+emotePatterns[emotePatterns.length] = "B-)"; emoteImageNames[emoteImageNames.length] = "face-glasses.png";
+emotePatterns[emotePatterns.length] = ":-*"; emoteImageNames[emoteImageNames.length] = "face-kiss.png";
+emotePatterns[emotePatterns.length] = ":-(|)"; emoteImageNames[emoteImageNames.length] = "face-monkey.png";
+emotePatterns[emotePatterns.length] = ":-|"; emoteImageNames[emoteImageNames.length] = "face-plain.png";
+emotePatterns[emotePatterns.length] = ":-("; emoteImageNames[emoteImageNames.length] = "face-sad.png";
+emotePatterns[emotePatterns.length] = ":-)"; emoteImageNames[emoteImageNames.length] = "face-smile.png";
+emotePatterns[emotePatterns.length] = ":-D"; emoteImageNames[emoteImageNames.length] = "face-smile-big.png";
+emotePatterns[emotePatterns.length] = ":-0"; emoteImageNames[emoteImageNames.length] = "face-surprise.png";
+emotePatterns[emotePatterns.length] = ";-)"; emoteImageNames[emoteImageNames.length] = "face-wink.png";
+
+function markupChatMessage(messageText){
+for(var i = 0; i < emotePatterns.length; i++){
+ messageText = emotify(messageText, emotePatterns[i], emoteIconBase + emoteImageNames[i]);
+}
+return messageText;
+}
+
+function emotify(messageText, emotePattern, imageURL){
+var workingText = messageText;
+while(workingText.indexOf(emotePattern) != -1){
+ workingText = workingText.substring(0, workingText.indexOf(emotePattern)) + "<img src='" + imageURL +"' width='16' height='16' />" + workingText.substring(workingText.indexOf(emotePattern) + emotePattern.length);
+}
+return workingText;
+}
+*/
+
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-11-20 20:28:39 UTC (rev 593)
+++ maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/ViewerApplet.java 2007-11-21 17:16:32 UTC (rev 594)
@@ -16,6 +16,7 @@
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Color;
+import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
@@ -40,7 +41,9 @@
import com.ogoglio.client.model.Thing;
import com.ogoglio.util.ContextMenuItemInfo;
import com.ogoglio.util.Log;
+import com.ogoglio.util.WebConstants;
import com.ogoglio.viewer.j3d.J3DRenderer;
+import com.ogoglio.viewer.j3d.J3DUserRenderable;
import com.ogoglio.viewer.render.Renderer;
public class ViewerApplet extends Applet {
@@ -60,7 +63,9 @@
private String authCookie = null;
private Map popupMap = new HashMap();
-
+
+ private ChatPanel chatPanel = new ChatPanel(new ChatPanelListener());
+
public ViewerApplet() {
setBackground(Color.WHITE);
setLayout(new BorderLayout());
@@ -92,6 +97,7 @@
float ry = getFloatParameter("ry", 0);
float rz = getFloatParameter("rz", 0);
boolean movable = !"false".equals(getParameter("movable"));
+ boolean showChat = !"false".equals(getParameter("showChat"));
try {
serviceURI = new URI(getParameter("serviceURI"));
@@ -109,8 +115,15 @@
removeAll();
validate();
- renderer.getCanvas().setSize(getWidth(), getHeight());
- add(renderer.getCanvas(), BorderLayout.CENTER);
+ if(showChat){
+ renderer.getCanvas().setSize(getWidth(), getHeight() - chatPanel.getPreferredSize().height);
+ renderer.getCanvas().setPreferredSize(new Dimension(getWidth(), getHeight() - chatPanel.getPreferredSize().height));
+ add(chatPanel, BorderLayout.SOUTH);
+ add(renderer.getCanvas(), BorderLayout.CENTER);
+ } else {
+ renderer.getCanvas().setSize(getWidth(), getHeight());
+ add(renderer.getCanvas(), BorderLayout.CENTER);
+ }
validate();
renderer.startRenderer();
renderer.getCanvas().requestFocus();
@@ -138,8 +151,8 @@
}
private void performAShutdown(String method) {
-
- Log.info("Destroying " + this + ": " + renderer + ", " + spaceClient+" b/c "+method+" called on applet");
+
+ Log.info("Destroying " + this + ": " + renderer + ", " + spaceClient + " b/c " + method + " called on applet");
if (renderer != null) {
renderer.stopRenderer();
}
@@ -193,22 +206,22 @@
renderer.getCanvas().requestFocus();
}
- private void focusCommandField() {
- try {
- JSObject win = JSObject.getWindow(this); // get handle to a window.
- if (win == null) {
- Log.error("Could not do live connect. Check that mayscript is true in the applet tag.");
- return;
+ private class ChatPanelListener implements ChatPanel.Listener {
+ public void userReleasedFocus() {
+ if(renderer != null && renderer.getCanvas() != null){
+ renderer.getCanvas().requestFocus();
}
- win.call("focusCommandField", null); // Call a JavaScript function
- } catch (Exception e) {
- if (!printedLiveConnectErrorMessage) {
- Log.error("Could not use LiveConnect (ignoring future errors): " + e);
- printedLiveConnectErrorMessage = true;
- }
}
+
+ public void userSentMessage(String message) {
+ spaceClient.userIssuedCommand(message);
+ }
}
+ public void sendChatMessage(String message) {
+ spaceClient.userIssuedCommand(message);
+ }
+
private void showPopup(Thing thing, int x, int y, long nonce) {
ThingGeneratedPopup popup = new ThingGeneratedPopup(thing, nonce);
popup.show(this, x, y);
@@ -286,27 +299,6 @@
}
}
- private void addChatMessage(String message) {
- try {
- JSObject win = JSObject.getWindow(this); // get handle to a window.
- if (win == null) {
- Log.warn("Could not do live connect. Check that mayscript is true in the applet tag.");
- return;
- }
- String[] args = { message };
- win.call("displayChatMessage", args); // Call a JavaScript function
- } catch (Exception e) {
- if (!printedLiveConnectErrorMessage) {
- Log.warn("Could not use LiveConnect (ignoring future errors): " + e);
- printedLiveConnectErrorMessage = true;
- }
- }
- }
-
- public void sendChatMessage(String message) {
- spaceClient.userIssuedCommand(message);
- }
-
public String getUsername() {
return spaceClient.getUsername();
}
@@ -314,11 +306,15 @@
private class SpaceClientListener implements SpaceClient.Listener {
public void disconnected() {
- addChatMessage("Disconnected.");
+ chatPanel.displayMessage(null, "Disconnected.");
}
public void receivedChatMessage(String username, String message) {
- addChatMessage(username + ":" + message);
+ if (username != null && username.startsWith(WebConstants.GUEST_COOKIE_PREFIX)) {
+ username = J3DUserRenderable.convertGuestCookieToDisplayName(username);
+ }
+
+ chatPanel.displayMessage(username, message);
}
public void receivedSpaceTransfer(URI link) {
@@ -326,10 +322,10 @@
String[] pathElements = link.getPath().split("/");
switchToSpace(Long.parseLong(pathElements[pathElements.length - 1]));
} catch (IOException e) {
- addChatMessage("system: That space could not be reached");
+ chatPanel.displayMessage("system", "That space could not be reached");
e.printStackTrace();
} catch (Exception e) {
- addChatMessage("system: That spaceID is unusable (" + e.getMessage() + "): " + link);
+ chatPanel.displayMessage("system", "That spaceID is unusable (" + e.getMessage() + "): " + link);
}
}
@@ -337,8 +333,8 @@
showLink(displayName, link);
}
- public void receivedCommandFocusRequest() {
- focusCommandField();
+ public void receivedCommandFocusRequest(String preloadedText) {
+ chatPanel.focusOnCommandField(preloadedText);
}
public void receivedBrowserMessage(long sourceThingID, String message) {
@@ -367,7 +363,7 @@
JMenuItem moveItem = null;
JMenuItem seatItem = null;
-
+
Thing thing = null;
long startTime;
@@ -379,15 +375,15 @@
nonce = theNonce;
startTime = System.currentTimeMillis();
- if(theThing.getTemplate().isASeat()){
+ if (theThing.getTemplate().isASeat()) {
seatItem = add("Sit Here");
- seatItem.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
+ seatItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
spaceClient.userRequestedSeat(thing);
}
});
}
-
+
moveItem = add("Move");
moveItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|