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
 /**
  * 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.º 3
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.º 4
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.º 5
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.º 6
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Pixel[][] pixels = game.getDisplay();
    for (Pixel[] row : pixels) {
      for (Pixel pixel : row) {
        game.getPixelType(pixel.id).draw(pixel, game, g);
      }
    }
    List<Animation> animations = game.getAnimations();

    for (Animation a : animations) {
      a.draw(g);
    }
    frames++;
  }
Exemplo n.º 7
0
 /** Take one step forward in the animation sequence. */
 public void stepForward() {
   if (anime != null) {
     anime.takeStepForward();
   }
   // shareIndex ();
   shareValue();
 }
Exemplo n.º 8
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.º 9
0
 /** Take one step backward in the animation sequence. */
 protected void stepBackward() {
   if (anime != null) {
     anime.takeStepBackward();
   }
   // shareIndex ();
   shareValue();
 }
Exemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
0
 /** Go to the beginning of the animation sequence. */
 public void gotoBeginning() {
   if (anime != null) {
     anime.setCurrent(0);
   }
   setRunning(false);
   // shareIndex ();
   shareValue();
 }
Exemplo n.º 15
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.º 16
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.º 17
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;
 }
Exemplo n.º 18
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.º 19
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.º 20
0
 /**
  * Get the display master that the animation is in
  *
  * @return The display master or null
  */
 protected DisplayMaster getDisplayMaster() {
   if (anime != null) {
     return anime.getDisplayMaster();
   }
   return null;
 }
 public boolean finished(float time) {
   return animation.finished(time);
 }
Exemplo n.º 22
0
 /**
  * We got the tiem from another animation widget.
  *
  * @param time The time.
  */
 protected void handleSharedTime(Real time) {
   if (anime != null) {
     anime.setAniValue(time);
   }
 }
Exemplo n.º 23
0
 /**
  * Get the array of times
  *
  * @return times
  */
 public DateTime[] getTimes() {
   return anime.getTimes();
 }
Exemplo n.º 24
0
 /**
  * THis allows external code to set the time. It sets the time on the animation and it does a
  * doShare.
  *
  * @param time The time
  */
 public void setTimeFromUser(Real time) {
   anime.setAniValue(time);
   //        shareValue(time);
   shareValue();
 }
 public void draw(float time) {
   animation.apply(form, time);
   appearance.draw(form);
 }
Exemplo n.º 26
0
 /**
  * Are we running
  *
  * @return Is running
  */
 public boolean isRunning() {
   if (anime != null) {
     return anime.isAnimating();
   }
   return false;
 }
Exemplo n.º 27
0
 /** Share the index of the animation step. */
 protected void shareIndex() {
   doShare(SHARE_INDEX, new Integer(anime.getCurrent()));
 }