@Override public JComponent getPreferredFocusedComponent() { final Enumeration<AbstractButton> enumeration = myGroup.getElements(); while (enumeration.hasMoreElements()) { final AbstractButton button = enumeration.nextElement(); if (button.isSelected()) { return button; } } return myPanel; }
// Get what the user selects as the answer public String getSelection() { String selectedChoice = null; Enumeration<AbstractButton> buttons = bg.getElements(); while (buttons.hasMoreElements()) { JRadioButton temp = (JRadioButton) buttons.nextElement(); if (temp.isSelected()) { selectedChoice = temp.getText(); } } return (selectedChoice); }
/** * Sets the selected strack trace level on the radio buttons. The radio buttons store their stack * trace level as a client property and I'll look for a match using that. This way, we don't have * to edit this if new levels are created. * * @param newStackTraceLevel the new stack trace level. */ private void setSelectedStackTraceLevel(ShowStacktrace newStackTraceLevel) { Enumeration<AbstractButton> buttonEnumeration = stackTraceButtonGroup.getElements(); while (buttonEnumeration.hasMoreElements()) { JRadioButton radioButton = (JRadioButton) buttonEnumeration.nextElement(); ShowStacktrace level = (ShowStacktrace) radioButton.getClientProperty(STACK_TRACE_LEVEL_CLIENT_PROPERTY); if (newStackTraceLevel == level) { radioButton.setSelected(true); return; } } }
/** * Returns the currently selected stack trace level. The radio buttons store their stack trace * level as a client property so once we get the selected button, we know the level. This way, we * don't have to edit this if new levels are created. Unfortunately, Swing doesn't have an easy * way to get the actual button from the group. * * @return the selected stack trace level */ private ShowStacktrace getSelectedStackTraceLevel() { ButtonModel selectedButtonModel = stackTraceButtonGroup.getSelection(); if (selectedButtonModel != null) { Enumeration<AbstractButton> buttonEnumeration = stackTraceButtonGroup.getElements(); while (buttonEnumeration.hasMoreElements()) { JRadioButton radioButton = (JRadioButton) buttonEnumeration.nextElement(); if (radioButton.getModel() == selectedButtonModel) { ShowStacktrace level = (ShowStacktrace) radioButton.getClientProperty(STACK_TRACE_LEVEL_CLIENT_PROPERTY); return level; } } } return ShowStacktrace.INTERNAL_EXCEPTIONS; }
private void refreshMenu() { // refresh the associated mnemonics, so that the keyboard shortcut // keys are properly renumbered... // get an enumeration to the elements of the current button group Enumeration e = frameRadioButtonMenuItemGroup.getElements(); int displayedCount = 1; int currentMenuCount = 0; while (e.hasMoreElements()) { BaseRadioButtonMenuItem b = (BaseRadioButtonMenuItem) e.nextElement(); // compute the key mnemonic based upon the currentMenuCount currentMenuCount = displayedCount; if (currentMenuCount > 9) { currentMenuCount /= 10; } b.setMnemonic(KeyEvent.VK_0 + currentMenuCount); b.setText(displayedCount + " " + b.getAssociatedFrame().getTitle()); displayedCount++; } }
@Override protected JComponent createCenterPanel() { myTitledSeparator.setText(myAnalysisNoon); // include test option myInspectTestSource.setSelected(myAnalysisOptions.ANALYZE_TEST_SOURCES); // module scope if applicable myModuleButton.setText( AnalysisScopeBundle.message("scope.option.module.with.mnemonic", myModuleName)); boolean useModuleScope = false; if (myModuleName != null) { useModuleScope = myAnalysisOptions.SCOPE_TYPE == AnalysisScope.MODULE; myModuleButton.setSelected(myRememberScope && useModuleScope); } myModuleButton.setVisible( myModuleName != null && ModuleManager.getInstance(myProject).getModules().length > 1); boolean useUncommitedFiles = false; final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); final boolean hasVCS = !changeListManager.getAffectedFiles().isEmpty(); if (hasVCS) { useUncommitedFiles = myAnalysisOptions.SCOPE_TYPE == AnalysisScope.UNCOMMITTED_FILES; myUncommitedFilesButton.setSelected(myRememberScope && useUncommitedFiles); } myUncommitedFilesButton.setVisible(hasVCS); DefaultComboBoxModel model = new DefaultComboBoxModel(); model.addElement(ALL); final List<? extends ChangeList> changeLists = changeListManager.getChangeListsCopy(); for (ChangeList changeList : changeLists) { model.addElement(changeList.getName()); } myChangeLists.setModel(model); myChangeLists.setEnabled(myUncommitedFilesButton.isSelected()); myChangeLists.setVisible(hasVCS); // file/package/directory/module scope if (myFileName != null) { myFileButton.setText(myFileName); myFileButton.setMnemonic(myFileName.charAt(getSelectedScopeMnemonic())); } else { myFileButton.setVisible(false); } VirtualFile file = PsiUtilBase.getVirtualFile(myContext); ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); boolean searchInLib = file != null && (fileIndex.isInLibraryClasses(file) || fileIndex.isInLibrarySource(file)); String preselect = StringUtil.isEmptyOrSpaces(myAnalysisOptions.CUSTOM_SCOPE_NAME) ? FindSettings.getInstance().getDefaultScopeName() : myAnalysisOptions.CUSTOM_SCOPE_NAME; if (searchInLib && GlobalSearchScope.projectScope(myProject).getDisplayName().equals(preselect)) { preselect = GlobalSearchScope.allScope(myProject).getDisplayName(); } if (GlobalSearchScope.allScope(myProject).getDisplayName().equals(preselect) && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.CUSTOM) { myAnalysisOptions.CUSTOM_SCOPE_NAME = preselect; searchInLib = true; } // custom scope myCustomScopeButton.setSelected( myRememberScope && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.CUSTOM); myScopeCombo.init(myProject, searchInLib, true, preselect); // correct selection myProjectButton.setSelected( myRememberScope && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.PROJECT || myFileName == null); myFileButton.setSelected( myFileName != null && (!myRememberScope || myAnalysisOptions.SCOPE_TYPE != AnalysisScope.PROJECT && !useModuleScope && myAnalysisOptions.SCOPE_TYPE != AnalysisScope.CUSTOM && !useUncommitedFiles)); myScopeCombo.setEnabled(myCustomScopeButton.isSelected()); final ActionListener radioButtonPressed = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onScopeRadioButtonPressed(); } }; final Enumeration<AbstractButton> enumeration = myGroup.getElements(); while (enumeration.hasMoreElements()) { enumeration.nextElement().addActionListener(radioButtonPressed); } // additional panel - inspection profile chooser JPanel wholePanel = new JPanel(new BorderLayout()); wholePanel.add(myPanel, BorderLayout.NORTH); final JComponent additionalPanel = getAdditionalActionSettings(myProject); if (additionalPanel != null) { wholePanel.add(additionalPanel, BorderLayout.CENTER); } new RadioUpDownListener( myProjectButton, myModuleButton, myUncommitedFilesButton, myFileButton, myCustomScopeButton); return wholePanel; }