Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
StateManager.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 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.communications;
20 
21 import com.google.common.eventbus.Subscribe;
22 import java.util.HashSet;
23 import java.util.Set;
26 import org.sleuthkit.datamodel.CommunicationsFilter;
27 
33 final class StateManager {
34 
35  private final History<CommunicationsState> historyManager = new History<>();
36  private CommunicationsFilter comFilter;
37  private final PinnedAccountModel pinModel;
38  private DateControlState currentStartState;
39  private DateControlState currentEndState;
40 
46  public StateManager(PinnedAccountModel pinModel){
47  this.pinModel = pinModel;
48  CVTEvents.getCVTEventBus().register(this);
49  }
50 
51  @Subscribe
52  void pinAccount(CVTEvents.PinAccountsEvent pinEvent) {
53  if(pinEvent.isReplace()){
54  HashSet<AccountDeviceInstanceKey> pinnedList = new HashSet<>();
55  pinnedList.addAll(pinEvent.getAccountDeviceInstances());
56  historyManager.advance(new CommunicationsState(comFilter, pinnedList, -1, currentStartState, currentEndState));
57  } else {
58  HashSet<AccountDeviceInstanceKey> pinnedList = new HashSet<>();
59  pinnedList.addAll(pinEvent.getAccountDeviceInstances());
60  pinnedList.addAll(pinModel.getPinnedAccounts());
61 
62  historyManager.advance(new CommunicationsState( comFilter, pinnedList, -1, currentStartState, currentEndState));
63  }
64  }
65 
66  @Subscribe
67  void filterChange(CVTEvents.FilterChangeEvent filterEvent) {
68  comFilter = filterEvent.getNewFilter();
69  currentStartState = filterEvent.getStartControlState();
70  currentEndState = filterEvent.getEndControlState();
71  historyManager.advance(new CommunicationsState(comFilter, pinModel.getPinnedAccounts(), -1, currentStartState, currentEndState));
72  }
73 
74  @Subscribe
75  void unpinAccounts(CVTEvents.UnpinAccountsEvent pinEvent) {
76 
77  HashSet<AccountDeviceInstanceKey> pinnedList = new HashSet<>();
78  pinnedList.addAll(pinModel.getPinnedAccounts());
79  pinnedList.removeAll(pinEvent.getAccountDeviceInstances());
80 
81  historyManager.advance(new CommunicationsState(comFilter, pinnedList, -1, currentStartState, currentEndState));
82  }
83 
84  @Subscribe
85  void zoomedGraph(CVTEvents.ScaleChangeEvent zoomEvent) {
86  historyManager.advance(new CommunicationsState(comFilter, pinModel.getPinnedAccounts(), zoomEvent.getZoomValue(), currentStartState, currentEndState));
87  }
88 
94  public CommunicationsState retreat(){
95  if(canRetreat()) {
96  return historyManager.retreat();
97  } else {
98  return null;
99  }
100  }
101 
107  public CommunicationsState advance() {
108  if(canAdvance()) {
109  return historyManager.advance();
110  } else {
111  return null;
112  }
113  }
114 
120  public boolean canRetreat() {
121  return historyManager.canRetreat();
122  }
123 
129  public boolean canAdvance(){
130  return historyManager.canAdvance();
131  }
132 
136  final class CommunicationsState{
137  private final CommunicationsFilter communcationFilter;
138  private final Set<AccountDeviceInstanceKey> pinnedList;
139  private final double zoomValue;
140  private final DateControlState startDateState;
141  private final DateControlState endDateState;
142 
151  protected CommunicationsState(CommunicationsFilter communcationFilter,
152  Set<AccountDeviceInstanceKey> pinnedList, double zoomValue,
153  DateControlState startDateState, DateControlState endDateState){
154  this.pinnedList = pinnedList;
155  this.communcationFilter = communcationFilter;
156  this.zoomValue = zoomValue;
157  this.startDateState = startDateState;
158  this.endDateState = endDateState;
159  }
160 
166  public boolean isZoomChange() {
167  return (zoomValue != -1);
168  }
169 
175  public Set<AccountDeviceInstanceKey> getPinnedList(){
176  return pinnedList;
177  }
178 
185  public CommunicationsFilter getCommunicationsFilter() {
186  return communcationFilter;
187  }
188 
194  public double getZoomValue() {
195  return zoomValue;
196  }
197 
203  public DateControlState getStartControlState() {
204  return startDateState;
205  }
206 
212  public DateControlState getEndControlState() {
213  return endDateState;
214  }
215  }
216 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.