List of usage examples for javax.swing JMenuItem addMouseListener
public synchronized void addMouseListener(MouseListener l)
From source file:org.accada.reader.hal.impl.sim.multi.GraphicSimulatorServer.java
/** * creates the context menu if it does not already exists * //www .j a v a 2 s . c o m * @return context menu */ private JPopupMenu getContextMenu() { if (contextMenu == null) { contextMenu = new JPopupMenu(); // add new tag item JMenuItem newTagContextMenuItem = new JMenuItem(guiText.getString("AddNewTagMenuItem")); newTagContextMenuItem.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { showAddTagDialog(); contextMenu.setVisible(false); } }); contextMenu.add(newTagContextMenuItem); } return contextMenu; }
From source file:org.gtdfree.GTDFree.java
protected TrayIcon getTrayIcon() { if (trayIcon == null) { if (ApplicationHelper.isGTKLaF()) { trayIcon = new TrayIcon(ApplicationHelper.loadImage(ApplicationHelper.icon_name_large_tray_splash)); } else {//from www . ja v a 2 s . c o m trayIcon = new TrayIcon(ApplicationHelper.loadImage(ApplicationHelper.icon_name_small_tray_splash)); } trayIcon.setImageAutoSize(true); trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { trayIconPopup.setVisible(false); if (getJFrame().isVisible()) { getJFrame().setVisible(false); } else { pushVisible(); } } else { if (trayIconPopup.isVisible()) { trayIconPopup.setVisible(false); } else { Point p = new Point(e.getPoint()); /* * Disabled, because we are anyway doing things like rollover, * which are probably done by Frame. if (getJFrame().isShowing()) { SwingUtilities.convertPointFromScreen(p, getJFrame()); trayIconPopup.show(getJFrame(), p.x, p.y); } else { }*/ trayIconPopup.show(null, p.x, p.y); } } } }); trayIcon.setToolTip("GTD-Free - " + Messages.getString("GTDFree.Tray.desc")); //$NON-NLS-1$ //$NON-NLS-2$ /* * Necessary only when popup is showing with null window. Hides popup. */ MouseListener hideMe = new MouseAdapter() { @Override public void mouseExited(MouseEvent e) { if (e.getComponent() instanceof JMenuItem) { JMenuItem jm = (JMenuItem) e.getComponent(); jm.getModel().setRollover(false); jm.getModel().setArmed(false); jm.repaint(); } Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), trayIconPopup); //System.out.println(p.x+" "+p.y+" "+trayIconPopup.getWidth()+" "+trayIconPopup.getHeight()); if (p.x < 0 || p.x >= trayIconPopup.getWidth() || p.y < 0 || p.y >= trayIconPopup.getHeight()) { trayIconPopup.setVisible(false); } } @Override public void mouseEntered(MouseEvent e) { if (e.getComponent() instanceof JMenuItem) { JMenuItem jm = (JMenuItem) e.getComponent(); jm.getModel().setRollover(true); jm.getModel().setArmed(true); jm.repaint(); } } }; trayIconPopup = new JPopupMenu(); trayIconPopup.addMouseListener(hideMe); JMenuItem mi = new JMenuItem(Messages.getString("GTDFree.Tray.Drop")); //$NON-NLS-1$ mi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_small_collecting)); mi.setToolTipText(Messages.getString("GTDFree.Tray.Drop.desc")); //$NON-NLS-1$ mi.addMouseListener(hideMe); /* * Workaround for tray, if JFrame is showing, then mouse click is not fired */ mi.addMouseListener(new MouseAdapter() { private boolean click = false; @Override public void mousePressed(MouseEvent e) { click = true; } @Override public void mouseReleased(MouseEvent e) { if (click) { click = false; doMouseClicked(e); } } @Override public void mouseExited(MouseEvent e) { click = false; } private void doMouseClicked(MouseEvent e) { trayIconPopup.setVisible(false); Clipboard c = null; if (e.getButton() == MouseEvent.BUTTON1) { c = Toolkit.getDefaultToolkit().getSystemClipboard(); } else if (e.getButton() == MouseEvent.BUTTON2) { c = Toolkit.getDefaultToolkit().getSystemSelection(); } else { return; } try { Object o = c.getData(DataFlavor.stringFlavor); if (o != null) { getEngine().getGTDModel().collectAction(o.toString()); } flashMessage(Messages.getString("GTDFree.Tray.Collect.ok"), e.getLocationOnScreen()); //$NON-NLS-1$ } catch (Exception e1) { Logger.getLogger(this.getClass()).debug("Internal error.", e1); //$NON-NLS-1$ flashMessage(Messages.getString("GTDFree.Tray.Collect.fail") + e1.getMessage(), //$NON-NLS-1$ e.getLocationOnScreen()); } } }); TransferHandler th = new TransferHandler() { private static final long serialVersionUID = 1L; @Override public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { return DataFlavor.selectBestTextFlavor(transferFlavors) != null; } @Override public boolean importData(JComponent comp, Transferable t) { try { DataFlavor f = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors()); Object o = t.getTransferData(f); if (o != null) { getEngine().getGTDModel().collectAction(o.toString()); } return true; } catch (UnsupportedFlavorException e) { Logger.getLogger(this.getClass()).debug("Internal error.", e); //$NON-NLS-1$ } catch (IOException e) { Logger.getLogger(this.getClass()).debug("Internal error.", e); //$NON-NLS-1$ } return false; } }; mi.setTransferHandler(th); trayIconPopup.add(mi); mi = new JMenuItem(); mi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_delete)); mi.setText(Messages.getString("GTDFree.Tray.Hide")); //$NON-NLS-1$ mi.setToolTipText(Messages.getString("GTDFree.Tray.Hide.desc")); //$NON-NLS-1$ mi.addMouseListener(hideMe); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trayIconPopup.setVisible(false); if (getJFrame().isVisible()) { getJFrame().setVisible(false); } } }); trayIconPopup.add(mi); mi = new JMenuItem(); mi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_small_splash)); mi.setText(Messages.getString("GTDFree.Tray.Show")); //$NON-NLS-1$ mi.setToolTipText(Messages.getString("GTDFree.Tray.Show.desc")); //$NON-NLS-1$ mi.addMouseListener(hideMe); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trayIconPopup.setVisible(false); pushVisible(); } }); trayIconPopup.add(mi); mi = new JMenuItem(); mi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_exit)); mi.setText(Messages.getString("GTDFree.Tray.Exit")); //$NON-NLS-1$ mi.addMouseListener(hideMe); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trayIconPopup.setVisible(false); close(false); } }); trayIconPopup.add(mi); } return trayIcon; }
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java
/** * Brings up the <code>Available Scripts</code> on top of the specified * component at the specified location.// w w w .j a va 2 s. c o m * * @param c The component that requested the pop-pup menu. * @param p The point at which to display the menu, relative to the * <code>component</code>'s coordinates. */ void showAvailableScriptsMenu(Component c, Point p) { if (p == null) return; if (c == null) { c = scriptButton; } IconManager icons = IconManager.getInstance(); Collection<ScriptObject> scripts = model.getAvailableScripts(); if (CollectionUtils.isEmpty(scripts)) return; if (scriptsMenu == null) { scriptsMenu = new JPopupMenu(); JMenuItem refresh = new JMenuItem(icons.getIcon(IconManager.REFRESH)); refresh.setText("Reload Scripts"); refresh.setToolTipText("Reloads the existing scripts."); refresh.addMouseListener(new MouseAdapter() { /** * Launches the dialog when the user releases the mouse. * MouseAdapter#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { model.setAvailableScripts(null); scriptsMenu = null; controller.reloadAvailableScripts(e.getPoint()); } }); scriptsMenu.add(refresh); scriptsMenu.add(new JSeparator()); ScriptObject so; Map<String, JMenu> menus = new HashMap<String, JMenu>(); String path; Icon icon = icons.getIcon(IconManager.ANALYSIS); Icon largeIcon = icons.getIcon(IconManager.ANALYSIS_48); ActionListener listener = new ActionListener() { /** * Listens to the selection of a script. * @see ActionListener#actionPerformed(ActionEvent) */ public void actionPerformed(ActionEvent e) { ScriptMenuItem item = (ScriptMenuItem) e.getSource(); controller.handleScriptSelection(item.getScript()); } }; String name = ""; //loop twice to check if we need to add the first element String refString = null; int count = 0; Iterator<ScriptObject> i = scripts.iterator(); String sep; String[] values; String value; while (i.hasNext()) { so = i.next(); value = ""; path = so.getPath(); if (path != null) { sep = FilenameUtils.getPrefix(path); if (path.startsWith(sep)) path = path.substring(1, path.length()); values = UIUtilities.splitString(path); if (values != null && values.length > 0) value = values[0]; } if (refString == null) { refString = value; count++; } else if (refString.equals(value)) count++; } int index = 0; if (scripts.size() == count) index++; i = scripts.iterator(); List<JMenuItem> topMenus = new ArrayList<JMenuItem>(); JMenu ref = null; while (i.hasNext()) { so = i.next(); path = so.getPath(); if (path != null) { sep = FilenameUtils.getPrefix(path); if (path.startsWith(sep)) path = path.substring(1, path.length()); values = UIUtilities.splitString(path); if (values != null) { for (int j = index; j < values.length; j++) { value = values[j]; JMenu v; String text = name + value; if (menus.containsKey(text)) { v = menus.get(text); } else { value = value.replace(ScriptObject.PARAMETER_SEPARATOR, ScriptObject.PARAMETER_UI_SEPARATOR); v = new JMenu(value); } if (ref == null) topMenus.add(v); else ref.add(v); ref = v; name += values[j]; menus.put(name, v); } } } ScriptMenuItem item = new ScriptMenuItem(so); item.addActionListener(listener); if (ref != null) ref.add(item); else topMenus.add(item); name = ""; ref = null; if (so.getIcon() == null) { so.setIcon(icon); so.setIconLarge(largeIcon); } } Iterator<JMenuItem> j = topMenus.iterator(); while (j.hasNext()) { scriptsMenu.add(j.next()); } } scriptsMenu.show(c, p.x, p.y); }
From source file:org.pdfsam.guiclient.commons.panels.JVisualPdfPageSelectionPanel.java
/** * panel initialization//from w w w .j a v a 2 s . c om */ private void init() { setLayout(new GridBagLayout()); thumbnailList.setDrawDeletedItems(drawDeletedItems); if (dndSupport == DND_SUPPORT_FILES) { thumbnailList.setTransferHandler(new VisualListExportTransferHandler(pdfLoader)); } else if (dndSupport == DND_SUPPORT_JAVAOBJECTS) { thumbnailList.setTransferHandler(new VisualListTransferHandler()); } else if (dndSupport == DND_SUPPORT_FILES_AND_JAVAOBJECTS) { thumbnailList.setTransferHandler(new VisualListTransferHandler(pdfLoader)); } else { thumbnailList.setTransferHandler(new VisualListExportTransferHandler(null)); } thumbnailList.setDragEnabled(true); thumbnailList.setDropMode(DropMode.INSERT); pagesWorker = new PagesWorker(thumbnailList); thumbnailList.addKeyListener(new VisualPdfSelectionKeyAdapter(pagesWorker)); thumbnailList.addMouseListener(new PageOpenerMouseAdapter(thumbnailList)); if (showButtonPanel) { initButtonPanel(pagesWorker); initKeyListener(); } //JList orientation if (HORIZONTAL_ORIENTATION == orientation) { thumbnailList.setLayoutOrientation(JList.HORIZONTAL_WRAP); } else { if (wrap) { thumbnailList.setLayoutOrientation(JList.VERTICAL_WRAP); } } topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS)); topPanel.setPreferredSize(new Dimension(400, 30)); pdfSelectionActionListener = new VisualPdfSelectionActionListener(this, pdfLoader); if (topPanelStyle >= STYLE_TOP_PANEL_FULL) { //load button loadFileButton.setMargin(new Insets(1, 1, 1, 1)); loadFileButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Open")); loadFileButton.setPreferredSize(new Dimension(100, 30)); loadFileButton .setToolTipText(GettextResource.gettext(config.getI18nResourceBundle(), "Load a pdf document")); loadFileButton.setIcon(new ImageIcon(this.getClass().getResource("/images/add.png"))); loadFileButton.addKeyListener(new EnterDoClickListener(loadFileButton)); loadFileButton.setAlignmentX(Component.CENTER_ALIGNMENT); loadFileButton.setAlignmentY(Component.CENTER_ALIGNMENT); loadFileButton.setActionCommand(VisualPdfSelectionActionListener.ADD); loadFileButton.addActionListener(pdfSelectionActionListener); } documentProperties.setIcon(new ImageIcon(this.getClass().getResource("/images/info.png"))); documentProperties.setVisible(false); if (topPanelStyle >= STYLE_TOP_PANEL_MEDIUM) { clearButton.setMargin(new Insets(1, 1, 1, 1)); clearButton.setMinimumSize(new Dimension(30, 30)); clearButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Clear")); clearButton.setIcon(new ImageIcon(this.getClass().getResource("/images/clear.png"))); clearButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resetPanel(); } }); } zoomInButton.setMargin(new Insets(1, 1, 1, 1)); zoomInButton.setMinimumSize(new Dimension(30, 30)); zoomInButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Zoom in")); zoomInButton.setIcon(new ImageIcon(this.getClass().getResource("/images/zoomin.png"))); zoomInButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { thumbnailList.incZoomLevel(); zoomOutButton.setEnabled(true); if (thumbnailList.getCurrentZoomLevel() >= JVisualSelectionList.MAX_ZOOM_LEVEL) { zoomInButton.setEnabled(false); } ((VisualListModel) thumbnailList.getModel()).elementsChanged(); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error setting zoom level."), ex); } } }); zoomOutButton.setMargin(new Insets(1, 1, 1, 1)); zoomOutButton.setMinimumSize(new Dimension(30, 30)); zoomOutButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Zoom out")); zoomOutButton.setIcon(new ImageIcon(this.getClass().getResource("/images/zoomout.png"))); zoomOutButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { thumbnailList.deincZoomLevel(); zoomInButton.setEnabled(true); if (thumbnailList.getCurrentZoomLevel() <= JVisualSelectionList.MIN_ZOOM_LEVEL) { zoomOutButton.setEnabled(false); } ((VisualListModel) thumbnailList.getModel()).elementsChanged(); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error setting zoom level."), ex); } } }); thumbnailList.setModel(new VisualListModel()); thumbnailList.setCellRenderer(new VisualListRenderer()); thumbnailList.setVisibleRowCount(-1); thumbnailList.setSelectionMode(selectionType); JScrollPane listScroller = new JScrollPane(thumbnailList); //preview item menuItemPreview.setIcon(new ImageIcon(this.getClass().getResource("/images/preview-viewer.png"))); menuItemPreview.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Preview")); menuItemPreview.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { int[] selection = thumbnailList.getSelectedIndices(); if (selection != null && selection.length == 1) { VisualPageListItem item = (VisualPageListItem) thumbnailList.getModel() .getElementAt(selection[0]); PagePreviewOpener.getInstance().openPreview(item.getParentFileCanonicalPath(), item.getDocumentPassword(), item.getPageNumber()); } } }); if (showContextMenu) { //popup final JMenuItem menuItemMoveUp = new JMenuItem(); menuItemMoveUp.setIcon(new ImageIcon(this.getClass().getResource("/images/up.png"))); menuItemMoveUp.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Move Up")); menuItemMoveUp.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.MOVE_UP, pagesWorker)); popupMenu.add(menuItemMoveUp); final JMenuItem menuItemMoveDown = new JMenuItem(); menuItemMoveDown.setIcon(new ImageIcon(this.getClass().getResource("/images/down.png"))); menuItemMoveDown.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Move Down")); menuItemMoveDown .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.MOVE_DOWN, pagesWorker)); popupMenu.add(menuItemMoveDown); final JMenuItem menuItemRemove = new JMenuItem(); menuItemRemove.setIcon(new ImageIcon(this.getClass().getResource("/images/remove.png"))); menuItemRemove.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Delete")); menuItemRemove.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.REMOVE, pagesWorker)); popupMenu.add(menuItemRemove); //if elements are physically deleted i don't need this item if (drawDeletedItems) { final JMenuItem menuItemUndelete = new JMenuItem(); menuItemUndelete.setIcon(new ImageIcon(this.getClass().getResource("/images/remove.png"))); menuItemUndelete.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Undelete")); menuItemUndelete .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.UNDELETE, pagesWorker)); popupMenu.add(menuItemUndelete); } //rotate item final JMenuItem menuItemRotate = new JMenuItem(); menuItemRotate.setIcon(new ImageIcon(this.getClass().getResource("/images/clockwise.png"))); menuItemRotate.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Rotate clockwise")); menuItemRotate .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.ROTATE_CLOCK, pagesWorker)); popupMenu.add(menuItemRotate); //rotate anticlock item final JMenuItem menuItemAntiRotate = new JMenuItem(); menuItemAntiRotate.setIcon(new ImageIcon(this.getClass().getResource("/images/anticlockwise.png"))); menuItemAntiRotate .setText(GettextResource.gettext(config.getI18nResourceBundle(), "Rotate anticlockwise")); menuItemAntiRotate.addMouseListener( new VisualPdfSelectionMouseAdapter(PagesWorker.ROTATE_ANTICLOCK, pagesWorker)); popupMenu.add(menuItemAntiRotate); //reverse item final JMenuItem menuItemReverse = new JMenuItem(); menuItemReverse.setIcon(new ImageIcon(this.getClass().getResource("/images/reverse.png"))); menuItemReverse.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Reverse")); menuItemReverse.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.REVERSE, pagesWorker)); popupMenu.add(menuItemReverse); enableSetOutputPathMenuItem(); addPopupShower(); } popupMenu.add(menuItemPreview); if (topPanelStyle >= STYLE_TOP_PANEL_FULL) { topPanel.add(Box.createRigidArea(new Dimension(5, 0))); topPanel.add(loadFileButton); } if (topPanelStyle >= STYLE_TOP_PANEL_MEDIUM) { topPanel.add(Box.createRigidArea(new Dimension(5, 0))); topPanel.add(clearButton); } topPanel.add(Box.createRigidArea(new Dimension(5, 0))); topPanel.add(documentProperties); topPanel.add(Box.createHorizontalGlue()); topPanel.add(zoomInButton); topPanel.add(Box.createRigidArea(new Dimension(5, 0))); topPanel.add(zoomOutButton); GridBagConstraints topConstraints = new GridBagConstraints(); topConstraints.fill = GridBagConstraints.BOTH; topConstraints.gridx = 0; topConstraints.gridy = 0; topConstraints.gridwidth = 3; topConstraints.gridheight = 1; topConstraints.insets = new Insets(5, 5, 5, 5); topConstraints.weightx = 1.0; topConstraints.weighty = 0.0; if (topPanelStyle > STYLE_TOP_PANEL_HIDE) { add(topPanel, topConstraints); } GridBagConstraints thumbConstraints = new GridBagConstraints(); thumbConstraints.fill = GridBagConstraints.BOTH; thumbConstraints.gridx = 0; thumbConstraints.gridy = 1; thumbConstraints.gridwidth = (showButtonPanel ? 2 : 3); thumbConstraints.gridheight = 2; thumbConstraints.insets = new Insets(5, 5, 5, 5); thumbConstraints.weightx = 1.0; thumbConstraints.weighty = 1.0; add(listScroller, thumbConstraints); if (showButtonPanel) { GridBagConstraints buttonsConstraints = new GridBagConstraints(); buttonsConstraints.fill = GridBagConstraints.BOTH; buttonsConstraints.gridx = 2; buttonsConstraints.gridy = 1; buttonsConstraints.gridwidth = 1; buttonsConstraints.gridheight = 2; buttonsConstraints.insets = new Insets(5, 5, 5, 5); buttonsConstraints.weightx = 0.0; buttonsConstraints.weighty = 1.0; add(buttonPanel, buttonsConstraints); } }
From source file:studio.ui.Studio.java
private void rebuildMenus(TabIndexChanged event) { AppMenuBar appMenubar = getJMenuBar() instanceof AppMenuBar ? (AppMenuBar) getJMenuBar() : null; ToolBarActions toolBar = null;/*from www. j a v a 2s. c o m*/ ActionMenu menuBar = null; if (appToolbar == null && appMenubar == null) { appToolbar = new ToolBarActions(); getContentPane().add(appToolbar, BorderLayout.NORTH); appMenubar = new AppMenuBar(); setJMenuBar(appMenubar); toolBar = new ToolBarActions("File"); menuBar = new ActionMenu("File", 'f', "File operations", (MouseAdapter) null); Action action = new NewFileAction(tabEditors, tabConsoles); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem item = new JMenuItem("Script"); item.setToolTipText("New script"); item.addMouseListener(new ActionHintsListener(tabEditors, "Create new script")); item.addActionListener(action); popupMenu.add(item); item = new JMenuItem("Project"); item.setToolTipText("New project"); item.addMouseListener(new ActionHintsListener(tabEditors, "Create new project")); try { item.addActionListener(new AddProjectAction(treeProjects)); popupMenu.add(item); } catch (StudioException ex) { } JButton button = new DropDownButton(action, popupMenu); if (button instanceof DataListener) { tabEditors.addFireDataListener((DataListener) button); } button.addMouseListener(new ActionHintsListener(tabEditors, action)); toolBar.add(button); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); action = new OpenFileAction(tabEditors, tabConsoles); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); popupMenu = null; if (studioConfig.getOpenedFiles() != null && !studioConfig.getOpenedFiles().isEmpty()) { popupMenu = new JPopupMenu(); int pos = 0; for (EditorFile file : studioConfig.getOpenedFiles()) { item = new JMenuItem((char) (pos + 48) + " " + file.getPath(), pos + 48); item.addMouseListener(new ActionHintsListener(tabEditors, "Open file " + file)); popupMenu.add(item); if (++pos > 9) { break; } } } button = new DropDownButton(action, popupMenu); if (button instanceof DataListener) { tabEditors.addFireDataListener((DataListener) button); } button.addMouseListener(new ActionHintsListener(tabEditors, action)); toolBar.add(button); appToolbar.add(toolBar); appMenubar.add(menuBar); appToolbar.add(new ToolBarActions("KDB+")); appMenubar.add(new ActionMenu("KDB+", 'k', "KDB+ databse operations", (MouseAdapter) null)); appToolbar.add(new ToolBarActions("Edit")); appMenubar.add(new ActionMenu("Edit", 'E', "Editor operations", (MouseAdapter) null)); toolBar = new ToolBarActions("Options"); appToolbar.add(toolBar); menuBar = new ActionMenu("Tools", 'T', "Tools", (MouseAdapter) null); ActionMenu opMenuBar = new ActionMenu("Options", 'O', "Studio settings", (MouseAdapter) null); ActionMenu lfMenuBar = new ActionMenu("Look and feel", 'L', "L&F", (MouseAdapter) null); LookAndFeelAction.getActionLookAndFeel(this, lfMenuBar, studioConfig); opMenuBar.add(lfMenuBar); opMenuBar.addSeparator(); action = new EditorSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); action = new TokensSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); opMenuBar.addSeparator(); action = new ConsoleSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); opMenuBar.addSeparator(); action = new ConnectionsSettingsAction(treeConnections); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.add(opMenuBar); opMenuBar.addSeparator(); action = new GlobalSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); opMenuBar.addSeparator(); action = new ProjectSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); menuBar = new ActionMenu("Help", 'H', "Help...", (MouseAdapter) null); action = new VisitKxAction(); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.addSeparator(); action = new VisitWroclawAction(); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.addSeparator(); action = new KeyListAction(tabEditors); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.addSeparator(); action = new AboutAction(tabEditors); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); menuBar.addSeparator(); action = new CheckUpdate(this); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); toolBar = null; this.setJMenuBar(appMenubar); } appToolbar.getToolBar("Edit").setVisible(event != null && event.getData() != -1); appToolbar.getToolBar("Options").setVisible(event != null && event.getData() != -1); appToolbar.getToolBar("KDB+").setVisible(event != null && event.getData() != -1); appToolbar.getToolBar("File").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("Edit").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("Tools").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("KDB+").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("File").setVisible(event != null && event.getData() != -1); if (event != null && event.getSource() instanceof EditorsTabbedPane && event.getData() != -1) { Editor editor = ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()); if (editor != null) { JPopupMenu menu = editor.getComponentPopupMenu(); if (menu != null) { for (int count = 0; count < menu.getComponentCount(); count++) { if (menu.getComponent(count) instanceof JMenuItem) { JMenuItem menuItem = (JMenuItem) menu.getComponent(count); if (menuItem.getAction().getClass() == SaveAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction(), true); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction(), true); } else { if (menuItem.getAction().getClass() == SaveAsAction.class || menuItem.getAction().getClass() == SaveAllAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction()); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction()); } else { if (menuItem.getAction().getClass() == CloseAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction(), true); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction(), true); } else { if (menuItem.getAction().getClass() == CloseAllAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction()); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction()); } else { if (menuItem.getAction().getClass() == RunAction.class || menuItem.getAction().getClass() == RunLineAction.class || menuItem.getAction().getClass() == CancelRunAction.class) { appToolbar.getToolBar("KDB+").update(tabEditors, menuItem.getAction()); appMenubar.getMenu("KDB+").update(tabEditors, menuItem.getAction()); } else { if (menuItem.getAction().getClass() == ExtKit.ReplaceAction.class || menuItem.getAction() .getClass() == ActionFactory.RedoAction.class || menuItem.getAction() .getClass() == ActionFactory.UndoAction.class || menuItem.getAction() .getClass() == BaseKit.CopyAction.class || menuItem.getAction() .getClass() == BaseKit.PasteAction.class || menuItem.getAction() .getClass() == ExtKit.GotoAction.class || menuItem.getAction() .getClass() == BaseKit.SelectAllAction.class || menuItem.getAction() .getClass() == BaseKit.SelectLineAction.class || menuItem.getAction() .getClass() == BaseKit.CutAction.class) { appToolbar.getToolBar("Edit").update(tabEditors, menuItem.getAction()); if (menuItem.getAction().getClass() == ExtKit.GotoAction.class || menuItem.getAction() .getClass() == BaseKit.CopyAction.class || menuItem.getAction() .getClass() == BaseKit.SelectAllAction.class) { appMenubar.getMenu("Edit").update(tabEditors, menuItem.getAction(), true); } else { appMenubar.getMenu("Edit").update(tabEditors, menuItem.getAction()); } } } } } } } } } } } } if (event != null && event.getData() != -1 && event.getSource() instanceof EditorsTabbedPane && ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()) != null) { ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()).requestFocus(); } }