Author: amarkhel
Date: 2009-02-10 09:54:12 -0500 (Tue, 10 Feb 2009)
New Revision: 12614
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ImageUtils.java
trunk/test-applications/realworld/web/src/main/webapp/includes/image/slideshow.xhtml
Removed:
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/realWorld-taglib.xml
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/album.xhtml
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/confirmation.xhtml
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/image.xhtml
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/linkPanel.xhtml
Modified:
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/pages.xml
Log:
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ImageUtils.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ImageUtils.java
(rev 0)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ImageUtils.java 2009-02-10
14:54:12 UTC (rev 12614)
@@ -0,0 +1,148 @@
+/**
+ *
+ */
+package org.richfaces.realworld.util;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.imageio.stream.FileImageInputStream;
+import javax.imageio.stream.ImageInputStream;
+
+import org.richfaces.model.UploadItem;
+import org.richfaces.realworld.service.Constants;
+
+/**
+ * @author Andrey Markavtsov
+ *
+ */
+public class ImageUtils {
+
+ public static class ImageDimension {
+ public int WIDTH;
+ public int HEIGHT;
+ public String POSTFIX_NAME;
+ public ImageDimension(int width, int height, String postfix_name) {
+ super();
+ WIDTH = width;
+ HEIGHT = height;
+ POSTFIX_NAME = postfix_name;
+ }
+ };
+
+ public static final String _MEDIUM = "_medium";
+ public static final String _MINI = "_mini";
+
+
+ public static ImageDimension MINI = new ImageDimension(100, 100, _MINI);
+ public static ImageDimension MEDIUM = new ImageDimension(640, 480, _MEDIUM);
+
+
+ BufferedImage bufferedImage;
+
+ double width;
+ double height;
+
+ public ImageUtils(BufferedImage bufferedImage) {
+ if (bufferedImage == null) {
+ throw new NullPointerException("Buffered image is null");
+ }
+
+ this.height = bufferedImage.getHeight();
+ this.width = bufferedImage.getWidth();
+ this.bufferedImage = bufferedImage;
+ }
+
+ private BufferedImage scaleToWidth(int width) throws IOException {
+ double height = width * this.height / this.width;
+ BufferedImage newImage = new BufferedImage(width, (int) height,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics2D = createGraphics(newImage);
+ graphics2D.drawImage(bufferedImage, 0, 0, (int) width, (int) height,
+ null);
+ return newImage;
+ }
+
+ private BufferedImage scaleToHeight(int height) throws IOException {
+ double width = height * this.width / this.height;
+ BufferedImage newImage = new BufferedImage((int) width, (int) height,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics2D = createGraphics(newImage);
+ graphics2D.drawImage(bufferedImage, 0, 0, (int) width, (int) height,
+ null);
+ return newImage;
+ }
+
+ private Graphics2D createGraphics(BufferedImage image) {
+ Graphics2D graphics2D = image.createGraphics();
+ graphics2D.setBackground(new Color(255, 255, 255));
+ graphics2D.clearRect(0, 0, image.getWidth(), image.getHeight());
+ graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+ RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ return graphics2D;
+ }
+
+ public BufferedImage resizeImage(double width, double height)
+ throws IOException {
+
+ if (width > height) {
+ if (this.bufferedImage.getWidth() < width) {
+ return bufferedImage;
+ }
+ return scaleToWidth((int) width);
+ } else {
+ if (this.bufferedImage.getHeight() < height) {
+ return bufferedImage;
+ }
+ return scaleToHeight((int) height);
+ }
+
+ }
+
+ public static void resizeImage(UploadItem image, String pathToUpload, ImageDimension ...
dimensions)
+ throws IOException {
+
+ BufferedImage bufferedImage = ImageIO.read(new FileImageInputStream(image.getFile()));
+
+ ImageUtils utils = new ImageUtils(bufferedImage);
+ int width, height;
+
+ ImageIO.write(bufferedImage, Constants.JPG, new File(pathToUpload));
+
+ for (ImageDimension dimension : dimensions) {
+ String fileName = transformPath(pathToUpload,dimension.POSTFIX_NAME);
+ width = dimension.WIDTH;
+ height = dimension.HEIGHT;
+ BufferedImage resizedBuffer = bufferedImage;
+
+ if (width > height) {
+ if (bufferedImage.getWidth() > width) {
+ resizedBuffer = utils.scaleToWidth((int) width);
+ }
+ } else {
+ if (bufferedImage.getHeight() > height) {
+ resizedBuffer = utils.scaleToHeight((int) height);
+ }
+ }
+
+ if (resizedBuffer != null) {
+ ImageIO.write(resizedBuffer, Constants.JPG, new File(fileName));
+ }
+
+ }
+
+ }
+
+ public static String transformPath(String target, String substitute){
+ String begin = target.substring(0, target.lastIndexOf(Constants.DOT));
+ String end = target.substring(target.lastIndexOf(Constants.DOT));
+ return begin + substitute + end;
+ }
+
+}
Property changes on:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ImageUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/pages.xml
===================================================================
--- trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/pages.xml 2009-02-10
14:53:24 UTC (rev 12613)
+++ trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/pages.xml 2009-02-10
14:54:12 UTC (rev 12614)
@@ -15,6 +15,7 @@
</page>
<page view-id="/index.xhtml">
+ <begin-conversation if="#{!conversation.longRunning}"/>
<action if="#{!identity.isLoggedIn()}"
execute="#{authenticator.start}"/>
<navigation from-action="#{authenticator.logout}">
<rule if-outcome="logout">
@@ -22,6 +23,9 @@
<redirect view-id="/index.html"/>
</rule>
</navigation>
+ <navigation from-action="#{authenticator.start}">
+ <redirect view-id="/index.xhtml"/>
+ </navigation>
</page>
<exception class="org.jboss.seam.framework.EntityNotFoundException">
Deleted:
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/realWorld-taglib.xml
===================================================================
---
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/realWorld-taglib.xml 2009-02-10
14:53:24 UTC (rev 12613)
+++
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/realWorld-taglib.xml 2009-02-10
14:54:12 UTC (rev 12614)
@@ -1,23 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE facelet-taglib PUBLIC
- "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
- "facelet-taglib_1_0.dtd">
-<facelet-taglib>
- <
namespace>http://richfaces.org/richx</namespace>
- <tag>
- <tag-name>album</tag-name>
- <source>templates/album.xhtml</source>
- </tag>
- <tag>
- <tag-name>confirmation</tag-name>
- <source>templates/confirmation.xhtml</source>
- </tag>
- <tag>
- <tag-name>image</tag-name>
- <source>templates/image.xhtml</source>
- </tag>
- <tag>
- <tag-name>linkPanel</tag-name>
- <source>templates/linkPanel.xhtml</source>
- </tag>
-</facelet-taglib>
\ No newline at end of file
Deleted:
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/album.xhtml
===================================================================
(Binary files differ)
Deleted:
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/confirmation.xhtml
===================================================================
(Binary files differ)
Deleted:
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/image.xhtml
===================================================================
(Binary files differ)
Deleted:
trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/linkPanel.xhtml
===================================================================
(Binary files differ)
Added:
trunk/test-applications/realworld/web/src/main/webapp/includes/image/slideshow.xhtml
===================================================================
(Binary files differ)
Property changes on:
trunk/test-applications/realworld/web/src/main/webapp/includes/image/slideshow.xhtml
___________________________________________________________________
Name: svn:mime-type
+ application/xhtml+xml