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

The following examples show how to use java.util.prefs.Preferences#putInt() . 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: ConfigSaver.java    From Luyten with Apache License 2.0 6 votes vote down vote up
private void saveLuytenPreferences(Preferences prefs) throws Exception {
	for (Field field : LuytenPreferences.class.getDeclaredFields()) {
		if (Modifier.isStatic(field.getModifiers()))
			continue;
		field.setAccessible(true);
		String prefId = field.getName();
		Object value = field.get(luytenPreferences);

		if (field.getType() == String.class) {
			prefs.put(prefId, (String) (value == null ? "" : value));

		} else if (field.getType() == Boolean.class || field.getType() == boolean.class) {
			prefs.putBoolean(prefId, (Boolean) (value == null ? new Boolean(false) : value));

		} else if (field.getType() == Integer.class || field.getType() == int.class) {
			prefs.putInt(prefId, (Integer) (value == null ? new Integer(0) : value));
		}
	}
}
 
Example 2
Source File: GraphOptionsPanelController.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(GraphPreferenceKeys.class);
            final GraphOptionsPanel graphOptionsPanel = getPanel();

            prefs.putInt(GraphPreferenceKeys.BLAZE_SIZE, graphOptionsPanel.getBlazeSize());
            prefs.putInt(GraphPreferenceKeys.BLAZE_OPACITY, graphOptionsPanel.getBlazeOpacity());
        }
    }
}
 
Example 3
Source File: MainWindow.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
private void saveContours(String askFileMessage, String imageFormat) {
    String PREFS_NAME = "contours_scale";
    String filePath = FileUtils.askFile(this, askFileMessage,
            fileName(imageFormat), false, imageFormat, null);
    if (filePath != null) {
        String title = "Image Resolution";
        Preferences prefs = Preferences.userNodeForPackage(MainWindow.class);
        imageResolutionSpinner.setValue(prefs.getInt(PREFS_NAME, 5));
        int res = JOptionPane.showOptionDialog(getContentPane(), imageResolutionPanel, title,
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
        if (res == JOptionPane.OK_OPTION) {
            int scale = (Integer) (imageResolutionSpinner.getValue());
            exportContours(filePath, imageFormat, scale);
            prefs.putInt(PREFS_NAME, scale);
        }
    }
}
 
Example 4
Source File: GraphsPanel.java    From swift-k with Apache License 2.0 6 votes vote down vote up
void saveLayout() {
    /*
     * Stored are:
     * - the layout itself
     * - the graph count and what's being graphed in each
     * - the graph colors
     */
    try {
        Preferences prefs = Preferences.userNodeForPackage(GraphsPanel.class);
        Preferences layout = prefs.node("layout");
        grid.getTree().store(layout);
        prefs.putInt("graphCount", graphs.size());
        for (int i = 0; i < graphs.size(); i++) {
            Preferences gp = prefs.node("graph" + i);
            graphs.get(i).store(gp);
        }
    }
    catch (Exception e) {
        System.err.println("Failed to save layout: "  + e);
    }
}
 
Example 5
Source File: PhpTypinghooksTestBase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void setOptionsForDocument(Document doc, Map<String, Object> options) throws Exception {
    Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
    for (String option : options.keySet()) {
        Object value = options.get(option);
        if (value instanceof Integer) {
            prefs.putInt(option, ((Integer)value).intValue());
        }
        else if (value instanceof String) {
            prefs.put(option, (String)value);
        }
        else if (value instanceof Boolean) {
            prefs.put(option, ((Boolean)value).toString());
        }
        else if (value instanceof CodeStyle.BracePlacement) {
            prefs.put(option, ((CodeStyle.BracePlacement)value).name());
        }
        else if (value instanceof CodeStyle.WrapStyle) {
            prefs.put(option, ((CodeStyle.WrapStyle)value).name());
        }
    }
}
 
Example 6
Source File: InternalSourceAppearance.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
void saveSettings() {
    if (settingsPanel == null || !currentSettingsDirty()) return;
    
    Preferences settings = NbPreferences.forModule(InternalSourceAppearance.class);
    settings.put(PROP_FONT_NAME, currentFontName());
    settings.putInt(PROP_FONT_STYLE, currentFontStyle());
    settings.putInt(PROP_FONT_SIZE, currentFontSize());
    
    changeSupport.firePropertyChange(new PropertyChangeEvent(this, "appearance", null, null)); // NOI18N
}
 
Example 7
Source File: MenuHandler.java    From DiskBrowser with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void quit (Preferences prefs)
// ---------------------------------------------------------------------------------//
{
  prefs.putBoolean (PREFS_LINE_WRAP, lineWrapItem.isSelected ());
  prefs.putBoolean (PREFS_SHOW_LAYOUT, showLayoutItem.isSelected ());
  prefs.putBoolean (PREFS_SHOW_CATALOG, showCatalogItem.isSelected ());
  prefs.putBoolean (PREFS_SHOW_FREE_SECTORS, showFreeSectorsItem.isSelected ());
  prefs.putBoolean (PREFS_COLOUR_QUIRKS, colourQuirksItem.isSelected ());
  prefs.putBoolean (PREFS_MONOCHROME, monochromeItem.isSelected ());
  //    prefs.putBoolean (PREFS_DEBUGGING, debuggingItem.isSelected ());
  prefs.putInt (PREFS_PALETTE,
      HiResImage.getPaletteFactory ().getCurrentPaletteIndex ());
  fontAction.quit (prefs);

  int scale = scale1Item.isSelected () ? 1 : scale2Item.isSelected () ? 2 : 3;
  prefs.putInt (PREFS_SCALE, scale);

  prefs.putBoolean (PREFS_SPLIT_REMARKS, splitRemarkItem.isSelected ());
  prefs.putBoolean (PREFS_ALIGN_ASSIGN, alignAssignItem.isSelected ());
  prefs.putBoolean (PREFS_SHOW_CARET, showCaretItem.isSelected ());
  prefs.putBoolean (PREFS_SHOW_HEADER, showHeaderItem.isSelected ());
  prefs.putBoolean (PREFS_SHOW_TARGETS, showBasicTargetsItem.isSelected ());
  prefs.putBoolean (PREFS_ONLY_SHOW_TARGETS, onlyShowTargetLinesItem.isSelected ());

  prefs.putBoolean (PREFS_SHOW_ASSEMBLER_TARGETS,
      showAssemblerTargetsItem.isSelected ());
  prefs.putBoolean (PREFS_SHOW_ASSEMBLER_STRINGS,
      showAssemblerStringsItem.isSelected ());
  prefs.putBoolean (PREFS_SHOW_ASSEMBLER_HEADER, showAssemblerHeaderItem.isSelected ());

  prefs.putBoolean (PREFS_PRODOS_SORT_DIRECTORIES,
      prodosSortDirectoriesItem.isSelected ());
}
 
Example 8
Source File: FormattingCustomizerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void deepCopy(Preferences from, Preferences to) throws BackingStoreException {
    for(String kid : from.childrenNames()) {
        Preferences fromKid = from.node(kid);
        Preferences toKid = to.node(kid);
        deepCopy(fromKid, toKid);
    }
    for(String key : from.keys()) {
        String value = from.get(key, null);
        if (value == null) continue;

        Class type = guessType(value);
        if (Integer.class == type) {
            to.putInt(key, from.getInt(key, -1));
        } else if (Long.class == type) {
            to.putLong(key, from.getLong(key, -1L));
        } else if (Float.class == type) {
            to.putFloat(key, from.getFloat(key, -1f));
        } else if (Double.class == type) {
            to.putDouble(key, from.getDouble(key, -1D));
        } else if (Boolean.class == type) {
            to.putBoolean(key, from.getBoolean(key, false));
        } else if (String.class == type) {
            to.put(key, value);
        } else /* byte [] */ {
            to.putByteArray(key, from.getByteArray(key, new byte [0]));
        }
    }
}
 
Example 9
Source File: StubLocationManager.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getStatus() {
    Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
    if (JavaSEPort.locSimulation != null) {
        int s = JavaSEPort.locSimulation.getState();
        setStatus(s);
        p.putInt("lastGoodLocationStat", s);
        return s;
    } else {
        return p.getInt("lastGoodLocationStat" ,super.getStatus());
    }
}
 
Example 10
Source File: UserInputHistory.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void copyInto(Preferences preferences) {
    preferences.putInt(getLengthKey(), maxNumEntries);
    for (int i = 0; i < 100; i++) {
        preferences.put(getNumKey(i), "");
    }
    final String[] entries = getEntries();
    if (entries != null) {
        for (int i = 0; i < entries.length; i++) {
            preferences.put(getNumKey(i), entries[i]);
        }
    }
}
 
Example 11
Source File: LocationSimulation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void locationStateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_locationStateActionPerformed
    /*Platform.runLater(new Runnable() {

        public void run() {*/
            Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
            p.putInt("state", locationState.getSelectedIndex());
    /*    }
    });*/
}
 
Example 12
Source File: ReindenterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testLineIndentationAtMultilineCommentStartWithTabIndents() throws Exception {
    Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
    preferences.putBoolean("expand-tabs", false);
    preferences.putInt("tab-size", 4);
    preferences.putBoolean("enableBlockCommentFormatting", true);
    try {
        performLineIndentationTest("package t;\npublic class T {\n\t/*\n|\n\tpublic void op() {\n\t}\n}\n",
                "package t;\npublic class T {\n\t/*\n\t * \n\tpublic void op() {\n\t}\n}\n");
    } finally {
        preferences.remove("enableBlockCommentFormatting");
        preferences.remove("tab-size");
        preferences.remove("expand-tabs");
    }
}
 
Example 13
Source File: MapImage.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
public static void setPropertyUnitFactoryDamageOutline(final Color color) {
  final Preferences pref = Preferences.userNodeForPackage(MapImage.class);
  pref.putInt(PROPERTY_UNIT_FACTORY_DAMAGE_OUTLINE_STRING, color.getRGB());
  propertyUnitFactoryDamageOutline = color;
}
 
Example 14
Source File: MapImage.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
public static void setPropertyMapFont(final Font font) {
  final Preferences pref = Preferences.userNodeForPackage(MapImage.class);
  pref.putInt(PROPERTY_MAP_FONT_SIZE_STRING, font.getSize());
  propertyMapFont = font;
}
 
Example 15
Source File: Setting.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
public static Setting<Dimension> createDimension(Preferences preferences, String key, Dimension defaultValue) {
	return new SettingBase<>(
		defaultValue,
		value -> Dimension.fromId(preferences.getInt(key, value.getId())),
		value -> preferences.putInt(key, value.getId()));
}
 
Example 16
Source File: PHPFormatterTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void reformatFileContents(String file, Map<String, Object> options, boolean isTemplate, IndentPrefs indentPrefs) throws Exception {
    FileObject fo = getTestFile(file);
    assertNotNull(fo);

    String text = read(fo);

    int formatStart = 0;
    int formatEnd = text.length();
    int startMarkPos = text.indexOf(FORMAT_START_MARK);

    if (startMarkPos >= 0) {
        formatStart = startMarkPos;
        text = text.substring(0, formatStart) + text.substring(formatStart + FORMAT_START_MARK.length());
        formatEnd = text.indexOf(FORMAT_END_MARK);
        text = text.substring(0, formatEnd) + text.substring(formatEnd + FORMAT_END_MARK.length());
        GSFPHPParserTestUtil.setUnitTestCaretPosition(formatEnd);
        if (!isTemplate) {
            formatEnd --;
        }
        if (formatEnd == -1) {
            throw new IllegalStateException();
        }
    }

    BaseDocument doc = getDocument(text);
    assertNotNull(doc);

    if (isTemplate) {
        int carretPosition = text.indexOf('^');
        if (carretPosition == -1) {
            carretPosition = formatEnd;
        } else {
            if (carretPosition < formatStart) {
                formatStart--;
            }
            if (carretPosition < formatEnd) {
                formatEnd--;
            }
            text = text.substring(0, carretPosition) + text.substring(carretPosition + 1);
        }

        TokenFormatter.setUnitTestCarretPosition(carretPosition);
        GSFPHPParserTestUtil.setUnitTestCaretPosition(carretPosition);
        doc.remove(0, doc.getLength());
        doc.insertString(0, text, null);
        doc.putProperty(TokenFormatter.TEMPLATE_HANDLER_PROPERTY, new Object());
    }

    Formatter formatter = getFormatter(indentPrefs);
    //assertNotNull("getFormatter must be implemented", formatter);

    setupDocumentIndentation(doc, indentPrefs);

    Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
    for (String option : options.keySet()) {
        Object value = options.get(option);
        if (value instanceof Integer) {
            prefs.putInt(option, ((Integer) value).intValue());
        } else if (value instanceof String) {
            prefs.put(option, (String) value);
        } else if (value instanceof Boolean) {
            prefs.put(option, ((Boolean) value).toString());
        } else if (value instanceof CodeStyle.BracePlacement) {
            prefs.put(option, ((CodeStyle.BracePlacement) value).name());
        } else if (value instanceof CodeStyle.WrapStyle) {
            prefs.put(option, ((CodeStyle.WrapStyle) value).name());
        }
    }

    format(doc, formatter, formatStart, formatEnd, false);
    String after = doc.getText(0, doc.getLength());
    assertDescriptionMatches(file, after, false, ".formatted");
    GSFPHPParserTestUtil.setUnitTestCaretPosition(-1);
}
 
Example 17
Source File: MapImage.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
public static void setPropertyUnitFactoryDamageColor(final Color color) {
  final Preferences pref = Preferences.userNodeForPackage(MapImage.class);
  pref.putInt(PROPERTY_UNIT_FACTORY_DAMAGE_COLOR_STRING, color.getRGB());
  propertyUnitFactoryDamageColor = color;
}
 
Example 18
Source File: OneOfFilterCondition.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void save( Preferences prefs, String prefix ) throws BackingStoreException {
    prefs.putInt( prefix+"_optionId", id ); //NOI18N
}
 
Example 19
Source File: IntegerPluginProperty.java    From hop with Apache License 2.0 4 votes vote down vote up
public void saveToPreferences( final Preferences node ) {
  node.putInt( this.getKey(), this.getValue() );
}
 
Example 20
Source File: PHPFormatterQATest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
  protected void reformatFileContents(String file, Map<String, Object> options) throws Exception {
      FileObject fo = getTestFile(file);
      assertNotNull(fo);

      String text = read(fo);

      int formatStart = 0;
      int formatEnd = text.length();
      int startMarkPos = text.indexOf(FORMAT_START_MARK);

      if (startMarkPos >= 0){
          formatStart = startMarkPos;
          text = text.substring(0, formatStart) + text.substring(formatStart + FORMAT_START_MARK.length());
          formatEnd = text.indexOf(FORMAT_END_MARK);
          text = text.substring(0, formatEnd) + text.substring(formatEnd + FORMAT_END_MARK.length());
          formatEnd --;
          if (formatEnd == -1){
              throw new IllegalStateException();
          }
      }

      BaseDocument doc = getDocument(text);
      assertNotNull(doc);


      IndentPrefs preferences = new IndentPrefs(4, 4);
      Formatter formatter = getFormatter(preferences);
      //assertNotNull("getFormatter must be implemented", formatter);

      setupDocumentIndentation(doc, preferences);

      Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
      for (String option : options.keySet()) {
          Object value = options.get(option);
          if (value instanceof Integer) {
              prefs.putInt(option, ((Integer)value).intValue());
          }
          else if (value instanceof String) {
              prefs.put(option, (String)value);
          }
          else if (value instanceof Boolean) {
              prefs.put(option, ((Boolean)value).toString());
          }
   else if (value instanceof CodeStyle.BracePlacement) {
prefs.put(option, ((CodeStyle.BracePlacement)value).name());
   }
   else if (value instanceof CodeStyle.WrapStyle) {
prefs.put(option, ((CodeStyle.WrapStyle)value).name());
   }
      }

      format(doc, formatter, formatStart, formatEnd, false);
      String after = doc.getText(0, doc.getLength());
      assertDescriptionMatches(file, after, false, ".formatted");
  }