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