Revision 10548
branches/v10/extensions/extCoords/src/org/gvsig/iver/extensions/coords/FakeControl.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 |
package org.gvsig.iver.extensions.coords; |
|
42 |
|
|
43 |
import java.awt.event.ActionEvent; |
|
44 |
import java.awt.event.ActionListener; |
|
45 |
import java.util.ArrayList; |
|
46 |
import java.util.Iterator; |
|
47 |
|
|
48 |
import javax.swing.JComponent; |
|
49 |
|
|
50 |
import org.gvsig.gui.beans.controls.IControl; |
|
51 |
|
|
52 |
/** |
|
53 |
* |
|
54 |
* @author C?sar Mart?nez Izquierdo <cesar.martinez@iver.es> |
|
55 |
*/ |
|
56 |
public class FakeControl extends JComponent implements IControl { |
|
57 |
|
|
58 |
private ArrayList actionListeners = new ArrayList(); |
|
59 |
private int eventId=0; |
|
60 |
|
|
61 |
/** |
|
62 |
* |
|
63 |
*/ |
|
64 |
private static final long serialVersionUID = 1L; |
|
65 |
|
|
66 |
/* (non-Javadoc) |
|
67 |
* @see org.gvsig.gui.beans.controls.IControl#addActionListener(java.awt.event.ActionListener) |
|
68 |
*/ |
|
69 |
public void addActionListener(ActionListener listener) { |
|
70 |
if (!actionListeners.contains(listener)) |
|
71 |
actionListeners.add(listener); |
|
72 |
} |
|
73 |
|
|
74 |
/* (non-Javadoc) |
|
75 |
* @see org.gvsig.gui.beans.controls.IControl#removeActionListener(java.awt.event.ActionListener) |
|
76 |
*/ |
|
77 |
public void removeActionListener(ActionListener listener) { |
|
78 |
actionListeners.remove(listener); |
|
79 |
} |
|
80 |
|
|
81 |
private void callActionListeners(String message) { |
|
82 |
Iterator acIterator = actionListeners.iterator(); |
|
83 |
while (acIterator.hasNext()) { |
|
84 |
ActionListener listener = (ActionListener) acIterator.next(); |
|
85 |
listener.actionPerformed(new ActionEvent(this, eventId, message)); |
|
86 |
} |
|
87 |
eventId++; |
|
88 |
} |
|
89 |
|
|
90 |
/* (non-Javadoc) |
|
91 |
* @see org.gvsig.gui.beans.controls.IControl#setValue(java.lang.Object) |
|
92 |
*/ |
|
93 |
public Object setValue(Object value) { |
|
94 |
try { |
|
95 |
String text = (String) value; |
|
96 |
callActionListeners(text); |
|
97 |
return text; |
|
98 |
} |
|
99 |
catch (ClassCastException ex) { |
|
100 |
return null; |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
} |
branches/v10/extensions/extCoords/src/org/gvsig/iver/extensions/coords/Label.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.iver.extensions.coords; |
|
43 |
|
|
44 |
import java.awt.event.ActionEvent; |
|
45 |
import java.awt.event.ActionListener; |
|
46 |
import java.util.ArrayList; |
|
47 |
import java.util.Iterator; |
|
48 |
|
|
49 |
import javax.swing.JLabel; |
|
50 |
|
|
51 |
import org.gvsig.gui.beans.controls.IControl; |
|
52 |
|
|
53 |
/** |
|
54 |
* @author Cesar Martinez Izquierdo <cesar.martinez@iver.es> |
|
55 |
* |
|
56 |
*/ |
|
57 |
public class Label extends JLabel implements IControl { |
|
58 |
private static final long serialVersionUID = 1L; |
|
59 |
private ArrayList actionListeners = new ArrayList(); |
|
60 |
private int eventId=0; |
|
61 |
|
|
62 |
|
|
63 |
/* (non-Javadoc) |
|
64 |
* @see org.gvsig.gui.beans.controls.IControl#addActionListener(java.awt.event.ActionListener) |
|
65 |
*/ |
|
66 |
public void addActionListener(ActionListener listener) { |
|
67 |
|
|
68 |
if (!actionListeners.contains(listener)) |
|
69 |
actionListeners.add(listener); |
|
70 |
} |
|
71 |
|
|
72 |
/* (non-Javadoc) |
|
73 |
* @see org.gvsig.gui.beans.controls.IControl#removeActionListener(java.awt.event.ActionListener) |
|
74 |
*/ |
|
75 |
public void removeActionListener(ActionListener listener) { |
|
76 |
actionListeners.remove(listener); |
|
77 |
|
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
private void callActionListeners(String message) { |
|
82 |
Iterator acIterator = actionListeners.iterator(); |
|
83 |
while (acIterator.hasNext()) { |
|
84 |
ActionListener listener = (ActionListener) acIterator.next(); |
|
85 |
listener.actionPerformed(new ActionEvent(this, eventId, message)); |
|
86 |
} |
|
87 |
eventId++; |
|
88 |
} |
|
89 |
|
|
90 |
/* (non-Javadoc) |
|
91 |
* @see org.gvsig.gui.beans.controls.IControl#setValue(java.lang.Object) |
|
92 |
*/ |
|
93 |
public Object setValue(Object value) { |
|
94 |
try { |
|
95 |
String text = (String) value; |
|
96 |
setText(text); |
|
97 |
callActionListeners(text); |
|
98 |
return text; |
|
99 |
} |
|
100 |
catch (ClassCastException ex) { |
|
101 |
return null; |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
} |
|
0 | 106 |
branches/v10/extensions/extCoords/src/org/gvsig/iver/extensions/coords/DistanceUnitsConfig.java | ||
---|---|---|
1 | 1 |
package org.gvsig.iver.extensions.coords; |
2 | 2 |
|
3 | 3 |
import javax.swing.JComboBox; |
4 |
import javax.swing.JComponent; |
|
5 | 4 |
import javax.swing.JLabel; |
6 | 5 |
import javax.swing.JPanel; |
7 | 6 |
|
... | ... | |
20 | 19 |
* @author Vicente Caballero Navarro |
21 | 20 |
*/ |
22 | 21 |
public class DistanceUnitsConfig extends JPanel implements IWindow { |
23 |
private static String[] unitsNames = null; |
|
22 |
private static final long serialVersionUID = 1L; |
|
23 |
private static String[] unitsNames = null; |
|
24 | 24 |
private JLabel lblDistanceUnits = null; |
25 | 25 |
private JComboBox cmbDistanceUnits = null; |
26 | 26 |
private IProjectView view = null; |
... | ... | |
42 | 42 |
* This method initializes this |
43 | 43 |
*/ |
44 | 44 |
private void initialize() { |
45 |
this.setSize(331, 74);
|
|
45 |
this.setSize(331, 84);
|
|
46 | 46 |
this.add(getLblDistanceUnits(), null); |
47 | 47 |
this.add(getCmbDistanceUnits(), null); |
48 | 48 |
this.add(getAcceptCancel(), null); |
... | ... | |
114 | 114 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG); |
115 | 115 |
wi.setTitle(PluginServices.getText(this, "distance_units")); |
116 | 116 |
|
117 |
JComponent statusBar = PluginServices.getMainFrame().getStatusBar(); |
|
118 |
JComponent component = PluginServices.getMainFrame().getComponentByName("coords"); |
|
119 |
wi.setX(component.getX()); |
|
120 |
wi.setY(statusBar.getY()); |
|
121 |
|
|
122 | 117 |
return wi; |
123 | 118 |
} |
124 | 119 |
|
branches/v10/extensions/extCoords/src/org/gvsig/iver/extensions/coords/CoordsExtension.java | ||
---|---|---|
38 | 38 |
* +34 963163400 |
39 | 39 |
* dac@iver.es |
40 | 40 |
*/ |
41 |
|
|
42 | 41 |
package org.gvsig.iver.extensions.coords; |
43 | 42 |
|
44 |
import java.awt.event.ActionEvent;
|
|
45 |
import java.awt.event.ActionListener;
|
|
43 |
import java.awt.Dimension;
|
|
44 |
import java.awt.event.MouseAdapter;
|
|
46 | 45 |
|
47 |
import org.apache.log4j.Logger;
|
|
48 |
import org.gvsig.gui.beans.controls.combolabel.ComboCoords;
|
|
46 |
import javax.swing.BorderFactory;
|
|
47 |
import javax.swing.border.BevelBorder;
|
|
49 | 48 |
|
50 | 49 |
import com.iver.andami.PluginServices; |
51 | 50 |
import com.iver.andami.plugins.Extension; |
52 |
import com.iver.andami.plugins.IExtension; |
|
53 | 51 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
54 | 52 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
55 | 53 |
|
... | ... | |
59 | 57 |
* This extension replaces the labels which contain the coordinates with |
60 | 58 |
* new labels which show a window and allow to change the View coordinates. |
61 | 59 |
*/ |
62 |
public class CoordsExtension extends Extension implements ActionListener { |
|
63 |
private Logger logger = PluginServices.getLogger(); |
|
64 |
private String CONTROLNAME = "coords"; |
|
65 |
private ComboCoords coordsControl; |
|
66 |
private String axisText0 = "X ="; |
|
67 |
private String axisText1 = "Y ="; |
|
60 |
public class CoordsExtension extends Extension { |
|
61 |
//private Logger logger = PluginServices.getLogger(); |
|
62 |
private Label xLabel = null; |
|
63 |
private Label yLabel = null; |
|
64 |
private Label unitsLabel = null; |
|
65 |
private Label projectionLabel = null; |
|
66 |
private int numLabel=0; |
|
68 | 67 |
|
69 | 68 |
/* (non-Javadoc) |
70 | 69 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String) |
... | ... | |
75 | 74 |
return; |
76 | 75 |
|
77 | 76 |
if (actionCommand.startsWith("CHANGE_UNITS")){ |
78 |
System.out.println("CoordsExtension -- CHANGE_UNITS"); |
|
79 |
View view = (View)activeWindow; |
|
80 |
IProjectView model = view.getModel(); |
|
81 |
DistanceUnitsConfig duc=new DistanceUnitsConfig(model); |
|
82 |
PluginServices.getMDIManager().addWindow(duc); |
|
77 |
View view = (View)activeWindow; |
|
78 |
IProjectView model = view.getModel(); |
|
79 |
DistanceUnitsConfig duc=new DistanceUnitsConfig(model); |
|
80 |
PluginServices.getMDIManager().addWindow(duc); |
|
83 | 81 |
} |
84 | 82 |
} |
85 | 83 |
|
... | ... | |
87 | 85 |
* @see com.iver.andami.plugins.IExtension#initialize() |
88 | 86 |
*/ |
89 | 87 |
public void initialize() { |
90 |
PluginServices.getMainFrame().removeStatusBarLabels(com.iver.cit.gvsig.project.documents.view.gui.View.class); |
|
88 |
// remove the previous existing labels |
|
89 |
PluginServices.getMainFrame().removeStatusBarLabels(View.class); |
|
91 | 90 |
|
92 |
// add the new control |
|
93 |
coordsControl = new org.gvsig.gui.beans.controls.combolabel.ComboCoords(); |
|
94 |
coordsControl.setLabelX(axisText0); |
|
95 |
coordsControl.setLabelY(axisText1); |
|
96 |
coordsControl.setValueX(""); |
|
97 |
coordsControl.setValueY(""); |
|
98 |
coordsControl.addActionListener(this); |
|
99 |
coordsControl.setName(CONTROLNAME); |
|
100 |
|
|
101 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class,coordsControl); |
|
102 |
PluginServices.getMainFrame().setStatusBarLabels(com.iver.cit.gvsig.project.documents.view.gui.View.class, getLabelSet()); |
|
91 |
// add new Label controls |
|
92 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, getXLabel()); |
|
93 |
getXLabel().setText("X ="); |
|
94 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, getYLabel()); |
|
95 |
getYLabel().setText("Y ="); |
|
96 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, getUnitsLabel()); |
|
97 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, getProjectionLabel()); |
|
103 | 98 |
|
104 |
// add fake controls for x and y, so that they listen the coords sent by gvsig and display them in our coordsControl |
|
105 |
FakeControl xControl = new FakeControl(); |
|
106 |
xControl.setName("x"); |
|
107 |
xControl.addActionListener(new ActionListener() { |
|
108 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
109 |
String[] commandParts = e.getActionCommand().split(" = "); |
|
110 |
if (commandParts.length==2) |
|
111 |
coordsControl.setValueX(commandParts[1]); |
|
112 |
} |
|
113 |
} |
|
114 |
); |
|
115 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, xControl); |
|
116 |
FakeControl yControl = new FakeControl(); |
|
117 |
yControl.setName("y"); |
|
118 |
yControl.addActionListener(new ActionListener() { |
|
119 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
120 |
String[] commandParts = e.getActionCommand().split(" = "); |
|
121 |
if (commandParts.length==2) |
|
122 |
coordsControl.setValueY(commandParts[1]); |
|
123 |
} |
|
124 |
} |
|
125 |
); |
|
126 |
PluginServices.getMainFrame().addStatusBarControl(CoordsExtension.class, yControl); |
|
99 |
// add listeners |
|
100 |
getXLabel().addMouseListener(new MouseListener()); |
|
101 |
getYLabel().addMouseListener(new MouseListener()); |
|
102 |
getUnitsLabel().addMouseListener(new MouseListener()); |
|
127 | 103 |
} |
104 |
|
|
105 |
private void doubleClick(java.awt.event.MouseEvent e) { |
|
106 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
|
107 |
if (!(activeWindow instanceof View)) |
|
108 |
return; |
|
109 |
View view= (View) activeWindow; |
|
110 |
IProjectView model = view.getModel(); |
|
111 |
DistanceUnitsConfig duc=new DistanceUnitsConfig(model); |
|
112 |
PluginServices.getMDIManager().addWindow(duc); |
|
113 |
} |
|
128 | 114 |
|
129 | 115 |
/* (non-Javadoc) |
130 | 116 |
* @see com.iver.andami.plugins.IExtension#isEnabled() |
131 | 117 |
*/ |
132 | 118 |
public boolean isEnabled() { |
133 |
IExtension extension = PluginServices.getExtension(com.iver.cit.gvsig.ViewControls.class); |
|
134 |
return extension.isEnabled(); |
|
119 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = |
|
120 |
PluginServices.getMDIManager().getActiveWindow(); |
|
121 |
|
|
122 |
if (activeWindow!=null && activeWindow instanceof View) { |
|
123 |
return true; |
|
124 |
} |
|
125 |
return false; |
|
135 | 126 |
} |
136 | 127 |
|
137 | 128 |
/* (non-Javadoc) |
138 | 129 |
* @see com.iver.andami.plugins.IExtension#isVisible() |
139 | 130 |
*/ |
140 | 131 |
public boolean isVisible() { |
141 |
IExtension extension = PluginServices.getExtension(com.iver.cit.gvsig.ViewControls.class); |
|
142 |
return extension.isVisible(); |
|
132 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = |
|
133 |
PluginServices.getMDIManager().getActiveWindow(); |
|
134 |
|
|
135 |
if (activeWindow !=null && activeWindow instanceof View) { |
|
136 |
return true; |
|
137 |
} |
|
138 |
return false; |
|
143 | 139 |
} |
144 | 140 |
|
145 |
private com.iver.andami.plugins.config.generate.Label[] getLabelSet() { |
|
146 |
com.iver.andami.plugins.config.generate.Label unitsLabel = new com.iver.andami.plugins.config.generate.Label(); |
|
147 |
unitsLabel.setSize(85); |
|
148 |
unitsLabel.setId("units"); |
|
149 |
com.iver.andami.plugins.config.generate.Label projectionLabel = new com.iver.andami.plugins.config.generate.Label(); |
|
150 |
projectionLabel.setSize(85); |
|
151 |
projectionLabel.setId("projection"); |
|
152 |
com.iver.andami.plugins.config.generate.Label[] labels = new com.iver.andami.plugins.config.generate.Label[2]; |
|
153 |
labels[0]=unitsLabel; |
|
154 |
labels[1]=projectionLabel; |
|
155 |
return labels; |
|
141 |
private Label getLabel(int width) { |
|
142 |
Label lbl = new Label(); |
|
143 |
lbl.setPreferredSize(new Dimension(width, PluginServices.getMainFrame().getStatusBar().getHeight()-2)); |
|
144 |
lbl.setSize(new Dimension(width, PluginServices.getMainFrame().getStatusBar().getHeight()-2)); |
|
145 |
lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); |
|
146 |
lbl.setName("Label"+numLabel++); |
|
147 |
return lbl; |
|
156 | 148 |
} |
157 |
|
|
158 |
public void actionPerformed(ActionEvent e) { |
|
149 |
|
|
150 |
public Label getXLabel() { |
|
151 |
if (xLabel!=null) |
|
152 |
return xLabel; |
|
153 |
xLabel = getLabel(120); |
|
154 |
xLabel.setName("x"); |
|
155 |
return xLabel; |
|
159 | 156 |
} |
160 | 157 |
|
158 |
public Label getYLabel() { |
|
159 |
if (yLabel!=null) |
|
160 |
return yLabel; |
|
161 |
yLabel = getLabel(120); |
|
162 |
yLabel.setName("y"); |
|
163 |
return yLabel; |
|
164 |
} |
|
165 |
|
|
166 |
public Label getUnitsLabel() { |
|
167 |
if (unitsLabel!=null) |
|
168 |
return unitsLabel; |
|
169 |
unitsLabel = getLabel(85); |
|
170 |
unitsLabel.setName("units"); |
|
171 |
return unitsLabel; |
|
172 |
} |
|
173 |
|
|
174 |
public Label getProjectionLabel() { |
|
175 |
if (projectionLabel!=null) |
|
176 |
return projectionLabel; |
|
177 |
projectionLabel = getLabel(85); |
|
178 |
projectionLabel.setName("projection"); |
|
179 |
return projectionLabel; |
|
180 |
} |
|
181 |
|
|
182 |
private class MouseListener extends MouseAdapter { |
|
183 |
public void mouseClicked(java.awt.event.MouseEvent e) { |
|
184 |
//simpleClick(e); |
|
185 |
if (e.getClickCount()==2) { |
|
186 |
doubleClick(e); |
|
187 |
} |
|
188 |
} |
|
189 |
} |
|
161 | 190 |
} |
branches/v10/extensions/extCoords/.classpath | ||
---|---|---|
3 | 3 |
<classpathentry kind="src" path="src"/> |
4 | 4 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
5 | 5 |
<classpathentry combineaccessrules="false" kind="src" path="/_fwAndami"/> |
6 |
<classpathentry kind="lib" path="/_fwAndami/lib/beans.jar" sourcepath="/libUI/src"/>
|
|
6 |
<classpathentry kind="lib" path="/_fwAndami/lib/beans.jar"/> |
|
7 | 7 |
<classpathentry kind="lib" path="/_fwAndami/lib/log4j-1.2.8.jar"/> |
8 | 8 |
<classpathentry combineaccessrules="false" kind="src" path="/appgvSIG"/> |
9 |
<classpathentry combineaccessrules="false" kind="src" path="/libFMap"/> |
|
9 | 10 |
<classpathentry kind="output" path="bin"/> |
10 | 11 |
</classpath> |
Also available in: Unified diff