Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AbstractTimeLineView.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 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.timeline.ui;
20 
21 import com.google.common.collect.ImmutableList;
22 import com.google.common.eventbus.Subscribe;
23 import java.util.concurrent.ExecutionException;
24 import java.util.logging.Level;
25 import javafx.application.Platform;
26 import javafx.beans.InvalidationListener;
27 import javafx.beans.Observable;
28 import javafx.beans.property.ReadOnlyBooleanProperty;
29 import javafx.beans.property.ReadOnlyBooleanWrapper;
30 import javafx.concurrent.Task;
31 import javafx.scene.Cursor;
32 import javafx.scene.Node;
33 import javafx.scene.layout.BorderPane;
34 import javafx.scene.layout.StackPane;
35 import org.controlsfx.control.MaskerPane;
36 import org.openide.util.NbBundle;
44 
49 public abstract class AbstractTimeLineView extends BorderPane {
50 
51  private static final Logger LOGGER = Logger.getLogger(AbstractTimeLineView.class.getName());
52 
57  private final ReadOnlyBooleanWrapper hasVisibleEvents = new ReadOnlyBooleanWrapper(true);
58 
64  private final ReadOnlyBooleanWrapper outOfDate = new ReadOnlyBooleanWrapper(false);
65 
70  private InvalidationListener updateListener = (Observable any) -> refresh();
71 
75  private Task<Boolean> updateTask;
76 
79 
86  this.controller = controller;
87  this.filteredEvents = controller.getEventsModel();
88  this.filteredEvents.registerForEvents(this);
89  this.filteredEvents.zoomParametersProperty().addListener(updateListener);
90  TimeLineController.getTimeZone().addListener(updateListener);
91  }
92 
99  @Subscribe
101  refresh();
102  }
103 
110  public boolean isOutOfDate() {
111  return outOfDate.get();
112  }
113 
121  public ReadOnlyBooleanProperty outOfDateProperty() {
122  return outOfDate.getReadOnlyProperty();
123  }
124 
131  return controller;
132  }
133 
141  protected final synchronized void refresh() {
142  if (updateTask != null) {
143  updateTask.cancel(true);
144  updateTask = null;
145  }
146  updateTask = getNewUpdateTask();
147  updateTask.stateProperty().addListener((Observable observable) -> {
148  switch (updateTask.getState()) {
149  case CANCELLED:
150  case FAILED:
151  case READY:
152  case RUNNING:
153  case SCHEDULED:
154  break;
155  case SUCCEEDED:
156  try {
157  this.hasVisibleEvents.set(updateTask.get());
158  } catch (InterruptedException | ExecutionException ex) {
159  LOGGER.log(Level.SEVERE, "Unexpected exception updating view", ex); //NON-NLS
160  }
161  break;
162  }
163  });
164  getController().monitorTask(updateTask);
165  }
166 
173  return filteredEvents;
174  }
175 
183  protected abstract Task<Boolean> getNewUpdateTask();
184 
190  protected abstract ViewMode getViewMode();
191 
198  abstract protected ImmutableList<Node> getSettingsControls();
199 
206  abstract protected boolean hasCustomTimeNavigationControls();
207 
214  abstract protected ImmutableList<Node> getTimeNavigationControls();
215 
219  final synchronized void dispose() {
220  //cancel and gc updateTask
221  if (updateTask != null) {
222  updateTask.cancel(true);
223  updateTask = null;
224  }
225  //remvoe and gc updateListener
226  this.filteredEvents.zoomParametersProperty().removeListener(updateListener);
227  TimeLineController.getTimeZone().removeListener(updateListener);
228  updateListener = null;
229  filteredEvents.unRegisterForEvents(this);
230  controller.unRegisterForEvents(this);
231  }
232 
240  boolean hasVisibleEvents() {
241  return hasVisibleEventsProperty().get();
242  }
243 
251  ReadOnlyBooleanProperty hasVisibleEventsProperty() {
252  return hasVisibleEvents.getReadOnlyProperty();
253  }
254 
259  void setOutOfDate() {
260  outOfDate.set(true);
261  }
262 
266  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
267  abstract protected void clearData();
268 
275  protected abstract class ViewRefreshTask<AxisValuesType> extends LoggedTask<Boolean> {
276 
277  private final Node center;
278 
286  protected ViewRefreshTask(String taskName, boolean logStateChanges) {
287  super(taskName, logStateChanges);
288  this.center = getCenter();
289  }
290 
301  @NbBundle.Messages(value = {"ViewRefreshTask.preparing=Analyzing zoom and filter settings"})
302  @Override
303  protected Boolean call() throws Exception {
304  updateProgress(-1, 1);
305  updateMessage(Bundle.ViewRefreshTask_preparing());
306  Platform.runLater(() -> {
307  MaskerPane maskerPane = new MaskerPane();
308  maskerPane.textProperty().bind(messageProperty());
309  maskerPane.progressProperty().bind(progressProperty());
310  setCenter(new StackPane(center, maskerPane));
311  setCursor(Cursor.WAIT);
312  });
313  return true;
314  }
315 
321  @Override
322  protected void succeeded() {
323  super.succeeded();
324  outOfDate.set(false);
325  cleanup();
326  }
327 
332  @Override
333  protected void cancelled() {
334  super.cancelled();
335  cleanup();
336  }
337 
342  @Override
343  protected void failed() {
344  super.failed();
345  cleanup();
346  }
347 
352  private void cleanup() {
353  setCenter(center); //clear masker pane installed in call()
354  setCursor(Cursor.DEFAULT);
355  }
356 
363  protected abstract void setDateValues(AxisValuesType values);
364 
372  protected void resetView(AxisValuesType axisValues) {
373  Platform.runLater(() -> {
374  clearData();
375  setDateValues(axisValues);
376  });
377  }
378  }
379 }
static ReadOnlyObjectProperty< TimeZone > getTimeZone()
abstract ImmutableList< Node > getTimeNavigationControls()
synchronized ReadOnlyObjectProperty< ZoomParams > zoomParametersProperty()
abstract ImmutableList< Node > getSettingsControls()
synchronized void monitorTask(final Task<?> task)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.