Revision 167

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/FrameChangedNotificationImpl.java
1
package org.gvsig.app.project.documents.layout;
2

  
3
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
4

  
5
public class FrameChangedNotificationImpl extends DefaultLayoutNotification implements FrameChangedNotification {
6
	private IFFrame frame;
7

  
8
	public FrameChangedNotificationImpl(String type, IFFrame frame) {
9
		super(type);
10
		this.frame = frame;
11
	}
12
	
13
	public IFFrame getFrame() {
14
		return this.frame;
15
	}
16

  
17
}
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FrameChangedNotification.java
1
package org.gvsig.app.project.documents.layout;
2

  
3
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
4

  
5
public interface FrameChangedNotification extends LayoutNotification {
6
    public static final String FRAME_ADDED = "frame_added";
7
    public static final String FRAME_ADDING = "frame_adding";
8
    public static final String FRAME_REMOVING = "frame_removed";
9
    public static final String FRAME_REMOVED = "frame_removed";
10
	/*
11
	 * Gets the changed Frame
12
	 */
13
	public IFFrame getFrame();
14

  
15

  
16
}
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/commands/FrameManager.java
70 70
     */
71 71
    public int doAddFFrame(IFFrame frame) {
72 72
        fframes.add(frame);
73

  
74
        return fframes.size() - 1;
73
        int index = fframes.size() - 1;
74
        notifyAdded(index);
75
        return index; 
75 76
    }
76 77

  
77 78
    /**
......
85 86
    public void doAddFFrame(IFFrame frame, int index) {
86 87
        invalidates.set(index, false);
87 88
        fframes.set(index, frame);
89
        notifyAdded(index);
88 90
    }
89 91

  
90 92
    /**
......
131 133
     */
132 134
    public void undoRemoveFFrame(int index) {
133 135
        invalidates.set(index, false);
136
        notifyAdded(index);
134 137
    }
135 138

  
136 139
    /**
......
141 144
     */
142 145
    public void doRemoveFFrame(int index) {
143 146
        invalidates.set(index, true);
147
        notifyRemoved(index);
144 148
    }
149
    
150
    protected void notifyRemoved(int index) {
151
    	IFFrame frame = fframes.get(index);
152
    	frame.frameRemoved();
153
    }
154
    
155
    protected void notifyAdded(int index) {
156
    	IFFrame frame = fframes.get(index);
157
    	frame.frameAdded();
158
    }
145 159

  
146 160
    /**
147 161
     * Returns all the fframes that are not removed.
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
148 148
            IFFrame fframe = validFrames[i];
149 149

  
150 150
            if (fframe.isSelected()) {
151
                observers.notifyObservers(this, 
152
                        new FrameChangedNotificationImpl(FrameChangedNotificationImpl.FRAME_REMOVING, fframe));
153 151
                fframe.setSelected(false);
154 152
                fcr.delete(fframe);
155
                observers.notifyObservers(this, 
156
                        new FrameChangedNotificationImpl(FrameChangedNotificationImpl.FRAME_REMOVED, fframe));
157 153
            }
158 154
        }
159 155
        fcr.endComplex();
......
175 171
    }
176 172

  
177 173
    public void delFFrame(IFFrame frame) {
178
        observers.notifyObservers(this, 
179
                new FrameChangedNotificationImpl(FrameChangedNotificationImpl.FRAME_REMOVING, frame));
180 174
        for (int i = 0; i < fcr.getFrameManager().getAllFFrames().length; i++) {
181 175
            if (fcr.getFrameManager().getFFrame(i).equals(frame)) {
182 176
            	frame.setSelected(false);
......
184 178
            }
185 179
        }
186 180
        updateFFrames();
187
        observers.notifyObservers(this, 
188
                new FrameChangedNotificationImpl(FrameChangedNotificationImpl.FRAME_REMOVED, frame));
189 181
    }
190 182

  
191 183
    public FrameCommandsRecord getFrameCommandsRecord() {
......
193 185
    }
194 186

  
195 187
    public void addFFrame(IFFrame frame, boolean clearSelection, boolean select) {
196
    	this.addObserver(frame);
197
        observers.notifyObservers(this, 
198
                new FrameChangedNotificationImpl(FrameChangedNotification.FRAME_ADDING, frame)); 
199 188
        IFFrame[] fframes = getFFrames();
200 189
        if (clearSelection) {
201 190
            for (int i = fframes.length - 1; i >= 0; i--) {
......
218 207
        frame.setSelected(select);
219 208
        frame.setLevel(getNumBefore());
220 209
        updateFFrames();
221
        observers.notifyObservers(this, 
222
                new FrameChangedNotificationImpl(FrameChangedNotificationImpl.FRAME_ADDED, frame));
223 210
    }
224 211

  
225 212
    public void addFFrameSameProperties(IFFrame frame) {
226
    	this.addObserver(frame);
227
        observers.notifyObservers(this, 
228
                new FrameChangedNotificationImpl(FrameChangedNotificationImpl.FRAME_ADDING, frame)); 
229 213
        fcr.insert(frame);
230 214
        frame.setSelected(true);
231 215
        frame.setLevel(getNumBefore());
232 216
        updateFFrames();
233
        observers.notifyObservers(this, 
234
                new FrameChangedNotificationImpl(FrameChangedNotificationImpl.FRAME_ADDED, frame));
235 217
    }
236 218

  
237 219
    public int getNumBehind() {
......
354 336
    
355 337
    public void notifAllObservers(){
356 338
        observers.notifyObservers(this, 
357
            new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
339
            new DefaultLayoutNotification(LayoutNotification.LAYOUT_REFRESH));
358 340
    }
359 341

  
360 342
    public static void registerPersistent() {
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrame.java
34 34
import java.awt.image.BufferedImage;
35 35

  
36 36
import org.gvsig.andami.PluginServices;
37
import org.gvsig.andami.ui.mdiManager.IWindow;
38 37
import org.gvsig.app.project.ProjectManager;
39 38
import org.gvsig.app.project.documents.Document;
40 39
import org.gvsig.app.project.documents.layout.Attributes;
41 40
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
42 41
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
43
import org.gvsig.app.project.documents.layout.FrameChangedNotificationImpl;
44 42
import org.gvsig.app.project.documents.layout.LayoutContext;
45
import org.gvsig.app.project.documents.layout.LayoutControl;
46 43
import org.gvsig.app.project.documents.layout.LayoutDocument;
47 44
import org.gvsig.app.project.documents.layout.LayoutManager;
48
import org.gvsig.app.project.documents.layout.LayoutNotification;
49
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
50 45
import org.gvsig.tools.ToolsLocator;
51 46
import org.gvsig.tools.dynobject.DynStruct;
52
import org.gvsig.tools.observer.Observable;
53 47
import org.gvsig.tools.observer.ObservableHelper;
54 48
import org.gvsig.tools.observer.Observer;
55 49
import org.gvsig.tools.persistence.PersistenceManager;
......
830 824
		
831 825
	}
832 826
	
833
	/**
834
	 * This method is called just before the FFrame is going to
835
	 * be added to the Layout
836
	 */
837
	protected void beforeAdded() {}
827
	public void frameRemoved() {}
838 828
	
839
	/**
840
	 * This method is called just before the FFrame is going to
841
	 * be removed from the Layout
842
	 */
843
	protected void beforeRemoved() {}
829
	public void frameAdded() {}
844 830
	
845
	/**
846
	 * This method is called just after the FFrame has been
847
	 * added to the Layout
848
	 */
849
	protected void afterAdded() {}
850
	
851
	
852
	/**
853
	 * This method is called just before the FFrame is going to
854
	 * be removed from the Layout
855
	 */
856
	protected void afterRemoved() {}
857
	
858
	public void update(Observable observable, Object notification) {
859
		if ((notification != null) && (notification instanceof FrameChangedNotificationImpl)){
860
			FrameChangedNotificationImpl layoutNotification = (FrameChangedNotificationImpl)notification;
861
			if (this.equals(layoutNotification.getFrame()) && FrameChangedNotificationImpl.FRAME_ADDED.equals(layoutNotification.getType())){
862
				afterAdded();
863
			}else if (this.equals(layoutNotification.getFrame()) && FrameChangedNotificationImpl.FRAME_ADDING.equals(layoutNotification.getType())){
864
				beforeAdded();
865
			}else if (this.equals(layoutNotification.getFrame()) && FrameChangedNotificationImpl.FRAME_REMOVING.equals(layoutNotification.getType())){
866
				beforeRemoved();
867
			}else if (this.equals(layoutNotification.getFrame()) && FrameChangedNotificationImpl.FRAME_REMOVED.equals(layoutNotification.getType())){
868
				afterRemoved();
869
			}
870
		}
871
	}
872

  
873 831
	public LayoutContext getLayoutContext() {
874 832
		return layoutContext;
875 833
	}
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/IFFrame.java
44 44
 * 
45 45
 * @author Vicente Caballero Navarro
46 46
 */
47
public interface IFFrame extends IPrintable, Persistent, Cloneable, Observable, Disposable, Observer {
47
public interface IFFrame extends IPrintable, Persistent, Cloneable, Observable, Disposable {
48 48

  
49 49
    public static final int N = 1;
50 50
    public static final int NE = 2;
......
328 328
	public LayoutContext getLayoutContext();
329 329

  
330 330
	public void setLayoutContext(LayoutContext layoutContext);
331
	
332
	/**
333
	 * This method is called when the FFrame has been
334
	 * removed from the Layout
335
	 */
336
	public void frameRemoved();
337
	
338
	/**
339
	 * This method is called when the FFrame has been
340
	 * added to the Layout
341
	 */
342
	public void frameAdded();
331 343
}
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
369 369
    			!b_validCache) { 
370 370

  
371 371
    		viewPort.setDPI(getDrawPaperDPI());
372
        	viewPort.setImageSize(new Dimension(width, height));
373
        	viewPort.refreshExtent(); // really needed (calculateAffineTransform is already called by setImageSize, but extentChanged listeners are not notified 
372
        	viewPort.setImageSize(new Dimension(width, height)); 
374 373
            
375 374
            m_image =
376 375
                    new BufferedImage(
......
754 753
            DynStruct definition =
755 754
                manager.addDefinition(FFrameView.class,
756 755
                    PERSISTENCE_DEFINITION_NAME,
757
                    "FFrameView persistence definition", null, null);
758
//                definition.extend(manager
759
//                        .getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME));
760
                
756
                    "FFrameView persistence definition", null, null); 
761 757
            definition.extend(manager
762 758
                .getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME));
763 759

  
......
936 932
		this.mapContext = null;
937 933
	}
938 934

  
939
	/**
940
	 * This method is called just before the FFrame is going to
941
	 * be removed from the Layout
942
	 */
943
	protected void beforeRemoved() {
935
	public void frameRemoved() {
944 936
		if (mapContext!=null) {
945 937
			clearOwnListeners(mapContext);
946 938
		}
......
950 942
		if (b_hasToc && getLayoutContext()!=null) {
951 943
			getLayoutContext().setTocModel(null);
952 944
		}
945
		m_image = null; // FIXME: we could instead move it to a LRU cache to keep the last N images
953 946
	}
954 947

  
955
	/**
956
	 * This method is called just after the FFrame has been
957
	 * added to the Layout
958
	 */
959
	protected void afterAdded() {
948
	public void frameAdded() {
960 949
		setListeners();
961 950
		updateScaleCtrl();
962 951
	}

Also available in: Unified diff