JensHeyer
12 Mar 2009, 3:21 AM
Hello everbody,
currently I am trying to get familiar with the Fx effect classes and I am not sure but could it be that there can only be one effect at a time?
Here is my example:
TextBox txt = new TextBox();
txt.setText("Hello");
TextBox txt2 = new TextBox();
txt2.setText("World");
final Fx effect = new Fx(new FxConfig(7000));
final WidgetComponent wc = new WidgetComponent(txt);
txt.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
effect.cancel();
effect.run(new Scale(wc.el(), Scale.GREEN));
}
});
final Fx effect2 = new Fx(new FxConfig(7000));
final WidgetComponent wc2 = new WidgetComponent(txt2);
txt2.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
effect2.cancel();
effect2.run(new Scale(wc2.el(), Scale.GREEN));
}
});
RootPanel.get().add(wc);
RootPanel.get().add(wc2);
public class Scale extends BaseEffect {
public static final int RED = 0;
public static final int GREEN = 1;
public static final int BLUE = 2;
private int red = 0;
private int green = 0;
private int blue = 0;
public Scale(El el, int color) {
super(el);
switch(color) {
case Scale.RED:
this.red = 255;
break;
case Scale.GREEN:
this.green = 255;
break;
case Scale.BLUE:
this.blue = 255;
break;
default:
break;
}
el.setStyleAttribute("color", this.buildHexString());
}
@Override
public void onUpdate(double progress) {
this.red = (int) getValue(this.red, 0, progress);
this.green = (int) getValue(this.green, 0, progress);
this.blue = (int) getValue(this.blue, 0, progress);
el.setStyleAttribute("color", this.buildHexString());
}
@Override
public void onCancel() {
}
@Override
public void onComplete() {
el.setStyleAttribute("color", "#000000");
System.out.println("Complete");
}
private String buildHexString() {
String red = Integer.toHexString(this.red);
if (red.length() < 2) {
red = "0" + red;
}
String green = Integer.toHexString(this.green);
if (green.length() < 2) {
green = "0" + green;
}
String blue = Integer.toHexString(this.blue);
if (blue.length() < 2) {
blue = "0" + blue;
}
return "#" + red + green + blue;
}
}
By the time clicking at the "Hello" TextBox the text gets green and slowly goes back to black. That is exactly what I want - but when I am clicking at the "Hello" TextBox and then (before the "Hello" effect ends) the "World" TextBox the second one only gets green without changing the color over time.
Would be great if anybody could help me solving this problem.
currently I am trying to get familiar with the Fx effect classes and I am not sure but could it be that there can only be one effect at a time?
Here is my example:
TextBox txt = new TextBox();
txt.setText("Hello");
TextBox txt2 = new TextBox();
txt2.setText("World");
final Fx effect = new Fx(new FxConfig(7000));
final WidgetComponent wc = new WidgetComponent(txt);
txt.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
effect.cancel();
effect.run(new Scale(wc.el(), Scale.GREEN));
}
});
final Fx effect2 = new Fx(new FxConfig(7000));
final WidgetComponent wc2 = new WidgetComponent(txt2);
txt2.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
effect2.cancel();
effect2.run(new Scale(wc2.el(), Scale.GREEN));
}
});
RootPanel.get().add(wc);
RootPanel.get().add(wc2);
public class Scale extends BaseEffect {
public static final int RED = 0;
public static final int GREEN = 1;
public static final int BLUE = 2;
private int red = 0;
private int green = 0;
private int blue = 0;
public Scale(El el, int color) {
super(el);
switch(color) {
case Scale.RED:
this.red = 255;
break;
case Scale.GREEN:
this.green = 255;
break;
case Scale.BLUE:
this.blue = 255;
break;
default:
break;
}
el.setStyleAttribute("color", this.buildHexString());
}
@Override
public void onUpdate(double progress) {
this.red = (int) getValue(this.red, 0, progress);
this.green = (int) getValue(this.green, 0, progress);
this.blue = (int) getValue(this.blue, 0, progress);
el.setStyleAttribute("color", this.buildHexString());
}
@Override
public void onCancel() {
}
@Override
public void onComplete() {
el.setStyleAttribute("color", "#000000");
System.out.println("Complete");
}
private String buildHexString() {
String red = Integer.toHexString(this.red);
if (red.length() < 2) {
red = "0" + red;
}
String green = Integer.toHexString(this.green);
if (green.length() < 2) {
green = "0" + green;
}
String blue = Integer.toHexString(this.blue);
if (blue.length() < 2) {
blue = "0" + blue;
}
return "#" + red + green + blue;
}
}
By the time clicking at the "Hello" TextBox the text gets green and slowly goes back to black. That is exactly what I want - but when I am clicking at the "Hello" TextBox and then (before the "Hello" effect ends) the "World" TextBox the second one only gets green without changing the color over time.
Would be great if anybody could help me solving this problem.