⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 activity.java

📁 用applet实现很多应用小程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            fireActivityScheduled();
    }
    
    /**
     * Sets a flag indicating whether or not this activity is currently running
     * @param s the new running state of this activity
     */
    synchronized boolean setRunning(boolean s) {
        boolean b = m_isRunning;
        m_isRunning = s;
        return b;
    }
    
    /**
     * Indicates if this activity is currently running.
     * @return true if running, false otherwise
     */
    public synchronized boolean isRunning() {
        return m_isRunning;
    }
    
    // ------------------------------------------------------------------------
    // Activity Listeners
    
    /**
     * Add an ActivityListener to monitor this activity's events.
     * @param l the ActivityListener to add
     */
    public void addActivityListener(ActivityListener l) {
        if ( m_listeners == null )
            m_listeners = new CopyOnWriteArrayList();
        if ( !m_listeners.contains(l) )
            m_listeners.add(l);
    }
    
    /**
     * Remove a registered ActivityListener
     * @param l the ActivityListener to remove
     */
    public void removeActivityListener(ActivityListener l) {
        if ( m_listeners == null )
            return;
        m_listeners.remove(l);
        if ( m_listeners.size() == 0 )
            m_listeners = null;
    }

    protected void fireActivityScheduled() {
        if ( m_listeners == null ) return;
        Object[] a = m_listeners.getArray();
        for ( int i=0; i<a.length; ++i ) {
            ((ActivityListener)a[i]).activityScheduled(this);
        }
    }
    
    protected void fireActivityStarted() {
        if ( m_listeners == null ) return;
        Object[] a = m_listeners.getArray();
        for ( int i=0; i<a.length; ++i ) {
            ((ActivityListener)a[i]).activityStarted(this);
        }
    }
    
    protected void fireActivityStepped() {
        if ( m_listeners == null ) return;
        Object[] a = m_listeners.getArray();
        for ( int i=0; i<a.length; ++i ) {
            ((ActivityListener)a[i]).activityStepped(this);
        }
    }
    
    protected void fireActivityFinished() {
        if ( m_listeners == null ) return;
        Object[] a = m_listeners.getArray();
        for ( int i=0; i<a.length; ++i ) {
            ((ActivityListener)a[i]).activityFinished(this);
        }
    }
    
    protected void fireActivityCancelled() {
        if ( m_listeners == null ) return;
        Object[] a = m_listeners.getArray();
        for ( int i=0; i<a.length; ++i ) {
            ((ActivityListener)a[i]).activityCancelled(this);
        }
    }
    
    // ------------------------------------------------------------------------
    // Accessor / Mutator Methods
    
    /**
     * Returns a value between 0 and 1 inclusive, indicating the current
     * position in an animation or other similarly parameterized activity.
     * The returned value is determined by consulting this Activity's
     * pacing function.
     * @param elapsedTime the time in milliseconds since the start of this
     *  Activity.
     * @return a value between 0 and 1 indicating the current position in
     *  an animation.
     * @see prefuse.activity.Activity#getPacingFunction()
     */
    public double getPace(long elapsedTime) {
        long duration = getDuration();
        double frac = (duration == 0L ? 0.0 : ((double)elapsedTime)/duration);
        frac = Math.min(1, Math.max(0, frac));
        return m_pacer!=null ? m_pacer.pace(frac) : frac;
    }
    
    /**
     * Returns the pacing function associated with this Activity. Pacing
     * functions are used to control the pace of animations.
     * @return this Activity's pacing function. A value of null indicates a
     *  basic, linear pace is used, moving from 0 to 1 uniformly over time.
     */
    public synchronized Pacer getPacingFunction() {
        return m_pacer;
    }
    
    /**
     * Sets the pacing function associated with this Activity. Pacing
     * functions are used to control the pace of animations.
     * @param pfunc this Activity's new pacing function, or null to
     *  indicate a basic, linear pace moving from 0 to 1 uniformly
     *  over time.
     */
    public synchronized void setPacingFunction(Pacer pfunc) {
        m_pacer = pfunc;
    }
    
    /**
     * Get the time at which this activity should complete.
     * @return the stopping time for this activity, or Long.MAX_VALUE
     *  if this activity should run indefinitely.
     */
    public long getStopTime() {
        if (m_duration == -1) {
            return Long.MAX_VALUE;
        }
        return m_startTime + m_duration;
    }
    
    /**
     * Get the time at which this activity should be run next.
     * @return the time this activity should run next
     */
    public long getNextTime() {
        return m_nextTime;
    }
    
    /**
     * Returns the duration of this activity
     * @return the duration of this activity, in milliseconds
     */
    public long getDuration() {
        return m_duration;
    }

    /**
     * Set the duration of this activity
     * @param duration The new duration, in milliseconds, for this activity.
     *  A value of {@link #INFINITY} indicates that this activity should run
     *  indefinitely.
     */
    public void setDuration(long duration) {
        this.m_duration = duration;
    }

    /**
     * Returns this activity's start time
     * @return the starting time for this activity
     */
    public long getStartTime() {
        return m_startTime;
    }

    /**
     * Sets this activity's start time
     * @param time the new starting time for this activity
     */
    public void setStartTime(long time) {
        m_startTime = time;
    }

    /**
     * Returns the delay between runs for this activity
     * @return the step time between runs of this activity
     */
    public long getStepTime() {
        return m_stepTime;
    }

    /**
     * Sets the delay between runs for this activity
     * @param time the new step time between runs of this activity
     */
    public void setStepTime(long time) {
        m_stepTime = time;
    }
    
    /**
     * Indicates whether or not this activity is currently enabled.
     * @return true if enabled, false otherwise
     */
    public boolean isEnabled() {
        return m_enabled;
    }
    
    /**
     * Sets whether this component is enabled.
     * @param s true to enable component, false to disable it
     */
    public void setEnabled(boolean s) {
        m_enabled = s;
    }
    
} // end of class Activity

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -