类javax.swing.DefaultButtonModel源码实例Demo

下面列出了怎么用javax.swing.DefaultButtonModel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netbeans   文件: DocumentSwitcherTable.java
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;
}
 
源代码2 项目: netbeans   文件: MnemonicsTest.java
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());
    }
}
 
源代码3 项目: netbeans   文件: DropdownButton.java
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);
}
 
源代码4 项目: netbeans   文件: DropdownButton.java
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);
}
 
源代码5 项目: netbeans   文件: ProfilerPopup.java
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;
}
 
源代码6 项目: whyline   文件: WhylineButton.java
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; }
	});
	
}
 
源代码7 项目: visualvm   文件: DropdownButton.java
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);
}
 
源代码8 项目: visualvm   文件: DropdownButton.java
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);
}
 
源代码9 项目: visualvm   文件: ProfilerPopup.java
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;
}
 
源代码10 项目: dragonwell8_jdk   文件: bug7189299.java
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.");
    }
}
 
源代码11 项目: TencentKona-8   文件: bug7189299.java
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.");
    }
}
 
源代码12 项目: jdk8u60   文件: bug7189299.java
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.");
    }
}
 
源代码13 项目: openjdk-jdk8u   文件: bug7189299.java
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.");
    }
}
 
源代码14 项目: netbeans   文件: CustomizerLibraries.java
@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);
}
 
源代码15 项目: netbeans   文件: ButtonBuilders.java
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);
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: bug7189299.java
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.");
    }
}
 
源代码17 项目: openjdk-jdk9   文件: bug7189299.java
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.");
    }
}
 
源代码18 项目: jdk8u-jdk   文件: bug7189299.java
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.");
    }
}
 
源代码19 项目: hottub   文件: bug7189299.java
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.");
    }
}
 
源代码20 项目: openjdk-8-source   文件: bug7189299.java
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.");
    }
}
 
源代码21 项目: visualvm   文件: ButtonBuilders.java
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);
}
 
源代码22 项目: visualvm   文件: DisplayAreaSupport.java
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);
}
 
源代码23 项目: openjdk-8   文件: bug7189299.java
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.");
    }
}
 
源代码24 项目: jdk8u_jdk   文件: bug7189299.java
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.");
    }
}
 
源代码25 项目: netbeans-mmd-plugin   文件: ColorChooserButton.java
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);
}
 
源代码26 项目: netbeans-mmd-plugin   文件: ColorChooserButton.java
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);
}
 
源代码27 项目: netbeans-mmd-plugin   文件: ColorChooserButton.java
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);
}
 
源代码28 项目: jdk8u-jdk   文件: bug7189299.java
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.");
    }
}
 
源代码29 项目: jdk8u-dev-jdk   文件: bug7189299.java
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.");
    }
}
 
源代码30 项目: CodenameOne   文件: UserPreferences.java
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());
    }
  });
}
 
 类所在包
 同包方法