下面列出了javax.swing.AbstractButton#setSelected ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Set value of a search pattern option. Bound abstract button will be
* selected or deselected accordingly.
*/
private void setOption(@NonNull Option option, boolean value) {
Parameters.notNull("option", option); //NOI18N
options.put(option, value);
AbstractButton button = bindings.get(option);
if (button != null) {
button.setSelected(value);
}
if (option == Option.REGULAR_EXPRESSION) {
if ((matchType == MatchType.REGEXP) != value) {
setMatchType(value ? MatchType.REGEXP : MatchType.LITERAL);
}
updateValidity();
}
fireChange();
}
/**
* Bind an abstract button (usually checkbox) to a SearchPattern option.
*
* @param option Option whose value the button should represent.
* @param button Button to control and display the option.
*/
public void bind(@NonNull final Option option,
@NonNull final AbstractButton button) {
Parameters.notNull("option", option); //NOI18N
Parameters.notNull("button", button); //NOI18N
if (bindings.containsKey(option)) {
throw new IllegalStateException(
"Already binded with option " + option); // NOI18N
}
bindings.put(option, button);
button.setSelected(getOption(option));
button.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
setOption(option, button.isSelected());
}
});
}
public void add(AbstractButton b) {
if (b == null) {
return;
}
buttons.addElement(b);
if (b.isSelected()) {
if (modifiedSelection == null) {
modifiedSelection = b.getModel();
} else {
b.setSelected(false);
}
}
b.getModel().setGroup(this);
}
/**
* This method builds the specified button according to the specified
* parameters.
*
* @param button The button to build.
* @param text The text displayed on the button.
* @param icon The icon to use.
* @param handler The action listener that monitors the buttons events.
* @param command The action command used when the button is clicked.
* @param group The group the button should belong to.
* @param selected The initial selected state of the button.
* @param tip The tool tip to display.
*/
public
static
void
buildButton(AbstractButton button, String text, Icon icon,
ActionListener handler, String command, ButtonGroup group,
boolean selected, String tip)
{
button.addActionListener(handler);
button.setActionCommand(command);
button.setIcon(icon);
button.setSelected(selected);
button.setText(text);
button.setToolTipText(tip);
if(group != null)
{
group.add(button);
}
}
private void selectABrowser() {
String browser = getPreviouslySelectedBrowser();
if (browser == null) {
browser = RunManager.getGlobalSettings().getBrowser();
}
if (browser != null) {
for (Enumeration<AbstractButton> buttons = browserSelectButtonGroup.getElements(); buttons.hasMoreElements();) {
AbstractButton button = buttons.nextElement();
if (button.getActionCommand().equals(browser)) {
button.setSelected(true);
}
}
} else {
browserSelectButtonGroup.setSelected(browserSelectButtonGroup.getElements().nextElement().getModel(), true);
}
}
/**
* Temporarily massage this component so it is visible, enabled, unselected,
* unfocused, etc.
*/
private void storeState(JComponent c) {
if (c instanceof AbstractButton) {
AbstractButton b = (AbstractButton) c;
b.putClientProperty(WAS_SELECTED, new Boolean(b.isSelected()));
b.putClientProperty(WAS_FOCUS_PAINTED, new Boolean(b.isSelected()));
b.setSelected(false);
b.setFocusPainted(false);
}
if (c.isEnabled() == false) {
c.putClientProperty(WAS_ENABLED, new Boolean(c.isEnabled()));
c.setEnabled(true);
}
if (c.isVisible() == false) {
c.putClientProperty(WAS_VISIBLE, new Boolean(c.isVisible()));
c.setVisible(true);
}
for (int a = 0; a < c.getComponentCount(); a++) {
if (c.getComponent(a) instanceof JComponent) {
storeState((JComponent) c.getComponent(a));
}
}
}
/**
* Selects the given action in the menu. This methods also updates the selection status of the
* toggle button.
*
* @param action
* the action which should be selected
*/
public void setSelected(Action action) {
Enumeration<AbstractButton> menuEnum = popupMenuGroup.getElements();
boolean found = false;
while (menuEnum.hasMoreElements()) {
AbstractButton button = menuEnum.nextElement();
if (action == button.getAction()) {
button.setSelected(true);
found = true;
} else {
button.setSelected(false);
}
}
if (found) {
setFont(getFont().deriveFont(Font.BOLD));
updateSelectionStatus();
} else {
setFont(getFont().deriveFont(Font.PLAIN));
clearMenuSelection();
}
}
@Override
protected void applyRadioGroupRules() {
if ( radioGroupMap != null )
{
for ( ButtonGroup tempSwingRadioButtonListener : radioGroupMap.values() )
{
// -- If no RadioButtons within the radioGroup are selected, then first one in list will be selected --
if (tempSwingRadioButtonListener.getSelection() == null){
AbstractButton ab = tempSwingRadioButtonListener.getElements().nextElement();
if (ab != null) {
ab.setSelected(true);
}
}
}
}
}
protected void parallelSpeedUpActionPerformed(ActionEvent evt) {
AbstractButton button = (AbstractButton) evt.getSource();
boolean selected = button.isSelected();
String confStr = translate("message.confirm.parallel") + "\r\n";
if (selected) {
confStr += " " + translate("message.confirm.on");
} else {
confStr += " " + translate("message.confirm.off");
}
if (View.showConfirmDialog(null, confStr, translate("message.parallel"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
Configuration.parallelSpeedUp.set(selected);
} else {
button.setSelected(Configuration.parallelSpeedUp.get());
}
}
/**
* Initialize this action with the specified tree table panel.
* @param panel the graph panel to which this action applies.
*/
public ToggleMasterSlaveRelationShipsAction(final MasterSlaveRelationShipsHandler panel) {
this.panel = panel;
setupIcon("/org/jppf/ui/resources/sparkle.png");
setupNameAndTooltip(BTN_NAME + ".on");
//setupTooltip(BTN_NAME + ".on");
button = (AbstractButton) ((OptionElement) panel).findFirstWithName("/" + BTN_NAME).getUIComponent();
button.setSelected(true);
}
/**
* Initialize this action with the specified tree table panel.
* @param panel the graph panel to which this action applies.
*/
public ToggleLayoutAction(final GraphOption panel) {
super(panel);
setupIcon("/org/jppf/ui/resources/layout.gif");
setupNameAndTooltip("graph.toggle.layout.on");
button = (AbstractButton) panel.findFirstWithName("/graph.toggle.layout").getUIComponent();
button.setSelected(true);
}
/** Updates the state of those pushbuttons in the left
* vertical tool box that need to indicate the special "ambiguous"
* state marking that some of the currently selected components
* have the respective property set while some do not.
*/
private void updateButton(AbstractButton button, boolean nonEmptySelection, boolean allSelectedUnambiguous, String iconWarning, String toolTipWarning, String iconNormal, String toolTipNormal) {
button.setSelected(allSelectedUnambiguous);
if(nonEmptySelection && !allSelectedUnambiguous) {
button.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/layoutsupport/griddesigner/resources/" + iconWarning, false)); // NOI18N
button.setToolTipText(NbBundle.getMessage(GridBagCustomizer.class, "GridBagCustomizer." + toolTipWarning)); // NOI18N
} else {
button.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/layoutsupport/griddesigner/resources/" + iconNormal, false)); // NOI18N
button.setToolTipText(NbBundle.getMessage(GridBagCustomizer.class, "GridBagCustomizer." + toolTipNormal)); // NOI18N
}
}
protected void autoDeobfuscationActionPerformed(ActionEvent evt) {
AbstractButton button = (AbstractButton) evt.getSource();
boolean selected = button.isSelected();
if (View.showConfirmDialog(mainFrame.getPanel(), translate("message.confirm.autodeobfuscate") + "\r\n" + (selected ? translate("message.confirm.on") : translate("message.confirm.off")), translate("message.confirm"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
Configuration.autoDeobfuscate.set(selected);
mainFrame.getPanel().autoDeobfuscateChanged();
} else {
button.setSelected(Configuration.autoDeobfuscate.get());
}
}
static final void updateButton(AbstractButton btnResume) {
if (isSuspended()) {
int pending = Integer.getInteger("org.netbeans.io.pending", 0); // NOI18N
btnResume.setText(Bundle.MSG_Resume(pending));
btnResume.setSelected(true);
} else {
btnResume.setText(null);
btnResume.setSelected(false);
}
}
private void updateItemsSelected() {
boolean selected = isPreferencesSelected();
if (menuItem != null) {
menuItem.setSelected(selected);
}
if (popupItem != null) {
popupItem.setSelected(selected);
}
if (toolbarItems != null) {
for(AbstractButton b : toolbarItems) {
b.setSelected(selected);
}
}
}
private void myInit() {
tabManagers = new ArrayList<>();
// create the first tab
addTable(LogFilter.createDefaultTab());
// activate the selected button
for (Enumeration<AbstractButton> buttons = btGrpLogLevel.getElements(); buttons.hasMoreElements();) {
AbstractButton button = buttons.nextElement();
if (button.getActionCommand().equals(rowFilter.getLogLevel().toString())) {
button.setSelected(true);
}
}
}
/**
* Binds the selection state of the specified abstract button (which can be e.g. a {@link XCheckBox} or a {@link JCheckBoxMenuItem}) to the specified
* {@link IBoolSetting} from the specified {@link ISettingsBean}.
*
* @param button button whose state to be bounded
* @param setting setting to control the visibility of the component
* @param settings settings bean storing the setting
*/
public static void bindSelectionToSetting( final AbstractButton button, final IBoolSetting setting, final ISettingsBean settings ) {
final ISettingChangeListener scl = new ISettingChangeListener() {
@Override
public void valuesChanged( final ISettingChangeEvent event ) {
if ( event.affected( setting ) )
button.setSelected( event.get( setting ) );
}
};
addBindExecuteScl( scl, settings, setting.selfSet(), button );
}
/** Restore this component back to its original goodness. */
private void restoreState(JComponent c) {
if (c instanceof AbstractButton) {
AbstractButton b = (AbstractButton) c;
if (b.getClientProperty(WAS_SELECTED) != null) {
b.setSelected(((Boolean) b.getClientProperty(WAS_SELECTED))
.booleanValue());
b.putClientProperty(WAS_SELECTED, null);
}
if (b.getClientProperty(WAS_FOCUS_PAINTED) != null) {
b.setFocusPainted(((Boolean) b
.getClientProperty(WAS_FOCUS_PAINTED)).booleanValue());
b.putClientProperty(WAS_FOCUS_PAINTED, null);
}
}
if (c.getClientProperty(WAS_ENABLED) != null) {
c.setEnabled(((Boolean) c.getClientProperty(WAS_ENABLED))
.booleanValue());
c.putClientProperty(WAS_ENABLED, null);
}
if (c.getClientProperty(WAS_VISIBLE) != null) {
c.setVisible(((Boolean) c.getClientProperty(WAS_VISIBLE))
.booleanValue());
c.putClientProperty(WAS_VISIBLE, null);
}
for (int a = 0; a < c.getComponentCount(); a++) {
if (c.getComponent(a) instanceof JComponent) {
restoreState((JComponent) c.getComponent(a));
}
}
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
AbstractButton button = (AbstractButton) e.getSource();
button.getModel().setRollover(false);
button.setSelected(false);
}
private void copySettingsToUI() {
/**
* If one of the JSpinners is currently focused, it will keep its UI value
* even if we set its value here. Therefore, have this dialog request the focus.
*/
this.requestFocus();
//Set field values from appConfigController
String username = appConfigController.getUsername();
if (null != username) {
jTextField_username.setText(username);
}
String vehicleType = appConfigController.getVehicleType();
if (null != username) {
jTextField_vehicleType.setText(vehicleType);
}
String uniqueId = appConfigController.getUniqueId();
if (null != uniqueId) {
jTextField_uniqueId.setText(uniqueId);
}
String sic = appConfigController.getSic();
if (null != sic) {
jTextField_sic.setText(sic);
}
int port = appConfigController.getPort();
if (-1 < port) {
jSpinner_messagingPort.setValue(port);
}
int positionMessageInterval = appConfigController.getPositionMessageInterval();
if (-1 < positionMessageInterval) {
jSpinner_positionMessageInterval.setValue(positionMessageInterval);
}
int vehicleStatusMessageInterval = appConfigController.getVehicleStatusMessageInterval();
if (-1 < vehicleStatusMessageInterval) {
jSpinner_vehicleStatusMessageInterval.setValue(vehicleStatusMessageInterval);
}
double speedMultiplier = appConfigController.getSpeedMultiplier();
if (0 < speedMultiplier) {
jSpinner_speedMultiplier.setValue(speedMultiplier);
}
jCheckBox_showMessageLabels.setSelected(appConfigController.isShowMessageLabels());
jCheckBox_decorated.setSelected(appConfigController.isDecorated());
jCheckBox_showLocalTimeZone.setSelected(appConfigController.isShowLocalTimeZone());
if (appConfigController.isShowMgrs()) {
jRadioButton_mgrs.setSelected(true);
} else {
jRadioButton_lonLat.setSelected(true);
}
Enumeration<AbstractButton> headingUnitsButtons = buttonGroup_headingUnits.getElements();
while (headingUnitsButtons.hasMoreElements()) {
AbstractButton button = headingUnitsButtons.nextElement();
if (button.getActionCommand().equals(Integer.toString(appConfigController.getHeadingUnits()))) {
button.setSelected(true);
break;
}
}
jComboBox_geomessageVersion.setSelectedItem(appConfigController.getGeomessageVersion());
}