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

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.