Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ZoomSettingsPane.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-16 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.zooming;
20 
21 import java.util.function.Consumer;
22 import java.util.function.Function;
23 import javafx.application.Platform;
24 import javafx.beans.InvalidationListener;
25 import javafx.beans.binding.BooleanBinding;
26 import javafx.beans.property.ReadOnlyObjectProperty;
27 import javafx.fxml.FXML;
28 import javafx.scene.control.Label;
29 import javafx.scene.control.Slider;
30 import javafx.scene.control.TitledPane;
31 import javafx.util.StringConverter;
32 import org.openide.util.NbBundle;
38 
45 public class ZoomSettingsPane extends TitledPane {
46 
47  @FXML
48  private Label zoomLabel;
49 
50  @FXML
51  private Label descrLODLabel;
52  @FXML
53  private Slider descrLODSlider;
54 
55  @FXML
56  private Label typeZoomLabel;
57  @FXML
58  private Slider typeZoomSlider;
59 
60  @FXML
61  private Label timeUnitLabel;
62  @FXML
63  private Slider timeUnitSlider;
64 
67 
73  public ZoomSettingsPane(TimeLineController controller) {
74  this.controller = controller;
75  this.filteredEvents = controller.getEventsModel();
76  FXMLConstructor.construct(this, "ZoomSettingsPane.fxml"); // NON-NLS
77  }
78 
79  @NbBundle.Messages({
80  "ZoomSettingsPane.descrLODLabel.text=Description Detail:",
81  "ZoomSettingsPane.typeZoomLabel.text=Event Type:",
82  "ZoomSettingsPane.timeUnitLabel.text=Time Units:",
83  "ZoomSettingsPane.zoomLabel.text=Zoom"})
84  public void initialize() {
85  zoomLabel.setText(Bundle.ZoomSettingsPane_zoomLabel_text());
86 
87  typeZoomSlider.setMin(1); //don't show ROOT_TYPE
88  typeZoomSlider.setMax(EventTypeZoomLevel.values().length - 1);
89  configureSliderListeners(typeZoomSlider,
90  controller::pushEventTypeZoom,
91  filteredEvents.eventTypeZoomProperty(),
92  EventTypeZoomLevel.class,
93  EventTypeZoomLevel::ordinal,
94  Function.identity());
95  typeZoomLabel.setText(Bundle.ZoomSettingsPane_typeZoomLabel_text());
96 
97  descrLODSlider.setMax(DescriptionLoD.values().length - 1);
98  configureSliderListeners(descrLODSlider,
99  controller::pushDescrLOD,
100  filteredEvents.descriptionLODProperty(),
101  DescriptionLoD.class,
102  DescriptionLoD::ordinal,
103  Function.identity());
104  descrLODLabel.setText(Bundle.ZoomSettingsPane_descrLODLabel_text());
105  //the description slider is only usefull in the detail view
106  descrLODSlider.disableProperty().bind(controller.viewModeProperty().isEqualTo(ViewMode.COUNTS));
107 
115  timeUnitSlider.setMax(TimeUnits.values().length - 2);
116  configureSliderListeners(timeUnitSlider,
117  controller::pushTimeUnit,
118  filteredEvents.timeRangeProperty(),
119  TimeUnits.class,
120  //for the purposes of this slider we want the TimeUnit one bigger than RangeDivisionInfo indicates
121  modelTimeRange -> RangeDivisionInfo.getRangeDivisionInfo(modelTimeRange).getPeriodSize().ordinal() - 1,
122  index -> index + 1); //compensate for the -1 above when mapping to the Enum whose displayName will be shown at index
123  timeUnitLabel.setText(Bundle.ZoomSettingsPane_timeUnitLabel_text());
124 
125  //hide the whole panel in list mode
126  BooleanBinding notListMode = controller.viewModeProperty().isNotEqualTo(ViewMode.LIST);
127  visibleProperty().bind(notListMode);
128  managedProperty().bind(notListMode);
129 
130  }
131 
169  private static <DriverType, EnumType extends Enum<EnumType> & DisplayNameProvider> void configureSliderListeners(
170  Slider slider,
171  Consumer<EnumType> sliderValueConsumer,
172  ReadOnlyObjectProperty<DriverType> modelProperty,
173  Class<EnumType> enumClass,
174  Function<DriverType, Integer> driverValueMapper,
175  Function<Integer, Integer> labelIndexMapper) {
176 
177  //set the tick labels to the enum displayNames
178  slider.setLabelFormatter(new EnumSliderLabelFormatter<>(enumClass, labelIndexMapper));
179 
180  //make a listener to responds to slider value changes (by updating the view)
181  final InvalidationListener sliderListener = observable -> {
182  //only process event if the slider value is not changing (user has released slider thumb)
183  if (slider.isValueChanging() == false) {
184  //convert slider value to EnumType and pass to consumer
185  EnumType sliderValueAsEnum = enumClass.getEnumConstants()[Math.round((float) slider.getValue())];
186  sliderValueConsumer.accept(sliderValueAsEnum);
187  }
188  };
189  //attach listener
190  slider.valueProperty().addListener(sliderListener);
191  slider.valueChangingProperty().addListener(sliderListener);
192 
193  //set intial value of slider
194  slider.setValue(driverValueMapper.apply(modelProperty.get()));
195 
196  //handle changes in the model property
197  modelProperty.addListener(modelProp -> {
198  //remove listener to avoid circular updates
199  slider.valueProperty().removeListener(sliderListener);
200  slider.valueChangingProperty().removeListener(sliderListener);
201 
202  Platform.runLater(() -> {
203  //sync value of slider to model property value
204  slider.setValue(driverValueMapper.apply(modelProperty.get()));
205 
206  //reattach listener
207  slider.valueProperty().addListener(sliderListener);
208  slider.valueChangingProperty().addListener(sliderListener);
209  });
210  });
211  }
212 
221  static private class EnumSliderLabelFormatter<EnumType extends Enum<EnumType> & DisplayNameProvider> extends StringConverter<Double> {
222 
226  private final Class<EnumType> clazz;
232  private final Function<Integer, Integer> indexAdjsuter;
233 
234  EnumSliderLabelFormatter(Class<EnumType> clazz, Function<Integer, Integer> indexMapper) {
235  this.clazz = clazz;
236  this.indexAdjsuter = indexMapper;
237  }
238 
239  @Override
240  public String toString(Double dbl) {
241  //get the displayName of the EnumType whose index is the given dbl after it has been narrowed and then adjusted
242  return clazz.getEnumConstants()[indexAdjsuter.apply(dbl.intValue())].getDisplayName();
243  }
244 
245  @Override
246  public Double fromString(String string) {
247  throw new UnsupportedOperationException("This method should not be used. This EnumSliderLabelFormatter is being used in an unintended way.");
248  }
249  }
250 }
synchronized ReadOnlyObjectProperty< EventTypeZoomLevel > eventTypeZoomProperty()
static RangeDivisionInfo getRangeDivisionInfo(Interval timeRange)
static< DriverType, EnumTypeextendsEnum< EnumType > &DisplayNameProvider void configureSliderListeners(Slider slider, Consumer< EnumType > sliderValueConsumer, ReadOnlyObjectProperty< DriverType > modelProperty, Class< EnumType > enumClass, Function< DriverType, Integer > driverValueMapper, Function< Integer, Integer > labelIndexMapper)
synchronized ReadOnlyObjectProperty< ViewMode > viewModeProperty()
synchronized ReadOnlyObjectProperty< DescriptionLoD > descriptionLODProperty()
static void construct(Node node, String fxmlFileName)
synchronized ReadOnlyObjectProperty< Interval > timeRangeProperty()

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.