Revision 168

View differences:

trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/LayoutContext.java
265 265
     * Triggers a notification to the TocModel observers of type
266 266
     * {@link TocModelChangedNotification#MODEL_CHANGED}
267 267
     */
268
	public void notifyTocUpdated();
268
	public void notifyTocUpdated(TocModelChangedNotification.Type notificationType);
269 269
    
270 270
    public void addTocObserver(TocModelObserver observer);
271 271
    
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/DefaultLayoutContext.java
428 428
		}
429 429
		else {
430 430
	    	tocObservers.notifyObservers(this, 
431
	                new TocModelChangedImpl(TocModelChangedNotification.MODEL_SET, tocModel));			
431
	                new TocModelChangedImpl(TocModelChangedNotification.Type.MODEL_SET, tocModel));			
432 432
		}
433 433
	}
434 434
	
435
	public void notifyTocUpdated() {
435
	public void notifyTocUpdated(TocModelChangedNotification.Type type) {
436 436
    	tocObservers.notifyObservers(this, 
437
                new TocModelChangedImpl(TocModelChangedNotification.MODEL_CHANGED, tocModel));			
437
    			new TocModelChangedImpl(type, tocModel));			
438 438
		
439 439
	}
440 440

  
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/TocModelChangedNotification.java
8 8
 *
9 9
 */
10 10
public interface TocModelChangedNotification {
11
	/**
12
	 * The model (MapContext object) has been set (understood as
13
	 * added, removed or replaced) by a new one, including a null one.
14
	 */
15
	public static final String MODEL_SET = "model_replaced";
16
	/**
17
	 * There has been some change on the model (layer added or removed,
18
	 * visibility changes, etc)
19
	 */	
20
	public static final String MODEL_CHANGED = "model_changed";
21 11
	
12
	public enum Type {
13
		/**
14
		 * The model (MapContext object) has been set (understood as
15
		 * added, removed or replaced) by a new one, including a null one.
16
		 */
17
		MODEL_SET,
18

  
19
		/**
20
		 * There has been some change on the model collection
21
		 * (layer added or removed, visibility changed, etc)
22
		 */	
23
		MODEL_CHANGED;		
24
	}
25

  
22 26
    /**
23 27
     * Returns the type of this notification, represented by one of the constants defined in this interface.
24 28
     * @return a String containing this notification's type
25 29
     */
26
    public String getType();
30
    public Type getType();
27 31
    
28 32
    /**
29 33
     * Gets the added or changed model
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/TocModelChangedImpl.java
4 4

  
5 5
public class TocModelChangedImpl implements TocModelChangedNotification {
6 6
	private MapContext mapContext = null;
7
	private String type = null;
7
	private Type type = null;
8 8
	
9
	public TocModelChangedImpl(String type, MapContext model) {
9
	public TocModelChangedImpl(Type type, MapContext model) {
10 10
		this.type = type;
11 11
		this.mapContext = model;
12 12
	}	
......
15 15
		return mapContext;
16 16
	}
17 17

  
18
	public String getType() {
18
	public Type getType() {
19 19
		return type;
20 20
	}
21 21

  
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
44 44
import org.gvsig.app.project.documents.layout.FLayoutFunctions;
45 45
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
46 46
import org.gvsig.app.project.documents.layout.LayoutNotification;
47
import org.gvsig.app.project.documents.layout.TocModelChangedImpl;
48
import org.gvsig.app.project.documents.layout.TocModelChangedNotification;
47 49
import org.gvsig.app.project.documents.view.ViewDocument;
48
import org.gvsig.app.project.documents.view.toc.gui.TOC;
49 50
import org.gvsig.compat.print.PrintAttributes;
50 51
import org.gvsig.fmap.dal.exception.ReadException;
51 52
import org.gvsig.fmap.geom.Geometry;
......
62 63
import org.gvsig.fmap.mapcontext.layers.CancelationException;
63 64
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
64 65
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener;
66
import org.gvsig.fmap.mapcontext.layers.LayerEvent;
65 67
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent;
66
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
67
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
68 68
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
69 69
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener;
70 70
import org.gvsig.gui.beans.Messages;
......
95 95
    private static final String ENVELOPE_FIELD = "envelope";
96 96
    private static final String SHOWGRID_FIELD = "showGrid";
97 97
    private static final String GRID_FIELD = "gridview";
98
    private static final String MAPCONTEXT_FIELD = "mapContext";
99 98
    // following fields are unused - should be deleted? 
100 99
    private static final String EXTENSION_FIELD = "extension";
101 100
    private static final String HAS_TOC = "hasToc";
......
129 128
	protected OwnMapContextListener ownMapContextListener;
130 129
	private boolean b_hasToc = false;
131 130

  
131
	private boolean b_updatingToc=false;
132 132

  
133

  
133 134
    /**
134 135
     * Creates a new FFrameView object.
135 136
     */
......
771 772
            definition.addDynFieldBoolean(SHOWGRID_FIELD).setMandatory(true);
772 773
            definition.addDynFieldObject(GRID_FIELD)
773 774
                .setClassOfValue(IFFrame.class).setMandatory(false);
774
            definition.addDynFieldObject(MAPCONTEXT_FIELD)
775
                .setClassOfValue(MapContext.class).setMandatory(false);
776 775
            definition.addDynFieldBoolean(HAS_TOC).setMandatory(false);
777 776
        }
778 777
    }
......
787 786
        linked = state.getBoolean(BLINKED_FIELD);
788 787
        mapUnits = state.getInt(MAPUNITS_FIELD);;
789 788
        viewDocument = (ViewDocument) state.get(VIEW_FIELD);
789
        if (state.hasValue(HAS_TOC)) {
790
        	this.b_hasToc = state.getBoolean(HAS_TOC);
791
        }        
792
        if (viewDocument!=null) {
793
        	this.setView(viewDocument);
794
        	// it is crucial to don't persist the MapContext and get a cloned one from the View instead,
795
        	// as the cloned instance is different from the one created using persistence. In particular,
796
        	// the cloned one will share the EventBuffer with the original one, while persistence would
797
        	// create 2 separate EventBuffers, which will then have a very stange behaviour
798
        }
799
        if (getMapContext()!=null) {
800
        	double mapScale = state.getDouble(SCALE_FIELD);
801
        	getMapContext().setScaleView((long)mapScale); // FIXME: really needed?? probably already persisted on Mapcontext
802
        	getMapContext().getViewPort().setEnvelope(
803
                (Envelope) state.get(ENVELOPE_FIELD));
804
        	if (this.getLayoutContext()!=null) {
805
        		this.getLayoutContext().setTocModel(getMapContext());
806
        	}
790 807

  
791
        if (state.hasValue(MAPCONTEXT_FIELD)) {
792
            MapContext mctxt = (MapContext) state.get(MAPCONTEXT_FIELD);
793
            this.setViewMapContext(mctxt);
794
            double mapScale = state.getDouble(SCALE_FIELD);
795
            mapContext.getViewPort().setDPI(getDrawPaperDPI());
796
            mapContext.setScaleView((long)mapScale); // FIXME: really needed?? probably already persisted on Mapcontext
797
            mapContext.getViewPort().setEnvelope(
798
                (Envelope) state.get(ENVELOPE_FIELD));
799
            if (state.hasValue(HAS_TOC)) {
800
            	this.b_hasToc = state.getBoolean(HAS_TOC);
801
            	if (this.getLayoutContext()!=null) {
802
            		this.getLayoutContext().setTocModel(mapContext);
803
            	}
804
            }
805 808
        }
806

  
807 809
        showGrid = state.getBoolean(SHOWGRID_FIELD);
808 810
        grid = (IFFrame) state.get(GRID_FIELD);
809 811
    }
......
824 826
            state.set(ENVELOPE_FIELD, getMapContext().getViewPort()
825 827
                .getEnvelope());
826 828
            state.set(SCALE_FIELD, (double)getMapContext().getScaleView());
827
            state.set(MAPCONTEXT_FIELD, getMapContext());
828 829
        }
829 830

  
830 831
        state.set(SHOWGRID_FIELD, showGrid);
......
866 867
	
867 868
	protected void invalidateToc() {
868 869
		if (getLayoutContext()!=null) {
869
			getLayoutContext().updateFFrames();
870
			getLayoutContext().notifyTocUpdated(TocModelChangedNotification.Type.MODEL_CHANGED);
870 871
		}
871
			
872 872
	}
873 873

  
874 874
	public void refresh() {
......
1060 1060

  
1061 1061
		public void visibilityChanged(LayerCollectionEvent e)
1062 1062
				throws CancelationException {
1063
			// this event is not being received, maybe is only triggered if the
1064
			// visibility of the whole group changes??
1063 1065
			conditionalRedraw();
1064 1066
			invalidateToc();
1065 1067
		}
......
1071 1073
	}
1072 1074

  
1073 1075
	private class OwnMapContextListener
1074
	implements ViewPortListener, LegendListener, LayerCollectionListener {
1076
		implements ViewPortListener, LegendListener, LayerCollectionListener {
1075 1077

  
1076 1078
		public void extentChanged(ExtentEvent e) {
1077 1079
			if (!b_viewOriginatedUpdate && (getTypeScale() == AUTOMATICO)) {
......
1119 1121

  
1120 1122
		public void legendChanged(final LegendChangedEvent e) {
1121 1123
			conditionalRedraw();
1124
			invalidateToc();
1122 1125
		}
1123 1126

  
1124 1127
		public void layerAdded(final LayerCollectionEvent e) {
1125 1128
			conditionalRedraw();
1129
			invalidateToc();
1126 1130
		}
1127 1131

  
1128 1132
		public void layerMoved(final LayerPositionEvent e) {
1129 1133
			conditionalRedraw();
1134
			invalidateToc();
1130 1135
		}
1131 1136

  
1132 1137
		public void layerRemoved(final LayerCollectionEvent e) {
1133 1138
			conditionalRedraw();
1139
			invalidateToc();
1134 1140
		}
1135 1141

  
1136 1142
		public void layerAdding(LayerCollectionEvent e)
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/gui/DefaultLayoutPanel.java
24 24
import java.awt.BorderLayout;
25 25
import java.awt.Component;
26 26
import java.awt.Graphics2D;
27
import java.awt.event.MouseEvent;
28
import java.awt.event.MouseListener;
27 29
import java.awt.geom.AffineTransform;
28 30
import java.awt.print.PageFormat;
29 31
import java.awt.print.Printable;
......
195 197
				
196 198
				public void tocUpdated(Object observable,
197 199
						TocModelChangedNotification notification) {
198
					if (TocModelChangedNotification.MODEL_CHANGED==notification.getType()) {
200
					if (TocModelChangedNotification.Type.MODEL_CHANGED==notification.getType()) {
199 201
						if (DefaultLayoutPanel.this.toc!=null){
200 202
							DefaultLayoutPanel.this.toc.refresh();
201 203
						}
202 204
					}
203
					else if (TocModelChangedNotification.MODEL_SET==notification.getType()) {
205
					else if (TocModelChangedNotification.Type.MODEL_SET==notification.getType()) {
204 206
						MapContext mapContext = notification.getModel();
205 207
						if (mapContext!=null) {
206 208
							createToc();

Also available in: Unified diff