Example usage for java.util.prefs Preferences getDouble

List of usage examples for java.util.prefs Preferences getDouble

Introduction

In this page you can find the example usage for java.util.prefs Preferences getDouble.

Prototype

public abstract double getDouble(String key, double def);

Source Link

Document

Returns the double value represented by the string associated with the specified key in this preference node.

Usage

From source file:gridrover.GridRover.java

/**
* This method does the work of getting our application started.
*
* @param args Command line arguments/*from   ww  w. j  a  v a2s.  c om*/
*/
public static void main(String[] args) {
    System.out.println("GridRover Copyright (C) 2008-2009 Lucas Adam M. Paul");
    System.out.println("This program comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.TXT.");
    System.out.println("This is free software, and you are welcome to redistribute it");
    System.out.println("under certain conditions; see LICENSE.TXT for details.\n");

    log.info("Loading preferences...");
    Preferences prefs = Preferences.userNodeForPackage(GridRover.class);
    int width = prefs.getInt(MAP_WIDTH, 10);
    int length = prefs.getInt(MAP_HEIGHT, 10);
    double maxElevation = prefs.getDouble(MAX_ELEVATION, 25.0);
    int precision = prefs.getInt(ELEVATION_PRECISION, 2);

    log.info("Loading data files...");

    XmlFileParser fileParser = new XmlFileParser(new ResourceLocater(null));
    List<Spectrum> spectra = fileParser.getSpectra("spectrum_types.xml");
    log.debug("Checking we got our spectra.");
    for (Spectrum spec : spectra) {
        log.debug("Type: " + spec.getName());
        List<String> list = spec.getColors();
        for (String color : list)
            log.debug("\tColor: " + color);
        list = spec.getShapes();
        for (String shape : list)
            log.debug("\tShape: " + shape);
    }
    //List<Thing> itemPrototypes = fileParser.getThings("physical_objects.xml");
    List<ThingBean> itemPrototypes = fileParser.getThings("physical_objects.xml", spectra);
    log.debug("Checking we got our Things.");
    for (ThingBean tb : itemPrototypes) {
        log.debug("Name: " + tb.getName());
        log.debug("Mass: " + tb.getMinMass() + " - " + tb.getMaxMass());
        log.debug("Density: " + tb.getMinDensity() + " - " + tb.getMaxDensity());
        List<AppearanceBean> appearance = tb.getAppearanceBeans();
        for (AppearanceBean ab : appearance) {
            log.debug("Under the " + ab.getStimulus() + " spectrum, " + tb.getName() + " reacts with:");
            List<ResponseBean> responses = ab.getResponseBeans();
            for (ResponseBean rb : responses) {
                log.debug(rb.getSpectrumAction().toString() + " " + rb.getColor() + " " + rb.getShape()
                        + " in spectrum " + rb.getSpectrum());
            }
        }
    }

    log.info("Initializing GridRover...");
    GameEngine engine = new GameEngine(width, length, maxElevation, precision);
    Rover rover = new Rover("Rover", 185.0, 5.52, 100.0, new CommandlineRoverControl()); // Mass 185.0 kg, 1.5 meters tall by 2.3 meters wide by 1.6 meters long
    engine.addRover(rover, width / 2, length / 2); // Add a single rover in the middle of the map
    engine.addAmbientLighting(spectra.get(0));
    engine.scatterItemsRandomly(itemPrototypes, 0.5, 5); // 50% chance of items in a given square, up to 5 items per square

    log.info("Running GridRover...");
    engine.eventLoop();
    System.out.println("All events completed.  GridRover now terminating.");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);

    // Preference key name
    final String PREF_NAME = "name_of_preference";

    // Save//  w  ww  .j  a v  a2s. c  o  m
    prefs.put(PREF_NAME, "a string"); // String
    prefs.putBoolean(PREF_NAME, true); // boolean
    prefs.putInt(PREF_NAME, 123); // int
    prefs.putLong(PREF_NAME, 123L); // long
    prefs.putFloat(PREF_NAME, 12.3F); // float
    prefs.putDouble(PREF_NAME, 12.3); // double
    byte[] bytes = new byte[1024];
    prefs.putByteArray(PREF_NAME, bytes); // byte[]

    // Retrieve
    String s = prefs.get(PREF_NAME, "a string"); // String
    boolean b = prefs.getBoolean(PREF_NAME, true); // boolean
    int i = prefs.getInt(PREF_NAME, 123); // int
    long l = prefs.getLong(PREF_NAME, 123L); // long
    float f = prefs.getFloat(PREF_NAME, 12.3F); // float
    double d = prefs.getDouble(PREF_NAME, 12.3); // double
    bytes = prefs.getByteArray(PREF_NAME, bytes); // byte[]
}

From source file:net.chaosserver.timelord.swingui.AnnoyTimeDialog.java

/**
 * Constructs a annoy time dialog for setting the dialog.
 *
 * @param applicationFrame the parent frame
 *//*from www .ja v  a 2  s . c o  m*/
public AnnoyTimeDialog(JFrame applicationFrame) {
    super(applicationFrame, "Set Day Start Time", true);

    JPanel annoyTimePanel = new JPanel();

    minuteSlider = new JSlider(0, 60);
    minuteSlider.setMajorTickSpacing(15);
    minuteSlider.setMinorTickSpacing(3);
    minuteSlider.setPaintLabels(true);
    minuteSlider.setPaintTicks(true);
    minuteSlider.setSnapToTicks(true);

    Preferences preferences = Preferences.userNodeForPackage(Timelord.class);

    double timeIncrement = preferences.getDouble(Timelord.TIME_INCREMENT, 0.25);

    if (log.isDebugEnabled()) {
        log.debug("Loaded Time Increment Preference [" + timeIncrement + "] from preference ["
                + Timelord.TIME_INCREMENT + "]");
    }

    minuteSlider.setValue((int) (timeIncrement * 60));

    annoyTimePanel.add(minuteSlider);

    JButton okayButton = new JButton(
            resourceBundle.getString("net.chaosserver.timelord.swingui.TimelordMenu.okay"));
    okayButton.setActionCommand(ACTION_OK);
    okayButton.addActionListener(this);
    annoyTimePanel.add(okayButton);

    JButton cancelButton = new JButton(
            resourceBundle.getString("net.chaosserver.timelord.swingui.TimelordMenu.cancel"));
    cancelButton.setActionCommand(ACTION_CANCEL);
    cancelButton.addActionListener(this);
    annoyTimePanel.add(cancelButton);

    this.getContentPane().add(annoyTimePanel);
    this.pack();

    this.setLocationRelativeTo(applicationFrame);
}

From source file:net.chaosserver.timelord.swingui.Timelord.java

/**
 * Returns the dimension of the last saved framesize.
 *
 * @return last saved frame size in preferences
 *//* w ww. j  a v a  2s . c o  m*/
protected Dimension loadLastFrameSize() {
    Preferences preferences = Preferences.userNodeForPackage(this.getClass());

    Dimension windowSize = new Dimension();
    windowSize.setSize(preferences.getDouble(FRAME_WIDTH, DEFAULT_FRAME_WIDTH),
            preferences.getDouble(FRAME_HEIGHT, DEFAULT_FRAME_HEIGHT));

    return windowSize;
}

From source file:net.chaosserver.timelord.swingui.Timelord.java

/**
 * Gets back the point location where the frame was last saved.
 *
 * @return location where the frame was last saved
 *//* ww w.j a  va2  s .  com*/
protected Point loadLastFrameLocation() {
    Preferences preferences = Preferences.userNodeForPackage(this.getClass());

    Point windowLocation = new Point();
    windowLocation.setLocation(preferences.getDouble(FRAME_X_LOCATION, 0),
            preferences.getDouble(FRAME_Y_LOCATION, 0));

    return windowLocation;
}

From source file:com.wwidesigner.gui.StudyModel.java

/**
 * Set study model preferences from application preferences.
 * /*from w w w .  java 2 s .  c om*/
 * @param newPreferences
 */
public void setPreferences(Preferences newPreferences) {
    double currentTemperature = newPreferences.getDouble(OptimizationPreferences.TEMPERATURE_OPT,
            OptimizationPreferences.DEFAULT_TEMPERATURE);
    double currentPressure = newPreferences.getDouble(OptimizationPreferences.PRESSURE_OPT,
            OptimizationPreferences.DEFAULT_PRESSURE);
    int currentHumidity = newPreferences.getInt(OptimizationPreferences.HUMIDITY_OPT,
            OptimizationPreferences.DEFAULT_HUMIDITY);
    int currentCO2 = newPreferences.getInt(OptimizationPreferences.CO2_FRACTION_OPT,
            OptimizationPreferences.DEFAULT_CO2_FRACTION);
    double xCO2 = currentCO2 * 1.0e-6;
    getParams().setProperties(currentTemperature, currentPressure, currentHumidity, xCO2);
    getParams().printProperties();

    String optimizerPreference = newPreferences.get(OptimizationPreferences.OPTIMIZER_TYPE_OPT,
            OptimizationPreferences.OPT_DEFAULT_NAME);
    if (optimizerPreference.contentEquals(OptimizationPreferences.OPT_DEFAULT_NAME)) {
        preferredOptimizerType = null;
    } else if (optimizerPreference.contentEquals(OptimizationPreferences.OPT_DIRECT_NAME)) {
        preferredOptimizerType = BaseObjectiveFunction.OptimizerType.DIRECTOptimizer;
    } else {
        preferredOptimizerType = null;
    }
}

From source file:org.jamocha.gui.JamochaGui.java

private void loadState(final Stage primaryStage) {
    final Preferences userPrefs = Preferences.userNodeForPackage(getClass());
    // get window location from user preferences: use x=100, y=100, width=400, height=400 as
    // default//from  w  w  w  .  ja va 2 s  . com
    primaryStage.setX(userPrefs.getDouble("stage.x", 100));
    primaryStage.setY(userPrefs.getDouble("stage.y", 100));
    primaryStage.setWidth(userPrefs.getDouble("stage.width", 800));
    primaryStage.setHeight(userPrefs.getDouble("stage.height", 600));
}