예제 #1
0
  /**
   * Initialize the preferences system. This will load
   *
   * <ul>
   *   <li>general user prefs
   *   <li>user filter settings
   *   <li>user segmentation settings
   * </ul>
   *
   * from existing files in {@link StaticUtils#getConfigDir()} (and others for general prefs; see
   * {@link #getPreferencesFile()}) and set things up to create them via {@link #save()} if they
   * don't yet exist.
   *
   * <p>When the preferences system is required but actual user preferences shouldn't be loaded or
   * altered (testing scenarios), use {@link TestPreferencesInitializer} methods or be sure to set
   * the config dir with {@link RuntimePreferences#setConfigDir(String)} before calling this method.
   */
  public static synchronized void init() {
    if (didInit) {
      return;
    }
    didInit = true;
    File srxFile = new File(StaticUtils.getConfigDir(), SRX.CONF_SENTSEG);
    SRX srx = SRX.loadSRX(srxFile);
    if (srx == null) {
      srx = SRX.getDefault();
    }
    m_srx = srx;

    File filtersFile = new File(StaticUtils.getConfigDir(), FilterMaster.FILE_FILTERS);
    Filters filters = null;
    try {
      filters = FilterMaster.loadConfig(filtersFile);
    } catch (Exception ex) {
      Log.log(ex);
    }
    if (filters == null) {
      filters = FilterMaster.createDefaultFiltersConfig();
    }
    m_filters = filters;

    File loadFile = getPreferencesFile();
    File saveFile = new File(StaticUtils.getConfigDir(), Preferences.FILE_PREFERENCES);
    m_preferences = new PreferencesImpl(new PreferencesXML(loadFile, saveFile));
  }
예제 #2
0
  /** Displays the filters setup dialog to allow customizing file filters in detail. */
  public void optionsSetupFileFiltersMenuItemActionPerformed() {
    FiltersCustomizer dlg =
        new FiltersCustomizer(
            mainWindow,
            false,
            FilterMaster.createDefaultFiltersConfig(),
            FilterMaster.loadConfig(StaticUtils.getConfigDir()),
            null);
    dlg.setVisible(true);
    if (dlg.getReturnStatus() == FiltersCustomizer.RET_OK) {
      // saving config
      FilterMaster.saveConfig(dlg.result, StaticUtils.getConfigDir());

      if (Core.getProject().isProjectLoaded()) {
        if (FilterMaster.loadConfig(Core.getProject().getProjectProperties().getProjectInternal())
            != null) {
          // project specific filters are in place. No need to reload project when
          // non-project-specific filters are changed
          return;
        }
        // asking to reload a project
        int res =
            JOptionPane.showConfirmDialog(
                mainWindow,
                OStrings.getString("MW_REOPEN_QUESTION"),
                OStrings.getString("MW_REOPEN_TITLE"),
                JOptionPane.YES_NO_OPTION);
        if (res == JOptionPane.YES_OPTION) ProjectUICommands.projectReload();
      }
    }
  }
예제 #3
0
 /**
  * Gets the prefs file to use. Looks in these places in this order:
  *
  * <ol>
  *   <li>omegat.prefs in config dir
  *   <li>omegat.prefs in install dir (defaults supplied with local install)
  * </ol>
  */
 private static File getPreferencesFile() {
   File prefsFile = new File(StaticUtils.getConfigDir(), FILE_PREFERENCES);
   if (prefsFile.exists()) {
     return prefsFile;
   }
   // If user prefs don't exist, fall back to defaults (possibly) bundled with OmegaT.
   prefsFile = new File(StaticUtils.installDir(), FILE_PREFERENCES);
   if (prefsFile.exists()) {
     return prefsFile;
   }
   return null;
 }
예제 #4
0
  public static void setSRX(SRX newSrx) {
    SRX oldValue = m_srx;
    m_srx = newSrx;

    File srxFile = new File(StaticUtils.getConfigDir() + SRX.CONF_SENTSEG);
    try {
      SRX.saveTo(m_srx, srxFile);
    } catch (IOException ex) {
      ex.printStackTrace();
    }
    m_propChangeSupport.firePropertyChange(Preferences.PROPERTY_SRX, oldValue, newSrx);
  }
예제 #5
0
  public static void setFilters(Filters newFilters) {
    Filters oldValue = m_filters;
    m_filters = newFilters;

    File filtersFile = new File(StaticUtils.getConfigDir(), FilterMaster.FILE_FILTERS);
    try {
      FilterMaster.saveConfig(m_filters, filtersFile);
    } catch (IOException ex) {
      ex.printStackTrace();
    }
    m_propChangeSupport.firePropertyChange(Preferences.PROPERTY_FILTERS, oldValue, newFilters);
  }
예제 #6
0
  public static void projectRemote(String url) {
    String dir = url.replace("/", "_").replace(':', '_');
    File projectDir = new File(StaticUtils.getConfigDir() + "/remoteProjects/" + dir);
    File projectFile = new File(projectDir, OConsts.FILE_PROJECT);

    byte[] data;
    try {
      projectDir.mkdirs();
      data = WikiGet.getURLasByteArray(url);
      FileUtils.writeByteArrayToFile(projectFile, data);
    } catch (Exception ex) {
      Log.logErrorRB(ex, "TEAM_REMOTE_RETRIEVE_ERROR", url);
      Core.getMainWindow().displayErrorRB(ex, "TEAM_REMOTE_RETRIEVE_ERROR", url);
      return;
    }

    projectOpen(projectDir);
  }
예제 #7
0
 public void optionsAccessConfigDirMenuItemActionPerformed() {
   openFile(new File(StaticUtils.getConfigDir()));
 }