/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package eric.animations; import eric.GUI.themes; import eric.GUI.window.myJMenuItem; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Vector; import eric.JEricPanel; import javax.swing.JPopupMenu; import javax.swing.JSeparator; import javax.swing.JSlider; import javax.swing.SwingUtilities; import javax.swing.border.TitledBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import rene.gui.Global; import rene.util.xml.XmlWriter; import rene.zirkel.ZirkelCanvas; import rene.zirkel.objects.ConstructionObject; import rene.zirkel.objects.ExpressionObject; import rene.zirkel.objects.PointObject; /** * * @author erichake */ public class AnimationPanel extends JEricPanel implements MouseListener { private ZirkelCanvas ZC; private Vector V=new Vector(); private static Image icon=themes.getImage("animation.png"); private int W=32, H=32, X=10, Y=47; private int minspeed=0; private int maxspeed=100; private int speed=40; private boolean stopped=false; private double a, b, A1, A2, B2; public void paintComponent(Graphics g) { g.drawImage(icon, 0, 0, W, H, this); } public int getMaxSpeed() { return maxspeed; } public AnimationPanel(ZirkelCanvas zc) { ZC=zc; setBounds(X, Y, W, H); addMouseListener(this); a=maxspeed/10; b=maxspeed-10; A1=b/a; A2=(maxspeed-b)/(maxspeed-a); B2=maxspeed*(b-a)/(maxspeed-a); } public double getDelay() { int cur=speed; double v; if (cur>a) { v=A2*cur+B2; } else { v=A1*cur; } double d=(maxspeed-v)*6; return d; } public void setDelay(double delay) { double cur=maxspeed-delay/6; if (cur>b) { speed=(int) ((cur-B2)/A2); } else { speed=(int) (cur/A1); } } public void showPopup() { JPopupMenu popup=new JPopupMenu(); // add Cancel Item : myJMenuItem item=new myJMenuItem(Global.Loc("animation.run")) { @Override public void action() { startAnimation(); } }; popup.add(item); item=new myJMenuItem(Global.Loc("animation.stop")) { @Override public void action() { stopAnimation(); } }; popup.add(item); item=new myJMenuItem(Global.Loc("animation.reverse")) { @Override public void action() { reverseAnimation(); } }; popup.add(item); popup.add(new JSeparator()); item=new myJMenuItem(Global.Loc("animation.removeall")) { @Override public void action() { removeAllAnimations(); } }; popup.add(item); popup.add(new JSeparator()); popup.add(new SpeedSliderMenuItem()); popup.show(this, W-10, H); } public Vector getAnimations() { return V; } public void reverseAnimation() { for (int i=0; i