From 20debd55e730d0dbd98308cd74628129181f57cb Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 9 Nov 2015 17:16:56 -0500 Subject: [PATCH] improve default chart tooltip. fixe guideline tooltip. fix guideline drag mouse event handler --- .../ui/AbstractVisualizationPane.java | 15 +++-- .../ui/countsview/CountsViewPane.java | 2 +- .../ui/detailview/EventBundleNodeBase.java | 4 +- .../ui/detailview/EventDetailsChart.java | 14 ++--- .../timeline/ui/detailview/GuideLine.java | 56 +++++++++---------- 5 files changed, 40 insertions(+), 51 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/AbstractVisualizationPane.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/AbstractVisualizationPane.java index 9ba8977757..52d64c0c1f 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/AbstractVisualizationPane.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/AbstractVisualizationPane.java @@ -72,13 +72,12 @@ import org.sleuthkit.autopsy.timeline.events.RefreshRequestedEvent; * common history context menu items out of derived classes? -jm */ public abstract class AbstractVisualizationPane & TimeLineChart> extends BorderPane { - - @NbBundle.Messages("AbstractVisualization.Drag_Tooltip.text=Drag the mouse to select a time interval to zoom into.") - private static final Tooltip DRAG_TOOLTIP = new Tooltip(Bundle.AbstractVisualization_Drag_Tooltip_text()); + @NbBundle.Messages("AbstractVisualization.Default_Tooltip.text=Drag the mouse to select a time interval to zoom into.\nRight-click for more actions.") + private static final Tooltip DEFAULT_TOOLTIP = new Tooltip(Bundle.AbstractVisualization_Default_Tooltip_text()); private static final Logger LOGGER = Logger.getLogger(AbstractVisualizationPane.class.getName()); - public static Tooltip getDragTooltip() { - return DRAG_TOOLTIP; + public static Tooltip getDefaultTooltip() { + return DEFAULT_TOOLTIP; } protected final SimpleBooleanProperty hasEvents = new SimpleBooleanProperty(true); @@ -242,16 +241,16 @@ public abstract class AbstractVisualizationPane }); TimeLineController.getTimeZone().addListener(invalidationListener); - + //show tooltip text in status bar hoverProperty().addListener((observable, oldActivated, newActivated) -> { if (newActivated) { - controller.setStatus(DRAG_TOOLTIP.getText()); + controller.setStatus(DEFAULT_TOOLTIP.getText()); } else { controller.setStatus(""); } }); - + update(); } diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/countsview/CountsViewPane.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/countsview/CountsViewPane.java index f33e4e53fe..ff5a3d4798 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/countsview/CountsViewPane.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/countsview/CountsViewPane.java @@ -267,7 +267,7 @@ public class CountsViewPane extends AbstractVisualizationPane(new CountsViewSettingsPane().getChildrenUnmodifiable()); diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/EventBundleNodeBase.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/EventBundleNodeBase.java index 6c028f8dc6..de3e33abce 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/EventBundleNodeBase.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/EventBundleNodeBase.java @@ -175,7 +175,7 @@ public abstract class EventBundleNodeBase imp projectionMap.clear(); controller.selectEventIDs(Collections.emptyList()); }); - Tooltip.install(this, AbstractVisualizationPane.getDragTooltip()); + Tooltip.install(this, AbstractVisualizationPane.getDefaultTooltip()); dateAxis.setAutoRanging(false); @@ -430,7 +429,7 @@ public final class EventDetailsChart extends XYChart imp nodeGroup.setTranslateY(-d * h); } - private void clearGuideLine() { + void clearGuideLine() { getChartChildren().remove(guideLine); guideLine = null; } @@ -612,16 +611,11 @@ public final class EventDetailsChart extends XYChart imp setGraphic(new ImageView(MARKER)); // NON-NLS setEventHandler(actionEvent -> { if (guideLine == null) { - guideLine = new GuideLine(0, 0, 0, getHeight(), getXAxis()); + guideLine = new GuideLine(0, 0, 0, getHeight(), EventDetailsChart.this); guideLine.relocate(sceneToLocal(clickEvent.getSceneX(), 0).getX(), 0); guideLine.endYProperty().bind(heightProperty().subtract(getXAxis().heightProperty().subtract(getXAxis().tickLengthProperty()))); getChartChildren().add(guideLine); - guideLine.setOnMouseClicked(mouseEvent -> { - if (mouseEvent.getButton() == MouseButton.SECONDARY) { - clearGuideLine(); - mouseEvent.consume(); - } - }); + } else { guideLine.relocate(sceneToLocal(clickEvent.getSceneX(), 0).getX(), 0); } diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/GuideLine.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/GuideLine.java index 7d6ef47f50..547db5a84c 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/GuideLine.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/GuideLine.java @@ -18,31 +18,40 @@ */ package org.sleuthkit.autopsy.timeline.ui.detailview; -import javafx.beans.binding.StringBinding; import javafx.scene.Cursor; -import javafx.scene.chart.Axis; import javafx.scene.control.Tooltip; +import javafx.scene.input.MouseButton; import javafx.scene.paint.Color; import javafx.scene.shape.Line; -import org.joda.time.DateTime; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.timeline.TimeLineController; +import org.sleuthkit.autopsy.timeline.ui.AbstractVisualizationPane; /** * */ -@NbBundle.Messages({"GuideLine.tooltip.text={0}\nRight-click to remove.\nRight-drag to reposition."}) +@NbBundle.Messages({"GuideLine.tooltip.text={0}\nRight-click to remove.\nDrag to reposition."}) class GuideLine extends Line { - private final Axis dateAxis; + private static final Tooltip CHART_DEFAULT_TOOLTIP = AbstractVisualizationPane.getDefaultTooltip(); + private Tooltip tooltip = new Tooltip(); private double startLayoutX; private double dragStartX = 0; + private final EventDetailsChart chart; - GuideLine(double startX, double startY, double endX, double endY, Axis axis) { + /** + * + * @param startX + * @param startY + * @param endX + * @param endY + * @param chart + */ + GuideLine(double startX, double startY, double endX, double endY, EventDetailsChart chart) { super(startX, startY, endX, endY); - dateAxis = axis; + this.chart = chart; //TODO: assign via css setCursor(Cursor.E_RESIZE); getStrokeDashArray().setAll(5.0, 5.0); @@ -51,17 +60,16 @@ class GuideLine extends Line { setStrokeWidth(3); Tooltip.install(this, tooltip); - tooltip.textProperty().bind(new StringBinding() { - { - bind(layoutXProperty()); - } - - @Override - protected String computeValue() { - return Bundle.GuideLine_tooltip_text(formatSpan(getDateTime())); + tooltip.setOnShowing(windowEvent -> tooltip.setText(Bundle.GuideLine_tooltip_text(getDateTimeAsString()))); + setOnMouseEntered(entered -> Tooltip.uninstall(chart, CHART_DEFAULT_TOOLTIP)); + setOnMouseExited(exited -> Tooltip.install(chart, CHART_DEFAULT_TOOLTIP)); + setOnMouseClicked(mouseEvent -> { + if (mouseEvent.getButton() == MouseButton.SECONDARY + && mouseEvent.isStillSincePress() == false) { + chart.clearGuideLine(); + mouseEvent.consume(); } }); -// setOnMouseEntered(enteredEvent -> updateToolTipText()); setOnMousePressed(pressedEvent -> { startLayoutX = getLayoutX(); dragStartX = pressedEvent.getScreenX(); @@ -69,24 +77,12 @@ class GuideLine extends Line { setOnMouseDragged(dragEvent -> { double dX = dragEvent.getScreenX() - dragStartX; relocate(startLayoutX + dX, 0); -// updateToolTipText(); dragEvent.consume(); }); } - private void updateToolTipText() { - Tooltip.uninstall(this, tooltip); - - tooltip = new Tooltip(Bundle.GuideLine_tooltip_text(formatSpan(getDateTime()))); - Tooltip.install(this, tooltip); - } - - private String formatSpan(DateTime date) { - return date.toString(TimeLineController.getZonedFormatter()); - } - - private DateTime getDateTime() { - return dateAxis.getValueForDisplay(dateAxis.parentToLocal(getLayoutX(), 0).getX()); + private String getDateTimeAsString() { + return chart.getDateTimeForPosition(getLayoutX()).toString(TimeLineController.getZonedFormatter()); } }