public void actionPerformed(ActionEvent ev) { JComponent src = (JComponent) ev.getSource(); if (src == saveAsMI) { saveAs(); } else { int index = timeRangeMenu.getPopupMenu().getComponentIndex(src); setViewRange(rangeValues[index]); } }
public void mousePressed(MouseEvent e) { // jdf if (!isEnabled()) return; final int x = e.getX(); final int y = e.getY(); int sel = findSelection(x, y); ///if (sel == -1) return false; if (sel == -1) return; currentRollover = -1; switch (sel) { case RUN: editor.handleRun(e.isShiftDown()); break; // case STOP: // editor.handleStop(); // break; // case OPEN: popup = menu.getPopupMenu(); popup.show(EditorToolbar.this, x, y); break; case NEW: if (shiftPressed) { editor.base.handleNew(); } else { editor.base.handleNewReplace(); } break; case SAVE: editor.handleSave(false); break; case EXPORT: boolean t = e.isControlDown(); editor.handleExport(e.isShiftDown(),autoOpenSerialMonitor ? !t : t); // Control is down if autoOpenSerialMonitor is true in preferences break; case SERIAL: editor.handleSerial(); handleMouse(e); break; } }
/** * Examines the list of menu items to determine whether <code>popup</code> is a popup menu. * * @param popup a <code>JPopupMenu</code> * @return true if <code>popup</code> */ boolean isSubPopupMenu(JPopupMenu popup) { int ncomponents = this.getComponentCount(); Component[] component = this.getComponents(); for (int i = 0; i < ncomponents; i++) { Component comp = component[i]; if (comp instanceof JMenu) { JMenu menu = (JMenu) comp; JPopupMenu subPopup = menu.getPopupMenu(); if (subPopup == popup) return true; if (subPopup.isSubPopupMenu(popup)) return true; } } return false; }
/** * Gets the <tt>JMenu</tt> which is the component of this plug-in. If it still doesn't exist, it's * created. * * @return the <tt>JMenu</tt> which is the component of this plug-in */ private JMenu getMenu() { if (menu == null) { menu = new SIPCommMenu(); menu.setText(getName()); if (Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU.equals(getContainer())) { Icon icon = OtrActivator.resourceService.getImage("plugin.otr.MENU_ITEM_ICON_16x16"); if (icon != null) menu.setIcon(icon); } if (!inMacOSXScreenMenuBar) menu.getPopupMenu().addPopupMenuListener(this); } return menu; }
// Main program -- create and start GUI public Mesh(boolean debug) { // Create drawing area for shape worldDraw = new WorldView(this, shape, debug); worldDraw.setSize(500, 500); // Create menubar JMenuBar menubar = new JMenuBar(); setJMenuBar(menubar); JMenu menu = new JMenu("File"); menu.getPopupMenu().setLightWeightPopupEnabled(false); menubar.add(menu); // Exit when quit selected JMenuItem resetm = menu.add("Reset"); resetm.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Parameter.blockAction(true); // Reset all parameters shape.reset(); Parameter.blockAction(false); Parameter.onUserAction(); } }); // Exit when quit selected JMenuItem quitm = menu.add("Quit"); quitm.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); // ------------------------------------------------------ // Lay out main window GridBagLayout layout = new GridBagLayout(); GridBagConstraints con = new GridBagConstraints(); Container c = getContentPane(); c.setLayout(layout); // World viewport con.gridwidth = 1; con.weightx = 0.2; con.weighty = 1.0; con.fill = GridBagConstraints.BOTH; con.insets = new Insets(4, 4, 4, 2); layout.setConstraints(worldDraw, con); c.add(worldDraw); // -- Parameter controls // Make container for controls Container cc = new Container(); con.gridwidth = GridBagConstraints.REMAINDER; con.weightx = 0.2; con.weighty = 1.0; con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(cc, con); c.add(cc); // Fill compartment GridBagLayout clayout = new GridBagLayout(); cc.setLayout(clayout); GridBagConstraints ccon = new GridBagConstraints(); ccon.weightx = 1.0; ccon.weighty = 1.0; ccon.anchor = GridBagConstraints.NORTH; ccon.insets = new Insets(10, 10, 0, 10); ccon.fill = GridBagConstraints.BOTH; ccon.gridwidth = GridBagConstraints.REMAINDER; makeControls(cc, clayout, ccon, shape.getParams(), shape.getOptions(), "Object parameters"); // ------------------------------------------------------ // Exit when window closes addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // Placement of window on screen setLocation(100, 50); pack(); setVisible(true); }
public static void main(String[] args) throws Throwable { sun.awt.SunToolkit toolkit = (sun.awt.SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { test = new TaskbarPositionTest(); } }); // Use Robot to automate the test Robot robot; robot = new Robot(); robot.setAutoDelay(125); // 1 - menu Util.hitMnemonics(robot, KeyEvent.VK_1); toolkit.realSync(); isPopupOnScreen(menu1.getPopupMenu(), screenBounds); // 2 menu with sub menu robot.keyPress(KeyEvent.VK_RIGHT); robot.keyRelease(KeyEvent.VK_RIGHT); Util.hitMnemonics(robot, KeyEvent.VK_S); toolkit.realSync(); isPopupOnScreen(menu2.getPopupMenu(), screenBounds); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); // Focus should go to non editable combo box toolkit.realSync(); Thread.sleep(500); robot.keyPress(KeyEvent.VK_DOWN); // How do we check combo boxes? // Editable combo box robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); // combo1.getUI(); // Popup from Text field robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_CONTROL); // Popup from a mouse click. Point pt = new Point(2, 2); SwingUtilities.convertPointToScreen(pt, panel); robot.mouseMove((int) pt.getX(), (int) pt.getY()); robot.mousePress(InputEvent.BUTTON3_MASK); robot.mouseRelease(InputEvent.BUTTON3_MASK); toolkit.realSync(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { test.setLocation(-30, 100); combo1.addPopupMenuListener(new ComboPopupCheckListener()); combo1.requestFocus(); } }); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); robot.keyPress(KeyEvent.VK_ESCAPE); robot.keyRelease(KeyEvent.VK_ESCAPE); toolkit.realSync(); Thread.sleep(500); }