Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ImageTagsGroup.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.contentviewers.imagetagging;
20 
21 import com.sun.javafx.event.EventDispatchChainImpl;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import java.beans.PropertyChangeSupport;
25 import javafx.event.Event;
26 import javafx.scene.Group;
27 import javafx.scene.Node;
28 import javafx.scene.input.MouseEvent;
29 
41 public final class ImageTagsGroup extends Group {
42 
43  private final EventDispatchChainImpl NO_OP_CHAIN = new EventDispatchChainImpl();
44  private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
45 
46  private volatile ImageTag currentFocus;
47 
48  public ImageTagsGroup(Node backDrop) {
49 
50  //Reset focus of current selection if the back drop has focus.
51  backDrop.setOnMousePressed((mouseEvent) -> {
52  if (currentFocus != null) {
53  currentFocus.getEventDispatcher().dispatchEvent(
54  new Event(ImageTagControls.NOT_FOCUSED), NO_OP_CHAIN);
55  }
56 
57  this.pcs.firePropertyChange(new PropertyChangeEvent(this,
58  ImageTagControls.NOT_FOCUSED.getName(), currentFocus, null));
59  currentFocus = null;
60  });
61 
62  //Set the focus of selected tag
63  this.addEventFilter(MouseEvent.MOUSE_PRESSED, (MouseEvent e) -> {
64  if (!e.isPrimaryButtonDown()) {
65  return;
66  }
67 
68  //Pull out the logical image tag that this node is associated with
69  Node topLevelChild = e.getPickResult().getIntersectedNode();
70  while (!this.getChildren().contains(topLevelChild)) {
71  topLevelChild = topLevelChild.getParent();
72  }
73 
74  requestFocus((ImageTag) topLevelChild);
75  });
76  }
77 
83  public void addFocusChangeListener(PropertyChangeListener fcl) {
84  this.pcs.addPropertyChangeListener(fcl);
85  }
86 
92  public ImageTag getFocus() {
93  return currentFocus;
94  }
95 
99  public void clearFocus() {
100  if(currentFocus != null) {
101  resetFocus(currentFocus);
102  currentFocus = null;
103  }
104  }
105 
111  private void resetFocus(ImageTag n) {
112  n.getEventDispatcher().dispatchEvent(new Event(ImageTagControls.NOT_FOCUSED), NO_OP_CHAIN);
113  this.pcs.firePropertyChange(new PropertyChangeEvent(this, ImageTagControls.NOT_FOCUSED.getName(), n, null));
114  }
115 
121  private void requestFocus(ImageTag n) {
122  if (n.equals(currentFocus)) {
123  return;
124  } else if (currentFocus != null && !currentFocus.equals(n)) {
125  resetFocus(currentFocus);
126  }
127 
128  n.getEventDispatcher().dispatchEvent(new Event(ImageTagControls.FOCUSED), NO_OP_CHAIN);
129  this.pcs.firePropertyChange(new PropertyChangeEvent(this, ImageTagControls.FOCUSED.getName(), currentFocus, n));
130 
131  currentFocus = n;
132  n.toFront();
133  }
134 }

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.