List of usage examples for javax.swing Action actionPerformed
public void actionPerformed(ActionEvent e);
From source file:com.diversityarrays.kdxplore.trialmgr.TrialManagerApp.java
public TrialManagerApp(KdxPluginInfo pluginInfo) throws IOException { super(new BorderLayout()); this.messagesPanel = pluginInfo.getMessagePrinter(); this.backgroundRunner = pluginInfo.getBackgroundRunner(); this.userDataFolder = pluginInfo.getUserDataFolder(); this.clientProvider = pluginInfo.getClientProvider(); this.offlineData = pluginInfo.getSingletonSharedResource(OfflineData.class); KDSmartApplication.getInstance().setMessagePrinter(pluginInfo.getMessagePrintStream()); this.driverType = DriverType.getDriverTypeFromSystemProperties(DriverType.H2); offlineData.addOfflineDataChangeListener(offlineDataChangeListener); linkedIcon = KDClientUtils.getIcon(ImageId.CONNECTED_24); unlinkedIcon = KDClientUtils.getIcon(ImageId.DISCONNECTED_24); barcodeIcon = KDClientUtils.getIcon(ImageId.BARCODE_PAGE); updateDatabaseUrlLabel();//from w w w . j a v a2 s .com this.clientProvider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { handleClientChanged(); } }); explorerProperties = ExplorerProperties.getInstance(); PreferenceCollection pc = TrialManagerPreferences.getInstance().getPreferenceCollection(this, Msg.APPNAME_TRIAL_MANAGER()); KdxplorePreferences.getInstance().addPreferenceCollection(pc); TraitValue.DISPLAY_DATE_DIFF_AS_NDAYS = explorerProperties.getDisplayElapsedDaysAsCount(); ExplorerServices explorerServices = new ExplorerServices(pluginInfo, offlineData // , clientProvider ); trialExplorerPanel = new TrialExplorerPanel(this, // KdxApp pluginInfo, explorerServices.getKdxDeviceService(), this, // as TrialExplorerManager offlineData, driverType, barcodeIcon, clientUrlChanger, trialsLoadedConsumer, traitRemovalHandler); tabbedPane.addTab(TAB_TRIALS, KDClientUtils.getIcon(ImageId.KDS_TRIALS), trialExplorerPanel); Transformer<Trial, Boolean> checkIfEditorIsActive = new Transformer<Trial, Boolean>() { @Override public Boolean transform(Trial trial) { return trialExplorerPanel.isEditorActiveForTrial(trial); } }; traitExplorerPanel = new TraitExplorerPanel(messagesPanel, offlineData, clientProvider, // uploadHandler, backgroundRunner, barcodeIcon, checkIfEditorIsActive); tabbedPane.addTab(TAB_TRAITS, KDClientUtils.getIcon(ImageId.KDS_TRAITS), traitExplorerPanel); tagExplorerPanel = new TagExplorerPanel(offlineData); tabbedPane.addTab(TAB_TAGS, KDClientUtils.getIcon(ImageId.BLACK_TAG), tagExplorerPanel); // Now tie together those panels that need to talk to each other trialExplorerPanel.setTraitExplorer(traitExplorerPanel); Box box = Box.createHorizontalBox(); explorerServices.addActions(box); box.add(Box.createHorizontalGlue()); box.add(databaseUrlLabel); box.add(Box.createHorizontalGlue()); Action action = offlineData.getOfflineDataAction(); if (action != null) { JButton button = new JButton(pluginInfo.getKdxploreIcon()); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (RunMode.getRunMode().isDeveloper()) { if (0 != (ActionEvent.SHIFT_MASK & e.getModifiers())) { openJdbcExplorer(); return; } } action.actionPerformed(e); } }); box.add(button); } add(box, BorderLayout.NORTH); add(tabbedPane, BorderLayout.CENTER); }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java
/** * Sets the font family and size//from ww w.ja v a 2s.c o m * @param family the family name * @param size the size */ public void setFontFamilyAndSize(String family, int size) { // Family ActionEvent evt = new ActionEvent(editorPane, ActionEvent.ACTION_PERFORMED, family); Action action = new StyledEditorKit.FontFamilyAction(family, family); action.actionPerformed(evt); // Size evt = new ActionEvent(editorPane, ActionEvent.ACTION_PERFORMED, Integer.toString(size)); action = new StyledEditorKit.FontSizeAction(Integer.toString(size), size); action.actionPerformed(evt); }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java
/** * Sets the font color/*from w w w . j a v a2 s .c om*/ * @param color the color */ public void setFontColor(Color color) { ActionEvent evt = new ActionEvent(editorPane, ActionEvent.ACTION_PERFORMED, ""); Action action = new HTMLEditorKit.ForegroundAction(Integer.toString(color.getRGB()), color); action.actionPerformed(evt); }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java
/** * Sets the given style constant.// w w w . j av a 2s . co m * * @param action the action * @param styleConstant the style constant */ private void setStyleConstant(Action action, Object styleConstant) { ActionEvent event = new ActionEvent(editorPane, ActionEvent.ACTION_PERFORMED, styleConstant.toString()); action.actionPerformed(event); }
From source file:edu.ucla.stat.SOCR.chart.Chart.java
/** * Add customized table actions. //from ww w . ja v a 2 s. c om * Clicking tab in the last cell will add one new column. * Clicking return in the last cell will add one new row. * */ protected void hookTableAction() { //Tab--add column String actionName = "selectNextColumnCell"; final Action tabAction = dataTable.getActionMap().get(actionName); Action myAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { //if (dataTable.isEditing() && isLastCell()) { if (isLastCell()) { //resetTableColumns(dataTable.getColumnCount()+1); appendTableColumns(1); } else tabAction.actionPerformed(e); } }; dataTable.getActionMap().put(actionName, myAction); //Enter--append row String actionName2 = "selectNextRowCell"; final Action enterAction = dataTable.getActionMap().get(actionName2); Action myAction2 = new AbstractAction() { public void actionPerformed(ActionEvent e) { //if (dataTable.isEditing() && isLastCell()) { if (isLastCell()) { appendTableRows(1); } else enterAction.actionPerformed(e); } }; dataTable.getActionMap().put(actionName2, myAction2); /* String actionName3 = "deleteSelectedData"; final Action delAction = dataTable.getActionMap().get(actionName3); Action myAction3 = new AbstractAction() { public void actionPerformed(ActionEvent e) { if ((dataTable.getSelectedRow() >= 0) && (dataTable.getSelectedColumn() >= 0)){ int[] rows=dataTable.getSelectedRows(); int[] cols=dataTable.getSelectedColumns(); for (int i=rows[0]; i<cols[rows.length-1]; i++) for (int j = cols[0]; j<cols[cols.length-1]; j++){ dataTable.setValueAt("", i, j); } }else delAction.actionPerformed(e); } }; dataTable.getActionMap().put("delete", myAction3);*/ }
From source file:op.tools.SYSTools.java
public static BigDecimal checkBigDecimal(javax.swing.event.CaretEvent evt, boolean nees2BePositive) { BigDecimal bd = null;//from w ww. j av a2 s.c om JTextComponent txt = (JTextComponent) evt.getSource(); Action toolTipAction = txt.getActionMap().get("hideTip"); if (toolTipAction != null) { ActionEvent hideTip = new ActionEvent(txt, ActionEvent.ACTION_PERFORMED, ""); toolTipAction.actionPerformed(hideTip); } try { OPDE.debug(txt.getText()); OPDE.debug(assimilateDecimalSeparators(txt.getText())); bd = parseDecimal(txt.getText()); // bd = BigDecimal.valueOf(Double.parseDouble(assimilateDecimalSeparators(txt.getText()))); OPDE.debug(bd); if (nees2BePositive && bd.compareTo(BigDecimal.ZERO) <= 0) { txt.setToolTipText("<html><font color=\"red\"><b>" + SYSTools.xx("misc.msg.invalidnumber") + "</b></font></html>"); toolTipAction = txt.getActionMap().get("postTip"); bd = BigDecimal.ONE; } else { txt.setToolTipText(""); } } catch (NumberFormatException ex) { if (nees2BePositive) { bd = BigDecimal.ONE; } else { bd = BigDecimal.ZERO; } txt.setToolTipText( "<html><font color=\"red\"><b>" + SYSTools.xx("misc.msg.invalidnumber") + "</b></font></html>"); toolTipAction = txt.getActionMap().get("postTip"); if (toolTipAction != null) { ActionEvent postTip = new ActionEvent(txt, ActionEvent.ACTION_PERFORMED, ""); toolTipAction.actionPerformed(postTip); } } return bd; }
From source file:org.apache.log4j.chainsaw.LogUI.java
/** * Activates itself as a viewer by configuring Size, and location of itself, * and configures the default Tabbed Pane elements with the correct layout, * table columns, and sets itself viewable. *///from w ww . j a v a 2 s.co m public void activateViewer() { LoggerRepository repo = LogManager.getLoggerRepository(); if (repo instanceof LoggerRepositoryEx) { this.pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry(); } initGUI(); initPrefModelListeners(); /** * We add a simple appender to the MessageCenter logger * so that each message is displayed in the Status bar */ MessageCenter.getInstance().getLogger().addAppender(new AppenderSkeleton() { protected void append(LoggingEvent event) { getStatusBar().setMessage(event.getMessage().toString()); } public void close() { } public boolean requiresLayout() { return false; } }); initSocketConnectionListener(); if (pluginRegistry.getPlugins(Receiver.class).size() == 0) { noReceiversDefined = true; } getFilterableColumns().add(ChainsawConstants.LEVEL_COL_NAME); getFilterableColumns().add(ChainsawConstants.LOGGER_COL_NAME); getFilterableColumns().add(ChainsawConstants.THREAD_COL_NAME); getFilterableColumns().add(ChainsawConstants.NDC_COL_NAME); getFilterableColumns().add(ChainsawConstants.PROPERTIES_COL_NAME); getFilterableColumns().add(ChainsawConstants.CLASS_COL_NAME); getFilterableColumns().add(ChainsawConstants.METHOD_COL_NAME); getFilterableColumns().add(ChainsawConstants.FILE_COL_NAME); getFilterableColumns().add(ChainsawConstants.NONE_COL_NAME); JPanel panePanel = new JPanel(); panePanel.setLayout(new BorderLayout(2, 2)); getContentPane().setLayout(new BorderLayout()); getTabbedPane().addChangeListener(getToolBarAndMenus()); getTabbedPane().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { LogPanel thisLogPanel = getCurrentLogPanel(); if (thisLogPanel != null) { thisLogPanel.updateStatusBar(); } } }); KeyStroke ksRight = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); KeyStroke ksLeft = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); KeyStroke ksGotoLine = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksRight, "MoveRight"); getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksLeft, "MoveLeft"); getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksGotoLine, "GotoLine"); Action moveRight = new AbstractAction() { public void actionPerformed(ActionEvent e) { int temp = getTabbedPane().getSelectedIndex(); ++temp; if (temp != getTabbedPane().getTabCount()) { getTabbedPane().setSelectedTab(temp); } } }; Action moveLeft = new AbstractAction() { public void actionPerformed(ActionEvent e) { int temp = getTabbedPane().getSelectedIndex(); --temp; if (temp > -1) { getTabbedPane().setSelectedTab(temp); } } }; Action gotoLine = new AbstractAction() { public void actionPerformed(ActionEvent e) { String inputLine = JOptionPane.showInputDialog(LogUI.this, "Enter the line number to go:", "Goto Line", -1); try { int lineNumber = Integer.parseInt(inputLine); int row = getCurrentLogPanel().setSelectedEvent(lineNumber); if (row == -1) { JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number", "Error", 0); } } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number", "Error", 0); } } }; getTabbedPane().getActionMap().put("MoveRight", moveRight); getTabbedPane().getActionMap().put("MoveLeft", moveLeft); getTabbedPane().getActionMap().put("GotoLine", gotoLine); /** * We listen for double clicks, and auto-undock currently selected Tab if * the mouse event location matches the currently selected tab */ getTabbedPane().addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if ((e.getClickCount() > 1) && ((e.getModifiers() & InputEvent.BUTTON1_MASK) > 0)) { int tabIndex = getTabbedPane().getSelectedIndex(); if ((tabIndex != -1) && (tabIndex == getTabbedPane().getSelectedIndex())) { LogPanel logPanel = getCurrentLogPanel(); if (logPanel != null) { logPanel.undock(); } } } } }); panePanel.add(getTabbedPane()); addWelcomePanel(); getContentPane().add(toolbar, BorderLayout.NORTH); getContentPane().add(statusBar, BorderLayout.SOUTH); mainReceiverSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panePanel, receiversPanel); dividerSize = mainReceiverSplitPane.getDividerSize(); mainReceiverSplitPane.setDividerLocation(-1); getContentPane().add(mainReceiverSplitPane, BorderLayout.CENTER); /** * We need to make sure that all the internal GUI components have been added to the * JFrame so that any plugns that get activated during initPlugins(...) method * have access to inject menus */ initPlugins(pluginRegistry); mainReceiverSplitPane.setResizeWeight(1.0); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { exit(); } }); preferencesFrame.setTitle("'Application-wide Preferences"); preferencesFrame.setIconImage(((ImageIcon) ChainsawIcons.ICON_PREFERENCES).getImage()); preferencesFrame.getContentPane().add(applicationPreferenceModelPanel); preferencesFrame.setSize(750, 520); Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); preferencesFrame.setLocation(new Point((screenDimension.width / 2) - (preferencesFrame.getSize().width / 2), (screenDimension.height / 2) - (preferencesFrame.getSize().height / 2))); pack(); final JPopupMenu tabPopup = new JPopupMenu(); final Action hideCurrentTabAction = new AbstractAction("Hide") { public void actionPerformed(ActionEvent e) { Component selectedComp = getTabbedPane().getSelectedComponent(); if (selectedComp instanceof LogPanel) { displayPanel(getCurrentLogPanel().getIdentifier(), false); tbms.stateChange(); } else { getTabbedPane().remove(selectedComp); } } }; final Action hideOtherTabsAction = new AbstractAction("Hide Others") { public void actionPerformed(ActionEvent e) { Component selectedComp = getTabbedPane().getSelectedComponent(); String currentName; if (selectedComp instanceof LogPanel) { currentName = getCurrentLogPanel().getIdentifier(); } else if (selectedComp instanceof WelcomePanel) { currentName = ChainsawTabbedPane.WELCOME_TAB; } else { currentName = ChainsawTabbedPane.ZEROCONF; } int count = getTabbedPane().getTabCount(); int index = 0; for (int i = 0; i < count; i++) { String name = getTabbedPane().getTitleAt(index); if (getPanelMap().keySet().contains(name) && !name.equals(currentName)) { displayPanel(name, false); tbms.stateChange(); } else { index++; } } } }; Action showHiddenTabsAction = new AbstractAction("Show All Hidden") { public void actionPerformed(ActionEvent e) { for (Iterator iter = getPanels().entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); Boolean docked = (Boolean) entry.getValue(); if (docked.booleanValue()) { String identifier = (String) entry.getKey(); int count = getTabbedPane().getTabCount(); boolean found = false; for (int i = 0; i < count; i++) { String name = getTabbedPane().getTitleAt(i); if (name.equals(identifier)) { found = true; break; } } if (!found) { displayPanel(identifier, true); tbms.stateChange(); } } } } }; tabPopup.add(hideCurrentTabAction); tabPopup.add(hideOtherTabsAction); tabPopup.addSeparator(); tabPopup.add(showHiddenTabsAction); final PopupListener tabPopupListener = new PopupListener(tabPopup); getTabbedPane().addMouseListener(tabPopupListener); this.handler.addPropertyChangeListener("dataRate", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { double dataRate = ((Double) evt.getNewValue()).doubleValue(); statusBar.setDataRate(dataRate); } }); getSettingsManager().addSettingsListener(this); getSettingsManager().addSettingsListener(MRUFileListPreferenceSaver.getInstance()); getSettingsManager().addSettingsListener(receiversPanel); try { //if an uncaught exception is thrown, allow the UI to continue to load getSettingsManager().loadSettings(); } catch (Exception e) { e.printStackTrace(); } //app preferences have already been loaded (and configuration url possibly set to blank if being overridden) //but we need a listener so the settings will be saved on exit (added after loadsettings was called) getSettingsManager().addSettingsListener(new ApplicationPreferenceModelSaver(applicationPreferenceModel)); setVisible(true); if (applicationPreferenceModel.isReceivers()) { showReceiverPanel(); } else { hideReceiverPanel(); } removeSplash(); synchronized (initializationLock) { isGUIFullyInitialized = true; initializationLock.notifyAll(); } if (noReceiversDefined && applicationPreferenceModel.isShowNoReceiverWarning()) { SwingHelper.invokeOnEDT(new Runnable() { public void run() { showReceiverConfigurationPanel(); } }); } Container container = tutorialFrame.getContentPane(); final JEditorPane tutorialArea = new JEditorPane(); tutorialArea.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); tutorialArea.setEditable(false); container.setLayout(new BorderLayout()); try { tutorialArea.setPage(ChainsawConstants.TUTORIAL_URL); JTextComponentFormatter.applySystemFontAndSize(tutorialArea); container.add(new JScrollPane(tutorialArea), BorderLayout.CENTER); } catch (Exception e) { MessageCenter.getInstance().getLogger().error("Error occurred loading the Tutorial", e); } tutorialFrame.setIconImage(new ImageIcon(ChainsawIcons.HELP).getImage()); tutorialFrame.setSize(new Dimension(640, 480)); final Action startTutorial = new AbstractAction("Start Tutorial", new ImageIcon(ChainsawIcons.ICON_RESUME_RECEIVER)) { public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(null, "This will start 3 \"Generator\" receivers for use in the Tutorial. Is that ok?", "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { new Thread(new Tutorial()).start(); putValue("TutorialStarted", Boolean.TRUE); } else { putValue("TutorialStarted", Boolean.FALSE); } } }; final Action stopTutorial = new AbstractAction("Stop Tutorial", new ImageIcon(ChainsawIcons.ICON_STOP_RECEIVER)) { public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(null, "This will stop all of the \"Generator\" receivers used in the Tutorial, but leave any other Receiver untouched. Is that ok?", "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { new Thread(new Runnable() { public void run() { LoggerRepository repo = LogManager.getLoggerRepository(); if (repo instanceof LoggerRepositoryEx) { PluginRegistry pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry(); List list = pluginRegistry.getPlugins(Generator.class); for (Iterator iter = list.iterator(); iter.hasNext();) { Plugin plugin = (Plugin) iter.next(); pluginRegistry.stopPlugin(plugin.getName()); } } } }).start(); setEnabled(false); startTutorial.putValue("TutorialStarted", Boolean.FALSE); } } }; stopTutorial.putValue(Action.SHORT_DESCRIPTION, "Removes all of the Tutorials Generator Receivers, leaving all other Receivers untouched"); startTutorial.putValue(Action.SHORT_DESCRIPTION, "Begins the Tutorial, starting up some Generator Receivers so you can see Chainsaw in action"); stopTutorial.setEnabled(false); final SmallToggleButton startButton = new SmallToggleButton(startTutorial); PropertyChangeListener pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { stopTutorial.setEnabled(((Boolean) startTutorial.getValue("TutorialStarted")).equals(Boolean.TRUE)); startButton.setSelected(stopTutorial.isEnabled()); } }; startTutorial.addPropertyChangeListener(pcl); stopTutorial.addPropertyChangeListener(pcl); pluginRegistry.addPluginListener(new PluginListener() { public void pluginStarted(PluginEvent e) { } public void pluginStopped(PluginEvent e) { List list = pluginRegistry.getPlugins(Generator.class); if (list.size() == 0) { startTutorial.putValue("TutorialStarted", Boolean.FALSE); } } }); final SmallButton stopButton = new SmallButton(stopTutorial); final JToolBar tutorialToolbar = new JToolBar(); tutorialToolbar.setFloatable(false); tutorialToolbar.add(startButton); tutorialToolbar.add(stopButton); container.add(tutorialToolbar, BorderLayout.NORTH); tutorialArea.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (e.getDescription().equals("StartTutorial")) { startTutorial.actionPerformed(null); } else if (e.getDescription().equals("StopTutorial")) { stopTutorial.actionPerformed(null); } else { try { tutorialArea.setPage(e.getURL()); } catch (IOException e1) { MessageCenter.getInstance().getLogger() .error("Failed to change the URL for the Tutorial", e1); } } } } }); /** * loads the saved tab settings and if there are hidden tabs, * hide those tabs out of currently loaded tabs.. */ if (!getTabbedPane().tabSetting.isWelcome()) { displayPanel(ChainsawTabbedPane.WELCOME_TAB, false); } if (!getTabbedPane().tabSetting.isZeroconf()) { displayPanel(ChainsawTabbedPane.ZEROCONF, false); } tbms.stateChange(); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
public static void addDoubleClickAction(JComponent component, final Action action) { component.addMouseListener(new MouseAdapter() { @Override/* www .ja v a 2s. c o m*/ public void mouseClicked(MouseEvent e) { if (e.getClickCount() == DOUBLE_CLICK_COUNT && e.getButton() == MouseEvent.BUTTON1) { action.actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, (String) action.getValue(Action.ACTION_COMMAND_KEY), e.getWhen(), e.getModifiers())); } } }); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
/** * Creates a wrapper around an existing action of the component to be used * in menus./* w ww. j a v a 2 s . co m*/ * * @param c * base component * @param actionKey * key in the component's ActionMap * @param caption * caption of the action wrapper * @param acceleratorKey * accelerator key of the action wrapper * @return action that translates its * {@link Action#actionPerformed(ActionEvent)} to the underlaying * existing action. */ public static Action createActionWrapper(final JComponent c, final String actionKey, String caption, final String acceleratorKey) { final Action baseAction = c.getActionMap().get(actionKey); Action result = new AbstractAction(caption) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(acceleratorKey)); } @Override public void actionPerformed(ActionEvent e) { ActionEvent newEvent = new ActionEvent(c, e.getID(), actionKey, e.getWhen(), e.getModifiers()); baseAction.actionPerformed(newEvent); } @Override public void setEnabled(boolean newValue) { super.setEnabled(newValue); baseAction.setEnabled(newValue); } }; return result; }
From source file:org.isatools.isacreator.gui.formelements.SubForm.java
protected void setupTableTabBehaviour() { InputMap im = scrollTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); // Override the default tab behaviour // Tab to the next editable cell. When no editable cells goto next cell. final Action previousTabAction = scrollTable.getActionMap().get(im.get(tab)); Action newTabAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { int rowSel = scrollTable.getSelectedRow(); int colSel = scrollTable.getSelectedColumn(); if (rowSel == (scrollTable.getRowCount() - 1)) { scrollTable.setRowSelectionInterval(0, 0); if ((colSel + 1) == scrollTable.getColumnCount()) { scrollTable.setColumnSelectionInterval(0, 0); } else { scrollTable.setColumnSelectionInterval(colSel + 1, colSel + 1); }//from ww w. ja va 2s. c o m } else { rowSel = rowSel + 1; scrollTable.setRowSelectionInterval(rowSel, rowSel); if (colSel > -1) { scrollTable.setColumnSelectionInterval(colSel, colSel); } } scrollTable.scrollRectToVisible(scrollTable.getCellRect(rowSel, colSel, true)); JTable table = (JTable) e.getSource(); int row = table.getSelectedRow(); int originalRow = row; int column = table.getSelectedColumn(); int originalColumn = column; while (!table.isCellEditable(row, column)) { previousTabAction.actionPerformed(e); row = table.getSelectedRow(); column = table.getSelectedColumn(); // Back to where we started, get out. if ((row == originalRow) && (column == originalColumn)) { break; } } if (table.editCellAt(row, column)) { table.getEditorComponent().requestFocusInWindow(); } } }; scrollTable.getActionMap().put(im.get(tab), newTabAction); }