private void changeMap() {
    try {
      JFileChooser fileChooser = new JFileChooser();
      int result = fileChooser.showOpenDialog(this);
      if (result == JFileChooser.APPROVE_OPTION) {
        File f = fileChooser.getSelectedFile();
        if (!f.exists()) throw new Exception("File doesn't exists!");

        String path = f.getAbsolutePath();
        // String path = Constants.ROOT_MAPSFORGE_DIR + "\\styles\\default.xml";

        Constants.MAP_FILE = path;

        File fProperties = new File("properties.props");

        Properties props = new Properties();
        props.load(new FileInputStream(fProperties));
        props.put("mapFile", Constants.MAP_FILE);
        props.save(new FileOutputStream(fProperties), "");

        MapFile mf = new MapFile(f);
        double lat = mf.boundingBox().getCenterPoint().latitude;
        double lng = mf.boundingBox().getCenterPoint().longitude;
        _mapView.getModel().mapViewPosition.setCenter(new LatLong(lat, lng));

        refreshUI();
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
          this, e.toString(), "Error while changing map file", JOptionPane.ERROR_MESSAGE);
    }
  }
  /**
   * @throws IOException
   * @tests java.util.Properties#save(java.io.OutputStream, java.lang.String)
   */
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "save",
      args = {java.io.OutputStream.class, java.lang.String.class})
  public void test_saveLjava_io_OutputStreamLjava_lang_String() throws IOException {
    Properties myProps = new Properties();
    myProps.setProperty("Property A", "aye");
    myProps.setProperty("Property B", "bee");
    myProps.setProperty("Property C", "see");

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    myProps.save(out, "A Header");
    out.close();

    Properties myProps2 = new Properties();
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    myProps2.load(in);
    in.close();

    Enumeration e = myProps.propertyNames();
    while (e.hasMoreElements()) {
      String nextKey = (String) e.nextElement();
      assertTrue(
          "Stored property list not equal to original",
          myProps2.getProperty(nextKey).equals(myProps.getProperty(nextKey)));
    }
  }
Beispiel #3
0
 // saves the current configuration (breakpoints, window sizes and positions...)
 private void saveConfig() {
   try {
     ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(idxName + ".config"));
     Breakpoints.save(out);
     Properties.save(out);
     out.close();
   } catch (IOException exc) {
     consoleFrame.echoInfo("Could not save settings: " + exc);
   }
 }
 public static void saveSettings(Activity aActivity) {
   Properties lProps = new Properties();
   try {
     lProps.put("url", mURL);
     lProps.save(
         aActivity.openFileOutput(CONFIG_FILE, Context.MODE_PRIVATE),
         "jWebSocketClient Configuration");
   } catch (Exception ex) {
     Toast.makeText(
             aActivity.getApplicationContext(),
             ex.getClass().getSimpleName() + ":" + ex.getMessage(),
             Toast.LENGTH_SHORT)
         .show();
   }
 }
Beispiel #5
0
  public static void main(String[] args) {
    try {
      FileInputStream fis = new FileInputStream(args[0]);
      OrderedProperties p = new OrderedProperties();
      java.util.Properties props = new java.util.Properties();

      p.load(fis);
      fis.close();
      fis = new FileInputStream(args[0]);
      props.load(fis);

      p.store(System.out);
      System.out.println("-------");
      props.save(System.out, null);
    } catch (IOException e) {
      System.out.println(e);
    }
  }
Beispiel #6
0
 public boolean write() {
   try {
     Properties configFile = new Properties();
     configFile.load(new FileInputStream(settingsFile));
     configFile.put("SMTP_Host", mSMTPHost);
     configFile.put("SMTP_Port", mSMTPPort);
     configFile.put("POP3_Host", mPOP3Host);
     configFile.put("POP3_Port", mPOP3Port);
     configFile.put("From", mFrom);
     configFile.put("Password", mPass);
     configFile.put("Name", mName);
     configFile.put("Mails_Location", mMailsLocation);
     configFile.put("Contacts_Location", mContactsLocation);
     // TODO : There are some wrong and deprecated usage of date formatting, fix it.
     configFile.put(
         "Last_Update",
         Integer.toString(mLastUpdate.getYear() + 1900)
             + "/"
             + Integer.toString(mLastUpdate.getMonth())
             + "/"
             + Integer.toString(mLastUpdate.getDay())
             + "-"
             + Integer.toString(mLastUpdate.getHours())
             + "-"
             + Integer.toString(mLastUpdate.getMinutes())
             + "-"
             + Integer.toString(mLastUpdate.getSeconds()));
     FileOutputStream out = new FileOutputStream(settingsFile);
     // TODO : There is a usage of ini save method that deprecated.
     configFile.save(out, "properties updated");
   } catch (Exception e) {
     System.out.println("Write Exception:" + e.getMessage());
     return false;
   }
   return true;
 }
 /** @deprecated */
 public void save(OutputStream out, String comments) {
   p.save(out, comments);
 }
  /**
   * implemented. <br>
   * Add a test to determine of store generates a comment line with the current time <br>
   * <br>
   * depricated method !!!
   */
  public void test_save() {
    th.checkPoint("save(java.io.OutputStream,java.lang.String)void");
    Properties p = new Properties(defProps);
    try {
      p.save(null, "no comment");
      th.fail("should throw NullPointerException");
    } catch (NullPointerException ne) {
      th.check(true);
    } catch (Exception e) {
      th.fail("should throw an NullPointerEception instead of: " + e);
    }

    try {
      p.save(bout, null);
      th.check(true);
    } catch (NullPointerException ne) {
      th.fail("should not throw NullPointerException");
    } catch (Exception e) {
      th.fail("shouldn't throw any Exception, but got: " + e);
    }

    resetStreams();
    try {
      p.save(bout, null);
    } catch (Exception e) {
      th.fail("shouldn't throw any Exception, but got: " + e);
    }
    byte ba[] = bout.toByteArray();
    th.check((ba[0] == (byte) '#') && (ba[1] != (byte) '#'), "just date should be written");
    th.debug(ba.length + " -- got: " + new String(ba));
    th.check(ba.length < 50, "default properties are never printed out");
    resetStreams();
    try {
      p.load(bin);
    } catch (Exception e) {
    }
    try {
      p.save(bout, "no comments");
    } catch (Exception e) {
      th.fail("shouldn't throw any Exception, but got: " + e);
    }
    ba = bout.toByteArray();
    String s = new String(ba, 0, 12);
    th.check(s.equals("#no comments"), "got: " + s);
    int i = 0, count = 0;
    while (i < 2 && count < ba.length) {
      if (ba[count++] == (byte) '\n') i++;
    }
    // we will construct a vector containing all the lines with should be written
    Vector v = new Vector();
    Enumeration ek = p.keys();
    while (ek.hasMoreElements()) {
      s = (String) ek.nextElement();
      v.add(s + "=" + p.getProperty(s));
    }
    while (count < ba.length) {
      int start = count;
      while (count < ba.length) {
        if (ba[count] != '\n') count++;
        else break;
      }
      s = new String(ba, start, count - start);
      th.check(v.contains(s), "v does not contain: " + s);
      v.removeElement(s);
      count++;
    }
  }