Exemplo n.º 1
0
  /**
   * Put the simulation that has just been opened into the Simulation menu's recently opened file
   * list.
   *
   * @param newSelected the newly opened simulation
   */
  private void saveToRecent(final String newSelected) {
    String[] recent = siafuConfig.getStringArray("ui.recentsimulation");
    String[] newRecent = new String[AMOUNT_OF_RECENT_ITEMS];

    newRecent[0] = newSelected;
    for (int i = 0; i < AMOUNT_OF_RECENT_ITEMS - 1 && i < recent.length; i++) {
      if (newSelected.equals(recent[i])) {
        continue;
      } else {
        newRecent[i + 1] = recent[i];
      }
    }

    siafuConfig.setProperty("ui.recentsimulation", newRecent);
    try {
      siafuConfig.save();
    } catch (ConfigurationException e) {
      throw new RuntimeException("Can not save the configuration file", e);
    }
  }
Exemplo n.º 2
0
  /**
   * Add an item to the recently opened list in the simulation menu.
   *
   * @param parent the parent menu
   */
  private void addRecent(final Menu parent) {
    String[] recent = siafuConfig.getStringArray("ui.recentsimulation");
    if (recent != null && recent.length != 0) {
      new MenuItem(parent, SWT.SEPARATOR);

      for (int i = 0; i < recent.length; i++) {
        MenuItem m = new MenuItem(parent, SWT.PUSH);
        String name = recent[i].substring(recent[i].lastIndexOf(File.separator) + 1);
        int length = recent[i].length();
        if (length > MAXIMUM_RECENT_ENTRY_LENGTH) {
          length = MAXIMUM_RECENT_ENTRY_LENGTH;
        }
        String path = "[" + recent[i].substring(0, length) + "]";
        m.setText("&" + (i + 1) + " " + name + " " + path);
        m.setData(recent[i]);
        m.addSelectionListener(
            new SelectionAdapter() {
              public void widgetSelected(final SelectionEvent e) {
                openSimulation((String) e.widget.getData());
              }
            });
      }
    }
  }