List of usage examples for javax.swing JPopupMenu getComponentCount
public int getComponentCount()
From source file:edu.ku.brc.af.ui.forms.ResultSetController.java
/** * Creates the UI for the controller.//from www.j av a 2 s . c o m * @param addNewBtn indicates it should include the "Add" (New Object) button * @param addDelBtn indicates it should include Delete button * @param objTitle the title of a single object in the controller (used for building tooltips) */ protected void buildRecordNavBar(final boolean addNewBtn, final boolean addDelBtn, final boolean addSearchBtn, final String objTitle) { String colDef = "p,2dlu,p,2dlu,max(50dlu;p):grow,2dlu,p,2dlu,p" + (addNewBtn ? ",12px,p" : "") + (addDelBtn ? ",2dlu,p" : "") + (addSearchBtn ? ",2dlu,p" : ""); Insets insets = new Insets(1, 1, 1, 1); DefaultFormBuilder rowBuilder = new DefaultFormBuilder(new FormLayout(colDef, "p")); firstBtn = UIHelper.createIconBtn("FirstRec", null, null); prevBtn = UIHelper.createIconBtn("PrevRec", null, null); btnsHash.put(CommandType.Previous, prevBtn); btnsHash.put(CommandType.First, firstBtn); recDisp = createLabel(" "); recDisp.setHorizontalAlignment(SwingConstants.CENTER); recDisp.setOpaque(true); recDisp.setBackground(Color.WHITE); recDisp.setBorder(enabledBorder); recDisp.setFont(recDisp.getFont().deriveFont(recDisp.getFont().getSize2D() - 2)); MouseListener mouseListener = new MouseAdapter() { private boolean showIfPopupTrigger(MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { JPopupMenu popupMenu = createPopupMenu(); if (popupMenu != null && popupMenu.getComponentCount() > 0) { popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); return true; } } return false; } @Override public void mousePressed(MouseEvent mouseEvent) { showIfPopupTrigger(mouseEvent); } @Override public void mouseReleased(MouseEvent mouseEvent) { showIfPopupTrigger(mouseEvent); } /* (non-Javadoc) * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent) */ @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { if (numRecords == 1) { UIRegistry.writeTimedSimpleGlassPaneMsg(getResourceString("OnlyOneRrecordInCon")); } else { showGotoRecDlg(); } } } }; recDisp.addMouseListener(mouseListener); nextBtn = UIHelper.createIconBtn("NextRec", null, null); lastBtn = UIHelper.createIconBtn("LastRec", null, null); btnsHash.put(CommandType.Next, nextBtn); btnsHash.put(CommandType.Last, lastBtn); firstBtn.setToolTipText(createTooltip("GotoFirstRecordTT", objTitle)); prevBtn.setToolTipText(createTooltip("GotoPreviousRecordTT", objTitle)); nextBtn.setToolTipText(createTooltip("GotoNextRecordTT", objTitle)); lastBtn.setToolTipText(createTooltip("GotoLastRecordTT", objTitle)); firstBtn.setOpaque(false); prevBtn.setOpaque(false); nextBtn.setOpaque(false); lastBtn.setOpaque(false); CellConstraints cc = new CellConstraints(); rowBuilder.add(firstBtn, cc.xy(1, 1)); rowBuilder.add(prevBtn, cc.xy(3, 1)); rowBuilder.add(recDisp, cc.xy(5, 1)); rowBuilder.add(nextBtn, cc.xy(7, 1)); rowBuilder.add(lastBtn, cc.xy(9, 1)); int col = 11; if (addNewBtn) { if (false) { newRecBtn = new JButton("+") { public void setEnabled(boolean enable) { //log.debug("newRecBtn - RS: "+ formValidator.getName() + " " + newRecBtn.hashCode() + " "+enable+" isNewObj: "+isNewObj); if (formValidator != null && formValidator.getName() != null && formValidator.getName().equals("Collection Object")) { int x = 0; x++; if (enable) { int y = 0; y++; } } if (enable) { int x = 0; x++; } super.setEnabled(enable); } }; setControlSize(newRecBtn); ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ResultSetControllerListener rscl : listeners) { rscl.newRecordAdded(); } } }; newRecBtn.addActionListener(l); } else { newRecBtn = UIHelper.createIconBtn("NewRecord", null, new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ResultSetControllerListener rscl : listeners) { rscl.newRecordAdded(); } } }); } newRecBtn.setToolTipText(createTooltip("NewRecordTT", objTitle)); newRecBtn.setEnabled(true); newRecBtn.setMargin(insets); btnsHash.put(CommandType.NewItem, newRecBtn); if (doLayoutBtns) { rowBuilder.add(newRecBtn, cc.xy(col, 1)); col += 2; } } if (addDelBtn) { if (false) { delRecBtn = new JButton("-") { public void setEnabled(boolean enable) { //log.debug("delRecBtn - RS: "+formValidator.getName() + " " + hashCode() + " "+enable); if (formValidator != null && formValidator.getName() != null && formValidator.getName().equals("Permit")) { int x = 0; x++; } if (!enable) { int x = 0; x++; } super.setEnabled(enable); } }; } else { delRecBtn = UIHelper.createIconBtn("DeleteRecord", null, null); } delRecBtn.setToolTipText(createTooltip("DeleteRecordTT", objTitle)); delRecBtn.setMargin(insets); btnsHash.put(CommandType.DelItem, delRecBtn); if (doLayoutBtns) { rowBuilder.add(delRecBtn, cc.xy(col, 1)); col += 2; } } if (addSearchBtn) { searchRecBtn = UIHelper.createIconBtn("Search", IconManager.IconSize.Std16, null, null); searchRecBtn.setToolTipText(createTooltip("SearchForRecordTT", objTitle)); searchRecBtn.setMargin(insets); if (doLayoutBtns) { rowBuilder.add(searchRecBtn, cc.xy(col, 1)); col += 2; } } firstBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { firstRecord(); } }); prevBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { prevRecord(); } }); nextBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { nextRecord(); } }); lastBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { lastRecord(); } }); // Make sure it gets centered rowBuilder.getPanel().setOpaque(false); DefaultFormBuilder outerCenteredPanel = new DefaultFormBuilder(new FormLayout("c:p:g", "p")); outerCenteredPanel.add(rowBuilder.getPanel(), cc.xy(1, 1)); panel = outerCenteredPanel.getPanel(); panel.setOpaque(false); }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
public void showTabPopup(MouseEvent e) { JComponent tabHeaderComponent = (JComponent) e.getComponent(); int tabIndex = getTabIndex(tabHeaderComponent); JComponent tabContent = (JComponent) tabsPane.getComponentAt(tabIndex); WindowBreadCrumbs windowBreadCrumbs = tabs.get(tabContent); Window window = windowBreadCrumbs.getCurrentWindow(); JPopupMenu popupMenu = createWindowPopupMenu(window); if (popupMenu.getComponentCount() > 0) { popupMenu.show(tabHeaderComponent, e.getX(), e.getY()); }//from w w w . j a va 2 s. c o m }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
public void attachTab(WindowBreadCrumbs breadCrumbs, Stack<Map.Entry<Window, Integer>> stack, Window window, Integer hashCode, final JComponent tabContent, Map<Window, WindowOpenInfo> openInfos) { frame.add(tabContent);/*from w ww. j a va 2 s .co m*/ frame.addWindowListener(new ValidationAwareWindowClosingListener() { @Override public void windowClosingAfterValidation(WindowEvent e) { closeTab(tabContent); } }); tabs.put(tabContent, breadCrumbs); windowOpenMode.putAll(openInfos); stacks.put(breadCrumbs, stack); for (Map.Entry<Window, Integer> entry : stack) { entry.getKey().setWindowManager(this); } window.setWindowManager(this); if (hashCode != null) { windows.put(window, hashCode); } JPopupMenu popupMenu = createWindowPopupMenu(window); if (popupMenu.getComponentCount() > 0) { frame.getRootPane().setComponentPopupMenu(popupMenu); } }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected JDialog showWindowDialog(final Window window, String caption, String description, OpenType openType, boolean forciblyDialog) { final DialogWindow dialog = new DialogWindow(frame, caption); dialog.setName(window.getId());//from w ww . j av a 2 s . c om dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); JComponent jComponent = DesktopComponentsHelper.getComposition(window); dialog.add(jComponent); dialog.addWindowListener(new ValidationAwareWindowClosingListener() { @Override public void windowClosingAfterValidation(WindowEvent e) { if (BooleanUtils.isNotFalse(window.getDialogOptions().getCloseable())) { if (!isCloseWithCloseButtonPrevented(window)) { if (window.close("close")) { dialog.dispose(); } } } } }); Dimension dim = new Dimension(); if (forciblyDialog) { // todo move it to desktop application preferences dim.width = 800; dim.height = 500; dialog.setResizable(BooleanUtils.isNotFalse(openType.getResizable())); if (!dialog.isResizable()) { dialog.setFixedHeight(dim.height); dialog.setFixedWidth(dim.width); } window.setHeight("100%"); } else { dialog.setResizable(BooleanUtils.isTrue(openType.getResizable())); if (openType.getWidth() == null) { dim.width = 600; if (!dialog.isResizable()) { dialog.setFixedWidth(dim.width); } } else if (openType.getWidth() == DialogParams.AUTO_SIZE_PX) { window.setWidth(AUTO_SIZE); } else { if (openType.getWidthUnit() != null && openType.getWidthUnit() != SizeUnit.PIXELS) { throw new UnsupportedOperationException("Dialog size can be set only in pixels"); } dim.width = openType.getWidth().intValue(); if (!dialog.isResizable()) { dialog.setFixedWidth(dim.width); } } if (openType.getHeight() != null && openType.getHeight() != DialogParams.AUTO_SIZE_PX) { if (openType.getHeightUnit() != null && openType.getHeightUnit() != SizeUnit.PIXELS) { throw new UnsupportedOperationException("Dialog size can be set only in pixels"); } dim.height = openType.getHeight().intValue(); if (!dialog.isResizable()) { dialog.setFixedHeight(dim.height); } window.setHeight("100%"); } else { window.setHeight(AUTO_SIZE); } } getDialogParams().reset(); dialog.setMinimumSize(dim); dialog.pack(); if (openType.getPositionY() == null && openType.getPositionX() == null) { dialog.setLocationRelativeTo(frame); } else { dialog.setLocation(openType.getPositionX() != null ? openType.getPositionX() : 0, openType.getPositionY() != null ? openType.getPositionY() : 0); } boolean modal = true; if (!hasModalWindow() && openType.getModal() != null) { modal = openType.getModal(); } if (modal) { DialogWindow lastDialogWindow = getLastDialogWindow(); if (lastDialogWindow == null) frame.deactivate(null); else lastDialogWindow.disableWindow(null); dialog.setSoftModal(true); } dialog.setVisible(true); JPopupMenu popupMenu = createWindowPopupMenu(window); if (popupMenu.getComponentCount() > 0) { jComponent.setComponentPopupMenu(popupMenu); } return dialog; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
protected void initComponent() { layout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]"); panel = new JPanel(layout); topPanel = new JPanel(new BorderLayout()); topPanel.setVisible(false);// ww w .j a v a 2s . c o m panel.add(topPanel, "growx"); scrollPane = new JScrollPane(impl); impl.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); impl.setFillsViewportHeight(true); panel.add(scrollPane, "grow"); impl.setShowGrid(true); impl.setGridColor(Color.lightGray); impl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { handleClickAction(); } } @Override public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } protected void showPopup(MouseEvent e) { if (e.isPopupTrigger() && contextMenuEnabled) { // select row Point p = e.getPoint(); int viewRowIndex = impl.rowAtPoint(p); int rowNumber; if (viewRowIndex >= 0) { rowNumber = impl.convertRowIndexToModel(viewRowIndex); } else { rowNumber = -1; } ListSelectionModel model = impl.getSelectionModel(); if (!model.isSelectedIndex(rowNumber)) { model.setSelectionInterval(rowNumber, rowNumber); } // show popup menu JPopupMenu popupMenu = createPopupMenu(); if (popupMenu.getComponentCount() > 0) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } } }); ColumnControlButton columnControlButton = new ColumnControlButton(impl) { @Override protected ColumnVisibilityAction createColumnVisibilityAction(TableColumn column) { ColumnVisibilityAction columnVisibilityAction = super.createColumnVisibilityAction(column); columnVisibilityAction.addPropertyChangeListener(evt -> { if ("SwingSelectedKey".equals(evt.getPropertyName()) && evt.getNewValue() instanceof Boolean) { ColumnVisibilityAction action = (ColumnVisibilityAction) evt.getSource(); String columnName = action.getActionCommand(); boolean collapsed = !((boolean) evt.getNewValue()); Column col = getColumn(columnName); if (col != null) { col.setCollapsed(collapsed); } } }); return columnVisibilityAction; } }; impl.setColumnControl(columnControlButton); impl.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); impl.getActionMap().put("enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (enterPressAction != null) { enterPressAction.actionPerform(DesktopAbstractTable.this); } else { handleClickAction(); } } }); Messages messages = AppBeans.get(Messages.NAME); // localize default column control actions for (Object actionKey : impl.getActionMap().allKeys()) { if ("column.packAll".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packAll")); } else if ("column.packSelected".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packSelected")); } else if ("column.horizontalScroll".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.horizontalScroll")); } } // Ability to configure fonts in table // Add action to column control String configureFontsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.configureFontsLabel"); impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "fonts", new AbstractAction(configureFontsLabel) { @Override public void actionPerformed(ActionEvent e) { Component rootComponent = SwingUtilities.getRoot(impl); final FontDialog fontDialog = FontDialog.show(rootComponent, impl.getFont()); fontDialog.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { Font result = fontDialog.getResult(); if (result != null) { impl.setFont(result); packRows(); } } }); fontDialog.open(); } }); // Ability to reset settings String resetSettingsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.resetSettings"); impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "resetSettings", new AbstractAction(resetSettingsLabel) { @Override public void actionPerformed(ActionEvent e) { resetPresentation(); } }); scrollPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { if (!columnsInitialized) { adjustColumnHeaders(); } columnsInitialized = true; } }); // init default row height SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (!fontInitialized) { applyFont(impl, impl.getFont()); } } }); }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Adds a special key listener to process a RETURN key for selecting and item * in the popup list. This is installed only for Windows and Linux. * @param popupMenu the popup menu to be altered. *//*from w ww . j ava2 s . c om*/ public static void addSpecialKeyListenerForPopup(final JPopupMenu popupMenu) { if (!UIHelper.isMacOS()) { popupMenu.addKeyListener(new KeyAdapter() { //@Override public void keyPressed(KeyEvent e) { super.keyPressed(e); if (e.getKeyCode() == VK_ENTER) { for (int i = 0; i < popupMenu.getComponentCount(); i++) { Component c = popupMenu.getComponent(i); if (c instanceof JMenuItem) { JMenuItem mi = (JMenuItem) c; if (mi.isArmed()) { mi.doClick(); popupMenu.setVisible(false); } } } } } }); } }
From source file:edu.ku.brc.specify.tasks.SystemSetupTask.java
/** * Adds the Context PopupMenu for the RecordSet. * @param roc the RolloverCommand btn to add the pop to *//*from w w w . j a v a2 s. co m*/ public void addPopMenu(final RolloverCommand roc, final PickList pickList) { if (roc.getLabelText() != null) { final JPopupMenu popupMenu = new JPopupMenu(); JMenuItem delMenuItem = new JMenuItem(getResourceString("Delete")); if (!pickList.getIsSystem()) { delMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { CommandDispatcher.dispatch(new CommandAction(SYSTEMSETUPTASK, DELETE_CMD_ACT, roc)); } }); } else { delMenuItem.setEnabled(false); } popupMenu.add(delMenuItem); JMenuItem viewMenuItem = new JMenuItem(getResourceString("EDIT")); viewMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { startEditor(edu.ku.brc.specify.datamodel.PickList.class, "name", roc.getName(), roc.getName(), PICKLIST); } }); popupMenu.add(viewMenuItem); MouseListener mouseListener = new MouseAdapter() { private boolean showIfPopupTrigger(MouseEvent mouseEvent) { if (roc.isEnabled() && mouseEvent.isPopupTrigger() && popupMenu.getComponentCount() > 0) { popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); return true; } return false; } @Override public void mousePressed(MouseEvent mouseEvent) { if (roc.isEnabled()) { showIfPopupTrigger(mouseEvent); } } @Override public void mouseReleased(MouseEvent mouseEvent) { if (roc.isEnabled()) { showIfPopupTrigger(mouseEvent); } } }; roc.addMouseListener(mouseListener); } }
From source file:edu.ku.brc.specify.tasks.RecordSetTask.java
/** * Adds the Context PopupMenu for the RecordSet. * @param roc the RolloverCommand btn to add the pop to *//*from ww w . j a va 2 s .c om*/ public void addPopMenu(final RolloverCommand roc, final boolean isOKDelete, final boolean isOKModify) { if (roc.getLabelText() != null) { final JPopupMenu popupMenu = new JPopupMenu(); if (isOKModify) { JMenuItem renameMenuItem = new JMenuItem(UIRegistry.getResourceString("Rename")); renameMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { roc.startEditting(RecordSetTask.this); } }); popupMenu.add(renameMenuItem); } if (isOKDelete) { JMenuItem delMenuItem = new JMenuItem(UIRegistry.getResourceString("Delete")); delMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { CommandDispatcher.dispatch(new CommandAction(RECORD_SET, DELETE_CMD_ACT, roc)); } }); popupMenu.add(delMenuItem); } JMenuItem viewMenuItem = new JMenuItem(UIRegistry.getResourceString("View")); viewMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { CommandAction cmdAction = new CommandAction("Express_Search", "ViewRecordSet", roc); cmdAction.setProperty("canModify", isOKDelete); CommandDispatcher.dispatch(cmdAction); } }); popupMenu.add(viewMenuItem); MouseListener mouseListener = new MouseAdapter() { private boolean showIfPopupTrigger(MouseEvent mouseEvent) { if (roc.isEnabled() && mouseEvent.isPopupTrigger() && popupMenu.getComponentCount() > 0) { popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); return true; } return false; } @Override public void mousePressed(MouseEvent mouseEvent) { if (roc.isEnabled()) { showIfPopupTrigger(mouseEvent); } } @Override public void mouseReleased(MouseEvent mouseEvent) { if (roc.isEnabled()) { showIfPopupTrigger(mouseEvent); } } }; roc.addMouseListener(mouseListener); } }
From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java
/** * CReates the popup menu for a cell. (THis really needs to be moved outside of this class). * @param pnt the point to pop it up// ww w . j av a 2s.c o m * @return the popup menu */ protected JPopupMenu createMenuForSelection(final Point pnt) { //final int row = rowAtPoint(pnt); Class<?> cellClass = getModel().getColumnClass(convertColumnIndexToModel(columnAtPoint(pnt))); boolean isImage = cellClass == ImageIcon.class || cellClass == Image.class; JPopupMenu pMenu = new JPopupMenu(); UsageTracker.incrUsageCount("WB.SpreadsheetContextMenu"); if (getSelectedColumnCount() == 1) { final int[] rows = getSelectedRowModelIndexes(); if (rows.length > 1) { //if (row == rows[0]) //{ if (!isImage) { JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("SpreadSheet.FillDown"))); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int selectedUICol = getSelectedColumn(); int selectedModelCol = convertColumnIndexToModel(selectedUICol); model.fill(selectedModelCol, rows[0], rows); popupMenu.setVisible(false); } }); } //} else if (row == rows[rows.length-1]) //{ if (!isImage) { JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("Spreadsheet.FillUp"))); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int selectedUICol = getSelectedColumn(); int selectedModelCol = convertColumnIndexToModel(selectedUICol); model.fill(selectedModelCol, rows[rows.length - 1], rows); popupMenu.setVisible(false); } }); } //} } } if (!isImage) { JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("SpreadSheet.ClearCells"))); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int[] rows = getSelectedRowModelIndexes(); int[] cols = getSelectedColumnModelIndexes(); model.clearCells(rows, cols); popupMenu.setVisible(false); } }); } if (deleteAction != null) { JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("SpreadSheet.DeleteRows"))); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { deleteAction.actionPerformed(ae); popupMenu.setVisible(false); } }); } //add copy, paste, cut if (!isImage) //copy, paste currently only implemented for string data { boolean isSelection = getSelectedColumnCount() > 0 && getSelectedRowCount() > 0; if (pMenu.getComponentCount() > 0) { pMenu.add(new JPopupMenu.Separator()); } JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("CutMenu"))); mi.setEnabled(isSelection && !isImage); // copy, paste currently // only implemented for // string data mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { SwingUtilities.invokeLater(new Runnable() { /* * (non-Javadoc) * * @see java.lang.Runnable#run() */ @Override public void run() { cutOrCopy(true); } }); } }); mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("CopyMenu"))); mi.setEnabled(isSelection && !isImage); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { SwingUtilities.invokeLater(new Runnable() { /* * (non-Javadoc) * * @see java.lang.Runnable#run() */ @Override public void run() { cutOrCopy(false); } }); } }); mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("PasteMenu"))); mi.setEnabled(isSelection && !isImage && canPasteFromClipboard()); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { SwingUtilities.invokeLater(new Runnable() { /* * (non-Javadoc) * * @see java.lang.Runnable#run() */ @Override public void run() { paste(); } }); } }); } pMenu.setInvoker(this); return pMenu; }
From source file:nz.govt.natlib.ndha.manualdeposit.bulkupload.BulkUploadQueueManagement.java
public JPopupMenu getBulkUploadMenu() { JPopupMenu menu = new JPopupMenu(); String text = "Cancel job"; if (theBulkUploadItemsTable.getSelectedRowCount() > 1) { text += "s"; }/*w w w . j a va 2s . c o m*/ JMenuItem item = new JMenuItem(text); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelJobs(evt); } }); menu.add(item); BulkUploadTableModel model = (BulkUploadTableModel) theBulkUploadItemsTable.getModel(); int noOfErrorJobsSelected = model.getSelectedErrorCount(theBulkUploadItemsTable); if (noOfErrorJobsSelected > 0) { if (noOfErrorJobsSelected > 1) { text = "Resubmit jobs in error"; } else { text = "Resubmit job in error"; } item = new JMenuItem(text); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { resubmitErrorJobs(evt); } }); menu.add(item); } if (menu == null || menu.getComponentCount() == 0) { return null; } else { return menu; } }