Skip to content

Commit

Permalink
Fixed animator error. ChangeTo AnimateProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
daxzel committed Jul 3, 2013
1 parent f73aa9a commit d37bbaf
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 69 deletions.
37 changes: 32 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vaadin.version>7.1.0</vaadin.version>
<vaadin.version>7.1.0.h.M0</vaadin.version>
<plugin.vaadin.version>7.1.0</plugin.vaadin.version>
<vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>
<jdkVersion>1.7</jdkVersion>
</properties>
Expand Down Expand Up @@ -56,14 +57,14 @@
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client</artifactId>
<artifactId>vaadin-themes</artifactId>
<version>${vaadin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
<artifactId>vaadin-client</artifactId>
<version>${vaadin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.vaadin.addons</groupId>
Expand Down Expand Up @@ -105,6 +106,20 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
Expand All @@ -119,7 +134,7 @@
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<version>${plugin.vaadin.version}</version>
<configuration>
<extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
<webappDirectory>${basedir}/WebContent/VAADIN/widgetsets
Expand All @@ -145,6 +160,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<webAppSourceDirectory>${basedir}/WebContent</webAppSourceDirectory>
<webAppConfig>
<baseResource implementation="org.mortbay.resource.ResourceCollection">
<resourcesAsCSV>${basedir}/WebContent</resourcesAsCSV>
</baseResource>
</webAppConfig>
</configuration>
</plugin>
</plugins>
</build>
</project>
134 changes: 73 additions & 61 deletions src/org/vaadin/notifique/Notifique.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.util.List;
import java.util.Map;

import org.vaadin.jouni.animator.Animator;

import com.vaadin.event.LayoutEvents.LayoutClickEvent;
import com.vaadin.event.LayoutEvents.LayoutClickListener;
import com.vaadin.server.Resource;
Expand All @@ -21,6 +19,8 @@
import com.vaadin.ui.Panel;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.themes.Reindeer;
import org.vaadin.jouni.animator.AnimatorProxy;
import org.vaadin.jouni.animator.shared.AnimType;

public class Notifique extends CustomComponent {

Expand Down Expand Up @@ -77,30 +77,34 @@ public interface HideListener extends Serializable {

private Panel root;
private CssLayout css;
private List<Message> items = new LinkedList<Message>();
private List<Message> items = new LinkedList();
private boolean autoScroll;
private int visibleCount = 5;
private boolean fillFromTop = false;
private HideListener hideListener;
private ClickListener clickListener;
private AnimatorProxy ap;

public class Message implements Serializable {
private static final long serialVersionUID = 5892777954593320723L;
private Component component;
private MessageAnimator animation;
private CssLayout animatedContent;
private boolean visible;
private Object data;

private void show() {
animation.rollDown();
ap.animate(animatedContent, AnimType.ROLL_DOWN_OPEN).setDuration(200)
.setDelay(0);

visible = true;
}

public void hide() {
if (!isVisible()) {
return;
}
animation.rollUp();
ap.animate(animatedContent, AnimType.ROLL_UP_CLOSE_REMOVE).setDuration(200)
.setDelay(0);
visible = false;
if (getHideListener() != null) {
getHideListener().messageHide(this);
Expand Down Expand Up @@ -130,41 +134,51 @@ public Notifique getNotifique() {
}

/**
* Custom animator extension allowing us to react on hide events coming from
* client-side.
*
* We use this to actually remove the components from layout after they have
* been animated away.
*
* @author Sami Ekblad
*
*/
public class MessageAnimator extends Animator {
private static final long serialVersionUID = 1L;

@Override
public void changeVariables(Object source, Map<String, Object> variables) {
boolean wasHidden = isRolledUp();
super.changeVariables(source, variables);
if (!wasHidden && isRolledUp()) {
removeAfterHide(this);
} else if (!isRolledUp() && !fillFromTop) {
root.setScrollTop(10000);
root.requestRepaint(); // TODO
}
}

public MessageAnimator(Component toAnimate) {
super(toAnimate);
setWidth("100%");
}
}
// * Custom animator extension allowing us to react on hide events coming from
// * client-side.
// *
// * We use this to actually remove the components from layout after they have
// * been animated away.
// *
// * @author Sami Ekblad
// *
// */
// public class MessageAnimator extends Animator {
// private static final long serialVersionUID = 1L;
//
// @Override
// public void changeVariables(Object source, Map<String, Object> variables) {
// boolean wasHidden = isRolledUp();
// super.changeVariables(source, variables);
// if (!wasHidden && isRolledUp()) {
// removeAfterHide(this);
// } else if (!isRolledUp() && !fillFromTop) {
// root.setScrollTop(10000);
// root.requestRepaint(); // TODO
// }
// }
//
// public MessageAnimator(Component toAnimate) {
// super(toAnimate);
// setWidth("100%");
// }
// }

public Notifique(boolean autoScroll) {
ap = new AnimatorProxy();
css = new CssLayout();
root = new Panel(css);
root.setStyleName(Reindeer.PANEL_LIGHT);
css.setWidth("100%");
css.addComponent(ap);
ap.addListener(new AnimatorProxy.AnimationListener() {
@Override
public void onAnimation(AnimatorProxy.AnimationEvent animationEvent) {
if (animationEvent.getAnimation().getType().equals(AnimType.ROLL_LEFT_CLOSE_REMOVE)) {
items.remove(animationEvent.getComponent());
}
}
});
root.addStyleName(STYLE_QUEUE);
root.getContent().setStyleName(STYLE_QUEUE);
setCompositionRoot(root);
Expand All @@ -181,10 +195,10 @@ protected void publish(Message m) {
if (fillFromTop) {
items.add(0, m);
((CssLayout) root.getContent())
.addComponentAsFirst(m.animation);
.addComponentAsFirst(m.animatedContent);
} else {
items.add(m);
css.addComponent(m.animation);
css.addComponent(m.animatedContent);
}
m.show();
if (autoScroll && items.size() > getVisibleCount()) {
Expand All @@ -196,27 +210,27 @@ protected void publish(Message m) {
}
}

/**
* Remove the item after it has been hidden.
*
* @param toBeRemoved
*/
private void removeAfterHide(MessageAnimator toBeRemoved) {
synchronized (items) {
Message removed = null;
for (Message m : items) {
if (m.animation.equals(toBeRemoved)) {
removed = m;
break;
}
}

if (removed != null) {
css.removeComponent(removed.animation);
items.remove(removed);
}
}
}
// /**
// * Remove the item after it has been hidden.
// *
// * @param toBeRemoved
// */
// private void removeAfterHide(MessageAnimator toBeRemoved) {
// synchronized (items) {
// Message removed = null;
// for (Message m : items) {
// if (m.animatedContent.equals(toBeRemoved)) {
// removed = m;
// break;
// }
// }
//
// if (removed != null) {
// css.removeComponent(removed.animatedContent);
// items.remove(removed);
// }
// }
// }

/**
* Create a new item into the queue. It is not visible until added with
Expand All @@ -239,10 +253,8 @@ protected Message createMessage(final Component component, String style) {
css.addComponent(component);

// Wrap component into an animator
final MessageAnimator anim = new MessageAnimator(css);
m.component = component;
m.animation = anim;
anim.setImmediate(true);
m.animatedContent = css;

return m;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Date;

import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import org.vaadin.notifique.Notifique;
import org.vaadin.notifique.Notifique.ClickListener;
Expand All @@ -15,6 +16,7 @@
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Button.ClickEvent;

@Theme("reindeer")
public class NotifiqueSampleApplicationUI extends UI implements
ClickListener, HideListener {

Expand Down
6 changes: 3 additions & 3 deletions src/org/vaadin/notifique/widgetset/NotifiqueWidgetset.gwt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
Firefox 2 and safari is used for webkit based browsers including
Google Chrome.
-->
<!-- <set-property name="user.agent" value="gecko"/> -->
<stylesheet src="notifique/styles.css "/>

<inherits name="com.vaadin.DefaultWidgetSet" />
<inherits name="org.vaadin.jouni.animator.AnimatorWidgetset" />

<inherits name="com.vaadin.DefaultWidgetSet" />
<stylesheet src="notifique/styles.css "/>

</module>

0 comments on commit d37bbaf

Please sign in to comment.