root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.swing / org.gvsig.proj.swing.impl / src / main / java / org / gvsig / proj / swing / impl / CrsAndCtSelectorController.java @ 874
History | View | Annotate | Download (4.3 KB)
1 |
package org.gvsig.proj.swing.impl; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
|
7 |
import javax.swing.JComponent; |
8 |
|
9 |
import org.gvsig.proj.CoordinateReferenceSystem; |
10 |
import org.gvsig.proj.CoordinateTransformation; |
11 |
import org.gvsig.proj.swing.CoordinateReferenceSystemAndTransformationSelectorComponent; |
12 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSelectorComponent; |
13 |
|
14 |
public class CrsAndCtSelectorController implements CoordinateReferenceSystemAndTransformationSelectorComponent { |
15 |
private CrsAndCtSelectorView view;
|
16 |
private CrsSelectorController crsSelector;
|
17 |
private CtSelectorController ctSelector;
|
18 |
private DefaultCoordinateReferenceSystemSwingManager manager;
|
19 |
private CrsRole selectedCrsRole = CrsRole.SOURCE;
|
20 |
|
21 |
public CrsAndCtSelectorController(DefaultCoordinateReferenceSystemSwingManager manager) {
|
22 |
this.view = new CrsAndCtSelectorView(); |
23 |
this.manager = manager;
|
24 |
} |
25 |
|
26 |
private void initComponents() { |
27 |
this.crsSelector = new CrsSelectorController(this.manager); |
28 |
this.view.jtabbedpane1.setEnabledAt(1, false); |
29 |
this.view.pnlCrsSelectorContainer.setLayout(new BorderLayout()); |
30 |
this.view.pnlCrsSelectorContainer.add(this.crsSelector.asJComponent(), BorderLayout.CENTER); |
31 |
this.ctSelector = new CtSelectorController(this.manager); |
32 |
this.ctSelector.getView().pnlCrsSelectors.setVisible(false); |
33 |
this.view.pnlCtSelectorContainer.setLayout(new BorderLayout()); |
34 |
this.view.pnlCtSelectorContainer.add(this.ctSelector.asJComponent(), BorderLayout.CENTER); |
35 |
this.crsSelector.addCRSSelectionListener(new ActionListener() { |
36 |
|
37 |
@Override
|
38 |
public void actionPerformed(ActionEvent e) { |
39 |
// CtSelector tab should be enabled only if a Crs was selected by the user
|
40 |
CrsAndCtSelectorController.this.setCtTabEnabledStatus(); |
41 |
} |
42 |
}); |
43 |
} |
44 |
|
45 |
@Override
|
46 |
public JComponent asJComponent() { |
47 |
return this.view; |
48 |
} |
49 |
|
50 |
@Override
|
51 |
public CoordinateReferenceSystemSelectorComponent getCoordinateReferenceSystemSelectorComponent() {
|
52 |
return this.crsSelector; |
53 |
} |
54 |
|
55 |
@Override
|
56 |
public CoordinateReferenceSystem getCoordinateReferenceSystem() {
|
57 |
return this.crsSelector.getCoordinateReferenceSystem(); |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public CoordinateTransformation getCoordinateTransformation() {
|
62 |
return this.ctSelector.getCoordinateTransformation(); |
63 |
} |
64 |
|
65 |
@Override
|
66 |
public void setSelectedCoordinateReferenceSystem(CoordinateReferenceSystem selectableCrs) { |
67 |
this.crsSelector.setCoordinateReferenceSystem(selectableCrs);
|
68 |
if (this.selectedCrsRole.equals(CrsRole.SOURCE)) { |
69 |
this.ctSelector.setSourceCoordinateReferenceSystem(selectableCrs);
|
70 |
} |
71 |
else {
|
72 |
this.ctSelector.setTargetCoordinateReferenceSystem(selectableCrs);
|
73 |
} |
74 |
setCtTabEnabledStatus(); |
75 |
} |
76 |
|
77 |
@Override
|
78 |
public void setFixedCoordinateReferenceSystem(CoordinateReferenceSystem fixedCrs, CrsRole role) { |
79 |
if (role.equals(CrsRole.SOURCE)) {
|
80 |
this.ctSelector.setSourceCoordinateReferenceSystem(fixedCrs);
|
81 |
this.selectedCrsRole = CrsRole.TARGET;
|
82 |
} |
83 |
else {
|
84 |
this.ctSelector.setTargetCoordinateReferenceSystem(fixedCrs);
|
85 |
this.selectedCrsRole = CrsRole.SOURCE;
|
86 |
} |
87 |
setCtTabEnabledStatus(); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* Enables the CtSelector tab when a source and target CRS are available and are different,
|
92 |
* and disables the tab otherwise
|
93 |
*/
|
94 |
protected void setCtTabEnabledStatus() { |
95 |
if (this.ctSelector.getSourceCoordinateReferenceSystem()!=null && |
96 |
this.ctSelector.getTargetCoordinateReferenceSystem()!=null |
97 |
&& !(this.ctSelector.getSourceCoordinateReferenceSystem().equals(this.ctSelector.getTargetCoordinateReferenceSystem()))) { |
98 |
this.view.jtabbedpane1.setEnabledAt(1, true); |
99 |
} |
100 |
else {
|
101 |
this.view.jtabbedpane1.setEnabledAt(1, true); |
102 |
} |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public CrsRole getSelectedCrsRole() {
|
107 |
return this.selectedCrsRole; |
108 |
} |
109 |
|
110 |
@Override
|
111 |
public CrsRole getFixedCrsRole() {
|
112 |
if (this.selectedCrsRole.equals(CrsRole.SOURCE)) { |
113 |
return CrsRole.TARGET;
|
114 |
} |
115 |
else {
|
116 |
return CrsRole.SOURCE;
|
117 |
} |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public void addCoordinateTransformationSelectionListener(ActionListener listener) { |
122 |
this.ctSelector.addCoordinateTransformationSelectionListener(listener);
|
123 |
} |
124 |
|
125 |
@Override
|
126 |
public void addCRSSelectionListener(ActionListener listener) { |
127 |
this.crsSelector.addCRSSelectionListener(listener);
|
128 |
} |
129 |
|
130 |
@Override
|
131 |
public void enableTransformationAlphanumericFilter(String searchString) { |
132 |
this.ctSelector.enableAlphanumericFilter(searchString);
|
133 |
} |
134 |
|
135 |
} |