Java Code Examples for javax.swing.JToggleButton#ToggleButtonModel
The following examples show how to use
javax.swing.JToggleButton#ToggleButtonModel .
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: J2SEProjectProperties.java From netbeans with Apache License 2.0 | 5 votes |
private static JToggleButton.ToggleButtonModel createToggleButtonModel ( @NonNull final PropertyEvaluator evaluator, @NonNull final String propName, final boolean defaultValue, @NonNull final Integer[] kind) { assert evaluator != null; assert propName != null; assert kind != null && kind.length == 1; String value = evaluator.getProperty( propName ); boolean isSelected = false; if (value == null) { isSelected = defaultValue; } else { String lowercaseValue = value.toLowerCase(); if ( lowercaseValue.equals( "yes" ) || lowercaseValue.equals( "no" ) ) { // NOI18N kind[0] = BOOLEAN_KIND_YN; } else if ( lowercaseValue.equals( "on" ) || lowercaseValue.equals( "off" ) ) { // NOI18N kind[0] = BOOLEAN_KIND_ED; } else { kind[0] = BOOLEAN_KIND_TF; } if ( lowercaseValue.equals( "true") || // NOI18N lowercaseValue.equals( "yes") || // NOI18N lowercaseValue.equals( "on") ) { // NOI18N isSelected = true; } } JToggleButton.ToggleButtonModel bm = new JToggleButton.ToggleButtonModel(); bm.setSelected(isSelected ); return bm; }
Example 2
Source File: GrailsProjectProperties.java From netbeans with Apache License 2.0 | 5 votes |
public ButtonModel getDisplayBrowserModel() { if (displayBrowserModel == null) { displayBrowserModel = new JToggleButton.ToggleButtonModel(); displayBrowserModel.setSelected(config.getDisplayBrowser()); } return displayBrowserModel; }
Example 3
Source File: StayOpenPopupMenu.java From netbeans with Apache License 2.0 | 5 votes |
private static void performAction(StayOpen item, int modifiers) { JMenuItem i = item.getItem(); // Skip disabled items if (!item.getItem().isEnabled()) return; // Handle toggle items if (i.getModel() instanceof JToggleButton.ToggleButtonModel) i.setSelected(!i.isSelected()); // Invoke item action item.actionPerformed(new ActionEvent(item, ActionEvent.ACTION_PERFORMED, item.getItem().getActionCommand(), EventQueue.getMostRecentEventTime(), modifiers)); }
Example 4
Source File: StayOpenPopupMenu.java From visualvm with GNU General Public License v2.0 | 5 votes |
private static void performAction(StayOpen item, int modifiers) { JMenuItem i = item.getItem(); // Skip disabled items if (!item.getItem().isEnabled()) return; // Handle toggle items if (i.getModel() instanceof JToggleButton.ToggleButtonModel) i.setSelected(!i.isSelected()); // Invoke item action item.actionPerformed(new ActionEvent(item, ActionEvent.ACTION_PERFORMED, item.getItem().getActionCommand(), EventQueue.getMostRecentEventTime(), modifiers)); }
Example 5
Source File: AppClientProjectProperties.java From netbeans with Apache License 2.0 | 5 votes |
private static JToggleButton.ToggleButtonModel createToggleButtonModel (final PropertyEvaluator evaluator, final String propName, Integer[] kind) { assert evaluator != null && propName != null && kind != null && kind.length == 1; String value = evaluator.getProperty( propName ); boolean isSelected = false; if (value == null) { isSelected = true; } else { String lowercaseValue = value.toLowerCase(); if ( lowercaseValue.equals( "yes" ) || lowercaseValue.equals( "no" ) ) { // NOI18N kind[0] = BOOLEAN_KIND_YN; } else if ( lowercaseValue.equals( "on" ) || lowercaseValue.equals( "off" ) ) { // NOI18N kind[0] = BOOLEAN_KIND_ED; } else { kind[0] = BOOLEAN_KIND_TF; } if ( lowercaseValue.equals( "true") || // NOI18N lowercaseValue.equals( "yes") || // NOI18N lowercaseValue.equals( "on") ) { // NOI18N isSelected = true; } } JToggleButton.ToggleButtonModel bm = new JToggleButton.ToggleButtonModel(); bm.setSelected(isSelected ); return bm; }
Example 6
Source File: J2SEModularProjectProperties.java From netbeans with Apache License 2.0 | 5 votes |
private static JToggleButton.ToggleButtonModel createToggleButtonModel ( @NonNull final PropertyEvaluator evaluator, @NonNull final String propName, final boolean defaultValue, @NonNull final Integer[] kind) { assert evaluator != null; assert propName != null; assert kind != null && kind.length == 1; String value = evaluator.getProperty( propName ); boolean isSelected = false; if (value == null) { isSelected = defaultValue; } else { String lowercaseValue = value.toLowerCase(); if ( lowercaseValue.equals( "yes" ) || lowercaseValue.equals( "no" ) ) { // NOI18N kind[0] = BOOLEAN_KIND_YN; } else if ( lowercaseValue.equals( "on" ) || lowercaseValue.equals( "off" ) ) { // NOI18N kind[0] = BOOLEAN_KIND_ED; } else { kind[0] = BOOLEAN_KIND_TF; } if ( lowercaseValue.equals( "true") || // NOI18N lowercaseValue.equals( "yes") || // NOI18N lowercaseValue.equals( "on") ) { // NOI18N isSelected = true; } } JToggleButton.ToggleButtonModel bm = new JToggleButton.ToggleButtonModel(); bm.setSelected(isSelected ); return bm; }
Example 7
Source File: JFXProjectProperties.java From netbeans with Apache License 2.0 | 4 votes |
public JToggleButton.ToggleButtonModel getAllowOfflineModel() { return allowOfflineModel; }
Example 8
Source File: StoreGroupTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testBooleans() throws Exception { // Test values String[][] TEST_PROPERTIES = new String[][] { new String[] { "propTrue", "true", "false", "true" }, new String[] { "propFalse", "false", "true", "false" }, new String[] { "propYes", "yes", "no", "true" }, new String[] { "propNo", "no", "yes", "false"}, new String[] { "propOn", "on", "off", "true" }, new String[] { "propOff", "off", "on", "false" }, }; JToggleButton.ToggleButtonModel[] models = new JToggleButton.ToggleButtonModel[ TEST_PROPERTIES.length ]; JToggleButton.ToggleButtonModel[] inverseModels = new JToggleButton.ToggleButtonModel[ TEST_PROPERTIES.length ]; JToggleButton buttons[] = new JToggleButton[ TEST_PROPERTIES.length ]; JToggleButton inverseButtons[] = new JToggleButton[ TEST_PROPERTIES.length ]; // Needed objects EditableProperties ep = new EditableProperties(false); PropertyEvaluator evaluator = new PlainPropertyEvaluator( ep ); StoreGroup sg = new StoreGroup(); StoreGroup inverseSg = new StoreGroup(); // Test correct value of the model for( int i = 0; i < TEST_PROPERTIES.length; i++ ) { ep.setProperty( TEST_PROPERTIES[i][0], TEST_PROPERTIES[i][1] ); } for( int i = 0; i < TEST_PROPERTIES.length; i++ ) { models[i] = sg.createToggleButtonModel( evaluator, TEST_PROPERTIES[i][0] ); inverseModels[i] = inverseSg.createInverseToggleButtonModel( evaluator, TEST_PROPERTIES[i][0] ); buttons[i] = new JToggleButton(); buttons[i].setModel( models[i] ); inverseButtons[i] = new JToggleButton(); inverseButtons[i].setModel( inverseModels[i] ); } for( int i = 0; i < TEST_PROPERTIES.length; i++ ) { assertEquals( "Button [" + i + "] has to have correct value.", Boolean.valueOf( TEST_PROPERTIES[i][3] ).booleanValue(), buttons[i].isSelected() ); assertEquals( "InverseButton [" + i + "] has to have correct value.", !Boolean.valueOf( TEST_PROPERTIES[i][3] ).booleanValue(), inverseButtons[i].isSelected() ); } // Change value of all the buttons and test the correct property values for( int i = 0; i < TEST_PROPERTIES.length; i++ ) { buttons[i].setSelected( !buttons[i].isSelected() ); inverseButtons[i].setSelected( !inverseButtons[i].isSelected() ); } EditableProperties inverseEp = new EditableProperties(false); sg.store( ep ); inverseSg.store( inverseEp ); for( int i = 0; i < TEST_PROPERTIES.length; i++ ) { assertEquals( "Property [" + i + "] has to have correct value.", TEST_PROPERTIES[i][2], ep.getProperty( TEST_PROPERTIES[i][0] ) ); assertEquals( "Property [" + i + "] has to have correct value.", TEST_PROPERTIES[i][2], inverseEp.getProperty( TEST_PROPERTIES[i][0] ) ); } }
Example 9
Source File: JFXProjectProperties.java From netbeans with Apache License 2.0 | 4 votes |
public JToggleButton.ToggleButtonModel getDisableProxyModel() { return disableProxy; }
Example 10
Source File: JFXProjectProperties.java From netbeans with Apache License 2.0 | 4 votes |
public JToggleButton.ToggleButtonModel getAddDesktopShortcutModel() { return addDesktopShortcut; }
Example 11
Source File: JFXProjectProperties.java From netbeans with Apache License 2.0 | 4 votes |
public JToggleButton.ToggleButtonModel getInstallPermanentlyModel() { return installPermanently; }
Example 12
Source File: JFXProjectProperties.java From netbeans with Apache License 2.0 | 4 votes |
public JToggleButton.ToggleButtonModel getBackgroundUpdateCheckModel() { return backgroundUpdateCheck; }
Example 13
Source File: JFXProjectProperties.java From netbeans with Apache License 2.0 | 4 votes |
public JToggleButton.ToggleButtonModel getBinaryEncodeCSSModel() { return binaryEncodeCSS; }
Example 14
Source File: CustomizerDataSupport.java From netbeans with Apache License 2.0 | 4 votes |
/** Create a ToggleButtonModel inilialized by the specified selected parameter. */ private JToggleButton.ToggleButtonModel createToggleButtonModel(boolean selected) { JToggleButton.ToggleButtonModel model = new JToggleButton.ToggleButtonModel(); model.setSelected(selected); return model; }
Example 15
Source File: CustomizerDataSupport.java From netbeans with Apache License 2.0 | 4 votes |
/** Create a ToggleButtonModel inilialized by the specified selected parameter. */ private JToggleButton.ToggleButtonModel createToggleButtonModel(boolean selected) { JToggleButton.ToggleButtonModel model = new JToggleButton.ToggleButtonModel(); model.setSelected(selected); return model; }
Example 16
Source File: SuiteInstallerProjectProperties.java From netbeans with Apache License 2.0 | 4 votes |
public SuiteInstallerProjectProperties(Project suiteProject) { this.suiteProject = suiteProject; Preferences prefs = prefs(suiteProject); windowsModel = new JToggleButton.ToggleButtonModel(); windowsModel.setSelected(prefs.getBoolean(GENERATE_FOR_WINDOWS, Utilities.isWindows())); linuxModel = new JToggleButton.ToggleButtonModel(); linuxModel.setSelected(prefs.getBoolean(GENERATE_FOR_LINUX, Utilities.getOperatingSystem() == Utilities.OS_LINUX)); solarisModel = new JToggleButton.ToggleButtonModel(); solarisModel.setSelected(prefs.getBoolean(GENERATE_FOR_SOLARIS, Utilities.getOperatingSystem() == Utilities.OS_SOLARIS)); macModel = new JToggleButton.ToggleButtonModel(); macModel.setSelected(prefs.getBoolean(GENERATE_FOR_MAC, Utilities.isMac())); // license model: ResourceBundle rb = NbBundle.getBundle(SuiteInstallerProjectProperties.class); Enumeration<String> keys = rb.getKeys(); String prefix = "SuiteInstallerProjectProperties.license.type."; List<String> names = new ArrayList<String>(); List<String> types = new ArrayList<String>(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.startsWith(prefix)) { String type = key.substring(prefix.length()); String value = NbBundle.getMessage(SuiteInstallerProjectProperties.class, key); if (type.equals(LICENSE_TYPE_NO)) { //No License is the first option names.add(0, value); types.add(0, type); } else { names.add(value); types.add(type); } } } licenseModel = new LicenseComboBoxModel(suiteProject, names, types); String licenseFileName = prefs.get(LICENSE_FILE, null); String licenseType = prefs.get(LICENSE_TYPE, null); if (licenseFileName != null) { File licenseFile = new File(licenseFileName); if (!licenseFile.isAbsolute()) { licenseFile = PropertyUtils.resolveFile(FileUtil.toFile(suiteProject.getProjectDirectory()), licenseFileName); } licenseModel.getNames().add(licenseFile.getAbsolutePath()); licenseModel.getTypes().add(LICENSE_TYPE_FILE); String name = licenseModel.getNames().get(licenseModel.getNames().size() - 1); licenseModel.setSelectedItem(name); } else if (licenseType != null) { int index = licenseModel.getTypes().indexOf(licenseType); if (index != -1) { licenseModel.setSelectedItem(licenseModel.getNames().get(index)); } } }
Example 17
Source File: J2SECustomPropertySaverTest.java From netbeans with Apache License 2.0 | 4 votes |
public JToggleButton.ToggleButtonModel getModel2() { return model2; }
Example 18
Source File: J2SECustomPropertySaverTest.java From netbeans with Apache License 2.0 | 4 votes |
public JToggleButton.ToggleButtonModel getModel1() { return model1; }
Example 19
Source File: StoreGroup.java From netbeans with Apache License 2.0 | 2 votes |
/** Creates toggle button model representing a boolean in the StoreGroup. <BR> * In case the value is one of "true", "yes" "on" the button model * will be "selected". If the property does not exist or is set * to some other value the result of isPressed will be false.<BR> * Call to the store() method stores the model in appropriate form * e.g "true/false", "yes/no", "on/off".<BR> * Method will throw <CODE>IllegalArgumentException</CODE> if you try to get more * than one model for one property. * @param evaluator The PropertyEvaluator to be used to evaluate given * property * @param propertyName Name of the ANT property * @return ButtonModel representing the value */ public final JToggleButton.ToggleButtonModel createToggleButtonModel( PropertyEvaluator evaluator, String propertyName ) { return createBooleanButtonModel( evaluator, propertyName, false ); }
Example 20
Source File: StoreGroup.java From netbeans with Apache License 2.0 | 2 votes |
/** Creates toggle button model representing a boolean in the StoreGroup. <BR> * In case the value is one of "true", "yes" "on" the button model * will NOT be "selected". If the property does not exist or is set * to some other value the result of isPressed will be true.<BR> * Call to the store() method stores the model in appropriate form * e.g "true/false", "yes/no", "on/off".<BR> * Method will throw <CODE>IllegalArgumentException</CODE> if you try to get more * than one model for one property. * @param evaluator The PropertyEvaluator to be used to evaluate given * property * @param propertyName Name of the ANT property * @return ButtonModel representing the value */ public final JToggleButton.ToggleButtonModel createInverseToggleButtonModel( PropertyEvaluator evaluator, String propertyName ) { return createBooleanButtonModel( evaluator, propertyName, true ); }