// Return a collection of common actions.
  // Each action in the collection is a compound
  // action. There is one compound action in the collection
  // for each action which is common to all viewlets in the selection.
  public Collection getCommonActions() {
    Collection commonActions = new LinkedList();
    Collection firstViewletsActions;
    ViewletAction currentAction;
    Iterator viewletsIterator;
    Iterator firstViewletsActionsIterator;
    Viewlet firstViewlet, currentViewlet;
    List currentViewletActions;
    boolean allContainAction;

    if (isEmpty()) {
      return (Collections.EMPTY_SET);
    }
    firstViewlet = (Viewlet) (iterator().next());
    firstViewletsActions = firstViewlet.getActions();
    firstViewletsActionsIterator = firstViewletsActions.iterator();

    // for each currentAction in the first viewlet's actions
    while (firstViewletsActionsIterator.hasNext()) {
      currentAction = (ViewletAction) firstViewletsActionsIterator.next();
      viewletsIterator = iterator();
      allContainAction = true;
      // test whether each viewlet has an action equals() to currentAction
      while (viewletsIterator.hasNext() && allContainAction) {
        currentViewlet = (Viewlet) viewletsIterator.next();
        if (!currentViewlet.getActions().contains(currentAction)) {
          allContainAction = false;
        }
      }
      if (allContainAction) {
        commonActions.add(currentAction.createCompoundAction(this));
      }
    }
    return (commonActions);
  }
Пример #2
0
    protected void loadAirspacesFromPath(String path, Collection<Airspace> airspaces) {
      File file = ExampleUtil.saveResourceToTempFile(path, ".zip");
      if (file == null) return;

      try {
        ZipFile zipFile = new ZipFile(file);

        ZipEntry entry = null;
        for (Enumeration<? extends ZipEntry> e = zipFile.entries();
            e.hasMoreElements();
            entry = e.nextElement()) {
          if (entry == null) continue;

          String name = WWIO.getFilename(entry.getName());

          if (!(name.startsWith("gov.nasa.worldwind.render.airspaces") && name.endsWith(".xml")))
            continue;

          String[] tokens = name.split("-");

          try {
            Class c = Class.forName(tokens[0]);
            Airspace airspace = (Airspace) c.newInstance();
            BufferedReader input =
                new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry)));
            String s = input.readLine();
            airspace.restoreState(s);
            airspaces.add(airspace);

            if (tokens.length >= 2) {
              airspace.setValue(AVKey.DISPLAY_NAME, tokens[1]);
            }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }