Exemplo n.º 1
0
  /**
   * From the "animationInfo" set of animation properties, set all these values into all the
   * Animation objects held as memeber data.
   *
   * @param transfer AnimationInfo to get properties from
   */
  public void setProperties(AnimationInfo transfer) {
    setBoxPanelVisible(transfer.getBoxesVisible());
    animationInfo.set(transfer);
    setSharing(animationInfo.shared);
    if (animationInfo.getAnimationGroup() != null) {
      setShareGroup(animationInfo.getAnimationGroup());
    }
    if (propertiesDialog != null) {
      propertiesDialog.setInfo(animationInfo);
    }

    try {
      if (anime != null) {
        anime.setAnimationInfo(animationInfo);
        DisplayMaster displayMaster = anime.getDisplayMaster();
        if (displayMaster != null) {
          displayMaster.dataChange();
        } else {
          if (getAnimationSetInfo().getActive()) {
            anime.setSet(getAnimationSetInfo().makeTimeSet(null));
          } else {
            anime.setSet(getAnimationSetInfo().getBaseTimes());
          }
        }
      }
    } catch (Exception exp) {
      LogUtil.logException("Error setting properties", exp);
    }
    updateRunButton();
    checkAutoUpdate();
  }
Exemplo n.º 2
0
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   JFrame frame = new JFrame();
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   Animation panel = new Animation();
   frame.getContentPane().add(panel);
   frame.pack();
   frame.setVisible(true);
   frame.setFocusable(false);
   if (!panel.isFocusOwner()) panel.requestFocus();
 }
Exemplo n.º 3
0
 /**
  * Get the time at the given index. May return null.
  *
  * @param index Index
  * @return Time
  */
 public DateTime getTimeAtIndex(int index) {
   if (anime == null) {
     return null;
   }
   if (timesArray == null) {
     timesArray = Animation.getDateTimeArray(anime.getSet());
   }
   if ((timesArray == null) || (index < 0) || (index >= timesArray.length)) {
     return null;
   }
   return timesArray[index];
 }
Exemplo n.º 4
0
 /** Share the value of the animation step. */
 protected void shareValue() {
   Animation myAnimation = anime;
   AnimationInfo myAnimationInfo = animationInfo;
   if ((myAnimation != null) && (myAnimationInfo != null)) {
     if (myAnimation.getNumSteps() > 0) {
       if (animationInfo.getShareIndex()) {
         shareIndex();
       } else {
         shareValue(myAnimation.getAniValue());
       }
     }
   }
 }
Exemplo n.º 5
0
  private void paintAnimations(Graphics2D g2d) {

    LinkedList<Animation> toRemove = new LinkedList<Animation>();
    // get all the animations you can, forget about the ones that are about to be added
    animationLock.lock();
    List<Animation> toPaint = (List<Animation>) animations.clone();
    animationLock.unlock();
    for (Animation x : toPaint) {
      if (x.isOver()) toRemove.add(x);
      else x.step(g2d);
    }

    animations.removeAll(toRemove);
  }
Exemplo n.º 6
0
  /** Go to the end of the animation sequence. */
  public void gotoEnd() {
    if (anime != null) {
      visad.Set aset = anime.getSet();
      if (aset != null) {
        try {
          anime.setCurrent(aset.getLength() - 1);
        } catch (VisADException ve) {;
        }
      }
    }

    setRunning(false);
    // shareIndex ();
    shareValue();
  }
Exemplo n.º 7
0
 /** Take one step backward in the animation sequence. */
 protected void stepBackward() {
   if (anime != null) {
     anime.takeStepBackward();
   }
   // shareIndex ();
   shareValue();
 }
Exemplo n.º 8
0
  /**
   * Method called when sharing is turned on.
   *
   * @param from source of shareable information
   * @param dataId ID for the data
   * @param data the shareable data
   */
  public void receiveShareData(Sharable from, Object dataId, Object[] data) {

    if (dataId.equals(SHARE_INDEX)) {
      if (anime != null) {
        anime.setCurrent(((Integer) data[0]).intValue());
      }
    } else if (dataId.equals(SHARE_VALUE)) {
      Real sharedValue = (Real) data[0];
      debug("receiveShareData " + sharedValue);
      handleSharedTime(sharedValue);
    } else if (dataId.equals(CMD_STARTSTOP)) {
      setRunning(((Boolean) data[0]).booleanValue());
    } else if (dataId.equals(CMD_FORWARD)) {
      stepForward();
    } else if (dataId.equals(CMD_BACKWARD)) {
      stepBackward();
    } else if (dataId.equals(CMD_BEGINNING)) {
      gotoBeginning();
    } else if (dataId.equals(CMD_END)) {
      gotoEnd();
    } else if (dataId.equals(CMD_PROPS)) {
      AnimationInfo newInfo = (AnimationInfo) data[0];
      if (propertiesDialog != null) {
        newInfo.shared = getSharing();
        propertiesDialog.setInfo(newInfo);
      }
      setProperties(newInfo);
    } else {
      super.receiveShareData(from, dataId, data);
    }
  }
Exemplo n.º 9
0
 /**
  * Set the current frame to the index supplied. Turn off animation This ignores any frames the
  * user may have turned off
  *
  * @param index index into the animation set
  */
 public void gotoIndex(int index) {
   if (anime != null) {
     setRunning(false);
     anime.setCurrent(index, false);
   }
   shareValue();
 }
Exemplo n.º 10
0
 /**
  * Set the times that should be used. If this is set we don't go to the displaymaster to get the
  * times.
  *
  * @param times List of times
  * @throws RemoteException On badness
  * @throws VisADException On badness
  */
 public void setBaseTimes(Set times) throws VisADException, RemoteException {
   getAnimationSetInfo().setBaseTimes(times);
   if (times != null) {
     if (anime != null) {
       if (getAnimationSetInfo().getActive()) {
         Set newSet = getAnimationSetInfo().makeTimeSet(null);
         anime.setSet(newSet);
       } else {
         anime.setSet(times);
       }
       updateIndicator(anime.getSet());
     }
   } else {
     updateIndicator(null);
   }
 }
Exemplo n.º 11
0
 /**
  * Remove the listener from the Animation. Called when object is destroyed.
  *
  * @see #destroy
  */
 private void removeAnimationListener() {
   if ((anime != null) && (animationListener != null)) {
     anime.removePropertyChangeListener(animationListener);
     animationListener = null;
     anime = null;
   }
 }
Exemplo n.º 12
0
 /** Take one step forward in the animation sequence. */
 public void stepForward() {
   if (anime != null) {
     anime.takeStepForward();
   }
   // shareIndex ();
   shareValue();
 }
Exemplo n.º 13
0
 /**
  * The user has clicked on the box. Pass this through to the animation
  *
  * @param stepsOk What time steps are ok
  */
 public void stepsOkChanged(boolean[] stepsOk) {
   try {
     anime.setStepsOk(stepsOk);
   } catch (Exception exp) {
     LogUtil.logException("Error setting steps ok", exp);
   }
 }
Exemplo n.º 14
0
 /**
  * Handles the keyboard input.
  *
  * @param elapsed time elapsed since the last frame
  */
 private void handleControllerInput(float elapsed) {
   if (controllerActive) {
     if (controller.justPressed(KeyEvent.VK_A)) {
       simpleAttack();
     }
     if (state == DynamicObjectState.Attacking) {
       curAnim.update(elapsed);
       return;
     } else if (controller.justPressed(KeyEvent.VK_S)) spellAttack(0);
     else if (controller.justPressed(KeyEvent.VK_D)) spellAttack(1);
     else if (controller.justPressed(KeyEvent.VK_F)) spellAttack(2);
     else if (controller.justPressed(KeyEvent.VK_5)) spellManager.activateShield(ElementType.Fire);
     else if (controller.justPressed(KeyEvent.VK_6))
       spellManager.activateShield(ElementType.Water);
     else if (controller.justPressed(KeyEvent.VK_7))
       spellManager.activateShield(ElementType.Earth);
     else if (controller.isDownPressed()) move(Heading.Down);
     else if (controller.isUpPressed()) move(Heading.Up);
     else if (controller.isLeftPressed()) move(Heading.Left);
     else if (controller.isRightPressed()) move(Heading.Right);
     else if (controller.justReleased(KeyEvent.VK_LEFT)
         || controller.justReleased(KeyEvent.VK_RIGHT)
         || controller.justReleased(KeyEvent.VK_UP)
         || controller.justReleased(KeyEvent.VK_DOWN)) stopMovement();
     else if (controller.justPressed(KeyEvent.VK_ENTER)) collision.checkOnKeyTriggers(this);
   }
 }
Exemplo n.º 15
0
  public void draw(Graphics g) {
    // draw background
    g.drawImage(bgImage, 0, 0, null);

    // draw image
    g.drawImage(anim.getImage(), 0, 0, null);
  }
Exemplo n.º 16
0
 /**
  * Sets the <CODE>ucar.visad.display.Animation</CODE> controlled by this widget. Removes any other
  * <CODE>ucar.visad.display.Animation</CODE> from the control of this widget.
  *
  * @param newAnimation ucar.visad.display.Animation to control
  */
 public void setAnimation(Animation newAnimation) {
   if (newAnimation == null) {
     throw new NullPointerException("Animation can't be null");
   }
   removeAnimationListener();
   anime = newAnimation;
   animationInfo.set(anime.getAnimationInfo());
   updateIndicator(anime.getSet());
   animationListener =
       new PropertyChangeListener() {
         public void propertyChange(PropertyChangeEvent evt) {
           handleAnimationPropertyChange(evt);
         }
       };
   anime.addPropertyChangeListener(animationListener);
 }
Exemplo n.º 17
0
  public void loadImages() {
    // load images
    bgImage = loadImage("images/background.jpg");
    Image player1 = loadImage("images/player1.png");
    Image player2 = loadImage("images/player2.png");
    Image player3 = loadImage("images/player3.png");

    // create animation
    anim = new Animation();
    anim.addFrame(player1, 250);
    anim.addFrame(player2, 150);
    anim.addFrame(player1, 150);
    anim.addFrame(player2, 150);
    anim.addFrame(player3, 200);
    anim.addFrame(player2, 150);
  }
Exemplo n.º 18
0
 /** Go to the beginning of the animation sequence. */
 public void gotoBeginning() {
   if (anime != null) {
     anime.setCurrent(0);
   }
   setRunning(false);
   // shareIndex ();
   shareValue();
 }
Exemplo n.º 19
0
  // Overrides Animation.animate()
  @Override
  public void animate() {

    // Move the image
    moveIt(xSpeed, ySpeed);
    super.animate();

    // Move the underlying Rectangle
    setLocation(x, y);
  }
Exemplo n.º 20
0
 /**
  * Update the state of the box panel with the animation set
  *
  * @param timesArray Array of times in set
  */
 private void updateBoxPanel(DateTime[] timesArray) {
   if (boxPanel != null) {
     boxPanel.setNumTimes(timesArray.length);
     if (anime != null) {
       boxPanel.setOnIndex(anime.getCurrent());
     }
     if (propertiesDialog != null) {
       propertiesDialog.boxPanel.applyProperties(this.boxPanel);
     }
   }
 }
Exemplo n.º 21
0
  /**
   * Contruct a new AnimationWidget.
   *
   * @param parentf the parent JFrame
   * @param anim a ucar.visad.display.Animation object to manage
   * @param info Default values for the AnimationInfo
   */
  public AnimationWidget(JFrame parentf, Animation anim, AnimationInfo info) {

    // Initialize sharing to true
    super("AnimationWidget", true);
    timesCbx =
        new JComboBox() {
          public String getToolTipText(MouseEvent event) {
            if (boxPanel != null) {
              return boxPanel.getToolTipText();
            }
            return " ";
          }
        };
    timesCbx.setToolTipText("");
    timesCbxMutex = timesCbx.getTreeLock();
    timesCbx.setFont(new Font("Dialog", Font.PLAIN, 9));
    timesCbx.setLightWeightPopupEnabled(false);
    // set to non-visible until items are added
    timesCbx.setVisible(false);
    timesCbx.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (!ignoreTimesCbxEvents && (anime != null)) {
              debug("got timesCbx event");
              setTimeFromUser((Real) timesCbx.getSelectedItem());
              if (boxPanel != null) {
                boxPanel.setOnIndex(timesCbx.getSelectedIndex());
              }
            }
          }
        });

    animationInfo = new AnimationInfo();
    if (anim != null) {
      setAnimation(anim);
    }
    if (anime != null) {
      animationInfo.set(anime.getAnimationInfo());
    }
    if (info != null) {
      setProperties(info);
      animationInfo.setRunning(info.getRunning());
    }

    boxPanel = new AnimationBoxPanel(this);
    if (timesArray != null) {
      updateBoxPanel(timesArray);
    }
  }
Exemplo n.º 22
0
  /**
   * The animation changed. Handle the change.
   *
   * @param evt The event
   */
  private void handleAnimationPropertyChange(PropertyChangeEvent evt) {
    //        System.err.println ("Handlechange:" +evt.getPropertyName());
    if (evt.getPropertyName().equals(Animation.ANI_VALUE)) {
      debug("handleAnimationPropertyChange value :" + evt.getPropertyName());
      Real eventValue = (Real) evt.getNewValue();
      // if there's nothing to do, return;
      if ((eventValue == null) || eventValue.isMissing()) {
        return;
      }

      /** The Animation associated with this widget */
      DateTime time = null;
      try {
        time = new DateTime(eventValue);
      } catch (VisADException ve) {;
      }
      final DateTime theDateTime = time;
      final int theIndex = ((anime != null) ? anime.getCurrent() : -1);
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              boolean oldValue = ignoreTimesCbxEvents;
              try {
                ignoreTimesCbxEvents = true;
                //                        synchronized (timesCbxMutex) {
                xcnt++;

                timesCbx.setSelectedItem(theDateTime);
                //                        }
                if ((boxPanel != null) && (theIndex >= 0)) {
                  boxPanel.setOnIndex(theIndex);
                }
                timesCbx.repaint();
              } finally {
                ignoreTimesCbxEvents = oldValue;
              }
            }
          });
      shareValue();
    } else if (evt.getPropertyName().equals(Animation.ANI_SET)) {
      if (ignoreAnimationSetChange) {
        return;
      }
      updateIndicatorInner((Set) evt.getNewValue(), true);
    }
  }
Exemplo n.º 23
0
 /**
  * Set the animation state and change the start/stop widget
  *
  * @param state true to start animating
  */
 public void setRunning(boolean state) {
   // Check to make sure don't infinitely loop
   if (settingStartStop) {
     return;
   }
   settingStartStop = true;
   animationInfo.setRunning(state);
   if (anime != null) {
     anime.setAnimating(state);
   }
   if (!state) {
     doShare(CMD_STARTSTOP, new Boolean(state));
   }
   shareValue();
   updateRunButton();
   settingStartStop = false;
 }
  public void frameTest() {
    Image TestImage;
    Image TestImage2;
    TestImage = loadImage("images/Tank.jpg");
    TestImage2 = loadImage("images/Tank.jpg");
    Animation AnimTest = new Animation();
    AnimTest.addFrame(TestImage, 200);

    Animation AnimTest2 = new Animation();
    AnimTest2.addFrame(TestImage2, 500);
    System.out.println(AnimTest.getImage());
    System.out.println(AnimTest2.getImage());
  }
Exemplo n.º 25
0
  /**
   * _more_
   *
   * @param timeSet _more_
   * @param timeSetChange _more_
   */
  private void updateIndicatorInner(Set timeSet, boolean timeSetChange) {
    //      timeSet  = checkAnimationSet(timeSet);
    timesArray = Animation.getDateTimeArray(timeSet);

    // Stop running if there are no times
    if ((timesArray.length == 0) && timeSetChange) {
      setRunning(false);
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            // Only set the list data if we have created the gui contents
            if (madeContents) {
              setTimesInTimesBox();
              updateRunButton();
            }
          }
        });
    updateBoxPanel(timesArray);
  }
Exemplo n.º 26
0
  public void animationLoop() {
    long startTime = System.currentTimeMillis();
    long currTime = startTime;

    while (currTime - startTime < DEMO_TIME) {
      long elapsedTime = System.currentTimeMillis() - currTime;
      currTime += elapsedTime;

      // update animation
      anim.update(elapsedTime);

      // draw to screen
      Graphics g = screen.getFullScreenWindow().getGraphics();
      draw(g);
      g.dispose();

      // take a nap
      try {
        Thread.sleep(20);
      } catch (InterruptedException ex) {
      }
    }
  }
Exemplo n.º 27
0
 /**
  * Are we running
  *
  * @return Is running
  */
 public boolean isRunning() {
   if (anime != null) {
     return anime.isAnimating();
   }
   return false;
 }
Exemplo n.º 28
0
  public static Geoset read(BufferedReader mdl) {
    String line = MDLReader.nextLine(mdl);
    System.out.println("geo begins with " + line);
    if (line.contains("Geoset")) {
      line = MDLReader.nextLine(mdl);
      Geoset geo = new Geoset();
      if (!line.contains("Vertices")) {
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: Vertices not found at beginning of Geoset!");
      }
      while (!((line = MDLReader.nextLine(mdl)).contains("\t}"))) {
        geo.addVertex(GeosetVertex.parseText(line));
      }
      line = MDLReader.nextLine(mdl);
      if (line.contains("Normals")) {
        // If we have normals:
        while (!((line = MDLReader.nextLine(mdl)).contains("\t}"))) {
          geo.addNormal(Normal.parseText(line));
        }
      }
      while (((line = MDLReader.nextLine(mdl)).contains("TVertices"))) {
        geo.addUVLayer(UVLayer.read(mdl));
      }
      if (!line.contains("VertexGroup")) {
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: VertexGroups missing or invalid!");
      }
      int i = 0;
      while (!((line = MDLReader.nextLine(mdl)).contains("\t}"))) {
        geo.getVertex(i).setVertexGroup(MDLReader.readInt(line));
        i++;
      }
      line = MDLReader.nextLine(mdl);
      if (!line.contains("Faces")) {
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: Faces missing or invalid!");
      }
      line = MDLReader.nextLine(mdl);
      if (!line.contains("Triangles")) {
        System.out.println(line);
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: Triangles missing or invalid!");
      }
      geo.setTriangles(Triangle.read(mdl, geo));
      line = MDLReader.nextLine(mdl); // Throw away the \t} closer for faces
      line = MDLReader.nextLine(mdl);
      if (!line.contains("Groups")) {
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: Groups (Matrices) missing or invalid!");
      }
      while (!((line = MDLReader.nextLine(mdl)).contains("\t}"))) {
        geo.addMatrix(Matrix.parseText(line));
      }
      MDLReader.mark(mdl);
      line = MDLReader.nextLine(mdl);
      while (!line.contains("}") || line.contains("},")) {
        if (line.contains("Extent") || line.contains("BoundsRadius")) {
          System.out.println("Parsing geoset extLog:" + line);
          MDLReader.reset(mdl);
          geo.setExtLog(ExtLog.read(mdl));
          System.out.println("Completed geoset extLog.");
        } else if (line.contains("Anim")) {
          MDLReader.reset(mdl);
          geo.add(Animation.read(mdl));
          MDLReader.mark(mdl);
        } else if (line.contains("MaterialID")) {
          geo.materialID = MDLReader.readInt(line);
          MDLReader.mark(mdl);
        } else if (line.contains("SelectionGroup")) {
          geo.selectionGroup = MDLReader.readInt(line);
          MDLReader.mark(mdl);
        } else {
          geo.addFlag(MDLReader.readFlag(line));
          System.out.println("Reading to geoFlag: " + line);
          MDLReader.mark(mdl);
        }
        line = MDLReader.nextLine(mdl);
      }
      //             JOptionPane.showMessageDialog(MDLReader.getDefaultContainer(),"Geoset reading
      // completed!");
      System.out.println("Geoset reading completed!");

      return geo;
    } else {
      JOptionPane.showMessageDialog(
          MDLReader.getDefaultContainer(),
          "Unable to parse Geoset: Missing or unrecognized open statement '" + line + "'.");
    }
    return null;
  }
Exemplo n.º 29
0
 /**
  * Get the array of times
  *
  * @return times
  */
 public DateTime[] getTimes() {
   return anime.getTimes();
 }
Exemplo n.º 30
0
 /** Share the index of the animation step. */
 protected void shareIndex() {
   doShare(SHARE_INDEX, new Integer(anime.getCurrent()));
 }