Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
SwingFXMenuUtils.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 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.listvew;
20 
21 import javafx.scene.control.Menu;
22 import javafx.scene.control.MenuItem;
23 import javafx.scene.control.SeparatorMenuItem;
24 import javax.swing.JMenu;
25 import javax.swing.JMenuItem;
26 import javax.swing.JPopupMenu;
27 import javax.swing.MenuElement;
28 import javax.swing.SwingUtilities;
29 
34 public class SwingFXMenuUtils extends MenuItem {
35 
43  public static MenuItem createFXMenu(MenuElement jMenuElement) {
44  if (jMenuElement == null) {
45  //Since null is sometime used to represenet a seperator, follow that convention.
46  return new SeparatorMenuItem();
47  } else if (jMenuElement instanceof JMenu) {
48  return new MenuAdapter((JMenu) jMenuElement);
49  } else if (jMenuElement instanceof JPopupMenu) {
50  return new MenuAdapter((JPopupMenu) jMenuElement);
51  } else {
52  return new MenuItemAdapter((JMenuItem) jMenuElement);
53  }
54  }
55 
59  private static class MenuItemAdapter extends MenuItem {
60 
61  private MenuItemAdapter(final JMenuItem jMenuItem) {
62  super(jMenuItem.getText());
63  setOnAction(actionEvent -> SwingUtilities.invokeLater(jMenuItem::doClick));
64  }
65  }
66 
71  private static class MenuAdapter extends Menu {
72 
78  MenuAdapter(final JMenu jMenu) {
79  super(jMenu.getText());
80  populateSubMenus(jMenu);
81  }
82 
88  MenuAdapter(JPopupMenu jPopupMenu) {
89  super(jPopupMenu.getLabel());
90  populateSubMenus(jPopupMenu);
91  }
92 
99  private void populateSubMenus(MenuElement menu) {
100  for (MenuElement menuElement : menu.getSubElements()) {
101  if (menuElement == null) {
102  //Since null is sometime used to represenet a seperator, follow that convention.
103  getItems().add(new SeparatorMenuItem());
104 
105  } else if (menuElement instanceof JMenuItem) {
106  getItems().add(SwingFXMenuUtils.createFXMenu(menuElement));
107 
108  } else if (menuElement instanceof JPopupMenu) {
109  populateSubMenus(menuElement);
110 
111  } else {
112  throw new UnsupportedOperationException("Unown MenuElement subclass: " + menuElement.getClass().getName());
113  }
114  }
115  }
116  }
117 }
static MenuItem createFXMenu(MenuElement jMenuElement)

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.