Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
GuideLine.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-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.ui.detailview;
20 
21 import javafx.scene.chart.Axis;
22 import javafx.scene.control.Tooltip;
23 import javafx.scene.input.MouseButton;
24 import javafx.scene.shape.Line;
25 import org.joda.time.DateTime;
26 import org.openide.util.NbBundle;
29 
34 @NbBundle.Messages({"# {0} - date/time at guideline position",
35  "GuideLine.tooltip.text={0}\nRight-click to remove.\nDrag to reposition."})
36 class GuideLine extends Line {
37 
38  private final Tooltip CHART_DEFAULT_TOOLTIP = AbstractTimelineChart.getDefaultTooltip();
39 
40  private final Tooltip tooltip = new Tooltip();
41  private final DetailsChart chart;
42 
43  //used across invocations of mouse event handlers to maintain state
44  private double startLayoutX;
45  private double dragStartX = 0;
46 
50  GuideLine(DetailsChart chart) {
51  super(0, 0, 0, 0);
52  this.chart = chart;
53  Axis<DateTime> xAxis = chart.getXAxis();
54  endYProperty().bind(chart.heightProperty().subtract(xAxis.heightProperty().subtract(xAxis.tickLengthProperty())));
55 
56  getStyleClass().add("guide-line"); //NON-NLS
57 
58  Tooltip.install(this, tooltip);
59  tooltip.setOnShowing(showing -> tooltip.setText(Bundle.GuideLine_tooltip_text(getDateTimeAsString())));
60 
61  //this is a hack to override the tooltip of the enclosing chart.
62  setOnMouseEntered(entered -> Tooltip.uninstall(chart, CHART_DEFAULT_TOOLTIP));
63  setOnMouseExited(exited -> Tooltip.install(chart, CHART_DEFAULT_TOOLTIP));
64 
65  setOnMouseClicked(clickedEvent -> {
66  if (clickedEvent.getButton() == MouseButton.SECONDARY
67  && clickedEvent.isStillSincePress()) {
68  chart.clearGuideLine(this);
69  clickedEvent.consume();
70  }
71  });
72  setOnMousePressed(pressedEvent -> {
73  startLayoutX = getLayoutX();
74  dragStartX = pressedEvent.getScreenX();
75  });
76  setOnMouseDragged(dragEvent -> {
77  double dX = dragEvent.getScreenX() - dragStartX;
78  relocate(startLayoutX + dX, 0);
79  dragEvent.consume();
80  });
81  }
82 
83  private String getDateTimeAsString() {
84  return chart.getDateTimeForPosition(getLayoutX()).toString(TimeLineController.getZonedFormatter());
85  }
86 }

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