/**
  * Acción a realizar cuando el usuario pulsa el botón "Aceptar". Cierra la ventana tras aplicar
  * los cambios realizados.
  */
 @Action
 public void aceptar() {
   org.jdesktop.application.ResourceMap resourceMap =
       org.jdesktop.application.Application.getInstance(delphsim.DelphSimApp.class)
           .getContext()
           .getResourceMap(PreferenciasSimulacion.class);
   try {
     // Actualizamos las preferencias
     PreferenciasSimulacion.preferencias.put(
         "metodo", Integer.toString(this.metodoComboBox.getSelectedIndex())); // NOI18N
     PreferenciasSimulacion.preferencias.put(
         "h", Double.toString((Double) this.hSpinner.getValue())); // NOI18N
     if (this.autosaveCheckBox.isSelected()) {
       PreferenciasSimulacion.preferencias.put("autosave", "si"); // NOI18N
     } else {
       PreferenciasSimulacion.preferencias.put("autosave", "no"); // NOI18N
     }
     // Las exportamos al fichero
     String rutaArchivo =
         new File(System.getProperty("java.class.path")).getParent()
             + resourceMap.getString("archivoPreferencias.path"); // NOI18N
     File f = new File(rutaArchivo);
     FileOutputStream os = new FileOutputStream(f);
     PreferenciasSimulacion.preferencias.exportSubtree(os);
     // Y cerramos la ventana
     dispose();
   } catch (IOException ioe) {
     System.err.println(ioe.getMessage());
   } catch (BackingStoreException bse) {
     System.err.println(bse.getMessage());
   }
 }
Example #2
0
 public static void resetPreferences() {
   try {
     Base.preferences.removeNode();
     Base.preferences.flush();
     preferences = Preferences.userNodeForPackage(Base.class);
   } catch (BackingStoreException bse) {
     bse.printStackTrace();
   }
 }
 /**
  * Exports Preferences to an XML file.
  *
  * @param filename String File to export to
  */
 public void exportPreferences(String filename) throws IOException {
   File f = new File(filename);
   OutputStream os = new FileOutputStream(f);
   try {
     prefs.exportSubtree(os);
   } catch (BackingStoreException ex) {
     throw new IOException(ex.getMessage());
   }
 }
Example #4
0
 public static void setDelayedParsing(final boolean delayedParsing) {
   final Preferences pref = Preferences.userNodeForPackage(GameRunner2.class);
   pref.putBoolean(DELAYED_PARSING, delayedParsing);
   try {
     pref.sync();
   } catch (final BackingStoreException e) {
     e.printStackTrace();
   }
 }
Example #5
0
 public static void setDefaultLookAndFeel(final String lookAndFeelClassName) {
   final Preferences pref = Preferences.userNodeForPackage(GameRunner2.class);
   pref.put(LOOK_AND_FEEL_PREF, lookAndFeelClassName);
   try {
     pref.sync();
   } catch (final BackingStoreException e) {
     e.printStackTrace();
   }
 }
Example #6
0
 public void clearConfiguration() {
   try {
     for (String key : prefs.keys()) {
       if (key.startsWith(keyPrefix) && !key.equals("gMCP.NumberOfStarts")) {
         prefs.remove(key);
       }
     }
   } catch (BackingStoreException e) {
     // We really don't want to throw an error here...
     logger.error("Error clearing configuration:\n" + e.getMessage(), e);
   }
 }
 private static void saveModel(GuiQuickstartDataModel model) {
   Preferences preferences = Preferences.userNodeForPackage(GuiBootstrapMain.class);
   updatePreferences(preferences, "transitDataBundlePath", model.getTransitDataBundlePath());
   updatePreferences(preferences, "gtfsPath", model.getGtfsPath());
   updatePreferences(preferences, "tripUpdatesUrl", model.getTripUpdatesUrl());
   updatePreferences(preferences, "vehiclePositionsUrl", model.getVehiclePositionsUrl());
   updatePreferences(preferences, "alertsUrl", model.getAlertsUrl());
   try {
     preferences.sync();
   } catch (BackingStoreException e) {
     e.printStackTrace();
   }
 }
 /** Calling this method will write all preferences into the preference store. */
 public void flush() {
   if (getBoolean("memoryStickMode")) {
     try {
       exportPreferences("jabref.xml");
     } catch (IOException e) {
       Globals.logger(
           "Could not save preferences for memory stick mode: " + e.getLocalizedMessage());
     }
   }
   try {
     prefs.flush();
   } catch (BackingStoreException ex) {
     ex.printStackTrace();
   }
 }
Example #9
0
 /**
  * Returns a String which lists all Preferences in Preferences.userRoot() which start with the
  * keyPrefix.
  *
  * @return String which lists all Preferences in Preferences.userRoot() which start with the
  *     keyPrefix.
  * @throws BackingStoreException
  */
 public String getConfigurationForDebugPurposes() {
   String s = "";
   s += keyPrefix + "\n";
   try {
     for (String key : prefs.keys()) {
       if (key.startsWith(keyPrefix)) {
         String val = prefs.get(key, "__NOT FOUND__");
         key = key.substring(keyPrefix.length());
         s += key + " : " + val + "\n";
       }
     }
   } catch (BackingStoreException e) {
     // We really don't want to throw an error here...
     logger.error("Error printing configuration:\n" + e.getMessage(), e);
   }
   return s;
 }
Example #10
0
 private void sendText() {
   String text = textField.getText().trim();
   String voice = (String) speechComboBox.getSelectedItem();
   if (text != null && !text.isEmpty()) {
     prefs.put("roboy_voice", voice);
     try {
       prefs.flush();
     } catch (BackingStoreException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     if (model.sendText(text, voice)) {
       // btnSpeech.setEnabled(false);
       // textField.setEnabled(false);
     }
   }
 }
 public void saveAll() {
   for (DynamiPrefs p : prefsPages) {
     p.prefs().write(storedPreferences);
   }
   try {
     try (FileOutputStream output =
         new FileOutputStream(new File(PrefsConstants.PREFS_FILE_PATH))) {
       storedPreferences.exportNode(output);
     }
     //			Preferences.userRoot().exportNode();
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (BackingStoreException e) {
     e.printStackTrace();
   }
 }
Example #12
0
 public static void setProxy(
     final String proxyHost, final String proxyPort, final ProxyChoice proxyChoice) {
   final Preferences pref = Preferences.userNodeForPackage(GameRunner2.class);
   final ProxyChoice choice;
   if (proxyChoice != null) {
     choice = proxyChoice;
     pref.put(PROXY_CHOICE, proxyChoice.toString());
   } else {
     choice = ProxyChoice.valueOf(pref.get(PROXY_CHOICE, ProxyChoice.NONE.toString()));
   }
   if (proxyHost != null && proxyHost.trim().length() > 0) {
     pref.put(PROXY_HOST, proxyHost); // user pref, not system properties
     if (choice == ProxyChoice.USE_USER_PREFERENCES) System.setProperty(HTTP_PROXYHOST, proxyHost);
   }
   if (proxyPort != null && proxyPort.trim().length() > 0) {
     try {
       Integer.parseInt(proxyPort);
       pref.put(PROXY_PORT, proxyPort); // user pref, not system properties
       if (choice == ProxyChoice.USE_USER_PREFERENCES)
         System.setProperty(HTTP_PROXYPORT, proxyPort);
     } catch (final NumberFormatException nfe) {
       nfe.printStackTrace();
     }
   }
   if (choice == ProxyChoice.NONE) {
     System.clearProperty(HTTP_PROXYHOST);
     System.clearProperty(HTTP_PROXYPORT);
   } else if (choice == ProxyChoice.USE_SYSTEM_SETTINGS) {
     setToUseSystemProxies();
   }
   if (proxyHost != null || proxyPort != null || proxyChoice != null) {
     try {
       pref.flush();
       pref.sync();
     } catch (final BackingStoreException e) {
       e.printStackTrace();
     }
   }
   /*System.out.println(System.getProperty(HTTP_PROXYHOST));
   System.out.println(System.getProperty(HTTP_PROXYPORT));*/
 }
Example #13
0
  public PreferencesDialog(JabRefFrame parent) {
    super(parent, Localization.lang("JabRef preferences"), false);
    JabRefPreferences prefs = JabRefPreferences.getInstance();
    frame = parent;

    main = new JPanel();
    JPanel mainPanel = new JPanel();
    JPanel lower = new JPanel();

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(lower, BorderLayout.SOUTH);

    final CardLayout cardLayout = new CardLayout();
    main.setLayout(cardLayout);

    List<PrefsTab> tabs = new ArrayList<>();
    tabs.add(new GeneralTab(prefs));
    tabs.add(new NetworkTab(prefs));
    tabs.add(new FileTab(frame, prefs));
    tabs.add(new FileSortTab(prefs));
    tabs.add(new EntryEditorPrefsTab(frame, prefs));
    tabs.add(new GroupsPrefsTab(prefs));
    tabs.add(new AppearancePrefsTab(prefs));
    tabs.add(new ExternalTab(frame, this, prefs));
    tabs.add(new TablePrefsTab(prefs));
    tabs.add(new TableColumnsTab(prefs, parent));
    tabs.add(new BibtexKeyPatternPrefTab(prefs, parent.getCurrentBasePanel()));
    tabs.add(new PreviewPrefsTab(prefs));
    tabs.add(new NameFormatterTab(prefs));
    tabs.add(new ImportSettingsTab(prefs));
    tabs.add(new XmpPrefsTab(prefs));
    tabs.add(new AdvancedTab(prefs));

    // add all tabs
    tabs.forEach(tab -> main.add((Component) tab, tab.getTabName()));

    mainPanel.setBorder(BorderFactory.createEtchedBorder());

    String[] tabNames = tabs.stream().map(PrefsTab::getTabName).toArray(String[]::new);
    JList<String> chooser = new JList<>(tabNames);
    chooser.setBorder(BorderFactory.createEtchedBorder());
    // Set a prototype value to control the width of the list:
    chooser.setPrototypeCellValue("This should be wide enough");
    chooser.setSelectedIndex(0);
    chooser.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // Add the selection listener that will show the correct panel when
    // selection changes:
    chooser.addListSelectionListener(
        e -> {
          if (e.getValueIsAdjusting()) {
            return;
          }
          String o = chooser.getSelectedValue();
          cardLayout.show(main, o);
        });

    JPanel buttons = new JPanel();
    buttons.setLayout(new GridLayout(4, 1));
    buttons.add(importPreferences, 0);
    buttons.add(exportPreferences, 1);
    buttons.add(showPreferences, 2);
    buttons.add(resetPreferences, 3);

    JPanel westPanel = new JPanel();
    westPanel.setLayout(new BorderLayout());
    westPanel.add(chooser, BorderLayout.CENTER);
    westPanel.add(buttons, BorderLayout.SOUTH);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(main, BorderLayout.CENTER);
    mainPanel.add(westPanel, BorderLayout.WEST);

    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ok.addActionListener(new OkAction());
    CancelAction cancelAction = new CancelAction();
    cancel.addActionListener(cancelAction);
    lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(lower);
    buttonBarBuilder.addGlue();
    buttonBarBuilder.addButton(ok);
    buttonBarBuilder.addButton(cancel);
    buttonBarBuilder.addGlue();

    // Key bindings:
    KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction);

    // Import and export actions:
    exportPreferences.setToolTipText(Localization.lang("Export preferences to file"));
    exportPreferences.addActionListener(
        e -> {
          Optional<Path> path =
              new NewFileDialogs(frame, System.getProperty("user.home"))
                  .withExtension(FileExtensions.XML)
                  .saveNewFile();
          path.ifPresent(
              exportFile -> {
                try {
                  prefs.exportPreferences(exportFile.toString());
                } catch (JabRefException ex) {
                  LOGGER.warn(ex.getMessage(), ex);
                  JOptionPane.showMessageDialog(
                      PreferencesDialog.this,
                      ex.getLocalizedMessage(),
                      Localization.lang("Export preferences"),
                      JOptionPane.ERROR_MESSAGE);
                }
              });
        });

    importPreferences.setToolTipText(Localization.lang("Import preferences from file"));
    importPreferences.addActionListener(
        e -> {
          Optional<Path> fileName =
              new NewFileDialogs(frame, System.getProperty("user.home"))
                  .withExtension(FileExtensions.XML)
                  .openDlgAndGetSelectedFile();

          if (fileName.isPresent()) {
            try {
              prefs.importPreferences(fileName.get().toString());
              updateAfterPreferenceChanges();
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  Localization.lang("You must restart JabRef for this to come into effect."),
                  Localization.lang("Import preferences"),
                  JOptionPane.WARNING_MESSAGE);
            } catch (JabRefException ex) {
              LOGGER.warn(ex.getMessage(), ex);
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  ex.getLocalizedMessage(),
                  Localization.lang("Import preferences"),
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });

    showPreferences.addActionListener(
        e ->
            new PreferencesFilterDialog(new JabRefPreferencesFilter(Globals.prefs), frame)
                .setVisible(true));
    resetPreferences.addActionListener(
        e -> {
          if (JOptionPane.showConfirmDialog(
                  PreferencesDialog.this,
                  Localization.lang(
                      "Are you sure you want to reset all settings to default values?"),
                  Localization.lang("Reset preferences"),
                  JOptionPane.OK_CANCEL_OPTION)
              == JOptionPane.OK_OPTION) {
            try {
              prefs.clear();
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  Localization.lang("You must restart JabRef for this to come into effect."),
                  Localization.lang("Reset preferences"),
                  JOptionPane.WARNING_MESSAGE);
            } catch (BackingStoreException ex) {
              LOGGER.warn(ex.getMessage(), ex);
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  ex.getLocalizedMessage(),
                  Localization.lang("Reset preferences"),
                  JOptionPane.ERROR_MESSAGE);
            }
            updateAfterPreferenceChanges();
          }
        });

    setValues();

    pack();
  }
Example #14
0
  /** Create the application. */
  public Wow() {
    initialize();
    // ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
    coreWallet = new CoreWallet();
    fileChooser = new JFileChooser();
    FileNameExtensionFilter filter =
        new FileNameExtensionFilter("Wow DOGE Wallet Files", "dogewallet");
    fileChooser.addChoosableFileFilter(filter);
    addressesListModel = new AddressesListModel();
    listAddresses.setModel(addressesListModel); // new DefaultListModel());
    transactionsTableModel = new TransactionsTableModel();
    tableTransactions.setModel(transactionsTableModel);
    tableTransactions.setDefaultRenderer(Object.class, new TransactionsTableCellRenderer());
    addressBookTableModel = new AddressBookTableModel(coreWallet.getPreferences());
    tableAddressBook.setModel(addressBookTableModel);
    try {
      addressBookTableModel.getAddressBook().load();
    } catch (IOException e1) {
      e1.printStackTrace();
      JOptionPane.showMessageDialog(
          frmWow,
          e1.getMessage(),
          "Error during Reading Address Book Data",
          JOptionPane.ERROR_MESSAGE);
    } catch (ClassNotFoundException e1) {
      e1.printStackTrace();
      JOptionPane.showMessageDialog(
          frmWow, e1.getMessage(), "Error in Reading Address Book Data", JOptionPane.ERROR_MESSAGE);
    } catch (BackingStoreException e1) {
      e1.printStackTrace();
      JOptionPane.showMessageDialog(
          frmWow,
          e1.getMessage(),
          "Error within Reading Address Book Data",
          JOptionPane.ERROR_MESSAGE);
    }

    JMenuBar menuBar = new JMenuBar();
    frmWow.setJMenuBar(menuBar);

    mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    menuBar.add(mnFile);

    JMenuItem mntmNew = new JMenuItem("New Wallet");
    mntmNew.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            DialogNew d = new DialogNew();
            d.setLocationRelativeTo(frmWow);
            if (d.showDialog()) {
              try {
                coreWallet.open(new File(d.getFolder(), d.getWalletFileName()));
                mnRecent.addFileToFileHistory(
                    new File(d.getFolder(), d.getWalletFileName()).getAbsolutePath());
                mnRecent.storeToPreferences();
              } catch (IOException e) {
                JOptionPane.showMessageDialog(
                    frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
              } catch (Exception e) {
                JOptionPane.showMessageDialog(
                    frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
              }
            }
          }
        });
    mntmNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.META_MASK));
    mntmNew.setMnemonic(KeyEvent.VK_N);
    mnFile.add(mntmNew);

    JMenuItem mntmOpen = new JMenuItem("Open Wallet...");
    mntmOpen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            int returnVal = fileChooser.showOpenDialog(frmWow);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
              try {
                File file = fileChooser.getSelectedFile();
                coreWallet.open(file);
                mnRecent.addFileToFileHistory(file.getAbsolutePath());
                mnRecent.storeToPreferences();
              } catch (IOException e) {
                JOptionPane.showMessageDialog(
                    frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
              } catch (Exception e) {
                JOptionPane.showMessageDialog(
                    frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
              }
            }
          }
        });
    mntmOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.META_MASK));
    mnFile.add(mntmOpen);

    JMenuItem mntmSaveAs = new JMenuItem("Save As...");
    mntmSaveAs.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            int returnVal = fileChooser.showSaveDialog(frmWow);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
              try {
                File file = fileChooser.getSelectedFile();
                String file_name = file.toString();
                if (!file_name.endsWith(".dogewallet")) file_name += ".dogewallet";
                file = new File(file_name);
                File temp =
                    new File(file.getParentFile().getAbsolutePath(), "TEMP" + file.getName());
                coreWallet.saveToFile(temp, file);
              } catch (IOException e) {
                JOptionPane.showMessageDialog(
                    frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
              }
            }
          }
        });
    // coreWallet = new CoreWallet();

    mnRecent =
        new RecentFilesMenu("Open Recent Wallet", coreWallet.getPreferences().node("Recent")) {
          @Override
          protected Action createOpenAction(String fileFullPath) {
            return new OpenAction(this, fileFullPath);
          }
        };
    mnFile.add(mnRecent);
    mntmSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.META_MASK));
    mnFile.add(mntmSaveAs);

    JMenu mnHelp = new JMenu("Help");
    menuBar.add(mnHelp);

    JMenuItem mntmHelp = new JMenuItem("Wow - Doge Wallet Help");
    mnHelp.add(mntmHelp);

    JMenuItem mntmAbout = new JMenuItem("About Wow - Doge Wallet");
    mntmAbout.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DialogAbout d = new DialogAbout();
            d.setLocationRelativeTo(frmWow);
            d.showDialog();
          }
        });
    mnHelp.add(mntmAbout);

    tableAddressBook.setDefaultRenderer(Object.class, new AddressBookTableCellRenderer());

    (new Thread(this)).start();
  }
Example #15
0
  public File browse(
      Component parent,
      BrowseType browseType,
      FileType fileType,
      PrefType prefType,
      boolean dirsOnly,
      String startingDir) {
    init(parent);

    try {
      prefs.sync();
    } catch (BackingStoreException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    File selFile = null;
    if (startingDir != null) {
      File f = new File(startingDir);

      if (f.isFile()) //
      startingDir = f.getParent();
      else {
        if (!f.exists()) f.mkdir();

        if (dirsOnly) { // make parent dir the starting dir, if it exists
          startingDir = f.getParent();
          selFile = f;
        }
      }
    }

    String lastDir =
        startingDir != null && startingDir.length() != 0
            ? startingDir
            : prefs.get("file." + browseType.name() + "." + prefType.name(), null);
    if (lastDir == null) {
      if (prefType == PrefType.FontLoad) {
        lastDir = getBestFontPath();
      } else {
        lastDir = System.getProperty("user.home");
      }
    }

    File lastDirFile = new File(lastDir);
    String lastDirFileName = "";
    if (lastDirFile.exists() && lastDirFile.isFile()) lastDirFileName = lastDirFile.getName();

    File file = null;

    if (useJFileChooser) {
      jFileChooser.setFileFilter(fileType.swingFilter);

      jFileChooser.setCurrentDirectory(new File(lastDir));

      if (selFile != null) jFileChooser.setSelectedFile(selFile);

      jFileChooser.setFileSelectionMode(
          dirsOnly ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);
      int a =
          browseType == BrowseType.Open
              ? jFileChooser.showOpenDialog(parent)
              : jFileChooser.showSaveDialog(parent);
      if (a == JFileChooser.APPROVE_OPTION) {
        prefs.put(
            "file." + browseType.name(), jFileChooser.getCurrentDirectory().getAbsolutePath());
        file = jFileChooser.getSelectedFile();
      }
    } else {
      System.setProperty("apple.awt.fileDialogForDirectories", Boolean.toString(dirsOnly));

      fileDialog.setAlwaysOnTop(true);
      fileDialog.setFilenameFilter(fileType.awtFilter);
      fileDialog.setDirectory(lastDir);
      fileDialog.setFile(lastDirFileName);
      fileDialog.setMode(browseType == BrowseType.Open ? FileDialog.LOAD : FileDialog.SAVE);
      fileDialog.setVisible(true);
      String res = fileDialog.getFile();
      if (res != null) {
        File ret = new File(fileDialog.getDirectory(), res);
        File dir = ret;
        if (dir.getParentFile() != null && !dir.isDirectory()) dir = dir.getParentFile();
        prefs.put("file." + browseType.name(), dir.getAbsolutePath());
        file = ret;
      }
    }

    if (file != null) {
      try {
        prefs.flush();
      } catch (BackingStoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    return file;
  }