Author: ilya_shaikovsky
Date: 2010-08-19 11:32:41 -0400 (Thu, 19 Aug 2010)
New Revision: 18818
Added:
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/Color.java
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/image/
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/image/source.png
Modified:
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/MediaBean.java
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/MediaData.java
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/push/ChoicesBean.java
branches/RF-7939-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/imgUsage.xhtml
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/samples/imgUsage-sample.xhtml
branches/RF-7939-showcase/src/main/webapp/richfaces/push/samples/push-sample.xhtml
Log:
https://jira.jboss.org/browse/RF-9020
Added: branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/Color.java
===================================================================
--- branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/Color.java
(rev 0)
+++
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/Color.java 2010-08-19
15:32:41 UTC (rev 18818)
@@ -0,0 +1,46 @@
+package org.richfaces.demo.mediaOutput;
+
+/**
+ * @author Ilya Shaikovsky Class created to hold rgb properties of the color. Used in
order to avoid AWT dependencies as
+ * GAE not allows them
+ */
+public class Color {
+
+ private int red;
+ private int green;
+ private int blue;
+
+ public Color(int red, int green, int blue) {
+ this.red = red;
+ this.green = green;
+ this.blue = blue;
+ }
+
+ public int getRed() {
+ return red;
+ }
+
+ public void setRed(int red) {
+ this.red = red;
+ }
+
+ public int getGreen() {
+ return green;
+ }
+
+ public void setGreen(int green) {
+ this.green = green;
+ }
+
+ public int getBlue() {
+ return blue;
+ }
+
+ public void setBlue(int blue) {
+ this.blue = blue;
+ }
+ @Override
+ public String toString() {
+ return String.valueOf(getRed()) + String.valueOf(getGreen()) +
String.valueOf(getBlue());
+ }
+}
Modified:
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/MediaBean.java
===================================================================
---
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/MediaBean.java 2010-08-19
15:11:17 UTC (rev 18817)
+++
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/MediaBean.java 2010-08-19
15:32:41 UTC (rev 18818)
@@ -1,86 +1,477 @@
package org.richfaces.demo.mediaOutput;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+import java.nio.charset.Charset;
+import java.util.zip.CRC32;
+import java.util.zip.Deflater;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.Inflater;
+import java.util.zip.InflaterInputStream;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
-import javax.imageio.ImageIO;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
@ManagedBean(name = "mediaBean")
@RequestScoped
public class MediaBean {
- public void paint(OutputStream out, Object data) throws IOException {
- if (data instanceof MediaData) {
- MediaData paintData = (MediaData) data;
- BufferedImage img = new BufferedImage(paintData.width, paintData.height,
BufferedImage.TYPE_INT_RGB);
- Graphics2D g2d = img.createGraphics();
+ private static final String RICHFACES_MEDIA_OUTPUT_IMAGE_SOURCE =
"/richfaces/mediaOutput/image/source.png";
+ private static final int BUFFER_SIZE = 8192;
- g2d.setColor(Color.WHITE);
- g2d.fillRect(0, 0, 300, 120);
+ private Color[] colors;
+ private boolean isIndexed = false;
- int testLenght = paintData.text.length();
- int fontSize = testLenght < 8 ? 40 : 40 - (testLenght - 8);
+ private Charset asciiCharset = Charset.forName("US-ASCII");
- if (fontSize < 12) {
- fontSize = 12;
+ private int sectionLength;
+
+ private int imageWidth;
+
+ private byte[] lengthBytes = new byte[4];
+
+ private byte[] chunkTypeBytes = new byte[4];
+
+ private class Section {
+
+ protected void writeHeaderSectionData(OutputStream outChannel) throws IOException
{
+ outChannel.write(lengthBytes);
+ outChannel.write(chunkTypeBytes);
+ }
+
+ protected void writeInt(OutputStream outChannel, int value) throws IOException {
+ byte[] bs = new byte[4];
+ ByteBuffer.wrap(bs).order(ByteOrder.BIG_ENDIAN).asIntBuffer().put(value);
+ outChannel.write(bs);
+ }
+
+ protected void writeSectionData(InputStream inChannel, OutputStream outChannel)
throws IOException {
+ byte[] bs = new byte[BUFFER_SIZE];
+ int read = 0;
+ int remaining = sectionLength;
+
+ while ((read = inChannel.read(bs, 0, Math.min(remaining, bs.length))) > 0)
{
+ outChannel.write(bs, 0, read);
+ remaining -= read;
}
- Font font = new Font("Serif", Font.HANGING_BASELINE, fontSize);
+ if (remaining > 0) {
+ throw new IllegalArgumentException();
+ }
- g2d.setFont(font);
+ byte[] crc = new byte[4];
+ if (inChannel.read(crc) < crc.length) {
+ throw new IllegalArgumentException();
+ }
- int x = 10;
- int y = fontSize * 5 / 2;
+ outChannel.write(crc);
+ }
- g2d.translate(x, y);
+ public void write(InputStream inChannel, OutputStream outChannel) throws
IOException {
+ writeHeaderSectionData(outChannel);
+ writeSectionData(inChannel, outChannel);
+ }
+ };
- Color color = new Color(paintData.color);
+ private class HeaderSection extends Section {
- g2d.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(),
30));
+ @Override
+ protected void writeSectionData(InputStream inChannel, OutputStream outChannel)
throws IOException {
+ // // Width 4 bytes
+ // // Height 4 bytes
+ // // Bit depth 1 byte
+ // // Colour type 1 byte
+ // // Compression method 1 byte
+ // // Filter method 1 byte
+ // // Interlace method 1 byte
- AffineTransform origTransform = g2d.getTransform();
+ byte[] headerBytes = new byte[sectionLength];
- g2d.shear(-0.5 * paintData.scale, 0);
- g2d.scale(1, paintData.scale);
- g2d.drawString(paintData.text, 0, 0);
- g2d.setTransform(origTransform);
- g2d.setPaint(color);
- g2d.drawString(paintData.text, 0, 0);
- ImageIO.write(img, "jpeg", out);
+ if (inChannel.read(headerBytes) < headerBytes.length) {
+ throw new IllegalArgumentException();
+ }
+
+ if (headerBytes[8] != 8) {
+ throw new IllegalStateException("Color depth is not 8");
+ }
+
+ if (headerBytes[9] != 2 && headerBytes[9] != 3) {
+ throw new IllegalStateException("Unsupported color type");
+ }
+
+ imageWidth = ByteBuffer.wrap(headerBytes, 0,
4).order(ByteOrder.BIG_ENDIAN).asIntBuffer().get();
+
+ isIndexed = (headerBytes[9] == 3);
+
+ outChannel.write(headerBytes);
+
+ byte[] crc = new byte[4];
+ if (inChannel.read(crc) < crc.length) {
+ throw new IllegalArgumentException();
+ }
+
+ outChannel.write(crc);
}
- }
- private void copy(InputStream in, OutputStream out) throws IOException {
- byte[] buffer = new byte[2048];
- int read;
+ };
- while ((read = in.read(buffer)) != -1) {
- out.write(buffer, 0, read);
+ private void transformColors(byte[] data, int offset, int length) {
+ float[] intensities = new float[3];
+
+ for (int i = offset; i < length + offset; i += 3) {
+ float weight = 0;
+ for (int j = 0; j < intensities.length; j++) {
+ intensities[j] = ((float) (data[i + j] & 0xFF)) / 255;
+ weight += intensities[j];
+ }
+
+ float r = 0;
+ float g = 0;
+ float b = 0;
+
+ for (int j = 0; j < intensities.length; j++) {
+ r += intensities[j] * colors[j].getRed();
+ g += intensities[j] * colors[j].getGreen();
+ b += intensities[j] * colors[j].getBlue();
+ }
+
+ data[i] = (byte) (r);
+ data[i + 1] = (byte) (g);
+ data[i + 2] = (byte) (b);
}
}
- public void paintFlash(OutputStream out, Object data) throws IOException {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ private class PaletteSection extends Section {
+ @Override
+ protected void writeSectionData(InputStream inChannel, OutputStream outChannel)
throws IOException {
+ if (!isIndexed) {
+ super.writeSectionData(inChannel, outChannel);
+ } else {
+ byte[] data = new byte[2000 * 3];
+ int read;
+ int remaining = sectionLength;
- if (loader == null) {
- loader = getClass().getClassLoader();
+ assert (data.length < BUFFER_SIZE);
+
+ CRC32 crc32 = new CRC32();
+ crc32.update(chunkTypeBytes);
+
+ while ((read = (inChannel.read(data, 0, Math.min(remaining,
data.length)))) > 0) {
+ remaining -= read;
+
+ transformColors(data, 0, read);
+
+ outChannel.write(data, 0, read);
+ crc32.update(data, 0, read);
+ }
+
+ if (remaining > 0) {
+ throw new IllegalArgumentException();
+ }
+
+ inChannel.skip(4);
+
+ writeInt(outChannel, (int) crc32.getValue());
+ }
}
+ };
- InputStream stream =
loader.getResourceAsStream("org/richfaces/demo/mediaOutput/text.swf");
+ private class LimitedInputStream extends FilterInputStream {
- if (stream != null) {
- try {
- copy(stream, out);
- } finally {
- stream.close();
+ private int remaining;
+
+ protected LimitedInputStream(InputStream inChannel) {
+ super(inChannel);
+ this.remaining = sectionLength;
+ }
+
+ @Override
+ public int available() throws IOException {
+ return Math.min(super.available(), this.remaining);
+ }
+
+ @Override
+ public int read() throws IOException {
+ if (this.remaining > 0) {
+ int read = super.read();
+ if (read != -1) {
+ this.remaining--;
+ }
+
+ return read;
+ } else {
+ return -1;
}
}
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int read = super.read(b, 0, Math.min(len, this.remaining));
+ if (read > 0) {
+ this.remaining -= read;
+ }
+
+ return read;
+ }
+
+ @Override
+ public synchronized void mark(int readlimit) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean markSupported() {
+ return false;
+ }
+
+ @Override
+ public synchronized void reset() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+ long toSkip = Math.min(this.remaining, n);
+ long skipped = super.skip(toSkip);
+
+ if (skipped > 0) {
+ this.remaining -= skipped;
+ }
+
+ return skipped;
+ }
+ };
+
+ private class DataSection extends Section {
+
+ private byte paeth(byte a, byte b, byte c) {
+ int p = (a & 0xFF) + (b & 0xFF) - (c & 0xFF);
+ int pa = Math.abs(p - a);
+ int pb = Math.abs(p - b);
+ int pc = Math.abs(p - c);
+
+ int pr;
+
+ if (pa <= pb && pa <= pc) {
+ pr = a;
+ } else if (pb <= pc) {
+ pr = b;
+ } else {
+ pr = c;
+ }
+
+ return (byte) pr;
+ };
+
+ private class Filter {
+ protected int idx;
+ byte a = 0;
+ byte b = 0;
+ byte c = 0;
+
+ byte oa = 0;
+ byte ob = 0;
+ byte oc = 0;
+
+ int step = 3;
+
+ byte[] bs;
+ byte[] ps;
+
+ public void setIdx(int idx) {
+ this.idx = idx;
+
+ oa = a;
+ ob = b;
+ oc = c;
+
+ b = ps[idx];
+ if (idx > step) {
+ a = bs[idx - step];
+ c = ps[idx - step];
+ }
+ }
+
+ public void next() {
+ idx = idx + step;
+ setIdx(idx);
+ }
+ };
+
+ private class SubFilter extends Filter {
+ @Override
+ public void next() {
+ bs[idx] = (byte) ((bs[idx] & 0xFF) + (a & 0xFF) - (oa &
0xFF));
+ setIdx(idx + step);
+ }
+ };
+
+ private class UpFilter extends Filter {
+ @Override
+ public void next() {
+ bs[idx] = (byte) ((bs[idx] & 0xFF) + (b & 0xFF) - (ob &
0xFF));
+ setIdx(idx + step);
+ }
+ };
+
+ private class PaethFilter extends Filter {
+ @Override
+ public void next() {
+ bs[idx] = (byte) (paeth(a, b, c) - paeth(oa, ob, oc) + (bs[idx] &
0xFF));
+ setIdx(idx + step);
+ }
+ }
+
+ private void reconstruct(byte[] bs, byte[] ps) {
+ Filter[] filters = new Filter[3];
+
+ for (int i = 0; i < filters.length; i++) {
+ switch (bs[0]) {
+ case 0:
+ filters[i] = new Filter();
+ break;
+ case 1:
+ filters[i] = new SubFilter();
+ break;
+ case 2:
+ filters[i] = new UpFilter();
+ break;
+ case 4:
+ filters[i] = new PaethFilter();
+ break;
+
+ default:
+ throw new IllegalArgumentException(Integer.toHexString(bs[0]));
+ }
+
+ filters[i].bs = bs;
+ filters[i].ps = ps;
+ filters[i].step = 3;
+
+ filters[i].setIdx(1 + i);
+ }
+
+ for (int i = 1; i < (bs.length - 1) / 3; i++) {
+ for (Filter filter : filters) {
+ filter.next();
+ }
+ }
+
+ bs[0] = 0;
+ }
+
+ @Override
+ public void write(InputStream inChannel, OutputStream outChannel) throws
IOException {
+ if (isIndexed) {
+ super.write(inChannel, outChannel);
+ } else {
+ byte[] ps = new byte[imageWidth * 3 + 1];
+ byte[] bs = new byte[imageWidth * 3 + 1];
+
+ assert (bs.length < BUFFER_SIZE);
+
+ int read = 0;
+
+ InputStream inflaterInputStream = new BufferedInputStream(new
InflaterInputStream(
+ new LimitedInputStream(inChannel), new Inflater(), 2048),
BUFFER_SIZE);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(sectionLength);
+ DeflaterOutputStream deflaterOutputStream = new
DeflaterOutputStream(baos, new Deflater(), 2048);
+
+ while ((read = (inflaterInputStream.read(bs))) > 0) {
+ reconstruct(bs, ps);
+ transformColors(bs, 1, read - 1);
+
+ deflaterOutputStream.write(bs, 0, read);
+
+ byte[] swapVar = bs;
+ bs = ps;
+ ps = swapVar;
+ }
+
+ deflaterOutputStream.finish();
+
+ byte[] compressedSectionBytes = baos.toByteArray();
+ writeInt(outChannel, compressedSectionBytes.length);
+
+ CRC32 crc32 = new CRC32();
+ outChannel.write(chunkTypeBytes);
+ crc32.update(chunkTypeBytes);
+
+ if (inChannel.skip(4) < 4) {
+ throw new IllegalArgumentException();
+ }
+
+ outChannel.write(compressedSectionBytes);
+
+ writeInt(outChannel, (int) crc32.getValue());
+ }
+ }
+
+ };
+
+ private Section readNextSection(InputStream inChannel) throws IOException {
+ int read = inChannel.read(lengthBytes);
+ if (read != -1) {
+ if (read < lengthBytes.length) {
+ throw new IllegalArgumentException();
+ }
+
+ if (inChannel.read(chunkTypeBytes) < chunkTypeBytes.length) {
+ throw new IllegalArgumentException();
+ }
+
+ IntBuffer lengthBuffer =
ByteBuffer.wrap(lengthBytes).order(ByteOrder.BIG_ENDIAN).asIntBuffer();
+ sectionLength = lengthBuffer.get(0);
+ String chunkTypeString = new String(chunkTypeBytes, asciiCharset);
+
+ if ("IHDR".equals(chunkTypeString)) {
+ return new HeaderSection();
+ } else if ("PLTE".equals(chunkTypeString)) {
+ return new PaletteSection();
+ } else if ("IDAT".equals(chunkTypeString)) {
+ return new DataSection();
+ } else {
+ return new Section();
+ }
+ } else {
+ return null;
+ }
}
+
+ public void process(OutputStream outStream, Object data) throws Exception {
+ colors = ((MediaData) data).getNewColors();
+
+ ExternalContext extContext =
FacesContext.getCurrentInstance().getExternalContext();
+ BufferedInputStream inStream = new BufferedInputStream(extContext
+ .getResourceAsStream(RICHFACES_MEDIA_OUTPUT_IMAGE_SOURCE), BUFFER_SIZE);
+ try {
+ // skip 8-bytes of header
+ byte[] bs = new byte[8];
+ if (inStream.read(bs) < bs.length) {
+ throw new IllegalArgumentException();
+ }
+ outStream.write(bs);
+
+ Section section = null;
+ while ((section = readNextSection(inStream)) != null) {
+ section.write(inStream, outStream);
+ }
+ } finally {
+ inStream.close();
+ outStream.close();
+ }
+ }
}
Modified:
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/MediaData.java
===================================================================
---
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/MediaData.java 2010-08-19
15:11:17 UTC (rev 18817)
+++
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/mediaOutput/MediaData.java 2010-08-19
15:32:41 UTC (rev 18818)
@@ -3,65 +3,44 @@
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
-import javax.faces.bean.RequestScoped;
+import javax.faces.bean.ViewScoped;
-@ManagedBean(name = "mediaData")
-@RequestScoped
+@ManagedBean
+@ViewScoped
public class MediaData implements Serializable {
-
- /**
- *
- */
+ private static final Color[] COLORS = { new Color(255, 0, 0), new Color(0, 0, 255),
new Color(0, 255, 0),
+ new Color(255, 255, 0), new Color(0, 255, 255) };
private static final long serialVersionUID = 1L;
- int height = 120;
- int width = 300;
- Integer color;
- float scale;
- String text;
+ private int colorIndex1 = 0;
+ private int colorIndex2 = 1;
+ private int colorIndex3 = 2;
- public MediaData() {
- setText("RichFaces 4.0");
- setColor(1000);
- setScale(2);
+ public Color[] getNewColors() {
+ return new Color[] { COLORS[colorIndex1], COLORS[colorIndex2],
COLORS[colorIndex3], };
}
- public Integer getColor() {
- return color;
+ public int getColorIndex1() {
+ return colorIndex1;
}
- public void setColor(Integer color) {
- this.color = color;
+ public void setColorIndex1(int colorIndex1) {
+ this.colorIndex1 = colorIndex1;
}
- public float getScale() {
- return scale;
+ public int getColorIndex2() {
+ return colorIndex2;
}
- public void setScale(float scale) {
- this.scale = scale;
+ public void setColorIndex2(int colorIndex2) {
+ this.colorIndex2 = colorIndex2;
}
- public String getText() {
- return text;
+ public int getColorIndex3() {
+ return colorIndex3;
}
- public void setText(String text) {
- this.text = text;
+ public void setColorIndex3(int colorIndex3) {
+ this.colorIndex3 = colorIndex3;
}
- public int getWidth() {
- return width;
- }
-
- public void setWidth(int width) {
- this.width = width;
- }
-
- public int getHeight() {
- return height;
- }
-
- public void setHeight(int height) {
- this.height = height;
- }
-}
+}
\ No newline at end of file
Modified:
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/push/ChoicesBean.java
===================================================================
---
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/push/ChoicesBean.java 2010-08-19
15:11:17 UTC (rev 18817)
+++
branches/RF-7939-showcase/src/main/java/org/richfaces/demo/push/ChoicesBean.java 2010-08-19
15:32:41 UTC (rev 18818)
@@ -1,27 +1,26 @@
package org.richfaces.demo.push;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.EventListener;
import java.util.EventObject;
import java.util.List;
-import java.util.Random;
import javax.faces.bean.ManagedBean;
-import javax.faces.bean.SessionScoped;
+import javax.faces.bean.ViewScoped;
import org.ajax4jsf.event.PushEventListener;
+import org.richfaces.demo.common.data.RandomHelper;
@ManagedBean(name = "choicesBean")
-@SessionScoped
-public class ChoicesBean implements Runnable {
+@ViewScoped
+public class ChoicesBean implements Serializable{
PushEventListener listener;
-
- private boolean enabled = false;
+
+ private boolean enabled = true;
private List<Choice> choices;
private List<Choice> lastVotes;
- private Date startDate;
- private Thread thread;
private String updateInfo;
public ChoicesBean() {
@@ -39,6 +38,13 @@
lastVotes.add(new Choice("Apple"));
}
+ public void initiateEvent() {
+ for (Choice choice : lastVotes) {
+ choice.setVotesCount(RandomHelper.rand(0, 3));
+ }
+ listener.onEvent(new EventObject(this));
+ }
+
public List<Choice> getChoices() {
return choices;
}
@@ -58,56 +64,13 @@
}
public synchronized void start() {
- if (thread == null) {
- setStartDate(new Date());
- setEnabled(true);
- thread = new Thread(this);
- thread.setDaemon(true);
- thread.start();
- }
+ setEnabled(true);
}
public synchronized void stop() {
- if (thread != null) {
- setStartDate(null);
- setEnabled(false);
- thread = null;
- }
+ setEnabled(false);
}
- public static int rand(int lo, int hi) {
- Random rn2 = new Random();
- int n = hi - lo + 1;
- int i = rn2.nextInt() % n;
-
- if (i < 0) {
- i = -i;
- }
-
- return lo + i;
- }
-
- public void run() {
- while (thread != null) {
- try {
- if (((new Date()).getTime() - startDate.getTime()) >= 60000) {
- stop();
- }
-
- // changing votes count
- for (Choice choice : lastVotes) {
- choice.setVotesCount(rand(0, 3));
- }
-
- // System.out.println("New Event!");
- listener.onEvent(new EventObject(this));
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
-
public void processUpdates() {
for (Choice choice : lastVotes) {
if (choice.getVotesCount() > 0) {
@@ -116,26 +79,14 @@
choices.get(index).increment(choice.getVotesCount());
}
}
-
updateInfo = "[ ";
-
for (Choice choice : lastVotes) {
updateInfo += choice.getVotesCount() + " ";
}
-
updateInfo += "] ";
-
- // System.out.println("ChoicesBean.processUpdates()");
}
- public Thread getThread() {
- return thread;
- }
-
public boolean isEnabled() {
-
- // System.out.println("ChoicesBean.isEnabled()");
- // System.out.println(enabled);
return enabled;
}
@@ -143,14 +94,6 @@
this.enabled = enabled;
}
- public Date getStartDate() {
- return startDate;
- }
-
- public void setStartDate(Date startDate) {
- this.startDate = startDate;
- }
-
public String getUpdateInfo() {
return updateInfo;
}
Modified:
branches/RF-7939-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
===================================================================
---
branches/RF-7939-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2010-08-19
15:11:17 UTC (rev 18817)
+++
branches/RF-7939-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2010-08-19
15:32:41 UTC (rev 18818)
@@ -162,7 +162,7 @@
</sample>
</samples>
</demo>
- <demo>
+ <demo new="true">
<id>mediaOutput</id>
<name>a4j:mediaOutput</name>
<samples>
Added: branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/image/source.png
===================================================================
(Binary files differ)
Property changes on:
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/image/source.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/imgUsage.xhtml
===================================================================
---
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/imgUsage.xhtml 2010-08-19
15:11:17 UTC (rev 18817)
+++
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/imgUsage.xhtml 2010-08-19
15:32:41 UTC (rev 18818)
@@ -9,9 +9,9 @@
other binary resources defined by a user on-the-fly.</p>
<p><b>createContent</b> attribute references to the method that
will be used for content creating. The method accepts two parameters.
- The first parameter has an OutputStream type. It is a reference to the
- steam that should be used for output. The second parameter is a
- reference to a 'value' attribute of the component.</p>
+ The first parameter has an <b>OutputStream </b>type. It is a reference
+ to the steam that should be used for output. The second parameter is a
+ reference to a '<b>value</b>' attribute of the component.</p>
<p><b>value</b> attribute references to data that can be used as
input data for a content creator method. The data should be
serializable because it is encoded to the URL of the resource.</p>
@@ -23,7 +23,10 @@
cached. If it is set to true, it will be cached and the serialized
value of 'value' attribute plays the role of a cache key.</p>
- <p>Dynamically generated JPEG file:</p>
+ <p>As <b>Google Application Engine restricts AWT classes usage</b> -
in
+ this sample we <b>reading existent image and performing just re-indexing of the
+ palette</b> using colors you selected below. So try to change the color and
+ click process.</p>
<ui:include src="#{demoNavigator.sampleIncludeURI}" />
<ui:include src="/templates/includes/source-view.xhtml">
<ui:param name="src" value="#{demoNavigator.sampleIncludeURI}"
/>
Modified:
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/samples/imgUsage-sample.xhtml
===================================================================
---
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/samples/imgUsage-sample.xhtml 2010-08-19
15:11:17 UTC (rev 18817)
+++
branches/RF-7939-showcase/src/main/webapp/richfaces/mediaOutput/samples/imgUsage-sample.xhtml 2010-08-19
15:32:41 UTC (rev 18818)
@@ -5,8 +5,38 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
- <a4j:mediaOutput element="img" cacheable="false"
session="true"
- createContent="#{mediaBean.paint}" value="#{mediaData}"
- mimeType="image/jpeg" />
-
+ <h:form>
+ <h:panelGrid columns="6">
+ <h:outputText value="Color 1" />
+ <h:selectOneMenu value="#{mediaData.colorIndex1}">
+ <f:selectItem itemLabel="Red" itemValue="0"/>
+ <f:selectItem itemLabel="Dark Blue" itemValue="1"/>
+ <f:selectItem itemLabel="Green" itemValue="2"/>
+ <f:selectItem itemLabel="Yellow" itemValue="3"/>
+ <f:selectItem itemLabel="Blue" itemValue="4"/>
+ </h:selectOneMenu>
+ <h:outputText value="Color 1" />
+ <h:selectOneMenu value="#{mediaData.colorIndex2}">
+ <f:selectItem itemLabel="Red" itemValue="0"/>
+ <f:selectItem itemLabel="Dark Blue" itemValue="1"/>
+ <f:selectItem itemLabel="Green" itemValue="2"/>
+ <f:selectItem itemLabel="Yellow" itemValue="3"/>
+ <f:selectItem itemLabel="Blue" itemValue="4"/>
+ </h:selectOneMenu>
+ <h:outputText value="Color 1" />
+ <h:selectOneMenu value="#{mediaData.colorIndex3}">
+ <f:selectItem itemLabel="Red" itemValue="0"/>
+ <f:selectItem itemLabel="Dark Blue" itemValue="1"/>
+ <f:selectItem itemLabel="Green" itemValue="2"/>
+ <f:selectItem itemLabel="Yellow" itemValue="3"/>
+ <f:selectItem itemLabel="Blue" itemValue="4"/>
+ </h:selectOneMenu>
+ <f:facet name="footer">
+ <a4j:commandButton value="Process the image" render="img"
execute="@form"/>
+ </f:facet>
+ </h:panelGrid>
+ <a4j:mediaOutput element="img" cacheable="false"
session="true" id="img"
+ createContent="#{mediaBean.process}" value="#{mediaData}"
+ mimeType="image/jpeg" />
+ </h:form>
</ui:composition>
\ No newline at end of file
Modified:
branches/RF-7939-showcase/src/main/webapp/richfaces/push/samples/push-sample.xhtml
===================================================================
---
branches/RF-7939-showcase/src/main/webapp/richfaces/push/samples/push-sample.xhtml 2010-08-19
15:11:17 UTC (rev 18817)
+++
branches/RF-7939-showcase/src/main/webapp/richfaces/push/samples/push-sample.xhtml 2010-08-19
15:32:41 UTC (rev 18818)
@@ -25,27 +25,38 @@
</h:column>
</h:dataTable>
- <a4j:jsFunction name="startPush" action="#{choicesBean.start}"
- execute="@this" render="push, stop, start" />
- <a4j:jsFunction name="stopPush" action="#{choicesBean.stop}"
- execute="@this" render="push, stop, start" />
-
- <h:commandButton onclick="startPush()" value="Start"
id="start"
- disabled="#{choicesBean.enabled}" type="button" />
-
- <h:commandButton onclick="stopPush()" type="button"
value="Stop"
- id="stop" disabled="#{!choicesBean.enabled}" />
-
<a4j:outputPanel layout="block" id="tempResults">
<h:outputText
value="Latest update votes was: #{choicesBean.updateInfo} at
#{choicesBean.timeStamp}"
rendered="#{choicesBean.enabled}" />
+ <h:outputText style="color:red"
+ value="The push has been disabled automatically after 3 minutes of working.
Please refresh the page."
+ rendered="#{!choicesBean.enabled}" />
</a4j:outputPanel>
-
+
+ <fieldset>
+ <legend><b>Firing event</b></legend>
+ <a4j:commandLink style="font-weight:bold;"
+ value="Initiate server Event" id="initiate"
+ disabled="#{!choicesBean.enabled}" render="@none"
+ action="#{choicesBean.initiateEvent}" />
+ <p>Pay attention that this link has <b>@none value in render</b> so
it's actually not performs any updates.
+ It's just <b>queues server side event</b> which will be
<b>fetched by push</b> component and processed</p>
+ </fieldset>
+
<a4j:push enabled="#{choicesBean.enabled}" interval="1000"
eventProducer="#{choicesBean.addListener}" id="push"
- action="#{choicesBean.processUpdates}">
- <a4j:ajax render="choiceVotes push tempResults" />
- </a4j:push>
+ action="#{choicesBean.processUpdates}"
+ render="choiceVotes push tempResults" />
+
</h:form>
+
+ <h:form>
+ <!-- This poll used only to expire push after a minute of working. Done in order not
+ to flood the server with the requests from pages "forgotten" to be closed
before
+ weekends :)-->
+ <a4j:poll interval="180000" action="#{choicesBean.stop}"
+ enabled="#{choicesBean.enabled}"
+ render="push start initiate poll tempResults" id="poll" />
+ </h:form>
</ui:composition>
\ No newline at end of file