Author: nbelaevski
Date: 2010-11-08 18:06:12 -0500 (Mon, 08 Nov 2010)
New Revision: 19995
Added:
trunk/core/api/src/main/java/org/richfaces/resource/AbstractJava2DUserResource.java
trunk/core/api/src/main/java/org/richfaces/resource/AbstractUserResource.java
trunk/core/api/src/main/java/org/richfaces/resource/DynamicUserResource.java
trunk/core/impl/src/test/java/org/richfaces/resource/UserResourcesTestCase.java
Removed:
trunk/core/impl/src/main/java/org/ajax4jsf/resource/AnimationResource.java
trunk/core/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/AnimatedGifEncoder.java
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/GifDecoder.java
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/LZWEncoder.java
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/NeuQuant.java
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/BaseTreeImage.java
Modified:
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java
trunk/core/api/src/main/java/org/richfaces/resource/Java2DAnimatedUserResource.java
trunk/core/api/src/main/java/org/richfaces/resource/Java2DUserResource.java
trunk/core/impl/src/main/java/org/richfaces/VersionBean.java
trunk/core/impl/src/main/java/org/richfaces/application/CoreConfiguration.java
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/images/InputErrorIcon.java
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java
trunk/core/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DAnimatedUserResourceWrapperImpl.java
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java
trunk/core/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java
trunk/ui/core/ui/src/main/java/org/richfaces/resource/PushResource.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/ArrowBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteBaseGradient.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteButtonGradient.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteFieldGradient.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarIcon.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarSeparator.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowBottom.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowLeft.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowRight.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowBottom.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowTop.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeLineImage.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeLineLastImage.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeMinusImage.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreePlusImage.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarAnimatedBackgroundImage.java
Log:
https://jira.jboss.org/browse/RF-9534
Modified:
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java
===================================================================
---
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -22,6 +22,7 @@
package org.richfaces.cdk.resource.scan.impl;
import java.io.IOException;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.Collection;
@@ -35,6 +36,7 @@
import org.richfaces.cdk.vfs.VFSRoot;
import org.richfaces.cdk.vfs.VFSType;
import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.DynamicUserResource;
import org.richfaces.resource.ResourceFactory;
import org.richfaces.resource.ResourceKey;
@@ -102,11 +104,8 @@
ReflectionsExt refl = new ReflectionsExt(configurationBuilder);
Collection<Class<?>> allClasses = Sets.newHashSet();
- // TODO - reflections library doesn't handle @Inherited correctly
- for (Class<?> annotatedClass :
refl.getTypesAnnotatedWith(DynamicResource.class)) {
- allClasses.add(annotatedClass);
- allClasses.addAll(refl.getSubTypesOf(annotatedClass));
- }
+ addAnnotatedClasses(DynamicResource.class, refl, allClasses);
+ addAnnotatedClasses(DynamicUserResource.class, refl, allClasses);
allClasses.addAll(refl.getMarkedClasses());
allClasses = Collections2.filter(allClasses,
UNINSTANTIATABLE_CLASSES_PREDICATE);
@@ -115,6 +114,14 @@
resources.addAll(resourceFactory.getMappedDynamicResourceKeys());
}
+ private void addAnnotatedClasses(Class<? extends Annotation> annotationClass,
ReflectionsExt refl, Collection<Class<?>> allClasses) {
+ // TODO - reflections library doesn't handle @Inherited correctly
+ for (Class<?> annotatedClass : refl.getTypesAnnotatedWith(annotationClass))
{
+ allClasses.add(annotatedClass);
+ allClasses.addAll(refl.getSubTypesOf(annotatedClass));
+ }
+ }
+
public Collection<ResourceKey> getResources() {
return resources;
}
Added:
trunk/core/api/src/main/java/org/richfaces/resource/AbstractJava2DUserResource.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/AbstractJava2DUserResource.java
(rev 0)
+++
trunk/core/api/src/main/java/org/richfaces/resource/AbstractJava2DUserResource.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import java.awt.Dimension;
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class AbstractJava2DUserResource implements Java2DUserResource {
+
+ private ImageType imageType;
+
+ private Dimension dimension;
+
+ public AbstractJava2DUserResource(Dimension dimension) {
+ this(ImageType.PNG, dimension);
+ }
+
+ public AbstractJava2DUserResource(ImageType imageType, Dimension dimension) {
+ super();
+ this.imageType = imageType;
+ this.dimension = dimension;
+ }
+
+ public ImageType getImageType() {
+ return imageType;
+ }
+
+ public Dimension getDimension() {
+ return dimension;
+ }
+
+ public Map<String, String> getResponseHeaders() {
+ return null;
+ }
+
+ public Date getLastModified() {
+ return null;
+ }
+}
Added: trunk/core/api/src/main/java/org/richfaces/resource/AbstractUserResource.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/AbstractUserResource.java
(rev 0)
+++
trunk/core/api/src/main/java/org/richfaces/resource/AbstractUserResource.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class AbstractUserResource implements UserResource {
+
+ public Map<String, String> getResponseHeaders() {
+ return null;
+ }
+
+ public Date getLastModified() {
+ return null;
+ }
+
+ public int getContentLength() {
+ return -1;
+ }
+
+}
Added: trunk/core/api/src/main/java/org/richfaces/resource/DynamicUserResource.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/DynamicUserResource.java
(rev 0)
+++
trunk/core/api/src/main/java/org/richfaces/resource/DynamicUserResource.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.TYPE)
+@Inherited
+public @interface DynamicUserResource {
+
+ public boolean cacheable() default true;
+
+ public boolean versioned() default true;
+
+}
Modified:
trunk/core/api/src/main/java/org/richfaces/resource/Java2DAnimatedUserResource.java
===================================================================
---
trunk/core/api/src/main/java/org/richfaces/resource/Java2DAnimatedUserResource.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/api/src/main/java/org/richfaces/resource/Java2DAnimatedUserResource.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -21,7 +21,6 @@
*/
package org.richfaces.resource;
-import java.awt.Dimension;
import java.awt.Graphics2D;
/**
@@ -38,6 +37,6 @@
public boolean hasNextFrame();
- public void paint(Graphics2D graphics2d, Dimension dimension);
+ public void paint(Graphics2D graphics2d);
}
Modified: trunk/core/api/src/main/java/org/richfaces/resource/Java2DUserResource.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/Java2DUserResource.java 2010-11-08
15:56:04 UTC (rev 19994)
+++ trunk/core/api/src/main/java/org/richfaces/resource/Java2DUserResource.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -40,6 +40,6 @@
public Dimension getDimension();
- public void paint(Graphics2D graphics2D, Dimension dimension);
+ public void paint(Graphics2D graphics2D);
}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/resource/AnimationResource.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/resource/AnimationResource.java 2010-11-08
15:56:04 UTC (rev 19994)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/resource/AnimationResource.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -1,105 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.ajax4jsf.resource;
-
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-
-import org.ajax4jsf.resource.image.animatedgif.AnimatedGifEncoder;
-import org.richfaces.resource.ImageType;
-
-public abstract class AnimationResource extends Java2Dresource {
-
- private int[] delays;
- private int currFrameIndex = 0;
-
- public AnimationResource() {
- super(ImageType.GIF);
- }
-
- protected abstract Dimension getFrameSize();
-
- protected abstract int getNumberOfFrames();
-
- protected int getRepeat() {
- return -1;
- }
-
- protected int[] getFrameDelays() {
- if (delays == null) {
- delays = new int[getNumberOfFrames()];
- Arrays.fill(delays, 0);
- }
-
- return delays;
- }
-
-
-
- @Override
- public InputStream getInputStream() throws IOException {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream output = new DataOutputStream(baos);
- Dimension frameSize = getFrameSize();
- int numberOfFrames = getNumberOfFrames();
- BufferedImage frame = null;
- currFrameIndex = 0;
- if (frameSize.getHeight() > 0.0 && frameSize.getWidth() > 0.0
- && numberOfFrames > 0) {
- AnimatedGifEncoder encoder = new AnimatedGifEncoder();
- encoder.start(output);
- encoder.setRepeat(getRepeat());
- int[] delays = getFrameDelays();
- while (currFrameIndex < numberOfFrames) {
- frame = getImageType().createImage(frameSize.width,
- frameSize.height);
- Graphics2D graphics = frame.createGraphics();
- paint(graphics, currFrameIndex++);
- graphics.dispose();
- encoder.addFrame(frame);
- if (delays != null && delays.length > currFrameIndex) {
- encoder.setDelay(delays[currFrameIndex]);
- }
- }
- encoder.finish();
- }
- output.flush();
- output.close();
- return new ByteArrayInputStream(baos.toByteArray());
-
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- protected abstract void paint(Graphics2D graphics2D, int frameIndex);
-
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java 2010-11-08
15:56:04 UTC (rev 19994)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -1,193 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.resource;
-
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.faces.context.FacesContext;
-import javax.imageio.ImageIO;
-
-import org.ajax4jsf.util.HtmlColor;
-import org.richfaces.renderkit.util.HtmlDimensions;
-import org.richfaces.resource.AbstractCacheableResource;
-import org.richfaces.resource.ImageType;
-import org.richfaces.resource.StateHolderResource;
-import org.richfaces.skin.Skin;
-import org.richfaces.skin.SkinFactory;
-
-/**
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.3 $ $Date: 2007/02/01 15:31:57 $
- */
-public abstract class Java2Dresource extends AbstractCacheableResource implements
StateHolderResource {
- private static final String SKIN_MARKER = "Skin.";
- private ImageType imageType;
-
- public Java2Dresource(ImageType imageType) {
- super();
- this.imageType = imageType;
- }
- public ImageType getImageType() {
- return this.imageType;
- }
- /**
- * Primary calculation of image dimensions - used when HTML code is
- * generated to render IMG's width and height Subclasses should override
- * this method to provide correct sizes of rendered images
- *
- * @return dimensions of the image to be displayed on page
- */
- public abstract Dimension getDimension();
-
- /**
- * Template method for create image as Applet-like paint.
- *
- * @param graphics2D -
- * graphics to paint.
- */
- protected void paint(Graphics2D graphics2D, Dimension dimension) {
- graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
- graphics2D.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
-
- graphics2D.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
- RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
- }
-
- /*
- * (non-Javadoc)
- * @see org.richfaces.resource.AbstractBaseResource#getInputStream()
- */
- @Override
- public InputStream getInputStream() throws IOException {
- Dimension dimension = getDimension();
- int width = dimension.width;
- int height = dimension.height;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- if ((width > 0) && (height > 0)) {
- BufferedImage image = imageType.createImage(width, height);
- Graphics2D g2d = image.createGraphics();
-
- try {
- paint(g2d, dimension);
- } finally {
- g2d.dispose();
- }
-
- try {
- ImageIO.write(image, imageType.getFormatName(), baos);
- } finally {
- try {
- baos.close();
- } catch (IOException e) {
-
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- return new ByteArrayInputStream(baos.toByteArray());
- }
-
- @Override
- public String getContentType() {
- return imageType.getMimeType();
- }
-
- protected String getValueParameter(FacesContext context, String name) {
- SkinFactory skinFactory = SkinFactory.getInstance();
-
- Skin skin = skinFactory.getSkin(context);
- String value = (String) skin.getParameter(context, name);
-
- if (value == null || value.length() == 0) {
- skin = skinFactory.getDefaultSkin(context);
- value = (String) skin.getParameter(context, name);
- }
-
- return value;
- }
-
- protected String encodeSkinParameter(String param){
- if(param.startsWith(SKIN_MARKER)){
- String name = param.substring(SKIN_MARKER.length());
- return getValueParameter(FacesContext.getCurrentInstance(), name );
- }
- return param;
- }
-
- protected Integer getColorValueParameter(FacesContext context, String name, boolean
useDefault) {
- Skin skin;
- if (useDefault) {
- skin = SkinFactory.getInstance().getDefaultSkin(context);
- } else {
- skin = SkinFactory.getInstance().getSkin(context);
- }
-
- return decodeColor((String) skin.getParameter(context, name));
- }
-
- protected Integer getHeight(FacesContext context, String heightParamName) {
- SkinFactory skinFactory = SkinFactory.getInstance();
- Skin skin = skinFactory.getSkin(context);
-
- String height = (String) skin.getParameter(context, heightParamName);
- if (height == null || height.length() == 0) {
- skin = skinFactory.getDefaultSkin(context);
- height = (String) skin.getParameter(context, heightParamName);
- }
-
- if (height != null && height.length() != 0) {
- return Integer.valueOf(HtmlDimensions.decode(height).intValue());
- } else {
- return Integer.valueOf(16);
- }
- }
-
- protected Integer decodeColor(String value) {
- if (value != null && value.length() != 0) {
- return Integer.valueOf(HtmlColor.decode(value).getRGB());
- } else {
- return null;
- }
- }
-
- public void readState(FacesContext context, DataInput dataInput) throws IOException
{}
-
- public void writeState(FacesContext context, DataOutput dataOutput) throws
IOException {}
-
- public boolean isTransient() {
- return false;
- }
-}
Deleted:
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/AnimatedGifEncoder.java
===================================================================
---
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/AnimatedGifEncoder.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/AnimatedGifEncoder.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -1,486 +0,0 @@
-package org.ajax4jsf.resource.image.animatedgif;
-
-import java.io.*;
-import java.awt.*;
-import java.awt.image.*;
-
-/**
- * Class AnimatedGifEncoder - Encodes a GIF file consisting of one or
- * more frames.
- * <pre>
- * Example:
- * AnimatedGifEncoder e = new AnimatedGifEncoder();
- * e.start(outputFileName);
- * e.setDelay(1000); // 1 frame per sec
- * e.addFrame(image1);
- * e.addFrame(image2);
- * e.finish();
- * </pre>
- * No copyright asserted on the source code of this class. May be used
- * for any purpose, however, refer to the Unisys LZW patent for restrictions
- * on use of the associated LZWEncoder class. Please forward any corrections
- * to kweiner(a)fmsware.com.
- *
- * @author Kevin Weiner, FM Software
- * @version 1.03 November 2003
- *
- */
-
-public class AnimatedGifEncoder {
-
- protected int width; // image size
- protected int height;
- protected Color transparent = null; // transparent color if given
- protected int transIndex; // transparent index in color table
- protected int repeat = -1; // no repeat
- protected int delay = 0; // frame delay (hundredths)
- protected boolean started = false; // ready to output frames
- protected OutputStream out;
- protected BufferedImage image; // current frame
- protected byte[] pixels; // BGR byte array from frame
- protected byte[] indexedPixels; // converted frame indexed to palette
- protected int colorDepth; // number of bit planes
- protected byte[] colorTab; // RGB palette
- protected boolean[] usedEntry = new boolean[256]; // active palette entries
- protected int palSize = 7; // color table size (bits-1)
- protected int dispose = -1; // disposal code (-1 = use default)
- protected boolean closeStream = false; // close stream when finished
- protected boolean firstFrame = true;
- protected boolean sizeSet = false; // if false, get size from first frame
- protected int sample = 10; // default sample interval for quantizer
-
- /**
- * Sets the delay time between each frame, or changes it
- * for subsequent frames (applies to last frame added).
- *
- * @param ms int delay time in milliseconds
- */
- public void setDelay(int ms) {
- delay = Math.round(ms / 10.0f);
- }
-
- /**
- * Sets the GIF frame disposal code for the last added frame
- * and any subsequent frames. Default is 0 if no transparent
- * color has been set, otherwise 2.
- * @param code int disposal code.
- */
- public void setDispose(int code) {
- if (code >= 0) {
- dispose = code;
- }
- }
-
- /**
- * Sets the number of times the set of GIF frames
- * should be played. Default is 1; 0 means play
- * indefinitely. Must be invoked before the first
- * image is added.
- *
- * @param iter int number of iterations.
- * @return
- */
- public void setRepeat(int iter) {
- if (iter >= 0) {
- repeat = iter;
- }
- }
-
- /**
- * Sets the transparent color for the last added frame
- * and any subsequent frames.
- * Since all colors are subject to modification
- * in the quantization process, the color in the final
- * palette for each frame closest to the given color
- * becomes the transparent color for that frame.
- * May be set to null to indicate no transparent color.
- *
- * @param c Color to be treated as transparent on display.
- */
- public void setTransparent(Color c) {
- transparent = c;
- }
-
- /**
- * Adds next GIF frame. The frame is not written immediately, but is
- * actually deferred until the next frame is received so that timing
- * data can be inserted. Invoking <code>finish()</code> flushes all
- * frames. If <code>setSize</code> was not invoked, the size of the
- * first image is used for all subsequent frames.
- *
- * @param im BufferedImage containing frame to write.
- * @return true if successful.
- */
- public boolean addFrame(BufferedImage im) {
- if ((im == null) || !started) {
- return false;
- }
- boolean ok = true;
- try {
- if (!sizeSet) {
- // use first frame's size
- setSize(im.getWidth(), im.getHeight());
- }
- image = im;
- getImagePixels(); // convert to correct format if necessary
- analyzePixels(); // build color table & map pixels
- if (firstFrame) {
- writeLSD(); // logical screen descriptior
- writePalette(); // global color table
- if (repeat >= 0) {
- // use NS app extension to indicate reps
- writeNetscapeExt();
- }
- }
- writeGraphicCtrlExt(); // write graphic control extension
- writeImageDesc(); // image descriptor
- if (!firstFrame) {
- writePalette(); // local color table
- }
- writePixels(); // encode and write pixel data
- firstFrame = false;
- } catch (IOException e) {
- ok = false;
- }
-
- return ok;
- }
-
- /**
- * Flushes any pending data and closes output file.
- * If writing to an OutputStream, the stream is not
- * closed.
- */
- public boolean finish() {
- if (!started) {
- return false;
- }
- boolean ok = true;
- started = false;
- try {
- out.write(0x3b); // gif trailer
- out.flush();
- if (closeStream) {
- out.close();
- }
- } catch (IOException e) {
- ok = false;
- }
-
- // reset for subsequent use
- transIndex = 0;
- out = null;
- image = null;
- pixels = null;
- indexedPixels = null;
- colorTab = null;
- closeStream = false;
- firstFrame = true;
-
- return ok;
- }
-
- /**
- * Sets frame rate in frames per second. Equivalent to
- * <code>setDelay(1000/fps)</code>.
- *
- * @param fps float frame rate (frames per second)
- */
- public void setFrameRate(float fps) {
- if (fps != 0f) {
- delay = Math.round(100f / fps);
- }
- }
-
- /**
- * Sets quality of color quantization (conversion of images
- * to the maximum 256 colors allowed by the GIF specification).
- * Lower values (minimum = 1) produce better colors, but slow
- * processing significantly. 10 is the default, and produces
- * good color mapping at reasonable speeds. Values greater
- * than 20 do not yield significant improvements in speed.
- *
- * @param quality int greater than 0.
- * @return
- */
- public void setQuality(int quality) {
- if (quality < 1) {
- quality = 1;
- }
- sample = quality;
- }
-
- /**
- * Sets the GIF frame size. The default size is the
- * size of the first frame added if this method is
- * not invoked.
- *
- * @param w int frame width.
- * @param h int frame width.
- */
- public void setSize(int w, int h) {
- if (started && !firstFrame) {
- return;
- }
- width = w;
- height = h;
- if (width < 1) {
- width = 320;
- }
- if (height < 1) {
- height = 240;
- }
- sizeSet = true;
- }
-
- /**
- * Initiates GIF file creation on the given stream. The stream
- * is not closed automatically.
- *
- * @param os OutputStream on which GIF images are written.
- * @return false if initial write failed.
- */
- public boolean start(OutputStream os) {
- if (os == null) {
- return false;
- }
- boolean ok = true;
- closeStream = false;
- out = os;
- try {
- writeString("GIF89a"); // header
- } catch (IOException e) {
- ok = false;
- }
- started = ok;
- return started;
- }
-
- /**
- * Initiates writing of a GIF file with the specified name.
- *
- * @param file String containing output file name.
- * @return false if open or initial write failed.
- */
- public boolean start(String file) {
- boolean ok = true;
- try {
- out = new BufferedOutputStream(new FileOutputStream(file));
- ok = start(out);
- closeStream = true;
- } catch (IOException e) {
- ok = false;
- }
- started = ok;
- return started;
- }
-
- /**
- * Analyzes image colors and creates color map.
- */
- protected void analyzePixels() {
- int len = pixels.length;
- int nPix = len / 3;
- indexedPixels = new byte[nPix];
- NeuQuant nq = new NeuQuant(pixels, len, sample);
- // initialize quantizer
- colorTab = nq.process(); // create reduced palette
- // convert map from BGR to RGB
- for (int i = 0; i < colorTab.length; i += 3) {
- byte temp = colorTab[i];
- colorTab[i] = colorTab[i + 2];
- colorTab[i + 2] = temp;
- usedEntry[i / 3] = false;
- }
- // map image pixels to new palette
- int k = 0;
- for (int i = 0; i < nPix; i++) {
- int index =
- nq.map(pixels[k++] & 0xff,
- pixels[k++] & 0xff,
- pixels[k++] & 0xff);
- usedEntry[index] = true;
- indexedPixels[i] = (byte) index;
- }
- pixels = null;
- colorDepth = 8;
- palSize = 7;
- // get closest match to transparent color if specified
- if (transparent != null) {
- transIndex = findClosest(transparent);
- }
- }
-
- /**
- * Returns index of palette color closest to c
- *
- */
- protected int findClosest(Color c) {
- if (colorTab == null) {
- return -1;
- }
- int r = c.getRed();
- int g = c.getGreen();
- int b = c.getBlue();
- int minpos = 0;
- int dmin = 256 * 256 * 256;
- int len = colorTab.length;
- for (int i = 0; i < len; i += 3) {
- int dr = r - (colorTab[i] & 0xff);
- int dg = g - (colorTab[i + 1] & 0xff);
- int db = b - (colorTab[i + 2] & 0xff);
- int d = dr * dr + dg * dg + db * db;
- int index = i + 2 / 3;
- if (usedEntry[index] && (d < dmin)) {
- dmin = d;
- minpos = index;
- }
-
- }
- return minpos;
- }
-
- /**
- * Extracts image pixels into byte array "pixels"
- */
- protected void getImagePixels() {
- int w = image.getWidth();
- int h = image.getHeight();
- int type = image.getType();
- if ((w != width)
- || (h != height)
- || (type != BufferedImage.TYPE_3BYTE_BGR)) {
- // create new image with right size/format
- BufferedImage temp =
- new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
- Graphics2D g = temp.createGraphics();
- g.drawImage(image, 0, 0, null);
- image = temp;
- }
- pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
- }
-
- /**
- * Writes Graphic Control Extension
- */
- protected void writeGraphicCtrlExt() throws IOException {
- out.write(0x21); // extension introducer
- out.write(0xf9); // GCE label
- out.write(4); // data block size
- int transp;
- int disp;
- if (transparent == null) {
- transp = 0;
- disp = 0; // dispose = no action
- } else {
- transp = 1;
- disp = 2; // force clear if using transparent color
- }
- if (dispose >= 0) {
- disp = dispose & 7; // user override
- }
- disp <<= 2;
-
- // packed fields
- out.write(0 | // 1:3 reserved
- disp | // 4:6 disposal
- 0 | // 7 user input - 0 = none
- transp); // 8 transparency flag
-
- writeShort(delay); // delay x 1/100 sec
- out.write(transIndex); // transparent color index
- out.write(0); // block terminator
- }
-
- /**
- * Writes Image Descriptor
- */
- protected void writeImageDesc() throws IOException {
- out.write(0x2c); // image separator
- writeShort(0); // image position x,y = 0,0
- writeShort(0);
- writeShort(width); // image size
- writeShort(height);
- // packed fields
- if (firstFrame) {
- // no LCT - GCT is used for first (or only) frame
- out.write(0);
- } else {
- // specify normal LCT
- out.write(0x80 | // 1 local color table 1=yes
- 0 | // 2 interlace - 0=no
- 0 | // 3 sorted - 0=no
- 0 | // 4-5 reserved
- palSize); // 6-8 size of color table
- }
- }
-
- /**
- * Writes Logical Screen Descriptor
- */
- protected void writeLSD() throws IOException {
- // logical screen size
- writeShort(width);
- writeShort(height);
- // packed fields
- out.write((0x80 | // 1 : global color table flag = 1 (gct used)
- 0x70 | // 2-4 : color resolution = 7
- 0x00 | // 5 : gct sort flag = 0
- palSize)); // 6-8 : gct size
-
- out.write(0); // background color index
- out.write(0); // pixel aspect ratio - assume 1:1
- }
-
- /**
- * Writes Netscape application extension to define
- * repeat count.
- */
- protected void writeNetscapeExt() throws IOException {
- out.write(0x21); // extension introducer
- out.write(0xff); // app extension label
- out.write(11); // block size
- writeString("NETSCAPE" + "2.0"); // app id + auth code
- out.write(3); // sub-block size
- out.write(1); // loop sub-block id
- writeShort(repeat); // loop count (extra iterations, 0=repeat forever)
- out.write(0); // block terminator
- }
-
- /**
- * Writes color table
- */
- protected void writePalette() throws IOException {
- out.write(colorTab, 0, colorTab.length);
- int n = (3 * 256) - colorTab.length;
- for (int i = 0; i < n; i++) {
- out.write(0);
- }
- }
-
- /**
- * Encodes and writes pixel data
- */
- protected void writePixels() throws IOException {
- LZWEncoder encoder =
- new LZWEncoder(width, height, indexedPixels, colorDepth);
- encoder.encode(out);
- }
-
- /**
- * Write 16-bit value to output stream, LSB first
- */
- protected void writeShort(int value) throws IOException {
- out.write(value & 0xff);
- out.write((value >> 8) & 0xff);
- }
-
- /**
- * Writes string to output stream
- */
- protected void writeString(String s) throws IOException {
- for (int i = 0; i < s.length(); i++) {
- out.write((byte) s.charAt(i));
- }
- }
-}
Deleted:
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/GifDecoder.java
===================================================================
---
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/GifDecoder.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/GifDecoder.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -1,817 +0,0 @@
-package org.ajax4jsf.resource.image.animatedgif;
-
-import java.net.*;
-import java.io.*;
-import java.util.*;
-import java.awt.*;
-import java.awt.image.*;
-
-/**
- * Class GifDecoder - Decodes a GIF file into one or more frames.
- * <br><pre>
- * Example:
- * GifDecoder d = new GifDecoder();
- * d.read("sample.gif");
- * int n = d.getFrameCount();
- * for (int i = 0; i < n; i++) {
- * BufferedImage frame = d.getFrame(i); // frame i
- * int t = d.getDelay(i); // display duration of frame in milliseconds
- * // do something with frame
- * }
- * </pre>
- * No copyright asserted on the source code of this class. May be used for
- * any purpose, however, refer to the Unisys LZW patent for any additional
- * restrictions. Please forward any corrections to kweiner(a)fmsware.com.
- *
- * @author Kevin Weiner, FM Software; LZW decoder adapted from John Cristy's
ImageMagick.
- * @version 1.03 November 2003
- *
- */
-
-public class GifDecoder {
-
- /**
- * File read status: No errors.
- */
- public static final int STATUS_OK = 0;
-
- /**
- * File read status: Error decoding file (may be partially decoded)
- */
- public static final int STATUS_FORMAT_ERROR = 1;
-
- /**
- * File read status: Unable to open source.
- */
- public static final int STATUS_OPEN_ERROR = 2;
- protected static final int MAXSTACKSIZE = 4096;
- protected BufferedInputStream in;
- protected int status;
-
- protected int width; // full image width
- protected int height; // full image height
- protected boolean gctFlag; // global color table used
- protected int gctSize; // size of global color table
- protected int loopCount = 1; // iterations; 0 = repeat forever
-
- protected int[] gct; // global color table
- protected int[] lct; // local color table
- protected int[] act; // active color table
-
- protected int bgIndex; // background color index
- protected int bgColor; // background color
- protected int lastBgColor; // previous bg color
- protected int pixelAspect; // pixel aspect ratio
-
- protected boolean lctFlag; // local color table flag
- protected boolean interlace; // interlace flag
- protected int lctSize; // local color table size
-
- protected int ix;
- protected int iy;
- protected int iw;
- protected int ih; // current image rectangle
- protected Rectangle lastRect; // last image rect
- protected BufferedImage image; // current frame
- protected BufferedImage lastImage; // previous frame
-
- protected byte[] block = new byte[256]; // current data block
- protected int blockSize = 0; // block size
-
- // last graphic control extension info
- protected int dispose = 0;
- // 0=no action; 1=leave in place; 2=restore to bg; 3=restore to prev
- protected int lastDispose = 0;
- protected boolean transparency = false; // use transparent color
- protected int delay = 0; // delay in milliseconds
- protected int transIndex; // transparent color index
-
-
- // max decoder pixel stack size
-
- // LZW decoder working arrays
- protected short[] prefix;
- protected byte[] suffix;
- protected byte[] pixelStack;
- protected byte[] pixels;
-
- protected ArrayList frames; // frames read from current file
- protected int frameCount;
-
- static class GifFrame {
- private BufferedImage image;
- private int delay;
- public GifFrame(BufferedImage im, int del) {
- image = im;
- delay = del;
- }
-
- public BufferedImage getImage() {
- return image;
- }
-
- public int getDelay() {
- return delay;
- }
- }
-
- /**
- * Gets display duration for specified frame.
- *
- * @param n int index of frame
- * @return delay in milliseconds
- */
- public int getDelay(int n) {
- //
- delay = -1;
- if ((n >= 0) && (n < frameCount)) {
- delay = ((GifFrame) frames.get(n)).delay;
- }
- return delay;
- }
-
- /**
- * Gets the number of frames read from file.
- * @return frame count
- */
- public int getFrameCount() {
- return frameCount;
- }
-
- /**
- * Gets the first (or only) image read.
- *
- * @return BufferedImage containing first frame, or null if none.
- */
- public BufferedImage getImage() {
- return getFrame(0);
- }
-
- /**
- * Gets the "Netscape" iteration count, if any.
- * A count of 0 means repeat indefinitiely.
- *
- * @return iteration count if one was specified, else 1.
- */
- public int getLoopCount() {
- return loopCount;
- }
-
- /**
- * Creates new frame image from current data (and previous
- * frames as specified by their disposition codes).
- */
- protected void setPixels() {
- // expose destination image's pixels as int array
- int[] dest =
- ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
-
- // fill in starting image contents based on last image's dispose code
- if (lastDispose > 0) {
- if (lastDispose == 3) {
- // use image before last
- int n = frameCount - 2;
- if (n > 0) {
- lastImage = getFrame(n - 1);
- } else {
- lastImage = null;
- }
- }
-
- if (lastImage != null) {
- int[] prev =
- ((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData();
- System.arraycopy(prev, 0, dest, 0, width * height);
- // copy pixels
-
- if (lastDispose == 2) {
- // fill last image rect area with background color
- Graphics2D g = image.createGraphics();
- Color c = null;
- if (transparency) {
- c = new Color(0, 0, 0, 0); // assume background is transparent
- } else {
- c = new Color(lastBgColor); // use given background color
- }
- g.setColor(c);
- g.setComposite(AlphaComposite.Src); // replace area
- g.fill(lastRect);
- g.dispose();
- }
- }
- }
-
- // copy each source line to the appropriate place in the destination
- int pass = 1;
- int inc = 8;
- int iline = 0;
- for (int i = 0; i < ih; i++) {
- int line = i;
- if (interlace) {
- if (iline >= ih) {
- pass++;
- switch (pass) {
- case 2 :
- iline = 4;
- break;
- case 3 :
- iline = 2;
- inc = 4;
- break;
- case 4 :
- iline = 1;
- inc = 2;
- break;
- default:
- break;
- }
- }
- line = iline;
- iline += inc;
- }
- line += iy;
- if (line < height) {
- int k = line * width;
- int dx = k + ix; // start of line in dest
- int dlim = dx + iw; // end of dest line
- if ((k + width) < dlim) {
- dlim = k + width; // past dest edge
- }
- int sx = i * iw; // start of line in source
- while (dx < dlim) {
- // map color and insert in destination
- int index = ((int) pixels[sx++]) & 0xff;
- int c = act[index];
- if (c != 0) {
- dest[dx] = c;
- }
- dx++;
- }
- }
- }
- }
-
- /**
- * Gets the image contents of frame n.
- *
- * @return BufferedImage representation of frame, or null if n is invalid.
- */
- public BufferedImage getFrame(int n) {
- BufferedImage im = null;
- if ((n >= 0) && (n < frameCount)) {
- im = ((GifFrame) frames.get(n)).image;
- }
- return im;
- }
-
- /**
- * Gets image size.
- *
- * @return GIF image dimensions
- */
- public Dimension getFrameSize() {
- return new Dimension(width, height);
- }
-
- /**
- * Reads GIF image from stream
- *
- * @param BufferedInputStream containing GIF file.
- * @return read status code (0 = no errors)
- */
- public int read(BufferedInputStream is) {
- init();
- if (is != null) {
- in = is;
- readHeader();
- if (!err()) {
- readContents();
- if (frameCount < 0) {
- status = STATUS_FORMAT_ERROR;
- }
- }
- } else {
- status = STATUS_OPEN_ERROR;
- }
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return status;
- }
-
- /**
- * Reads GIF image from stream
- *
- * @param InputStream containing GIF file.
- * @return read status code (0 = no errors)
- */
- public int read(InputStream is) {
- init();
- if (is != null) {
- if (!(is instanceof BufferedInputStream)) {
- is = new BufferedInputStream(is);
- }
- in = (BufferedInputStream) is;
- readHeader();
- if (!err()) {
- readContents();
- if (frameCount < 0) {
- status = STATUS_FORMAT_ERROR;
- }
- }
- } else {
- status = STATUS_OPEN_ERROR;
- }
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return status;
- }
-
- /**
- * Reads GIF file from specified file/URL source
- * (URL assumed if name contains ":/" or "file:")
- *
- * @param name String containing source
- * @return read status code (0 = no errors)
- */
- public int read(String name) {
- status = STATUS_OK;
- try {
- name = name.trim().toLowerCase();
- if ((name.indexOf("file:") >= 0) ||
- (name.indexOf(":/") > 0)) {
- URL url = new URL(name);
- in = new BufferedInputStream(url.openStream());
- } else {
- in = new BufferedInputStream(new FileInputStream(name));
- }
- status = read(in);
- } catch (IOException e) {
- status = STATUS_OPEN_ERROR;
- }
-
- return status;
- }
-
- /**
- * Decodes LZW image data into pixel array.
- * Adapted from John Cristy's ImageMagick.
- */
- protected void decodeImageData() {
- int nullCode = -1;
- int npix = iw * ih;
- int available;
- int clear;
- int codeMask;
- int codeSize;
- int endOfInformation;
- int inCode;
- int oldCode;
- int bits;
- int code;
- int count;
- int i;
- int datum;
- int dataSize;
- int first;
- int top;
- int bi;
- int pi;
-
- if ((pixels == null) || (pixels.length < npix)) {
- pixels = new byte[npix]; // allocate new pixel array
- }
- if (prefix == null) {
- prefix = new short[MAXSTACKSIZE];
- }
- if (suffix == null) {
- suffix = new byte[MAXSTACKSIZE];
- }
- if (pixelStack == null) {
- pixelStack = new byte[MAXSTACKSIZE + 1];
- }
-
- // Initialize GIF data stream decoder.
-
- dataSize = read();
- clear = 1 << dataSize;
- endOfInformation = clear + 1;
- available = clear + 2;
- oldCode = nullCode;
- codeSize = dataSize + 1;
- codeMask = (1 << codeSize) - 1;
- for (code = 0; code < clear; code++) {
- prefix[code] = 0;
- suffix[code] = (byte) code;
- }
-
- // Decode GIF pixel stream.
- bi = 0;
- datum = 0;
- bits = 0;
- count = 0;
- first = 0;
- top = 0;
- pi = 0;
- bi = 0;
-
- for (i = 0; i < npix;) {
- if (top == 0) {
- if (bits < codeSize) {
- // Load bytes until there are enough bits for a code.
- if (count == 0) {
- // Read a new data block.
- count = readBlock();
- if (count <= 0) {
- break;
- }
- bi = 0;
- }
- datum += (((int) block[bi]) & 0xff) << bits;
- bits += 8;
- bi++;
- count--;
- continue;
- }
-
- // Get the next code.
-
- code = datum & codeMask;
- datum >>= codeSize;
- bits -= codeSize;
-
- // Interpret the code
-
- if ((code > available) || (code == endOfInformation)) {
- break;
- }
- if (code == clear) {
- // Reset decoder.
- codeSize = dataSize + 1;
- codeMask = (1 << codeSize) - 1;
- available = clear + 2;
- oldCode = nullCode;
- continue;
- }
- if (oldCode == nullCode) {
- pixelStack[top++] = suffix[code];
- oldCode = code;
- first = code;
- continue;
- }
- inCode = code;
- if (code == available) {
- pixelStack[top++] = (byte) first;
- code = oldCode;
- }
- while (code > clear) {
- pixelStack[top++] = suffix[code];
- code = prefix[code];
- }
- first = ((int) suffix[code]) & 0xff;
-
- // Add a new string to the string table,
-
- if (available >= MAXSTACKSIZE) {
- break;
- }
- pixelStack[top++] = (byte) first;
- prefix[available] = (short) oldCode;
- suffix[available] = (byte) first;
- available++;
- if (((available & codeMask) == 0)
- && (available < MAXSTACKSIZE)) {
- codeSize++;
- codeMask += available;
- }
- oldCode = inCode;
- }
-
- // Pop a pixel off the pixel stack.
-
- top--;
- pixels[pi++] = pixelStack[top];
- i++;
- }
-
- for (i = pi; i < npix; i++) {
- pixels[i] = 0; // clear missing pixels
- }
-
- }
-
- /**
- * Returns true if an error was encountered during reading/decoding
- */
- protected boolean err() {
- return status != STATUS_OK;
- }
-
- /**
- * Initializes or re-initializes reader
- */
- protected void init() {
- status = STATUS_OK;
- frameCount = 0;
- frames = new ArrayList();
- gct = null;
- lct = null;
- }
-
- /**
- * Reads a single byte from the input stream.
- */
- protected int read() {
- int curByte = 0;
- try {
- curByte = in.read();
- } catch (IOException e) {
- status = STATUS_FORMAT_ERROR;
- }
- return curByte;
- }
-
- /**
- * Reads next variable length block from input.
- *
- * @return number of bytes stored in "buffer"
- */
- protected int readBlock() {
- blockSize = read();
- int n = 0;
- if (blockSize > 0) {
- try {
- int count = 0;
- while (n < blockSize) {
- count = in.read(block, n, blockSize - n);
- if (count == -1) {
- break;
- }
- n += count;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- if (n < blockSize) {
- status = STATUS_FORMAT_ERROR;
- }
- }
- return n;
- }
-
- /**
- * Reads color table as 256 RGB integer values
- *
- * @param ncolors int number of colors to read
- * @return int array containing 256 colors (packed ARGB with full alpha)
- */
- protected int[] readColorTable(int ncolors) {
- int nbytes = 3 * ncolors;
- int[] tab = null;
- byte[] c = new byte[nbytes];
- int n = 0;
- try {
- n = in.read(c);
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (n < nbytes) {
- status = STATUS_FORMAT_ERROR;
- } else {
- tab = new int[256]; // max size to avoid bounds checks
- int i = 0;
- int j = 0;
- while (i < ncolors) {
- int r = ((int) c[j++]) & 0xff;
- int g = ((int) c[j++]) & 0xff;
- int b = ((int) c[j++]) & 0xff;
- tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b;
- }
- }
- return tab;
- }
-
- /**
- * Main file parser. Reads GIF content blocks.
- */
- protected void readContents() {
- // read GIF file content blocks
- boolean done = false;
- while (!(done || err())) {
- int code = read();
- switch (code) {
-
- case 0x2C : // image separator
- readImage();
- break;
-
- case 0x21 : // extension
- code = read();
- switch (code) {
- case 0xf9 : // graphics control extension
- readGraphicControlExt();
- break;
-
- case 0xff : // application extension
- readBlock();
- String app = "";
- for (int i = 0; i < 11; i++) {
- app += (char) block[i];
- }
- if (app.equals("NETSCAPE2.0")) {
- readNetscapeExt();
- } else {
- skip();
- }// don't care
- break;
-
- default : // uninteresting extension
- skip();
- }
- break;
-
- case 0x3b : // terminator
- done = true;
- break;
-
- case 0x00 : // bad byte, but keep going and see what happens
- break;
-
- default :
- status = STATUS_FORMAT_ERROR;
- }
- }
- }
-
- /**
- * Reads Graphics Control Extension values
- */
- protected void readGraphicControlExt() {
- read(); // block size
- int packed = read(); // packed fields
- dispose = (packed & 0x1c) >> 2; // disposal method
- if (dispose == 0) {
- dispose = 1; // elect to keep old image if discretionary
- }
- transparency = (packed & 1) != 0;
- delay = readShort() * 10; // delay in milliseconds
- transIndex = read(); // transparent color index
- read(); // block terminator
- }
-
- /**
- * Reads GIF file header information.
- */
- protected void readHeader() {
- String id = "";
- for (int i = 0; i < 6; i++) {
- id += (char) read();
- }
- if (!id.startsWith("GIF")) {
- status = STATUS_FORMAT_ERROR;
- return;
- }
-
- readLSD();
- if (gctFlag && !err()) {
- gct = readColorTable(gctSize);
- bgColor = gct[bgIndex];
- }
- }
-
- /**
- * Reads next frame image
- */
- protected void readImage() {
- ix = readShort(); // (sub)image position & size
- iy = readShort();
- iw = readShort();
- ih = readShort();
-
- int packed = read();
- lctFlag = (packed & 0x80) != 0; // 1 - local color table flag
- interlace = (packed & 0x40) != 0; // 2 - interlace flag
- // 3 - sort flag
- // 4-5 - reserved
- lctSize = 2 << (packed & 7); // 6-8 - local color table size
-
- if (lctFlag) {
- lct = readColorTable(lctSize); // read table
- act = lct; // make local table active
- } else {
- act = gct; // make global table active
- if (bgIndex == transIndex) {
- bgColor = 0;
- }
- }
- int save = 0;
- if (transparency) {
- save = act[transIndex];
- act[transIndex] = 0; // set transparent color if specified
- }
-
- if (act == null) {
- status = STATUS_FORMAT_ERROR; // no color table defined
- }
-
- if (err()) {
- return;
- }
-
- decodeImageData(); // decode pixel data
- skip();
-
- if (err()) {
- return;
- }
-
- frameCount++;
-
- // create new image to receive frame data
- image =
- new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
-
- setPixels(); // transfer pixel data to image
-
- frames.add(new GifFrame(image, delay)); // add image to frame list
-
- if (transparency) {
- act[transIndex] = save;
- }
- resetFrame();
-
- }
-
- /**
- * Reads Logical Screen Descriptor
- */
- protected void readLSD() {
-
- // logical screen size
- width = readShort();
- height = readShort();
-
- // packed fields
- int packed = read();
- gctFlag = (packed & 0x80) != 0; // 1 : global color table flag
- // 2-4 : color resolution
- // 5 : gct sort flag
- gctSize = 2 << (packed & 7); // 6-8 : gct size
-
- bgIndex = read(); // background color index
- pixelAspect = read(); // pixel aspect ratio
- }
-
- /**
- * Reads Netscape extenstion to obtain iteration count
- */
- protected void readNetscapeExt() {
- do {
- readBlock();
- if (block[0] == 1) {
- // loop count sub-block
- int b1 = ((int) block[1]) & 0xff;
- int b2 = ((int) block[2]) & 0xff;
- loopCount = (b2 << 8) | b1;
- }
- } while ((blockSize > 0) && !err());
- }
-
- /**
- * Reads next 16-bit value, LSB first
- */
- protected int readShort() {
- // read 16-bit value, LSB first
- return read() | (read() << 8);
- }
-
- /**
- * Resets frame state for reading next image.
- */
- protected void resetFrame() {
- lastDispose = dispose;
- lastRect = new Rectangle(ix, iy, iw, ih);
- lastImage = image;
- lastBgColor = bgColor;
- int dispose = 0;
- boolean transparency = false;
- int delay = 0;
- lct = null;
- }
-
- /**
- * Skips variable length blocks up to and including
- * next zero length block.
- */
- protected void skip() {
- do {
- readBlock();
- } while ((blockSize > 0) && !err());
- }
-}
Deleted:
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/LZWEncoder.java
===================================================================
---
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/LZWEncoder.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/LZWEncoder.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -1,291 +0,0 @@
-package org.ajax4jsf.resource.image.animatedgif;
-
-import java.io.OutputStream;
-import java.io.IOException;
-
-//==============================================================================
-// Adapted from Jef Poskanzer's Java port by way of J. M. G. Elliott.
-// K Weiner 12/00
-
-class LZWEncoder {
- static final int BITS = 12;
- static final int HSIZE = 5003;
- private static final int EOF = -1;
- private int imgW;
- private int imgH;
- private byte[] pixAry;
- private int initCodeSize;
- private int remaining;
- private int curPixel;
-
- private int nBits; // number of bits/code
- private int maxbits = BITS; // user settable max # bits/code
- private int maxcode; // maximum code, given n_bits
- private int maxmaxcode = 1 << BITS; // should NEVER generate this code
-
- private int[] htab = new int[HSIZE];
- private int[] codetab = new int[HSIZE];
-
- private int hsize = HSIZE; // for dynamic table sizing
-
- private int freeEnt = 0; // first unused entry
-
- // block compression parameters -- after all codes are used up,
- // and compression rate changes, start over.
- private boolean clearFlg = false;
-
- // Algorithm: use open addressing double hashing (no chaining) on the
- // prefix code / next character combination. We do a variant of Knuth's
- // algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
- // secondary probe. Here, the modular division first probe is gives way
- // to a faster exclusive-or manipulation. Also do block compression with
- // an adaptive reset, whereby the code table is cleared when the compression
- // ratio decreases, but after the table fills. The variable-length output
- // codes are re-sized at this point, and a special CLEAR code is generated
- // for the decompressor. Late addition: construct the table according to
- // file size for noticeable speed improvement on small files. Please direct
- // questions about this implementation to ames!jaw.
-
- private int gInitBits;
-
- private int clearCode;
- private int eOFCode;
-
- // output
- //
- // Output the given code.
- // Inputs:
- // code: A n_bits-bit integer. If == -1, then EOF. This assumes
- // that n_bits =< wordsize - 1.
- // Outputs:
- // Outputs code to the file.
- // Assumptions:
- // Chars are 8 bits long.
- // Algorithm:
- // Maintain a BITS character long buffer (so that 8 codes will
- // fit in it exactly). Use the VAX insv instruction to insert each
- // code in turn. When the buffer fills up empty it and start over.
-
- private int curAccum = 0;
- private int curBits = 0;
- private int aCount;
-
- // Define the storage for the packet accumulator
- private byte[] accum = new byte[256];
-
- private int[] masks =
- {
- 0x0000,
- 0x0001,
- 0x0003,
- 0x0007,
- 0x000F,
- 0x001F,
- 0x003F,
- 0x007F,
- 0x00FF,
- 0x01FF,
- 0x03FF,
- 0x07FF,
- 0x0FFF,
- 0x1FFF,
- 0x3FFF,
- 0x7FFF,
- 0xFFFF
- };
-
- LZWEncoder(int width, int height, byte[] pixels, int colorDepth) {
- imgW = width;
- imgH = height;
- pixAry = pixels;
- initCodeSize = Math.max(2, colorDepth);
- }
-
- // Add a character to the end of the current packet, and if it is 254
- // characters, flush the packet to disk.
- void charOut(byte c, OutputStream outs) throws IOException {
- accum[aCount++] = c;
- if (aCount >= 254) {
- flushChar(outs);
- }
- }
-
- // Clear out the hash table
-
- // table clear for block compress
- void clBlock(OutputStream outs) throws IOException {
- clHash(hsize);
- freeEnt = clearCode + 2;
- clearFlg = true;
-
- output(clearCode, outs);
- }
-
- // reset code table
- void clHash(int hsize) {
- for (int i = 0; i < hsize; ++i) {
- htab[i] = -1;
- }
- }
-
- void compress(int initBits, OutputStream outs) throws IOException {
- int fcode;
- int i /* = 0 */;
- int c;
- int ent;
- int disp;
- int hsizeReg;
- int hshift;
-
- // Set up the globals: g_init_bits - initial number of bits
- gInitBits = initBits;
-
- // Set up the necessary values
- clearFlg = false;
- nBits = gInitBits;
- maxcode = maxcode(nBits);
-
- clearCode = 1 << (initBits - 1);
- eOFCode = clearCode + 1;
- freeEnt = clearCode + 2;
-
- aCount = 0; // clear packet
-
- ent = nextPixel();
-
- hshift = 0;
- for (fcode = hsize; fcode < 65536; fcode *= 2) {
- ++hshift;
- }
- hshift = 8 - hshift; // set hash code range bound
-
- hsizeReg = hsize;
- clHash(hsizeReg); // clear hash table
-
- output(clearCode, outs);
-
- outer_loop :
- while ((c = nextPixel()) != EOF) {
- fcode = (c << maxbits) + ent;
- i = (c << hshift) ^ ent; // xor hashing
-
- if (htab[i] == fcode) {
- ent = codetab[i];
- continue;
- } else if (htab[i] >= 0) {
- disp = hsizeReg - i; // secondary hash (after G. Knott)
- if (i == 0) {
- disp = 1;
- }
- do {
- i -= disp;
- if (i < 0) {
- i += hsizeReg;
- }
-
- if (htab[i] == fcode) {
- ent = codetab[i];
- continue outer_loop;
- }
- } while (htab[i] >= 0);
- }
- output(ent, outs);
- ent = c;
- if (freeEnt < maxmaxcode) {
- codetab[i] = freeEnt++; // code -> hashtable
- htab[i] = fcode;
- } else {
- clBlock(outs);
- }
- }
- // Put out the final code.
- output(ent, outs);
- output(eOFCode, outs);
- }
-
- //----------------------------------------------------------------------------
- void encode(OutputStream os) throws IOException {
- os.write(initCodeSize); // write "initial code size" byte
-
- remaining = imgW * imgH; // reset navigation variables
- curPixel = 0;
-
- compress(initCodeSize + 1, os); // compress and write the pixel data
-
- os.write(0); // write block terminator
- }
-
- // Flush the packet to disk, and reset the accumulator
- void flushChar(OutputStream outs) throws IOException {
- if (aCount > 0) {
- outs.write(aCount);
- outs.write(accum, 0, aCount);
- aCount = 0;
- }
- }
-
- final int maxcode(int nBits) {
- return (1 << nBits) - 1;
- }
-
- //----------------------------------------------------------------------------
- // Return the next pixel from the image
- //----------------------------------------------------------------------------
- private int nextPixel() {
- if (remaining == 0) {
- return EOF;
- }
-
- --remaining;
-
- byte pix = pixAry[curPixel++];
-
- return pix & 0xff;
- }
-
- void output(int code, OutputStream outs) throws IOException {
- curAccum &= masks[curBits];
-
- if (curBits > 0) {
- curAccum |= (code << curBits);
- } else {
- curAccum = code;
- }
-
- curBits += nBits;
-
- while (curBits >= 8) {
- charOut((byte) (curAccum & 0xff), outs);
- curAccum >>= 8;
- curBits -= 8;
- }
-
- // If the next entry is going to be too big for the code size,
- // then increase it, if possible.
- if (freeEnt > maxcode || clearFlg) {
- if (clearFlg) {
- nBits = gInitBits;
- maxcode = maxcode(nBits);
- clearFlg = false;
- } else {
- ++nBits;
- if (nBits == maxbits) {
- maxcode = maxmaxcode;
- } else {
- maxcode = maxcode(nBits);
- }
- }
- }
-
- if (code == eOFCode) {
- // At EOF, write the rest of the buffer.
- while (curBits > 0) {
- charOut((byte) (curAccum & 0xff), outs);
- curAccum >>= 8;
- curBits -= 8;
- }
-
- flushChar(outs);
- }
- }
-}
Deleted:
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/NeuQuant.java
===================================================================
---
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/NeuQuant.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/ajax4jsf/resource/image/animatedgif/NeuQuant.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -1,519 +0,0 @@
-/* NeuQuant Neural-Net Quantization Algorithm
- * ------------------------------------------
- *
- * Copyright (c) 1994 Anthony Dekker
- *
- * NEUQUANT Neural-Net quantization algorithm by Anthony Dekker, 1994.
- * See "Kohonen neural networks for optimal colour quantization"
- * in "Network: Computation in Neural Systems" Vol. 5 (1994) pp 351-367.
- * for a discussion of the algorithm.
- *
- * Any party obtaining a copy of these files from the author, directly or
- * indirectly, is granted, free of charge, a full and unrestricted irrevocable,
- * world-wide, paid up, royalty-free, nonexclusive right and license to deal
- * in this software and documentation files (the "Software"), including
without
- * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons who receive
- * copies from any such party to do so, with the only requirement being
- * that this copyright notice remain intact.
- */
-package org.ajax4jsf.resource.image.animatedgif;
-
-// Ported to Java 12/00 K Weiner
-
-public class NeuQuant {
-
- protected static final int NETSIZE = 256; /* number of colours used */
-
- /* four primes near 500 - assume no image has a length so large */
- /* that it is divisible by all four primes */
- protected static final int PRIME1 = 499;
- protected static final int PRIME2 = 491;
- protected static final int PRIME3 = 487;
- protected static final int PRIME4 = 503;
-
- protected static final int MINPICTUREBYTES = (3 * PRIME4);
- /* minimum size for input image */
-
- /* Program Skeleton
- ----------------
- [select samplefac in range 1..30]
- [read image from input file]
- pic = (unsigned char*) malloc(3*width*height);
- initnet(pic,3*width*height,samplefac);
- learn();
- unbiasnet();
- [write output image header, using writecolourmap(f)]
- inxbuild();
- write output image using inxsearch(b,g,r) */
-
- /* Network Definitions
- ------------------- */
-
- protected static final int MAXNETPOS = (NETSIZE - 1);
- protected static final int NETBIASSHIFT = 4; /* bias for colour values */
- protected static final int NCYCLES = 100; /* no. of learning cycles */
-
- /* defs for freq and bias */
- protected static final int INTBIASSHIFT = 16; /* bias for fractions */
- protected static final int INTBIAS = (((int) 1) << INTBIASSHIFT);
- protected static final int GAMMASHIFT = 10; /* gamma = 1024 */
- protected static final int GAMMA = (((int) 1) << GAMMASHIFT);
- protected static final int BETASHIFT = 10;
- protected static final int BETA = (INTBIAS >> BETASHIFT); /* beta = 1/1024 */
- protected static final int BETAGAMMA =
- (INTBIAS << (GAMMASHIFT - BETASHIFT));
-
- /* defs for decreasing radius factor */
- protected static final int INITRAD = (NETSIZE >> 3); /* for 256 cols, radius
starts */
- protected static final int RADIUSBIASSHIFT = 6; /* at 32.0 biased by 6 bits */
- protected static final int RADIUSBIAS = (((int) 1) << RADIUSBIASSHIFT);
- protected static final int INITRADIUS = (INITRAD * RADIUSBIAS); /* and decreases by a
*/
- protected static final int RADIUSDEC = 30; /* factor of 1/30 each cycle */
-
- /* defs for decreasing alpha factor */
- protected static final int ALPHABIASSHIFT = 10; /* alpha starts at 1.0 */
- protected static final int INITALPHA = (((int) 1) << ALPHABIASSHIFT);
-
- protected static final int RADBIASSHIFT = 8;
- protected static final int RADBIAS = (((int) 1) << RADBIASSHIFT);
- protected static final int ALPHARADBSHIFT = (ALPHABIASSHIFT + RADBIASSHIFT);
- protected static final int ALPHARADBIAS = (((int) 1) << ALPHARADBSHIFT);
-
- protected int alphadec; /* biased by 10 bits */
-
- /* radbias and alpharadbias used for radpower calculation */
-
-
- /* Types and Global Variables
- -------------------------- */
-
- protected byte[] thepicture; /* the input image itself */
- protected int lengthcount; /* lengthcount = H*W*3 */
-
- protected int samplefac; /* sampling factor 1..30 */
-
- // typedef int pixel[4]; /* BGRc */
- protected int[][] network; /* the network itself - [netsize][4] */
-
- protected int[] netindex = new int[256];
- /* for network lookup - really 256 */
-
- protected int[] bias = new int[NETSIZE];
- /* bias and freq arrays for learning */
- protected int[] freq = new int[NETSIZE];
- protected int[] radpower = new int[INITRAD];
- /* radpower for precomputation */
-
- /* Initialise network in range (0,0,0) to (255,255,255) and set parameters
- ----------------------------------------------------------------------- */
- public NeuQuant(byte[] thepic, int len, int sample) {
-
- int i;
- int[] p;
-
- thepicture = thepic;
- lengthcount = len;
- samplefac = sample;
-
- network = new int[NETSIZE][];
- for (i = 0; i < NETSIZE; i++) {
- network[i] = new int[4];
- p = network[i];
- p[0] = (i << (NETBIASSHIFT + 8)) / NETSIZE;
- p[1] = (i << (NETBIASSHIFT + 8)) / NETSIZE;
- p[2] = (i << (NETBIASSHIFT + 8)) / NETSIZE;
- freq[i] = INTBIAS / NETSIZE; /* 1/netsize */
- bias[i] = 0;
- }
- }
-
- public byte[] colorMap() {
- byte[] map = new byte[3 * NETSIZE];
- int[] index = new int[NETSIZE];
- for (int i = 0; i < NETSIZE; i++) {
- index[network[i][3]] = i;
- }
- int k = 0;
- for (int i = 0; i < NETSIZE; i++) {
- int j = index[i];
- map[k++] = (byte) (network[j][0]);
- map[k++] = (byte) (network[j][1]);
- map[k++] = (byte) (network[j][2]);
- }
- return map;
- }
-
- /* Insertion sort of network and building of netindex[0..255] (to do after unbias)
- -------------------------------------------------------------------------------
*/
- public void inxbuild() {
-
- int i;
- int j;
- int smallpos;
- int smallval;
- int[] p;
- int[] q;
- int previouscol;
- int startpos;
-
- previouscol = 0;
- startpos = 0;
- for (i = 0; i < NETSIZE; i++) {
- p = network[i];
- smallpos = i;
- smallval = p[1]; /* index on g */
- /* find smallest in i..netsize-1 */
- for (j = i + 1; j < NETSIZE; j++) {
- q = network[j];
- if (q[1] < smallval) { /* index on g */
- smallpos = j;
- smallval = q[1]; /* index on g */
- }
- }
- q = network[smallpos];
- /* swap p (i) and q (smallpos) entries */
- if (i != smallpos) {
- j = q[0];
- q[0] = p[0];
- p[0] = j;
- j = q[1];
- q[1] = p[1];
- p[1] = j;
- j = q[2];
- q[2] = p[2];
- p[2] = j;
- j = q[3];
- q[3] = p[3];
- p[3] = j;
- }
- /* smallval entry is now in position i */
- if (smallval != previouscol) {
- netindex[previouscol] = (startpos + i) >> 1;
- for (j = previouscol + 1; j < smallval; j++) {
- netindex[j] = i;
- }
- previouscol = smallval;
- startpos = i;
- }
- }
- netindex[previouscol] = (startpos + MAXNETPOS) >> 1;
- for (j = previouscol + 1; j < 256; j++) {
- netindex[j] = MAXNETPOS; /* really 256 */
- }
- }
-
- /* Main Learning Loop
- ------------------ */
- public void learn() {
-
- int i;
- int j;
- int b;
- int g;
- int r;
- int radius;
- int rad;
- int alpha;
- int step;
- int delta;
- int samplepixels;
- byte[] p;
- int pix;
- int lim;
-
- if (lengthcount < MINPICTUREBYTES){
- samplefac = 1;
- }
-
- alphadec = 30 + ((samplefac - 1) / 3);
- p = thepicture;
- pix = 0;
- lim = lengthcount;
- samplepixels = lengthcount / (3 * samplefac);
- delta = samplepixels / NCYCLES;
- alpha = INITALPHA;
- radius = INITRADIUS;
-
- rad = radius >> RADIUSBIASSHIFT;
- if (rad <= 1) {
- rad = 0;
- }
- for (i = 0; i < rad; i++) {
- radpower[i] =
- alpha * (((rad * rad - i * i) * RADBIAS) / (rad * rad));
- }
-
- //fprintf(stderr,"beginning 1D learning: initial radius=%d\n", rad);
-
- if (lengthcount < MINPICTUREBYTES) {
- step = 3;
- } else if ((lengthcount % PRIME1) != 0) {
- step = 3 * PRIME1;
- } else {
- if ((lengthcount % PRIME2) != 0) {
- step = 3 * PRIME2;
- } else {
- if ((lengthcount % PRIME3) != 0) {
- step = 3 * PRIME3;
- } else {
- step = 3 * PRIME4;
- }
- }
- }
-
- i = 0;
- while (i < samplepixels) {
- b = (p[pix + 0] & 0xff) << NETBIASSHIFT;
- g = (p[pix + 1] & 0xff) << NETBIASSHIFT;
- r = (p[pix + 2] & 0xff) << NETBIASSHIFT;
- j = contest(b, g, r);
-
- altersingle(alpha, j, b, g, r);
- if (rad != 0) {
- alterneigh(rad, j, b, g, r); /* alter neighbours */
- }
-
- pix += step;
- if (pix >= lim) {
- pix -= lengthcount;
- }
-
- i++;
- if (delta == 0) {
- delta = 1;
- }
- if (i % delta == 0) {
- alpha -= alpha / alphadec;
- radius -= radius / RADIUSDEC;
- rad = radius >> RADIUSBIASSHIFT;
- if (rad <= 1) {
- rad = 0;
- }
- for (j = 0; j < rad; j++) {
- radpower[j] =
- alpha * (((rad * rad - j * j) * RADBIAS) / (rad * rad));
- }
- }
- }
- //fprintf(stderr,"finished 1D learning: final alpha=%f
!\n",((float)alpha)/initalpha);
- }
-
- /* Search for BGR values 0..255 (after net is unbiased) and return colour index
- ---------------------------------------------------------------------------- */
- public int map(int b, int g, int r) {
-
- int i;
- int j;
- int dist;
- int a;
- int bestd;
- int[] p;
- int best;
-
- bestd = 1000; /* biggest possible dist is 256*3 */
- best = -1;
- i = netindex[g]; /* index on g */
- j = i - 1; /* start at netindex[g] and work outwards */
-
- while ((i < NETSIZE) || (j >= 0)) {
- if (i < NETSIZE) {
- p = network[i];
- dist = p[1] - g; /* inx key */
- if (dist >= bestd) {
- i = NETSIZE; /* stop iter */
- } else {
- i++;
- if (dist < 0) {
- dist = -dist;
- }
- a = p[0] - b;
- if (a < 0) {
- a = -a;
- }
- dist += a;
- if (dist < bestd) {
- a = p[2] - r;
- if (a < 0) {
- a = -a;
- }
- dist += a;
- if (dist < bestd) {
- bestd = dist;
- best = p[3];
- }
- }
- }
- }
- if (j >= 0) {
- p = network[j];
- dist = g - p[1]; /* inx key - reverse dif */
- if (dist >= bestd) {
- j = -1; /* stop iter */
- } else {
- j--;
- if (dist < 0) {
- dist = -dist;
- }
- a = p[0] - b;
- if (a < 0) {
- a = -a;
- }
- dist += a;
- if (dist < bestd) {
- a = p[2] - r;
- if (a < 0) {
- a = -a;
- }
- dist += a;
- if (dist < bestd) {
- bestd = dist;
- best = p[3];
- }
- }
- }
- }
- }
- return (best);
- }
- public byte[] process() {
- learn();
- unbiasnet();
- inxbuild();
- return colorMap();
- }
-
- /* Unbias network to give byte values 0..255 and record position i to prepare for
sort
-
----------------------------------------------------------------------------------- */
- public void unbiasnet() {
-
- int i;
- int j;
-
- for (i = 0; i < NETSIZE; i++) {
- network[i][0] >>= NETBIASSHIFT;
- network[i][1] >>= NETBIASSHIFT;
- network[i][2] >>= NETBIASSHIFT;
- network[i][3] = i; /* record colour no */
- }
- }
-
- /* Move adjacent neurons by precomputed alpha*(1-((i-j)^2/[r]^2)) in radpower[|i-j|]
- ---------------------------------------------------------------------------------
*/
- protected void alterneigh(int rad, int i, int b, int g, int r) {
-
- int j;
- int k;
- int lo;
- int hi;
- int a;
- int m;
- int[] p;
-
- lo = i - rad;
- if (lo < -1) {
- lo = -1;
- }
- hi = i + rad;
- if (hi > NETSIZE) {
- hi = NETSIZE;
- }
-
- j = i + 1;
- k = i - 1;
- m = 1;
- while ((j < hi) || (k > lo)) {
- a = radpower[m++];
- if (j < hi) {
- p = network[j++];
- try {
- p[0] -= (a * (p[0] - b)) / ALPHARADBIAS;
- p[1] -= (a * (p[1] - g)) / ALPHARADBIAS;
- p[2] -= (a * (p[2] - r)) / ALPHARADBIAS;
- } catch (Exception e) {
- e.printStackTrace();
- } // prevents 1.3 miscompilation
- }
- if (k > lo) {
- p = network[k--];
- try {
- p[0] -= (a * (p[0] - b)) / ALPHARADBIAS;
- p[1] -= (a * (p[1] - g)) / ALPHARADBIAS;
- p[2] -= (a * (p[2] - r)) / ALPHARADBIAS;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- /* Move neuron i towards biased (b,g,r) by factor alpha
- ---------------------------------------------------- */
- protected void altersingle(int alpha, int i, int b, int g, int r) {
-
- /* alter hit neuron */
- int[] n = network[i];
- n[0] -= (alpha * (n[0] - b)) / INITALPHA;
- n[1] -= (alpha * (n[1] - g)) / INITALPHA;
- n[2] -= (alpha * (n[2] - r)) / INITALPHA;
- }
-
- /* Search for biased BGR values
- ---------------------------- */
- protected int contest(int b, int g, int r) {
-
- /* finds closest neuron (min dist) and updates freq */
- /* finds best neuron (min dist-bias) and returns position */
- /* for frequently chosen neurons, freq[i] is high and bias[i] is negative */
- /* bias[i] = gamma*((1/netsize)-freq[i]) */
-
- int i;
- int dist;
- int a;
- int biasdist;
- int betafreq;
- int bestpos;
- int bestbiaspos;
- int bestd;
- int bestbiasd;
- int[] n;
-
- bestd = ~(((int) 1) << 31);
- bestbiasd = bestd;
- bestpos = -1;
- bestbiaspos = bestpos;
-
- for (i = 0; i < NETSIZE; i++) {
- n = network[i];
- dist = n[0] - b;
- if (dist < 0) {
- dist = -dist;
- }
- a = n[1] - g;
- if (a < 0) {
- a = -a;
- }
- dist += a;
- a = n[2] - r;
- if (a < 0) {
- a = -a;
- }
- dist += a;
- if (dist < bestd) {
- bestd = dist;
- bestpos = i;
- }
- biasdist = dist - ((bias[i]) >> (INTBIASSHIFT - NETBIASSHIFT));
- if (biasdist < bestbiasd) {
- bestbiasd = biasdist;
- bestbiaspos = i;
- }
- betafreq = (freq[i] >> BETASHIFT);
- freq[i] -= betafreq;
- bias[i] += (betafreq << GAMMASHIFT);
- }
- freq[bestpos] += BETA;
- bias[bestpos] -= BETAGAMMA;
- return (bestbiaspos);
- }
-}
Modified: trunk/core/impl/src/main/java/org/richfaces/VersionBean.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/VersionBean.java 2010-11-08 15:56:04 UTC
(rev 19994)
+++ trunk/core/impl/src/main/java/org/richfaces/VersionBean.java 2010-11-08 23:06:12 UTC
(rev 19995)
@@ -74,8 +74,6 @@
private String fullVersionString = UNKNOWN;
- private String resourceVersion = UNKNOWN;
-
private boolean containsDataFromManifest = false;
public Version() {
@@ -118,7 +116,6 @@
private void initializeDerivativeProperties() {
fullVersionString = MessageFormat.format("v.{0} SVN r.{1}",
implementationVersion, scmRevision);
- resourceVersion = implementationVersion.replace('.', '_');
}
private Manifest readManifest() {
@@ -194,10 +191,6 @@
return fullVersionString;
}
- public String getResourceVersion() {
- return resourceVersion;
- }
-
public String getImplementationTitle() {
return implementationTitle;
}
Modified: trunk/core/impl/src/main/java/org/richfaces/application/CoreConfiguration.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/application/CoreConfiguration.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/application/CoreConfiguration.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -62,6 +62,9 @@
@ConfigurationItem(defaultValue = "512", names =
RESOURCES_CACHE_SIZE_PARAM_NAME, literal = true)
resourcesCacheSize,
+
+ @ConfigurationItem(names = "org.richfaces.resourceDefaultVersion")
+ resourcesDefaultVersion,
@ConfigurationItem(names = "org.ajax4jsf.cache.LRU_MAP_CACHE_SIZE",
literal = true)
lruMapCacheSize,
@@ -82,6 +85,7 @@
pushJMSConnectionUsername,
@ConfigurationItem(defaultValue = "", names =
"org.richfaces.push.jms.connectionPassword")
- pushJMSConnectionPassword
+ pushJMSConnectionPassword
+
}
}
Modified: trunk/core/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -31,21 +31,16 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import java.util.Date;
-import java.util.Map;
import javax.faces.context.FacesContext;
-import org.richfaces.VersionBean;
import org.richfaces.renderkit.html.images.GradientType;
import org.richfaces.renderkit.html.images.GradientType.BiColor;
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.resource.ImageType;
-import org.richfaces.resource.Java2DUserResource;
+import org.richfaces.resource.AbstractJava2DUserResource;
+import org.richfaces.resource.DynamicUserResource;
import org.richfaces.resource.PostConstructResource;
import org.richfaces.resource.ResourceParameter;
import org.richfaces.resource.StateHolderResource;
-import org.richfaces.resource.VersionedResource;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
@@ -53,8 +48,8 @@
* @author Nick Belaevski - nbelaevski(a)exadel.com
* created 02.02.2007
*/
-@DynamicResource
-public class BaseGradient implements Java2DUserResource, StateHolderResource,
VersionedResource {
+@DynamicUserResource
+public class BaseGradient extends AbstractJava2DUserResource implements
StateHolderResource {
protected Integer headerBackgroundColor;
protected Integer headerGradientColor;
@@ -69,6 +64,9 @@
public BaseGradient(int width, int height, int gradientHeight, String baseColor,
String gradientColor,
boolean horizontal) {
+
+ super(null);
+
this.setWidth(width);
this.setHeight(height);
this.setGradientHeight(gradientHeight);
@@ -225,7 +223,7 @@
}
}
- public void paint(Graphics2D graphics2d, Dimension dimension) {
+ public void paint(Graphics2D graphics2d) {
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
@@ -234,7 +232,7 @@
graphics2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
graphics2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
- paintGradient(graphics2d, dimension);
+ paintGradient(graphics2d, getDimension());
}
/**
@@ -301,24 +299,8 @@
dataOutput.writeByte((byte) this.gradientType.ordinal());
}
- public Map<String, String> getResponseHeaders() {
- return null;
- }
-
- public Date getLastModified() {
- return null;
- }
-
- public ImageType getImageType() {
- return ImageType.PNG;
- }
-
public boolean isTransient() {
return false;
}
- public String getVersion() {
- return VersionBean.VERSION.getResourceVersion();
- }
-
}
Deleted:
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -1,252 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.renderkit.html;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.GradientPaint;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.resource.Java2Dresource;
-import org.richfaces.renderkit.html.images.GradientAlignment;
-import org.richfaces.renderkit.html.images.GradientType;
-import org.richfaces.renderkit.html.images.GradientType.BiColor;
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.resource.ImageType;
-import org.richfaces.skin.Skin;
-
-/**
- * @author Nick Belaevski - nbelaevski(a)exadel.com
- * created 02.02.2007
- */
-@DynamicResource
-public abstract class CustomizeableGradient extends Java2Dresource {
-
- private static final String BASE_COLOR = "baseColor";
-
- private static final String GRADIENT_COLOR = "gradientColor";
-
- protected Dimension dimension = new Dimension(20, 500);
-
- protected Integer gradientColor;
- protected Integer baseColor;
- protected Integer gradientHeight = 22;
-
- protected GradientType gradientType;
- protected GradientAlignment gradientAlignment;
-
- public CustomizeableGradient() {
- super(ImageType.PNG);
- }
-
-// @Override
-// public void populateParameters(Map<String, String> parameters){
-// if(parameters.containsKey(GRADIENT_COLOR)){
-// String gradientColorValue =
encodeSkinParameter(parameters.get(GRADIENT_COLOR));
-// this.gradientColor = decodeColor(gradientColorValue);
-// }
-// if(parameters.containsKey(BASE_COLOR)){
-// String baseColorValue = encodeSkinParameter(parameters.get(BASE_COLOR));
-// this.baseColor = decodeColor(baseColorValue);
-// }
-// }
-
- public Dimension getDimension() {
- return dimension;
- }
-
- private void drawRectangle(Graphics2D g2d, Rectangle2D rect, BiColor biColor, boolean
useTop) {
- if (biColor != null) {
- Color color = useTop ? biColor.getTopColor() : biColor.getBottomColor();
- g2d.setColor(color);
- g2d.fill(rect);
- }
- }
-
- private void drawGradient(Graphics2D g2d, Rectangle2D rectangle, BiColor colors, int
height) {
- if (colors != null) {
- GradientPaint gragient = new GradientPaint(0, 0, colors.getTopColor(), 0,
height, colors.getBottomColor());
- g2d.setPaint(gragient);
- g2d.fill(rectangle);
- }
- }
-
- protected void paint(Graphics2D g2d, Dimension dim) {
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
-
- g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
-
- if ((gradientColor != null || baseColor != null) && gradientType != null
- && gradientAlignment != null) {
-
- paintGradient(g2d, dim);
- }
- }
-
- protected void paintGradient(Graphics2D g2d, Dimension dim) {
- BiColor biColor = new GradientType.BiColor(gradientColor, baseColor);
- BiColor firstLayer = gradientType.getFirstLayerColors(biColor);
- BiColor secondLayer = gradientType.getSecondLayerColors(biColor);
-
- Rectangle2D rect =
- new Rectangle2D.Float(
- 0,
- 0,
- dim.width,
- dim.height);
-
- int topRectangleHeight = gradientAlignment.getTopRectangleHeight(dim.height,
gradientHeight);
- int bottomRectangleHeight =
gradientAlignment.getBottomRectangleHeight(dim.height, gradientHeight);
-
- rect = new Rectangle2D.Float(
- 0,
- 0,
- dim.width,
- topRectangleHeight);
-
- drawRectangle(g2d, rect, firstLayer, true);
- drawRectangle(g2d, rect, secondLayer, true);
-
- rect = new Rectangle2D.Float(
- 0,
- dim.height - bottomRectangleHeight,
- dim.width,
- dim.height);
-
- drawRectangle(g2d, rect, firstLayer, false);
- drawRectangle(g2d, rect, secondLayer, false);
-
- g2d.transform(AffineTransform.getTranslateInstance(0, topRectangleHeight));
-
- rect = new Rectangle2D.Float(
- 0,
- 0,
- dim.width,
- dim.height);
-
- drawGradient(g2d, rect, firstLayer, gradientHeight);
-
- rect = new Rectangle2D.Float(
- 0,
- 0,
- dim.width,
- gradientHeight / 2);
-
- drawGradient(g2d, rect, secondLayer, gradientHeight / 2);
- }
-
- @Override
- public void readState(FacesContext context, DataInput dataInput) throws IOException
{
- super.readState(context, dataInput);
-
- this.baseColor = dataInput.readInt();
- this.gradientColor = dataInput.readInt();
- this.gradientHeight = dataInput.readInt();
- this.gradientAlignment = GradientAlignment.values()[dataInput.readByte()];
- this.gradientType = GradientType.values()[dataInput.readByte()];
- }
-
- @Override
- public void writeState(FacesContext context, DataOutput dataOutput) throws
IOException {
- super.writeState(context, dataOutput);
-
- dataOutput.writeInt(this.baseColor);
- dataOutput.writeInt(this.gradientColor);
- dataOutput.writeInt(this.gradientHeight);
- dataOutput.writeByte((byte) this.gradientAlignment.ordinal());
-
- String gradientTypeString =
safeTrim(getValueParameter(FacesContext.getCurrentInstance(), Skin.GRADIENT_TYPE));
- if (gradientTypeString != null && gradientTypeString.length() != 0) {
- gradientType = GradientType.getByParameter(gradientTypeString);
- }
-
- dataOutput.writeByte((byte) this.gradientType.ordinal());
- }
-
- protected static String safeTrim(String s) {
- return s != null ? s.trim() : null;
- }
-
- public boolean isCacheable() {
- return true;
- }
-
- public Integer getGradientColor() {
- return gradientColor;
- }
-
- public void setGradientColor(Integer headerBackgroundColor) {
- this.gradientColor = headerBackgroundColor;
- }
-
- public void setGradientColorString(String colorString) {
- setGradientColor(decodeColor(colorString));
- }
-
- public Integer getBaseColor() {
- return baseColor;
- }
-
- public void setBaseColor(Integer headerGradientColor) {
- this.baseColor = headerGradientColor;
- }
-
- public void setBaseColorString(String colorString) {
- setBaseColor(decodeColor(colorString));
- }
-
- public GradientType getGradientType() {
- return gradientType;
- }
-
- public void setGradientType(GradientType gradientType) {
- this.gradientType = gradientType;
- }
-
- public GradientAlignment getGradientAlignment() {
- return gradientAlignment;
- }
-
- public void setGradientAlignment(GradientAlignment gradientAlignment) {
- this.gradientAlignment = gradientAlignment;
- }
-
- public Integer getGradientHeight() {
- return gradientHeight;
- }
-
- public void setGradientHeight(Integer gradientHeight) {
- this.gradientHeight = gradientHeight;
- }
-
-}
Modified:
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/images/InputErrorIcon.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/images/InputErrorIcon.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/images/InputErrorIcon.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -28,16 +28,11 @@
private static final Dimension DIMENSION = new Dimension(6, 11);
public InputErrorIcon() {
- super("warningColor");
+ super(DIMENSION, "warningColor");
}
@Override
- public Dimension getDimension() {
- return DIMENSION;
- }
-
- @Override
- public void paint(Graphics2D g2d, Dimension dimension) {
+ public void paint(Graphics2D g2d) {
g2d.setColor(getBasicColor());
g2d.fillRect(3, 2, 2, 6);
g2d.fillRect(3, 9, 2, 2);
Modified:
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -27,27 +27,25 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import java.util.Date;
-import java.util.Map;
import javax.faces.context.FacesContext;
-import org.richfaces.resource.CacheableResource;
-import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.AbstractJava2DUserResource;
+import org.richfaces.resource.DynamicUserResource;
import org.richfaces.resource.ImageType;
-import org.richfaces.resource.Java2DUserResource;
import org.richfaces.resource.StateHolderResource;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
-@DynamicResource
-public abstract class OneColorBasedResource implements Java2DUserResource,
CacheableResource, StateHolderResource {
+@DynamicUserResource
+public abstract class OneColorBasedResource extends AbstractJava2DUserResource implements
StateHolderResource {
private String basicColorParamName;
private Color basicColor;
- public OneColorBasedResource(final String basicColorParamName) {
+ public OneColorBasedResource(Dimension dimension, final String basicColorParamName)
{
+ super(ImageType.GIF, dimension);
this.basicColorParamName = basicColorParamName;
}
@@ -72,35 +70,5 @@
basicColor = new Color(dataInput.readInt());
}
- public boolean isCacheable(FacesContext context) {
- return true;
- }
-
- public Date getExpires(FacesContext context) {
- return null;
- }
-
- public int getTimeToLive(FacesContext context) {
- return 0;
- }
-
- public String getEntityTag(FacesContext context) {
- return null;
- }
-
- public Map<String, String> getResponseHeaders() {
- return null;
- }
-
- public Date getLastModified() {
- return null;
- }
-
- public ImageType getImageType() {
- return ImageType.GIF;
- }
-
- public abstract Dimension getDimension();
-
- public abstract void paint(Graphics2D graphics2d, Dimension dimension);
+ public abstract void paint(Graphics2D graphics2d);
}
Modified: trunk/core/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -21,6 +21,9 @@
*/
package org.richfaces.resource;
+import static org.richfaces.application.CoreConfiguration.Items.resourcesDefaultVersion;
+import static
org.richfaces.application.configuration.ConfigurationServiceHelper.getStringConfigurationValue;
+
import java.util.Date;
import java.util.Map;
@@ -39,9 +42,16 @@
private T resourceObject;
- public BaseResourceWrapper(T resourceObject) {
+ private boolean cacheable;
+
+ private boolean versioned;
+
+ public BaseResourceWrapper(T resourceObject, boolean cacheable, boolean versioned) {
super();
+
this.resourceObject = resourceObject;
+ this.cacheable = cacheable;
+ this.versioned = versioned;
}
protected abstract Map<String, String> getWrappedResourceResponseHeaders();
@@ -58,11 +68,30 @@
return headers;
}
+ private String getPackageVersion() {
+ Package pkg = resourceObject.getClass().getPackage();
+
+ if (pkg != null) {
+ return pkg.getImplementationVersion();
+ }
+
+ return null;
+ }
+
public String getVersion() {
if (resourceObject instanceof VersionedResource) {
return ((VersionedResource) resourceObject).getVersion();
}
+ if (versioned) {
+ String packageVersion = getPackageVersion();
+ if (packageVersion != null) {
+ return packageVersion;
+ }
+
+ return getStringConfigurationValue(FacesContext.getCurrentInstance(),
resourcesDefaultVersion);
+ }
+
return null;
}
@@ -72,7 +101,7 @@
return ((CacheableResource) resourceObject).isCacheable(context);
}
- return false;
+ return cacheable;
}
@Override
Modified:
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DAnimatedUserResourceWrapperImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DAnimatedUserResourceWrapperImpl.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DAnimatedUserResourceWrapperImpl.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -45,8 +45,8 @@
*/
public class Java2DAnimatedUserResourceWrapperImpl extends Java2DUserResourceWrapperImpl
{
- public Java2DAnimatedUserResourceWrapperImpl(Java2DAnimatedUserResource
resourceObject) {
- super(resourceObject);
+ public Java2DAnimatedUserResourceWrapperImpl(Java2DAnimatedUserResource
resourceObject, boolean cacheable, boolean versioned) {
+ super(resourceObject, cacheable, versioned);
}
private static ImageWriter getSequenceCapableImageWriter(ImageType imageType) {
@@ -142,7 +142,7 @@
Graphics2D g2d = null;
try {
g2d = createGraphics(image);
- userResource.paint(g2d, dimension);
+ userResource.paint(g2d);
imageWriter.writeToSequence(new IIOImage(image, null,
imageMetaData),
defaultImageWriteParam);
} finally {
Modified:
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -21,7 +21,6 @@
*/
package org.richfaces.resource;
-import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
@@ -48,8 +47,8 @@
public class Java2DUserResourceWrapperImpl extends
BaseResourceWrapper<Java2DUserResource>
implements Java2DUserResourceWrapper {
- public Java2DUserResourceWrapperImpl(Java2DUserResource resourceObject) {
- super(resourceObject);
+ public Java2DUserResourceWrapperImpl(Java2DUserResource resourceObject, boolean
cacheable, boolean versioned) {
+ super(resourceObject, cacheable, versioned);
}
public InputStream getInputStream() throws IOException {
@@ -146,7 +145,7 @@
Graphics2D g2d = null;
try {
g2d = createGraphics(image);
- resource.paint(g2d, new Dimension(image.getWidth(), image.getHeight()));
+ resource.paint(g2d);
ImageIO.write(image, imageType.getFormatName(), outputStream);
} finally {
if (g2d != null) {
Modified: trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -207,6 +207,92 @@
}
}
+ private Resource createDynamicUserResourceInstance(Class<?> loadedClass) throws
Exception, LinkageError {
+ String resourceName = loadedClass.getName();
+
+ boolean checkResult = false;
+ boolean cacheable = false;
+ boolean versioned = false;
+
+ DynamicUserResource dynamicUserResource =
loadedClass.getAnnotation(DynamicUserResource.class);
+
+ if (dynamicUserResource != null) {
+ cacheable = dynamicUserResource.cacheable();
+ versioned = dynamicUserResource.versioned();
+ checkResult = true;
+
+ LOGGER.debug(MessageFormat.format("Dynamic resource annotation is
present on resource class {0}",
+ resourceName));
+ }
+
+ if (!checkResult) {
+ DynamicResource dynamicResource =
loadedClass.getAnnotation(DynamicResource.class);
+ if (dynamicResource != null) {
+ LOGGER.debug(MessageFormat.format("Dynamic resource annotation is
present on resource class {0}",
+ resourceName));
+
+ checkResult = true;
+ }
+ }
+
+ if (!checkResult) {
+ LOGGER.debug(MessageFormat.format("Dynamic resource annotation is not
present on resource class {0}",
+ resourceName));
+
+ checkResult = checkResourceMarker(resourceName);
+ }
+
+ if (!checkResult) {
+ return null;
+ }
+
+ BaseResourceWrapper<?> result = null;
+
+ if (Java2DAnimatedUserResource.class.isAssignableFrom(loadedClass)) {
+ Java2DAnimatedUserResource java2DAnimatedUserResource =
(Java2DAnimatedUserResource) loadedClass.newInstance();
+ result = new
Java2DAnimatedUserResourceWrapperImpl(java2DAnimatedUserResource, cacheable, versioned);
+ } else if (Java2DUserResource.class.isAssignableFrom(loadedClass)) {
+ Java2DUserResource java2DUserResource = (Java2DUserResource)
loadedClass.newInstance();
+ result = new Java2DUserResourceWrapperImpl(java2DUserResource, cacheable,
versioned);
+ } else if (UserResource.class.isAssignableFrom(loadedClass)) {
+ UserResource userResource = (UserResource) loadedClass.newInstance();
+ result = new UserResourceWrapperImpl(userResource, cacheable, versioned);
+ }
+
+ return result;
+ }
+
+ private Resource createDynamicResourceInstance(Class<?> loadedClass) throws
Exception, LinkageError {
+ String resourceName = loadedClass.getName();
+
+ boolean checkResult = false;
+
+ DynamicResource annotation = loadedClass.getAnnotation(DynamicResource.class);
+
+ if (annotation != null) {
+ LOGGER.debug(MessageFormat.format("Dynamic resource annotation is
present on resource class {0}",
+ resourceName));
+
+ checkResult = true;
+ } else {
+ LOGGER.debug(MessageFormat.format(
+ "Dynamic resource annotation is not present on resource class
{0}", resourceName));
+ }
+
+ if (!checkResult) {
+ checkResult = checkResourceMarker(resourceName);
+ }
+
+ if (!checkResult) {
+ return null;
+ }
+
+ Class<? extends Resource> resourceClass =
loadedClass.asSubclass(Resource.class);
+ Resource result = (Resource) resourceClass.newInstance();
+
+ return result;
+ }
+
/**
* Should be called only if {@link #isResourceExists(String)} returns
<code>true</code>
*
@@ -227,62 +313,25 @@
if (contextClassLoader != null) {
try {
Class<?> loadedClass = Class.forName(resourceName, false,
contextClassLoader);
-
- boolean legitimateResource = false;
-
- DynamicResource annotation =
loadedClass.getAnnotation(DynamicResource.class);
- legitimateResource = (annotation != null);
- if (legitimateResource) {
- LOGGER.debug(MessageFormat.format("Dynamic resource annotation
is present on resource class {0}",
- resourceName));
- } else {
- LOGGER.debug(MessageFormat.format(
- "Dynamic resource annotation is not present on resource
class {0}", resourceName));
+
+ resource = createDynamicUserResourceInstance(loadedClass);
+ if (resource == null) {
+ resource = createDynamicResourceInstance(loadedClass);
}
+
+ if (resource != null) {
+ resource.setResourceName(resourceName);
- if (!legitimateResource) {
- // TODO resource marker extension name?
- URL resourceMarkerUrl =
contextClassLoader.getResource("META-INF/" + resourceName
- + ".resource.properties");
-
- legitimateResource = resourceMarkerUrl != null;
-
- if (LOGGER.isDebugEnabled()) {
- if (legitimateResource) {
- LOGGER.debug(MessageFormat.format("Marker file for {0}
resource found in classpath",
- resourceName));
+ if (parameters != null) {
+ if (resource instanceof BaseResourceWrapper<?>) {
+ BaseResourceWrapper<?> baseResourceWrapper =
(BaseResourceWrapper<?>) resource;
+
+ injectProperties(baseResourceWrapper.getWrapped(),
parameters);
} else {
- LOGGER.debug(MessageFormat.format("Marker file for {0}
resource does not exist",
- resourceName));
+ injectProperties(resource, parameters);
}
}
- }
- if (legitimateResource) {
- Object wrappedResource;
- if (Java2DAnimatedUserResource.class.isAssignableFrom(loadedClass))
{
- Java2DAnimatedUserResource java2DAnimatedUserResource =
(Java2DAnimatedUserResource) loadedClass.newInstance();
- wrappedResource = java2DAnimatedUserResource;
- resource = new
Java2DAnimatedUserResourceWrapperImpl(java2DAnimatedUserResource);
- } else if (Java2DUserResource.class.isAssignableFrom(loadedClass)) {
- Java2DUserResource java2DUserResource = (Java2DUserResource)
loadedClass.newInstance();
- wrappedResource = java2DUserResource;
- resource = new
Java2DUserResourceWrapperImpl(java2DUserResource);
- } else if (UserResource.class.isAssignableFrom(loadedClass)) {
- UserResource userResource = (UserResource)
loadedClass.newInstance();
- wrappedResource = userResource;
- resource = new UserResourceWrapperImpl(userResource);
- } else {
- Class<? extends Resource> resourceClass =
loadedClass.asSubclass(Resource.class);
- resource = (Resource) resourceClass.newInstance();
- wrappedResource = resource;
- }
-
- if (parameters != null) {
- injectProperties(wrappedResource, parameters);
- }
-
- resource.setResourceName(resourceName);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(MessageFormat
.format("Successfully created instance of {0}
resource", resourceName));
@@ -302,6 +351,27 @@
return resource;
}
+ private boolean checkResourceMarker(String resourceName) {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+
+ // TODO resource marker extension name?
+ URL resourceMarkerUrl = contextClassLoader.getResource("META-INF/" +
resourceName
+ + ".resource.properties");
+
+ boolean result = (resourceMarkerUrl != null);
+
+ if (LOGGER.isDebugEnabled()) {
+ if (result) {
+ LOGGER.debug(MessageFormat.format("Marker file for {0} resource
found in classpath",
+ resourceName));
+ } else {
+ LOGGER.debug(MessageFormat.format("Marker file for {0} resource does
not exist",
+ resourceName));
+ }
+ }
+ return result;
+ }
+
public Resource createResource(FacesContext context, ResourceRequestData
resourceData) {
String resourceName = resourceData.getResourceName();
Modified:
trunk/core/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -33,9 +33,9 @@
*
*/
public class UserResourceWrapperImpl extends BaseResourceWrapper<UserResource>
implements UserResourceWrapper {
-
- public UserResourceWrapperImpl(UserResource resourceObject) {
- super(resourceObject);
+
+ public UserResourceWrapperImpl(UserResource resourceObject, boolean cacheable,
boolean versioned) {
+ super(resourceObject, cacheable, versioned);
}
@Override
Added: trunk/core/impl/src/test/java/org/richfaces/resource/UserResourcesTestCase.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/resource/UserResourcesTestCase.java
(rev 0)
+++
trunk/core/impl/src/test/java/org/richfaces/resource/UserResourcesTestCase.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -0,0 +1,198 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.context.FacesContext;
+
+import org.jboss.test.faces.FacesEnvironment;
+import org.jboss.test.faces.FacesEnvironment.FacesRequest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.io.ByteStreams;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class UserResourcesTestCase {
+
+ protected static class BaseUserResource extends AbstractUserResource {
+
+ public InputStream getInputStream() throws IOException {
+ return
ByteStreams.newInputStreamSupplier(getClass().getSimpleName().getBytes("US-ASCII")).getInput();
+ }
+
+ public String getContentType() {
+ return "text/plain";
+ }
+
+ }
+
+ protected static class BaseJava2DUserResource extends AbstractJava2DUserResource {
+
+ public BaseJava2DUserResource() {
+ super(new Dimension(10, 5));
+ }
+
+ public void paint(Graphics2D graphics2d) {
+ }
+
+ }
+
+ @DynamicUserResource(versioned = false)
+ public static final class NonVersionedUserResource extends BaseUserResource {
+ }
+
+ @DynamicUserResource(versioned = false)
+ public static final class NonVersionedJava2DUserResource extends
BaseJava2DUserResource {
+ }
+
+ @DynamicUserResource(cacheable = false)
+ public static final class NonCacheableUserResource extends BaseUserResource {
+ }
+
+ @DynamicUserResource(cacheable = false)
+ public static final class NonCacheableJava2DUserResource extends
BaseJava2DUserResource {
+ }
+
+ @DynamicUserResource
+ public static final class DefaultSettingsUserResource extends BaseUserResource {
+ }
+
+ @DynamicUserResource
+ public static final class DefaultSettingsJava2DUserResource extends
BaseJava2DUserResource {
+ }
+
+ @DynamicUserResource
+ public static final class SettingsOverridableResource extends BaseUserResource
implements VersionedResource, CacheableResource {
+
+ public boolean isCacheable(FacesContext context) {
+ return
Boolean.TRUE.equals(context.getAttributes().get(CACHEABLE_OVERRIDE_KEY));
+ }
+
+ public Date getExpires(FacesContext context) {
+ return null;
+ }
+
+ public int getTimeToLive(FacesContext context) {
+ return 0;
+ }
+
+ public String getEntityTag(FacesContext context) {
+ return null;
+ }
+
+ public String getVersion() {
+ return (String)
FacesContext.getCurrentInstance().getAttributes().get(VERSION_OVERRIDE_KEY);
+ }
+
+ }
+
+ private static final String PACKAGE_VERSION = "test-package-1.0";
+
+ private static final String CACHEABLE_OVERRIDE_KEY =
"org.richfaces.test.CacheableOverrideKey";
+
+ private static final String VERSION_OVERRIDE_KEY =
"org.richfaces.test.VersionOverrideKey";
+
+ private FacesEnvironment environment;
+
+ private FacesRequest facesRequest;
+
+ private ResourceHandler resourceHandler;
+
+ @Before
+ public void setUp() throws Exception {
+ environment = FacesEnvironment.createEnvironment();
+
environment.getServer().addInitParameter("org.richfaces.resourceDefaultVersion",
PACKAGE_VERSION);
+ environment.start();
+
+
+ facesRequest = environment.createFacesRequest();
+ facesRequest.start();
+
+ resourceHandler =
FacesContext.getCurrentInstance().getApplication().getResourceHandler();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ resourceHandler = null;
+
+ facesRequest.release();
+ facesRequest = null;
+
+ environment.release();
+ environment = null;
+
+ }
+
+ private void checkResource(Resource resource, boolean cacheable, String version) {
+ assertTrue(resource instanceof VersionedResource);
+ assertEquals(version, ((VersionedResource) resource).getVersion());
+
+ assertTrue(resource instanceof CacheableResource);
+ assertEquals(cacheable, ((CacheableResource)
resource).isCacheable(FacesContext.getCurrentInstance()));
+ }
+
+ @Test
+ public void testResources() throws Exception {
+
checkResource(resourceHandler.createResource(DefaultSettingsUserResource.class.getName()),
true, PACKAGE_VERSION);
+
checkResource(resourceHandler.createResource(NonCacheableUserResource.class.getName()),
false, PACKAGE_VERSION);
+
checkResource(resourceHandler.createResource(NonVersionedUserResource.class.getName()),
true, null);
+ }
+
+ @Test
+ public void testJava2DResources() throws Exception {
+
checkResource(resourceHandler.createResource(DefaultSettingsJava2DUserResource.class.getName()),
true, PACKAGE_VERSION);
+
checkResource(resourceHandler.createResource(NonCacheableJava2DUserResource.class.getName()),
false, PACKAGE_VERSION);
+
checkResource(resourceHandler.createResource(NonVersionedJava2DUserResource.class.getName()),
true, null);
+ }
+
+ @Test
+ public void testSettingsOverridableResource() throws Exception {
+ Map<Object, Object> attributes =
FacesContext.getCurrentInstance().getAttributes();
+
+ attributes.put(CACHEABLE_OVERRIDE_KEY, true);
+ attributes.put(VERSION_OVERRIDE_KEY, "some.version");
+
+
checkResource(resourceHandler.createResource(SettingsOverridableResource.class.getName()),
true, "some.version");
+
+ attributes.put(CACHEABLE_OVERRIDE_KEY, false);
+ attributes.put(VERSION_OVERRIDE_KEY, null);
+
+
checkResource(resourceHandler.createResource(SettingsOverridableResource.class.getName()),
false, null);
+ }
+}
Modified: trunk/ui/core/ui/src/main/java/org/richfaces/resource/PushResource.java
===================================================================
--- trunk/ui/core/ui/src/main/java/org/richfaces/resource/PushResource.java 2010-11-08
15:56:04 UTC (rev 19994)
+++ trunk/ui/core/ui/src/main/java/org/richfaces/resource/PushResource.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -53,6 +53,8 @@
private static final String FORGET_PUSH_SESSION_ID_PARAM =
"forgetPushSessionId";
+ private static final InputStream EMPTY_INPUT_STREAM = new ByteArrayInputStream(new
byte[0]);
+
public Map<String, String> getResponseHeaders() {
return null;
}
@@ -85,6 +87,12 @@
ExternalContext externalContext = facesContext.getExternalContext();
PushContextFactory pushContextFactory =
ServiceTracker.getService(PushContextFactory.class);
+
+ //resource plugin stub
+ if (pushContextFactory == null) {
+ return EMPTY_INPUT_STREAM;
+ }
+
PushContext pushContext = pushContextFactory.getPushContext();
String forgetPushSessionId =
externalContext.getRequestParameterMap().get(FORGET_PUSH_SESSION_ID_PARAM);
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/ArrowBase.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/ArrowBase.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/ArrowBase.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -29,14 +29,12 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import java.util.Date;
-import java.util.Map;
import javax.faces.context.FacesContext;
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.resource.ImageType;
-import org.richfaces.resource.Java2DUserResource;
+import org.richfaces.resource.AbstractJava2DUserResource;
+import org.richfaces.resource.DynamicUserResource;
+import org.richfaces.resource.PostConstructResource;
import org.richfaces.resource.StateHolderResource;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
@@ -45,13 +43,18 @@
* @author Konstantin Mishin
*
*/
-@DynamicResource
-public abstract class ArrowBase implements Java2DUserResource, StateHolderResource {
+@DynamicUserResource
+public abstract class ArrowBase extends AbstractJava2DUserResource implements
StateHolderResource {
private int color;
private String colorName = Skin.GENERAL_TEXT_COLOR;
- private void initialize() {
+ public ArrowBase(Dimension dimension) {
+ super(dimension);
+ }
+
+ @PostConstructResource
+ public void initialize() {
FacesContext context = FacesContext.getCurrentInstance();
Skin skin = SkinFactory.getInstance(context).getSkin(context);
this.color = skin.getColorParameter(context, colorName);
@@ -61,15 +64,12 @@
this.colorName = colorName;
}
- public abstract Dimension getDimension();
-
- public void paint(Graphics2D graphics2d, Dimension dimension) {
+ public void paint(Graphics2D graphics2d) {
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics2d.setColor(new Color(color));
}
public void writeState(FacesContext context, DataOutput dataOutput) throws
IOException {
- initialize();
dataOutput.writeInt(this.color);
}
@@ -77,18 +77,6 @@
this.color = dataInput.readInt();
}
- public Map<String, String> getResponseHeaders() {
- return null;
- }
-
- public Date getLastModified() {
- return null;
- }
-
- public ImageType getImageType() {
- return ImageType.PNG;
- }
-
public boolean isTransient() {
return false;
}
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteBaseGradient.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteBaseGradient.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteBaseGradient.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -29,15 +29,11 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import java.util.Date;
-import java.util.Map;
import javax.faces.context.FacesContext;
-import org.richfaces.resource.CacheableResource;
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.resource.ImageType;
-import org.richfaces.resource.Java2DUserResource;
+import org.richfaces.resource.AbstractJava2DUserResource;
+import org.richfaces.resource.DynamicUserResource;
import org.richfaces.resource.StateHolderResource;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
@@ -46,8 +42,8 @@
* @author Nick Belaevski
*
*/
-@DynamicResource
-public abstract class AutocompleteBaseGradient implements Java2DUserResource,
CacheableResource, StateHolderResource {
+@DynamicUserResource
+public abstract class AutocompleteBaseGradient extends AbstractJava2DUserResource
implements StateHolderResource {
private static final Dimension DIMENSION = new Dimension(18, 8);
@@ -59,46 +55,20 @@
private Color bottomColor;
- public Map<String, String> getResponseHeaders() {
- return null;
+ public AutocompleteBaseGradient() {
+ super(DIMENSION);
}
-
- public Date getLastModified() {
- return null;
- }
-
- public ImageType getImageType() {
- return ImageType.PNG;
- }
-
- public Dimension getDimension() {
- return DIMENSION;
- }
-
- public void paint(Graphics2D graphics2d, Dimension dimension) {
+
+ public void paint(Graphics2D graphics2d) {
+ Dimension dimension = getDimension();
+
GradientPaint paint = new GradientPaint(0, 0, topColor, 0, dimension.height,
bottomColor);
graphics2d.setPaint(paint);
graphics2d.fill(new Rectangle(dimension));
}
- public boolean isCacheable(FacesContext context) {
- return true;
- }
-
- public Date getExpires(FacesContext context) {
- return null;
- }
-
- public int getTimeToLive(FacesContext context) {
- return 0;
- }
-
- public String getEntityTag(FacesContext context) {
- return null;
- }
-
public void writeState(FacesContext context, DataOutput dataOutput) throws
IOException {
- Skin skin = SkinFactory.getInstance().getSkin(context);
+ Skin skin = SkinFactory.getInstance(context).getSkin(context);
Integer topColor = skin.getColorParameter(context, topColorSkinParameter);
Integer bottomColor = skin.getColorParameter(context, bottomColorSkinParameter);
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteButtonGradient.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteButtonGradient.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteButtonGradient.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -21,14 +21,12 @@
*/
package org.richfaces.renderkit.html.images;
-import org.richfaces.resource.DynamicResource;
import org.richfaces.skin.Skin;
/**
* @author Nick Belaevski
*
*/
-@DynamicResource
public class AutocompleteButtonGradient extends AutocompleteBaseGradient {
public AutocompleteButtonGradient() {
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteFieldGradient.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteFieldGradient.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/AutocompleteFieldGradient.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -21,14 +21,12 @@
*/
package org.richfaces.renderkit.html.images;
-import org.richfaces.resource.DynamicResource;
import org.richfaces.skin.Skin;
/**
* @author Nick Belaevski
*
*/
-@DynamicResource
public class AutocompleteFieldGradient extends AutocompleteBaseGradient {
public AutocompleteFieldGradient() {
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarIcon.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarIcon.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarIcon.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -35,14 +35,11 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import java.util.Date;
-import java.util.Map;
import javax.faces.context.FacesContext;
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.resource.ImageType;
-import org.richfaces.resource.Java2DUserResource;
+import org.richfaces.resource.AbstractJava2DUserResource;
+import org.richfaces.resource.DynamicUserResource;
import org.richfaces.resource.PostConstructResource;
import org.richfaces.resource.StateHolderResource;
import org.richfaces.skin.Skin;
@@ -52,8 +49,8 @@
* @author amarkhel
*
*/
-@DynamicResource
-public class CalendarIcon implements Java2DUserResource, StateHolderResource{
+@DynamicUserResource
+public class CalendarIcon extends AbstractJava2DUserResource implements
StateHolderResource {
private static final Dimension DIMENSION = new Dimension(20, 20);
@@ -61,7 +58,10 @@
private Integer headerBackgroundColor;
-
+ public CalendarIcon() {
+ super(DIMENSION);
+ }
+
@PostConstructResource
public final void initialize() {
FacesContext context = FacesContext.getCurrentInstance();
@@ -70,7 +70,6 @@
this.headerTextColor = skin.getColorParameter(context,
Skin.HEADER_BACKGROUND_COLOR);
this.headerBackgroundColor = skin.getColorParameter(context,
Skin.SELECT_CONTROL_COLOR);
}
-
public boolean isTransient() {
return false;
@@ -86,30 +85,15 @@
this.headerBackgroundColor = dataInput.readInt();
}
- public Map<String, String> getResponseHeaders() {
- return null;
- }
-
- public Date getLastModified() {
- return null;
- }
-
- public ImageType getImageType() {
- return ImageType.PNG;
- }
-
- public Dimension getDimension() {
- return DIMENSION;
- }
-
protected BufferedImage createImage(int width, int height) {
return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
}
- public void paint(Graphics2D graphics2d, Dimension dimension) {
+ public void paint(Graphics2D graphics2d) {
BufferedImage image = paintImage();
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ Dimension dimension = getDimension();
graphics2d.drawImage(image, 0, 0, dimension.width, dimension.height, null);
}
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarSeparator.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarSeparator.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarSeparator.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -29,14 +29,11 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import java.util.Date;
-import java.util.Map;
import javax.faces.context.FacesContext;
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.resource.ImageType;
-import org.richfaces.resource.Java2DUserResource;
+import org.richfaces.resource.AbstractJava2DUserResource;
+import org.richfaces.resource.DynamicUserResource;
import org.richfaces.resource.PostConstructResource;
import org.richfaces.resource.StateHolderResource;
import org.richfaces.skin.Skin;
@@ -46,13 +43,17 @@
* @author amarkhel
*
*/
-@DynamicResource
-public class CalendarSeparator implements Java2DUserResource, StateHolderResource {
+@DynamicUserResource
+public class CalendarSeparator extends AbstractJava2DUserResource implements
StateHolderResource {
private static final Dimension DIMENSION = new Dimension(1, 15);
private Integer headerTextColor;
+ public CalendarSeparator() {
+ super(DIMENSION);
+ }
+
@PostConstructResource
public void initialize() {
FacesContext context = FacesContext.getCurrentInstance();
@@ -73,23 +74,7 @@
this.headerTextColor = dataInput.readInt();
}
- public Map<String, String> getResponseHeaders() {
- return null;
- }
-
- public Date getLastModified() {
- return null;
- }
-
- public ImageType getImageType() {
- return ImageType.PNG;
- }
-
- public Dimension getDimension() {
- return DIMENSION;
- }
-
- public void paint(Graphics2D graphics2d, Dimension dimension) {
+ public void paint(Graphics2D graphics2d) {
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
graphics2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE);
graphics2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowBase.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowBase.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowBase.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -30,10 +30,10 @@
*/
public abstract class SliderArrowBase extends ArrowBase {
- private Dimension dimension = new Dimension(7, 7);
+ private static final Dimension DIMENSION = new Dimension(7, 7);
- @Override
- public Dimension getDimension() {
- return dimension;
+ public SliderArrowBase() {
+ super(DIMENSION);
}
+
}
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowBottom.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowBottom.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowBottom.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -22,7 +22,6 @@
package org.richfaces.renderkit.html.images;
-import java.awt.Dimension;
import java.awt.Graphics2D;
/**
@@ -32,8 +31,8 @@
public class SliderArrowBottom extends SliderArrowBase {
@Override
- public void paint(Graphics2D graphics2d, Dimension dimension) {
- super.paint(graphics2d, dimension);
+ public void paint(Graphics2D graphics2d) {
+ super.paint(graphics2d);
graphics2d.drawLine(0, 1, 6, 1);
graphics2d.drawLine(1, 2, 5, 2);
graphics2d.drawLine(2, 3, 4, 3);
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowLeft.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowLeft.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowLeft.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -22,7 +22,6 @@
package org.richfaces.renderkit.html.images;
-import java.awt.Dimension;
import java.awt.Graphics2D;
/**
@@ -32,8 +31,8 @@
public class SliderArrowLeft extends SliderArrowBase {
@Override
- public void paint(Graphics2D graphics2d, Dimension dimension) {
- super.paint(graphics2d, dimension);
+ public void paint(Graphics2D graphics2d) {
+ super.paint(graphics2d);
graphics2d.drawLine(4, 0, 4, 6);
graphics2d.drawLine(3, 1, 3, 5);
graphics2d.drawLine(2, 2, 2, 4);
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowRight.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowRight.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SliderArrowRight.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -22,7 +22,6 @@
package org.richfaces.renderkit.html.images;
-import java.awt.Dimension;
import java.awt.Graphics2D;
/**
@@ -32,8 +31,8 @@
public class SliderArrowRight extends SliderArrowBase {
@Override
- public void paint(Graphics2D graphics2d, Dimension dimension) {
- super.paint(graphics2d, dimension);
+ public void paint(Graphics2D graphics2d) {
+ super.paint(graphics2d);
graphics2d.drawLine(2, 0, 2, 6);
graphics2d.drawLine(3, 1, 3, 5);
graphics2d.drawLine(4, 2, 4, 4);
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowBase.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowBase.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowBase.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -30,10 +30,10 @@
*/
public abstract class SpinnerArrowBase extends ArrowBase {
- private Dimension dimension = new Dimension(5, 3);
+ private static final Dimension DIMENSION = new Dimension(5, 3);
- @Override
- public Dimension getDimension() {
- return dimension;
+ public SpinnerArrowBase() {
+ super(DIMENSION);
}
+
}
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowBottom.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowBottom.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowBottom.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -22,7 +22,6 @@
package org.richfaces.renderkit.html.images;
-import java.awt.Dimension;
import java.awt.Graphics2D;
/**
@@ -32,8 +31,8 @@
public class SpinnerArrowBottom extends SpinnerArrowBase {
@Override
- public void paint(Graphics2D graphics2d, Dimension dimension) {
- super.paint(graphics2d, dimension);
+ public void paint(Graphics2D graphics2d) {
+ super.paint(graphics2d);
graphics2d.drawLine(0, 0, 4, 0);
graphics2d.drawLine(1, 1, 3, 1);
graphics2d.drawLine(2, 2, 2, 2);
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowTop.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowTop.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/html/images/SpinnerArrowTop.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -22,7 +22,6 @@
package org.richfaces.renderkit.html.images;
-import java.awt.Dimension;
import java.awt.Graphics2D;
/**
@@ -32,8 +31,8 @@
public class SpinnerArrowTop extends SpinnerArrowBase {
@Override
- public void paint(Graphics2D graphics2d, Dimension dimension) {
- super.paint(graphics2d, dimension);
+ public void paint(Graphics2D graphics2d) {
+ super.paint(graphics2d);
graphics2d.drawLine(2, 0, 2, 0);
graphics2d.drawLine(1, 1, 3, 1);
graphics2d.drawLine(0, 2, 4, 2);
Deleted:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/BaseTreeImage.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/BaseTreeImage.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/BaseTreeImage.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -1,84 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.renderkit.html.images;
-
-import java.awt.Dimension;
-import java.util.Date;
-import java.util.Map;
-
-import javax.faces.context.FacesContext;
-
-import org.richfaces.resource.CacheableResource;
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.resource.ImageType;
-import org.richfaces.resource.Java2DUserResource;
-import org.richfaces.resource.StateHolderResource;
-
-/**
- * @author Nick Belaevski
- *
- */
-@DynamicResource
-public abstract class BaseTreeImage implements Java2DUserResource, StateHolderResource,
CacheableResource {
-
- private Dimension dimension;
-
- protected BaseTreeImage(Dimension dimension) {
- super();
- this.dimension = dimension;
- }
- public boolean isCacheable(FacesContext context) {
- return true;
- }
- public Date getExpires(FacesContext context) {
- return null;
- }
-
- public int getTimeToLive(FacesContext context) {
- return -1;
- }
-
- public String getEntityTag(FacesContext context) {
- return null;
- }
-
- public boolean isTransient() {
- return false;
- }
-
- public Map<String, String> getResponseHeaders() {
- return null;
- }
-
- public Date getLastModified() {
- return null;
- }
-
- public ImageType getImageType() {
- return ImageType.PNG;
- }
-
- public Dimension getDimension() {
- return dimension;
- }
-
-}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeLineImage.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeLineImage.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeLineImage.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -30,8 +30,10 @@
import javax.faces.context.FacesContext;
-import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.AbstractJava2DUserResource;
+import org.richfaces.resource.DynamicUserResource;
import org.richfaces.resource.PostConstructResource;
+import org.richfaces.resource.StateHolderResource;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
@@ -39,15 +41,15 @@
* @author Nick Belaevski
*
*/
-@DynamicResource
-public class TreeLineImage extends BaseTreeImage {
+@DynamicUserResource
+public class TreeLineImage extends AbstractJava2DUserResource implements
StateHolderResource {
private static final Dimension DIMENSION = new Dimension(16, 16);
protected Integer trimColorValue;
public TreeLineImage() {
- super(DIMENSION);
+ this(DIMENSION);
}
protected TreeLineImage(Dimension dimension) {
@@ -63,7 +65,7 @@
trimColorValue = skin.getColorParameter(context, Skin.TRIM_COLOR);
}
- public void paint(Graphics2D g2d, Dimension dimension) {
+ public void paint(Graphics2D g2d) {
g2d.setColor(new Color(trimColorValue));
g2d.drawLine(7, 0, 7, 15);
@@ -77,6 +79,8 @@
trimColorValue = dataInput.readInt();
}
-
+ public boolean isTransient() {
+ return false;
+ }
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeLineLastImage.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeLineLastImage.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeLineLastImage.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -25,13 +25,10 @@
import java.awt.Dimension;
import java.awt.Graphics2D;
-import org.richfaces.resource.DynamicResource;
-
/**
* @author Nick Belaevski
*
*/
-@DynamicResource
public class TreeLineLastImage extends TreeLineImage {
private static final Dimension DIMENSION = new Dimension(16, 200);
@@ -40,7 +37,7 @@
super(DIMENSION);
}
- public void paint(Graphics2D g2d, Dimension dimension) {
+ public void paint(Graphics2D g2d) {
g2d.setColor(new Color(trimColorValue));
g2d.drawLine(7, 0, 7, 99);
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeMinusImage.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeMinusImage.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreeMinusImage.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -21,19 +21,15 @@
*/
package org.richfaces.renderkit.html.images;
-import java.awt.Dimension;
import java.awt.Graphics2D;
-import org.richfaces.resource.DynamicResource;
-
/**
* @author Nick Belaevski
*
*/
-@DynamicResource
public class TreeMinusImage extends TreePlusImage {
- public void paint(Graphics2D g2d, Dimension dimension) {
+ public void paint(Graphics2D g2d) {
drawFrame(g2d);
drawHorizontalCrossLine(g2d);
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreePlusImage.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreePlusImage.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/html/images/TreePlusImage.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -32,8 +32,10 @@
import javax.faces.context.FacesContext;
-import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.AbstractJava2DUserResource;
+import org.richfaces.resource.DynamicUserResource;
import org.richfaces.resource.PostConstructResource;
+import org.richfaces.resource.StateHolderResource;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
@@ -41,8 +43,8 @@
* @author Nick Belaevski
*
*/
-@DynamicResource
-public class TreePlusImage extends BaseTreeImage {
+@DynamicUserResource
+public class TreePlusImage extends AbstractJava2DUserResource implements
StateHolderResource {
private static final Dimension DIMENSION = new Dimension(16, 16);
@@ -80,7 +82,7 @@
g2d.fill(rect);
}
- public void paint(Graphics2D g2d, Dimension dimension) {
+ public void paint(Graphics2D g2d) {
drawFrame(g2d);
drawHorizontalCrossLine(g2d);
@@ -111,4 +113,8 @@
trimColorValue = dataInput.readInt();
}
+ public boolean isTransient() {
+ return false;
+ }
+
}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarAnimatedBackgroundImage.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarAnimatedBackgroundImage.java 2010-11-08
15:56:04 UTC (rev 19994)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarAnimatedBackgroundImage.java 2010-11-08
23:06:12 UTC (rev 19995)
@@ -30,14 +30,12 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import java.util.Date;
-import java.util.Map;
import javax.faces.context.FacesContext;
import org.richfaces.renderkit.util.ColorUtils;
-import org.richfaces.resource.CacheableResource;
-import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.AbstractJava2DUserResource;
+import org.richfaces.resource.DynamicUserResource;
import org.richfaces.resource.ImageType;
import org.richfaces.resource.Java2DAnimatedUserResource;
import org.richfaces.resource.StateHolderResource;
@@ -49,8 +47,8 @@
*
*/
//TODO - add version
-@DynamicResource
-public class ProgressBarAnimatedBackgroundImage implements Java2DAnimatedUserResource,
StateHolderResource, CacheableResource {
+@DynamicUserResource
+public class ProgressBarAnimatedBackgroundImage extends AbstractJava2DUserResource
implements Java2DAnimatedUserResource, StateHolderResource {
private static final int NUMBER_OF_FRAMES = 12;
@@ -59,23 +57,11 @@
private int frameNumber = 0;
private Color basicColor;
-
- public Map<String, String> getResponseHeaders() {
- return null;
- }
- public Date getLastModified() {
- return null;
+ public ProgressBarAnimatedBackgroundImage() {
+ super(ImageType.GIF, DIMENSION);
}
- public ImageType getImageType() {
- return ImageType.GIF;
- }
-
- public Dimension getDimension() {
- return DIMENSION;
- }
-
public boolean isLooped() {
return true;
}
@@ -122,9 +108,11 @@
return retVal;
}
- public void paint(Graphics2D g2d, Dimension dimension) {
+ public void paint(Graphics2D g2d) {
frameNumber++;
+ Dimension dimension = getDimension();
+
BufferedImage mainStage = createMainStage();
BufferedImage frame = mainStage.getSubimage(0, 48 - frameNumber * 2,
dimension.width, dimension.height);
g2d.drawImage(frame, null, null);
@@ -150,19 +138,4 @@
basicColor = new Color(dataInput.readInt());
}
- public boolean isCacheable(FacesContext context) {
- return true;
- }
-
- public Date getExpires(FacesContext context) {
- return null;
- }
-
- public int getTimeToLive(FacesContext context) {
- return 0;
- }
-
- public String getEntityTag(FacesContext context) {
- return null;
- }
}