Exemplo n.º 1
0
  /**
   * This function takes an OMGraphicList and loads each one with the array representing the records
   * in the dbf file. Each graphics stores the graphic in its object slot.
   */
  public void loadDbfModelIntoGraphics(OMGraphicList list) {
    if (list != null && dbfModel.getRowCount() > 0) {
      int numgraphics = list.size();

      for (int i = 0; i < numgraphics; i++) {
        try {
          OMGraphic omg = list.getOMGraphicAt(i);
          Integer recnum = (Integer) (omg.getAttribute(ShapeConstants.SHAPE_INDEX_ATTRIBUTE));
          // OFF BY ONE!!! The shape record numbers
          // assigned to the records start with 0, while
          // everything else we do starts with 0. The DbfTableModel
          // follows java convention and starts at 0. The integer
          // stored in the OMG should know it too.
          Object inforec = dbfModel.getRecord(recnum.intValue());
          omg.putAttribute(ShapeConstants.SHAPE_DBF_INFO_ATTRIBUTE, inforec);
        } catch (ClassCastException cce) {
          if (Debug.debugging("shape")) {
            cce.printStackTrace();
          }
        } catch (NullPointerException npe) {
          npe.printStackTrace();
        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * DeterminePoliticalAreas goes over a list of omgraphics, and spits out a hashtable that holds
   * PoliticalArea objects for every area key. When an ID is found in the graphics, it is checked in
   * the hashtable for like graphics, and added to that PoliticalArea if found. If not found, a new
   * PoliticalArea is created and placed in the Hashtable. This will duplicate graphics if you call
   * it more than once for the same graphic list.
   *
   * @param graphicList the list of graphics. The top level graphic entries on the list represent
   *     areas.
   */
  public Hashtable determinePoliticalAreas(OMGraphicList graphicList, Hashtable poli_areas) {

    // Simple case. No graphics means an empty list of regions.
    String name = null;
    String key = null;

    if (graphicList != null) {
      int size = graphicList.size();
      for (int i = 0; i < size; i++) {
        OMGraphic graphic = graphicList.getOMGraphicAt(i);
        // below should be a vector like [ "Massachusetts",
        // "MA" ];

        Object obj = graphic.getAttribute(ShapeConstants.SHAPE_DBF_INFO_ATTRIBUTE);
        if (obj == null) {
          if (Debug.debugging("areas")) {
            Debug.error("AreaHandler: No attributes for graphic #" + i);
          }
          continue;
        }

        if (obj instanceof Vector) {
          Vector pair = (Vector) obj;

          name = (String) pair.elementAt(nameIndex);
          key = ((String) pair.elementAt(keyIndex)).toUpperCase().intern();
          if (Debug.debugging("areas")) {
            Debug.output("AreaHandler: looking at " + name + ", " + key);
          }
        } else if (obj instanceof String) {
          // Assume that the key is stored here, I guess.
          key = (String) obj;
          if (Debug.debugging("areas")) {
            Debug.output("AreaHandler: String app object, looking at " + key);
          }
        } else {
          if (Debug.debugging("areas")) {
            Debug.output("AreaHandler: Unidentified app object type " + obj);
          }
        }

        // Get the political area object for this keyiation.
        PoliticalArea area = (PoliticalArea) poli_areas.get(key);

        if (area == null) { // key is not in table
          area = new PoliticalArea(name, key);
          poli_areas.put(key, area); // add it to the table
          // AreaDrawParams adp =
          // (AreaDrawParams)drawingParams.get(key);
          // if (adp != null) {
          // area.setDrawingAttributes(adp.drawingAttributes);
          // }
        }

        // Add the graphic to the list for this political
        // area.
        area.addGraphic(graphic);
      }

      if (Debug.debugging("areas")) {
        Debug.output(
            "AreaHandler: Finished determinePoliticalAreas: "
                + poli_areas.size()
                + " areas defined.");
      }
    }

    return poli_areas;
  }