private void refreshTextHeight() {
    getCmbHeightField().removeAllItems();

    boolean enabled = numericFieldNames.length > 0;
    // getCmbHeightField().setEnabled(enabled);
    // getRdBtnHeightField().setEnabled(enabled);

    if (!enabled) {
      getRdBtnFixedHeight().setSelected(true);
    }

    for (int i = 0; i < numericFieldNames.length; i++) {
      getCmbHeightField().addItem(numericFieldNames[i]);
    }

    if (layer.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
      AttrInTableLabelingStrategy aux = (AttrInTableLabelingStrategy) layer.getLabelingStrategy();
      try {
        getTxtHeightField().setText(String.valueOf(aux.getFixedSize()));
        getRdBtnFixedHeight().setSelected(aux.usesFixedSize());
        getRdBtnHeightField().setSelected(!aux.usesFixedSize());

        String item = aux.getHeightField();
        getCmbHeightField().setSelectedItem(item);

      } catch (ReadDriverException e) {
        // should never happen
        NotificationManager.addWarning(
            PluginServices.getText(this, "could_not_restore_text_height_field"), e);
      }
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#polylineFinished
   * (com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
   */
  public void polylineFinished(MeasureEvent event) throws BehaviorException {
    try {
      GeneralPathX gp = event.getGP();
      IGeometry geom = ShapeFactory.createPolyline2D(gp);
      FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();

      for (int i = 0; i < actives.length; i++) {
        if (actives[i] instanceof FLyrVect) {
          FLyrVect lyrVect = (FLyrVect) actives[i];
          FBitSet oldBitSet = lyrVect.getSource().getRecordset().getSelection();
          FBitSet newBitSet = lyrVect.queryByShape(geom, DefaultStrategy.INTERSECTS);
          if (event.getEvent().isControlDown()) newBitSet.xor(oldBitSet);
          lyrVect.getRecordset().setSelection(newBitSet);
        }
      }
    } catch (com.vividsolutions.jts.geom.TopologyException topEx) {
      NotificationManager.showMessageError(
          PluginServices.getText(
              null, "Failed_selecting_geometries_by_polyline_topology_exception_explanation"),
          topEx);
    } catch (Exception ex) {
      NotificationManager.showMessageError(
          PluginServices.getText(null, "Failed_selecting_geometries"), ex);
    }
  }
  private void refreshCmbUnits() {

    if (layer.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
      AttrInTableLabelingStrategy aux = (AttrInTableLabelingStrategy) layer.getLabelingStrategy();
      getCmbUnits().setSelectedUnitIndex(aux.getUnit());
    }
  }
  private void refreshCmbRefSystem() {

    if (layer.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
      AttrInTableLabelingStrategy aux = (AttrInTableLabelingStrategy) layer.getLabelingStrategy();
      getCmbReferenceSystem().setSelectedIndex(aux.getReferenceSystem());
    }
  }
  private void refreshColorFont() {

    getCmbColorField().removeAllItems();

    boolean enabled = integerFieldNames.length > 0;
    // getCmbColorField().setEnabled(enabled);
    // getRdBtnColorField().setEnabled(enabled);

    if (!enabled) {
      getRdBtnFixedColor().setSelected(true);
    }

    for (int i = 0; i < integerFieldNames.length; i++) {
      getCmbColorField().addItem(integerFieldNames[i]);
    }

    if (layer.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
      AttrInTableLabelingStrategy aux = (AttrInTableLabelingStrategy) layer.getLabelingStrategy();
      try {

        getRdBtnFixedColor().setSelected(aux.usesFixedColor());
        getRdBtnColorField().setSelected(!aux.usesFixedColor());

        String item = aux.getColorField();
        getCmbColorField().setSelectedItem(item);
        getColorChooser().setColor(aux.getFixedColor());

      } catch (ReadDriverException e) {
        // should never happen
        NotificationManager.addWarning(
            PluginServices.getText(this, "could_not_restore_color_field"), e);
      }
    }
  }
  private void refreshFont() {

    if (layer.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
      AttrInTableLabelingStrategy aux = (AttrInTableLabelingStrategy) layer.getLabelingStrategy();
      labelFont = aux.getFont();
    }
  }
 private DefaultCancellableMonitorable createCancelMonitor() {
   DefaultCancellableMonitorable monitor = new DefaultCancellableMonitorable();
   monitor.setInitialStep(0);
   monitor.setDeterminatedProcess(true);
   int clipSteps = 0;
   try {
     if (onlyClipLayerSelection) {
       FBitSet selection = overlayLayer.getRecordset().getSelection();
       clipSteps = selection.cardinality();
     } else {
       clipSteps = overlayLayer.getSource().getShapeCount();
     }
     int firstSteps = 0;
     if (onlyFirstLayerSelection) {
       FBitSet selection = firstLayer.getRecordset().getSelection();
       firstSteps = selection.cardinality();
     } else {
       firstSteps = firstLayer.getSource().getShapeCount();
     }
     int totalSteps = clipSteps + firstSteps;
     monitor.setFinalStep(totalSteps);
   } catch (ReadDriverException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return monitor;
 }
Example #8
0
  public void saveEdits(int numRows)
      throws ReadDriverException, InitializeWriterException, StopWriterVisitorException {
    if (limit == -1 || numRows == 0 || (numRows % limit) != 0) {
      return;
    }
    ies.endComplexRow(PluginServices.getText(this, "expression"));
    if ((layer != null) && layer.getSource() instanceof VectorialEditableAdapter) {
      VectorialEditableAdapter vea = (VectorialEditableAdapter) layer.getSource();
      ISpatialWriter spatialWriter = (ISpatialWriter) vea.getDriver();
      vea.cleanSelectableDatasource();
      // We want that the recordset of the layer shows the changes of the fields
      layer.setRecordset(vea.getRecordset());
      ILayerDefinition lyrDef = EditionUtilities.createLayerDefinition(layer);
      spatialWriter.initialize(lyrDef);
      vea.saveEdits(spatialWriter, EditionEvent.ALPHANUMERIC);
      vea.getCommandRecord().clearAll();
    } else {
      if (ies instanceof IWriteable) {
        IWriteable w = (IWriteable) ies;
        IWriter writer = w.getWriter();
        if (writer == null) {
        } else {
          ITableDefinition tableDef = ies.getTableDefinition();
          writer.initialize(tableDef);

          ies.saveEdits(writer, EditionEvent.ALPHANUMERIC);
          ies.getSelection().clear();
        }
      }
      ies.getCommandRecord().clearAll();
    }
    ies.startComplexRow();
  }
  // TODO Esto lo vamos a quitar, y lo vamos a hacer para cada
  // feature individual
  private Geometry computeJtsClippingPoly()
      throws ReadDriverException, ExpansionFileReadException, VisitorException {
    ScalableUnionVisitor visitor = new ScalableUnionVisitor(overlayLayer.getShapeType());

    Strategy strategy = StrategyManager.getStrategy(overlayLayer);
    if (onlyClipLayerSelection) {
      strategy.process(visitor, overlayLayer.getRecordset().getSelection());
    } else {
      strategy.process(visitor);
    }
    return visitor.getJtsConvexHull();
  }
Example #10
0
  private void storeOriginalSelection() throws ReadDriverException {
    FBitSet bs = layer.getSelectionSupport().getSelection();
    ReadableVectorial source = layer.getSource();

    source.start();

    for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
      IFeature feature = source.getFeature(i);
      pksSelected.add(feature.getID());
    }

    source.stop();
  }
  public void checkPreconditions() throws GeoprocessException {
    if (firstLayer == null) throw new GeoprocessException("Clip: capa de entrada a null");
    if (overlayLayer == null) throw new GeoprocessException("Clip: capa de clip a null");
    if (this.writer == null || this.schemaManager == null) {
      throw new GeoprocessException("Operacion de clip sin especificar capa de resultados");
    }

    try {
      if (overlayLayer.getShapeType() != XTypes.POLYGON
          && (overlayLayer.getShapeType() != XTypes.MULTI)) {
        throw new GeoprocessException("La capa de recorte no es de polígonos");
      }
    } catch (ReadDriverException e) {
      throw new GeoprocessException(
          "Error al tratar de chequear si la capa de recorte es de polígonos");
    }
  }
  @Override
  public void export(MapContext mapContext, FLyrVect layer) {
    try {
      JFileChooser jfc = new JFileChooser(lastPath);
      SimpleFileFilter filterShp =
          new SimpleFileFilter("dxf", PluginServices.getText(this, "dxf_files"));
      jfc.setFileFilter(filterShp);
      if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
          == JFileChooser.APPROVE_OPTION) {
        File newFile = jfc.getSelectedFile();
        String path = newFile.getAbsolutePath();
        if (!(path.toLowerCase().endsWith(".dxf"))) {
          path = path + ".dxf";
        }
        newFile = new File(path);

        DxfWriter writer = (DxfWriter) LayerFactory.getWM().getWriter("DXF Writer");
        SHPLayerDefinition lyrDef = new SHPLayerDefinition();
        SelectableDataSource sds = layer.getRecordset();
        FieldDescription[] fieldsDescrip = sds.getFieldsDescription();
        lyrDef.setFieldsDesc(fieldsDescrip);
        lyrDef.setFile(newFile);
        lyrDef.setName(newFile.getName());
        lyrDef.setShapeType(layer.getShapeType());
        writer.setFile(newFile);
        writer.initialize(lyrDef);
        writer.setProjection(layer.getProjection());
        DxfFieldsMapping fieldsMapping = new DxfFieldsMapping();
        // TODO: Recuperar aqu� los campos del cuadro de di�logo.
        writer.setFieldMapping(fieldsMapping);
        DXFMemoryDriver dxfDriver = new DXFMemoryDriver();
        dxfDriver.open(newFile);
        writeFeatures(mapContext, layer, writer, dxfDriver);
        String fileName = newFile.getAbsolutePath();
        lastPath = fileName.substring(0, fileName.lastIndexOf(File.separatorChar));
      }

    } catch (ReadDriverException e) {
      NotificationManager.addError(e.getMessage(), e);
    } catch (InitializeWriterException e) {
      NotificationManager.addError(e.getMessage(), e);
    } catch (DriverLoadException e) {
      NotificationManager.addError(e.getMessage(), e);
    }
  }
  /** @see com.iver.andami.plugins.IExtension#isEnabled() */
  public boolean isEnabled() {

    try {
      if (EditionUtilities.getEditionStatus()
          == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
        view = (View) PluginServices.getMDIManager().getActiveWindow();
        mapControl = view.getMapControl();
        if (CADExtension.getEditionManager().getActiveLayerEdited() == null) return false;
        FLyrVect lv = (FLyrVect) CADExtension.getEditionManager().getActiveLayerEdited().getLayer();
        if (polygon.isApplicable(lv.getShapeType())) {
          return true;
        }
      }
    } catch (ReadDriverException e) {
      NotificationManager.addError(e.getMessage(), e);
    }
    return false;
  }
  private void refreshCmbTextField() {
    getCmbTextField().removeAllItems();
    for (int i = 0; i < fieldNames.length; i++) {
      getCmbTextField().addItem(fieldNames[i]);
    }

    if (layer.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
      AttrInTableLabelingStrategy aux = (AttrInTableLabelingStrategy) layer.getLabelingStrategy();
      try {
        String item = aux.getTextField();
        getCmbTextField().setSelectedItem(item != null ? item : NO_FIELD_ITEM);
      } catch (ReadDriverException e) {
        // should never happen
        NotificationManager.addWarning(
            PluginServices.getText(this, "could_not_restore_text_field"), e);
      }
    }
  }
Example #15
0
 public void setTable(Table table) {
   // TODO: table is only needed to make table.refresh on the dialog.
   // Probably a fireevent can be done to avoid this
   this.table = table;
   layer = (FLyrVect) table.getModel().getAssociatedTable();
   if (layer == null) ies = table.getModel().getModelo();
   else ies = (VectorialEditableAdapter) layer.getSource();
   BitSet columnSelected = table.getSelectedFieldIndices();
   selectedIndex = columnSelected.nextSetBit(0);
   init();
 }
Example #16
0
  private void doRestoreSelection() throws ReadDriverException {
    ReadableVectorial source = layer.getSource();
    Collection<String> pks = new ArrayList<String>(pksSelected);
    source.start();
    FBitSet selection = layer.getSelectionSupport().getSelection();
    selection.clear();
    for (int i = 0; i < source.getShapeCount(); i++) {
      IFeature feat = source.getFeature(i);
      String id = feat.getID();
      if (pks.contains(id)) {
        pks.remove(id);
        selection.set(i);
        if (pks.isEmpty()) {
          break;
        }
      }
    }

    source.stop();
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com
   * .iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
   */
  public void rectangle(RectangleEvent event) throws BehaviorException {
    try {
      // mapCtrl.getMapContext().selectByRect(event.getWorldCoordRect());
      Rectangle2D rect = event.getWorldCoordRect();
      FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();
      for (int i = 0; i < actives.length; i++) {
        if (actives[i] instanceof FLyrVect) {
          FLyrVect lyrVect = (FLyrVect) actives[i];
          FBitSet oldBitSet = lyrVect.getSource().getRecordset().getSelection();
          FBitSet newBitSet = lyrVect.queryByRect(rect);
          if (event.getEvent().isControlDown()) newBitSet.xor(oldBitSet);
          lyrVect.getRecordset().setSelection(newBitSet);
        }
      }

    } catch (ReadDriverException e) {
      throw new BehaviorException("No se pudo hacer la selección");
    } catch (VisitorException e) {
      throw new BehaviorException("No se pudo hacer la selección");
    }
  }
  public void setModel(FLayer layer, ILabelingStrategy str) {
    this.layer = (FLyrVect) layer;
    // to allow the labeling of non-FLyrVect layers
    if (layer instanceof FLyrVect) {
      FLyrVect lv = (FLyrVect) layer;
      try {
        fieldNames = lv.getRecordset().getFieldNames();

        // detect the numeric fields
        ArrayList<String> l = new ArrayList<String>();
        ArrayList<String> lColors = new ArrayList<String>();

        for (int i = 0; i < fieldNames.length; i++) {
          switch (lv.getRecordset().getFieldType(i)) {
            case Types.DECIMAL:
            case Types.NUMERIC:
            case Types.FLOAT:
            case Types.REAL:
            case Types.DOUBLE:
              l.add(fieldNames[i]);
              break;
            case Types.INTEGER:
            case Types.SMALLINT:
            case Types.TINYINT:
            case Types.BIGINT:
              lColors.add(fieldNames[i]);
              l.add(fieldNames[i]);
              break;
          }
        }
        numericFieldNames = l.toArray(new String[l.size()]);
        integerFieldNames = lColors.toArray(new String[lColors.size()]);
      } catch (ReadDriverException e) {
        NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e);
      }

      refreshControls();
    }
  }
  public PipeCADToolContext(PipeCADTool owner) {
    super();

    pointLayers = Preferences.getPointLayers();

    try {
      geometries = new ArrayList<IGeometry>();
      IFeatureIterator iterator;
      for (FLyrVect layer : pointLayers) {
        iterator = layer.getSource().getFeatureIterator();
        while (iterator.hasNext()) {
          geometries.add(iterator.next().getGeometry());
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    _owner = owner;
    setState(Polyline.FirstPoint);
    Polyline.FirstPoint.Entry(this);
  }
 /**
  * This method initializes layerTable
  *
  * @return javax.swing.JTable
  */
 private TableLayers getTableLayers() {
   if (tableLayers == null) {
     tableLayers = new TableLayers(layer.getSource(), legend);
   }
   return tableLayers;
 }
Example #21
0
 /**
  * @param layer Must be in edition or a ClassCastException will be thrown
  * @param selectedIndex The index of the field in the FieldDescription which will be filled by the
  *     expression
  */
 public void setLayer(FLyrVect layer, int selectedIndex) {
   this.layer = layer;
   ies = (VectorialEditableAdapter) layer.getSource();
   this.selectedIndex = selectedIndex;
   init();
 }
 public void setLayer(FLayer lyr, ILegend l) {
   layer = (FLyrVect) lyr;
   legend = (IVectorLegend) l;
   getTableLayers().setSource(layer.getSource());
   getTableLayers().setLegend(legend);
 }
Example #23
0
  public void doImportField(ImportFieldParams params) throws Exception {

    if (!params.isValid()) {
      // TODO: ver que excepcion a lanzar
      throw new Exception("invalid Paramenters: " + params.getValidationMsg());
    }

    IEditableSource edSource = null;
    IEditableSource edSourceToImport = params.getTableToImport().getModelo();

    SelectableDataSource rsSourceToImport = edSourceToImport.getRecordset();

    ArrayList fieldsToImport = new ArrayList();
    ArrayList fieldsToImport_des = new ArrayList();
    ArrayList fieldsToImport_pos = new ArrayList();
    Iterator iter;
    Map values;
    int i;

    try {
      rsSourceToImport.start();

      // Cargamos la lista con los campos que vamos a importar
      iter = params.getFieldsToImport().iterator();
      FielToImport fieldToImport;
      while (iter.hasNext()) {
        fieldToImport = (FielToImport) iter.next();
        if (fieldToImport.toImport) {
          fieldsToImport.add(fieldToImport);
        }
      }

      // Cargamos la lista de la definicio de capos desde la
      // tabla a importar
      iter = fieldsToImport.iterator();
      FieldDescription[] toImportAllFieldsDescription = edSourceToImport.getFieldsDescription();
      FieldDescription tmpFieldDesc, newFieldDesc;

      while (iter.hasNext()) {
        fieldToImport = (FielToImport) iter.next();
        for (i = 0; i < toImportAllFieldsDescription.length; i++) {
          tmpFieldDesc = toImportAllFieldsDescription[i];
          if (tmpFieldDesc.getFieldName().equals(fieldToImport.originalFieldName)) {
            newFieldDesc = tmpFieldDesc.cloneField();
            newFieldDesc.setFieldLength(tmpFieldDesc.getFieldLength());
            newFieldDesc.setFieldName(fieldToImport.fieldNameToUse);
            newFieldDesc.setDefaultValue(tmpFieldDesc.getDefaultValue());
            newFieldDesc.setFieldAlias(fieldToImport.fieldNameToUse);
            newFieldDesc.setFieldType(tmpFieldDesc.getFieldType());
            fieldsToImport_des.add(newFieldDesc);
            fieldsToImport_pos.add(new Integer(i));
          }
        }
      }

      // Cagamos los valores en un hash
      values =
          this.loadValuesFromSource(
              rsSourceToImport, params.getTableToImportField(), fieldsToImport_pos);
    } catch (Exception e) {
      throw e;
    } finally {

      rsSourceToImport.stop();
      rsSourceToImport = null;
      edSourceToImport = null;
    }

    FLyrVect layer = null;

    boolean changeEditing = false;
    // Ponemos en edicion si no lo esta
    if (params.getTable().getAssociatedTable() instanceof FLyrVect) {
      // Viene de una capa
      layer = (FLyrVect) params.getTable().getAssociatedTable();
      if (!layer.isEditing()) {
        layer.setEditing(true);
        changeEditing = true;
      }
      edSource = (VectorialEditableAdapter) layer.getSource();
    } else {
      // es una tabla normal
      edSource = params.getTable().getModelo();
      if (!edSource.isEditing()) {
        edSource.startEdition(EditionEvent.ALPHANUMERIC);
        changeEditing = true;
      }
    }

    edSource.startComplexRow();

    int originalFieldsCount = edSource.getRecordset().getFieldCount();
    int finalFieldsCount = originalFieldsCount + fieldsToImport.size();
    // Añadimos los campos
    iter = fieldsToImport_des.iterator();
    while (iter.hasNext()) {
      ((EditableAdapter) edSource).addField((FieldDescription) iter.next());
    }

    // Recorremos la fuente y vamos actualizando
    int rowCount = edSource.getRowCount();
    IRowEdited originalRow;
    IRow newRow;
    IRowEdited newRowEdited;
    Value[] finalValues;
    Value[] originalValues;
    Value[] valuesToUse;
    Value key;
    int column;
    int srcKeyPos = edSource.getRecordset().getFieldIndexByName(params.getTableField());
    for (i = 0; i < rowCount; i++) {
      originalRow = edSource.getRow(i);

      key = originalRow.getAttribute(srcKeyPos);
      valuesToUse = (Value[]) values.get(key);
      if (valuesToUse == null) {
        continue;
      }
      newRow = originalRow.getLinkedRow().cloneRow();
      originalValues = newRow.getAttributes();
      finalValues = new Value[finalFieldsCount];
      System.arraycopy(originalValues, 0, finalValues, 0, originalFieldsCount);
      for (column = 0; column < valuesToUse.length; column++) {
        finalValues[column + originalFieldsCount] = valuesToUse[column];
      }
      newRow.setAttributes(finalValues);
      newRowEdited = new DefaultRowEdited(newRow, IRowEdited.STATUS_MODIFIED, i);
      edSource.modifyRow(
          newRowEdited.getIndex(), newRowEdited.getLinkedRow(), "", EditionEvent.ALPHANUMERIC);
    }

    edSource.endComplexRow("Import fields");
    if (changeEditing) {
      if (layer == null) {
        IWriter writer = ((IWriteable) edSource).getWriter();
        writer.initialize(edSource.getTableDefinition());
        edSource.stopEdition(writer, EditionEvent.ALPHANUMERIC);
        edSource.getSelection().clear();

      } else {
        layer.setRecordset(edSource.getRecordset());
        ISpatialWriter spatialWriter =
            (ISpatialWriter) ((VectorialEditableAdapter) edSource).getWriter();
        ILayerDefinition lyrDef = EditionUtilities.createLayerDefinition(layer);
        spatialWriter.initialize(lyrDef);
        edSource.stopEdition(spatialWriter, EditionEvent.ALPHANUMERIC);
        layer.setEditing(false);
        edSource.getSelection().clear();
      }
    }
  }
Example #24
0
 private boolean isDBLayer() {
   return layer.getSource() instanceof VectorialDBAdapter;
 }