Java Code Examples for java.util.prefs.Preferences#putBoolean()

The following examples show how to use java.util.prefs.Preferences#putBoolean() . 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: ImportAnalysisTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testAddImport7() throws IOException {
    JavaSource src = getJavaSource(testFile);
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.putBoolean("importInnerClasses", true);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree node = (MethodTree) clazz.getMembers().get(0);
            BlockTree body = node.getBody();
            List<StatementTree> stats = new ArrayList<StatementTree>();
            for (StatementTree st : body.getStatements()) {
                stats.add(st);
            }
            TypeElement list = workingCopy.getElements().getTypeElement("java.util.Map.Entry");
            stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "entry", make.QualIdent(list), null));
            workingCopy.rewrite(body, make.Block(stats, false));
        }
    };
    src.runModificationTask(task).commit();
    preferences.remove("importInnerClasses");
    assertFiles("testAddImport6.pass"); //the same as testAddImport6, so using only one golden file
}
 
Example 2
Source File: Model.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void setFoldingOptions (
    boolean showCodeFolding,
    boolean foldImports,
    boolean foldInitialComent,
    boolean foldInnerClasses,
    boolean foldJavaDoc,
    boolean foldMethods,
    boolean foldTags
) {
    Collection<String> mimeTypes = new ArrayList<String>(EditorSettings.getDefault().getAllMimeTypes());
    mimeTypes.add("");
    for(String mimeType : mimeTypes) {
        Preferences prefs = MimeLookup.getLookup(mimeType).lookup(Preferences.class);
        
        prefs.putBoolean(SimpleValueNames.CODE_FOLDING_ENABLE, Boolean.valueOf(showCodeFolding));
        prefs.putBoolean("code-folding-collapse-import", foldImports); //NOI18N
        prefs.putBoolean("code-folding-collapse-initial-comment", foldInitialComent); //NOI18N
        prefs.putBoolean("code-folding-collapse-innerclass", foldInnerClasses); //NOI18N
        prefs.putBoolean("code-folding-collapse-javadoc", foldJavaDoc); //NOI18N
        prefs.putBoolean("code-folding-collapse-method", foldMethods); //NOI18N
        prefs.putBoolean("code-folding-collapse-tags", foldTags); //NOI18N
    }
}
 
Example 3
Source File: MinifyProperty.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
public void store() {
        Preferences prefs = NbPreferences.forModule(DummyCorePreference.class);
//        prefs.put("separatorJS", separatorJS != null ? separatorJS.toString() : null);
//        prefs.put("separatorHTML", separatorHTML != null ? separatorHTML.toString() : null);
//        prefs.put("separatorXML", separatorXML != null ? separatorXML.toString() : null);
//        prefs.put("separatorJSON", separatorJSON != null ? separatorJSON.toString() : null);

        Class<?> clazz = this.getClass();

        for (Field field : clazz.getDeclaredFields()) {
            try {
                if (field.getType() == boolean.class) {
                    prefs.putBoolean(field.getName(), field.getBoolean(this));
                } else if (field.getType() == String.class) {
                    prefs.put(field.getName(), (String) field.get(this));
                } else if (field.getType() == int.class) {
                    prefs.putInt(field.getName(), field.getInt(this));
                }
            } catch (IllegalArgumentException | IllegalAccessException ex) {
                Exceptions.printStackTrace(ex);
            }

        }

    }
 
Example 4
Source File: ProxyOptionsPanelController.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void applyChanges() {
    if (isValid()) {
        pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);

        if (isChanged()) {
            pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);

            final Preferences prefs = NbPreferences.forModule(ProxyPreferenceKeys.class);
            final ProxyOptionsPanel proxyOptionsPanel = getPanel();

            prefs.putBoolean(ProxyPreferenceKeys.USE_DEFAULTS, proxyOptionsPanel.getUseDefaultSettings());
            prefs.put(ProxyPreferenceKeys.DEFAULT, proxyOptionsPanel.getDefaultProxy());
            prefs.put(ProxyPreferenceKeys.ADDITIONAL, proxyOptionsPanel.getAdditionalProxies());
            prefs.put(ProxyPreferenceKeys.BYPASS, proxyOptionsPanel.getBypassProxyHosts());

            // TODO: remove this, make ProxyUtilities listen to preferences instead
            ProxyUtilities.setProxySelector(new ConstellationHttpProxySelector());
        }
    }
}
 
Example 5
Source File: FilterRepository.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void save() throws IOException {
    try {
        Preferences prefs = NbPreferences.forModule( FilterRepository.class );
        prefs = prefs.node( "Filters" ); //NOI18N
        prefs.clear();
        prefs.putBoolean( "firstTimeStart", false ); //NOI18N
        prefs.putBoolean( "firstTimeStartWithIssue", false ); //NOI18N

        prefs.putInt( "count", filters.size() ); //NOI18N
        prefs.putInt( "active", active ); //NOI18N
        for( int i=0; i<filters.size(); i++ ) {
            TaskFilter filter = filters.get( i );
            filter.save( prefs, "Filter_" + i ); //NOI18N
        }
    } catch( BackingStoreException bsE ) {
        IOException ioE = new IOException( "Cannot save filter repository" ); //NOI18N
        ioE.initCause( bsE );
        throw ioE;
    }
}
 
Example 6
Source File: FiltersManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void removeNotify() {
    //remember filter settings
    if( null != filterStates ) {
        Preferences prefs = getPreferences();
        for( String filterName : filterStates.keySet() ) {
            prefs.putBoolean( filterName, filterStates.get( filterName ) );
        }
    }
    super.removeNotify();
}
 
Example 7
Source File: Main.java    From ProtocolAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Save settings for sampler and flank detector to registry/config file
 */
public void saveAudioPreferences() {
	Preferences p = Preferences.userNodeForPackage(this.getClass());
	p.putInt("SourceNumber", m_AudioSampler.getSource());
	p.putBoolean("Mono", m_AudioSampler.getChannel() == Channel.MONO);
	p.putBoolean("LeftChannel", m_AudioSampler.getChannel() == Channel.LEFT ? true : false);
	p.putInt("FlankSwing", m_FlankDetector.getFlankSwing());
	p.putInt("FlankLength", m_FlankDetector.getFlankLength());
	p.putInt("FlankHoldoff", m_FlankDetector.getFlankHoldoff());
	p.putInt("PulseWidthCompensation", m_FlankDetector.getPulseWidthCompensation());
	p.putBoolean("UseFilter", m_Filter.isActive());
}
 
Example 8
Source File: AlwaysEnabledAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void togglePreferencesSelected() {
    String key = (String) getValue(PREFERENCES_KEY);
    Preferences prefs = prefs();
    if (key != null && prefs != null) {
        Object defaultValue = getValue(PREFERENCES_DEFAULT);
        prefs.putBoolean(key, !prefs.getBoolean(key, defaultValue instanceof Boolean ? (Boolean) defaultValue : false));
    }
}
 
Example 9
Source File: MessageDialogs.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkDisabled(String disableKey)
{
    if (disableKey == null)
        return false;
    Preferences prefs =
        PrefUtil.createNode("net/sf/gogui/gui/messagedialogs/disabled");
    boolean permanentlyDisabled = prefs.getBoolean(disableKey, false);
    if (permanentlyDisabled)
        return true;
    // Make sure this entry exists (right now these settings can only
    // be directly edited in the backing store)
    prefs.putBoolean(disableKey, permanentlyDisabled);
    return m_disabled.contains(disableKey);
}
 
Example 10
Source File: FmtSpaces.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void storeTo(Preferences preferences) {
    for (Item item : getAllItems()) {
        boolean df = provider.getDefaultAsBoolean(item.id);
        if (df == item.value)
            preferences.remove(item.id);
        else
            preferences.putBoolean(item.id, item.value);
    }
}
 
Example 11
Source File: FileSystemPreferencesFactory.java    From java-ocr-api with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws BackingStoreException {
    Preferences prefs = new FileSystemPreferencesFactory().userRoot().node(String.class.getName());
    String name = prefs.get("NAME", null);
    int age = prefs.getInt("AGE", -1);
    boolean isMale = prefs.getBoolean("MALE", false);

    System.out.println(name + "/" + age + "/" + isMale);

    prefs.put("NAME", "Homer");
    prefs.putInt("AGE", 45);
    prefs.putBoolean("MALE", true);
    prefs.flush();

    System.out.println("Done.");
}
 
Example 12
Source File: ImportAnalysisTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAddImport6() throws IOException {
    JavaSource src = getJavaSource(testFile);
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.putBoolean("importInnerClasses", true);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree node = (MethodTree) clazz.getMembers().get(0);
            BlockTree body = node.getBody();
            List<StatementTree> stats = new ArrayList<StatementTree>();
            for (StatementTree st : body.getStatements()) {
                stats.add(st);
            }
            TypeElement list = workingCopy.getElements().getTypeElement("java.util.Map.Entry");
            Types types = workingCopy.getTypes();
            stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "entry", make.Type(types.erasure(list.asType())), null));
            workingCopy.rewrite(body, make.Block(stats, false));
        }
    };
    src.runModificationTask(task).commit();
    preferences.remove("importInnerClasses");
    assertFiles("testAddImport6.pass");
}
 
Example 13
Source File: JsonPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Allow comments in JSON files.
 * @param supported the value to set
 */
public void setCommentSupported(final boolean supported) {
    final Preferences prefs = getPreferences();
    if (supported) {
        prefs.putBoolean(PREF_JSON_COMMENTS, supported);
    } else {
        prefs.remove(PREF_JSON_COMMENTS);
    }
}
 
Example 14
Source File: ErrorFixesFakeHint.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static void setCreateLocalVariableInPlace(Preferences p, boolean v) {
    p.putBoolean(LOCAL_VARIABLES_INPLACE, v);
}
 
Example 15
Source File: AccidentalAssignmentHint.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setCheckAssignmentsInWhileStatements(Preferences preferences, boolean isEnabled) {
    preferences.putBoolean(CHECK_ASSIGNMENTS_IN_WHILE_STATEMENTS, isEnabled);
}
 
Example 16
Source File: ErrorFixesFakeHint.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static void setUseLogger(Preferences p, boolean v) {
    p.putBoolean(SURROUND_USE_JAVA_LOGGER, v);
}
 
Example 17
Source File: UnusedVariableHint.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setCheckUnusedFormalParameters(Preferences preferences, boolean isEnabled) {
    preferences.putBoolean(CHECK_UNUSED_FORMAL_PARAMETERS, isEnabled);
}
 
Example 18
Source File: TestNbPreferencesThreading.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testThreading() throws Exception {
    Preferences prefs = org.openide.util.NbPreferences.forModule(NbPreferences.class);
    final boolean [] fileEventReceived = new boolean[] { false };
    final boolean [] fileEventBlock1 = new boolean[] { false };
    final boolean [] fileEventBlock2 = new boolean[] { true };
    
    PropertiesStorage.TEST_FILE_EVENT = new Runnable() {
        @Override
        public void run() {
            synchronized (fileEventReceived) {
                fileEventReceived[0] = true;
                fileEventReceived.notifyAll();
            }
            try {
                synchronized (fileEventBlock1) {
                    if (!fileEventBlock1[0]) {
                        fileEventBlock1.wait();
                    }
                }
                synchronized (fileEventBlock2) {
                    if (fileEventBlock2[0]) {
                        fileEventBlock2.wait();
                    }
                }
            } catch (InterruptedException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    };
    prefs.putBoolean("Guest", false);
    assertFalse(prefs.getBoolean("Guest", true));
    synchronized (fileEventReceived) {
        if (!fileEventReceived[0]) {
            fileEventReceived.wait();
        }
        fileEventReceived[0] = false;
    }
    prefs.putBoolean("Guest", true);
    
    assertTrue(prefs.getBoolean("Guest", false));
    
    { // Let process the file event
        synchronized (fileEventBlock1) {
            fileEventBlock1[0] = true;
            fileEventBlock1.notifyAll();
        }
        synchronized (fileEventBlock2) {
            fileEventBlock2[0] = false;
            fileEventBlock2.notifyAll();
        }
        synchronized (fileEventReceived) {
            if (!fileEventReceived[0]) {
                fileEventReceived.wait();
            }
        }
    } // when done, do the same test again
    
    assertTrue(prefs.getBoolean("Guest", false));
}
 
Example 19
Source File: Configuration.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setEnabled( Preferences p, boolean value ) {
    p.putBoolean(ENABLED_KEY, value);
}
 
Example 20
Source File: BooleanPluginProperty.java    From pentaho-kettle with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see at.aschauer.commons.pentaho.plugin.PluginProperty#saveToPreferences(java.util.prefs.Preferences)
 */
public void saveToPreferences( final Preferences node ) {
  node.putBoolean( this.getKey(), this.getValue() );
}