Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
OpenGeolocationAction.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.Component;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import javax.swing.ImageIcon;
25 import javax.swing.JButton;
26 import org.openide.awt.ActionID;
27 import org.openide.awt.ActionReference;
28 import org.openide.awt.ActionReferences;
29 import org.openide.awt.ActionRegistration;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.util.actions.CallableSystemAction;
33 import org.openide.windows.TopComponent;
34 import org.openide.windows.WindowManager;
37 
43 @ActionID(category = "Tools",
44  id = "org.sleuthkit.autopsy.geolocation.OpenGeolocationAction")
45 @ActionRegistration(displayName = "#CTL_OpenGeolocation", lazy = false)
46 @ActionReferences(value = {
47  @ActionReference(path = "Menu/Tools", position = 103),
48 @ActionReference(path = "Toolbars/Case", position = 103)})
49 @Messages({"CTL_OpenGeolocation=Geolocation"})
50 public class OpenGeolocationAction extends CallableSystemAction {
51 
52  private static final long serialVersionUID = 1L;
53  private final JButton toolbarButton = new JButton(getName(),
54  new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/blueGeo24.png"))); //NON-NLS
55 
60  toolbarButton.addActionListener(actionEvent -> performAction());
61  setEnabled(false); //disabled by default. Will be enabled in Case.java when a case is opened.
62 
63  PropertyChangeListener caseChangeListener = (PropertyChangeEvent evt) -> {
64  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
65  setEnabled(RuntimeProperties.runningWithGUI() && evt.getNewValue() != null);
66  }
67  };
68 
69  Case.addPropertyChangeListener(caseChangeListener);
70  }
71 
72  @Override
73  public void performAction() {
74  final TopComponent topComponent = WindowManager.getDefault().findTopComponent("GeolocationTopComponent");
75  if (topComponent != null) {
76  if (topComponent.isOpened() == false) {
77  topComponent.open();
78  }
79  topComponent.toFront();
80  topComponent.requestActive();
81  }
82  }
83 
89  @Override
90  public void setEnabled(boolean value) {
91  super.setEnabled(value);
92  toolbarButton.setEnabled(value);
93  }
94 
95  @Override
96  public String getName() {
97  return Bundle.CTL_OpenGeolocation();
98  }
99 
105  @Override
106  public Component getToolbarPresenter() {
107  return toolbarButton;
108  }
109 
110  @Override
111  public HelpCtx getHelpCtx() {
112  return HelpCtx.DEFAULT_HELP;
113  }
114 
115  @Override
116  public boolean asynchronous() {
117  return false; // run on edt
118  }
119 
120 }
static void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:667

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.