Autopsy  3.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 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.beans.value.ObservableValue;
23 import javafx.geometry.Pos;
24 import javafx.scene.control.ContentDisplay;
25 import javafx.scene.control.TextField;
26 import javafx.scene.control.TreeTableCell;
27 import javafx.scene.image.ImageView;
28 import javafx.scene.layout.HBox;
29 import javafx.scene.paint.Color;
30 import javafx.scene.shape.Rectangle;
31 import org.openide.util.NbBundle;
39 
44 class LegendCell extends TreeTableCell<AbstractFilter, AbstractFilter> implements TimeLineView {
45 
46  private static final Color CLEAR = Color.rgb(0, 0, 0, 0);
47 
48  private TimeLineController controller;
49 
50  private FilteredEventsModel filteredEvents;
51 
52  //We need a controller so we can listen to changes in EventTypeZoom to show/hide legends
53  public LegendCell(TimeLineController controller) {
54  setEditable(false);
55  setController(controller);
56  }
57 
58  @Override
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.eventTypeZoom().addListener((
78  ObservableValue<? extends EventTypeZoomLevel> observable,
79  EventTypeZoomLevel oldValue,
80  EventTypeZoomLevel newValue) -> {
81  setLegendColor(filter, rect, newValue);
82  });
83 
84  HBox hBox = new HBox(new Rectangle(filter.getEventType().getZoomLevel().ordinal() * 10, 5, CLEAR),
85  new ImageView(((TypeFilter) item).getFXImage()), rect
86  );
87  hBox.setAlignment(Pos.CENTER);
88  Platform.runLater(() -> {
89  setGraphic(hBox);
90  setContentDisplay(ContentDisplay.CENTER);
91  });
92 
93  } else if (item instanceof TextFilter) {
94  TextFilter f = (TextFilter) item;
95  TextField textField = new TextField();
96  textField.setPromptText(NbBundle.getMessage(this.getClass(), "Timeline.ui.filtering.promptText"));
97  textField.textProperty().bindBidirectional(f.textProperty());
98  Platform.runLater(() -> {
99  setGraphic(textField);
100  });
101 
102  } else {
103  Platform.runLater(() -> {
104  setGraphic(null);
105  setBackground(null);
106  });
107  }
108  }
109  }
110 
111  private void setLegendColor(TypeFilter filter, Rectangle rect, EventTypeZoomLevel eventTypeZoom) {
112  //only show legend color if filter is of the same zoomlevel as requested in filteredEvents
113  if (eventTypeZoom.equals(filter.getEventType().getZoomLevel())) {
114  Platform.runLater(() -> {
115  rect.setStroke(filter.getEventType().getSuperType().getColor());
116  rect.setFill(filter.getColor());
117  });
118  } else {
119  Platform.runLater(() -> {
120  rect.setStroke(CLEAR);
121  rect.setFill(CLEAR);
122  });
123  }
124  }
125 
126  @Override
127  synchronized public final void setController(TimeLineController controller) {
128  this.controller = controller;
129  setModel(this.controller.getEventsModel());
130  }
131 
132  @Override
133  public void setModel(FilteredEventsModel filteredEvents) {
134  this.filteredEvents = filteredEvents;
135  }
136 }
void setModel(final FilteredEventsModel filteredEvents)

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.