Java Code Examples for javax.swing.AbstractButton#isSelected()

The following examples show how to use javax.swing.AbstractButton#isSelected() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProfilerPopup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getDefaultComponent(Container aContainer) {
    Component c = getFirstComponent(aContainer);
    
    if (c instanceof AbstractButton) {
        ButtonModel bm = ((AbstractButton)c).getModel();
        if (bm instanceof DefaultButtonModel) {
            ButtonGroup bg = ((DefaultButtonModel)bm).getGroup();
            Enumeration<AbstractButton> en = bg == null ? null : bg.getElements();
            while (en != null && en.hasMoreElements()) {
                AbstractButton ab = en.nextElement();
                if (ab.isSelected()) return ab;
            }
        }
    }
    
    return c;
}
 
Example 2
Source File: FunctionEditor.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets an undoable edit.
 *
 * @param type may be ADD_EDIT, REMOVE_EDIT, NAME_EDIT, or EXPRESSION_EDIT 
 * @param redo the new state
 * @param redoRow the newly selected row
 * @param redoCol the newly selected column
 * @param undo the previous state
 * @param undoRow the previously selected row
 * @param undoCol the previously selected column
 * @param name the name of the edited object
 */
protected UndoableEdit getUndoableEdit(int type, Object redo, int redoRow, int redoCol, Object undo, int undoRow, int undoCol, String name) {
  if(type==EXPRESSION_EDIT) {
    ArrayList<AbstractButton> selectedButtons = new ArrayList<AbstractButton>();
    undo = new Object[] {undo, selectedButtons};
    redo = new Object[] {redo, selectedButtons};
    if(customButtons!=null) {
      for(AbstractButton b : customButtons) {
        if(b.isSelected()) {
          selectedButtons.add(b);
        }
      }
    }
  }
  return new DefaultEdit(type, redo, redoRow, redoCol, undo, undoRow, undoCol, name);
}
 
Example 3
Source File: ToggleButtonGroup.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example 4
Source File: ToggleMasterSlaveRelationShipsAction.java    From JPPF with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
  synchronized (panel) {
    final AbstractButton button = (AbstractButton) ((OptionElement) panel).findFirstWithName("/" + BTN_NAME).getUIComponent();
    final boolean selected = button.isSelected();
    panel.setShowMasterSlaveRelationShip(selected);
    setupNameAndTooltip(BTN_NAME + "." + (selected ? "on" : "off"));
  }
}
 
Example 5
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
protected void simplifyExpressionsActionPerformed(ActionEvent evt) {
    AbstractButton button = (AbstractButton) evt.getSource();
    boolean selected = button.isSelected();

    Configuration.simplifyExpressions.set(selected);
    mainFrame.getPanel().autoDeobfuscateChanged();
}
 
Example 6
Source File: ToolButtonFactory.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void setDefaultState(AbstractButton b) {
    if (b.isSelected()) {
        setSelectedState(b);
    } else {
        setNormalState(b);
    }
}
 
Example 7
Source File: AddFrame.java    From JavaMainRepo with Apache License 2.0 5 votes vote down vote up
public String getSelectedRadioButton() {
	for (Enumeration<AbstractButton> allButtons = buttonGroup.getElements(); allButtons.hasMoreElements();) {
		AbstractButton button = allButtons.nextElement();
		if (button.isSelected()) {
			return button.getText();
		}
	}
	return null;
}
 
Example 8
Source File: DemoSelectorPanel.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    AbstractButton b = (AbstractButton)c;
    if (b.isSelected()) {
        Color color = c.getBackground();
        g.setColor(Utilities.deriveColorHSB(color, 0, 0, -.20f));
        g.drawLine(x, y, x + width, y);
        g.setColor(Utilities.deriveColorHSB(color, 0, 0, -.10f));
        g.drawLine(x, y + 1, x + width, y + 1);
        g.drawLine(x, y + 2, x, y + height - 2);
        g.setColor(Utilities.deriveColorHSB(color, 0, 0, .24f));
        g.drawLine(x, y + height - 1, x + width, y + height-1);
    }
}
 
Example 9
Source File: TransparentToolBar.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void refresh(final AbstractButton b) {
    b.setBackground(UISupport.getDefaultBackground());
    boolean hovered = Boolean.TRUE.equals(b.getClientProperty(PROP_HOVERED));
    boolean filled = b.isEnabled() && (hovered || b.isSelected() || b.isFocusOwner());
    b.setOpaque(filled);
    b.setContentAreaFilled(filled);
    b.repaint();
}
 
Example 10
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
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());
    }
}
 
Example 11
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
protected void setSubLimiter(ActionEvent evt) {
    if (Main.isWorking()) {
        return;
    }

    AbstractButton button = (AbstractButton) evt.getSource();
    boolean selected = button.isSelected();
    Main.setSubLimiter(selected);
}
 
Example 12
Source File: CognizantITSSettings.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private String getSelectedButton(ButtonGroup bGroup) {
    for (Enumeration<AbstractButton> buttons = bGroup.getElements(); buttons.hasMoreElements();) {
        AbstractButton button = buttons.nextElement();
        if (button.isSelected()) {
            return button.getText();
        }
    }
    return "None";
}
 
Example 13
Source File: NbEditorToolBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void removeButtonContentAreaAndBorder(AbstractButton button) {
    boolean canRemove = true;
    if (button instanceof JToggleButton) {
        canRemove = !button.isSelected();
    }
    if (canRemove) {
        button.setContentAreaFilled(false);
        button.setBorderPainted(false);
    }
}
 
Example 14
Source File: TimeSeriesExportHelper.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static int parseLevel(ButtonGroup buttonGroup) {
    Enumeration<AbstractButton> buttonEnumeration = buttonGroup.getElements();
    while (buttonEnumeration.hasMoreElements()) {
        AbstractButton abstractButton = buttonEnumeration.nextElement();
        if (abstractButton.isSelected()) {
            String buttonText = abstractButton.getText();
            final int index = buttonText.indexOf(" (");
            if (index != -1) {
                buttonText = buttonText.substring(0, index);
            }
            return Integer.parseInt(buttonText);
        }
    }
    return-1;
}
 
Example 15
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
protected void disableDecompilationActionPerformed(ActionEvent evt) {
    AbstractButton button = (AbstractButton) evt.getSource();
    boolean selected = button.isSelected();

    Configuration.decompile.set(!selected);
    mainFrame.getPanel().disableDecompilationChanged();
}
 
Example 16
Source File: ToggleLayoutAction.java    From JPPF with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(final ActionEvent e) {
  synchronized (panel) {
    final AbstractButton button = (AbstractButton) panel.findFirstWithName("/graph.toggle.layout").getUIComponent();
    final boolean selected = button.isSelected();
    panel.setAutoLayout(selected);
    setupNameAndTooltip("graph.toggle.layout." + (selected ? "on" : "off"));
  }
}
 
Example 17
Source File: BoxTabbedPaneUI.java    From pumpernickel with MIT License 4 votes vote down vote up
protected void refreshTabStates() {
	List<Component> newTabs = new ArrayList<>();
	for (int a = 0; a < tabs.getTabCount(); a++) {
		JComponent tab = (JComponent) tabs.getTabComponentAt(a);
		if (tab == null)
			tab = getDefaultTab(a);

		TabContainer tabContainer = (TabContainer) tab
				.getClientProperty(PROPERTY_TAB_CONTAINER);
		if (tabContainer == null) {
			tabContainer = new TabContainer(tabs, a, tab);
			tab.putClientProperty(PROPERTY_TAB_CONTAINER, tabContainer);
		}

		newTabs.add(tabContainer);
		tab.putClientProperty(PROPERTY_TAB_INDEX, a);
		getStyle(tabs).formatControlRowButton(tabs, tabContainer, a);
	}

	Boolean hideSingleTab = (Boolean) tabs
			.getClientProperty(PROPERTY_HIDE_SINGLE_TAB);
	if (hideSingleTab == null)
		hideSingleTab = Boolean.FALSE;
	controlRow.setVisible(!(tabs.getTabCount() <= 1 && hideSingleTab));

	if (!(tabsContainer.getLayout() instanceof SplayedLayout)) {
		SplayedLayout l = new SplayedLayout(true) {

			@Override
			protected Collection<JComponent> getEmphasizedComponents(
					JComponent container) {
				Collection<JComponent> returnValue = super
						.getEmphasizedComponents(container);

				for (Component c : container.getComponents()) {
					if (c instanceof AbstractButton) {
						AbstractButton ab = (AbstractButton) c;
						if (ab.isSelected())
							returnValue.add(ab);
					}
				}
				return returnValue;
			}

		};
		tabsContainer.setLayout(l);
	}
	int orientation = tabs.getTabPlacement() == SwingConstants.LEFT
			|| tabs.getTabPlacement() == SwingConstants.RIGHT ? SwingConstants.VERTICAL
			: SwingConstants.HORIZONTAL;
	((SplayedLayout) tabsContainer.getLayout()).setOrientation(null,
			orientation);

	setComponents(tabsContainer, newTabs);

	tabsContainer.revalidate();
}
 
Example 18
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
protected void autoOpenLoadedSWFsActionPerformed(ActionEvent evt) {
    AbstractButton button = (AbstractButton) evt.getSource();
    boolean selected = button.isSelected();

    Configuration.autoOpenLoadedSWFs.set(selected);
}
 
Example 19
Source File: MainPanel.java    From swift-explorer with Apache License 2.0 4 votes vote down vote up
protected void onUploadDirectory() 
 {
 	List<StoredObject> sltObj = getSelectedStoredObjects() ;
 	if (sltObj != null && sltObj.size() > 1)
 		return ; // should never happen, because in such a case the menu is disable
 	StoredObject parentObject = (sltObj == null || sltObj.isEmpty()) ? (null) : (sltObj.get(0)) ;
 	
     final Container container = getSelectedContainer();
     final JFileChooser chooser = new JFileChooser();
     chooser.setMultiSelectionEnabled(false);
     chooser.setCurrentDirectory(lastFolder);
     chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY);
     
     final JPanel optionPanel = getOptionPanel ();
     chooser.setAccessory(optionPanel);
     AbstractButton overwriteCheck = setOverwriteOption (optionPanel) ;
     
     if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 
     {
         final File selectedDir = chooser.getSelectedFile();
         try 
         {
         	boolean overwriteAll = overwriteCheck.isSelected() ;
         	if (overwriteAll)
         	{
         		if (!confirm(getLocalizedString("confirm_overwrite_any_existing_files")))
         			return ;
         	}
	ops.uploadDirectory(container, parentObject, selectedDir, overwriteAll, getNewSwiftStopRequester (), callback);
	
	// We open the progress window, for it is likely that this operation
	// will take a while
          //onProgressButton () ;
} 
         catch (IOException e) 
{
	logger.error("Error occurred while uploading a directory.", e);
}
         lastFolder = chooser.getCurrentDirectory();
     }
 }
 
Example 20
Source File: AbstractDockingTest.java    From ghidra with Apache License 2.0 3 votes vote down vote up
/**
 * Ensures that the selected state of the button matches <code>selected</code>.
 * <p>
 * Note: this works for most toggle button implementations which are derived from
 * AbstractButton and relay on {@link AbstractButton#isSelected()} and
 * {@link AbstractButton#doClick()} for toggling, such as:
 * <ul>
 * 	<li>{@link JCheckBox}</li>
 *  <li>{@link JRadioButton}</li>
 *  <li>{@link EmptyBorderToggleButton}</li>
 * </ul>
 * @param button the button to select
 * @param selected true to toggle the button to selected; false for de-selected
 */
public static void setToggleButtonSelected(AbstractButton button, boolean selected) {
	boolean isSelected = button.isSelected();
	if (isSelected != selected) {
		pressButton(button);
	}
}