Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
LegendCell.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-18 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.timeline.ui.filtering;
20 
21 import javafx.application.Platform;
22 import javafx.geometry.Pos;
23 import javafx.scene.control.ContentDisplay;
24 import javafx.scene.control.TextField;
25 import javafx.scene.control.TreeTableCell;
26 import javafx.scene.image.ImageView;
27 import javafx.scene.layout.HBox;
28 import javafx.scene.paint.Color;
29 import javafx.scene.shape.Rectangle;
30 import org.openide.util.NbBundle;
35 import org.sleuthkit.datamodel.TimelineEventType;
36 import org.sleuthkit.datamodel.TimelineFilter.EventTypeFilter;
38 
43 final class LegendCell extends TreeTableCell<FilterState<?>, FilterState<?>> {
44 
45  private static final Color CLEAR = Color.rgb(0, 0, 0, 0);
46 
47  private final TimeLineController controller;
48 
49  private final EventsModel filteredEvents;
50 
51  //We need a controller so we can listen to changes in EventTypeZoom to show/hide legends
52  LegendCell(TimeLineController controller) {
53  setEditable(false);
54  this.controller = controller;
55  this.filteredEvents = this.controller.getEventsModel();
56  }
57 
58  @Override
59  @NbBundle.Messages("Timeline.ui.filtering.promptText=enter filter string")
60  public void updateItem(FilterState<?> item, boolean empty) {
61  super.updateItem(item, empty);
62  if (item == null) {
63  Platform.runLater(() -> {
64  setGraphic(null);
65  setBackground(null);
66  });
67  } else {
68 
69  //TODO: make some subclasses rather than use this if else chain.
70  if (item instanceof TextFilterState) {
71  TextFilterState filterState = (TextFilterState)item;
72  TextField textField = new TextField();
73  textField.setPromptText(Bundle.Timeline_ui_filtering_promptText());
74  textField.textProperty().bindBidirectional(filterState.descriptionSubstringProperty());
75  Platform.runLater(() -> setGraphic(textField));
76 
77  } else if (item.getFilter() instanceof EventTypeFilter) {
78  EventTypeFilter filter = (EventTypeFilter) item.getFilter();
79  Rectangle rect = new Rectangle(20, 20);
80 
81  rect.setArcHeight(5);
82  rect.setArcWidth(5);
83  rect.setStrokeWidth(3);
84  setLegendColor(filter, rect, this.filteredEvents.getEventTypeZoom());
85  this.filteredEvents.eventTypesHierarchyLevelProperty().addListener((obs, oldZoomLevel, newZoomLevel) -> {
86  setLegendColor(filter, rect, newZoomLevel);
87  });
88 
89  HBox hBox = new HBox(new Rectangle(filter.getRootEventType().getTypeHierarchyLevel().ordinal() * 10, 5, CLEAR),
90  new ImageView(EventTypeUtils.getImagePath(filter.getRootEventType())), rect
91  );
92  hBox.setAlignment(Pos.CENTER);
93  Platform.runLater(() -> {
94  setGraphic(hBox);
95  setContentDisplay(ContentDisplay.CENTER);
96  });
97 
98  } else {
99  Platform.runLater(() -> {
100  setGraphic(null);
101  setBackground(null);
102  });
103  }
104  }
105  }
106 
107  private void setLegendColor(EventTypeFilter filter, Rectangle rect, TimelineEventType.HierarchyLevel eventTypeZoom) {
108  //only show legend color if filter is of the same zoomlevel as requested in filteredEvents
109  if (eventTypeZoom.equals(filter.getRootEventType().getTypeHierarchyLevel())) {
110  Platform.runLater(() -> {
111  rect.setStroke(EventTypeUtils.getColor(filter.getRootEventType().getParent()));
112  rect.setFill(EventTypeUtils.getColor(filter.getRootEventType()));
113  });
114  } else {
115  Platform.runLater(() -> {
116  rect.setStroke(CLEAR);
117  rect.setFill(CLEAR);
118  });
119  }
120  }
121 }

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.