/**
   * Create a collection of layer lists and their included layers described by an array of XML
   * layer-list description elements.
   *
   * <p>Any exceptions occurring during creation of the layer lists or their included layers are
   * logged and not re-thrown. The layers associated with the exceptions are not included in the
   * returned layer list.
   *
   * @param elements the XML elements describing the layer lists to create.
   * @param params any parameters to apply when creating the included layers.
   * @return an array containing the specified layer lists.
   */
  protected LayerList[] createLayerLists(Element[] elements, AVList params) {
    ArrayList<LayerList> layerLists = new ArrayList<LayerList>();

    for (Element element : elements) {
      try {
        String href = WWXML.getText(element, "@href");
        if (href != null && href.length() > 0) {
          Object o = this.createFromConfigSource(href, params);
          if (o == null) continue;

          if (o instanceof Layer) {
            LayerList ll = new LayerList();
            ll.add((Layer) o);
            o = ll;
          }

          if (o instanceof LayerList) {
            LayerList list = (LayerList) o;
            if (list != null && list.size() > 0) layerLists.add(list);
          } else if (o instanceof LayerList[]) {
            LayerList[] lists = (LayerList[]) o;
            if (lists != null && lists.length > 0) layerLists.addAll(Arrays.asList(lists));
          } else {
            String msg =
                Logging.getMessage("LayerFactory.UnexpectedTypeForLayer", o.getClass().getName());
            Logging.logger().log(java.util.logging.Level.WARNING, msg);
          }

          continue;
        }

        String title = WWXML.getText(element, "@title");
        Element[] children = WWXML.getElements(element, "./Layer", null);
        if (children != null && children.length > 0) {
          LayerList list = this.createLayerList(children, params);
          if (list != null && list.size() > 0) {
            layerLists.add(list);
            if (title != null && title.length() > 0) list.setValue(AVKey.DISPLAY_NAME, title);
          }
        }
      } catch (Exception e) {
        Logging.logger().log(java.util.logging.Level.WARNING, e.getMessage(), e);
        // keep going to create other layers
      }
    }

    return layerLists.toArray(new LayerList[layerLists.size()]);
  }
    public AppFrame() {
      super(true, true, false);

      // Create list of positions along the control line.
      List<Position> positions =
          Arrays.asList(
              Position.fromDegrees(49.0457, -122.8115, 100),
              Position.fromDegrees(49.0539, -122.8091, 110),
              Position.fromDegrees(49.0621, -122.7937, 120),
              Position.fromDegrees(49.0681, -122.8044, 130),
              Position.fromDegrees(49.0682, -122.7730, 140),
              Position.fromDegrees(49.0482, -122.7764, 150),
              Position.fromDegrees(49.0498, -122.7466, 140),
              Position.fromDegrees(49.0389, -122.7453, 130),
              Position.fromDegrees(49.0321, -122.7759, 120),
              Position.fromDegrees(49.0394, -122.7689, 110),
              Position.fromDegrees(49.0629, -122.7666, 100));

      // We will generate four paths parallel to the control path. Allocate lists to store the
      // positions of these
      // paths.
      List<Position> pathPositions1 = new ArrayList<Position>();
      List<Position> pathPositions2 = new ArrayList<Position>();
      List<Position> pathPositions3 = new ArrayList<Position>();
      List<Position> pathPositions4 = new ArrayList<Position>();

      Globe globe = getWwd().getModel().getGlobe();

      // Generate two sets of lines parallel to the control line. The positions will be added to the
      // pathPosition lists.
      WWMath.generateParallelLines(positions, pathPositions1, pathPositions2, 50, globe);
      WWMath.generateParallelLines(positions, pathPositions3, pathPositions4, 100, globe);

      // Create Path objects from the position lists, and add them to a layer.
      RenderableLayer layer = new RenderableLayer();
      this.addPath(layer, positions, "Control Path");
      this.addPath(layer, pathPositions1, "Path 1");
      this.addPath(layer, pathPositions2, "Path 2");
      this.addPath(layer, pathPositions3, "Path 3");
      this.addPath(layer, pathPositions4, "Path 4");

      insertBeforePlacenames(getWwd(), layer);
    }
 public List<Tile> getTiles() {
   if (tileKeys.isEmpty()) {
     Tile[] tiles = buildTiles(this.placeNameService, this);
     // load tileKeys
     for (Tile t : tiles) {
       tileKeys.add(t.getFileCachePath());
       WorldWind.getMemoryCache(Tile.class.getName()).add(t.getFileCachePath(), t);
     }
     return Arrays.asList(tiles);
   } else {
     List<Tile> dataTiles = new ArrayList<Tile>();
     for (String s : tileKeys) {
       Tile t = (Tile) WorldWind.getMemoryCache(Tile.class.getName()).getObject(s);
       if (t != null) {
         dataTiles.add(t);
       }
     }
     return dataTiles;
   }
 }
  private void draw(DrawContext dc) {
    this.referencePoint = this.computeReferencePoint(dc);

    this.assembleTiles(dc); // Determine the tiles to draw.

    if (this.currentTiles.size() >= 1) {
      MercatorTextureTile[] sortedTiles = new MercatorTextureTile[this.currentTiles.size()];
      sortedTiles = this.currentTiles.toArray(sortedTiles);
      Arrays.sort(sortedTiles, levelComparer);

      GL gl = dc.getGL();

      if (this.isUseTransparentTextures() || this.getOpacity() < 1) {
        gl.glPushAttrib(GL.GL_COLOR_BUFFER_BIT | GL.GL_POLYGON_BIT | GL.GL_CURRENT_BIT);
        gl.glColor4d(1d, 1d, 1d, this.getOpacity());
        gl.glEnable(GL.GL_BLEND);
        gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
      } else {
        gl.glPushAttrib(GL.GL_COLOR_BUFFER_BIT | GL.GL_POLYGON_BIT);
      }

      gl.glPolygonMode(GL.GL_FRONT, GL.GL_FILL);
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);

      dc.setPerFrameStatistic(
          PerformanceStatistic.IMAGE_TILE_COUNT, this.tileCountName, this.currentTiles.size());
      dc.getGeographicSurfaceTileRenderer().renderTiles(dc, this.currentTiles);

      gl.glPopAttrib();

      if (this.drawTileIDs) this.drawTileIDs(dc, this.currentTiles);

      if (this.drawBoundingVolumes) this.drawBoundingVolumes(dc, this.currentTiles);

      this.currentTiles.clear();
    }

    this.sendRequests();
    this.requestQ.clear();
  }
    public void actionPerformed(ActionEvent e) {
      if (!this.isEnabled()) {
        return;
      }

      if (NEW_AIRSPACE.equals(e.getActionCommand())) {
        this.createNewEntry(this.getView().getSelectedFactory());
      } else if (CLEAR_SELECTION.equals(e.getActionCommand())) {
        this.selectEntry(null, true);
      } else if (SIZE_NEW_SHAPES_TO_VIEWPORT.equals(e.getActionCommand())) {
        if (e.getSource() instanceof AbstractButton) {
          boolean selected = ((AbstractButton) e.getSource()).isSelected();
          this.setResizeNewShapesToViewport(selected);
        }
      } else if (ENABLE_EDIT.equals(e.getActionCommand())) {
        if (e.getSource() instanceof AbstractButton) {
          boolean selected = ((AbstractButton) e.getSource()).isSelected();
          this.setEnableEdit(selected);
        }
      } else if (OPEN.equals(e.getActionCommand())) {
        this.openFromFile();
      } else if (OPEN_URL.equals(e.getActionCommand())) {
        this.openFromURL();
      } else if (OPEN_DEMO_AIRSPACES.equals(e.getActionCommand())) {
        this.openFromPath(DEMO_AIRSPACES_PATH);
        this.zoomTo(
            LatLon.fromDegrees(47.6584074779224, -122.3059199579634),
            Angle.fromDegrees(-152),
            Angle.fromDegrees(75),
            750);
      } else if (REMOVE_SELECTED.equals(e.getActionCommand())) {
        this.removeEntries(Arrays.asList(this.getSelectedEntries()));
      } else if (SAVE.equals(e.getActionCommand())) {
        this.saveToFile();
      } else if (SELECTION_CHANGED.equals(e.getActionCommand())) {
        this.viewSelectionChanged();
      }
    }