JAVA GWT Timer to fade color of Graphic

时间:2015-07-08 15:57:43

标签: java gwt timer graphic

I am thinking to use two Timers (one to fade towards a color, then one to fade right back to the original color) to create a fading effect on a Graphic. The graphic is built as follows:

SimpleMarkerSymbol pointSymbol = SimpleMarkerSymbol.create();
DojoColor color = DojoColor.fromRGB(125, 125, 255);
pointSymbol = (SimpleMarkerSymbol) pointSymbol.setColor(color);
pointSymbol = (SimpleMarkerSymbol) pointSymbol.setSize(6);

SimpleLineSymbol outline = SimpleLineSymbol.create();
color = DojoColor.fromRGB(0, 0, 0);
outline.setColor(color);
pointSymbol.setOutline(outline);

I have the following code so far for my fade timers:

Timer fadeInTimer = new Timer() {
    int r = 125;
    int g = 125;
    int b = 255;
    @Override
    public void run() {
        for(int i = 0; i<5;i++) {
            r++;
            g++;
            b--;
        }
        DojoColor color = DojoColor.fromRGB(r, g, b);
   }

};

Timer fadeOutTimer = new Timer() {
    int r = 125;
    int g = 125;
    int b = 255;
    @Override
    public void run() {
        for(int i = 0; i<5;i++) {
           r--;
           g--;
           b++;
         }
         DojoColor color = DojoColor.fromRGB(r, g, b);
    }
};

The idea here being that I will call the fadeInTimer x amount of times to change the color significantly (lets say x=25). Then I will call fadeOutTimer x amount of times to return it to the original color. I see that I can schedule a timer for a single occurence via a delay or I can schedule a repeating timer, however I need a repeating timer that will stop running after a given amount of time and I need my fadeOutTimer to wait for the fadeInTimer to complete. I am not sure how to accomplish this. Help is much appreciated.

1 个答案:

答案 0 :(得分:0)

您应该使用Animations

然后,您可以在第一个动画的onComplete方法中轻松开始新动画。