Revision 14619

View differences:

tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/exclusiveUI/ExclusiveUIExtension.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
package org.gvsig.examples.example1.exclusiveUI;
43

  
44
import java.util.HashSet;
45

  
46
import com.iver.andami.PluginServices;
47
import com.iver.andami.plugins.Extension;
48

  
49
/**
50
 * This extension shows how to use an ExclusiveUIExtension, an extension which
51
 * takes over the control of the GUI and decides which extensions will be
52
 * visible (or hidden).
53
 * 
54
 * @author Cesar Martinez Izquierdo <cesar.martinez@iver.es>
55
 * @author Vicente Caballero Navarro
56
 *
57
 */
58
public class ExclusiveUIExtension extends Extension {
59
	private HashSet goodExtensions = new HashSet();
60
	
61
	public void initialize() {
62

  
63
		goodExtensions.add("com.iver.core.Consola");
64
		goodExtensions.add("com.iver.core.StatusBar");
65
		goodExtensions.add("com.iver.core.PreferencesExtension");
66
		goodExtensions.add("com.iver.cit.gvsig.ViewControls");
67
		goodExtensions.add("com.iver.cit.gvsig.AddLayer");
68
		goodExtensions.add("com.iver.cit.gvsig.ProjectExtension");
69
		goodExtensions.add("com.iver.cit.gvsig.About");
70
		goodExtensions.add("com.iver.cit.gvsig.LayoutControls");
71
		goodExtensions.add("com.iver.cit.gvsig.ViewPropertiesExtension");
72
		goodExtensions.add("com.iver.cit.gvsig.ZoomPrev");
73
		goodExtensions.add("com.iver.cit.gvsig.ViewProjectWindow");
74
		goodExtensions.add("com.iver.cit.gvsig.Print");
75
		goodExtensions.add("com.iver.cit.gvsig.PrintProperties");
76
		goodExtensions.add("com.iver.cit.gvsig.LayoutEditableControls");
77
		goodExtensions.add("com.iver.cit.gvsig.LayoutUndoExtension");
78
		goodExtensions.add("com.iver.cit.gvsig.LayoutRedoExtension");
79
		goodExtensions.add("com.iver.cit.gvsig.LayoutInsertToolsExtension");
80
		goodExtensions.add("com.iver.cit.gvsig.LayoutGraphicControls");
81
		goodExtensions.add("com.iver.cit.gvsig.LayoutEditVertexExtension");
82
		goodExtensions.add("com.iver.cit.gvsig.ViewSelectionControls");
83
		goodExtensions.add("org.gvsig.examples.example1.extension.CenterViewToPointExtension");
84
		goodExtensions.add("org.gvsig.examples.example1.extension.InfoToolExampleExtension");
85
		goodExtensions.add("org.gvsig.examples.example1.extension.OpenCSVToPointsExtension");
86
		goodExtensions.add("org.gvsig.examples.example1.PreferencePageExtension");
87
		goodExtensions.add("org.gvsig.examples.example1.AboutExtension");
88
		goodExtensions.add("org.gvsig.examples.example1.PreferencePageExtension");
89
		goodExtensions.add("org.gvsig.examples.example1.TOCMenuExtension");
90

  
91
		PluginServices.setExclusiveUIExtension(this);
92
	}
93
	
94
	public boolean isVisible(Extension ext) {
95
		// if the extension is in our good list, ask the extension for visibility
96
		if (goodExtensions.contains(ext.getClass().getName())) {
97
			return ext.isVisible();	
98
		}
99
		return false;
100
	}
101

  
102

  
103
	public boolean isEnabled() {
104
		// TODO Auto-generated method stub
105
		return false;
106
	}
107

  
108
	public boolean isVisible() {
109
		// TODO Auto-generated method stub
110
		return false;
111
	}
112

  
113
	public void execute(String actionCommand) {
114
		// TODO Auto-generated method stub
115
		
116
	}
117

  
118
}
0 119

  
tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/centerViewToPoint/CenterViewToPointExtension.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
package org.gvsig.examples.example1.centerViewToPoint;
43

  
44
import java.awt.Color;
45
import java.util.prefs.Preferences;
46

  
47
import com.iver.andami.PluginServices;
48
import com.iver.andami.plugins.Extension;
49
import com.iver.cit.gvsig.fmap.MapContext;
50
import com.iver.cit.gvsig.fmap.layers.FLayers;
51
import com.iver.cit.gvsig.project.documents.view.IProjectView;
52
import com.iver.cit.gvsig.project.documents.view.gui.View;
53
import com.iver.utiles.StringUtilities;
54

  
55
/**
56
 * The CenterViewToPointExtension class allows to center the View over a
57
 * concrete point given by its coordinates.
58
 *
59
 * @author Vicente Caballero Navarro
60
 */
61
public class CenterViewToPointExtension extends Extension{
62

  
63
	private View vista;
64
	public static Color COLOR=Color.red;
65
	private static Preferences prefs = Preferences.userRoot().node( "centerviewtopoint" );
66

  
67
    /* (non-Javadoc)
68
     * @see com.iver.andami.plugins.Extension#inicializar()
69
     */
70
    public void initialize() {
71
    	String colorString=prefs.get("colorcenterviewtopoint",StringUtilities.color2String(CenterViewToPointExtension.COLOR));
72
		Color color=StringUtilities.string2Color(colorString);
73
		CenterViewToPointExtension.COLOR=color;
74

  
75
    }
76

  
77
    /* (non-Javadoc)
78
     * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
79
     */
80
    public void execute(String actionCommand) {
81
		if ("CENTERVIEWTOPOINT".equals(actionCommand)){
82
			vista = (View)PluginServices.getMDIManager().getActiveWindow();
83
			InputCoordinatesPanel dataSelectionPanel = new InputCoordinatesPanel(vista);
84
			PluginServices.getMDIManager().addWindow(dataSelectionPanel);
85
		}
86
    }
87

  
88
    public View getView(){
89
    	return vista;
90
    }
91
    /* (non-Javadoc)
92
     * @see com.iver.andami.plugins.Extension#isEnabled()
93
     */
94
    public boolean isEnabled() {
95
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
96
		 .getActiveWindow();
97
		if (f == null) {
98
		    return false;
99
		}
100
		if (f.getClass() == View.class) {
101
		    View vista = (View) f;
102
		    IProjectView model = vista.getModel();
103
		    MapContext mapa = model.getMapContext();
104
		    FLayers layers = mapa.getLayers();
105
		    for (int i=0;i < layers.getLayersCount();i++) {
106
               if (layers.getLayer(i).isAvailable()) return true;
107
		    }
108
		}
109
		return false;
110

  
111
    }
112

  
113
    /* (non-Javadoc)
114
     * @see com.iver.andami.plugins.Extension#isVisible()
115
     */
116
    public boolean isVisible() {
117
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
118
		 .getActiveWindow();
119
		if (f == null) {
120
		    return false;
121
		}
122
		if (f.getClass() == View.class) {
123
		    View vista = (View) f;
124
		    IProjectView model = vista.getModel();
125
		    MapContext mapa = model.getMapContext();
126
            if (mapa.getLayers().getLayersCount() > 0) {
127
                return true;
128
            }
129
            return false;
130
        }
131
		return false;
132
	}
133

  
134
}
0 135

  
tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/centerViewToPoint/CenterViewToPointPage.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
package org.gvsig.examples.example1.centerViewToPoint;
43

  
44
import java.awt.Color;
45
import java.util.prefs.Preferences;
46

  
47
import javax.swing.ImageIcon;
48
import javax.swing.JPanel;
49

  
50
import com.iver.andami.PluginServices;
51
import com.iver.andami.preferences.AbstractPreferencePage;
52
import com.iver.andami.preferences.StoreException;
53
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
54
import com.iver.utiles.StringUtilities;
55

  
56

  
57
/**
58
 * References page of center view to point options.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class CenterViewToPointPage extends AbstractPreferencePage {
63
    private static Preferences prefs = Preferences.userRoot().node("centerviewtopoint");
64
    private ColorChooserPanel colorPoint;
65
    private ImageIcon icon;
66

  
67
    public CenterViewToPointPage() {
68
        super();
69
        icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/CenterView.png"));
70
        addComponent(PluginServices.getText(this, "color_point") + ":",
71
            colorPoint = new ColorChooserPanel());
72
    }
73

  
74
    /* (non-Javadoc)
75
     * @see com.iver.andami.preferences.IPreference#initializeValues()
76
     */
77
    public void initializeValues() {
78
        String colorString = prefs.get("colorcenterviewtopoint",
79
                StringUtilities.color2String(CenterViewToPointExtension.COLOR));
80
        Color color = StringUtilities.string2Color(colorString);
81
        CenterViewToPointExtension.COLOR = color;
82
        colorPoint.setColor(color);
83
        colorPoint.setAlpha(255);
84
    }
85

  
86
    /* (non-Javadoc)
87
     * @see com.iver.andami.preferences.IPreference#getID()
88
     */
89
    public String getID() {
90
        return this.getClass().getName();
91
    }
92

  
93
    /* (non-Javadoc)
94
     * @see com.iver.andami.preferences.IPreference#getTitle()
95
     */
96
    public String getTitle() {
97
        return PluginServices.getText(this, "Centrar_la_Vista_sobre_un_punto");
98
    }
99

  
100
    /* (non-Javadoc)
101
     * @see com.iver.andami.preferences.IPreference#getPanel()
102
     */
103
    public JPanel getPanel() {
104
        return this;
105
    }
106

  
107
    /* (non-Javadoc)
108
     * @see com.iver.andami.preferences.AbstractPreferencePage#storeValues()
109
     */
110
    public void storeValues() throws StoreException {
111
        String colorString;
112
        colorString = StringUtilities.color2String(colorPoint.getColor());
113
        prefs.put("colorcenterviewtopoint", colorString);
114
        CenterViewToPointExtension.COLOR = colorPoint.getColor();
115
    }
116

  
117
    /* (non-Javadoc)
118
     * @see com.iver.andami.preferences.IPreference#initializeDefaults()
119
     */
120
    public void initializeDefaults() {
121
        colorPoint.setColor(CenterViewToPointExtension.COLOR);
122
    }
123

  
124
    /* (non-Javadoc)
125
     * @see com.iver.andami.preferences.IPreference#getIcon()
126
     */
127
    public ImageIcon getIcon() {
128
        return icon;
129
    }
130

  
131
    /* (non-Javadoc)
132
     * @see com.iver.andami.preferences.IPreference#isValueChanged()
133
     */
134
    public boolean isValueChanged() {
135
        return super.hasChanged();
136
    }
137

  
138
    /* (non-Javadoc)
139
     * @see com.iver.andami.preferences.AbstractPreferencePage#setChangesApplied()
140
     */
141
    public void setChangesApplied() {
142
        setChanged(false);
143
    }
144
}
0 145

  
tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/centerViewToPoint/TOCMenuExtension.java
1
package org.gvsig.examples.example1.centerViewToPoint;
2

  
3

  
4
import com.iver.andami.plugins.Extension;
5
import com.iver.utiles.extensionPoints.ExtensionPoints;
6
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
7

  
8
/**
9
 * This extensions shows how to add a context menu to the TOC (table of
10
 * contents) of the view).
11
 * 
12
 * @author cesar
13
 *
14
 */
15
public class TOCMenuExtension extends Extension {
16

  
17
	public void execute(String actionCommand) {
18
		
19
	}
20

  
21
	public void initialize() {
22
        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
23
        extensionPoints.add("View_TocActions", "CenterViewToPoint",
24
            new PropertiesTocMenuEntry());
25
        // after this, a new entry appears in the context menu
26
        // When we click on this entry, PropertiesTocMenuEntry.execute() is called.
27
	}
28

  
29
	public boolean isEnabled() {
30
		// the context menu will be visible regardless the extension status
31
		return false;
32
	}
33

  
34
	public boolean isVisible() {
35
		// the context menu will be visible regardless the extension status
36
		return false;
37
	}
38

  
39
}
0 40

  
tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/centerViewToPoint/PreferencePageExtension.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

  
43
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
44
 *
45
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
46
 *
47
 * This program is free software; you can redistribute it and/or
48
 * modify it under the terms of the GNU General Public License
49
 * as published by the Free Software Foundation; either version 2
50
 * of the License, or (at your option) any later version.
51
 *
52
 * This program is distributed in the hope that it will be useful,
53
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
54
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
55
 * GNU General Public License for more details.
56
 *
57
 * You should have received a copy of the GNU General Public License
58
 * along with this program; if not, write to the Free Software
59
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
60
 *
61
 * For more information, contact:
62
 *
63
 *  Generalitat Valenciana
64
 *   Conselleria d'Infraestructures i Transport
65
 *   Av. Blasco Ib??ez, 50
66
 *   46010 VALENCIA
67
 *   SPAIN
68
 *
69
 *      +34 963862235
70
 *   gvsig@gva.es
71
 *      www.gvsig.gva.es
72
 *
73
 *    or
74
 *
75
 *   IVER T.I. S.A
76
 *   Salamanca 50
77
 *   46005 Valencia
78
 *   Spain
79
 *
80
 *   +34 963163400
81
 *   dac@iver.es
82
 */
83
package org.gvsig.examples.example1.centerViewToPoint;
84

  
85

  
86
import com.iver.andami.plugins.Extension;
87
import com.iver.andami.preferences.IPreference;
88
import com.iver.andami.preferences.IPreferenceExtension;
89

  
90

  
91
/**
92
 * Example of extension which adds an option in the TOC context menu.
93
 * with a dialog of preferences, option in a context menu,
94
 * Exclusive extensions and about page.
95
 *
96
 * @author Vicente Caballero Navarro
97
 */
98
public class PreferencePageExtension extends Extension implements IPreferenceExtension {
99
	
100
    private CenterViewToPointPage centerViewPage = new CenterViewToPointPage();
101
    private IPreference[] preferencePages = {centerViewPage};
102

  
103
    /* (non-Javadoc)
104
     * @see com.iver.andami.plugins.IExtension#initialize()
105
     */
106
    public void initialize() {
107
    }
108
   
109
    /* (non-Javadoc)
110
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
111
     */
112
    public void execute(String arg0) {
113
    }
114

  
115
    /* (non-Javadoc)
116
     * @see com.iver.andami.plugins.IExtension#isEnabled()
117
     */
118
    public boolean isEnabled() {
119
        return false;
120
    }
121

  
122
    /* (non-Javadoc)
123
     * @see com.iver.andami.plugins.IExtension#isVisible()
124
     */
125
    public boolean isVisible() {
126
        return false;
127
    }
128

  
129
	/* (non-Javadoc)
130
	 * @see com.iver.andami.preferences.IPreferenceExtension#getPreferencesPage()
131
	 */
132
	public IPreference getPreferencesPage() {
133
		return centerViewPage;
134
	}
135
}
0 136

  
tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/centerViewToPoint/PropertiesTocMenuEntry.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

  
43
package org.gvsig.examples.example1.centerViewToPoint;
44

  
45
import com.iver.andami.PluginServices;
46
import com.iver.cit.gvsig.fmap.layers.FLayer;
47
import com.iver.cit.gvsig.project.documents.view.gui.View;
48
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
49
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
50

  
51

  
52

  
53
/**
54
 * Properties toc menu entry center view to point.
55
 *
56
 * @author Vicente Caballero Navarro
57
 */
58
public class PropertiesTocMenuEntry extends AbstractTocContextMenuAction {
59
    /* (non-Javadoc)
60
     * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getGroup()
61
     */
62
    public String getGroup() {
63
        return "examplegroup";
64
    }
65

  
66
    /* (non-Javadoc)
67
     * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getGroupOrder()
68
     */
69
    public int getGroupOrder() {
70
        return 1;
71
    }
72

  
73
    /* (non-Javadoc)
74
     * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getOrder()
75
     */
76
    public int getOrder() {
77
        return 1;
78
    }
79

  
80
    /* (non-Javadoc)
81
     * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
82
     */
83
    public String getText() {
84
        return PluginServices.getText(this, "Centrar_la_Vista_sobre_un_punto");
85
    }
86

  
87
    /* (non-Javadoc)
88
     * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
89
     */
90
    public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
91
        return true;
92
    }
93

  
94
    /* (non-Javadoc)
95
     * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
96
     */
97
    public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
98
        return (isTocItemBranch(item));
99
    }
100

  
101
    /* (non-Javadoc)
102
     * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
103
     */
104
    public void execute(ITocItem item, FLayer[] selectedItems) {
105
        View vista = (View) PluginServices.getMDIManager().getActiveWindow();
106
        InputCoordinatesPanel dataSelectionPanel = new InputCoordinatesPanel(vista);
107
        PluginServices.getMDIManager().addWindow(dataSelectionPanel);
108
    }
109
}
0 110

  
tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/centerViewToPoint/InputCoordinatesPanel.java
1
/*
2
 * Created on 08-nov-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package org.gvsig.examples.example1.centerViewToPoint;
45

  
46
import java.awt.Color;
47
import java.awt.Component;
48
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionListener;
50
import java.awt.event.MouseEvent;
51
import java.awt.geom.Point2D;
52
import java.awt.geom.Rectangle2D;
53

  
54
import javax.swing.JButton;
55
import javax.swing.JDialog;
56
import javax.swing.JLabel;
57
import javax.swing.JOptionPane;
58
import javax.swing.JPanel;
59
import javax.swing.JTextField;
60

  
61
import org.cresques.cts.IProjection;
62
import org.gvsig.gui.beans.AcceptCancelPanel;
63

  
64
import com.iver.andami.PluginServices;
65
import com.iver.andami.ui.mdiManager.IWindow;
66
import com.iver.andami.ui.mdiManager.WindowInfo;
67
import com.iver.cit.gvsig.fmap.MapControl;
68
import com.iver.cit.gvsig.fmap.core.IGeometry;
69
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
70
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
71
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
72
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
73
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
74
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
75
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
76
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
77
import com.iver.cit.gvsig.project.documents.view.gui.View;
78
import com.iver.cit.gvsig.project.documents.view.toolListeners.InfoListener;
79

  
80

  
81
/**
82
 * The InputCoordinatesPanel class creates a JPanel where the
83
 * user can input the coordinates of the point of reference
84
 * for center the View.
85
 *
86
 * @author jmorell
87
 */
88
public class InputCoordinatesPanel extends JPanel implements IWindow {
89
    private static final long serialVersionUID = 1L;
90
    private JLabel labelX = null;
91
    private JTextField textX = null;
92
    private JLabel labelY = null;
93
    private JTextField textY = null;
94
    private MapControl mapControl;
95
    private WindowInfo viewInfo = null;
96
    private String firstCoordinate;
97
    private String secondCoordinate;
98
    private Point2D center;
99
    private GraphicLayer lyr;
100
    private ColorChooserPanel colorPanel;
101
	private AcceptCancelPanel okCancelPanel = null;
102
	private JButton bRemovePoint = null;
103
	private View view=null;
104
	/**
105
     * This is the default constructor
106
     */
107
    public InputCoordinatesPanel(View view) {
108
        super();
109
        this.view=view;
110
        this.mapControl = view.getMapControl();
111
        lyr=mapControl.getMapContext().getGraphicsLayer();
112
        initializeCoordinates();
113
        initialize();
114
    }
115

  
116
    private void initializeCoordinates() {
117
        IProjection proj = mapControl.getProjection();
118
        String projName = proj.getAbrev();
119
        if (projName.equals("EPSG:23030") || projName.equals("EPSG:27492") || projName.equals("EPSG:42101") || projName.equals("EPSG:42304")) {
120
            firstCoordinate = "X";
121
            secondCoordinate = "Y";
122
        } else if (projName.equals("EPSG:4230") || projName.equals("EPSG:4326")) {
123
            firstCoordinate = "Lon";
124
            secondCoordinate = "Lat";
125
        } else {
126
            System.out.println("Proyecci?n: " + projName);
127
            System.out.println("Proyecci?n no soportada.");
128
        }
129
    }
130

  
131
    private void zoomToCoordinates() throws Exception {
132
       try{
133
    	Rectangle2D oldExtent = mapControl.getViewPort().getAdjustedExtent();
134
        double oldCenterX = oldExtent.getCenterX();
135
        double oldCenterY = oldExtent.getCenterY();
136
        double centerX = (new Double((String)textX.getText())).doubleValue();
137
        double centerY = (new Double((String)textY.getText())).doubleValue();
138
        center=new Point2D.Double(centerX,centerY);
139
        double movX = centerX-oldCenterX;
140
        double movY = centerY-oldCenterY;
141
        double upperLeftCornerX = oldExtent.getMinX()+movX;
142
        double upperLeftCornerY = oldExtent.getMinY()+movY;
143
        double width = oldExtent.getWidth();
144
        double height = oldExtent.getHeight();
145
        Rectangle2D extent = new Rectangle2D.Double(upperLeftCornerX, upperLeftCornerY, width, height);
146
        mapControl.getViewPort().setExtent(extent);
147
       }catch (NumberFormatException e) {
148
    	   throw new Exception();
149
       }
150

  
151
    }
152

  
153
    /**
154
     * This method initializes this
155
     *
156
     * @return void
157
     */
158
    private void initialize() {
159
        labelY = new JLabel();
160
        labelY.setBounds(10, 35, 28, 20);
161
        labelY.setText(secondCoordinate + ":");
162
        labelX = new JLabel();
163
        labelX.setBounds(10, 10, 28, 20);
164
        labelX.setText(firstCoordinate + ":");
165
        this.setLayout(null);
166
        this.setSize(307, 111);
167
        this.add(labelX, null);
168
        this.add(getTextX(), null);
169
        this.add(labelY, null);
170
        this.add(getTextY(), null);
171
        this.add(getColorPanel());
172
        this.add(getOkCancelPanel(), null);
173
        this.add(getBRemovePoint(), null);
174
    }
175

  
176
    /**
177
     * This method initializes textX
178
     *
179
     * @return javax.swing.JTextField
180
     */
181
    private JTextField getTextX() {
182
    	if (textX == null) {
183
    		textX = new JTextField();
184
    		textX.setBounds(40, 10, 260, 20);
185
    		textX.addActionListener(new java.awt.event.ActionListener() {
186
    			public void actionPerformed(java.awt.event.ActionEvent e) {
187
    				textX.transferFocus();
188
    			}
189
    		});
190
    	}
191
    	return textX;
192
    }
193

  
194
    /**
195
     * This method initializes textY
196
     *
197
     * @return javax.swing.JTextField
198
     */
199
    private JTextField getTextY() {
200
    	if (textY == null) {
201
    		textY = new JTextField();
202
    		textY.setBounds(40, 35, 260, 20);
203
    		textY.addActionListener(new java.awt.event.ActionListener() {
204
    			public void actionPerformed(java.awt.event.ActionEvent e) {
205
    				textY.transferFocus();
206
    			}
207
    		});
208
    	}
209
    	return textY;
210
    }
211

  
212
    /* (non-Javadoc)
213
     * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
214
     */
215
    public WindowInfo getWindowInfo() {
216
        if (viewInfo == null) {
217
            viewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
218
            viewInfo.setTitle(PluginServices.getText(this,"Centrar_la_Vista_sobre_un_punto"));
219
            viewInfo.setWidth(this.getWidth()+8);
220
            viewInfo.setHeight(this.getHeight());
221
        }
222
        return viewInfo;
223
    }
224
    private void openInfo(){
225
    	InfoListener infoListener=new InfoListener(mapControl);
226
    	MouseEvent e=new MouseEvent((Component)view,MouseEvent.BUTTON1,MouseEvent.ACTION_EVENT_MASK,MouseEvent.MOUSE_CLICKED,500,400,1,true);
227
    	Point2D centerPixels=mapControl.getViewPort().fromMapPoint(center.getX(),center.getY());
228
    	PointEvent pe=new PointEvent(centerPixels,e);
229
    	try {
230
			infoListener.point(pe);
231
		} catch (BehaviorException e1) {
232
			e1.printStackTrace();
233
		}
234
		if (mapControl.getMapContext().getLayers().getActives().length==0){
235
			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"no_hay_ninguna_capa_seleccionada")+" \n"+
236
					PluginServices.getText(this,"debe_seleccionar_las_capas_de_las_que_quiera_obtener_informacion"));
237
		}
238
    }
239
    private void drawPoint(Color color){
240
    	CenterViewToPointExtension.COLOR=color;
241
    	lyr.clearAllGraphics();
242
    	FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT,color);
243
        int idSymbol = lyr.addSymbol(theSymbol);
244
        IGeometry geom = ShapeFactory.createPoint2D(center.getX(),center.getY());
245
        FGraphic theGraphic = new FGraphic(geom, idSymbol);
246
        lyr.addGraphic(theGraphic);
247
        mapControl.drawGraphics();
248
	    mapControl.drawMap(false);
249

  
250
    }
251

  
252

  
253
	/**
254
	 * This method initializes jPanel
255
	 *
256
	 * @return javax.swing.JPanel
257
	 */
258
	private JPanel getColorPanel() {
259
		if (colorPanel==null){
260
		 	colorPanel=new ColorChooserPanel();
261
		 	colorPanel.setAlpha(250);
262
		 	colorPanel.setColor(CenterViewToPointExtension.COLOR);
263
		 	colorPanel.setBounds(new java.awt.Rectangle(40,59,123,24));
264
		}
265
		 	return colorPanel;
266
	}
267

  
268
	/**
269
	 * This method initializes okCancelPanel
270
	 *
271
	 * @return javax.swing.JPanel
272
	 */
273
	private AcceptCancelPanel getOkCancelPanel() {
274
		if (okCancelPanel == null) {
275
			ActionListener okAction, cancelAction;
276
			okAction = new java.awt.event.ActionListener() {
277
    			public void actionPerformed(java.awt.event.ActionEvent e) {
278
    				try{
279
    				zoomToCoordinates();
280
    				}catch (Exception e1) {
281
    					JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"formato_de_numero_incorrecto"));
282
    					return;
283
    				}
284
    				// y sale.
285
                    if (PluginServices.getMainFrame() == null)
286
                        ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
287
                    else
288
                        PluginServices.getMDIManager().closeWindow(InputCoordinatesPanel.this);
289

  
290
                    openInfo();
291
                    drawPoint(((ColorChooserPanel)getColorPanel()).getColor());
292
    			}
293
    		};
294
    		cancelAction = new ActionListener() {
295
				public void actionPerformed(ActionEvent e) {
296
					closeThis();
297
				}
298
    		};
299
			okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
300
			okCancelPanel.setBounds(new java.awt.Rectangle(40, 88, 260, 30));
301
		}
302
		return okCancelPanel;
303
	}
304

  
305
	private void closeThis() {
306
		PluginServices.getMDIManager().closeWindow(this);
307

  
308
	}
309

  
310
	/**
311
	 * This method initializes bRemovePoint
312
	 *
313
	 * @return javax.swing.JButton
314
	 */
315
	private JButton getBRemovePoint() {
316
		if (bRemovePoint == null) {
317
			bRemovePoint = new JButton();
318
			bRemovePoint.setBounds(new java.awt.Rectangle(181,59,101,25));
319
			bRemovePoint.setText(PluginServices.getText(this,"remove"));
320
			bRemovePoint.addActionListener(new java.awt.event.ActionListener() {
321
				public void actionPerformed(java.awt.event.ActionEvent e) {
322
					lyr.clearAllGraphics();
323
					mapControl.drawMap(false);
324
				}
325
			});
326
		}
327
		return bRemovePoint;
328
	}
329

  
330

  
331
}  //  @jve:decl-index=0:visual-constraint="103,18"
0 332

  
tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/loadCSVLayer/OpenCSVToPointsExtension.java
1
package org.gvsig.examples.example1.loadCSVLayer;
2

  
3
import java.net.URL;
4

  
5
import com.hardcode.driverManager.DriverLoadException;
6
import com.hardcode.gdbms.engine.data.DataSource;
7
import com.hardcode.gdbms.engine.data.DataSourceFactory;
8
import com.hardcode.gdbms.engine.data.NoSuchTableException;
9
import com.hardcode.gdbms.engine.data.driver.DriverException;
10
import com.iver.andami.PluginServices;
11
import com.iver.andami.plugins.Extension;
12
import com.iver.cit.gvsig.ProjectExtension;
13
import com.iver.cit.gvsig.fmap.MapContext;
14
import com.iver.cit.gvsig.fmap.layers.FLayerGenericVectorial;
15
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
16
import com.iver.cit.gvsig.project.Project;
17
import com.iver.cit.gvsig.project.ProjectFactory;
18
import com.iver.cit.gvsig.project.documents.view.ProjectView;
19
import com.iver.cit.gvsig.project.documents.view.gui.View;
20
import com.iver.gvsig.addeventtheme.AddEventThemeDriver;
21
import com.iver.utiles.extensionPoints.ExtensionPoint;
22
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
23

  
24
public class OpenCSVToPointsExtension extends Extension{
25

  
26
	public void initialize() {
27
		// TODO Auto-generated method stub
28

  
29
	}
30

  
31
	public void postInitialize() {
32
		try {
33
			addCSVPointLayer();
34
		} catch (DriverLoadException e) {
35
			// TODO Auto-generated catch block
36
			e.printStackTrace();
37
		} catch (NoSuchTableException e) {
38
			// TODO Auto-generated catch block
39
			e.printStackTrace();
40
		} catch (DriverException e) {
41
			// TODO Auto-generated catch block
42
			e.printStackTrace();
43
		} catch (InstantiationException e) {
44
			// TODO Auto-generated catch block
45
			e.printStackTrace();
46
		} catch (IllegalAccessException e) {
47
			// TODO Auto-generated catch block
48
			e.printStackTrace();
49
		}
50

  
51
	}
52

  
53
	public void execute(String actionCommand) {
54
		// TODO Auto-generated method stub
55

  
56
	}
57

  
58
	public boolean isEnabled() {
59
		// TODO Auto-generated method stub
60
		return false;
61
	}
62

  
63
	public boolean isVisible() {
64
		// TODO Auto-generated method stub
65
		return false;
66
	}
67

  
68

  
69

  
70
	private void addCSVPointLayer() throws DriverLoadException, NoSuchTableException, DriverException, InstantiationException, IllegalAccessException{
71
//		  Funcion encargada de crear y cargar en la vista la capa
72
//		  de trabajo a partir del fichero csv
73

  
74
		ProjectView pv=ProjectFactory.createView("Ejemplo CSV to Points");
75
		View view=(View)pv.createWindow();
76
		ProjectExtension pe=(ProjectExtension)PluginServices.getExtension(ProjectExtension.class);
77
		Project project=pe.getProject();
78
		project.addDocument(pv);
79
		PluginServices.getMDIManager().addWindow(view);
80

  
81
//		   csv
82
		  DataSourceFactory dataSourceFactory=LayerFactory.getDataSourceFactory();
83
		  URL fileURL = PluginServices.getPluginServices(this).getClassLoader().getResource("data/prueba.csv");
84
		  
85
		  dataSourceFactory.addFileDataSource("csv string", "prueba",fileURL.getPath());
86
		  DataSource ds = dataSourceFactory.createRandomDataSource("prueba");
87
		  ds.start();
88

  
89
//		   Crearemos el driver que gestiona la capa de eventos y lo enlazaremos con
90
//		   la fuente de datos que acabamos de crear indicandole que columnas de esta
91
//		   representan los puntos de la geomretria
92
		  int xFieldIndex = ds.getFieldIndexByName("X");
93
		  int yFieldIndex = ds.getFieldIndexByName("Y");
94
//		  DriverManager dm=new DriverManager();
95
		  AddEventThemeDriver driver=new AddEventThemeDriver();//(AddEventThemeDriver)dm.getDriver("csv string");
96
		  driver.setData(ds, xFieldIndex, yFieldIndex);
97

  
98
		  MapContext mapContext=view.getMapControl().getMapContext();
99

  
100
//		   Crearemos ahora la nueva capa basada en este driver
101
		  FLayerGenericVectorial layer = (FLayerGenericVectorial)(((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create("com.iver.cit.gvsig.fmap.layers.FLayerGenericVectorial"));
102
		  layer.setName("prueba");
103
		  layer.setDriver(driver);
104
		  layer.setProjection(mapContext.getProjection());
105
	      mapContext.getLayers().addLayer(layer);
106

  
107

  
108

  
109
//          capa = LayerFactory.createLayer("ademuz", driver, mapContext.getProjection());
110
//	      capa.addLayerListener(new AddEventThemListener());
111
//	      mapContext.getLayers().addLayer(layer);
112
//		   Una vez creada la capa se le a?ade una propiedad para reconocerla
113
//		   como nuestra capa de trabajo
114
		  layer.setProperty("CapaDePruebaCSV","propiedad para distinguir la capa de prueba");
115

  
116
//		   Indicamos al mapContext que se debe repintar
117
		  mapContext.invalidate();
118
		  mapContext.redraw();
119
	}
120
}
0 121

  
tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/infotool/tool/InfoToolListener.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

  
43
package org.gvsig.examples.example1.infotool.tool;
44

  
45

  
46
import com.iver.andami.PluginServices;
47
import com.iver.cit.gvsig.fmap.MapControl;
48
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
49

  
50

  
51
/**
52
 * Class that extends of the tool InfoToolListenerImpl and
53
 * override the methods that interests us to change its behavior.
54
 *
55
 * @author Vicente Caballero Navarro
56
 */
57
public class InfoToolListener extends InfoToolListenerImpl {
58

  
59
	public InfoToolListener(MapControl mapCtrl) {
60
        super(mapCtrl);
61

  
62
    }
63

  
64
    /* (non-Javadoc)
65
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
66
     */
67
    public void point(PointEvent event) {
68
    	super.point(event);
69
        PluginServices.getMainFrame().enableControls();
70
    }
71
}
0 72

  
tags/tmp_build/examples/exaExampleCenterViewToPoint/src/org/gvsig/examples/example1/infotool/tool/InfoToolListenerImpl.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

  
43
package org.gvsig.examples.example1.infotool.tool;
44

  
45
import java.awt.Cursor;
46
import java.awt.Image;
47
import java.awt.Point;
48
import java.awt.Toolkit;
49
import java.awt.geom.Point2D;
50
import java.awt.geom.Rectangle2D;
51

  
52
import javax.swing.ImageIcon;
53

  
54
import org.gvsig.examples.example1.centerViewToPoint.CenterViewToPointExtension;
55
import org.gvsig.examples.example1.infotool.tool.gui.InfoWindowExample;
56

  
57
import com.iver.andami.PluginServices;
58
import com.iver.cit.gvsig.fmap.MapControl;
59
import com.iver.cit.gvsig.fmap.core.IGeometry;
60
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
61
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
62
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
63
import com.iver.cit.gvsig.fmap.layers.FLayer;
64
import com.iver.cit.gvsig.fmap.layers.FLayerGenericVectorial;
65
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
66
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
67
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
68
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
69
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
70
import com.iver.cit.gvsig.project.documents.view.toolListeners.InfoListener;
71

  
72

  
73
/**
74
 * Implementation of the interface PointListener as tool
75
 * of information and center the extent to that point.
76
 *
77
 * @author Vicente Caballero Navarro
78
 */
79
public class InfoToolListenerImpl implements PointListener {
80
    private final Image icentertopoint = new ImageIcon(MapControl.class.getResource(
81
                "images/InfoCursor.gif")).getImage();
82
    private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(icentertopoint,
83
            new Point(16, 16), "");
84
    private MapControl mapControl;
85
    private InfoListener infoListener;
86
    /**
87
     * Create a new InfoToolListenerImpl.
88
     *
89
     * @param mapControl MapControl.
90
     */
91
    public InfoToolListenerImpl(MapControl mapControl) {
92
        this.mapControl = mapControl;
93
        infoListener=new InfoListener(mapControl);
94
    }
95

  
96
    /* (non-Javadoc)
97
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
98
     */
99
    public void point(PointEvent event) {
100
    	 FLayer[] layers=mapControl.getMapContext().getLayers().getActives();
101
         if (layers[0] instanceof FLayerGenericVectorial){
102
     		if (layers[0].getProperty("CapaDePruebaCSV")!=null){
103
     			Point2D centerPoint = mapControl.getViewPort().toMapPoint(event.getPoint());
104
     	        zoomToCoordinates(centerPoint);
105
     	        drawPoint(centerPoint);
106
     	        InfoWindowExample iwe=new InfoWindowExample();
107
     	        PluginServices.getMDIManager().addWindow(iwe);
108
     		}
109
     	 } else {
110
             try {
111
				infoListener.point(event);
112
			} catch (BehaviorException e) {
113
				e.printStackTrace();
114
			}
115
         }
116

  
117
    }
118

  
119
    private void drawPoint(Point2D center) {
120
        GraphicLayer lyr = mapControl.getMapContext().getGraphicsLayer();
121
        lyr.clearAllGraphics();
122

  
123
        FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT,
124
                CenterViewToPointExtension.COLOR);
125
        int idSymbol = lyr.addSymbol(theSymbol);
126
        IGeometry geom = ShapeFactory.createPoint2D(center.getX(), center.getY());
127
        FGraphic theGraphic = new FGraphic(geom, idSymbol);
128
        lyr.addGraphic(theGraphic);
129
        mapControl.drawGraphics();
130
        mapControl.drawMap(false);
131
    }
132

  
133
    private void zoomToCoordinates(Point2D center) {
134
        Rectangle2D oldExtent = mapControl.getViewPort().getAdjustedExtent();
135
        double oldCenterX = oldExtent.getCenterX();
136
        double oldCenterY = oldExtent.getCenterY();
137
        double movX = center.getX() - oldCenterX;
138
        double movY = center.getY() - oldCenterY;
139
        double upperLeftCornerX = oldExtent.getMinX() + movX;
140
        double upperLeftCornerY = oldExtent.getMinY() + movY;
141
        double width = oldExtent.getWidth();
142
        double height = oldExtent.getHeight();
143
        Rectangle2D extent = new Rectangle2D.Double(upperLeftCornerX,
144
                upperLeftCornerY, width, height);
145
        mapControl.getViewPort().setExtent(extent);
146
        mapControl.getMapContext().clearAllCachingImageDrawnLayers();
147
    }
148

  
149
    /* (non-Javadoc)
150
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
151
     */
152
    public Cursor getCursor() {
153
        return cur;
154
    }
155

  
156
    /* (non-Javadoc)
157
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
158
     */
159
    public boolean cancelDrawing() {
160
        return true;
161
    }
162

  
163
    /* (non-Javadoc)
164
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
165
     */
166
    public void pointDoubleClick(PointEvent event) {
167
    }
168
}
0 169

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff