initial commit towards HistoryManager implementation

This commit is contained in:
jmillman 2014-08-25 16:10:21 -04:00
parent 68096c5137
commit 2152129115
2 changed files with 99 additions and 15 deletions

View File

@ -0,0 +1,94 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2014 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.timeline;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javax.annotation.concurrent.GuardedBy;
import org.sleuthkit.autopsy.coreutils.ObservableStack;
/**
*
*/
public class HistoryManager<T> {
/** list based stack to hold history, 'top' is at index 0; */
@GuardedBy("this")
private final ObservableStack<T> historyStack = new ObservableStack<>();
@GuardedBy("this")
private final ObservableStack<T> forwardStack = new ObservableStack<>();
private final ReadOnlyObjectWrapper<T> currentState = new ReadOnlyObjectWrapper<>();
public ReadOnlyObjectWrapper<T> getCurrentState() {
return currentState;
}
public T currentState() {
return currentState.get();
}
synchronized public ObservableStack<T> getHistoryStack() {
return historyStack;
}
synchronized public ObservableStack<T> getForwardStack() {
return forwardStack;
}
synchronized public T advance() {
final T peek = forwardStack.peek();
if (peek != null && peek.equals(currentState.get()) == false) {
historyStack.push(currentState.get());
currentState.set(peek);
forwardStack.pop();
}
return peek;
}
synchronized public T retreat() {
final T peek = historyStack.peek();
if (peek != null && peek.equals(currentState.get()) == false) {
forwardStack.push(currentState.get());
currentState.set(peek);
} else if (peek != null && peek.equals(currentState)) {
historyStack.pop();
return retreat();
}
return peek;
}
synchronized private void advance(T newState) {
if (currentState.equals(newState) == false) {
historyStack.push(currentState.get());
currentState.set(newState);
if (newState.equals(forwardStack.peek())) {
forwardStack.pop();
} else {
forwardStack.clear();
}
}
}
}

View File

@ -529,22 +529,14 @@ public class TimeLineController {
return peek; return peek;
} }
@Deprecated
synchronized public void popZoomUpTo(ZoomParams zCrumb) {
ZoomParams popped = historyStack.peek();
while (popped.equals(zCrumb) == false) {
popped = historyStack.pop();
}
pushZoom(zCrumb);
}
synchronized private void pushZoom(ZoomParams zCrumb, boolean force) { synchronized private void pushZoom(ZoomParams zCrumb) {
final ZoomParams currentZoom = filteredEvents.getRequestedZoomParamters().get(); final ZoomParams currentZoom = filteredEvents.getRequestedZoomParamters().get();
if (force || currentZoom.equals(zCrumb) == false) { if ( currentZoom.equals(zCrumb) == false) {
historyStack.push(currentZoom); historyStack.push(currentZoom);
filteredEvents.requestZoomState(zCrumb, force); filteredEvents.requestZoomState(zCrumb, false);
if (zCrumb.equals(forwardStack.peek())) { if (zCrumb.equals(forwardStack.peek())) {
forwardStack.pop(); forwardStack.pop();
} else { } else {
@ -553,9 +545,7 @@ public class TimeLineController {
} }
} }
synchronized private void pushZoom(ZoomParams zCrumb) {
pushZoom(zCrumb, false);
}
public void selectTimeAndType(Interval interval, EventType type) { public void selectTimeAndType(Interval interval, EventType type) {
final Interval timeRange = filteredEvents.getSpanningInterval().overlap(interval); final Interval timeRange = filteredEvents.getSpanningInterval().overlap(interval);