use of javax.swing.event.MenuEvent in project fql by CategoricalData.
the class ApplicationFrame method buildMenu.
/**
* Builds the menu
*/
private void buildMenu() {
final JMenuBar mainMenu;
final JMenu menuFile;
final JMenu menuEdit;
@SuppressWarnings("unused") JMenu menuAction;
final JMenu menuHelp;
mainMenu = new JMenuBar();
// Make the File Menu
menuFile = new JMenu("File");
addMenuItem(menuFile, new FileNewOverviewAction(this), KeyEvent.VK_N);
addMenuItem(menuFile, new FileOpenAction(this), KeyEvent.VK_O);
menuFile.addSeparator();
addMenuItem(menuFile, new FileSaveAction(this), KeyEvent.VK_S);
addMenuItem(menuFile, new FileSaveAsAction(this), KeyEvent.VK_S, InputEvent.SHIFT_DOWN_MASK);
menuFile.addSeparator();
_recentFilesMenu = new JMenu("Open recent...");
menuFile.add(_recentFilesMenu);
updateRecentFilesMenu();
menuFile.addSeparator();
addMenuItem(menuFile, new OverviewDocumentInfoAction(this), KeyEvent.VK_I);
menuFile.addSeparator();
addMenuItem(menuFile, new FileQuitAction(this), KeyEvent.VK_Q);
mainMenu.add(menuFile);
menuFile.setMnemonic(KeyEvent.VK_F);
menuEdit = new JMenu("Edit");
menuEdit.add(new JMenuItem(new NewSketchAction(null, _overview)));
menuEdit.add(new JMenuItem(new ImportSketchAction(null, _overview)));
menuEdit.addSeparator();
menuEdit.add(_NewViewMenuItem = new JMenuItem(new NewViewAction(_overview)));
mainMenu.add(menuEdit);
menuEdit.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e1) {
final Object[] selection = _overview.getSelectionCells();
_NewViewMenuItem.setEnabled((selection.length == 1) && (selection[0] instanceof SketchNode));
}
@Override
public void menuDeselected(final MenuEvent e1) {
}
@Override
public void menuCanceled(final MenuEvent e1) {
}
});
menuEdit.addSeparator();
// If
addMenuItem(menuEdit, _ProgramSettingsItem = new JMenuItem("Preferences"), KeyEvent.VK_E);
// you
// change
// this
// title,
// update
// OSX.java
_ProgramSettingsItem.setToolTipText("Set Global Easik Properties");
_ProgramSettingsItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e1) {
final ProgramSettingsUI myUI = new ProgramSettingsUI(ApplicationFrame.this);
myUI.showDialog();
}
});
menuEdit.setMnemonic(KeyEvent.VK_E);
// Create help menu
menuHelp = new JMenu("Help");
mainMenu.add(menuHelp);
menuHelp.setMnemonic(KeyEvent.VK_H);
menuHelp.add(new HelpAction());
menuHelp.add(new AboutAction());
setJMenuBar(mainMenu);
}
use of javax.swing.event.MenuEvent in project cytoscape-api by cytoscape.
the class JMenuTracker method getGravityTracker.
/**
* This method will fetch an existing menu or create a new one if a menu
* with the specified name does not exist. The menu name is specified
* with a '.' delimited string, such that each token creates a new child
* menu. Insertion locations are determined in two possible ways: 1) a "gravity" or "weight"
* may be specified in square brackets after each item name. If the gravity has been
* omitted, the insertion location will be based on a case-insensitive alphanumeric
* ordering. An example of a string using weights is "File[10].New[40]".
*
* @param menuString A '.' delimited string identifying menu names.
* @return The last child JMenu object specified by the menu_string parameter.
*/
public GravityTracker getGravityTracker(final String menuString) {
if (menuString == null)
throw new NullPointerException("menu string is null");
if (menuString.isEmpty())
throw new IllegalArgumentException("menu string has zero length");
// Special case: if we have a popup menu and the menu is "." return the rootGravityTracker
if (menuString.equals(".") && rootPopupGravityTracker != null)
return rootPopupGravityTracker;
final List<MenuNameAndGravity> namesAndGravities = parseMenuString(menuString);
MenuGravityTracker parentGravityTracker = null;
MenuGravityTracker gravityTracker = null;
String menu_key = null;
for (final MenuNameAndGravity nameAndGravity : namesAndGravities) {
final String menu_token = nameAndGravity.getMenuName();
menu_key = menu_key == null ? menu_token : menu_key + "." + menu_token;
gravityTracker = menuMap.get(menu_key);
if (gravityTracker == null) {
final JMenu menu = new JMenu(menu_token);
menu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
// Force update of enabled state of all of its direct menu items
final int itemCount = menu.getItemCount();
for (int i = 0; i < itemCount; i++) {
final JMenuItem item = menu.getItem(i);
if (item != null && item.getAction() != null)
item.setEnabled(item.getAction().isEnabled());
}
}
@Override
public void menuDeselected(MenuEvent e) {
}
@Override
public void menuCanceled(MenuEvent e) {
}
});
// if there is a JMenu parent, use that
if (parentGravityTracker != null)
parentGravityTracker.addMenu(menu, nameAndGravity.getGravity());
else // otherwise use add the menu to the root component
if (rootMenuBar != null && rootPopupGravityTracker == null)
rootMenuBar.add(menu);
else if (rootMenuBar == null && rootPopupGravityTracker != null)
rootPopupGravityTracker.addMenu(menu, nameAndGravity.getGravity());
else
throw new IllegalStateException("we have no root popup menu or menu bar.");
gravityTracker = new MenuGravityTracker(menu);
menuMap.put(menu_key, gravityTracker);
}
parentGravityTracker = gravityTracker;
}
return gravityTracker;
}
use of javax.swing.event.MenuEvent in project cuba by cuba-platform.
the class MenuBuilder method createMenuBarItem.
private void createMenuBarItem(JMenuBar menuBar, MenuItem item) {
String caption = menuConfig.getItemCaption(item.getId());
if (!item.getChildren().isEmpty() || item.isMenu()) {
final JMenu jMenu = new JMenu(caption);
jMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
jMenu.requestFocus();
}
@Override
public void menuDeselected(MenuEvent e) {
}
@Override
public void menuCanceled(MenuEvent e) {
}
});
jMenu.setName(item.getId());
menuBar.add(jMenu);
createSubMenu(jMenu, item);
} else {
JMenuItem jMenuItem = new JMenuItem(caption);
jMenuItem.setName(item.getId());
// todo remove hardcoded border
jMenuItem.setBorder(BorderFactory.createEmptyBorder(1, 4, 2, 4));
assignShortcut(jMenuItem, item);
jMenuItem.setMaximumSize(new Dimension(jMenuItem.getPreferredSize().width, jMenuItem.getMaximumSize().height));
assignCommand(jMenuItem, item);
menuBar.add(jMenuItem);
}
}
use of javax.swing.event.MenuEvent in project artisynth_core by artisynth.
the class ViewerFrame method addMenuBar.
public JMenuBar addMenuBar() {
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menu = new JMenu("File");
menu.addMenuListener(new MenuAdapter() {
public void menuSelected(MenuEvent m_evt) {
createFileMenu((JMenu) m_evt.getSource());
}
});
menuBar.add(menu);
menu = new JMenu("View");
menu.addMenuListener(new MenuAdapter() {
public void menuSelected(MenuEvent m_evt) {
createViewMenu((JMenu) m_evt.getSource());
}
});
menuBar.add(menu);
return menuBar;
}
use of javax.swing.event.MenuEvent in project artisynth_core by artisynth.
the class MenuBarHandler method createMenus.
/**
* creates menu items
*/
public void createMenus() {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
myMenuBar = new JMenuBar();
myToolBar = new JPanel();
myToolBar.setLayout(new BoxLayout(myToolBar, BoxLayout.LINE_AXIS));
myToolBar.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
// File menu
JMenu menu = new JMenu("File");
menu.addMenuListener(new MenuListener() {
public void menuCanceled(MenuEvent m_evt) {
}
public void menuDeselected(MenuEvent m_evt) {
JMenu menu = (JMenu) m_evt.getSource();
menu.removeAll();
}
public void menuSelected(MenuEvent m_evt) {
createFileMenu((JMenu) m_evt.getSource());
}
});
myMenuBar.add(menu);
// Create the menu with models (taken from .demoModels)
menu = new JMenu("Models");
myMenuBar.add(menu);
createDemosMenu(menu);
menu = createScriptsMenu("Scripts");
if (menu != null) {
myMenuBar.add(menu);
}
// "Edit" menu:
menu = new JMenu("Edit");
menu.addMenuListener(new MenuListener() {
public void menuCanceled(MenuEvent m_evt) {
}
public void menuDeselected(MenuEvent m_evt) {
JMenu menu = (JMenu) m_evt.getSource();
menu.removeAll();
}
public void menuSelected(MenuEvent m_evt) {
createEditMenu((JMenu) m_evt.getSource());
}
});
myMenuBar.add(menu);
// "Settings" menu:
menu = new JMenu("Settings");
menu.addMenuListener(new MenuListener() {
public void menuCanceled(MenuEvent m_evt) {
}
public void menuDeselected(MenuEvent m_evt) {
JMenu menu = (JMenu) m_evt.getSource();
menu.removeAll();
}
public void menuSelected(MenuEvent m_evt) {
createSettingsMenu((JMenu) m_evt.getSource());
}
});
myMenuBar.add(menu);
// Create the view menu
menu = new JMenu("View");
menu.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent m_evt) {
createViewMenu((JMenu) m_evt.getSource());
}
public void menuDeselected(MenuEvent m_evt) {
JMenu menu = (JMenu) m_evt.getSource();
menu.removeAll();
}
public void menuCanceled(MenuEvent m_evt) {
}
});
myMenuBar.add(menu);
// Help menu section
menu = new JMenu("Help");
menu.addMenuListener(new MenuListener() {
public void menuCanceled(MenuEvent m_evt) {
}
public void menuDeselected(MenuEvent m_evt) {
JMenu menu = (JMenu) m_evt.getSource();
menu.removeAll();
}
public void menuSelected(MenuEvent m_evt) {
createHelpMenu((JMenu) m_evt.getSource());
}
});
myMenuBar.add(menu);
// Application menu section
menu = new JMenu("Application");
menu.addMenuListener(new MenuListener() {
public void menuCanceled(MenuEvent m_evt) {
}
public void menuDeselected(MenuEvent m_evt) {
JMenu menu = (JMenu) m_evt.getSource();
menu.removeAll();
}
public void menuSelected(MenuEvent m_evt) {
createApplicationMenu((JMenu) m_evt.getSource());
}
});
myApplicationMenu = menu;
// myFrame.setJMenuBar(myMenuBar);
// Adding iconic buttons
// Create a space separator
// height makes space for GridDisplay box
myMenuBar.add(Box.createRigidArea(new Dimension(20, 28)));
// Create navigation bar button
navBarButton = ButtonCreator.createIconicButton(GuiStorage.getNavBarIcon(), myFrame.getNavPanel().getStatus() ? "Hide NavBar" : "Show Navbar", myFrame.getNavPanel().getStatus() ? "Hide NavBar" : "Show Navbar", ButtonCreator.BUTTON_ENABLED, false, this);
myToolBar.add(Box.createRigidArea(new Dimension(2, 0)));
myToolBar.add(navBarButton);
myToolBar.add(Box.createRigidArea(new Dimension(2, 0)));
rerenderButton = ButtonCreator.createIconicButton(GuiUtils.loadIcon(ControlPanel.class, "icon/refresh.png"), "Re-render", "Re-render", ButtonCreator.BUTTON_ENABLED, false, this);
myToolBar.add(rerenderButton);
// Charles modification
// creates a message Box. Currently only used for Units
// grid not visible reset textField
myToolBar.add(Box.createRigidArea(new Dimension(10, 0)));
myToolBar.add(Box.createHorizontalGlue());
myGridDisplayIndex = myToolBar.getComponentCount();
myToolBar.add(GridDisplay.createPlaceHolder());
myStepDisplay = createStepDisplay();
myToolBar.add(myStepDisplay);
// myToolBar.add (Box.createRigidArea (new Dimension (4, 0)));
myTimeDisplay = createTimeDisplay();
myToolBar.add(myTimeDisplay);
myToolBar.add(Box.createRigidArea(new Dimension(4, 0)));
// Create reset button
resetButton = ButtonCreator.createIconicButton(GuiStorage.getResetIcon(), "Reset", "Reset", ButtonCreator.BUTTON_ENABLED, false, this);
myToolBar.add(resetButton);
myToolBar.add(Box.createRigidArea(new Dimension(2, 0)));
// Create play button
playButton = ButtonCreator.createIconicButton(GuiStorage.getPlayIcon(), "Play", "Play", ButtonCreator.BUTTON_DISABLED, false, this);
myToolBar.add(playButton);
myToolBar.add(Box.createRigidArea(new Dimension(2, 0)));
// Create step button
singleStepButton = ButtonCreator.createIconicButton(GuiStorage.getStepForwardIcon(), "Single step", "Single step", ButtonCreator.BUTTON_DISABLED, false, this);
myToolBar.add(singleStepButton);
myToolBar.add(Box.createRigidArea(new Dimension(2, 0)));
// Set the menu bar
myFrame.setJMenuBar(myMenuBar);
myFrame.add(myToolBar, BorderLayout.NORTH);
}
Aggregations