Revision 219 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java
FFrameView.java | ||
---|---|---|
106 | 106 |
|
107 | 107 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrameView"; |
108 | 108 |
|
109 |
private static final String MODE_FIELD = "mode"; |
|
110 |
private static final String TYPESCALE_FIELD = "typeScale"; |
|
111 | 109 |
private static final String QUALITY_FIELD = "quality"; |
112 |
private static final String BLINKED_FIELD = "bLinked"; |
|
113 | 110 |
private static final String MAPUNITS_FIELD = "mapUnits"; |
114 | 111 |
private static final String SCALE_FIELD = "scale"; |
115 | 112 |
private static final String VIEW_FIELD = "view"; |
... | ... | |
117 | 114 |
private static final String SHOWGRID_FIELD = "showGrid"; |
118 | 115 |
private static final String GRID_FIELD = "gridview"; |
119 | 116 |
private static final String HAS_TOC = "hasToc"; |
120 |
// following fields are unused - should be deleted? |
|
117 |
private static final String LAYER_SYNC_FIELD = "layerSync"; |
|
118 |
private static final String EXTENT_SYNC_FIELD = "extentSync"; |
|
119 |
// following fields are unused - they are kept for backward-compatibility |
|
121 | 120 |
private static final String EXTENSION_FIELD = "extension"; |
121 |
private static final String BLINKED_FIELD = "bLinked"; |
|
122 |
private static final String MODE_FIELD = "mode"; |
|
123 |
private static final String TYPESCALE_FIELD = "typeScale"; |
|
124 |
private static final String MAPCONTEXT_FIELD = "mapContext"; |
|
125 |
private static final String VIEWING_FIELD = "viewing"; |
|
122 | 126 |
|
123 | 127 |
private static final Logger logger = LoggerFactory |
124 | 128 |
.getLogger(FFrameView.class); |
125 | 129 |
public static final int PRESENTATION = 0; |
126 | 130 |
public static final int DRAFT = 1; |
127 |
protected int mode;
|
|
128 |
protected int typeScale = AUTOMATICO;
|
|
131 |
protected boolean syncLayers = true;
|
|
132 |
protected boolean syncExtents = true;
|
|
129 | 133 |
protected int quality = PRESENTATION; |
130 |
protected boolean linked = true; |
|
131 | 134 |
protected ViewDocument viewDocument = null; |
132 | 135 |
protected MapContext mapContext = null; |
133 | 136 |
protected int mapUnits = 1; // Meters. |
... | ... | |
270 | 273 |
clearOwnListeners(mapContext); |
271 | 274 |
} |
272 | 275 |
try { |
273 |
if (linked){
|
|
276 |
if (syncLayers){
|
|
274 | 277 |
mapContext = |
275 | 278 |
viewMapContext.createNewFMap( |
276 | 279 |
(ViewPort) viewMapContext.getViewPort().clone()); |
... | ... | |
622 | 625 |
} |
623 | 626 |
|
624 | 627 |
/** |
625 |
* Seleccionar si la vista esta relacionada o no con la original. |
|
626 |
* |
|
627 |
* @param b |
|
628 |
* true si est? ligada y false si no lo est?. |
|
629 |
*/ |
|
630 |
public void setLinked(boolean b) { |
|
631 |
linked = b; |
|
632 |
resetListeners(); |
|
633 |
} |
|
634 |
|
|
635 |
/** |
|
636 |
* Devuelve si est? ligada o no el FFrameView con la vista. |
|
637 |
* |
|
638 |
* @return True si la vista est? ligada. |
|
639 |
*/ |
|
640 |
public boolean getLinked() { |
|
641 |
return linked; |
|
642 |
} |
|
643 |
|
|
644 |
/** |
|
645 |
* Devuelve el tipo de escala que est? seleccionada AUTOMATICO o |
|
646 |
* MANUAL. |
|
647 |
* |
|
648 |
* @return entero que representa el tipo seleccionado. |
|
649 |
*/ |
|
650 |
public int getTypeScale() { |
|
651 |
return typeScale; |
|
652 |
} |
|
653 |
|
|
654 |
/** |
|
655 |
* Rellenar el tipo de escala que se desea. |
|
656 |
* |
|
657 |
* @param i |
|
658 |
* entero que representa el tipo de escala. |
|
659 |
*/ |
|
660 |
public void setTypeScale(int i) { |
|
661 |
typeScale = i; |
|
662 |
resetListeners(); |
|
663 |
} |
|
664 |
|
|
665 |
/** |
|
666 | 628 |
* Inserta la imagen para repintar el FFrameView. |
667 | 629 |
* |
668 | 630 |
* @param bi |
... | ... | |
812 | 774 |
Document d = ProjectManager.getInstance().getCurrentProject().getDocuments().get(0); |
813 | 775 |
FFrameView frame = (FFrameView) super.clone(); |
814 | 776 |
frame.createListeners(); // necessary to create the listeners within the right scope |
815 |
frame.setView(this.getView()); |
|
777 |
frame.setView(this.getView()); |
|
778 |
frame.getMapContext().getViewPort().setEnvelope(getMapContext().getViewPort().getEnvelope()); |
|
816 | 779 |
|
817 | 780 |
if (grid != null) { |
818 | 781 |
FFrameGrid newGrid = (FFrameGrid) this.grid.clone(); |
... | ... | |
860 | 823 |
definition.extend(manager |
861 | 824 |
.getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME)); |
862 | 825 |
|
863 |
definition.addDynFieldInt(MODE_FIELD).setMandatory(true); |
|
864 |
definition.addDynFieldInt(TYPESCALE_FIELD).setMandatory(true); |
|
865 | 826 |
definition.addDynFieldInt(EXTENSION_FIELD).setMandatory(false); |
866 | 827 |
definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true); |
867 |
definition.addDynFieldBoolean(BLINKED_FIELD).setMandatory(true); |
|
868 | 828 |
definition.addDynFieldInt(MAPUNITS_FIELD).setMandatory(true); |
869 | 829 |
definition.addDynFieldDouble(SCALE_FIELD).setMandatory(false); |
870 | 830 |
definition.addDynFieldObject(VIEW_FIELD) |
... | ... | |
875 | 835 |
definition.addDynFieldObject(GRID_FIELD) |
876 | 836 |
.setClassOfValue(IFFrame.class).setMandatory(false); |
877 | 837 |
definition.addDynFieldBoolean(HAS_TOC).setMandatory(false); |
838 |
// unused fields, kept for backward compatibility |
|
839 |
definition.addDynFieldInt(MODE_FIELD).setMandatory(false); |
|
840 |
definition.addDynFieldInt(TYPESCALE_FIELD).setMandatory(false); |
|
841 |
definition.addDynFieldBoolean(BLINKED_FIELD).setMandatory(false); |
|
842 |
definition.addDynFieldObject(MAPCONTEXT_FIELD) |
|
843 |
.setClassOfValue(MapContext.class).setMandatory(false); |
|
844 |
definition.addDynFieldInt(VIEWING_FIELD).setMandatory(false); |
|
878 | 845 |
} |
879 | 846 |
} |
880 | 847 |
|
... | ... | |
883 | 850 |
throws PersistenceException { |
884 | 851 |
super.loadFromState(state); |
885 | 852 |
b_frameInitialized = false; |
886 |
mode = state.getInt(MODE_FIELD); |
|
887 |
typeScale = state.getInt(TYPESCALE_FIELD); |
|
853 |
if (state.hasValue(EXTENT_SYNC_FIELD)) { |
|
854 |
syncExtents = state.getBoolean(EXTENT_SYNC_FIELD); |
|
855 |
} |
|
856 |
else { |
|
857 |
syncExtents = true; |
|
858 |
} |
|
859 |
if (state.hasValue(LAYER_SYNC_FIELD)) { |
|
860 |
syncLayers = state.getBoolean(LAYER_SYNC_FIELD); |
|
861 |
} |
|
862 |
else { |
|
863 |
syncLayers = true; |
|
864 |
} |
|
888 | 865 |
quality = state.getInt(QUALITY_FIELD); |
889 |
linked = state.getBoolean(BLINKED_FIELD);
|
|
866 |
syncLayers = state.getBoolean(BLINKED_FIELD);
|
|
890 | 867 |
mapUnits = state.getInt(MAPUNITS_FIELD);; |
891 | 868 |
viewDocument = (ViewDocument) state.get(VIEW_FIELD); |
892 | 869 |
if (state.hasValue(HAS_TOC)) { |
... | ... | |
916 | 893 |
@Override |
917 | 894 |
public void saveToState(PersistentState state) throws PersistenceException { |
918 | 895 |
super.saveToState(state); |
919 |
state.set(MODE_FIELD, mode);
|
|
920 |
state.set(TYPESCALE_FIELD, typeScale);
|
|
896 |
state.set(EXTENT_SYNC_FIELD, syncExtents);
|
|
897 |
state.set(LAYER_SYNC_FIELD, syncLayers);
|
|
921 | 898 |
state.set(QUALITY_FIELD, quality); |
922 |
state.set(BLINKED_FIELD, linked); |
|
923 | 899 |
state.set(MAPUNITS_FIELD, mapUnits); |
924 | 900 |
state.set(VIEW_FIELD, viewDocument); |
925 | 901 |
state.set(HAS_TOC, b_hasToc); |
... | ... | |
991 | 967 |
|
992 | 968 |
protected void setListeners() { |
993 | 969 |
if (getView()!=null) { |
994 |
if (linked) {
|
|
970 |
if (syncLayers) {
|
|
995 | 971 |
getView().getMapContext().addLayerListener(viewDocListener); |
996 | 972 |
getView().getMapContext().getLayers().addLayerCollectionListener(viewDocListener); |
997 | 973 |
getView().getMapContext().addAtomicEventListener(viewDocListener); |
998 | 974 |
} |
999 |
if (getTypeScale()==IFFrameUseFMap.AUTOMATICO) {
|
|
975 |
if (getExtentSynced()) {
|
|
1000 | 976 |
getView().getMapContext().getViewPort().addViewPortListener(viewDocListener); |
1001 | 977 |
} |
1002 | 978 |
} |
... | ... | |
1080 | 1056 |
updateScaleCtrl(); |
1081 | 1057 |
} |
1082 | 1058 |
} |
1059 |
|
|
1060 |
public boolean getLayerSynced() { |
|
1061 |
return syncLayers; |
|
1062 |
} |
|
1083 | 1063 |
|
1064 |
public void setLayerSynced(boolean synced) { |
|
1065 |
syncLayers = synced; |
|
1066 |
resetListeners(); |
|
1067 |
} |
|
1068 |
|
|
1069 |
public boolean getExtentSynced() { |
|
1070 |
return syncExtents; |
|
1071 |
} |
|
1072 |
|
|
1073 |
public void setExtentSynced(boolean synced) { |
|
1074 |
syncExtents = synced; |
|
1075 |
resetListeners(); |
|
1076 |
} |
|
1077 |
|
|
1084 | 1078 |
private class ViewDocListener |
1085 | 1079 |
implements ViewPortListener, LegendListener, LayerCollectionListener, AtomicEventListener { |
1086 | 1080 |
|
1087 | 1081 |
public void extentChanged(ExtentEvent e) { |
1088 |
if (!b_updating && getTypeScale()==AUTOMATICO) {
|
|
1082 |
if (!b_updating && getExtentSynced()) {
|
|
1089 | 1083 |
if (!b_frameInitialized) { |
1090 | 1084 |
b_frameInitialized = true; |
1091 | 1085 |
return; |
... | ... | |
1101 | 1095 |
} |
1102 | 1096 |
|
1103 | 1097 |
public void backColorChanged(ColorEvent e) { |
1104 |
if (!b_updating && linked) {
|
|
1098 |
if (!b_updating && syncLayers) {
|
|
1105 | 1099 |
if (getMapContext()!=null) { |
1106 | 1100 |
b_updating = true; |
1107 | 1101 |
mapContext.getViewPort().setBackColor(e.getNewColor()); |
... | ... | |
1112 | 1106 |
} |
1113 | 1107 |
|
1114 | 1108 |
public void projectionChanged(ProjectionEvent e) { |
1115 |
if (!b_updating && getTypeScale()==AUTOMATICO) {
|
|
1109 |
if (!b_updating && getExtentSynced()) {
|
|
1116 | 1110 |
if (getMapContext()!=null) { |
1117 | 1111 |
b_updating = true; |
1118 | 1112 |
getMapContext().getViewPort().setProjection(e.getNewProjection()); |
... | ... | |
1124 | 1118 |
} |
1125 | 1119 |
|
1126 | 1120 |
public void conditionalRedraw() { |
1127 |
if (!b_updating && linked) {
|
|
1121 |
if (!b_updating && syncLayers) {
|
|
1128 | 1122 |
b_updating = true; |
1129 | 1123 |
invalidateLayout(); |
1130 | 1124 |
// the view should also receive the event and update automatically |
... | ... | |
1199 | 1193 |
implements ViewPortListener, LegendListener, LayerCollectionListener { |
1200 | 1194 |
|
1201 | 1195 |
public void extentChanged(ExtentEvent e) { |
1202 |
if (!b_drawing && !b_updating && (getTypeScale() == AUTOMATICO)) {
|
|
1196 |
if (!b_drawing && !b_updating) { |
|
1203 | 1197 |
if (getView()!=null) { |
1204 | 1198 |
b_updating = true; |
1205 |
getView().getMapContext().getViewPort().setEnvelope(e.getNewExtent()); |
|
1199 |
if (getExtentSynced()){ |
|
1200 |
getView().getMapContext().getViewPort().setEnvelope(e.getNewExtent()); |
|
1201 |
} |
|
1206 | 1202 |
updateScaleCtrl(); |
1207 | 1203 |
invalidateLayout(); |
1208 | 1204 |
b_updating = false; |
... | ... | |
1214 | 1210 |
if (!b_updating) { |
1215 | 1211 |
if (getView()!=null) { |
1216 | 1212 |
b_updating = true; |
1217 |
getView().getMapContext().getViewPort().setBackColor(e.getNewColor()); |
|
1213 |
if (getLayerSynced()) { |
|
1214 |
getView().getMapContext().getViewPort().setBackColor(e.getNewColor()); |
|
1215 |
} |
|
1218 | 1216 |
invalidateLayout(); |
1219 | 1217 |
b_updating = false; |
1220 | 1218 |
} |
... | ... | |
1222 | 1220 |
} |
1223 | 1221 |
|
1224 | 1222 |
public void projectionChanged(ProjectionEvent e) { |
1225 |
if (!b_updating && (getTypeScale() == AUTOMATICO)) {
|
|
1223 |
if (!b_updating && getExtentSynced()) {
|
|
1226 | 1224 |
if (getView()!=null) { |
1227 | 1225 |
b_updating = true; |
1228 |
getView().getMapContext().getViewPort().setProjection(e.getNewProjection()); |
|
1226 |
if (getLayerSynced()) { |
|
1227 |
getView().getMapContext().getViewPort().setProjection(e.getNewProjection()); |
|
1228 |
} |
|
1229 | 1229 |
invalidateLayout(); |
1230 | 1230 |
// FIXME: force also a view redraw someway?? |
1231 | 1231 |
b_updating = false; |
... | ... | |
1295 | 1295 |
throws CancelationException { |
1296 | 1296 |
conditionalRedraw(); |
1297 | 1297 |
} |
1298 |
|
|
1299 | 1298 |
} |
1300 | 1299 |
} |
Also available in: Unified diff