Autopsy  4.13.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.geometry.Point2D;
27 import javafx.scene.Group;
28 import javafx.scene.Node;
29 import javafx.scene.input.MouseEvent;
30 
42 public final class ImageTagsGroup extends Group {
43 
44  private final EventDispatchChainImpl NO_OP_CHAIN = new EventDispatchChainImpl();
45  private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
46 
47  private volatile ImageTag currentFocus;
48 
49  public ImageTagsGroup(Node backDrop) {
50 
51  //Reset focus of current selection if the back drop has focus.
52  backDrop.setOnMousePressed((mouseEvent) -> {
53  if (currentFocus != null) {
54  currentFocus.getEventDispatcher().dispatchEvent(
55  new Event(ImageTagControls.NOT_FOCUSED), NO_OP_CHAIN);
56  }
57 
58  this.pcs.firePropertyChange(new PropertyChangeEvent(this,
59  ImageTagControls.NOT_FOCUSED.getName(), currentFocus, null));
60  currentFocus = null;
61  });
62 
63  //Set the focus of selected tag
64  this.addEventFilter(MouseEvent.MOUSE_PRESSED, (MouseEvent e) -> {
65  if (!e.isPrimaryButtonDown()) {
66  return;
67  }
68 
69  ImageTag selection = getTagToSelect(new Point2D(e.getX(), e.getY()));
70  requestFocus(selection);
71  });
72  }
73 
79  public void addFocusChangeListener(PropertyChangeListener fcl) {
80  this.pcs.addPropertyChangeListener(fcl);
81  }
82 
88  public ImageTag getFocus() {
89  return currentFocus;
90  }
91 
95  public void clearFocus() {
96  if(currentFocus != null) {
97  resetFocus(currentFocus);
98  currentFocus = null;
99  }
100  }
101 
110  private ImageTag getTagToSelect(Point2D coordinate) {
111  ImageTag tagToSelect = null;
112  double minTagSize = Double.MAX_VALUE;
113 
114  //Find all intersecting tags, select the absolute min based on L + W.
115  for (Node node : this.getChildren()) {
116  ImageTag tag = (ImageTag) node;
117  double tagSize = tag.getWidth() + tag.getHeight();
118  if (tag.contains(coordinate) && tagSize < minTagSize) {
119  tagToSelect = tag;
120  minTagSize = tagSize;
121  }
122  }
123 
124  return tagToSelect;
125  }
126 
132  private void resetFocus(ImageTag n) {
133  n.getEventDispatcher().dispatchEvent(new Event(ImageTagControls.NOT_FOCUSED), NO_OP_CHAIN);
134  this.pcs.firePropertyChange(new PropertyChangeEvent(this, ImageTagControls.NOT_FOCUSED.getName(), n, null));
135  }
136 
142  private void requestFocus(ImageTag n) {
143  if (n == null || n.equals(currentFocus)) {
144  return;
145  } else if (currentFocus != null && !currentFocus.equals(n)) {
146  resetFocus(currentFocus);
147  }
148 
149  n.getEventDispatcher().dispatchEvent(new Event(ImageTagControls.FOCUSED), NO_OP_CHAIN);
150  this.pcs.firePropertyChange(new PropertyChangeEvent(this, ImageTagControls.FOCUSED.getName(), currentFocus, n));
151 
152  currentFocus = n;
153  n.toFront();
154  }
155 }

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.