Java Code Examples for javax.swing.AbstractButton#addItemListener()
The following examples show how to use
javax.swing.AbstractButton#addItemListener() .
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: SearchPatternController.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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()); } }); }
Example 2
Source File: SwingUtil.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
public static void addModalTooltip(AbstractButton button, String on, String off) { button.setToolTipText(button.isSelected() ? on : off); button.addItemListener(l -> button.setToolTipText(button.isSelected() ? on : off)); }
Example 3
Source File: ToolButtonFactory.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private static void configure(AbstractButton button) { RolloverButtonEventListener l = new RolloverButtonEventListener(); button.addMouseListener(l); button.addItemListener(l); if (button.getAction() != null) { if (button.getIcon() != null) { button.putClientProperty("hideActionText", Boolean.TRUE); } Object largeIcon = button.getAction().getValue("_largeIcon"); if (largeIcon instanceof Icon) { button.setIcon((Icon) largeIcon); } } Icon icon = button.getIcon(); int minWidth = BUTTON_MIN_SIZE; int minHeight = BUTTON_MIN_SIZE; if (icon != null) { button.setText(null); minWidth = Math.max(icon.getIconWidth(), BUTTON_MIN_SIZE); minHeight = Math.max(icon.getIconHeight(), BUTTON_MIN_SIZE); if (icon instanceof ImageIcon) { button.setRolloverIcon(createRolloverIcon((ImageIcon) icon)); } } else { button.setText("[?]"); } final int space = 3; Dimension prefSize = new Dimension(minWidth + space, minHeight + space); Dimension minSize = new Dimension(minWidth, minHeight); Dimension maxSize = new Dimension(minWidth + space, minHeight + space); button.setPreferredSize(prefSize); button.setMaximumSize(maxSize); button.setMinimumSize(minSize); }
Example 4
Source File: AttributeFilters.java From ghidra with Apache License 2.0 | 4 votes |
/** * * @param precludedNames keys that will not be considered for filters * @param elements elements that will be considered for filters * @param maxFactor controls the threshold for filter creation * @param buttonSupplier provides toolkit controls for the filters * @param paintFunction provides a way to individually color the control buttons */ private AttributeFilters(Collection<String> precludedNames, Set<? extends Attributed> elements, double maxFactor, Supplier<AbstractButton> buttonSupplier, Function<String, Paint> paintFunction) { // count up the unique attribute values (skipping the 'precluded names' we know we don't want) for (Attributed element : elements) { Map<String, String> attributeMap = new HashMap<>(element.getAttributeMap()); for (Map.Entry<String, String> entry : attributeMap.entrySet()) { if (!precludedNames.contains(entry.getKey())) { multiset.add(entry.getValue()); } } } if (maxFactor == 0) { maxFactor = .01; } double threshold = Math.max(2, elements.size() * maxFactor); // accept the values with cardinality above the max of 2 and maxFactor times the of the number elements. multiset.removeIf(s -> multiset.count(s) < threshold); // create a button for every element that was retained multiset.elementSet(); for (String key : multiset.elementSet()) { AbstractButton button = buttonSupplier.get(); button.setForeground((Color) paintFunction.apply(key)); button.setText(key); button.addItemListener(item -> { if (item.getStateChange() == ItemEvent.SELECTED) { selectedTexts.add(button.getText()); fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, this.selectedTexts, ItemEvent.SELECTED)); } else if (item.getStateChange() == ItemEvent.DESELECTED) { selectedTexts.remove(button.getText()); fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, this.selectedTexts, ItemEvent.DESELECTED)); } }); buttons.add(button); } }