[diablu commit] r307 - in trunk/MailMan/Examples/Processing/Stories_in_places: . data

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 14, 2008, 7:51:38 AM10/14/08
to diablu...@googlegroups.com
Author: jorgediablu
Date: Tue Oct 14 04:50:29 2008
New Revision: 307

Added:
trunk/MailMan/Examples/Processing/Stories_in_places/Encoder.pde
trunk/MailMan/Examples/Processing/Stories_in_places/Sending.pde
trunk/MailMan/Examples/Processing/Stories_in_places/StoriesInPlace.txt
trunk/MailMan/Examples/Processing/Stories_in_places/Textbox.pde
trunk/MailMan/Examples/Processing/Stories_in_places/Word.pde
trunk/MailMan/Examples/Processing/Stories_in_places/contributors.txt

trunk/MailMan/Examples/Processing/Stories_in_places/data/Arial-Black-48.vlw
(contents, props changed)

trunk/MailMan/Examples/Processing/Stories_in_places/data/ArialMT-48.vlw
(contents, props changed)

trunk/MailMan/Examples/Processing/Stories_in_places/data/Courier10PitchBT-Bold-48.vlw
(contents, props changed)

trunk/MailMan/Examples/Processing/Stories_in_places/data/Nasalization-48.vlw
(contents, props changed)

trunk/MailMan/Examples/Processing/Stories_in_places/data/Verdana-52.vlw
(contents, props changed)
trunk/MailMan/Examples/Processing/Stories_in_places/data/bt.jpg
(contents, props changed)
trunk/MailMan/Examples/Processing/Stories_in_places/data/bt.png
(contents, props changed)
trunk/MailMan/Examples/Processing/Stories_in_places/data/st.png
(contents, props changed)
trunk/MailMan/Examples/Processing/Stories_in_places/data/stories.png
(contents, props changed)
trunk/MailMan/Examples/Processing/Stories_in_places/notsupported.txt
trunk/MailMan/Examples/Processing/Stories_in_places/server.txt
trunk/MailMan/Examples/Processing/Stories_in_places/spam.txt
Removed:

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-25.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-27.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-28.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-29.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-30.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-32.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-33.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-34.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-35.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-36.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-37.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-38.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-39.vlw

trunk/MailMan/Examples/Processing/Stories_in_places/data/AgencyFB-Reg-40.vlw
Modified:
trunk/MailMan/Examples/Processing/Stories_in_places/Stories_in_places.pde

Log:
[Mailman] Added Stories In Place Demo v1.

Added: trunk/MailMan/Examples/Processing/Stories_in_places/Encoder.pde
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/Stories_in_places/Encoder.pde Tue Oct
14 04:50:29 2008
@@ -0,0 +1,138 @@
+
+import java.io.*;
+
+
+ /**
+ * Encodes an already formed URL using the
<CODE>application/x-www-form-urlencoded</CODE>
+ * MIME format.
+ *
+ * @param s The String (URL) to be converted.
+ *
+ * @return The converted String (URL).
+ */
+ String URLEncode(String s) {
+ int questionMark = s.indexOf('?');
+
+ if (questionMark == -1) { // no parameters
+ return s;
+ } else {
+ return s.substring(0, questionMark+1) +
encodeURL(s.substring(questionMark+1));
+ }
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ * Converts a String to the
<CODE>application/x-www-form-urlencoded</CODE> MIME
+ * format.
+ *
+ * @param s The String to be converted.
+ *
+ * @return The converted String.
+ */
+ String encode(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-' || c == '*' || c == '_') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ *
+ * Similar to encode but we don't encode the '=' and '&' characters. This
+ * way we can use this to encode an already formed URL (or better, the
parameter
+ * part of an already formed URL).
+ */
+ String encodeURL(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-'
+ || c == '*' || c == '_'
+ || c == '=' || c == '&') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ void appendHex(int arg0, StringBuffer buff){
+ buff.append('%');
+ if (arg0<16) {
+ buff.append('0');
+ }
+ buff.append(Integer.toHexString(arg0));
+ }
+

Added: trunk/MailMan/Examples/Processing/Stories_in_places/Sending.pde
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/Stories_in_places/Sending.pde Tue Oct
14 04:50:29 2008
@@ -0,0 +1,12 @@
+class Sending {
+
+ String uuid;
+ String file;
+
+ public Sending(String uuid, String file) {
+ this.uuid = uuid;
+ this.file = file;
+
+ }
+
+}

Added:
trunk/MailMan/Examples/Processing/Stories_in_places/StoriesInPlace.txt
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/Stories_in_places/StoriesInPlace.txt
Tue Oct 14 04:50:29 2008
@@ -0,0 +1 @@
+Era uma vez... 1 gato Frances k tocava piano E 1 gato E falava LO5
DCREATED:19700211T091612Z LAST-MODIFIED:19700218T134649Z CLASS:PUBLIC
X-IRMC-LUID:000300010001 END:VNOTE Examplo E falava LO5 Examplo teers 1
gato Teste 1 gato

Modified:
trunk/MailMan/Examples/Processing/Stories_in_places/Stories_in_places.pde
==============================================================================
---
trunk/MailMan/Examples/Processing/Stories_in_places/Stories_in_places.pde
(original)
+++
trunk/MailMan/Examples/Processing/Stories_in_places/Stories_in_places.pde
Tue Oct 14 04:50:29 2008
@@ -1,7 +1,12 @@
+import processing.core.*;
+import fullscreen.*;
import processing.opengl.*;
import netP5.*;
import oscP5.*;

+int STORY_NUM = 1;
+
+
OscP5 osc;
NetAddress myRemoteLocation;

@@ -9,30 +14,44 @@
OscP5 oscClient;
OscP5 oscServer;

-PImage img;
+PImage cursorImg;
+PImage titulo;

-String start = "Era uma vez";
+String start = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Phasellus vel eros id tortor euismod mattis. Integer magna lectus,
malesuada nec, lacinia eu, luctus eget, enim. Nulla quis erat. Fusce
sapien. Mauris euismod scelerisque libero. Donec luctus aliquet metus. Duis
sed est volutpat lacus varius dapibus. Quisque pellentesque magna ac dolor.
Vivamus auctor. Vivamus lorem. Aenean massa ipsum, sollicitudin sed,
euismod sed, tristique non, erat. Nulla facilisi. Nunc consequat velit sit
amet neque. Maecenas bibendum sem id sem lobortis rutrum. Proin id velit.
Proin ac dolor vel elit tempus luctus. Integer eu pede consequat leo
porttitor tincidunt. Sed venenatis.";
+
+String contributors[];
+String serverData[] = {""};

String s = start;

PFont f;
-int fontSize = 32;
+PFont fontTextBox;
+PFont fontArialBlack;
+PFont fontNasa;
+
+int saverPos = 0;
+
+int FONT_SIZE = 52;
String vlw = ".vlw";

-int frameWidth = 800;
-int frameHeight = 600;
-int borderWidth = int(frameWidth * 0.05);
-int borderHeight = int(frameHeight * 0.05);
+int frameWidth = 1280;
+int frameHeight = 768;
+int borderWidth = 50;
+int borderHeight = 50;

boolean drawCursor = true;
-
+boolean drawTitle = false;
TextBox tb;

+String spam[];

+Vector sending;
+
+FullScreen fs;
void setup ()
{
-
-
+
+
size(frameWidth, frameHeight);
background(0);
oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
@@ -40,209 +59,342 @@

myRemoteLocation = new NetAddress("127.0.0.1", 12000);

- frame.setUndecorated(true);
- frameRate(10);
- f = loadFont("AgencyFB-Reg-40.vlw");
-
- tb = new TextBox(borderWidth, borderHeight+ 60,frameWidth -
2*borderWidth, frameHeight - 2*borderHeight);
- tb.addContent(start);
+ //frame.setUndecorated(true);

-
-
+ fs = new FullScreen(this);
+ fs.enter();
+ frameRate(1);
+ f = loadFont("ArialMT-48.vlw");
+ fontTextBox = loadFont("Courier10PitchBT-Bold-48.vlw");
+ fontArialBlack = loadFont("Arial-Black-48.vlw");
+ fontNasa = loadFont("Nasalization-48.vlw");
+
+ tb = new TextBox(50, 150, frameWidth-50*2, frameHeight-150-50);
+ tb.setFont(fontTextBox);
+ tb.setFontSize(FONT_SIZE);
+ // tb.addContent(start);
+ loadStory();
+ tb.clearColor();
+ loadContributors();
+ loadSpam();
+ loadServer();
+ // tb.addContent("Jorge Cardoso Stories in Place aha ha ah Stories in
Place Jorge Cardoso Stories in Place aha ha ah Stories in Place");
+
+ cursorImg = loadImage("bt.png");
+ smooth();
+ sending = new Vector();
+ titulo = loadImage("st.png");
+ noCursor();
}


void draw()
{
background(0);
- fill(128);
- tb.draw();
- if((frameCount % 8) == 0)
+ fill(255);
+ //if ( (frameCount%10) == 0) {
+ tb.draw();
+
+
+
+ textFont(f);
+ // Titulo
+ textSize(50);
+ fill(50, 100, 200);
+ String title = "Stories in Place";
+ //text(title, width/2-textWidth(title)/2, 45);
+ image(titulo, width/2-titulo.width/2, 0);
+
+ // Instru��es
+ textFont(fontArialBlack);
+ textSize(45);
+ fill(255,0, 0);
+ String inst = "!";
+ text(inst, 50, 130);
+
+ // textFont(f);
+ textSize(24.6);
+ fill(255);
+ String inst1 = "Escreve um fich. de texto ou nota e envia para o
dispositivo bluetooth 'StoriesInPlace'";
+ text(inst1, 70, 130);
+
+ drawContributors();
+//}
+
+ if((frameCount % 1) == 0)
drawCursor = !drawCursor;
if(drawCursor)
tb.drawCursor();
+
+ if ((frameCount %5) == 0) {
+ sender();
+ }
+
+ saverPos++;
+ saverPos %= width;
+ stroke(0);
+ line(saverPos, 0, saverPos, height);
+}
+
+void drawContributors() {
+
+ textFont(fontArialBlack);
+ textSize(23.5);
+ int x = width-50;
+ String sep = "|";
+ float sepWidth = textWidth(sep);
+ for (int i = contributors.length-1; i >= 0; i--) {
+ float l = textWidth(contributors[i]);
+ x -= l;
+ if (i == contributors.length-1) {
+ fill(255, 0, 0);
+ } else {
+ fill(255);
+ }
+ text(contributors[i], x, height-15);
+ x -= sepWidth;
+ fill(50, 100, 200);
+
+ //rect(x, height-15, 50, 10);
+ text(sep, x, height-15);
+ }
+ /*
+ if (textWidth(contributors) > width-50) {
+ text(contributors, -(textWidth(contributors)-width+50), height-15);
+ fill(0);
+ stroke(0);
+ rect(0, height-50, 50, 50);
+ } else {
+ text(contributors, 10, height-15);
+ }*/
+ fill(0);
+ stroke(0);
+ rect(0, height-50, 50, 50);
}


void oscEvent(OscMessage theOscMessage)
{

- if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"));
+ if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
{
recievePath(theOscMessage);
+ }
+ else {
+ println(theOscMessage);
}

}

void recievePath(OscMessage theOscMessage)
{
+ String uuid = (String) theOscMessage.arguments()[0];
+ String fname = (String) theOscMessage.arguments()[1];
+ String originalFilename = (String) theOscMessage.arguments()[2];
String filename = (String) theOscMessage.arguments()[4];
String mimetype = (String) theOscMessage.arguments()[3];
-
+
+ println(uuid + " " + fname + " " +filename + " "+ mimetype);
+
int[] n = new int[2];
-
- String content = s;
-
+
+ //String content = s;
+
String ext = filename;
ext = ext.substring(ext.lastIndexOf('.') +1);

-
- if(ext.compareToIgnoreCase("txt") == 0)
- parseTxt(filename);
- if(ext.compareToIgnoreCase("vnt") == 0)
- parseVnt(filename);
+ String content = "";
+ if(ext.compareToIgnoreCase("txt") == 0) {
+
+ content = parseTxt(filename);
+
+ }
+ else if(ext.compareToIgnoreCase("vnt") == 0) {
+
+ content = parseVnt(filename);
+ }
+ else { //not supported
+ sending.add(new Sending(uuid, "notsupported.txt"));
+ /*OscMessage message = new OscMessage("/Diablu/Mailman/SendPath",
new Object[] {
+ sketchPath("data/notsupported.txt"), uuid }
+ );
+ oscClient.send(message, myRemoteLocation);*/
+ //println("sent Response");
+ return;
+ }
+
+ if (content.length() > 0) {
+ // check commands
+ if (content.toLowerCase().indexOf("cmd:fontsize:-")>=0) {
+ tb.decreaseFont();
+ tb.distribute();
+ }
+ else if (content.toLowerCase().indexOf("cmd:fontsize:+")>=0) {
+ tb.increaseFont();
+ tb.distribute();
+ } else if (content.toLowerCase().indexOf("cmd:spam:")>=0) {
+ int s1 = content.indexOf("cmd:spam:");
+ int s2 = content.indexOf(":", s1+10);
+
+ String sWord = content.substring(s1+10, s2);
+
+ tb.addSpam(sWord);
+ saveSpam();
+ }
+ else {
+ contributors = expand(contributors, contributors.length+1);
+ contributors[contributors.length-1] = fname + " (" + hour() + ":" +
minute() + ")";
+ saveContributors();
+ tb.addContent(content);
+ String server
= "http://jorgecardoso.eu/DiABlu/StoriesInPlace/add.php?story_num="+
STORY_NUM + "&contribution="+content+"&friendly_name="+fname+"&uuid="+uuid;
+
+
+ server = URLEncode(server);
+
+ serverData = append(serverData, server);
+ saveServer();
+ println(server);
+ try {
+ loadStrings(server);
+ } catch (Exception e) {
+ println(e.getMessage());
+ }
+ saveStory();
+ // send story back
+ sending.add(new Sending(uuid, "StoriesInPlace.txt"));
+ }
+ }
}

-void parseTxt(String filename)
+String parseTxt(String filename)
{
byte bytes[] = loadBytes(filename);
-
+//println(bytes);
String content;
try{
if(bytes[0] == -1 && bytes[1] == -2)
{
content = new String(bytes, 0, bytes.length , "UTF-16");
- }
+ }
else{
- content = new String(bytes, 0, bytes.length , "UTF-8");
- }
- tb.addContent(content);
-
- } catch (UnsupportedEncodingException ex) {}
-
-}
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+ return content;

-void parseVnt(String filename)
-{
- String strings[] = loadStrings(filename);
+ }
+ catch (UnsupportedEncodingException ex) {

- String content;
-
- for(int i = 0; i < strings.length; i++)
- {
- if(strings[i].startsWith("BODY:"))
- {
- content = strings[i].substring(strings[i].indexOf(':')+1);
- tb.addContent(content);
- }
}
+ return "";

}

-
-
-class TextBox
+String parseVnt(String filename)
{
- int x;
- int y;
- int textBoxWidth;
- int textBoxHeight;
- Vector story;
- Word[][] lines;
- int totalLines;
- float lastLineWidth;
- float lastLineHeight;
- float[] wordsPerLine = new float[30];
-
- TextBox(int x, int w, int textBoxWidth, int textBoxHeight)
- {
- this.x = x;
- this.y = w;
- this.textBoxWidth = textBoxWidth;
- this.textBoxHeight = textBoxHeight;
- story = new Vector();
- lines = new Word[30][30];
- }
-
- public void addContent(String content)
- {
- println("addContent");
- StringTokenizer st = new StringTokenizer(content);
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content="";
+ String body = "";
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
{
- while(st.hasMoreTokens())
- {
- story.add(new Word(st.nextToken()));
- }
+ content = new String(bytes, 0, bytes.length , "UTF-16");
}
- distribute();
- }
-
- public void distribute()
- {
-
- float lineWidth = 0;
- float wordWidth = 0;
- int lineNum = 0;
- int linePos = 0;
- for(int i = 0; i < story.size(); i++)
- {
- Word w = (Word) story.get(i);
- textFont(w.font, w.fontSize);
- wordWidth = textWidth(w.word + " ");
- if(lineWidth + wordWidth > textBoxWidth)
- {
-
- lineNum++;
- totalLines = lineNum;
- linePos = 0;
- ((Word) story.get(i)).x = this.x;
- lineWidth = wordWidth;
- }
- else
- {
- ((Word) story.get(i)).x = lineWidth + this.x;
-
- lineWidth += wordWidth;
- }
-
- lastLineWidth = lineWidth + this.x;
- lastLineHeight = this.y + 40*(lineNum);
- ((Word) story.get(i)).y = lastLineHeight;
-
- lines[lineNum][linePos] = w;
- linePos++;
- wordsPerLine[lineNum] = linePos;
-
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
}
-
- }
+ //tb.addContent(content);

- public void draw()
- {
- for(int i = 0; i <=totalLines; i++)
- {
- for(int j = 0; j < (int) wordsPerLine[i]; j++)
- {
- textFont(lines[i][j].font, lines[i][j].fontSize);
- text(lines[i][j].word, lines[i][j].x, lines[i][j].y);
- }
- }
+
+ }
+ catch (UnsupportedEncodingException ex) {
+ println(ex.getMessage());
}
+
+
+ int start = content.toUpperCase().indexOf("BODY");
+ if(start < 0)
+ return "";
+ content = content.substring(start);
+ int dd = content.toUpperCase().indexOf(":");
+ if(dd < 0)
+ return "";
+ content = content.substring(dd+1);
+ int nl = content.toUpperCase().indexOf("\n");
+ if(nl < 0)
+ return "";
+ content = content.substring(0, nl);
+
+ while(content.toUpperCase().indexOf("=0A") != -1)
+ {
+ body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
+ content = content.substring(content.toUpperCase().indexOf("=0A")+3);
+ }
+ body += content;
+
+
+ return body;
+
+}
+
+
+public void saveContributors() {
+ saveStrings("contributors.txt", contributors);

- public void drawCursor()
- {
- stroke(128);
- line(lastLineWidth + 3, lastLineHeight +3, lastLineWidth + 3,
lastLineHeight - 22);
- }
+}
+public void loadContributors() {
+ String s[] = loadStrings("contributors.txt");
+ contributors = s;
+}
+public void saveStory() {
+ saveStrings("StoriesInPlace.txt", new String[] {tb.getStory()});
+ print ("Saved story");
}

-class Word
-{
- String word;
- PFont font;
- int fontSize;
-
- float x;
- float y;
+public void loadStory() {
+ String s[] = loadStrings("StoriesInPlace.txt");
+ tb.addContent(s[0]);
+}
+
+public void saveSpam() {
+ saveStrings("spam.txt", tb.getSpam());
+}
+
+public void loadSpam() {
+ spam = loadStrings("spam.txt");

- Word(String word)
- {
- this.word = word;
- font = loadFont("AgencyFB-Reg-32.vlw");
- fontSize = 32;
+ if (spam !=null ) {
+ for (int i = 0; i < spam.length; i++) {
+
+ tb.addSpam(spam[i]);
+ }
}
+// println(tb.getSpam());
}
-
-
+
+void saveServer() {
+ saveStrings("server.txt", serverData);
+}
+
+void loadServer() {
+ serverData = new String[] {""};
+ try {
+ serverData = loadStrings("server.txt");
+ } catch (Exception e) {}
+}
+
+public void sender() {

+ if (sending.size() > 0) {
+
+ Sending s = (Sending) sending.elementAt(0);
+ sending.remove(0);
+ println("Sending: " + s.uuid + " "+ s.file);
+ OscMessage message = new OscMessage("/Diablu/Mailman/SendPath", new
Object[] {
+ sketchPath(s.file), s.uuid }
+ );
+ oscClient.send(message, myRemoteLocation);
+ }
+}


Added: trunk/MailMan/Examples/Processing/Stories_in_places/Textbox.pde
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/Stories_in_places/Textbox.pde Tue Oct
14 04:50:29 2008
@@ -0,0 +1,237 @@
+
+
+class TextBox
+{
+ int x;
+ int y;
+ int textBoxWidth;
+ int textBoxHeight;
+
+ Vector story;
+ Word[][] lines;
+ int totalLines;
+ float lastLineWidth;
+ float lastLineHeight;
+ float[] wordsPerLine = new float[30];
+
+ PFont font;
+ int fontSize;
+
+ private String spam[] = {"merda"};
+
+ TextBox(int x, int w, int textBoxWidth, int textBoxHeight)
+ {
+ this.x = x;
+ this.y = w;
+ this.textBoxWidth = textBoxWidth;
+ this.textBoxHeight = textBoxHeight;
+ story = new Vector();
+
+ }
+ public void clearColor() {
+ for (int i = 0; i < story.size(); i++) {
+ Word w = (Word)story.get(i);
+ w.col = #ffffff;
+ }
+ }
+
+ public String[] getSpam() {
+ return spam;
+ }
+
+ public void addSpam(String s) {
+ spam = expand(spam, spam.length+1);
+ spam[spam.length-1] = s;
+
+ for (int i = 0; i < story.size(); i++) {
+ Word w = (Word)story.get(i);
+ w.processSpam();
+ }
+ }
+
+ public void setFont(PFont font) {
+ this.font = font;
+ }
+
+ public void setFontSize(int fontSize) {
+ this.fontSize = fontSize;
+ updateWordFontSize();
+ }
+
+ public int getFontSize() {
+ return this.fontSize;
+ }
+
+ public void increaseFont() {
+ this.fontSize+=2;
+ updateWordFontSize();
+ }
+ public void decreaseFont() {
+ this.fontSize-=2;
+ updateWordFontSize();
+ }
+
+ private void updateWordFontSize() {
+ for (int i = 0; i < story.size(); i++) {
+ Word w = (Word)story.get(i);
+ w.setFontSize(this.fontSize);
+ }
+ }
+
+ public void addContent(String content)
+ {
+ println("addContent " + content);
+
+ for (int i = 0; i < story.size(); i++) {
+ Word w = (Word)story.get(i);
+ w.col = #ffffff;
+ }
+
+ StringTokenizer st = new StringTokenizer(content);
+ {
+ while(st.hasMoreTokens())
+ {
+ Word w = new Word(this, st.nextToken(), this.font, this.fontSize);
+ w.setColor(#ff0000);
+ story.add(w );
+ }
+ }
+ distribute();
+ }
+
+
+
+ public void distribute()
+ {
+
+ float lineWidth = 0;
+ float wordWidth = 0;
+ int lineNum = 0;
+ int linePos = 0;
+
+ lines = new Word[40][40];
+ for(int i = 0; i < story.size(); i++)
+ {
+ Word w = (Word) story.get(i);
+ textFont(w.font, w.fontSize);
+ wordWidth = textWidth(w.word + " ");
+ if(lineWidth + wordWidth > textBoxWidth)
+ {
+
+ lineNum++;
+ if (lines.length == lineNum) {
+ lines = (Word[][])expand(lines);
+ }
+ if (lineNum >= wordsPerLine.length-1) {
+ expandWordsPerLine();
+ }
+ totalLines = lineNum;
+ linePos = 0;
+ ((Word) story.get(i)).x = this.x;
+ lineWidth = wordWidth;
+ }
+ else
+ {
+ ((Word) story.get(i)).x = lineWidth + this.x;
+
+ lineWidth += wordWidth;
+ }
+
+ lastLineWidth = lineWidth + this.x;
+ lastLineHeight = this.y + FONT_SIZE*(lineNum+1)+5;
+ ((Word) story.get(i)).y = lastLineHeight;
+ //println(lineNum + " " + linePos + " " + lines.length + " " +
lines[lineNum] + " " );
+ if (lines[lineNum] == null) {
+ lines[lineNum] = new Word[10];
+ }
+ if (linePos == lines[lineNum].length) {
+ lines[lineNum] = (Word[])expand(lines[lineNum]);
+ }
+ lines[lineNum][linePos] = w;
+ linePos++;
+
+
+ wordsPerLine[lineNum] = linePos;
+
+ }
+
+ }
+
+ private void expandWordsPerLine() {
+ wordsPerLine = expand(wordsPerLine);
+ }
+
+ public void draw()
+ {
+ float lastY = lines[totalLines][0].y;
+
+ float dec =0;
+ if (lastY > (this.y +this.textBoxHeight)) {
+ dec = lastY - (this.y +this.textBoxHeight);
+ }
+
+ for(int i = 0; i <=totalLines; i++)
+ //for(int i = totalLines-1; i >= 0; i--)
+ {
+ for(int j = 0; j < (int) wordsPerLine[i]; j++)
+ {
+ textFont(lines[i][j].font, lines[i][j].fontSize);
+ fill(lines[i][j].col);
+ //ellipse(lines[i][j].x, lines[i][j].y, 5, 5);
+ text(lines[i][j].word, lines[i][j].x, lines[i][j].y-dec-15); //-15
para dar espaco abaixo da baseline
+ }
+ }
+
+
+ fill(0);
+ stroke(0);
+ strokeWeight(1);
+ rect(0, 0, width, this.y);
+ rect(0, 0, borderWidth-1, height);
+ rect(width-borderWidth, 0, borderWidth, height);
+ rect(0, height-borderHeight, width, borderHeight);
+ //fill(255);
+ //println(lastLineHeight);
+ //ellipse(lastLineWidth, lastLineHeight, 5, 5);
+
+ noFill();
+ stroke(255);
+ strokeWeight(1);
+ rect(this.x, this.y, this.textBoxWidth, this.textBoxHeight);
+
+ line(10, this.y, 10, this.y+FONT_SIZE);
+ }
+
+ public void drawCursor()
+ {
+
+
+ float lastY = lines[totalLines][0].y;
+
+ float dec =0;
+ if (lastY > (this.y +this.textBoxHeight)) {
+ dec = lastY - (this.y +this.textBoxHeight);
+ }
+ strokeWeight(1);
+ fill(255);
+ stroke(255);
+
+ rect(lastLineWidth, lastLineHeight-5-dec, 3, -FONT_SIZE);
+ //image(cursorImg, lastLineWidth + 3, lastLineHeight +3-dec-30-15, 20,
35);
+ }
+
+ public String getStory() {
+ String storyString = "";
+ for (int i = 0; i < story.size(); i++) {
+ Word w = (Word)story.get(i);
+ storyString += w.word +" ";
+ }
+ return storyString;
+ }
+
+}
+
+
+
+
+

Added: trunk/MailMan/Examples/Processing/Stories_in_places/Word.pde
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/Stories_in_places/Word.pde Tue Oct 14
04:50:29 2008
@@ -0,0 +1,47 @@
+class Word
+{
+ String word;
+ PFont font;
+ int fontSize;
+ color col;
+
+ float x;
+ float y;
+
+ TextBox textBox;
+
+ Word(TextBox tb, String word, PFont font, int fontSize)
+ {
+ this.textBox = tb;
+
+ this.word = word;
+
+ this.font = font;
+ //font = loadFont("AgencyFB-Reg-32.vlw");
+ //font = f;
+ this.fontSize = fontSize;
+ processSpam();
+ }
+
+ public void processSpam() {
+ for (int j = 0; j < textBox.getSpam().length; j++) {
+ String spam = textBox.getSpam()[j];
+ if (this.word.equalsIgnoreCase(spam) ) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(word.charAt(0));
+ for (int i = 1 ; i < this.word.length()-1; i++) {
+ sb.append("*");
+ }
+ sb.append(word.charAt(this.word.length()-1));
+ this.word = sb.toString();
+ }
+ }
+ }
+
+ public void setFontSize(int fontSize) {
+ this.fontSize = fontSize;
+ }
+ public void setColor(color c) {
+ this.col = c;
+ }
+}

Added: trunk/MailMan/Examples/Processing/Stories_in_places/contributors.txt
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/Stories_in_places/contributors.txt
Tue Oct 14 04:50:29 2008
@@ -0,0 +1,22 @@
+
+JorgeSiemens
+BunnyInox (20:57)
+JorgeSiemens (20:57)
+BunnyInox (20:58)
+JorgeSiemens (21:21)
+JorgeSiemens (21:33)
+JorgeSiemens (21:48)
+JorgeSiemens (18:2)
+JorgeSiemens (18:50)
+JorgeSiemens (18:37)
+JorgePalm (19:4)
+JorgeSiemens (10:5)
+JorgeSiemens (12:14)
+Rick (12:19)
+DiABlu Pro (12:19)
+Rick (12:22)
+DiABlu Pro (12:22)
+JorgeSiemens (12:23)
+JorgeSiemens (12:33)
+Rick (12:35)
+JorgeSiemens (12:36)

Added:
trunk/MailMan/Examples/Processing/Stories_in_places/data/Arial-Black-48.vlw
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/Stories_in_places/data/ArialMT-48.vlw
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/Stories_in_places/data/Courier10PitchBT-Bold-48.vlw
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/Stories_in_places/data/Nasalization-48.vlw
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/Stories_in_places/data/Verdana-52.vlw
==============================================================================
Binary file. No diff available.

Added: trunk/MailMan/Examples/Processing/Stories_in_places/data/bt.jpg
==============================================================================
Binary file. No diff available.

Added: trunk/MailMan/Examples/Processing/Stories_in_places/data/bt.png
==============================================================================
Binary file. No diff available.

Added: trunk/MailMan/Examples/Processing/Stories_in_places/data/st.png
==============================================================================
Binary file. No diff available.

Added: trunk/MailMan/Examples/Processing/Stories_in_places/data/stories.png
==============================================================================
Binary file. No diff available.

Added: trunk/MailMan/Examples/Processing/Stories_in_places/notsupported.txt
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/Stories_in_places/notsupported.txt
Tue Oct 14 04:50:29 2008
@@ -0,0 +1,3 @@
+Stories in Place
+Sorry, the file you sent me is not supported.
+I can only read some simple text files (plain text files, notes).

Added: trunk/MailMan/Examples/Processing/Stories_in_places/server.txt
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/Stories_in_places/server.txt Tue Oct
14 04:50:29 2008
@@ -0,0 +1,3 @@
+
+http://jorgecardoso.eu/DiABlu/StoriesInPlace/add.php?story_num=1&contribution=Teste%0d&friendly_name=Rick&uuid=000FDE9EEB04
+http://jorgecardoso.eu/DiABlu/StoriesInPlace/add.php?story_num=1&contribution=1+gato%0d&friendly_name=JorgeSiemens&uuid=0001E33C596A

Added: trunk/MailMan/Examples/Processing/Stories_in_places/spam.txt
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/Stories_in_places/spam.txt Tue Oct 14
04:50:29 2008
@@ -0,0 +1,7 @@
+merda
+caralho
+foda
+foda-se
+puta
+cabrão
+cabrao
\ No newline at end of file
Reply all
Reply to author
Forward
0 new messages