svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / expressionevaluator / ViewCapturePointPanel.java @ 44007
History | View | Annotate | Download (5.24 KB)
1 |
package org.gvsig.app.project.documents.view.expressionevaluator; |
---|---|
2 |
|
3 |
import java.awt.Image; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.awt.event.ComponentAdapter; |
7 |
import java.awt.event.ComponentEvent; |
8 |
import javax.swing.JComponent; |
9 |
import javax.swing.event.AncestorEvent; |
10 |
import javax.swing.event.AncestorListener; |
11 |
import org.gvsig.andami.IconThemeHelper; |
12 |
import org.gvsig.app.ApplicationLocator; |
13 |
import org.gvsig.app.ApplicationManager; |
14 |
import org.gvsig.app.project.documents.view.ViewDocument; |
15 |
import org.gvsig.app.project.documents.view.ViewManager; |
16 |
import org.gvsig.app.project.documents.view.gui.IView; |
17 |
import org.gvsig.fmap.geom.Geometry; |
18 |
import org.gvsig.fmap.mapcontrol.MapControl; |
19 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
20 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
21 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
22 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
23 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener; |
24 |
import org.gvsig.tools.ToolsLocator; |
25 |
import org.gvsig.tools.i18n.I18nManager; |
26 |
import org.gvsig.tools.swing.api.Component; |
27 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
28 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
29 |
|
30 |
/**
|
31 |
*
|
32 |
* @author jjdelcerro
|
33 |
*/
|
34 |
@SuppressWarnings("UseSpecificCatch") |
35 |
public class ViewCapturePointPanel extends ViewCapturePointPanelView implements Component { |
36 |
|
37 |
private Geometry geometry = null; |
38 |
private MapControl mapControl = null; |
39 |
private String previousTool = null; |
40 |
private Behavior tool = null; |
41 |
|
42 |
public ViewCapturePointPanel() {
|
43 |
this.initComponents();
|
44 |
} |
45 |
|
46 |
private void initComponents() { |
47 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
48 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
49 |
|
50 |
toolsSwingManager.setDefaultPopupMenu(this.txtPoint);
|
51 |
|
52 |
this.btnToggleCapture.addActionListener(new ActionListener() { |
53 |
@Override
|
54 |
public void actionPerformed(ActionEvent e) { |
55 |
doToggleCapture(); |
56 |
} |
57 |
}); |
58 |
this.tool = new PointBehavior(new PointListener() { |
59 |
@Override
|
60 |
public void point(PointEvent event) throws BehaviorException { |
61 |
setGeometry(event.getMapPoint()); |
62 |
} |
63 |
|
64 |
@Override
|
65 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
66 |
setGeometry(event.getMapPoint()); |
67 |
} |
68 |
|
69 |
@Override
|
70 |
public Image getImageCursor() { |
71 |
return IconThemeHelper.getImage("cursor-select-by-point"); |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public boolean cancelDrawing() { |
76 |
return false; |
77 |
} |
78 |
}); |
79 |
this.btnToggleCapture.setText(i18n.getTranslation("_Start_capture")); |
80 |
|
81 |
this.addAncestorListener(new AncestorListener() { |
82 |
@Override
|
83 |
public void ancestorAdded(AncestorEvent event) { |
84 |
} |
85 |
|
86 |
@Override
|
87 |
public void ancestorRemoved(AncestorEvent event) { |
88 |
doEndCapture(); |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public void ancestorMoved(AncestorEvent event) { |
93 |
} |
94 |
}); |
95 |
this.addComponentListener(new ComponentAdapter() { |
96 |
@Override
|
97 |
public void componentHidden(ComponentEvent e) { |
98 |
doEndCapture(); |
99 |
} |
100 |
|
101 |
}); |
102 |
} |
103 |
|
104 |
@Override
|
105 |
public JComponent asJComponent() { |
106 |
return this; |
107 |
} |
108 |
|
109 |
private void setGeometry(Geometry geom) { |
110 |
this.geometry = geom;
|
111 |
try {
|
112 |
String wkt = geom.convertToWKT();
|
113 |
this.txtPoint.setText(wkt);
|
114 |
} catch (Exception ex) { |
115 |
this.txtPoint.setText("#########"); |
116 |
} |
117 |
this.txtPoint.setCaretPosition(0); |
118 |
} |
119 |
|
120 |
private void doToggleCapture() { |
121 |
if( this.mapControl == null ) { |
122 |
doStartCapture(); |
123 |
} else {
|
124 |
doEndCapture(); |
125 |
} |
126 |
} |
127 |
|
128 |
private void doStartCapture() { |
129 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
130 |
ApplicationManager application = ApplicationLocator.getManager(); |
131 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
132 |
if( viewdoc == null ) { |
133 |
return;
|
134 |
} |
135 |
this.mapControl = ((IView)(viewdoc.getMainWindow())).getMapControl();
|
136 |
this.previousTool = this.mapControl.getCurrentTool(); |
137 |
this.mapControl.addBehavior("ElementViewPointCaptureTool", this.tool); |
138 |
this.mapControl.setTool("ElementViewPointCaptureTool"); |
139 |
this.btnToggleCapture.setText(i18n.getTranslation("_End_capture")); |
140 |
|
141 |
} |
142 |
|
143 |
private void doEndCapture() { |
144 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
145 |
if( this.mapControl == null ) { |
146 |
return;
|
147 |
} |
148 |
this.mapControl.setTool(this.previousTool); |
149 |
this.mapControl = null; |
150 |
this.btnToggleCapture.setText(i18n.getTranslation("_Start_capture")); |
151 |
} |
152 |
|
153 |
Geometry getGeometry() { |
154 |
return this.geometry; |
155 |
} |
156 |
|
157 |
boolean insertAsWKT() {
|
158 |
return this.rdoInsertAsWKT.isSelected(); |
159 |
} |
160 |
|
161 |
boolean insertAsGeometry() {
|
162 |
return this.rdoInsertAsGeometry.isSelected(); |
163 |
} |
164 |
|
165 |
} |