Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
MapPanMouseInputListener.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 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.geolocation;
20 
21 import java.awt.Cursor;
22 import java.awt.Point;
23 import java.awt.event.MouseEvent;
24 import java.awt.geom.Point2D;
25 import javax.swing.SwingUtilities;
26 import javax.swing.event.MouseInputAdapter;
27 import org.jxmapviewer.JXMapViewer;
28 
34 final class MapPanMouseInputListener extends MouseInputAdapter {
35 
36  private Point prev;
37  private final JXMapViewer viewer;
38  private Cursor priorCursor;
39  private boolean dragging = false;
40 
46  MapPanMouseInputListener(JXMapViewer viewer) {
47  this.viewer = viewer;
48  }
49 
50  @Override
51  public void mousePressed(MouseEvent evt) {
52  if (!SwingUtilities.isLeftMouseButton(evt)) {
53  return;
54  }
55  if (!viewer.isPanningEnabled()) {
56  return;
57  }
58 
59  // Store the current click point and current cursor
60  prev = evt.getPoint();
61  priorCursor = viewer.getCursor();
62  }
63 
64  @Override
65  public void mouseDragged(MouseEvent evt) {
66  if (!SwingUtilities.isLeftMouseButton(evt)) {
67  return;
68  }
69 
70  if (!viewer.isPanningEnabled()) {
71  return;
72  }
73 
74  // If the map wasn't previously being dragged, set the cursor
75  if (!dragging) {
76  viewer.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
77  dragging = true;
78  }
79 
80  // Figure out the new map center
81  Point current = evt.getPoint();
82  double x = viewer.getCenter().getX();
83  double y = viewer.getCenter().getY();
84 
85  if (prev != null) {
86  x += prev.x - current.x;
87  y += prev.y - current.y;
88  }
89 
90  int maxHeight = (int) (viewer.getTileFactory().getMapSize(viewer.getZoom()).getHeight() * viewer
91  .getTileFactory().getTileSize(viewer.getZoom()));
92  if (y > maxHeight) {
93  y = maxHeight;
94  }
95 
96  prev = current;
97  viewer.setCenter(new Point2D.Double(x, y));
98  viewer.repaint();
99  }
100 
101  @Override
102  public void mouseReleased(MouseEvent evt) {
103  if (!SwingUtilities.isLeftMouseButton(evt)) {
104  return;
105  }
106 
107  prev = null;
108 
109  // If we were dragging set the cursor back
110  if (dragging) {
111  viewer.setCursor(priorCursor);
112  dragging = false;
113  }
114  }
115 }

Copyright © 2012-2022 Basis Technology. Generated on: Thu Sep 29 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.