Ejemplo n.º 1
0
  private boolean setupDefaultProperties() {
    fontProps = new Properties();

    // create program properties with default
    try {
      // If you application needs to look at other font directories
      // they can be added via the readSystemFonts method.
      fontManager.readSystemFonts(null);
      fontProps = fontManager.getFontProperties();

    } catch (Exception ex) {
      if (getBoolean("application.showLocalStorageDialogs", true)) {
        Resources.showMessageDialog(
            null,
            JOptionPane.ERROR_MESSAGE,
            messageBundle,
            "fontManager.properties.title",
            "manager.properties.session.readError",
            ex);
      } // log the error
      if (logger.isLoggable(Level.WARNING)) {
        logger.log(Level.WARNING, "Error loading default properties", ex);
      }
      return false;
    }
    return true;
  }
Ejemplo n.º 2
0
 public synchronized void saveProperties() {
   if (ownLock()) {
     try {
       FileOutputStream out = new FileOutputStream(propertyFile);
       try {
         fontProps.store(out, "-- ICEpf Font properties --");
       } finally {
         out.close();
       }
       recordMofifTime();
     } catch (IOException ex) {
       // check to make sure the storage relate dialogs can be shown
       if (getBoolean("application.showLocalStorageDialogs", true)) {
         Resources.showMessageDialog(
             null,
             JOptionPane.ERROR_MESSAGE,
             messageBundle,
             "fontManager.properties.title",
             "manager.properties.saveError",
             ex);
       }
       // log the error
       if (logger.isLoggable(Level.WARNING)) {
         logger.log(Level.WARNING, "Error saving font properties cache", ex);
       }
     }
   }
 }
Ejemplo n.º 3
0
  private void setupHomeDir(String homeString) {
    if (homeString == null) {
      homeString = sysProps.getProperty("swingri.home");
    }

    if (homeString != null) {
      dataDir = new File(homeString);
    } else {
      userHome = new File(sysProps.getProperty("user.home"));
      String dataDirStr = props.getString("application.datadir", DEFAULT_HOME_DIR);
      dataDir = new File(userHome, dataDirStr);
    }

    if (!dataDir.isDirectory()) {
      String path = dataDir.getAbsolutePath();
      boolean create;
      if (props.hasUserRejectedCreatingLocalDataDir()) {
        create = false;
      } else if (getBoolean("application.showLocalStorageDialogs", true)) {
        create =
            Resources.showConfirmDialog(
                null,
                messageBundle,
                "fontManager.properties.title",
                "manager.properties.createNewDirectory",
                path);
        if (!create) props.setUserRejectedCreatingLocalDataDir();
      } else {
        // Always create local-storage directory if show user prompt dialog setting is false.
        create = true;
      }

      if (!create) {
        dataDir = null;
      } else {
        dataDir.mkdirs();
        if (!dataDir.isDirectory()) {
          // check to make sure that dialog should be shown on the error.
          if (getBoolean("application.showLocalStorageDialogs", true)) {
            Resources.showMessageDialog(
                null,
                JOptionPane.ERROR_MESSAGE,
                messageBundle,
                "fontManager.properties.title",
                "manager.properties.failedCreation",
                dataDir.getAbsolutePath());
          }
          dataDir = null;
        }
      }
    }
  }
Ejemplo n.º 4
0
  public synchronized void loadProperties() {

    if (dataDir != null) {
      propertyFile = new File(dataDir, USER_FILENAME);
      // load font properties from last invocation
      if (propertyFile.exists()) {
        try {
          InputStream in = new FileInputStream(propertyFile);
          try {
            fontProps.load(in);
            fontManager.setFontProperties(fontProps);
          } finally {
            in.close();
          }
        } catch (IOException ex) {
          // check to make sure the storage relate dialogs can be shown
          if (getBoolean("application.showLocalStorageDialogs", true)) {
            Resources.showMessageDialog(
                null,
                JOptionPane.ERROR_MESSAGE,
                messageBundle,
                "fontManager.properties.title",
                "manager.properties.session.readError",
                ex);
          }
          // log the error
          if (logger.isLoggable(Level.WARNING)) {
            logger.log(Level.WARNING, "Error loading font properties cache", ex);
          }
        } catch (IllegalArgumentException e) {
          // propblem parsing fontProps, reread teh file
          setupDefaultProperties();
          saveProperties();
        }
      }
      // If no font data, then read font data and save the new file.
      else {
        setupDefaultProperties();
        saveProperties();
      }
    }
  }
Ejemplo n.º 5
0
  private void setupLock() {
    if (dataDir == null) {
      lockDir = null;
    } else {
      File dir = new File(dataDir, LOCK_FILE);
      if (!dir.mkdir()) {

        dir.delete();
        if (!dir.mkdir()) {
          dir = null;
          if (getBoolean("application.showLocalStorageDialogs", true)) {
            Resources.showMessageDialog(
                null,
                JOptionPane.ERROR_MESSAGE,
                messageBundle,
                "fontManager.properties.title",
                "manager.properties.session.nolock",
                LOCK_FILE);
          }
        }
      }
      lockDir = dir;
    }
  }