Example #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();
        }
      }
    }
  }
Example #2
0
  /**
   * Given the shapefile record number, find the drawing parameters from the DBF model that should
   * be used for the shape. Returns the default coloring if the key for the drawing parameters isn't
   * found.
   *
   * @param recordNumber the zero-based record number from the OMGraphicList
   */
  public DrawingAttributes getDrawParamsFromDBF(int recordNumber) {
    if (dbfModel == null) {
      return drawingAttributes;
    }

    if (dbfModel == null || dbfModel.getRowCount() < recordNumber) {
      if (Debug.debugging("areas")) {
        Debug.output("AreaHandler.getDrawParameters: record " + recordNumber + " has no info");
      }
      return drawingAttributes;
    }

    Object keyObj = dbfModel.getValueAt(recordNumber, keyIndex);
    String key = null;
    PoliticalArea pa = null;

    if (keyObj != null) {
      key = createStringFromKeyObject(keyObj);
      pa = (PoliticalArea) politicalAreas.get(key);
    }

    if (pa == null) {
      if (Debug.debugging("areas")) {
        Debug.output(
            "AreaHandler.getDrawParameters: record "
                + recordNumber
                + " has key \""
                + key
                + "\" and DEFAULT attributes");
      }
      return drawingAttributes;
    } else {
      // Only bother with this the first time around.
      if (pa.name == null) {
        // String name = (String) info.elementAt(nameIndex);
        String name = (String) dbfModel.getValueAt(recordNumber, nameIndex);
        if (name != null) {
          pa.name = name;
        } else {
          pa.name = "";
        }
      }

      if (Debug.debugging("areas")) {
        Debug.output(
            "AreaHandler.getDrawParameters: record "
                + recordNumber
                + " has key \""
                + key
                + "\" and SPECIALIZED attributes");
      }
      return pa.drawingAttributes;
    }
  }
Example #3
0
 /**
  * Get the name of the object at the index of the list. This is a zero-based index. Remember, the
  * record number out of the shape file is one-based. The index stored in the OMGraphic attribute
  * created from the shape files is zero-based to help with lookups.
  *
  * @param integer a zero-based index.
  * @return an empty string if something goes wrong, or the name as a String.
  */
 public String getName(Integer integer) {
   try {
     if (infoFile != null) {
       Vector vector = infoFile.getRecord(integer.intValue());
       if (vector != null) {
         return (String) vector.elementAt(nameIndex);
       }
     } else if (dbfModel != null) {
       Object obj = dbfModel.getValueAt(integer.intValue(), nameIndex);
       if (obj != null) {
         if (obj instanceof String) {
           return (String) obj;
         } else {
           return obj.toString();
         }
       }
     }
   } catch (ClassCastException cce) {
   }
   return "";
 }