List of usage examples for javax.swing.event MenuEvent getSource
public Object getSource()
From source file:MenuTest.java
public MenuTest() { super();/*from w ww .j av a 2s. c o m*/ MenuListener listener = new MenuListener() { public void menuCanceled(MenuEvent e) { dumpInfo("Canceled", e); } public void menuDeselected(MenuEvent e) { dumpInfo("Deselected", e); } public void menuSelected(MenuEvent e) { dumpInfo("Selected", e); } private void dumpInfo(String s, MenuEvent e) { JMenu menu = (JMenu) e.getSource(); System.out.println(s + ": " + menu.getText()); } }; JMenu fileMenu = new JMenu("File"); fileMenu.addMenuListener(listener); fileMenu.add(new JMenuItem("Open")); fileMenu.add(new JMenuItem("Close")); fileMenu.add(new JMenuItem("Exit")); JMenu helpMenu = new JMenu("Help"); helpMenu.addMenuListener(listener); helpMenu.add(new JMenuItem("About MenuTest")); helpMenu.add(new JMenuItem("Class Hierarchy")); helpMenu.addSeparator(); helpMenu.add(new JCheckBoxMenuItem("Balloon Help")); JMenu subMenu = new JMenu("Categories"); subMenu.addMenuListener(listener); JRadioButtonMenuItem rb; ButtonGroup group = new ButtonGroup(); subMenu.add(rb = new JRadioButtonMenuItem("A Little Help", true)); group.add(rb); subMenu.add(rb = new JRadioButtonMenuItem("A Lot of Help")); group.add(rb); helpMenu.add(subMenu); JMenuBar mb = new JMenuBar(); mb.add(fileMenu); mb.add(helpMenu); setJMenuBar(mb); }
From source file:gmgen.GMGenSystem.java
/** * Listens for menus to be clicked and calls the appropriate handlers. * //w w w.j a v a 2 s . com * @param e * the menu event that happened. */ @Override public void menuSelected(MenuEvent e) { if (e.getSource() == toolsMenu) { handleToolsMenu(); } }
From source file:com.ixora.rms.ui.RMSFrame.java
/** * Handles menu selected event./*from ww w . ja v a2s .c om*/ * * @param e */ private void handleMenuSelected(MenuEvent e) { try { JMenu m = getJMenuLoadSession(); if (m == e.getSource()) { buildLoadSchemeMruPopupMenu(this.fMRUPopupMenuForMenu); } } catch (Exception ex) { UIExceptionMgr.userException(ex); } }
From source file:com.pironet.tda.TDA.java
/** * check file menu/*from www .j a v a 2 s.c om*/ */ public void menuSelected(MenuEvent e) { JMenu source = (JMenu) e.getSource(); if ((source != null) && "File".equals(source.getText())) { // close menu item only active, if something is selected. getMainMenu().getCloseMenuItem().setEnabled(tree.getSelectionPath() != null); getMainMenu().getCloseToolBarButton().setEnabled(tree.getSelectionPath() != null); } }
From source file:edu.ku.brc.specify.Specify.java
/** * Create menus/*from w w w .ja v a 2 s . c o m*/ */ public JMenuBar createMenus() { JMenuBar mb = new JMenuBar(); JMenuItem mi; //-------------------------------------------------------------------- //-- File Menu //-------------------------------------------------------------------- JMenu menu = null; if (!UIHelper.isMacOS() || !isWorkbenchOnly) { menu = UIHelper.createLocalizedMenu(mb, "Specify.FILE_MENU", "Specify.FILE_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ } if (!isWorkbenchOnly) { // Add Menu for switching Collection String title = "Specify.CHANGE_COLLECTION"; //$NON-NLS-1$ String mnu = "Specify.CHANGE_COLL_MNEU"; //$NON-NLS-1$ changeCollectionMenuItem = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, false, null); changeCollectionMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (SubPaneMgr.getInstance().aboutToShutdown()) { // Actually we really need to start over // "true" means that it should NOT use any cached values it can find to automatically initialize itself // instead it should ask the user any questions as if it were starting over restartApp(null, databaseName, userName, true, false); } } }); menu.addMenuListener(new MenuListener() { @Override public void menuCanceled(MenuEvent e) { } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuSelected(MenuEvent e) { boolean enable = Uploader.getCurrentUpload() == null && ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getNumOfCollectionsForUser() > 1 && !TaskMgr.areTasksDisabled(); changeCollectionMenuItem.setEnabled(enable); } }); } if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { if (!UIRegistry.isMobile()) { menu.addSeparator(); } String title = "Specify.EXIT"; //$NON-NLS-1$ String mnu = "Specify.Exit_MNEU"; //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, true, null); if (!UIHelper.isMacOS()) { mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK)); } mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doExit(true); } }); } menu = UIRegistry.getInstance().createEditMenu(); mb.add(menu); //menu = UIHelper.createMenu(mb, "EditMenu", "EditMneu"); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { menu.addSeparator(); String title = "Specify.PREFERENCES"; //$NON-NLS-1$ String mnu = "Specify.PREFERENCES_MNEU";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, false, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doPreferences(); } }); mi.setEnabled(true); } //-------------------------------------------------------------------- //-- Data Menu //-------------------------------------------------------------------- JMenu dataMenu = UIHelper.createLocalizedMenu(mb, "Specify.DATA_MENU", "Specify.DATA_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ ResultSetController.addMenuItems(dataMenu); dataMenu.addSeparator(); // Save And New Menu Item Action saveAndNewAction = new AbstractAction(getResourceString("Specify.SAVE_AND_NEW")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.setSaveAndNew(((JCheckBoxMenuItem) e.getSource()).isSelected()); } } }; saveAndNewAction.setEnabled(false); JCheckBoxMenuItem saveAndNewCBMI = new JCheckBoxMenuItem(saveAndNewAction); dataMenu.add(saveAndNewCBMI); UIRegistry.register("SaveAndNew", saveAndNewCBMI); //$NON-NLS-1$ UIRegistry.registerAction("SaveAndNew", saveAndNewAction); //$NON-NLS-1$ mb.add(dataMenu); // Configure Carry Forward Action configCarryForwardAction = new AbstractAction( getResourceString("Specify.CONFIG_CARRY_FORWARD_MENU")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.configureCarryForward(); } } }; configCarryForwardAction.setEnabled(false); JMenuItem configCFWMI = new JMenuItem(configCarryForwardAction); dataMenu.add(configCFWMI); UIRegistry.register("ConfigCarryForward", configCFWMI); //$NON-NLS-1$ UIRegistry.registerAction("ConfigCarryForward", configCarryForwardAction); //$NON-NLS-1$ mb.add(dataMenu); //--------------------------------------- // Carry Forward Menu Item (On / Off) Action carryForwardAction = new AbstractAction(getResourceString("Specify.CARRY_FORWARD_CHECKED_MENU")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.toggleCarryForward(); ((JCheckBoxMenuItem) e.getSource()).setSelected(fvo.isDoCarryForward()); } } }; carryForwardAction.setEnabled(false); JCheckBoxMenuItem carryForwardCBMI = new JCheckBoxMenuItem(carryForwardAction); dataMenu.add(carryForwardCBMI); UIRegistry.register("CarryForward", carryForwardCBMI); //$NON-NLS-1$ UIRegistry.registerAction("CarryForward", carryForwardAction); //$NON-NLS-1$ mb.add(dataMenu); if (!isWorkbenchOnly) { final String AUTO_NUM = "AutoNumbering"; //--------------------------------------- // AutoNumber Menu Item (On / Off) Action autoNumberOnOffAction = new AbstractAction( getResourceString("FormViewObj.SET_AUTONUMBER_ONOFF")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.toggleAutoNumberOnOffState(); ((JCheckBoxMenuItem) e.getSource()).setSelected(fvo.isAutoNumberOn()); } } }; autoNumberOnOffAction.setEnabled(false); JCheckBoxMenuItem autoNumCBMI = new JCheckBoxMenuItem(autoNumberOnOffAction); dataMenu.add(autoNumCBMI); UIRegistry.register(AUTO_NUM, autoNumCBMI); //$NON-NLS-1$ UIRegistry.registerAction(AUTO_NUM, autoNumberOnOffAction); //$NON-NLS-1$ } if (System.getProperty("user.name").equals("rods")) { dataMenu.addSeparator(); AbstractAction gpxAction = new AbstractAction("GPS Data") { @Override public void actionPerformed(ActionEvent e) { GPXPanel.getDlgInstance().setVisible(true); } }; JMenuItem gpxMI = new JMenuItem(gpxAction); dataMenu.add(gpxMI); UIRegistry.register("GPXDlg", gpxMI); //$NON-NLS-1$ UIRegistry.registerAction("GPXDlg", gpxAction); //$NON-NLS-1$ } mb.add(dataMenu); SubPaneMgr.getInstance(); // force creating of the Mgr so the menu Actions are created. //-------------------------------------------------------------------- //-- System Menu //-------------------------------------------------------------------- if (!isWorkbenchOnly) { // TODO This needs to be moved into the SystemTask, but right now there is no way // to ask a task for a menu. menu = UIHelper.createLocalizedMenu(mb, "Specify.SYSTEM_MENU", "Specify.SYSTEM_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ /*if (true) { menu = UIHelper.createMenu(mb, "Forms", "o"); Action genForms = new AbstractAction() { public void actionPerformed(ActionEvent ae) { FormGenerator fg = new FormGenerator(); fg.generateForms(); } }; mi = UIHelper.createMenuItemWithAction(menu, "Generate All Forms", "G", "", true, genForms); }*/ } //-------------------------------------------------------------------- //-- Tab Menu //-------------------------------------------------------------------- menu = UIHelper.createLocalizedMenu(mb, "Specify.TABS_MENU", "Specify.TABS_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ String ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_CUR_MENU"); String mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_CUR_MNEU"); mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseCurrent")); if (!UIHelper.isMacOS()) { mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK)); } ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALL_MENU"); mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALL_MNEU"); mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseAll")); if (!UIHelper.isMacOS()) { mi.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); } ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALLBUT_MENU"); mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALLBUT_MNEU"); mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseAllBut")); menu.addSeparator(); // Configure Task JMenuItem configTaskMI = new JMenuItem(getAction("ConfigureTask")); menu.add(configTaskMI); //UIRegistry.register("ConfigureTask", configTaskMI); //$NON-NLS-1$ //-------------------------------------------------------------------- //-- Debug Menu //-------------------------------------------------------------------- boolean doDebug = AppPreferences.getLocalPrefs().getBoolean("debug.menu", false); if (!UIRegistry.isRelease() || doDebug) { menu = UIHelper.createLocalizedMenu(mb, "Specify.DEBUG_MENU", "Specify.DEBUG_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ String ttle = "Specify.SHOW_LOC_PREFS";//$NON-NLS-1$ String mneu = "Specify.SHOW_LOC_PREF_MNEU";//$NON-NLS-1$ String desc = "Specify.SHOW_LOC_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { openLocalPrefs(); } }); ttle = "Specify.SHOW_REM_PREFS";//$NON-NLS-1$ mneu = "Specify.SHOW_REM_PREFS_MNEU";//$NON-NLS-1$ desc = "Specify.SHOW_REM_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { openRemotePrefs(); } }); menu.addSeparator(); ttle = "Specify.CONFIG_LOGGERS";//$NON-NLS-1$ mneu = "Specify.CONFIG_LOGGERS_MNEU";//$NON-NLS-1$ desc = "Specify.CONFIG_LOGGER";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { final LoggerDialog dialog = new LoggerDialog(topFrame); UIHelper.centerAndShow(dialog); } }); ttle = "Specify.CONFIG_DEBUG_LOGGERS";//$NON-NLS-1$ mneu = "Specify.CONFIG_DEBUG_LOGGERS_MNEU";//$NON-NLS-1$ desc = "Specify.CONFIG_DEBUG_LOGGER";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { DebugLoggerDialog dialog = new DebugLoggerDialog(topFrame); UIHelper.centerAndShow(dialog); } }); menu.addSeparator(); ttle = "Specify.SHOW_MEM_STATS";//$NON-NLS-1$ mneu = "Specify.SHOW_MEM_STATS_MNEU";//$NON-NLS-1$ desc = "Specify.SHOW_MEM_STATS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { System.gc(); System.runFinalization(); // Get current size of heap in bytes double meg = 1024.0 * 1024.0; double heapSize = Runtime.getRuntime().totalMemory() / meg; // Get maximum size of heap in bytes. The heap cannot grow beyond this size. // Any attempt will result in an OutOfMemoryException. double heapMaxSize = Runtime.getRuntime().maxMemory() / meg; // Get amount of free memory within the heap in bytes. This size will increase // after garbage collection and decrease as new objects are created. double heapFreeSize = Runtime.getRuntime().freeMemory() / meg; UIRegistry.getStatusBar() .setText(String.format("Heap Size: %7.2f Max: %7.2f Free: %7.2f Used: %7.2f", //$NON-NLS-1$ heapSize, heapMaxSize, heapFreeSize, (heapSize - heapFreeSize))); } }); JMenu prefsMenu = new JMenu(UIRegistry.getResourceString("Specify.PREFS_IMPORT_EXPORT")); //$NON-NLS-1$ menu.add(prefsMenu); ttle = "Specify.IMPORT_MENU";//$NON-NLS-1$ mneu = "Specify.IMPORT_MNEU";//$NON-NLS-1$ desc = "Specify.IMPORT_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(prefsMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { importPrefs(); } }); ttle = "Specify.EXPORT_MENU";//$NON-NLS-1$ mneu = "Specify.EXPORT_MNEU";//$NON-NLS-1$ desc = "Specify.EXPORT_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(prefsMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { exportPrefs(); } }); ttle = "Associate Storage Items";//$NON-NLS-1$ mneu = "A";//$NON-NLS-1$ desc = "";//$NON-NLS-1$ mi = UIHelper.createMenuItemWithAction(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { associateStorageItems(); } }); ttle = "Load GPX Points";//$NON-NLS-1$ mneu = "a";//$NON-NLS-1$ desc = "";//$NON-NLS-1$ mi = UIHelper.createMenuItemWithAction(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { CustomDialog dlg = GPXPanel.getDlgInstance(); if (dlg != null) { dlg.setVisible(true); } } }); JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem("Security Activated"); //$NON-NLS-1$ menu.add(cbMenuItem); cbMenuItem.setSelected(AppContextMgr.isSecurityOn()); cbMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { boolean isSecurityOn = !SpecifyAppContextMgr.isSecurityOn(); AppContextMgr.getInstance().setSecurity(isSecurityOn); ((JMenuItem) ae.getSource()).setSelected(isSecurityOn); JLabel secLbl = statusField.getSectionLabel(3); if (secLbl != null) { secLbl.setIcon(IconManager.getImage(isSecurityOn ? "SecurityOn" : "SecurityOff", IconManager.IconSize.Std16)); secLbl.setHorizontalAlignment(SwingConstants.CENTER); secLbl.setToolTipText(getResourceString("Specify.SEC_" + (isSecurityOn ? "ON" : "OFF"))); } } }); JMenuItem sizeMenuItem = new JMenuItem("Set to " + PREFERRED_WIDTH + "x" + PREFERRED_HEIGHT); //$NON-NLS-1$ menu.add(sizeMenuItem); sizeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { topFrame.setSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } }); } //---------------------------------------------------- //-- Helper Menu //---------------------------------------------------- JMenu helpMenu = UIHelper.createLocalizedMenu(mb, "Specify.HELP_MENU", "Specify.HELP_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ HelpMgr.createHelpMenuItem(helpMenu, getResourceString("SPECIFY_HELP")); //$NON-NLS-1$ helpMenu.addSeparator(); String ttle = "Specify.LOG_SHOW_FILES";//$NON-NLS-1$ String mneu = "Specify.LOG_SHOW_FILES_MNEU";//$NON-NLS-1$ String desc = "Specify.LOG_SHOW_FILES";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); helpMenu.addSeparator(); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { AppBase.displaySpecifyLogFiles(); } }); ttle = "SecurityAdminTask.CHANGE_PWD_MENU"; //$NON-NLS-1$ mneu = "SecurityAdminTask.CHANGE_PWD_MNEU"; //$NON-NLS-1$ desc = "SecurityAdminTask.CHANGE_PWD_DESC"; //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { SecurityAdminTask.changePassword(true); } }); ttle = "Specify.CHECK_UPDATE";//$NON-NLS-1$ mneu = "Specify.CHECK_UPDATE_MNEU";//$NON-NLS-1$ desc = "Specify.CHECK_UPDATE_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { checkForUpdates(); } }); ttle = "Specify.AUTO_REG";//$NON-NLS-1$ mneu = "Specify.AUTO_REG_MNEU";//$NON-NLS-1$ desc = "Specify.AUTO_REG_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { RegisterSpecify.register(true, 0); } }); ttle = "Specify.SA_REG";//$NON-NLS-1$ mneu = "Specify.SA_REG_MNEU";//$NON-NLS-1$ desc = "Specify.SA_REG_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { RegisterSpecify.registerISA(); } }); ttle = "Specify.FEEDBACK";//$NON-NLS-1$ mneu = "Specify.FB_MNEU";//$NON-NLS-1$ desc = "Specify.FB_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { FeedBackDlg feedBackDlg = new FeedBackDlg(); feedBackDlg.sendFeedback(); } }); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { helpMenu.addSeparator(); ttle = "Specify.ABOUT";//$NON-NLS-1$ mneu = "Specify.ABOUTMNEU";//$NON-NLS-1$ desc = "Specify.ABOUT";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doAbout(); } }); } return mb; }
From source file:org.rdv.datapanel.DigitalTabularDataPanel.java
private void addColumn() { if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) { return;//from w w w .j a va 2s. c om } if (columnGroupCount != 0) { panelBox.add(Box.createHorizontalStrut(7)); } final int tableIndex = columnGroupCount; final DataTableModel tableModel = new DataTableModel(); final JTable table = new JTable(tableModel); table.setDragEnabled(true); table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount)); if (showThresholdCheckBoxGroup.isSelected()) { tableModel.setThresholdVisible(true); } if (showMinMaxCheckBoxGroup.isSelected()) { tableModel.setMaxMinVisible(true); table.getColumn("Min").setCellRenderer(doubleCellRenderer); table.getColumn("Max").setCellRenderer(doubleCellRenderer); } table.getColumn("Value").setCellRenderer(dataCellRenderer); tables.add(table); tableModels.add(tableModel); JScrollPane tableScrollPane = new JScrollPane(table); panelBox.add(tableScrollPane); // popup menu for panel JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { TransferHandler.getCopyAction().actionPerformed( new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers())); } }); popupMenu.add(copyMenuItem); popupMenu.addSeparator(); JMenuItem printMenuItem = new JMenuItem("Print..."); printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { table.print(JTable.PrintMode.FIT_WIDTH); } catch (PrinterException pe) { } } }); popupMenu.add(printMenuItem); popupMenu.addSeparator(); final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false); showMaxMinMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setMaxMinVisible(showMaxMinMenuItem.isSelected()); } }); showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem); popupMenu.add(showMaxMinMenuItem); final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false); showThresholdMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setThresholdVisible(showThresholdMenuItem.isSelected()); } }); showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem); popupMenu.add(showThresholdMenuItem); popupMenu.addSeparator(); JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row"); blankRowMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tableModel.addBlankRow(); } }); popupMenu.add(blankRowMenuItem); final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows"); removeSelectedRowsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeSelectedRows(tableIndex); } }); popupMenu.add(removeSelectedRowsMenuItem); popupMenu.addSeparator(); JMenu numberOfColumnsMenu = new JMenu("Number of columns"); numberOfColumnsMenu.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent me) { JMenu menu = (JMenu) me.getSource(); for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) { JMenuItem menuItem = menu.getItem(j); boolean selected = (j == (columnGroupCount - 1)); menuItem.setSelected(selected); } } public void menuDeselected(MenuEvent me) { } public void menuCanceled(MenuEvent me) { } }); for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) { final int number = i + 1; JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setNumberOfColumns(number); } }); numberOfColumnsMenu.add(item); } popupMenu.add(numberOfColumnsMenu); popupMenu.addPopupMenuListener(new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) { boolean anyRowsSelected = table.getSelectedRowCount() > 0; copyMenuItem.setEnabled(anyRowsSelected); removeSelectedRowsMenuItem.setEnabled(anyRowsSelected); } public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } public void popupMenuCanceled(PopupMenuEvent arg0) { } }); // set component popup and mouselistener to trigger it table.setComponentPopupMenu(popupMenu); tableScrollPane.setComponentPopupMenu(popupMenu); panelBox.revalidate(); columnGroupCount++; properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount)); }