Esempio 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();
  }
Esempio 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();
 }
Esempio 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];
 }
Esempio 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());
       }
     }
   }
 }
Esempio 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);
  }
Esempio 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();
  }
Esempio n. 7
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);
   }
 }
Esempio n. 8
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;
   }
 }
Esempio n. 9
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);
 }
Esempio n. 10
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);
    }
  }
Esempio n. 11
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);
   }
 }
Esempio n. 12
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();
 }
Esempio n. 13
0
 /** Take one step forward in the animation sequence. */
 public void stepForward() {
   if (anime != null) {
     anime.takeStepForward();
   }
   // shareIndex ();
   shareValue();
 }
Esempio n. 14
0
 /** Take one step backward in the animation sequence. */
 protected void stepBackward() {
   if (anime != null) {
     anime.takeStepBackward();
   }
   // shareIndex ();
   shareValue();
 }
Esempio n. 15
0
 /** Go to the beginning of the animation sequence. */
 public void gotoBeginning() {
   if (anime != null) {
     anime.setCurrent(0);
   }
   setRunning(false);
   // shareIndex ();
   shareValue();
 }
Esempio n. 16
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);
     }
   }
 }
Esempio n. 17
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);
    }
  }
Esempio n. 18
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;
 }
Esempio n. 19
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);
    }
  }
Esempio n. 20
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);
  }
Esempio n. 21
0
 /**
  * Get the array of times
  *
  * @return times
  */
 public DateTime[] getTimes() {
   return anime.getTimes();
 }
Esempio 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);
   }
 }
Esempio n. 23
0
 /** Share the index of the animation step. */
 protected void shareIndex() {
   doShare(SHARE_INDEX, new Integer(anime.getCurrent()));
 }
Esempio 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();
 }
Esempio n. 25
0
 /**
  * Are we running
  *
  * @return Is running
  */
 public boolean isRunning() {
   if (anime != null) {
     return anime.isAnimating();
   }
   return false;
 }
Esempio n. 26
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;
 }