|
From: <tre...@us...> - 2007-10-15 19:10:20
|
Revision: 501
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=501&view=rev
Author: trevorolio
Date: 2007-10-15 12:10:20 -0700 (Mon, 15 Oct 2007)
Log Message:
-----------
Switched the body editor applet to just show the 3D, with editing functions exposed to the page via LiveConnect.
Made body.html use the new functions to display morph controls, animation triggers, and a save button.
Hopefully we will avoid future use of applets for any 2D controls.
Modified Paths:
--------------
maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java
Modified: maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java
===================================================================
--- maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java 2007-10-15 19:10:14 UTC (rev 500)
+++ maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java 2007-10-15 19:10:20 UTC (rev 501)
@@ -15,23 +15,17 @@
import java.applet.Applet;
import java.awt.BorderLayout;
-import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
-import java.awt.FlowLayout;
import java.awt.GraphicsConfigTemplate;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
-import java.awt.Label;
import java.awt.Panel;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.Vector;
import java.util.zip.ZipInputStream;
import javax.media.j3d.AmbientLight;
@@ -43,8 +37,6 @@
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
-import javax.swing.BoxLayout;
-import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
@@ -82,12 +74,8 @@
private AccountDocument accountDoc = null;
- private WestPanel westPanel = null;
-
private BodyPanel bodyPanel = new BodyPanel();
- private EastPanel eastPanel = null;
-
private SpacelessUser user = null;
private WebAPIClient webClient = null;
@@ -95,17 +83,17 @@
private boolean completedInitialLoad = false;
private J3DDataManager dataManager = null;
-
+
private BodyDataDocument[] bodyDataDocuments = null;
-
+
public BodyEditorApplet() {
setBackground(Color.WHITE);
setLayout(new BorderLayout());
- setSize(new Dimension(800, 600));
+ setSize(new Dimension(300, 400));
}
-
- public void updateTextures(){
- if(bodyPanel == null || bodyPanel.renderable == null){
+
+ public void updateTextures() {
+ if (bodyPanel == null || bodyPanel.renderable == null) {
return;
}
dataManager.removeBodyTexture(user.getUsername(), user.getBodyConfiguration().getBodyConfigurationID());
@@ -113,12 +101,80 @@
bodyPanel.renderable.repaintSkinTexture();
}
+ public String[] getMorphNames() {
+ if (bodyPanel.bodyData == null) {
+ return new String[0];
+ }
+ MorphDeltaMap[] deltaMaps = bodyPanel.bodyData.getMorphDeltaMaps();
+ String[] results = new String[deltaMaps.length];
+ for (int i = 0; i < results.length; i++) {
+ results[i] = deltaMaps[i].getName();
+ }
+ return results;
+ }
+
+ public float getMorphSetting(String morphName) {
+ if (user == null) {
+ return 0;
+ }
+ return user.getBodyConfiguration().getSetting(morphName);
+ }
+
+ public void setMorphSetting(String morphName, float setting) {
+ if (user == null || bodyPanel == null || bodyPanel.renderable == null) {
+ return;
+ }
+ user.getBodyConfiguration().addSetting(morphName, setting);
+ bodyPanel.renderable.updateMorphs();
+ }
+
+ public String[] getAnimationNames() {
+ if (user == null || bodyPanel == null || bodyPanel.renderable == null) {
+ return new String[0];
+ }
+ Bvh[] animations = bodyPanel.bodyData.getAnimations();
+ String[] results = new String[animations.length];
+ for (int i = 0; i < results.length; i++) {
+ results[i] = animations[i].getName();
+ }
+ return results;
+ }
+
+ public void playAnimation(String animationName) {
+ if (user == null || bodyPanel == null || bodyPanel.renderable == null) {
+ return;
+ }
+ bodyPanel.renderable.playAnimation(animationName, false);
+ }
+
+ public String getBodyConfigurationDocument() {
+ if (user == null || bodyPanel == null || bodyPanel.renderable == null) {
+ return null;
+ }
+ return new BodyConfigurationDocument(user.getBodyConfiguration()).toElement().toString();
+ }
+
+ public void saveBodyConfiguration(){
+ if (user == null || bodyPanel == null || bodyPanel.renderable == null) {
+ return;
+ }
+ try {
+ webClient.updateBodyConfiguration(new BodyConfigurationDocument(user.getBodyConfiguration()));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
private class SpacelessUser extends User {
public SpacelessUser(String username, BodyConfigurationDocument bodyConfigDoc) {
super(new Space(new SpacelessContext(), 1, "Space", "nobody", false, 0), username, new Transform3D(), new BodyConfiguration(bodyConfigDoc));
}
}
+ public boolean completedInitialLoad() {
+ return completedInitialLoad;
+ }
+
private class SpacelessContext implements Context {
public InputStream getPageContentStream(long thingID, long pageID) {
@@ -168,8 +224,6 @@
bodyData = dataManager.getBodyData(user.getBodyConfiguration().getBodyDataID());
renderable = new J3DUserRenderable(user, bodyData, dataManager.getBodyTexture(user.getUsername(), user.getBodyConfiguration().getBodyConfigurationID()));
userGroup.addChild(renderable);
- westPanel.morphList.initList();
- eastPanel.animationList.initAnimationList();
return true;
} catch (Exception e) {
e.printStackTrace();
@@ -224,237 +278,6 @@
}
}
- private class MorphListPanel extends Panel implements ActionListener {
- Dimension dimension = new Dimension(150, 565);
-
- Button saveButton = new Button("Save");
-
- public MorphListPanel() {
- setPreferredSize(dimension);
- setMinimumSize(dimension);
- setLayout(new FlowLayout(FlowLayout.CENTER, 0, 1));
- setBackground(Color.WHITE);
- }
-
- void initList() {
- removeAll();
- validate();
- MorphDeltaMap[] deltaMaps = bodyPanel.bodyData.getMorphDeltaMaps();
- if (deltaMaps.length == 0) {
- add(saveButton);
- validate();
- return;
- }
-
- for (int i = deltaMaps.length - 1; i >= 0; i--) {
- add(new MorphPanel(deltaMaps[i]));
- validate();
- }
-
- saveButton.setBackground(Color.WHITE);
- saveButton.addActionListener(this);
- add(saveButton);
- validate();
- }
-
- public void actionPerformed(ActionEvent event) {
- if (event.getSource() == saveButton) {
- try {
- webClient.updateBodyConfiguration(new BodyConfigurationDocument(user.getBodyConfiguration()));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- private class MorphPanel extends Panel implements ActionListener {
-
- float buttonStep = 0.1f;
-
- Dimension dimension = new Dimension(150, 50);
-
- MorphDeltaMap morphDeltaMap = null;
-
- Label nameLabel = null;
-
- Label valueLabel = null;
-
- Button moreButton = new Button("+");
-
- Button lessButton = new Button("-");
-
- public MorphPanel(MorphDeltaMap morphDeltaMap) {
- setPreferredSize(dimension);
- setMinimumSize(dimension);
- setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
- setBackground(Color.WHITE);
-
- this.morphDeltaMap = morphDeltaMap;
- nameLabel = new Label(morphDeltaMap.getName() + ":");
- nameLabel.setBackground(Color.WHITE);
- add(nameLabel);
-
- Panel buttonPanel = new Panel();
- buttonPanel.setBackground(Color.WHITE);
-
- moreButton.setBackground(Color.WHITE);
- moreButton.addActionListener(this);
- buttonPanel.add(moreButton);
-
- valueLabel = new Label(formatValue(getMorphSetting()));
- valueLabel.setBackground(Color.WHITE);
- buttonPanel.add(valueLabel);
-
- lessButton.setBackground(Color.WHITE);
- lessButton.addActionListener(this);
- buttonPanel.add(lessButton);
-
- add(buttonPanel);
- }
-
- float getMorphSetting() {
- return user.getBodyConfiguration().getSetting(morphDeltaMap.getName());
- }
-
- public void actionPerformed(ActionEvent event) {
- float setting = -1;
- if (event.getSource() == moreButton) {
- setting = getMorphSetting();
- if (setting >= 1) {
- return;
- }
- setting += buttonStep;
- } else if (event.getSource() == lessButton) {
- setting = getMorphSetting();
- if (setting <= 0) {
- return;
- }
- setting -= buttonStep;
- }
- if (setting != -1) {
- user.getBodyConfiguration().addSetting(morphDeltaMap.getName(), setting);
- valueLabel.setText(formatValue(getMorphSetting()));
- bodyPanel.renderable.updateMorphs();
- }
- }
-
- String formatValue(float value) {
- Object[] args = { new Float(value) };
- return String.format("%1.1f", args);
- }
-
- }
-
- private class BodyPickerPanel extends Panel implements ActionListener {
- Dimension dimension = new Dimension(150, 35);
-
- JComboBox bodyComboBox = null;
-
- public BodyPickerPanel() {
- setPreferredSize(dimension);
- setMinimumSize(dimension);
- setLayout(new FlowLayout(FlowLayout.CENTER, 0, 5));
- setBackground(Color.WHITE);
-
- Vector names = new Vector();
- int selectedIndex = -1;
- for (int i = 0; i < bodyDataDocuments.length; i++) {
- names.add(bodyDataDocuments[i].getDisplayName());
- if(user.getBodyConfiguration().getBodyDataID() == bodyDataDocuments[i].getBodyDataID()){
- selectedIndex = i;
- }
- }
- bodyComboBox = new JComboBox(names.toArray());
- bodyComboBox.setSelectedIndex(selectedIndex);
- bodyComboBox.setBackground(Color.WHITE);
- bodyComboBox.addActionListener(this);
- add(bodyComboBox);
- }
-
- public void actionPerformed(ActionEvent event) {
- if(event.getSource() == bodyComboBox){
- String bodyName = (String)bodyComboBox.getSelectedItem();
- if(bodyName == null){
- return;
- }
- for (int i = 0; i < bodyDataDocuments.length; i++) {
- if(bodyName.equals(bodyDataDocuments[i].getDisplayName())){
- if(bodyDataDocuments[i].getBodyDataID() == user.getBodyConfiguration().getBodyDataID()){
- return;
- }
- user.getBodyConfiguration().setBodyDataID(bodyDataDocuments[i].getBodyDataID());
- bodyPanel.bodyData = dataManager.getBodyData(bodyDataDocuments[i].getBodyDataID());
- bodyPanel.renderable.initBody(bodyPanel.bodyData, dataManager.getBodyTexture(user.getUsername(), user.getBodyConfiguration().getBodyConfigurationID()));
- westPanel.morphList.initList();
- eastPanel.animationList.initAnimationList();
- }
- }
- }
- }
- }
-
- private class WestPanel extends Panel {
- Dimension dimension = new Dimension(150, 400);
-
- BodyPickerPanel bodyPickerPanel = new BodyPickerPanel();
-
- MorphListPanel morphList = new MorphListPanel();
-
- public WestPanel() {
- setPreferredSize(dimension);
- setMinimumSize(dimension);
- setLayout(new FlowLayout(FlowLayout.CENTER, 0, 5));
- setBackground(Color.WHITE);
- add(bodyPickerPanel);
- add(morphList);
- }
- }
-
- private class AnimationList extends Panel implements ActionListener {
- Dimension dimension = new Dimension(150, 400);
-
- public AnimationList() {
- setPreferredSize(dimension);
- setMinimumSize(dimension);
- setLayout(new FlowLayout(FlowLayout.CENTER, 0, 5));
- setBackground(Color.WHITE);
- }
-
- void initAnimationList() {
- removeAll();
- validate();
- Bvh[] animations = bodyPanel.bodyData.getAnimations();
- for (int i = 0; i < animations.length; i++) {
- Button button = new Button(animations[i].getName());
- button.addActionListener(this);
- add(button);
- validate();
- }
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() instanceof Button) {
- Button button = (Button) e.getSource();
- bodyPanel.renderable.playAnimation(button.getLabel(), false);
- }
- }
- }
-
- private class EastPanel extends Panel {
- Dimension dimension = new Dimension(150, 400);
-
- AnimationList animationList = new AnimationList();
-
- public EastPanel() {
- setPreferredSize(dimension);
- setMinimumSize(dimension);
- setLayout(new FlowLayout(FlowLayout.CENTER, 0, 5));
- setBackground(Color.WHITE);
- add(animationList);
- }
- }
-
public void start() {
authCookie = getParameter("loginCookie");
if (authCookie == null) {
@@ -481,13 +304,8 @@
user = new SpacelessUser(accountDoc.getUsername(), webClient.getDefaultBodyConfiguration(accountDoc.getUsername()));
bodyDataDocuments = webClient.getBodyDataDocuments();
-
- add(bodyPanel, BorderLayout.CENTER);
- westPanel = new WestPanel();
- add(westPanel, BorderLayout.WEST);
- eastPanel = new EastPanel();
- add(eastPanel, BorderLayout.EAST);
+ add(bodyPanel, BorderLayout.CENTER);
} catch (URISyntaxException e) {
e.printStackTrace();
removeAll();
@@ -571,9 +389,4 @@
configTemplate.setDoubleBuffer(GraphicsConfigTemplate.REQUIRED);
return device.getBestConfiguration(configTemplate);
}
-
- public boolean completedInitialLoad() {
- return completedInitialLoad;
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|