Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
SwingAnimator.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.discovery.ui;
20 
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import javax.swing.Timer;
24 
33 final class SwingAnimator {
34 
35  //callback object
36  private final SwingAnimatorCallback callback;
37 
38  //Timer to animate on the EDT
39  private Timer timer = null;
40 
41  //duration in milliseconds betweeen each firing of the Timer
42  private static final int INITIAL_TIMING = 30;
43  private int timing = INITIAL_TIMING;
44 
52  SwingAnimator(SwingAnimatorCallback callback) {
53  this(callback, INITIAL_TIMING);
54  }
55 
64  SwingAnimator(SwingAnimatorCallback callback, int frameTiming) {
65  this.callback = callback;
66  timing = frameTiming;
67  }
68 
76  boolean isRunning() {
77  if (timer == null) {
78  return false;
79  }
80  return timer.isRunning();
81  }
82 
88  void stop() {
89  if (timer != null) {
90  timer.stop();
91  }
92  }
93 
99  void start() {
100  if (timer != null && timer.isRunning()) {
101  stop();
102  }
103  timer = new Timer(timing, new CallbackListener());
104  timer.start();
105  }
106 
112  private class CallbackListener implements ActionListener {
113 
114  @Override
115  public void actionPerformed(ActionEvent e) {
116  if (callback.hasTerminated()) {
117  if (timer == null) {
118  throw new IllegalStateException("Callback listener should not be fired outside of SwingAnimator timer control");
119  }
120  timer.stop();
121  }
122  callback.callback(SwingAnimator.this);
123  }
124  }
125 
126 }

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.