Autopsy  4.19.1
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.AccountDeviceInstance;
27 import org.sleuthkit.datamodel.CommunicationsFilter;
28 
34 final class StateManager {
35 
36  private final History<CommunicationsState> historyManager = new History<>();
37  private CommunicationsFilter comFilter;
38  private final PinnedAccountModel pinModel;
39  private DateControlState currentStartState;
40  private DateControlState currentEndState;
41 
47  public StateManager(PinnedAccountModel pinModel){
48  this.pinModel = pinModel;
49  CVTEvents.getCVTEventBus().register(this);
50  }
51 
52  @Subscribe
53  void pinAccount(CVTEvents.PinAccountsEvent pinEvent) {
54  if(pinEvent.isReplace()){
55  HashSet<AccountDeviceInstance> pinnedList = new HashSet<>();
56  pinnedList.addAll(pinEvent.getAccountDeviceInstances());
57  historyManager.advance(new CommunicationsState(comFilter, pinnedList, -1, currentStartState, currentEndState));
58  } else {
59  HashSet<AccountDeviceInstance> pinnedList = new HashSet<>();
60  pinnedList.addAll(pinEvent.getAccountDeviceInstances());
61  pinnedList.addAll(pinModel.getPinnedAccounts());
62 
63  historyManager.advance(new CommunicationsState( comFilter, pinnedList, -1, currentStartState, currentEndState));
64  }
65  }
66 
67  @Subscribe
68  void filterChange(CVTEvents.FilterChangeEvent filterEvent) {
69  comFilter = filterEvent.getNewFilter();
70  currentStartState = filterEvent.getStartControlState();
71  currentEndState = filterEvent.getEndControlState();
72  historyManager.advance(new CommunicationsState(comFilter, pinModel.getPinnedAccounts(), -1, currentStartState, currentEndState));
73  }
74 
75  @Subscribe
76  void unpinAccounts(CVTEvents.UnpinAccountsEvent pinEvent) {
77 
78  HashSet<AccountDeviceInstance> pinnedList = new HashSet<>();
79  pinnedList.addAll(pinModel.getPinnedAccounts());
80  pinnedList.removeAll(pinEvent.getAccountDeviceInstances());
81 
82  historyManager.advance(new CommunicationsState(comFilter, pinnedList, -1, currentStartState, currentEndState));
83  }
84 
85  @Subscribe
86  void zoomedGraph(CVTEvents.ScaleChangeEvent zoomEvent) {
87  historyManager.advance(new CommunicationsState(comFilter, pinModel.getPinnedAccounts(), zoomEvent.getZoomValue(), currentStartState, currentEndState));
88  }
89 
95  public CommunicationsState retreat(){
96  if(canRetreat()) {
97  return historyManager.retreat();
98  } else {
99  return null;
100  }
101  }
102 
108  public CommunicationsState advance() {
109  if(canAdvance()) {
110  return historyManager.advance();
111  } else {
112  return null;
113  }
114  }
115 
121  public boolean canRetreat() {
122  return historyManager.canRetreat();
123  }
124 
130  public boolean canAdvance(){
131  return historyManager.canAdvance();
132  }
133 
137  final class CommunicationsState{
138  private final CommunicationsFilter communcationFilter;
139  private final Set<AccountDeviceInstance> pinnedList;
140  private final double zoomValue;
141  private final DateControlState startDateState;
142  private final DateControlState endDateState;
143 
152  protected CommunicationsState(CommunicationsFilter communcationFilter,
153  Set<AccountDeviceInstance> pinnedList, double zoomValue,
154  DateControlState startDateState, DateControlState endDateState){
155  this.pinnedList = pinnedList;
156  this.communcationFilter = communcationFilter;
157  this.zoomValue = zoomValue;
158  this.startDateState = startDateState;
159  this.endDateState = endDateState;
160  }
161 
167  public boolean isZoomChange() {
168  return (zoomValue != -1);
169  }
170 
176  public Set<AccountDeviceInstance> getPinnedList(){
177  return pinnedList;
178  }
179 
186  public CommunicationsFilter getCommunicationsFilter() {
187  return communcationFilter;
188  }
189 
195  public double getZoomValue() {
196  return zoomValue;
197  }
198 
204  public DateControlState getStartControlState() {
205  return startDateState;
206  }
207 
213  public DateControlState getEndControlState() {
214  return endDateState;
215  }
216  }
217 }

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