javax.swing.JPopupMenu Java Examples

The following examples show how to use javax.swing.JPopupMenu. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TableView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void showPopup (MouseEvent e) {
    int selRow = table.rowAtPoint(e.getPoint());

    if (selRow != -1) {
        if (! table.getSelectionModel().isSelectedIndex(selRow)) {
            table.getSelectionModel().clearSelection();
            table.getSelectionModel().setSelectionInterval(selRow, selRow);
        }
    } else {
        table.getSelectionModel().clearSelection();
    }
    Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), TableView.this);
    if (isPopupAllowed()) {
        JPopupMenu pop = createPopup(p);
        TableView.this.showPopup(p.x, p.y, pop);
        e.consume();
    }
}
 
Example #2
Source File: PersistenceClientSetupPanelVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void customizeTemplatesLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_customizeTemplatesLabelMouseClicked
    String viewTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.VIEW_TEMPLATE);
    String editTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.EDIT_TEMPLATE);
    String createTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.CREATE_TEMPLATE);
    String listTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.LIST_TEMPLATE);
    String baseTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.BASE_TEMPLATE);
    String controllerTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.CONTROLLER_TEMPLATE);
    String paginationTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.PAGINATION_TEMPLATE);
    String utilTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.UTIL_TEMPLATE);
    String bundleTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.BUNDLE_TEMPLATE);

    JPopupMenu menu = new JPopupMenu();
    List<String> paths = new ArrayList<>();
    processValidPath(menu, paths, viewTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.viewTemplate"));
    processValidPath(menu, paths, editTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.editTemplate"));
    processValidPath(menu, paths, createTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.createTemplate"));
    processValidPath(menu, paths, listTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.listTemplate"));
    processValidPath(menu, paths, baseTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.baseTemplate"));
    processValidPath(menu, paths, controllerTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.controllerTemplate"));
    processValidPath(menu, paths, paginationTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.paginationTemplate"));
    processValidPath(menu, paths, utilTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.utilTemplate"));
    processValidPath(menu, paths, bundleTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.bundleTemplate"));
    menu.insert(new OpenTemplateAction(this, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.allTemplates"), paths.toArray(new String[paths.size()])), 0);
    menu.show(customizeTemplatesLabel, evt.getX(), evt.getY());
}
 
Example #3
Source File: NodePopupFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a popup menu with entries from the selected nodes
 * related to the given component (usually a ETable subclass). The popup
 * is created for the table element in given column and row (column
 *  and row are in the view's coordinates (not the model's)).
 */
public JPopupMenu createPopupMenu(int row, int column, Node[] selectedNodes,
        Component component) {
    
    Action[] actions = NodeOp.findActions (selectedNodes);
    JPopupMenu res = Utilities.actionsToPopup(actions, component);
    if (showQuickFilter) {
        if ((component instanceof ETable) && (column >= 0)) {
            ETable et = (ETable)component;
            if (row >= 0) {
                Object val = et.getValueAt(row, column);
                val = et.transformValue(val);
                String s = NbBundle.getMessage(NodePopupFactory.class, "LBL_QuickFilter");
                res.add(et.getQuickFilterPopup(column, val, s));
            } else if (et.getQuickFilterColumn() == column) {
                addNoFilterItem(et, res);
            }
        }
    }
    return res;
}
 
Example #4
Source File: DataSectionComponent.java    From binnavi with Apache License 2.0 6 votes vote down vote up
private void showPopupMenu(final int rowIndex, final MouseEvent event) {
  final JPopupMenu popupMenu = new JPopupMenu();
  final JFrame owner =
      (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, DataSectionComponent.this);
  final TypeInstanceContainer instanceContainer =
      module.getContent().getTypeInstanceContainer();
  final TypeManager typeManager = module.getTypeManager();
  popupMenu.add(
      new CreateTypeInstanceAction(owner, instanceContainer, typeManager, currentSection));
  if (rowIndex != -1) {
    final TypeInstance existingInstance = typeDataModel.getTypeAtRow(rowIndex);
    popupMenu.add(
        new EditTypeInstanceAction(owner, typeManager, existingInstance, instanceContainer));
    popupMenu.add(new DeleteTypeInstanceAction(owner, existingInstance, instanceContainer));
  }
  popupMenu.show(event.getComponent(), event.getX(), event.getY());
}
 
Example #5
Source File: FileSaver.java    From Luyten with Apache License 2.0 6 votes vote down vote up
public FileSaver(JProgressBar bar, JLabel label) {
	this.bar = bar;
	this.label = label;
	final JPopupMenu menu = new JPopupMenu("Cancel");
	final JMenuItem item = new JMenuItem("Cancel");
	item.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent arg0) {
			setCancel(true);
		}
	});
	menu.add(item);
	this.label.addMouseListener(new MouseAdapter() {
		public void mouseClicked(MouseEvent ev) {
			if (SwingUtilities.isRightMouseButton(ev) && isExtracting())
				menu.show(ev.getComponent(), ev.getX(), ev.getY());
		}
	});
}
 
Example #6
Source File: OutlineView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Find relevant actions and call the factory to create a popup.
 */
private JPopupMenu createPopup(Point p) {
    int[] selRows = outline.getSelectedRows();
    ArrayList<Node> al = new ArrayList<Node> (selRows.length);
    for (int i = 0; i < selRows.length; i++) {
        Node n = getNodeFromRow(selRows[i]);
        if (n != null) {
            al.add(n);
        }
    }
    Node[] arr = al.toArray (new Node[al.size ()]);
    if (arr.length == 0) {
        if (manager.getRootContext() != null) {
            // display the context menu of the root node
            JPopupMenu popup = manager.getRootContext().getContextMenu();
            if (popup != null && popup.getSubElements().length > 0) {
                popupFactory.addNoFilterItem(outline, popup);
                return popup;
            }
        }
        // we'll have an empty popup
    }
    p = SwingUtilities.convertPoint(this, p, outline);
    int column = outline.columnAtPoint(p);
    int row = outline.rowAtPoint(p);
    return popupFactory.createPopupMenu(row, column, arr, outline);
}
 
Example #7
Source File: MissingPlotsListener.java    From collect-earth with MIT License 6 votes vote down vote up
private JPopupMenu getPopupMenu() {
	Action copyAction = new AbstractAction(Messages.getString("MissingPlotsListener.2")) { //$NON-NLS-1$

		private static final long serialVersionUID = 1L;

		@Override
		public void actionPerformed(ActionEvent e) {
			disclaimerTextArea.selectAll();
			String selection = disclaimerTextArea.getSelectedText();
			Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
			if (selection == null) {
				return;
			}
			StringSelection clipString = new StringSelection(selection);
			clipboard.setContents(clipString, clipString);
		}
	};

	JPopupMenu popup = new JPopupMenu();
	popup.add(copyAction);
	return popup;
}
 
Example #8
Source File: GroupContext.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public JPopupMenu getPopupMenu(final Set<UserObject> selectedUserObjects) {
  JPopupMenu menu = new JPopupMenu();
  ResourceBundleUtil labels = ResourceBundleUtil.getBundle(I18nPlantOverview.TREEVIEW_PATH);

  JMenuItem item = new JMenuItem(labels.getString("groupsMouseAdapter.popupMenuItem_removeFromGroup.text"));
  item.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
      openTCSView.removeGroupMembers(selectedUserObjects);
    }
  });

  menu.add(item);

  return menu;
}
 
Example #9
Source File: StringFsPopupEventAdapter.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
  * Show popup maybe.
  *
  * @param e the e
  */
 private void showPopupMaybe(MouseEvent e) {
   // Mouse event is pop-up trigger?
   if (e.isPopupTrigger()) {
     Object o = e.getSource();
     // Event was triggered over the tree?
     if (o instanceof javax.swing.JTree) {
JTree tree = (JTree) o;
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
// Get the node in the tree model where context click occurred.
Object leafComponent = path.getLastPathComponent();
if (leafComponent instanceof FSNode) {
  FSNode node = (FSNode) leafComponent;
  // FSNode is a string node and was shortened?
  if (node.getNodeClass() == FSNode.STRING_FS && node.isShortenedString()) {
    // Show pop-up
    JPopupMenu menu = new JPopupMenu();
    JMenuItem showStringItem = new JMenuItem("Show full string");
    showStringItem.addActionListener(new ShowStringHandler(node.getFullString()));
    menu.add(showStringItem);
    menu.show(e.getComponent(), e.getX(), e.getY());
  }
}
     }
   }
 }
 
Example #10
Source File: LanguageSelectionPanel.java    From wpcleaner with Apache License 2.0 6 votes vote down vote up
/**
 * Action called when a Variant button is clicked.
 * 
 * @param number Variant number.
 */
public void actionVariant(String number) {
  JPopupMenu menu = new JPopupMenu();
  int variantNumber = Integer.parseInt(number);
  String prefix = language.getCode();
  if (script != null) {
    prefix += "-" + script.getCode();
  }
  if (region != null) {
    prefix += "-" + region.getCode();
  }
  for (int i = 0; i < variantNumber; i++) {
    if (variant.get(i) != null) {
      prefix += "-" + variant.get(i).getCode();
    }
  }
  List<LanguageRegistry.Variant> variants = registry.getVariants(prefix);
  for (LanguageRegistry.Variant tmpVariant : variants) {
    JMenuItem item = new JMenuItem(tmpVariant.toString());
    item.setActionCommand(number + ";" + tmpVariant.getCode());
    item.addActionListener(EventHandler.create(
        ActionListener.class, this, "selectVariant", "actionCommand"));
    menu.add(item);
  }
  menu.show(buttonVariant.get(variantNumber), 0, buttonVariant.get(variantNumber).getHeight());
}
 
Example #11
Source File: FrmMeteoData.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void jList_DataFilesMouseClicked(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
    //JOptionPane.showMessageDialog(null, this.jList_DataFiles.getSelectedValue().toString(), "", JOptionPane.INFORMATION_MESSAGE);
    if (evt.getButton() == MouseEvent.BUTTON1) {
        if (this.jList_DataFiles.getSelectedIndex() < 0 || this.jList_DataFiles.getSelectedIndex() == _selectedIndex) {
            return;
        }
        _meteoDataInfo = _dataInfoList.get(this.jList_DataFiles.getSelectedIndex());

        updateParameters();
        _selectedIndex = this.jList_DataFiles.getSelectedIndex();
    } else if (evt.getButton() == MouseEvent.BUTTON3) {
        JPopupMenu mnuLayer = new JPopupMenu();
        JMenuItem removeLayerMI = new JMenuItem("Remove Data File");
        removeLayerMI.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                onRemoveDataClick(e);
            }
        });
        mnuLayer.add(removeLayerMI);
        mnuLayer.show(this.jList_DataFiles, evt.getX(), evt.getY());
    }
}
 
Example #12
Source File: ProfilerToolbarDropdownAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getToolbarPresenter() {
    if (toolbarPresenter == null) {
        // gets the real action registered in the menu from layer
        Action a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachMainProject"); // NOI18N
        final Action attachProjectAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();
        
        // gets the real action registered in the menu from layer
        a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachAction"); // NOI18N
        final Action attachProcessAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();

        JPopupMenu dropdownPopup = new JPopupMenu();
        dropdownPopup.add(createDropdownItem(defaultAction));
        dropdownPopup.add(createDropdownItem(attachProjectAction));
        dropdownPopup.addSeparator();
        dropdownPopup.add(createDropdownItem(attachProcessAction));

        JButton button = DropDownButtonFactory.createDropDownButton(new ImageIcon(
                new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), dropdownPopup);
        Actions.connect(button, defaultAction);

        toolbarPresenter = button;
    }

    return toolbarPresenter;
}
 
Example #13
Source File: LayerViewComponent.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showPopupMenu(int x, int y) {
    JPopupMenu menu = new JPopupMenu();
    for (ViewLayer next : layers) {
        Action action = layerActions.get(next);
        JMenu layerMenu = new JMenu(next.getName());
        layerMenu.add(new JMenuItem(action));
        if (next.isVisible()) {
            List<JMenuItem> items = next.getPopupMenuItems();
            if (items != null && !items.isEmpty()) {
                layerMenu.addSeparator();
                for (JMenuItem item : items) {
                    layerMenu.add(item);
                }
            }
        }
        menu.add(layerMenu);
    }
    menu.show(this, x, y);
}
 
Example #14
Source File: ButtonPopupSwitcher.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void doSelect(JComponent owner) {
    invokingComponent = owner;
    invokingComponent.addMouseListener(this);
    invokingComponent.addMouseMotionListener(this);
    pTable.addMouseListener(this);
    pTable.addMouseMotionListener(this);
    pTable.getSelectionModel().addListSelectionListener( this );

    displayer.getModel().addComplexListDataListener( this );

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);

    popup = new JPopupMenu();
    popup.setBorderPainted( false );
    popup.setBorder( BorderFactory.createEmptyBorder() );
    popup.add( pTable );
    popup.pack();
    int locationX = x - (int) pTable.getPreferredSize().getWidth();
    int locationY = y + 1;
    popup.setLocation( locationX, locationY );
    popup.setInvoker( invokingComponent );
    popup.addPopupMenuListener( this );
    popup.setVisible( true );
    shown = true;
    invocationTime = System.currentTimeMillis();
}
 
Example #15
Source File: DataToolTab.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected javax.swing.JPopupMenu getVertVariablesPopup() {
  if(varPopup==null) {
    buildVarPopup();
  }
  isHorzVarPopup = false;
  FontSizer.setFonts(varPopup, FontSizer.getLevel());
  for(Component c : varPopup.getComponents()) {
    JMenuItem item = (JMenuItem) c;
    if(yLine.getText().equals(item.getActionCommand())) {
      item.setFont(item.getFont().deriveFont(Font.BOLD));
    } else {
      item.setFont(item.getFont().deriveFont(Font.PLAIN));
    }
  }
  return varPopup;
}
 
Example #16
Source File: StatisticsPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private AbstractButton getExportButton() {
    final AbstractButton export = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Export24.gif"),
                                                                 false);
    export.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu viewPopup = new JPopupMenu("Export");
            viewPopup.add(exportAsCsvAction);
            viewPopup.add(putStatisticsIntoVectorDataAction);
            final Rectangle buttonBounds = export.getBounds();
            viewPopup.show(export, 1, buttonBounds.height + 1);
        }
    });
    export.setEnabled(false);
    return export;
}
 
Example #17
Source File: MainView.java    From HiJson with Apache License 2.0 6 votes vote down vote up
public void mouseReleased(MouseEvent e) {
    if (e.isPopupTrigger()) {
        JPopupMenu popMenu = new JPopupMenu();
        JMenuItem mtCopy = new JMenuItem(resourceMap.getString("mtCopy.text"));
        JMenuItem mtPaste = new JMenuItem(resourceMap.getString("mtPaste.text"));
        JMenuItem mtSelAll = new JMenuItem(resourceMap.getString("mtSelAll.text"));
        JMenuItem mtClean = new JMenuItem(resourceMap.getString("mtClean.text"));
        
        popMenu.add(mtCopy);
        popMenu.add(mtPaste);
        popMenu.add(mtSelAll);
        popMenu.add(mtClean);
        JTextArea ta = getTextArea();
        if(ta.getSelectedText() == null || ta.getSelectedText().length()==0){
            mtCopy.setEnabled(false);
        }

        mtCopy.addActionListener(new TextAreaMenuItemActionListener(1));
        mtPaste.addActionListener(new TextAreaMenuItemActionListener(2));
        mtSelAll.addActionListener(new TextAreaMenuItemActionListener(3));
        mtClean.addActionListener(new TextAreaMenuItemActionListener(4));
        popMenu.show(e.getComponent(), e.getX(), e.getY());
    }
}
 
Example #18
Source File: BoardsPane.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Triggered when mouse is pressed.
 *
 * @param e mouse event
 */
@Override
public void mousePressed (MouseEvent e)
{
    if (isContextWanted(e)) {
        JPopupMenu popup = new SeparablePopupMenu();

        // A title for this menu
        JMenuItem head = new JMenuItem("Boards for selection:");
        head.setHorizontalAlignment(SwingConstants.CENTER);
        head.setEnabled(false);
        popup.add(head);
        popup.addSeparator();

        for (Board board : boards) {
            JMenuItem item = new JCheckBoxMenuItem(board.getName(), board.isSelected());
            item.addItemListener(this);
            item.setToolTipText(
                    board.isSelected() ? "Deselect this board?" : "Select this board?");
            popup.add(item);
        }

        popup.show(component, e.getX(), e.getY());
    }
}
 
Example #19
Source File: MemMenu.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void configureMenu(JPopupMenu menu, Project proj) {
	this.proj = proj;
	this.frame = proj.getFrame();
	this.circState = proj.getCircuitState();

	Object attrs = instance.getAttributeSet();
	if (attrs instanceof RomAttributes) {
		((RomAttributes) attrs).setProject(proj);
	}

	boolean enabled = circState != null;
	edit = createItem(enabled, Strings.get("ramEditMenuItem"));
	clear = createItem(enabled, Strings.get("ramClearMenuItem"));
	load = createItem(enabled, Strings.get("ramLoadMenuItem"));
	save = createItem(enabled, Strings.get("ramSaveMenuItem"));
	// assembler = createItem(enabled, Strings.get("Assembler"));

	menu.addSeparator();
	menu.add(edit);
	menu.add(clear);
	menu.add(load);
	menu.add(save);
	// menu.add(assembler);
}
 
Example #20
Source File: ToolsAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void fillSubmenu(JPopupMenu pop) {
    if (lastPopup == null) {
        pop.addPopupMenuListener(this);
        lastPopup = pop;

        removeAll();

        Iterator it = generate(toolsAction, false).iterator();

        while (it.hasNext()) {
            java.awt.Component item = (java.awt.Component) it.next();

            if (item == null) {
                addSeparator();
            } else {
                add(item);
            }
        }

        // also work with empty element
        if (getMenuComponentCount() == 0) {
            JMenuItem empty = new JMenuItem(NbBundle.getMessage(ToolsAction.class, "CTL_EmptySubMenu"));
            empty.setEnabled(false);
            add(empty);
        }
    }
}
 
Example #21
Source File: MainProjectActionWithHistory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
   
        JPopupMenu menu = new JPopupMenu();
        JButton button = DropDownButtonFactory.createDropDownButton(
                new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu);
        final JMenuItem item = new JMenuItem(org.openide.awt.Actions.cutAmpersand((String) getValue("menuText")));
        item.setEnabled(isEnabled());

        addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                String propName = evt.getPropertyName();
                if ("enabled".equals(propName)) {
                    item.setEnabled((Boolean) evt.getNewValue());
                } else if ("menuText".equals(propName)) {
                    item.setText(org.openide.awt.Actions.cutAmpersand((String) evt.getNewValue()));
                }
            }
        });

        menu.add(item);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MainProjectActionWithHistory.this.actionPerformed(e);
            }
        });
       
        org.openide.awt.Actions.connect(button, this);
        menu.addPopupMenuListener(this);
        return button;
    
}
 
Example #22
Source File: JPopupMenuOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JPopupMenu.add(String)} through queue
 */
public JMenuItem add(final String string) {
    return (runMapping(new MapAction<JMenuItem>("add") {
        @Override
        public JMenuItem map() {
            return ((JPopupMenu) getSource()).add(string);
        }
    }));
}
 
Example #23
Source File: bug8071705.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void runActualTest(GraphicsDevice device,
                                  CountDownLatch latch,
                                  JFrame frame,
                                  boolean [] result)
{
    Rectangle screenBounds = setLocation(frame, device);
    JMenu menu = frame.getJMenuBar().getMenu(0);
    menu.doClick();

    Point location = menu.getLocationOnScreen();
    JPopupMenu pm = menu.getPopupMenu();
    Dimension pmSize = pm.getSize();

    int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY");
    int height = location.y + yOffset + pmSize.height + menu.getHeight();
    int available = screenBounds.y + screenBounds.height - height;
    if (available > 0) {
        Point origin = pm.getLocationOnScreen();
        if (origin.y < location.y) {
            // growing upward, wrong!
            result[0] = false;
        } else {
            // growing downward, ok!
            result[0] = true;
        }
    } else {
        // there is no space, growing upward would be ok, so we pass
        result[0] = true;
    }
}
 
Example #24
Source File: AnalysisSetPanel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/** Creates new form AnalysisSetPanel */
public AnalysisSetPanel(AbstractToolModel toolModel) {
   this.toolModel = toolModel;

   initComponents();
   analysisSetTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
   // Create popup menu for addButton (all available analyses)
   AnalysisSet.getAvailableAnalyses(availableAnalyses);
   addButton.addMouseListener(new MouseAdapter() {
      public void mousePressed(MouseEvent evt) {
         JPopupMenu popup = new JPopupMenu();
         for(int i=0; i<availableAnalyses.getSize(); i++)
            popup.add(new JMenuItem(new AddAnalysisAction(availableAnalyses.get(i))));
         popup.show(evt.getComponent(),evt.getX(),evt.getY());
   }});

   // Initialize table
   analysisSetTable.setModel(new AnalysisSetTableModel(toolModel));
   analysisSetTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   analysisSetTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
      public void valueChanged(ListSelectionEvent event) {
         if(event.getValueIsAdjusting()) return;
         tableSelectionChanged();
      }
   });
   // Adjust width of "Enabled" column
   analysisSetTable.getColumnModel().getColumn(0).setPreferredWidth(enabledColumnWidth);
   analysisSetTable.getColumnModel().getColumn(0).setMinWidth(enabledColumnWidth);
   analysisSetTable.getColumnModel().getColumn(0).setMaxWidth(enabledColumnWidth);

   updatePanel();

   toolModel.addObserver(this);
}
 
Example #25
Source File: SynthMenuLayout.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Dimension preferredLayoutSize(Container target) {
    if (target instanceof JPopupMenu) {
        JPopupMenu popupMenu = (JPopupMenu) target;
        popupMenu.putClientProperty(
                SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null);
    }

    return super.preferredLayoutSize(target);
}
 
Example #26
Source File: DebugMainProjectAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    if (!menuInitialized) {
        JPopupMenu menu = (JPopupMenu)e.getSource();
        debugHistorySupport.init(menu);
        attachHistorySupport.init(menu);
        menuInitialized = true;
    } else {
        debugHistorySupport.refreshItems();
    }
}
 
Example #27
Source File: MenuEditLayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void showContextMenu(Point popupPos) {
//        ComponentInspector inspector = ComponentInspector.getInstance();
//        Node[] selectedNodes = inspector.getSelectedNodes();
        Node[] selectedNodes = formDesigner.getSelectedNodes();
        JPopupMenu popup = NodeOp.findContextMenu(selectedNodes);
        if(!this.isVisible()) {
            this.setVisible(true);
        }
        if (popup != null) {
            popup.show(this, popupPos.x, popupPos.y);
        }
    }
 
Example #28
Source File: AbstractMenuCreator.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Add a submenu to a menu.
 * If the submenu contains to much elements, it is split into several submenus.
 * 
 * @param menu Menu.
 * @param submenu Submenu.
 * @param begin Number of items kept at the beginning.
 * @param end Number of items kept at the end.
 */
public void addSubmenu(JPopupMenu menu, JMenu submenu, int begin, int end) {
  Configuration config = Configuration.getConfiguration();
  final int maxElements = Math.max(
      config.getInt(null, ConfigurationValueInteger.MENU_SIZE),
      begin + end + 2);
  if (submenu.getMenuComponentCount() > maxElements) {
    List<JMenu> menuList = new ArrayList<JMenu>();
    while (submenu.getMenuComponentCount() > begin + end + 1) {
      int count = Math.min(maxElements, submenu.getMenuComponentCount() - begin - end);
      JMenu newMenu = new JMenu(submenu.getItem(begin).getText() + "...");
      for (int i = 0; i < count; i++) {
        JMenuItem item = submenu.getItem(begin);
        submenu.remove(begin);
        if (item != null) {
          newMenu.add(item);
        } else {
          addSeparator(newMenu);
        }
      }
      menuList.add(newMenu);
    }
    for (int i = 0; i < menuList.size(); i++) {
      submenu.add(menuList.get(i), begin + i);
    }
    addSubmenu(menu, submenu, begin, end);
  } else {
    menu.add(submenu);
  }
}
 
Example #29
Source File: LiveJDBCView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initUI(Set<ClientUtils.SourceCodeSelection> selection) {
        setLayout(new BorderLayout(0, 0));
        
        jdbcCallsView = new JDBCTreeTableView(selection, false) {
            protected void installDefaultAction() {
                getResultsComponent().setDefaultAction(new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        ProfilerTable t = getResultsComponent();
                        int row = t.getSelectedRow();
                        PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)t.getValueForRow(row);
                        if (isSQL(node)) {
                            showQueryImpl(node);
                        } else {
                            ClientUtils.SourceCodeSelection userValue = getUserValueForRow(row);
                            if (userValue != null) performDefaultAction(userValue);
                        }
                    }
                });
            }
            protected void performDefaultAction(ClientUtils.SourceCodeSelection userValue) {
                if (showSourceSupported()) showSource(userValue);
            }
            protected void populatePopup(JPopupMenu popup, Object value, ClientUtils.SourceCodeSelection userValue) {
                LiveJDBCView.this.populatePopup(jdbcCallsView, popup, value, userValue);
            }
            protected void popupShowing() { LiveJDBCView.this.popupShowing(); }
            protected void popupHidden()  { LiveJDBCView.this.popupHidden(); }
            protected boolean hasBottomFilterFindMargin() { return true; }
        };
        jdbcCallsView.notifyOnFocus(new Runnable() {
            public void run() { lastFocused = jdbcCallsView; }
        });
        
        add(jdbcCallsView, BorderLayout.CENTER);
        
//        // TODO: read last state?
//        setView(true, false);
    }
 
Example #30
Source File: OperatorTree.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/** Creates a new popup menu for the selected operator. */
private JPopupMenu createOperatorPopupMenu() {
	JPopupMenu menu = new JPopupMenu();
	menu.add(EXPAND_ALL_ACTION);
	menu.add(COLLAPSE_ALL_ACTION);
	menu.addSeparator();
	String name = "Tree";
	if (mainFrame.getProcess().getProcessLocation() != null) {
		name = mainFrame.getProcess().getProcessLocation().getShortName();
	}
	menu.add(PrintingTools.makeExportPrintMenu(this, name));

	return menu;
}