Пример #1
0
 void initSettings() {
   try {
     FileInputStream in = new FileInputStream(DB_SETTINGS_FILE);
     dbSettings.load(in);
     in.close();
   } catch (FileNotFoundException fnfe) {
     System.err.println("Cannot load settings file:\n" + fnfe.getMessage());
     return;
   } catch (IOException ioe) {
     System.err.println("IO exception :\n" + ioe.getMessage());
     return;
   }
   jtflHost.setText(dbSettings.getProperty(DB_URL));
   String encryption = dbSettings.getProperty("encryption");
   if (encryption.equalsIgnoreCase("on")) {
     try {
       jtflUser.setText(encrypter.decrypt(dbSettings.getProperty(DB_USER)));
       jpflPwd.setText(encrypter.decrypt(dbSettings.getProperty(DB_PWD)));
     } catch (EncryptionException ex) {
       ex.printStackTrace();
     }
   } else {
     jtflUser.setText(dbSettings.getProperty(DB_USER));
     jpflPwd.setText(dbSettings.getProperty(DB_PWD));
   }
 }
Пример #2
0
 public DBSettings(final MainWindow parent) {
   super(parent, true);
   mainWin = parent;
   initComponents();
   build();
   setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
   try {
     encrypter =
         new StringEncrypter(
             StringEncrypter.DESEDE_ENCRYPTION_SCHEME, "123456789012345678901234567890");
   } catch (EncryptionException ex) {
     ex.printStackTrace();
   }
   initSettings();
   setSize(PREFERRED_SIZE);
   setLocationRelativeTo(mainWin);
   jbtnOK.addActionListener(this);
   jbtnCancel.addActionListener(this);
 }
Пример #3
0
 void saveSettings() {
   dbSettings.setProperty("encryption", "on");
   dbSettings.setProperty(DB_URL, jtflHost.getText());
   try {
     dbSettings.setProperty(DB_USER, encrypter.encrypt(jtflUser.getText()));
     dbSettings.setProperty(DB_PWD, encrypter.encrypt(new String(jpflPwd.getPassword())));
   } catch (EncryptionException ex) {
     ex.printStackTrace();
   }
   try {
     FileOutputStream out = new FileOutputStream(DB_SETTINGS_FILE);
     dbSettings.store(out, "");
     out.close();
   } catch (FileNotFoundException fnfe) {
     System.err.println("Cannot save settings file:\n" + fnfe.getMessage());
     return;
   } catch (IOException ioe) {
     System.err.println("IO exception :\n" + ioe.getMessage());
     return;
   }
 }