Autopsy  4.10.0
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-15 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;
37 
42 final class LegendCell extends TreeTableCell<AbstractFilter, AbstractFilter> {
43 
44  private static final Color CLEAR = Color.rgb(0, 0, 0, 0);
45 
46  private final TimeLineController controller;
47 
48  private final FilteredEventsModel filteredEvents;
49 
50  //We need a controller so we can listen to changes in EventTypeZoom to show/hide legends
51  LegendCell(TimeLineController controller) {
52  setEditable(false);
53  this.controller = controller;
54  this.filteredEvents = this.controller.getEventsModel();
55  }
56 
57  @Override
58  @NbBundle.Messages("Timeline.ui.filtering.promptText=enter filter string")
59  public void updateItem(AbstractFilter item, boolean empty) {
60  super.updateItem(item, empty);
61  if (item == null) {
62  Platform.runLater(() -> {
63  setGraphic(null);
64  setBackground(null);
65  });
66  } else {
67 
68  //TODO: have the filter return an appropriate node, rather than use instanceof
69  if (item instanceof TypeFilter) {
70  TypeFilter filter = (TypeFilter) item;
71  Rectangle rect = new Rectangle(20, 20);
72 
73  rect.setArcHeight(5);
74  rect.setArcWidth(5);
75  rect.setStrokeWidth(3);
76  setLegendColor(filter, rect, this.filteredEvents.getEventTypeZoom());
77  this.filteredEvents.eventTypeZoomProperty().addListener((obs, oldZoomLevel, newZoomLevel) -> {
78  setLegendColor(filter, rect, newZoomLevel);
79  });
80 
81  HBox hBox = new HBox(new Rectangle(filter.getEventType().getZoomLevel().ordinal() * 10, 5, CLEAR),
82  new ImageView(((TypeFilter) item).getFXImage()), rect
83  );
84  hBox.setAlignment(Pos.CENTER);
85  Platform.runLater(() -> {
86  setGraphic(hBox);
87  setContentDisplay(ContentDisplay.CENTER);
88  });
89 
90  } else if (item instanceof TextFilter) {
91  TextFilter f = (TextFilter) item;
92  TextField textField = new TextField();
93  textField.setPromptText(Bundle.Timeline_ui_filtering_promptText());
94  textField.textProperty().bindBidirectional(f.textProperty());
95  Platform.runLater(() -> {
96  setGraphic(textField);
97  });
98 
99  } else {
100  Platform.runLater(() -> {
101  setGraphic(null);
102  setBackground(null);
103  });
104  }
105  }
106  }
107 
108  private void setLegendColor(TypeFilter filter, Rectangle rect, EventTypeZoomLevel eventTypeZoom) {
109  //only show legend color if filter is of the same zoomlevel as requested in filteredEvents
110  if (eventTypeZoom.equals(filter.getEventType().getZoomLevel())) {
111  Platform.runLater(() -> {
112  rect.setStroke(filter.getEventType().getSuperType().getColor());
113  rect.setFill(filter.getColor());
114  });
115  } else {
116  Platform.runLater(() -> {
117  rect.setStroke(CLEAR);
118  rect.setFill(CLEAR);
119  });
120  }
121  }
122 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.