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; }
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); }
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); }
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; }
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()); } }
private void go() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); ButtonModel model = new DefaultButtonModel(); JCheckBox check = new JCheckBox("a bit broken"); check.setModel(model); panel = new JPanel(new BorderLayout()); panel.add(new JTextField("Press Tab (twice?)"), BorderLayout.NORTH); panel.add(check); contentPane.add(panel); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); }
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; } }); }
PlasticComboBoxButton(JComboBox comboBox, Icon comboIcon, boolean iconOnly, CellRendererPane rendererPane, JList listBox) /* 36: */ { /* 37: 80 */ super(""); /* 38: 81 */ setModel(new DefaultButtonModel() /* 39: */ { /* 40: */ public void setArmed(boolean armed) /* 41: */ { /* 42: 83 */ super.setArmed((isPressed()) || (armed)); /* 43: */ } /* 44: 85 */ }); /* 45: 86 */ this.comboBox = comboBox; /* 46: 87 */ this.comboIcon = comboIcon; /* 47: 88 */ this.iconOnly = iconOnly; /* 48: 89 */ this.rendererPane = rendererPane; /* 49: 90 */ this.listBox = listBox; /* 50: 91 */ setEnabled(comboBox.isEnabled()); /* 51: 92 */ setFocusable(false); /* 52: 93 */ setRequestFocusEnabled(comboBox.isEnabled()); /* 53: 94 */ setBorder(UIManager.getBorder("ComboBox.arrowButtonBorder")); /* 54: 95 */ setMargin(new Insets(0, 2, 0, 2)); /* 55: 96 */ this.borderPaintsFocus = UIManager.getBoolean("ComboBox.borderPaintsFocus"); /* 56: */ }
public Result testConstructor() { InstrumentedUILog.clear(); DefaultButtonModel dbm = new InstrumentedButtonModel(); Util.waitQueueEventsProcess(); if (!InstrumentedUILog.equals(new Object[][] { /* 1 */{ "ButtonModel.setEnabled", "true" }, /* 2 */{ "ButtonModel.isEnabled" }, /* 3 */{ "ButtonModel.fireStateChanged" }, }) && !InstrumentedUILog.equals(new Object[0][0])) { InstrumentedUILog.printLog(); return failed("expected constructor to call another sequence of methods"); } return passed(); }
public void init() { // create objects ButtonModel model = new DefaultButtonModel(); JButton button = new JButton(this); button.setModel(model); button.setText(null); // store objects putValue(BUTTON, button); putValue(MODEL, model); putValue(ITEM, new JMenuItem(this)); // add listener and init text Status.LANGUAGE.addListener(new StatusListener() { @Override public void statusChanged(Status status, Object newValue) { // language changed. update action values and hide text updateText(); } }); updateText(); }
@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); }
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); }
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."); } }
public JButtonPad(String text, Icon icon) { // Create the model this.setCursor(new Cursor(Cursor.HAND_CURSOR)); setModel(new DefaultButtonModel()); // initialize init(text, icon); }
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() { @Override public void itemStateChanged(ItemEvent e) { prefs.putBoolean(button.getName() + ".selected", button.isSelected()); } }); }
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 Color selectedColor = JColorChooser.showDialog(ownerWindow == null ? Main.getApplicationFrame() : ownerWindow, String.format(UiUtils.BUNDLE.getString("ColorChoosingButton.dialogTitle"), getText()), value); if (selectedColor!=null) { setValue(selectedColor); lastResultOk = true; } else { lastResultOk = false; } super.fireActionPerformed(e); } }); setValue(Color.BLACK); }
public ColorChooserButton(@Nullable final DialogProvider dialogProvider) { super(); final ColorChooserButton theInstance = this; this.setModel(new DefaultButtonModel() { private static final long serialVersionUID = 3109256773218160485L; @Override protected void fireActionPerformed(ActionEvent e) { final PropertyEditor editor = PropertyEditorManager.findEditor(Color.class); if (editor == null) { LOGGER.error("Can't find registered color editor"); if (dialogProvider != null) dialogProvider.msgError(null, "Can't find color editor! unexpected state! Contact developer!"); return; } editor.setValue(value); final Color selectedColor = ColorChooser.chooseColor(theInstance, String.format(BUNDLE.getString("ColorChoosingButton.dialogTitle"), getText()), getValue()); if (selectedColor != null) { setValue(selectedColor); lastResultOk = true; } else { lastResultOk = false; } super.fireActionPerformed(e); } }); setValue(Color.BLACK); }
public ColorChooserButton() { super(); this.setModel(new DefaultButtonModel() { private static final long serialVersionUID = 3109256773218160485L; @Override protected void fireActionPerformed(ActionEvent e) { final PropertyEditor editor = PropertyEditorManager.findEditor(Color.class); if (editor == null) { LOGGER.error("Can't find registered color editor"); NbUtils.msgError(null, "Can't find color editor! unexpected state! Contact developer!"); return; } editor.setValue(value); final DialogDescriptor descriptor = new DialogDescriptor( editor.getCustomEditor(), String.format(java.util.ResourceBundle.getBundle("com/igormaznitsa/nbmindmap/i18n/Bundle").getString("ColorChoosingButton.dialogTitle"), getText()) ); DialogDisplayer.getDefault().createDialog(descriptor).setVisible(true); if (descriptor.getValue() == DialogDescriptor.OK_OPTION) { setValue((Color) editor.getValue()); lastResultOk = true; } else { lastResultOk = false; } super.fireActionPerformed(e); } }); setValue(Color.BLACK); }
/** * Creates a custom {@link ButtonModel} that forces the button to be in the pressed state if the corresponding * combo boxe's poup is showing. */ private ButtonModel createButtonModel() { return new DefaultButtonModel() { @Override public boolean isPressed() { return super.isPressed() || isPopupVisible(comboBox); } }; }
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()); } }); }
public JButton createButton(ImageIcon enabled, ImageIcon disabled, ImageIcon pressed) { JButton button = new JButton() { @Override public void paintComponent(Graphics g) { if (((DefaultButtonModel) getModel()).isPressed()) { Graphics2D g2d = (Graphics2D) g; GradientPaint gp = new GradientPaint(0, -1, new Color(0x1e1e1e), 0, getHeight() - 1, new Color(0x272727)); g2d.setPaint(gp); g2d.fillRect(0, 0, getWidth(), getHeight()); } super.paintComponent(g); } }; button.setIcon(enabled); button.setDisabledIcon(disabled); button.setPressedIcon(pressed); button.setContentAreaFilled(false); button.setFocusPainted(false); button.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, new Color(0x2d2d2d))); button.setHorizontalAlignment(SwingConstants.CENTER); button.setVerticalAlignment(SwingConstants.CENTER); button.setMinimumSize(new Dimension(MINI_BUTTON_WIDTH, MINI_BUTTON_HEIGHT)); button.setMaximumSize(new Dimension(MINI_BUTTON_WIDTH, MINI_BUTTON_HEIGHT)); button.setPreferredSize(new Dimension(MINI_BUTTON_WIDTH, MINI_BUTTON_HEIGHT)); return button; }
public Result testGetChangeListeners() { DefaultButtonModel dbm = new DefaultButtonModel() { }; if (dbm.getChangeListeners() == dbm.getChangeListeners()) { return failed("expected two calls on getChangeListeners() return different values"); } return passed(); }
public Result testStaticFields() { if (DefaultButtonModel.ARMED != 1 || DefaultButtonModel.ENABLED != 8 || DefaultButtonModel.PRESSED != 4 || DefaultButtonModel.ROLLOVER != 16 || DefaultButtonModel.SELECTED != 2) { return failed("static fields have wrong values"); } return passed(); }
public MPieMenuButton(final String text) { super(); setBorderPainted(false); // setRolloverEnabled(true); path = new Arc2D.Double(); setUI(new MPieMenuButtonUI()); setModel(new DefaultButtonModel()); init(text, null); setLayout(new PieButtonMenuLayout()); }
public MPieMenuButton(final Icon icon) { super(); setBorderPainted(false); setRolloverEnabled(true); path = new Arc2D.Double(); setUI(new MPieMenuButtonUI()); setModel(new DefaultButtonModel()); init(null, icon); }
/** * Simple constructor. * * @param b * Associated component. */ protected SubstanceScrollBarUI(JComponent b) { super(); this.thumbModel = new DefaultButtonModel(); this.thumbModel.setArmed(false); this.thumbModel.setSelected(false); this.thumbModel.setPressed(false); this.thumbModel.setRollover(false); b.setOpaque(false); }
static DefaultButtonModelBuilder fromField(Instance instance, String field, Heap heap) { Object model = instance.getValueOfField(field); if (!(model instanceof Instance)) return null; if (!DetailsUtils.isSubclassOf((Instance)model, DefaultButtonModel.class.getName())) return null; return new DefaultButtonModelBuilder((Instance)model, heap); }
protected DefaultButtonModel createInstanceImpl() { return new DefaultButtonModel(); }