[Gvsig_desarrolladores] problema con setScaleView

Manuel de la Calle Alonso mdelacalle en gmail.com
Mar Oct 2 12:59:31 CEST 2007


//Leo propiedades
Lo que hago aqui es leer un archivo XML así que eso no creo que te interese
mucho
//Abrir el proyecto
tengo el path del proyecto que necesito abrir y lo que he hecho es clonar
muchos métodos (todos los que me han
hecho falta de project Extension. Te pongo la clase , no sé si te valdrá
para algo

Saludos


* Created on 29/09/2007
 *
 * gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
 *
 * Plugin CMA.CHS Junta de Andalucía
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307,USA.
 *
 * For more information, contact:
 *
 * Junta de Andalucía. Consejería de Medio Ambiente
 * Confederación Hidrográfica del Sur
 *
 *
 * Fomento y Medio Ambiente de Extremadura. FOMEX
 * C/Santiago Caldera nº 4
 * 10004 Cáceres
 * http://www.fomex.es
 *
 */

package com.fomex.cma.chs.gvsig.extension;

import java.awt.Component;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.MarshalException;
import java.util.Iterator;

import javax.swing.JOptionPane;

import org.apache.log4j.Logger;

import com.fomex.cma.chs.gvsig.data.Conexion;
import com.fomex.cma.chs.gvsig.model.BDConn;
import com.fomex.cma.chs.gvsig.utils.MapUtils;
import com.iver.andami.PluginServices;
import com.iver.andami.ui.mdiManager.WindowInfo;
import com.iver.cit.gvsig.ProjectExtension;
import com.iver.cit.gvsig.fmap.MapContext;
import com.iver.cit.gvsig.fmap.MapControl;
import com.iver.cit.gvsig.fmap.ViewPort;
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
import com.iver.cit.gvsig.project.Project;
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
import com.iver.cit.gvsig.project.documents.gui.ProjectWindow;
import com.iver.cit.gvsig.project.documents.layout.ProjectMapFactory;
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory;
import com.iver.utiles.XMLEntity;
import com.iver.utiles.extensionPoints.ExtensionPoint;
import com.iver.utiles.extensionPoints.ExtensionPoints;
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
import com.iver.utiles.xml.XMLEncodingUtils;
import com.iver.utiles.xmlEntity.generate.XmlTag;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Point;

/**
 * Clase que va haciendo las acciones necesarias
 * para comenzar a trabajar con el plugin.
 * llama a otros plugins de gvSig para realizar
 * tareas comunes como abrir proyecto, centrar capas
 * y otras tareas necesarias para preparar el espacio
 * de trabajo
 * @since 29/09/2007
 *
 */
public class InitializePlugin {

    private static Logger logger = Logger.getLogger(InitializePlugin.class
            .getName());

    private ProjectWindow projectFrame;
    private Project proyecto;
    private WindowInfo seedProjectWindow;



    /**
     * Método que abre un proyecto a partir de un path.
     * Hay que cerrar todas las ventanas, es decir, cerramos
     * el gestor de proyectos. Hemos replicado bastantes métodos
     * de la extensión ProjectExtension, es decir lo abrimos de manera
     * muy parecida a como se hace en gvSig
     * @param pathVista
     * @see com.iver.cit.gvsig.ProjectExtension;
     */
    public void abrirProyecto(String pathVista){

     LayerFactory.setWritersPath(PluginServices.getPluginServices(this)
                  .getPluginDirectory()
                  .getAbsolutePath() +
                  File.separator + "drivers");

      LayerFactory.setDriversPath(PluginServices.getPluginServices(this)
                  .getPluginDirectory()
                  .getAbsolutePath() +
                  File.separator + "drivers");

      initializeDocumentActionsExtensionPoint();
      registerDocuments();

        logger.debug("Intentamos iniciar el proyecto: "+pathVista);
        proyecto = readProject("file:///"+pathVista);
        PluginServices.getMainFrame().setTitle("Nombre del proyecto que
aparece en la ventana");
        getProjectFrame().setProject(proyecto);
        PluginServices.getMDIManager().closeAllWindows();
        proyecto.restoreWindowProperties();
        logger.debug("El proyecto se ha abierto correctamente");
    }

    public Project readProject(String path) {
        BufferedReader reader =null;
        try {
        URL url=null;
            url = new URL(path);
            String encoding = XMLEncodingUtils.getEncoding(url.openStream
());
            InputStream is = url.openStream();
            if (encoding!=null) {
                Project proj=null;
                try {
                    reader = new BufferedReader(new InputStreamReader(is,
encoding));
                    proj=readProject(reader, true);
                } catch (UnsupportedEncodingException e) {
                    reader = new BufferedReader(new InputStreamReader(is));
                    try {
                        Project p=readProject(reader, false);
                    } catch (UnsupportedEncodingException e1) {
                        JOptionPane.showMessageDialog
((Component)PluginServices.getMainFrame(),PluginServices.getText(this,
e1.getLocalizedMessage()));
                        return null;
                    }
                }
                ProjectExtension.setPath(path);
                return proj;
            }
            else {
                reader = new BufferedReader(new InputStreamReader(is));
                Project p;
                try {
                    p = readProject(reader, false);
                } catch (UnsupportedEncodingException e) {
                    JOptionPane.showMessageDialog
((Component)PluginServices.getMainFrame(),PluginServices.getText(this,
e.getLocalizedMessage()));
                    return null;
                }
                ProjectExtension.setPath(path); //p.setPath(null);
                return p;
            }
        } catch (MalformedURLException e) {
            File file=new File(path);
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * Lee del XML el proyecto.<br><br>
     *
     * Reads the XML of the project.<br>
     * It returns a project object holding all needed info that is not
linked to the Project Dialog. <br>In case you want the project to be
     * linked to the window you must set this object to the extension:<br>
     *
     * <b>Example:</b><br>
     *
     * ...<br>
     * ...<br>
     * Project p = ProjectExtension.readProject(projectFile);<br>
     * ProjectExtension.setProject(p);
     * ...<br>
     * ...<br>
     * @param reader File reader
     * @param encodingFollowed Whether the encoded specified in the xml
header was followed
     * when creating the reader. If the property followHeaderEncoding is
false or not set,
     * then the encoding should have not been used when creating the reader,
so it must be
     * recreated.
     *
     * @return Project
     * @throws UnsupportedEncodingException
     *
     */
    public Project readProject(Reader reader, boolean encodingFollowed)
throws UnsupportedEncodingException {
        Project proj = null;

        try {
            XmlTag tag = (XmlTag) XmlTag.unmarshal(reader);
            XMLEntity xml=new XMLEntity(tag);
            String VERSION=xml.getStringProperty("VERSION");

            if (encodingFollowed) {
                if (xml.contains("followHeaderEncoding")) {
                    boolean useEncoding = xml.getBooleanProperty
("followHeaderEncoding");
                    if (!useEncoding) {
                        throw new UnsupportedEncodingException("the encoding
specified in the xml header is not safe");
                    }
                }
                else {
                    // Old projects didn't contain followHeaderEncoding and
they were
                    // not correctly encoded. We throw an exception now, and
we'll try
                    // to reopen the project
                    // using the default system encoding.
                    throw new UnsupportedEncodingException("the encoding
specified in the xml header is not safe");
                }
            }

            try {
                // if ((VERSION!=null) && (VERSION.equals("0.5") ||
VERSION.equals("0.4") || (VERSION.indexOf("GISPLANET") != -1))){
                if (VERSION != null) {
                    proj = Project.createFromXML(xml);
                }else{
                    proj = Project.createFromXML03(new XMLEntity(tag));
                }
                return proj;
            } catch (OpenException e){
                e.showError();
                //NotificationManager.addInfo("Al leer el proyecto", e);
            }
        }  catch (Exception e) {
            PluginServices.getLogger().error(PluginServices.getText(this,
"formato_incorrecto"),e);
            JOptionPane.showMessageDialog
((Component)PluginServices.getMainFrame(),PluginServices.getText(this,
"formato_incorrecto"));
            //NotificationManager.addError("Al leer el proyecto", e);
        }
        return null;
    }

    public ProjectWindow getProjectFrame() {
        if (projectFrame==null)
                projectFrame = new ProjectWindow();
        return projectFrame;
    }

    private void registerDocuments() {
        ProjectViewFactory.register();
        ProjectTableFactory.register();
        ProjectMapFactory.register();
    }

    private void initializeDocumentActionsExtensionPoint() {
        ExtensionPoints extensionPoints =
ExtensionPointsSingleton.getInstance();
        if (!extensionPoints.containsKey("DocumentActions_View")) {
            extensionPoints.put(
                new ExtensionPoint(
                    "DocumentActions_View",
                    "Context menu options of the view document list" +
                        " in the project window "+
                        "(register instances of " +
                        "
com.iver.cit.gvsig.project.AbstractDocumentContextMenuAction)"
                )
            );
        }
        if (!extensionPoints.containsKey("DocumentActions_Table")) {
            extensionPoints.put(
                new ExtensionPoint(
                    "DocumentActions_Table",
                    "Context menu options of the table document list" +
                        " in the project window "+
                        "(register instances of " +
                        "
com.iver.cit.gvsig.project.AbstractDocumentContextMenuAction)"
                )
            );
        }
        if (!extensionPoints.containsKey("DocumentActions_Map")) {
            extensionPoints.put(
                new ExtensionPoint(
                    "DocumentActions_Map",
                    "Context menu options of the map document list" +
                        " in the project window "+
                        "(register instances of " +
                        "
com.iver.cit.gvsig.project.AbstractDocumentContextMenuAction)"
                )
            );
        }
    }

}


On 10/2/07, Juan Lopez <juan.calahorra en gmail.com> wrote:
>
> Podrias escribir la parte referente a:
>
> //LEO PROPIEDADES
>
> //ABRO EL PROYECTO
>
> Yo estoy empezando a realizar una extension y tambien necesito abrir un
> proyecto (de momento no le he conseguido)
>
> Gracias de antemano
>
> _______________________________________________
> gvSIG_desarrolladores mailing list
> gvSIG_desarrolladores en runas.cap.gva.es
> http://runas.cap.gva.es/mailman/listinfo/gvsig_desarrolladores
>
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: http://runas.cap.gva.es/pipermail/gvsig_desarrolladores/attachments/20071002/c580a941/attachment-0001.htm


Más información sobre la lista de distribución gvSIG_desarrolladores