📄 scrollanimation.java
字号:
/* * Fire (Flexible Interface Rendering Engine) is a set of graphics widgets for creating GUIs for j2me applications. * Copyright (C) 2006-2008 Bluevibe (www.bluevibe.net) * This library 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 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 gr.fire.ui;import gr.fire.core.Animation;import gr.fire.core.Component;import gr.fire.core.FireScreen;import gr.fire.core.Panel;import javax.microedition.lcdui.Graphics;/** * @author padeler * */public class ScrollAnimation extends Animation{ public static final long MILISECONDS_PER_FRAME=40; public static final int SCROLL_PERCENT = 30; // percent of the viewports dimensions to scroll. public static final int SCROLL_FRAMES = 4; // number of frames in this animation. private Panel owner; private Integer direction; private int frameCount=0; private int stepChange=0; private long lastFrame; int width,height; public void paint(Graphics g) { owner.paint(g); } public Component getOwner() { return owner; } /* (non-Javadoc) * @see gr.fire.core.Animation#getProperties() */ public Object getProperties() { return direction; } public Component getTrigger() { return null; } public boolean isRunning() { return (frameCount<SCROLL_FRAMES); } /** * Setup this scrollAnimation object. * @param Owner is the Panel which will scroll * @param Trigger is ignored. * @param properties is an Integer with the animation direction. Animation directions are FireScreen.LEFT, FireScreen.RIGHT, FireScreen.UP, FireScreen.DOWN. */ public void setup(Component owner, Component trigger, Object properties) { if(owner==null || (owner instanceof Panel)==false || properties==null || (properties instanceof Integer)==false) throw new IllegalArgumentException("Owner must be a Panel, and properties must be an Integer with the scroll direction"); this.owner = (Panel)owner; this.direction = (Integer)properties; int d = direction.intValue(); int vpD; if(d==FireScreen.UP || d==FireScreen.DOWN) vpD = this.owner.getViewPortHeight(); else vpD = this.owner.getViewPortWidth(); stepChange = ((vpD * SCROLL_PERCENT)/SCROLL_FRAMES) / 100; width = this.owner.getWidth(); height = this.owner.getHeight(); lastFrame = System.currentTimeMillis(); } /* (non-Javadoc) * @see gr.fire.core.Animation#step() */ public boolean step() { long now = System.currentTimeMillis(); if(now-lastFrame>=MILISECONDS_PER_FRAME) { lastFrame = now; frameCount++; int vpX = owner.getViewPortPositionX(); int vpY = owner.getViewPortPositionY(); int d = direction.intValue(); boolean dontStop=true; switch(d) { case FireScreen.UP: dontStop = owner.setViewPortPosition(vpX,vpY-stepChange); break; case FireScreen.DOWN: dontStop = owner.setViewPortPosition(vpX,vpY+stepChange); break; case FireScreen.LEFT: dontStop = owner.setViewPortPosition(vpX-stepChange,vpY); break; case FireScreen.RIGHT: dontStop = owner.setViewPortPosition(vpX+stepChange,vpY); break; } if(dontStop==false) { stop(); return false; } return true; } return false; } public void forceComplete() { stepChange = stepChange*(SCROLL_FRAMES-frameCount); lastFrame=0; step(); } /* (non-Javadoc) * @see gr.fire.core.Animation#stop() */ public void stop() { frameCount = SCROLL_FRAMES; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -