コード例 #1
0
  /**
   * DOCUMENT ME!
   *
   * @param mapContext DOCUMENT ME!
   * @param layer DOCUMENT ME!
   * @param duplicate DOCUMENT ME!
   * @throws ReadDriverException
   * @throws EditionException DOCUMENT ME!
   * @throws DriverIOException DOCUMENT ME!
   */
  public void saveToShp(MapContext mapContext, Annotation_Layer layer, String duplicate)
      throws ReadDriverException {
    try {
      JFileChooser jfc = new JFileChooser();
      SimpleFileFilter filterShp =
          new SimpleFileFilter("shp", PluginServices.getText(this, "shp_files"));
      jfc.setFileFilter(filterShp);

      if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
          == JFileChooser.APPROVE_OPTION) {
        File newFile = jfc.getSelectedFile();
        String path = newFile.getAbsolutePath();

        if (newFile.exists()) {
          int resp =
              JOptionPane.showConfirmDialog(
                  (Component) PluginServices.getMainFrame(),
                  PluginServices.getText(this, "fichero_ya_existe_seguro_desea_guardarlo"),
                  PluginServices.getText(this, "guardar"),
                  JOptionPane.YES_NO_OPTION);

          if (resp != JOptionPane.YES_OPTION) {
            return;
          }
        }

        if (!(path.toLowerCase().endsWith(".shp"))) {
          path = path + ".shp";
        }

        newFile = new File(path);

        SelectableDataSource sds = layer.getRecordset();
        FieldDescription[] fieldsDescrip = sds.getFieldsDescription();

        ShpWriter writer = (ShpWriter) LayerFactory.getWM().getWriter("Shape Writer");
        Driver driver = null;

        SHPLayerDefinition lyrDefPoint = new SHPLayerDefinition();
        lyrDefPoint.setFieldsDesc(fieldsDescrip);

        File filePoints = new File(path);
        lyrDefPoint.setFile(filePoints);
        lyrDefPoint.setName(filePoints.getName());
        lyrDefPoint.setShapeType(FShape.POINT);
        writer.setFile(filePoints);
        writer.initialize(lyrDefPoint);
        driver = getOpenAnnotationDriver(filePoints);
        writeFeatures(mapContext, layer, writer, driver, duplicate);
      }
    } catch (InitializeWriterException e) {
      throw new ReadDriverException(layerAnnotation.getName(), e);
    } catch (DriverLoadException e) {
      throw new ReadDriverException(layerAnnotation.getName(), e);
    } catch (IOException e) {
      throw new ReadDriverException(layerAnnotation.getName(), e);
    }
  }
コード例 #2
0
  @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);
    }
  }