mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-19 11:07:43 +00:00
rename SwingMenuItemAdapter.java -> SwingFXMenuUtils.java and cleanup
This commit is contained in:
parent
41a1776c13
commit
edb5642140
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Autopsy Forensic Browser
|
|
||||||
*
|
|
||||||
* Copyright 2013-14 Basis Technology Corp.
|
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.sleuthkit.autopsy.timeline;
|
|
||||||
|
|
||||||
import javafx.scene.control.Menu;
|
|
||||||
import javafx.scene.control.MenuItem;
|
|
||||||
import javafx.scene.control.SeparatorMenuItem;
|
|
||||||
import javax.swing.JMenu;
|
|
||||||
import javax.swing.JMenuItem;
|
|
||||||
import javax.swing.JPopupMenu;
|
|
||||||
import javax.swing.MenuElement;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
//TODO: move this into CoreUtils? -jm
|
|
||||||
public class SwingMenuItemAdapter extends MenuItem {
|
|
||||||
|
|
||||||
SwingMenuItemAdapter(final JMenuItem jMenuItem) {
|
|
||||||
super(jMenuItem.getText());
|
|
||||||
setOnAction(actionEvent -> SwingUtilities.invokeLater(jMenuItem::doClick));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MenuItem create(MenuElement jmenuItem) {
|
|
||||||
if (jmenuItem == null) {
|
|
||||||
return new SeparatorMenuItem();
|
|
||||||
} else if (jmenuItem instanceof JMenu) {
|
|
||||||
return new SwingMenuAdapter((JMenu) jmenuItem);
|
|
||||||
} else if (jmenuItem instanceof JPopupMenu) {
|
|
||||||
return new SwingMenuAdapter((JPopupMenu) jmenuItem);
|
|
||||||
} else {
|
|
||||||
return new SwingMenuItemAdapter((JMenuItem) jmenuItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SwingMenuAdapter extends Menu {
|
|
||||||
|
|
||||||
SwingMenuAdapter(final JMenu jMenu) {
|
|
||||||
super(jMenu.getText());
|
|
||||||
buildChildren(jMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
SwingMenuAdapter(JPopupMenu jPopupMenu) {
|
|
||||||
super(jPopupMenu.getLabel());
|
|
||||||
buildChildren(jPopupMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildChildren(MenuElement jMenu) {
|
|
||||||
|
|
||||||
for (MenuElement menuE : jMenu.getSubElements()) {
|
|
||||||
if (menuE == null) {
|
|
||||||
getItems().add(new SeparatorMenuItem());
|
|
||||||
} else if (menuE instanceof JMenuItem) {
|
|
||||||
getItems().add(SwingMenuItemAdapter.create(menuE));
|
|
||||||
} else if (menuE instanceof JPopupMenu) {
|
|
||||||
buildChildren(menuE);
|
|
||||||
} else {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -50,7 +50,6 @@ import org.openide.util.actions.Presenter;
|
|||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.autopsy.coreutils.ThreadConfined;
|
import org.sleuthkit.autopsy.coreutils.ThreadConfined;
|
||||||
import org.sleuthkit.autopsy.timeline.FXMLConstructor;
|
import org.sleuthkit.autopsy.timeline.FXMLConstructor;
|
||||||
import org.sleuthkit.autopsy.timeline.SwingMenuItemAdapter;
|
|
||||||
import org.sleuthkit.autopsy.timeline.TimeLineController;
|
import org.sleuthkit.autopsy.timeline.TimeLineController;
|
||||||
import org.sleuthkit.autopsy.timeline.datamodel.SingleEvent;
|
import org.sleuthkit.autopsy.timeline.datamodel.SingleEvent;
|
||||||
import org.sleuthkit.autopsy.timeline.explorernodes.EventNode;
|
import org.sleuthkit.autopsy.timeline.explorernodes.EventNode;
|
||||||
@ -295,9 +294,9 @@ class ListTimeline extends BorderPane {
|
|||||||
if (Arrays.asList("&Properties", "Tools").contains(actionName) == false) {
|
if (Arrays.asList("&Properties", "Tools").contains(actionName) == false) {
|
||||||
if (element instanceof Presenter.Popup) {
|
if (element instanceof Presenter.Popup) {
|
||||||
JMenuItem submenu = ((Presenter.Popup) element).getPopupPresenter();
|
JMenuItem submenu = ((Presenter.Popup) element).getPopupPresenter();
|
||||||
menuItems.add(SwingMenuItemAdapter.create(submenu));
|
menuItems.add(SwingFXMenuUtils.createFXMenu(submenu));
|
||||||
} else {
|
} else {
|
||||||
menuItems.add(SwingMenuItemAdapter.create(new Actions.MenuItem(element, false)));
|
menuItems.add(SwingFXMenuUtils.createFXMenu(new Actions.MenuItem(element, false)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Autopsy Forensic Browser
|
||||||
|
*
|
||||||
|
* Copyright 2011-2016 Basis Technology Corp.
|
||||||
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.sleuthkit.autopsy.timeline.ui.listvew;
|
||||||
|
|
||||||
|
import javafx.scene.control.Menu;
|
||||||
|
import javafx.scene.control.MenuItem;
|
||||||
|
import javafx.scene.control.SeparatorMenuItem;
|
||||||
|
import javax.swing.JMenu;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.MenuElement;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows creation of JavaFX menus with the same structure as Swing menus and
|
||||||
|
* which invoke the same actions.
|
||||||
|
*/
|
||||||
|
public class SwingFXMenuUtils extends MenuItem {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method that creates a JavaFX MenuItem backed by a MenuElement
|
||||||
|
*
|
||||||
|
* @param jMenuElement The MenuElement to create a JavaFX menu for.
|
||||||
|
*
|
||||||
|
* @return a MenuItem for the given MenuElement
|
||||||
|
*/
|
||||||
|
public static MenuItem createFXMenu(MenuElement jMenuElement) {
|
||||||
|
if (jMenuElement == null) {
|
||||||
|
//Since null is sometime used to represenet a seperator, follow that convention.
|
||||||
|
return new SeparatorMenuItem();
|
||||||
|
} else if (jMenuElement instanceof JMenu) {
|
||||||
|
return new MenuAdapter((JMenu) jMenuElement);
|
||||||
|
} else if (jMenuElement instanceof JPopupMenu) {
|
||||||
|
return new MenuAdapter((JPopupMenu) jMenuElement);
|
||||||
|
} else {
|
||||||
|
return new MenuItemAdapter((JMenuItem) jMenuElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JavaFX MenuItem that invokes the backing JMenuItem when clicked.
|
||||||
|
*/
|
||||||
|
private static class MenuItemAdapter extends MenuItem {
|
||||||
|
|
||||||
|
private MenuItemAdapter(final JMenuItem jMenuItem) {
|
||||||
|
super(jMenuItem.getText());
|
||||||
|
setOnAction(actionEvent -> SwingUtilities.invokeLater(jMenuItem::doClick));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JavaFX Menu that has the same structure as a given Swing JMenu or
|
||||||
|
* JPopupMenu.
|
||||||
|
*/
|
||||||
|
private static class MenuAdapter extends Menu {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for JMenu
|
||||||
|
*
|
||||||
|
* @param jMenu The JMenu to parallel in this Menu.
|
||||||
|
*/
|
||||||
|
MenuAdapter(final JMenu jMenu) {
|
||||||
|
super(jMenu.getText());
|
||||||
|
populateSubMenus(jMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for JPopupMenu
|
||||||
|
*
|
||||||
|
* @param jPopupMenu The JPopupMenu to parallel in this Menu.
|
||||||
|
*/
|
||||||
|
MenuAdapter(JPopupMenu jPopupMenu) {
|
||||||
|
super(jPopupMenu.getLabel());
|
||||||
|
populateSubMenus(jPopupMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populate the sub menus of this menu.
|
||||||
|
*
|
||||||
|
* @param menu The MenuElement whose sub elements will be used to
|
||||||
|
* populate the sub menus of this menu.
|
||||||
|
*/
|
||||||
|
private void populateSubMenus(MenuElement menu) {
|
||||||
|
for (MenuElement menuElement : menu.getSubElements()) {
|
||||||
|
if (menuElement == null) {
|
||||||
|
//Since null is sometime used to represenet a seperator, follow that convention.
|
||||||
|
getItems().add(new SeparatorMenuItem());
|
||||||
|
|
||||||
|
} else if (menuElement instanceof JMenuItem) {
|
||||||
|
getItems().add(SwingFXMenuUtils.createFXMenu(menuElement));
|
||||||
|
|
||||||
|
} else if (menuElement instanceof JPopupMenu) {
|
||||||
|
populateSubMenus(menuElement);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user