|
From: <tre...@us...> - 2007-12-30 23:15:00
|
Revision: 651
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=651&view=rev
Author: trevorolio
Date: 2007-12-30 15:15:03 -0800 (Sun, 30 Dec 2007)
Log Message:
-----------
Added the ability to update the account photo using the body editor
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-12-29 20:07:54 UTC (rev 650)
+++ maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java 2007-12-30 23:15:03 UTC (rev 651)
@@ -17,27 +17,38 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
+import java.awt.GraphicsConfiguration;
import java.awt.Panel;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.zip.ZipInputStream;
+import javax.imageio.ImageIO;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
+import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
+import javax.media.j3d.GraphicsContext3D;
+import javax.media.j3d.ImageComponent;
+import javax.media.j3d.ImageComponent2D;
+import javax.media.j3d.Raster;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.swing.JLabel;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
+import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
import com.ogoglio.client.WebAPIAuthenticator;
@@ -63,12 +74,15 @@
import com.ogoglio.xml.AccountDocument;
import com.ogoglio.xml.BodyConfigurationDocument;
import com.ogoglio.xml.BodyDataDocument;
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGEncodeParam;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
/*
* NOTE: String arrays don't function in LiveConnect in IE, so we use the getXXXCount and getXXX(index) pattern
*/
-public class BodyEditorApplet extends Applet{
+public class BodyEditorApplet extends Applet {
private URI serviceURI = null;
@@ -194,6 +208,14 @@
bodyPanel.renderable.playAnimation(animationName, false, true);
}
+ public void saveAccountPhoto() {
+ if (user == null || bodyPanel == null || bodyPanel.renderable == null) {
+ return;
+ }
+ bodyPanel.canvas.writeJPEG = true;
+ bodyPanel.canvas.repaint();
+ }
+
public String getBodyConfigurationDocument() {
if (user == null || bodyPanel == null || bodyPanel.renderable == null) {
return null;
@@ -301,23 +323,23 @@
private class BodyPanel extends Panel implements MouseWheelListener {
Dimension dimension = new Dimension(300, 400);
- private J3DUniverse universe = null;
+ J3DUniverse universe = null;
- private J3DCamera camera = null;
+ J3DCamera camera = null;
- private J3DCanvas canvas = null;
+ CapturingCanvas3D canvas = null;
- private BranchGroup sceneRoot = new BranchGroup();
+ BranchGroup sceneRoot = new BranchGroup();
- private BranchGroup worldBranch = new BranchGroup();
+ BranchGroup worldBranch = new BranchGroup();
- private TransformGroup userGroup = new TransformGroup();
+ TransformGroup userGroup = new TransformGroup();
- private BoundingSphere bounds = new BoundingSphere(new Point3d(), 1000);
+ BoundingSphere bounds = new BoundingSphere(new Point3d(), 1000);
J3DUserRenderable renderable = null;
- private J3DBodyData bodyData = null;
+ J3DBodyData bodyData = null;
public BodyPanel() {
setPreferredSize(dimension);
@@ -326,7 +348,7 @@
setLayout(new BorderLayout());
universe = new J3DUniverse();
- canvas = new J3DCanvas(J3DRenderer.getGraphicsConfiguration(), false);
+ canvas = new CapturingCanvas3D(J3DRenderer.getGraphicsConfiguration(), false);
canvas.addMouseWheelListener(this);
camera = new J3DCamera();
camera.setCanvas(canvas);
@@ -461,6 +483,35 @@
//renderer.stopRenderer();
}
+ private class CapturingCanvas3D extends J3DCanvas {
+ boolean writeJPEG = false;
+
+ public CapturingCanvas3D(GraphicsConfiguration graphicsConfiguration, boolean offscreen) {
+ super(graphicsConfiguration, offscreen);
+ }
+
+ public void postSwap() {
+ if (!writeJPEG) {
+ super.postSwap();
+ return;
+ }
+ try {
+ GraphicsContext3D ctx = getGraphicsContext3D();
+ Raster ras = new Raster(new Point3f(-1.0f, -1.0f, -1.0f), Raster.RASTER_COLOR, 0, 0, getWidth(), getHeight(), new ImageComponent2D(ImageComponent.FORMAT_RGB, new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB)), null);
+ ctx.readRaster(ras);
+ BufferedImage img = ras.getImage().getImage();
+
+ ByteArrayOutputStream jpegBuffer = new ByteArrayOutputStream();
+ ImageIO.write(img, "jpeg", jpegBuffer);
+ webClient.setAccountPhoto(webClient.getAuthenticator().getUsername(), new ByteArrayInputStream(jpegBuffer.toByteArray()), "image/jpeg");
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ writeJPEG = false;
+ }
+ }
+ }
+
private class TemplateProvider implements TemplateDataProvider {
public InputStream getTemplateGeometry(String username, long templateID, int lod) {
return null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|