Skip to content

Commit

Permalink
Moved some hard-coded constants out into web.xml environment entries;…
Browse files Browse the repository at this point in the history
… added an 'Invert' button; fixed some other miscellaneous things.
  • Loading branch information
Hodapp87 committed Jul 17, 2012
1 parent 8af99f2 commit ef110e1
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 22 deletions.
Expand Up @@ -39,4 +39,5 @@ public void onSuccess(DisplayInfo info) {
});

}

}
38 changes: 36 additions & 2 deletions Glass Block Web Interface/src/org/hive13/client/PixelGrid.java
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
58 changes: 38 additions & 20 deletions Glass Block Web Interface/src/org/hive13/server/OscServiceImpl.java
Expand Up @@ -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;
Expand All @@ -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());
}
}

Expand All @@ -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();
}
Expand Down
10 changes: 10 additions & 0 deletions Glass Block Web Interface/src/org/hive13/shared/RGBColor.java
Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions Glass Block Web Interface/war/WEB-INF/web.xml
Expand Up @@ -20,5 +20,42 @@
<welcome-file-list>
<welcome-file>Glass_Block_Web_Interface.html</welcome-file>
</welcome-file-list>
<!-- Environment variables -->

<!-- These two properties are the IP address and the port of the board
running the display and listening over OSC -->
<env-entry>
<env-entry-name>displayHost</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>192.168.1.148</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>displayPort</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>12000</env-entry-value>
</env-entry>
<!-- Next two are the width and height in pixels -->
<env-entry>
<env-entry-name>displayWidth</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>7</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>displayHeight</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>8</env-entry-value>
</env-entry>
<!-- The name of the display (mostly for display purposes) -->
<env-entry>
<env-entry-name>displayName</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Procyon</env-entry-value>
</env-entry>
<!-- What port we listen on. This is basically arbitrary, since we don't listen... -->
<env-entry>
<env-entry-name>listenPort</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>12001</env-entry-value>
</env-entry>

</web-app>

0 comments on commit ef110e1

Please sign in to comment.