From ef110e1b04024980d0988accac73953f133cd605 Mon Sep 17 00:00:00 2001 From: Chris Hodapp Date: Mon, 16 Jul 2012 22:25:17 -0400 Subject: [PATCH] Moved some hard-coded constants out into web.xml environment entries; added an 'Invert' button; fixed some other miscellaneous things. --- .../client/Glass_Block_Web_Interface.java | 1 + .../src/org/hive13/client/PixelGrid.java | 38 +++++++++++- .../src/org/hive13/server/OscServiceImpl.java | 58 ++++++++++++------- .../src/org/hive13/shared/RGBColor.java | 10 ++++ Glass Block Web Interface/war/WEB-INF/web.xml | 37 ++++++++++++ 5 files changed, 122 insertions(+), 22 deletions(-) diff --git a/Glass Block Web Interface/src/org/hive13/client/Glass_Block_Web_Interface.java b/Glass Block Web Interface/src/org/hive13/client/Glass_Block_Web_Interface.java index 465166f..39e4d53 100644 --- a/Glass Block Web Interface/src/org/hive13/client/Glass_Block_Web_Interface.java +++ b/Glass Block Web Interface/src/org/hive13/client/Glass_Block_Web_Interface.java @@ -39,4 +39,5 @@ public void onSuccess(DisplayInfo info) { }); } + } diff --git a/Glass Block Web Interface/src/org/hive13/client/PixelGrid.java b/Glass Block Web Interface/src/org/hive13/client/PixelGrid.java index 9c5eebf..cf47a84 100644 --- a/Glass Block Web Interface/src/org/hive13/client/PixelGrid.java +++ b/Glass Block Web Interface/src/org/hive13/client/PixelGrid.java @@ -9,6 +9,7 @@ import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.HTMLTable; +import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Panel; import org.hive13.shared.DisplayInfo; import org.hive13.shared.RGBColor; @@ -25,24 +26,28 @@ public PixelGrid(DisplayInfo info, OscServiceAsync svc, Panel parent) super(info.getHeight(), info.getWidth()); this.info = info; + Label infoLabel = new Label(); + infoLabel.setText("Initializing..."); + parent.add(infoLabel); + //DOM.setStyleAttribute(getElement(), "border", "1px dotted red"); //DOM.setStyleAttribute(getElement(), "padding", "20px"); sinkEvents(Event.ONMOUSEDOWN | Event.ONMOUSEUP | Event.ONMOUSEOUT); syncImage(); setSize("300px", "300px"); setCellSpacing(0); - this.svc = svc; parent.add(this); parent.add(makeResetButton()); + parent.add(makeInvertButton()); + parent.remove(infoLabel); } private Button makeResetButton() { final Button resetButton = new Button(); resetButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { - System.out.println("clicked!"); svc.resetImage(new AsyncCallback() { public void onFailure(Throwable caught) { //infoLabel.setText("Error communicating with server! " + caught.getMessage()); @@ -58,6 +63,34 @@ public void onSuccess(Object o) { resetButton.setText("Clear"); return resetButton; } + + private Button makeInvertButton() { + final Button resetButton = new Button(); + resetButton.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent event) { + svc.resetImage(new AsyncCallback() { + public void onFailure(Throwable caught) { + //infoLabel.setText("Error communicating with server! " + caught.getMessage()); + System.out.println(caught.getMessage()); + } + + public void onSuccess(Object o) { + RGBColor[][] image = info.getImage(); + for(int n = 0; n < info.getHeight(); ++n) { + for(int m = 0; m < info.getWidth(); ++m) { + image[m][n].r = 255 - image[m][n].r; + image[m][n].g = 255 - image[m][n].g; + image[m][n].b = 255 - image[m][n].b; + } + } + syncImage(); + } + }); + } + }); + resetButton.setText("Invert"); + return resetButton; + } public void resetImage() { RGBColor[][] image = info.getImage(); @@ -96,6 +129,7 @@ public void onBrowserEvent(Event event) { System.out.println("Event at " + row + "," + column); switch (DOM.eventGetType(event)) { + case Event.ONMOUSEWHEEL: case Event.ONMOUSEDOWN: /* * Get the mouse wheel information diff --git a/Glass Block Web Interface/src/org/hive13/server/OscServiceImpl.java b/Glass Block Web Interface/src/org/hive13/server/OscServiceImpl.java index 11ae1a5..3972f9c 100644 --- a/Glass Block Web Interface/src/org/hive13/server/OscServiceImpl.java +++ b/Glass Block Web Interface/src/org/hive13/server/OscServiceImpl.java @@ -8,6 +8,9 @@ import java.net.UnknownHostException; import java.nio.ByteBuffer; +import javax.naming.Context; +import javax.naming.InitialContext; + import org.hive13.client.OscService; import org.hive13.shared.DisplayInfo; @@ -22,37 +25,57 @@ public class OscServiceImpl extends RemoteServiceServlet implements OscService { private DatagramSocket socket = null; private InetAddress remote = null; - private int listenPort = 12001; // doesn't matter? private DisplayInfo info = new DisplayInfo(); public OscServiceImpl() throws UnknownHostException, SocketException { super(); try { - - info.setDimensions(7, 8); - info.setHost("192.168.1.148"); - //info.setHost("192.168.20.102"); - info.setPort(12000); - info.setName("Procyon board"); + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + String host = (String) envCtx.lookup("displayHost"); + int port = Integer.parseInt((String) envCtx.lookup("displayPort")); + String name = (String) envCtx.lookup("displayName"); + int listenPort = Integer.parseInt((String) envCtx.lookup("listenPort")); + + int width = Integer.parseInt((String) envCtx.lookup("displayWidth")); + int height = Integer.parseInt((String) envCtx.lookup("displayHeight")); + + if (host == null) { + host = "192.168.1.148"; + port = 12000; + name = "Default Procyon board"; + listenPort = 12001; + width = 7; + height = 8; + } + + System.out.println("INIT: " + info.getHost() + ":" + info.getPort()); + + info.setDimensions(width, height); + info.setHost(host); + info.setPort(port); + info.setName(name); + + System.out.println("Opening socket..."); socket = new DatagramSocket(listenPort); remote = InetAddress.getByName(info.getHost()); - // Start out with empty image + // Start out with empty imagec RGBColor[][] image = info.getImage(); for (int y = 0; y < info.getHeight(); ++y) { for (int x = 0; x < info.getWidth(); ++x) { - image[x][y] = new RGBColor(); - image[x][y].r = 0; - image[x][y].g = 0; - image[x][y].b = 0; + image[x][y] = new RGBColor(0,0,0); } } + + System.out.println("Initialized display..."); + updateImage(); + System.out.println("updateImage() called..."); - System.out.println("INIT: " + info.getHost() + ":" + info.getPort()); } catch (Throwable t) { - System.out.println(t.getMessage()); + System.out.println("Exception thrown: " + t.getMessage()); } } @@ -76,12 +99,7 @@ public void updateImage() { public void setPixel(int x, int y, RGBColor c) { System.out.println("TOGGLING: " + x + "," + y); - RGBColor[][] image = info.getImage(); - - /*image[x][y].r = (byte) (255 - image[x][y].r); - image[x][y].g = (byte) (255 - image[x][y].g); - image[x][y].b = (byte) (255 - image[x][y].b);*/ - image[x][y] = c; + info.getImage()[x][y] = c; updateImage(); } diff --git a/Glass Block Web Interface/src/org/hive13/shared/RGBColor.java b/Glass Block Web Interface/src/org/hive13/shared/RGBColor.java index 211ad3e..8f445f1 100644 --- a/Glass Block Web Interface/src/org/hive13/shared/RGBColor.java +++ b/Glass Block Web Interface/src/org/hive13/shared/RGBColor.java @@ -5,6 +5,16 @@ public class RGBColor implements IsSerializable { // Just treat these like unsigned bytes. public int r, g, b; + + public RGBColor() { + r = g = b = 0; + } + + public RGBColor(int r, int g, int b) { + this.r = r; + this.g = g; + this.b = b; + } public String getString() { int rgb = r & 0xFF; diff --git a/Glass Block Web Interface/war/WEB-INF/web.xml b/Glass Block Web Interface/war/WEB-INF/web.xml index 468056c..cb7520b 100644 --- a/Glass Block Web Interface/war/WEB-INF/web.xml +++ b/Glass Block Web Interface/war/WEB-INF/web.xml @@ -20,5 +20,42 @@ Glass_Block_Web_Interface.html + + + + + displayHost + java.lang.String + 192.168.1.148 + + + displayPort + java.lang.String + 12000 + + + + displayWidth + java.lang.String + 7 + + + displayHeight + java.lang.String + 8 + + + + displayName + java.lang.String + Procyon + + + + listenPort + java.lang.String + 12001 +