/**
   * 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);
    }
  }
  public ExportStatisticsFile(List<MyObjectStatistics> valores) {

    JFileChooser jfc = new JFileChooser(lastPath);
    jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());

    // Adding required extensions (dbf, csv)
    dbfExtensionsSupported = new Hashtable<String, MyFileFilter>();
    csvExtensionsSupported = new Hashtable<String, MyFileFilter>();
    dbfExtensionsSupported.put(
        "dbf", new MyFileFilter("dbf", PluginServices.getText(this, "Ficheros_dbf"), "dbf"));
    csvExtensionsSupported.put(
        "csv", new MyFileFilter("csv", PluginServices.getText(this, "Ficheros_csv"), "csv"));

    Iterator<MyFileFilter> iter = csvExtensionsSupported.values().iterator();
    while (iter.hasNext()) {
      jfc.addChoosableFileFilter(iter.next());
    }

    iter = dbfExtensionsSupported.values().iterator();
    while (iter.hasNext()) {
      jfc.addChoosableFileFilter(iter.next());
    }

    // Opening a JFileCooser
    if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
        == JFileChooser.APPROVE_OPTION) {
      File endFile = jfc.getSelectedFile();
      if (endFile.exists()) { // File exists in the directory.
        int resp =
            JOptionPane.showConfirmDialog(
                (Component) PluginServices.getMainFrame(),
                PluginServices.getText(this, "fichero_ya_existe_seguro_desea_guardarlo")
                    + "\n"
                    + endFile.getAbsolutePath(),
                PluginServices.getText(this, "guardar"),
                JOptionPane.YES_NO_OPTION); // Informing the user
        if (resp != JOptionPane.YES_OPTION) { // cancel pressed.
          return;
        }
      } // end if exits.
      MyFileFilter filter = (MyFileFilter) jfc.getFileFilter(); // dbf, csv
      endFile = filter.normalizeExtension(endFile); // "name" + "." +
      // "dbf", "name" +
      // "." + "csv"

      if (filter.getExtensionOfAFile(endFile).toLowerCase().compareTo("csv") == 0) { // csv file
        exportToCSVFile(valores, endFile); // export to csv format
      } else if (filter.getExtensionOfAFile(endFile).toLowerCase().compareTo("dbf")
          == 0) { // dbf file
        exportToDBFFile(valores, endFile); // export to dbf format
      }
    } // end if aprove option.
  }
Beispiel #3
0
 /*
  *  (non-Javadoc)
  * @see com.iver.andami.plugins.Extension#initialize()
  */
 public void initialize() {
   getPersistedStatus();
   SelectableToolBar[] toolBars = PluginServices.getMainFrame().getToolbars();
   for (int i = toolBars.length - 1; i > 0; i--) {
     Menu menu = new Menu();
     menu.setActionCommand(ACTIONCOMMANDBASE + toolBars[i].getName());
     // menu.setTooltip(PluginServices.getText(this, "muestra_oculta_la_toolbar"));
     menu.setText(MENUBASE + toolBars[i].getName());
     if (toolBars[i].getAndamiVisibility()) menu.setIcon(ENABLEDIMAGE);
     PluginServices.getMainFrame()
         .addMenu(menu, this, PluginServices.getPluginServices(this).getClassLoader());
   }
 }
Beispiel #4
0
 /*
  *  (non-Javadoc)
  * @see com.iver.andami.plugins.Extension#initialize()
  */
 public void postInitialize() {
   // restores previous session' state
   getPersistedStatus();
   // now add a menu entry for each toolbar
   SelectableToolBar[] toolBars = PluginServices.getMainFrame().getToolbars();
   for (int i = toolBars.length - 1; i > 0; i--) {
     Menu menu = new Menu();
     menu.setActionCommand(ACTIONCOMMANDBASE + toolBars[i].getName());
     menu.setText(MENUBASE + toolBars[i].getName());
     if (toolBars[i].getAndamiVisibility()) menu.setIcon(ENABLEDIMAGE);
     PluginServices.getMainFrame()
         .addMenu(menu, this, PluginServices.getPluginServices(this).getClassLoader());
   }
 }
Beispiel #5
0
 public void layerRemoved(LayerCollectionEvent e) {
   VectorialLayerEdited vle = (VectorialLayerEdited) getActiveLayerEdited();
   if (vle != null && vle.getLayer().isActive()) {
     // FLayers layers=getMapControl().getMapContext().getLayers();
     // if (layers.getLayersCount()>0)
     //	layers.getLayer(0).setActive(true);
     try {
       vle.clearSelection();
     } catch (DataException e1) {
       NotificationManager.addError(e1);
     }
     editedLayers.remove(vle);
     getMapControl().setTool("zoomIn");
     FLyrVect lv = (FLyrVect) vle.getLayer();
     if (e.getAffectedLayer().equals(lv)) {
       IWindow window = PluginServices.getMDIManager().getActiveWindow();
       if (window instanceof View) {
         View view = (View) window;
         view.hideConsole();
         view.validate();
         view.repaint();
       }
     }
   }
   PluginServices.getMainFrame().enableControls();
 }
Beispiel #6
0
  /*
   *  (non-Javadoc)
   * @see com.iver.andami.plugins.Extension#actionPerformed()
   */
  public void actionPerformed(ActionEvent e) {
    String toolbarName = e.getActionCommand().substring(ACTIONCOMMANDBASE.length());
    javax.swing.JMenuItem menu =
        PluginServices.getMainFrame().getMenuEntry((MENUBASE + toolbarName).split("/"));

    if (!toolbarName.equals("")) {

      boolean oldVisibility = PluginServices.getMainFrame().getToolbarVisibility(toolbarName);
      if (oldVisibility == false) {
        URL icon =
            PluginServices.getPluginServices(this).getClassLoader().getResource(ENABLEDIMAGE);
        menu.setIcon(new ImageIcon(icon));
        persistStatus(toolbarName, !oldVisibility);
      } else {
        menu.setIcon(null);
        persistStatus(toolbarName, !oldVisibility);
      }
      PluginServices.getMainFrame().setToolbarVisibility(toolbarName, !oldVisibility);
    }
  }
Beispiel #7
0
 /**
  * Reads the stored toolbars' status from plugin-persinstence.xml, and sets the toolbars
  * accordingly.
  */
 private void getPersistedStatus() {
   PluginServices ps = PluginServices.getPluginServices(this);
   XMLEntity xml = ps.getPersistentXML();
   XMLEntity child = null;
   for (int i = xml.getChildrenCount() - 1; i >= 0; i--) {
     if (xml.getChild(i).getName().equals("Toolbars")) child = xml.getChild(i).getChild(0);
   }
   if (child != null) {
     SelectableToolBar[] toolBars = PluginServices.getMainFrame().getToolbars();
     for (int i = toolBars.length - 1; i >= 0; i--) {
       if (child.contains(toolBars[i].getName()))
         toolBars[i].setAndamiVisibility(
             child.getStringProperty(toolBars[i].getName()).equals("visible"));
     }
   }
 }
  @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);
    }
  }
Beispiel #9
0
  public void editionChanged(LayerEvent e) {
    Logger.global.info(e.toString());
    ILayerEdited lyrEdit = getLayerEdited(e.getSource());

    // Si no está en la lista, comprobamos que está en edición
    // y lo añadimos
    if ((lyrEdit == null) && e.getSource().isEditing()) {
      lyrEdit = FactoryLayerEdited.createLayerEdited(e.getSource());
      editedLayers.add(lyrEdit);
      if (getMapControl() != null) {
        getMapControl().setTool("cadtooladapter");
        CADExtension.setCADTool("_selection", true);
      }
      PluginServices.getMainFrame().setSelectedTool("_selection");
      // idActiveLayer = editedLayers.size() - 1;
      ile = getLayerEdited(e.getSource());
      System.out.println("NUEVA CAPA EN EDICION: " + lyrEdit.getLayer().getName());
      // activationChanged(e);

      // Ponemos el resto de temas desactivados
      if (mapCtrl != null) mapCtrl.getMapContext().getLayers().setActive(false);
      // y activamos el nuevo.
      e.getSource().setActive(true);

      if (e.getSource() instanceof FLyrVect) {
        FLyrVect fLyrVect = (FLyrVect) e.getSource();
        ((VectorialLayerEdited) lyrEdit)
            .setEditionChangeManager(new EditionChangeManager(fLyrVect));

        //				VectorialEditableAdapter vea =
        //					(VectorialEditableAdapter)fLyrVect.getSource();
        //				vea.addEditionListener(new EditionChangeManager(fLyrVect));
      }
    } else {
      for (int i = 0; i < editedLayers.size(); i++) {
        VectorialLayerEdited vle = (VectorialLayerEdited) editedLayers.get(i);
        if (vle.equals(lyrEdit)) {
          editedLayers.remove(i);
          ile = null;
          // idActiveLayer=-1;
          return;
        }
      }
    }
  }
Beispiel #10
0
  public void activationChanged(LayerEvent e) {
    if (e.getSource().isActive()) {
      ile = getLayerEdited(e.getSource());
    }
    //		IWindow window=PluginServices.getMDIManager().getActiveWindow();
    //		if (window instanceof View){
    //			View view=(View)window;
    //			if (e.getSource().isEditing()){
    //				view.showConsole();
    //			}else{
    //				view.hideConsole();
    //			}
    //		}

    if (ile == null || ile.getLayer().equals(e.getSource())) {

      if (ile != null && !ile.getLayer().isActive()) {
        VectorialLayerEdited lastVLE = (VectorialLayerEdited) ile;
        lastVLE.activationLost(e);
      }
      if (e.getSource() instanceof FLyrVect) {
        VectorialLayerEdited vle = null;
        vle = (VectorialLayerEdited) getLayerEdited(e.getSource());
        // for (int i = 0; i < editedLayers.size(); i++) {
        // vle = (VectorialLayerEdited) editedLayers.get(i);
        // if (vle.getLayer().equals(e.getSource())) {
        // idActiveLayer = i;
        ile = vle;
        if (getMapControl() != null && vle != null && vle.getLayer().isActive()) {
          getMapControl().setTool("cadtooladapter");
          vle.activationGained(e);
          return;
        }
      }
      // }
      // idActiveLayer=-1;
      // ile=null;
      if (getMapControl() != null) {
        getMapControl().setTool("zoomIn");
        PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
      }
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.gvsig.fmap.tools.Listeners.PointListener#point(org.gvsig.fmap.tools
   * .Events.PointEvent) The PointEvent method bring you a point in pixel
   * coordinates. You need to transform it to world coordinates. The class to
   * do conversions is ViewPort, obtained thru the MapContext of mapCtrl.
   */
  public void point(PointEvent event) throws BehaviorException {
    com.iver.cit.gvsig.fmap.ViewPort vp = mapCtrl.getViewPort();
    Point2D pReal = vp.toMapPoint(event.getPoint());

    SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers());
    while (it.hasNext()) {
      FLayer aux = it.next();
      if (!aux.isActive()) continue;
      Network net = (Network) aux.getProperty("network");

      if (net != null) {

        double realTol = vp.toMapDistance(pixelTolerance);
        Point2D pReal2 =
            vp.toMapPoint(
                (int) event.getPoint().getX() + pixelTolerance,
                (int) event.getPoint().getY() + pixelTolerance);

        // if ((vp.getProjection() != null) &&
        // !(vp.getProjection().isProjected())) {
        // realTol = vp.distanceWorld(pReal, pReal2);
        // }

        GvFlag flag;
        try {
          if (mode == TO_ARC) flag = net.addFlag(pReal.getX(), pReal.getY(), realTol);
          else flag = net.addFlagToNode(pReal.getX(), pReal.getY(), realTol);
          if (flag == null) {
            JOptionPane.showMessageDialog(
                null, PluginServices.getText(this, "point_not_on_the_network"));
            return;
          }
          NetworkUtils.addGraphicFlag(mapCtrl, flag);
          mapCtrl.drawGraphics();
          PluginServices.getMainFrame().enableControls();
        } catch (GraphException e) {
          e.printStackTrace();
          NotificationManager.addError(e);
        }
      }
    }
  }
Beispiel #12
0
  public void addElement(Object element, String elementName, Object containerFolder) {
    if (element instanceof ISymbol) {
      ISymbol sym = (ISymbol) element;
      if (containerFolder == null) {
        containerFolder = rootDir;
      }

      String fExtension = SymbolLibrary.SYMBOL_FILE_EXTENSION;
      File targetFile =
          new File(((File) containerFolder).getAbsolutePath() + File.separator + elementName);
      // save it
      XMLEntity xml = sym.getXMLEntity();
      if (!targetFile.getAbsolutePath().toLowerCase().endsWith(fExtension))
        targetFile = new File(targetFile.getAbsolutePath() + fExtension);
      if (targetFile.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;
        }
      }
      FileWriter writer;
      try {
        writer = new FileWriter(targetFile.getAbsolutePath());
        Marshaller m = new Marshaller(writer);
        m.setEncoding("ISO-8859-1");
        m.marshal(xml.getXmlTag());

      } catch (Exception ex) {
        NotificationManager.addError(PluginServices.getText(this, "save_error"), ex);
      }
    } else {
      throw new IllegalArgumentException(
          PluginServices.getText(this, "adding_a_non_symbol_as_element"));
    }
  }
  public void execute(ProjectDocument item, ProjectDocument[] selectedItems) {
    String sourceString = PluginServices.getFromClipboard();
    if (sourceString == null) return;

    ProjectExtension projectExtension =
        (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
    Project project = projectExtension.getProject();
    String docType = ((ProjectWindow) projectExtension.getProjectWindow()).getDocumentSelected();

    try {
      project.importFromXML(sourceString, docType);
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          (Component) PluginServices.getMainFrame(),
          "<html>"
              + PluginServices.getText(this, "No_ha_sido_posible_realizar_la_operacion")
              + "</html>", // Mensaje
          PluginServices.getText(this, "pegar"), // titulo
          JOptionPane.ERROR_MESSAGE);
    }
    project.setModified(true);
  }
  /**
   * @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 {
    FFrameOverView fframe =
        (FFrameOverView) FrameFactory.createFrameFromName(FFrameOverViewFactory.registerName);

    fframe.setLayout(layout);
    Rectangle2D r =
        new Rectangle2D
            .Double(); // rectOrigin.x+m_PointAnt.x,rectOrigin.y+m_PointAnt.y,m_LastPoint.x-m_PointAnt.x,m_LastPoint.y-m_PointAnt.y);

    r = getRectangle(TOLERANCE);
    fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layout.getLayoutControl().getAT()));
    FFrameOverViewDialog fframedialog = new FFrameOverViewDialog(layout, fframe);
    if (fframedialog != null) {
      fframedialog.setRectangle(fframe.getBoundingBox(layout.getLayoutControl().getAT()));
      PluginServices.getMDIManager().addWindow(fframedialog);
    }

    IFFrame newFrame = fframedialog.getFFrame();
    if (newFrame != null) {
      layout.getLayoutContext().addFFrame(newFrame, true, true);
    }
    PluginServices.getMainFrame().enableControls();
    layout.getLayoutControl().refresh();
  }
Beispiel #15
0
  /**
   * Evaluate the expression.
   *
   * @throws ReadDriverException
   * @throws BSFException
   */
  public boolean evalExpression(String expression) throws ReadDriverException, BSFException {
    long rowCount = sds.getRowCount();
    byte[] expressionBytes;
    String encoding = System.getProperty("file.encoding");
    try {
      expressionBytes = expression.getBytes(encoding);
      expression = new String(expressionBytes, "ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
    expression = expression.replaceAll("\\[", "field(\"").replaceAll("\\]", "\")");

    interpreter.declareBean("ee", this, EvalExpression.class);
    interpreter.exec(
        ExpressionFieldExtension.JYTHON,
        null,
        -1,
        -1,
        "def expression():\n" + "  return " + expression + "");
    if (rowCount > 0) {
      try {
        interpreter.exec(
            ExpressionFieldExtension.JYTHON,
            null,
            -1,
            -1,
            "def isCorrect():\n" + "    ee.isCorrectValue(expression())\n");
        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "isCorrect()");
      } catch (BSFException ee) {
        String message = ee.getMessage();
        if (message.length() > 200) {
          message = message.substring(0, 200);
        }
        int option =
            JOptionPane.showConfirmDialog(
                (Component) PluginServices.getMainFrame(),
                PluginServices.getText(this, "error_expression")
                    + "\n"
                    + message
                    + "\n"
                    + PluginServices.getText(this, "continue?"));
        if (option != JOptionPane.OK_OPTION) {
          return false;
        }
      }
    }
    ies.startComplexRow();

    ArrayList exceptions = new ArrayList();
    interpreter.declareBean("exceptions", exceptions, ArrayList.class);
    FBitSet selection = sds.getSelection();
    if (selection.cardinality() > 0) {
      interpreter.declareBean("selection", selection, FBitSet.class);
      interpreter.exec(
          ExpressionFieldExtension.JYTHON,
          null,
          -1,
          -1,
          "def p():\n"
              + "  i=selection.nextSetBit(0)\n"
              + "  while i >=0:\n"
              + "    indexRow.set(i)\n"
              + "    obj=expression()\n"
              + "    ee.setValue(obj,i)\n"
              + "    ee.saveEdits(i)\n"
              + "    i=selection.nextSetBit(i+1)\n");
    } else {
      interpreter.exec(
          ExpressionFieldExtension.JYTHON,
          null,
          -1,
          -1,
          "def p():\n"
              + "  for i in xrange("
              + rowCount
              + "):\n"
              + "    indexRow.set(i)\n"
              +
              //						"    print i , expression() , repr (expression())\n" +
              "    ee.setValue(expression(),i)\n"
              + "    ee.saveEdits(i)\n");
    }
    try {
      interpreter.eval(ExpressionFieldExtension.JYTHON, null, -1, -1, "p()");
    } catch (BSFException ee) {

      JOptionPane.showMessageDialog(
          (Component) PluginServices.getMainFrame(),
          PluginServices.getText(this, "evaluate_expression_with_errors")
              + " "
              + (rowCount - indexRow.get())
              + "\n"
              + ee.getMessage());
    }

    ies.endComplexRow(PluginServices.getText(this, "expression"));

    return true;
  }