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 / ViewCaptureRectanglePanel.java @ 44006
History | View | Annotate | Download (4.65 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.RectangleBehavior; |
19 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
20 |
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
21 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener; |
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 ViewCaptureRectanglePanel extends ViewCaptureRectanglePanelView 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 ViewCaptureRectanglePanel() {
|
41 |
this.initComponents();
|
42 |
} |
43 |
|
44 |
private void initComponents() { |
45 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
46 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
47 |
|
48 |
toolsSwingManager.setDefaultPopupMenu(this.txtBox);
|
49 |
|
50 |
this.btnToggleCapture.addActionListener(new ActionListener() { |
51 |
@Override
|
52 |
public void actionPerformed(ActionEvent e) { |
53 |
doToggleCapture(); |
54 |
} |
55 |
}); |
56 |
this.tool = new RectangleBehavior(new RectangleListener() { |
57 |
@Override
|
58 |
public void rectangle(EnvelopeEvent event) throws BehaviorException { |
59 |
setGeometry(event.getWorldCoordRect().getGeometry()); |
60 |
} |
61 |
|
62 |
@Override
|
63 |
public Image getImageCursor() { |
64 |
return IconThemeHelper.getImage("cursor-select-by-rectangle"); |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public boolean cancelDrawing() { |
69 |
return false; |
70 |
} |
71 |
}); |
72 |
this.btnToggleCapture.setText(i18n.getTranslation("_Start_capture")); |
73 |
|
74 |
this.addComponentListener(new ComponentAdapter() { |
75 |
@Override
|
76 |
public void componentHidden(ComponentEvent e) { |
77 |
doEndCapture(); |
78 |
} |
79 |
|
80 |
}); |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public JComponent asJComponent() { |
85 |
return this; |
86 |
} |
87 |
|
88 |
private void setGeometry(Geometry geom) { |
89 |
this.geometry = geom;
|
90 |
try {
|
91 |
String wkt = geom.convertToWKT();
|
92 |
this.txtBox.setText(wkt);
|
93 |
} catch (Exception ex) { |
94 |
this.txtBox.setText("#########"); |
95 |
} |
96 |
this.txtBox.setCaretPosition(0); |
97 |
} |
98 |
|
99 |
private void doToggleCapture() { |
100 |
if( this.mapControl == null ) { |
101 |
doStartCapture(); |
102 |
} else {
|
103 |
doEndCapture(); |
104 |
} |
105 |
} |
106 |
|
107 |
private void doStartCapture() { |
108 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
109 |
ApplicationManager application = ApplicationLocator.getManager(); |
110 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
111 |
if( viewdoc == null ) { |
112 |
return;
|
113 |
} |
114 |
this.mapControl = ((IView)(viewdoc.getMainWindow())).getMapControl();
|
115 |
this.previousTool = this.mapControl.getCurrentTool(); |
116 |
this.mapControl.addBehavior("ElementViewPointCaptureTool", this.tool); |
117 |
this.mapControl.setTool("ElementViewPointCaptureTool"); |
118 |
this.btnToggleCapture.setText(i18n.getTranslation("_End_capture")); |
119 |
|
120 |
} |
121 |
|
122 |
private void doEndCapture() { |
123 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
124 |
if( this.mapControl == null ) { |
125 |
return;
|
126 |
} |
127 |
this.mapControl.setTool(this.previousTool); |
128 |
this.mapControl = null; |
129 |
this.btnToggleCapture.setText(i18n.getTranslation("_Start_capture")); |
130 |
} |
131 |
|
132 |
Geometry getGeometry() { |
133 |
return this.geometry; |
134 |
} |
135 |
|
136 |
boolean insertAsWKT() {
|
137 |
return this.rdoInsertAsWKT.isSelected(); |
138 |
} |
139 |
|
140 |
boolean insertAsGeometry() {
|
141 |
return this.rdoInsertAsGeometry.isSelected(); |
142 |
} |
143 |
|
144 |
} |