19 package org.sleuthkit.autopsy.communications;
 
   21 import com.google.common.eventbus.Subscribe;
 
   22 import java.util.HashSet;
 
   33 final class StateManager {
 
   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;
 
   46     public StateManager(PinnedAccountModel pinModel){
 
   47         this.pinModel = pinModel;
 
   48         CVTEvents.getCVTEventBus().register(
this);
 
   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));
 
   58             HashSet<AccountDeviceInstanceKey> pinnedList = 
new HashSet<>();
 
   59             pinnedList.addAll(pinEvent.getAccountDeviceInstances());
 
   60             pinnedList.addAll(pinModel.getPinnedAccounts());
 
   62             historyManager.advance(
new CommunicationsState( comFilter, pinnedList, -1, currentStartState, currentEndState));
 
   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));
 
   75     void unpinAccounts(CVTEvents.UnpinAccountsEvent pinEvent) {
 
   77         HashSet<AccountDeviceInstanceKey> pinnedList = 
new HashSet<>();
 
   78         pinnedList.addAll(pinModel.getPinnedAccounts());
 
   79         pinnedList.removeAll(pinEvent.getAccountDeviceInstances());
 
   81         historyManager.advance(
new CommunicationsState(comFilter, pinnedList, -1, currentStartState, currentEndState));
 
   85     void zoomedGraph(CVTEvents.ScaleChangeEvent zoomEvent) {
 
   86         historyManager.advance(
new CommunicationsState(comFilter, pinModel.getPinnedAccounts(), zoomEvent.getZoomValue(), currentStartState, currentEndState));
 
   94     public CommunicationsState retreat(){
 
   96             return historyManager.retreat();
 
  107     public CommunicationsState advance() {
 
  109             return historyManager.advance();
 
  120     public boolean canRetreat() {
 
  121         return historyManager.canRetreat();
 
  129     public boolean canAdvance(){
 
  130         return historyManager.canAdvance();
 
  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;
 
  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;
 
  166         public boolean isZoomChange() {
 
  167             return (zoomValue != -1);
 
  175         public Set<AccountDeviceInstanceKey> getPinnedList(){
 
  185         public CommunicationsFilter getCommunicationsFilter() {
 
  186             return communcationFilter;
 
  194         public double getZoomValue() {
 
  203         public DateControlState getStartControlState() {
 
  204             return startDateState;
 
  212         public DateControlState getEndControlState() {