Java Code Examples for javax.swing.DefaultButtonModel

The following examples show how to use javax.swing.DefaultButtonModel. These examples are extracted from open source projects. 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 Project: netbeans   Source File: DocumentSwitcherTable.java    License: Apache License 2.0 6 votes vote down vote up
private JButton createCloseButton() {
    JButton res = CloseButtonFactory.createBigCloseButton();
    res.setModel( new DefaultButtonModel() {
        @Override
        public boolean isRollover() {
            return inCloseButtonRect;
        }
    });
    //allow third party look and feels to provide their own icons
    Icon defaultIcon = UIManager.getIcon( "nb.popupswitcher.closebutton.defaultIcon" ); //NOI18N
    if( null != defaultIcon )
        res.setIcon( defaultIcon );
    Icon rolloverIcon = UIManager.getIcon( "nb.popupswitcher.closebutton.rolloverIcon" ); //NOI18N
    if( null != rolloverIcon )
        res.setRolloverIcon( rolloverIcon );
    return res;
}
 
Example 2
Source Project: netbeans   Source File: MnemonicsTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testSetLocalizedTextWithModel() throws Exception {
    ButtonModel m = new DefaultButtonModel();
    JButton b = new JButton();
    Mnemonics.setLocalizedText(b, "Hello &There");
    assertEquals("Hello There", b.getText());
    if( Mnemonics.isAquaLF() ) {
        assertEquals(0, b.getMnemonic());
        assertEquals(-1, b.getDisplayedMnemonicIndex());
    } else {
        assertEquals('T', b.getMnemonic());
        assertEquals(6, b.getDisplayedMnemonicIndex());
    }
    b.setModel(m);
    assertEquals("Hello There", b.getText());
    if( Mnemonics.isAquaLF() ) {
        assertEquals(0, b.getMnemonic());
        assertEquals(-1, b.getDisplayedMnemonicIndex());
    } else {
        assertEquals('T', b.getMnemonic());
        assertEquals(6, b.getDisplayedMnemonicIndex());
    }
}
 
Example 3
Source Project: netbeans   Source File: DropdownButton.java    License: Apache License 2.0 6 votes vote down vote up
Button(String text, Icon icon) {
    super(text, icon);
    
    // See GenericToolbar.addImpl()
    putClientProperty("MetalListener", new Object()); // NOI18N
    
    if (UIUtils.isAquaLookAndFeel())
        putClientProperty("JComponent.sizeVariant", "regular"); // NOI18N
    
    setModel(new DefaultButtonModel() {
        public boolean isRollover() {
            return super.isRollover() || (isEnabled() && (popup != null && popup.getModel().isRollover()));
        }
        public boolean isPressed() {
            return pushed || super.isPressed();
        }
        public boolean isArmed() {
            return pushed || super.isArmed();
        }
    });
    
    setHorizontalAlignment(LEADING);
    setDefaultCapable(false);
}
 
Example 4
Source Project: netbeans   Source File: DropdownButton.java    License: Apache License 2.0 6 votes vote down vote up
Popup() {
    super(" "); // NOI18N
    
    // See GenericToolbar.addImpl()
    putClientProperty("MetalListener", new Object()); // NOI18N
    
    setModel(new DefaultButtonModel() {
        public boolean isRollover() {
            return super.isRollover() || pushed;
        }
    });
    
    setHorizontalAlignment(LEADING);
    setDefaultCapable(false);
    
    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false), NO_ACTION);
    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true), NO_ACTION);
}
 
Example 5
Source Project: netbeans   Source File: ProfilerPopup.java    License: 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 6
Source Project: whyline   Source File: WhylineButton.java    License: MIT License 6 votes vote down vote up
public WhylineButton(Action abstractAction, String tooltip) {
	
	super(abstractAction);

	setFont(UI.getMediumFont());
	setFocusable(false);
	setOpaque(false);
	setToolTipText(tooltip);
	setContentAreaFilled(true);
	setRolloverEnabled(true);
	
	// Hack so that toolbar buttons in MetalLookAndFeel always show their background.
	setModel(new DefaultButtonModel() {
		public boolean isRollover() { return true; }
	});
	
}
 
Example 7
Source Project: visualvm   Source File: DropdownButton.java    License: GNU General Public License v2.0 6 votes vote down vote up
Button(String text, Icon icon) {
    super(text, icon);
    
    // See GenericToolbar.addImpl()
    putClientProperty("MetalListener", new Object()); // NOI18N
    
    if (UIUtils.isAquaLookAndFeel())
        putClientProperty("JComponent.sizeVariant", "regular"); // NOI18N
    
    setModel(new DefaultButtonModel() {
        public boolean isRollover() {
            return super.isRollover() || (isEnabled() && (popup != null && popup.getModel().isRollover()));
        }
        public boolean isPressed() {
            return pushed || super.isPressed();
        }
        public boolean isArmed() {
            return pushed || super.isArmed();
        }
    });
    
    setHorizontalAlignment(LEADING);
    setDefaultCapable(false);
}
 
Example 8
Source Project: visualvm   Source File: DropdownButton.java    License: GNU General Public License v2.0 6 votes vote down vote up
Popup() {
    super(" "); // NOI18N
    
    // See GenericToolbar.addImpl()
    putClientProperty("MetalListener", new Object()); // NOI18N
    
    setModel(new DefaultButtonModel() {
        public boolean isRollover() {
            return super.isRollover() || pushed;
        }
    });
    
    setHorizontalAlignment(LEADING);
    setDefaultCapable(false);
    
    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false), NO_ACTION);
    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true), NO_ACTION);
}
 
Example 9
Source Project: visualvm   Source File: ProfilerPopup.java    License: GNU General Public License v2.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 10
Source Project: dragonwell8_jdk   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 11
Source Project: TencentKona-8   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 12
Source Project: jdk8u60   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 13
Source Project: openjdk-jdk8u   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 14
Source Project: netbeans   Source File: CustomizerLibraries.java    License: Apache License 2.0 5 votes vote down vote up
@Messages("CTL_AddSimple=&Add...")
public CustomizerLibraries(SingleModuleProperties props, ProjectCustomizer.Category category, @NonNull NbModuleProject p) {
    super(props, CustomizerLibraries.class, category);
    initComponents();
    if (!getProperties().isSuiteComponent()) {
        addLibrary.setVisible(false);
        Mnemonics.setLocalizedText(addDepButton, CTL_AddSimple());
    }
    refresh();
    dependencyList.setCellRenderer(CustomizerComponentFactory.getDependencyCellRenderer(false));
    javaPlatformCombo.setRenderer(JavaPlatformComponentFactory.javaPlatformListCellRenderer());
    removeTokenButton.setEnabled(false);
    wrappedJarsList.setCellRenderer(ClassPathListCellRenderer.createClassPathListRenderer(
            getProperties().getEvaluator(),
            FileUtil.toFileObject(getProperties().getProjectDirectoryFile())));
    DefaultButtonModel dummy = new DefaultButtonModel();
    EditMediator.register(
            p,
            getProperties().getHelper(),
            getProperties().getRefHelper(),
            emListComp,
            dummy,
            dummy,
            dummy,
            removeButton.getModel(),
            dummy,
            dummy,
            editButton.getModel(),
            null,
            null);
    attachListeners();
    pxml = new ProjectXMLManager(p);
}
 
Example 15
Source Project: netbeans   Source File: ButtonBuilders.java    License: Apache License 2.0 5 votes vote down vote up
protected void setupInstance(DefaultButtonModel instance) {
    super.setupInstance(instance);
    
    instance.setArmed((stateMask & DefaultButtonModel.ARMED) != 0);
    instance.setSelected((stateMask & DefaultButtonModel.SELECTED) != 0);
    instance.setEnabled((stateMask & DefaultButtonModel.ENABLED) != 0);
    instance.setPressed((stateMask & DefaultButtonModel.PRESSED) != 0);
    instance.setRollover((stateMask & DefaultButtonModel.ROLLOVER) != 0);
}
 
Example 16
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 17
Source Project: openjdk-jdk9   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 18
Source Project: jdk8u-jdk   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 19
Source Project: hottub   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 20
Source Project: openjdk-8-source   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 21
Source Project: visualvm   Source File: ButtonBuilders.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void setupInstance(DefaultButtonModel instance) {
    super.setupInstance(instance);
    
    instance.setArmed((stateMask & DefaultButtonModel.ARMED) != 0);
    instance.setSelected((stateMask & DefaultButtonModel.SELECTED) != 0);
    instance.setEnabled((stateMask & DefaultButtonModel.ENABLED) != 0);
    instance.setPressed((stateMask & DefaultButtonModel.PRESSED) != 0);
    instance.setRollover((stateMask & DefaultButtonModel.ROLLOVER) != 0);
}
 
Example 22
Source Project: visualvm   Source File: DisplayAreaSupport.java    License: GNU General Public License v2.0 5 votes vote down vote up
TabButton(String text, String description) {
    super(text);
    setModel(new DefaultButtonModel() {
        public boolean isPressed() { return false; }
    });
    setOpaque(false);
    setFocusPainted(false);
    setBorderPainted(false);
    setContentAreaFilled(false);
    setBorder(BorderFactory.createEmptyBorder(TABBUTTON_MARGIN_TOP, TABBUTTON_MARGIN_LEFT, TABBUTTON_MARGIN_BOTTOM, TABBUTTON_MARGIN_RIGHT));
    setToolTipText(description);
}
 
Example 23
Source Project: openjdk-8   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 24
Source Project: jdk8u_jdk   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 25
Source Project: netbeans-mmd-plugin   Source File: ColorChooserButton.java    License: Apache License 2.0 5 votes vote down vote up
public ColorChooserButton() {
  super();

  final ColorChooserButton theButtonInstance = this;

  this.setModel(new DefaultButtonModel() {
    private static final long serialVersionUID = 3109256773218160485L;

    @Override
    protected void fireActionPerformed(ActionEvent e) {
      final Window ownerWindow = SwingUtilities.getWindowAncestor(theButtonInstance);

      final ColorChooser colorChooser = new ColorChooser(usedColors, value);

      if (DialogProviderManager.getInstance().getDialogProvider()
              .msgOkCancel(ownerWindow == null ? Main.getApplicationFrame() : ownerWindow,
                      String.format(UiUtils.BUNDLE.getString("ColorChoosingButton.dialogTitle"),
                              getText()),
                      colorChooser.getPanel())) {
        final Color selectedColor = colorChooser.getColor();
        if (selectedColor != null) {
          setValue(selectedColor);
          lastResultOk = true;
        } else {
          lastResultOk = false;
        }

        super.fireActionPerformed(e);
      }
    }
  });

  setValue(Color.BLACK);
}
 
Example 26
Source Project: netbeans-mmd-plugin   Source File: ColorChooserButton.java    License: Apache License 2.0 5 votes vote down vote up
public ColorChooserButton(@Nullable final DialogProvider dialogProvider) {
  super();

  this.setHorizontalAlignment(SwingConstants.LEFT);

  this.setModel(new DefaultButtonModel() {
    private static final long serialVersionUID = 3109256773218160485L;

    @Override
    protected void fireActionPerformed(ActionEvent e) {
      final Window ownerWindow = SwingUtilities.getWindowAncestor(ColorChooserButton.this);

      final com.igormaznitsa.mindmap.swing.colorpicker.ColorChooser colorChooser = new com.igormaznitsa.mindmap.swing.colorpicker.ColorChooser(usedColors, value);

      final String title = String.format(BUNDLE.getString("ColorChoosingButton.dialogTitle"), getText());
      final boolean result;

      if (dialogProvider == null) {
        result = JOptionPane.showConfirmDialog(ownerWindow, colorChooser.getPanel(), title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null) == JOptionPane.OK_OPTION;
      } else {
        result = dialogProvider.msgOkCancel(ColorChooserButton.this, title, colorChooser.getPanel());
      }

      if (result) {
        setValue(colorChooser.getColor());
        lastResultOk = true;
      } else {
        lastResultOk = false;
      }

      super.fireActionPerformed(e);
    }

  });

  setValue(Color.BLACK);
}
 
Example 27
Source Project: netbeans-mmd-plugin   Source File: ColorChooserButton.java    License: Apache License 2.0 5 votes vote down vote up
public ColorChooserButton() {
  super();

  this.setModel(new DefaultButtonModel() {
    private static final long serialVersionUID = 3109256773218160485L;

    @Override
    protected void fireActionPerformed(@Nonnull final ActionEvent e) {
      final Window window = SwingUtilities.windowForComponent(ColorChooserButton.this);

      final ColorChooser colorChooser = new ColorChooser(usedColors, value);
      final DialogProvider provider = DialogProviderManager.getInstance().getDialogProvider();
      final String title = String.format(java.util.ResourceBundle.getBundle("com/igormaznitsa/nbmindmap/i18n/Bundle")
              .getString("ColorChoosingButton.dialogTitle"), getText());

      if (provider.msgOkCancel(window, title, colorChooser.getPanel())) {
        setValue(colorChooser.getColor());
        lastResultOk = true;
      } else {
        lastResultOk = false;
      }

      super.fireActionPerformed(e);
    }
  });

  setValue(Color.BLACK);
}
 
Example 28
Source Project: jdk8u-jdk   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 29
Source Project: jdk8u-dev-jdk   Source File: bug7189299.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleDefaultButtonModelListener() {
    HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
    StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit
            .getInputAttributes());
    DefaultButtonModel model = ((DefaultButtonModel) style
            .getAttribute(StyleConstants.ModelAttribute));
    ActionListener[] listeners = model.getActionListeners();
    int actionListenerNum = listeners.length;
    if (actionListenerNum != 1) {
        throw new RuntimeException(
                "Expected single ActionListener object registered with "
                + "DefaultButtonModel; found " + actionListenerNum
                + " listeners registered.");
    }

    int changeListenerNum = model.getChangeListeners().length;
    if (changeListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ChangeListener object registered "
                + "with DefaultButtonModel; found " + changeListenerNum
                + " listeners registered.");
    }
    int itemListenerNum = model.getItemListeners().length;
    if (itemListenerNum != 1) {
        throw new RuntimeException(
                "Expected at most one ItemListener object registered "
                + "with DefaultButtonModel; found " + itemListenerNum
                + " listeners registered.");
    }
}
 
Example 30
Source Project: CodenameOne   Source File: UserPreferences.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void track(final JRadioButton button) {
  final Preferences prefs = node().node("Buttons");
  boolean selected = prefs.getBoolean(button.getName() + ".selected", button
      .isSelected());
  ((DefaultButtonModel) button.getModel()).getGroup().setSelected(
      button.getModel(), selected);// .setSelected(selected);
  button.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
      prefs.putBoolean(button.getName() + ".selected", button.isSelected());
    }
  });
}