Revision 47779 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/swing/pickercontroller/impl/EnvelopePickerControllerImpl.java

View differences:

EnvelopePickerControllerImpl.java
5 5
import java.awt.Image;
6 6
import java.awt.event.ActionEvent;
7 7
import java.net.URL;
8
import java.util.function.Supplier;
8 9
import javax.swing.ImageIcon;
9 10
import javax.swing.JButton;
10 11
import javax.swing.JTextField;
......
92 93
    }
93 94
    
94 95

  
95
    private final MapControl mapControl;
96
    private final Supplier<MapControl> mapControl;
96 97
    private final JTextField txtUpperLeftX;
97 98
    private final JTextField txtUpperLeftY;
98 99
    private final JTextField txtLowerRightX;
......
106 107
    private String previosTool;
107 108
    
108 109
    public EnvelopePickerControllerImpl(
109
            MapControl mapControl,
110
            Supplier<MapControl> mapControl,
110 111
            JTextField txtUpperLeftX, 
111 112
            JTextField txtUpperLeftY, 
112 113
            JTextField txtLowerRightX, 
......
127 128
    }
128 129
    
129 130
    public EnvelopePickerControllerImpl(
130
            MapControl mapControl,
131
            Supplier<MapControl> mapControl,
131 132
            JTextComponent txtEnvelope, 
132 133
            JButton btnMapControlEnvelope, 
133 134
            final JToggleButton btnCapture
......
147 148
    private void initComponents() {
148 149
        ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
149 150
        I18nManager i18n = ToolsLocator.getI18nManager();
151
        MapControl theMapControl = this.getMapControl();
150 152
        this.captureCursor = new ImageIcon(this.getIcon("picker-envelope-cursor-capture").getImage());
151 153
        
152 154
        if( this.btnCapture!=null ) {
......
171 173
            });
172 174
            this.btnMapControlEnvelope.setEnabled(this.mapControl!=null);
173 175
        }
174
        if( this.mapControl!=null ) {
176
        if( theMapControl!=null ) {
175 177
            this.captureTool = new RectangleBehavior(new CaptureEnvelopeListener());
176
            this.mapControl.addBehavior("picker-envelope-capture", captureTool);
177
            this.previosTool = this.mapControl.getCurrentTool();
178
            theMapControl.addBehavior("picker-envelope-capture", captureTool);
179
            this.previosTool = this.mapControl.get().getCurrentTool();
178 180
        }
179 181
        
180 182
        if( this.txtEnvelope==null ) {
......
214 216
    }
215 217
            
216 218
    protected void doSetEnvelopeFromMapControlEnvelope() {
217
        if( !this.isEditable() || mapControl==null ) {
219
        MapControl theMapControl = this.getMapControl();
220
        if( !this.isEditable() || theMapControl==null ) {
218 221
            return;
219 222
        }
220 223
        try {
221
            Envelope env = this.mapControl.getViewPort().getEnvelope();
224
            Envelope env = theMapControl.getViewPort().getEnvelope();
222 225
            if( env == null ) {
223 226
                return;
224 227
            }
......
229 232
        }
230 233
    }
231 234
    
235
    
232 236
    protected void doCaptureEnvelope(boolean enabled) {
233
        if( !this.isEditable() || mapControl==null ) {
237
        MapControl theMapControl = this.getMapControl();
238
        if( !this.isEditable() || theMapControl==null ) {
234 239
            return;
235 240
        }
236
        Envelope env = this.mapControl.getViewPort().getEnvelope();
241
        
242
        Envelope env = theMapControl.getViewPort().getEnvelope();
237 243
        if( env == null ) {
238 244
            return;
239 245
        }
240 246
        if( enabled ) {
241
            this.previosTool = this.mapControl.getCurrentTool();
242
            this.mapControl.setTool("picker-envelope-capture");
247
            this.previosTool = theMapControl.getCurrentTool();
248
            theMapControl.setTool("picker-envelope-capture");
243 249
        } else {
244
            this.mapControl.setTool(this.previosTool);
250
            theMapControl.setTool(this.previosTool);
245 251
        }
246 252
    }
247 253

  
......
344 350
                return null;
345 351
            }
346 352
        }
347
        if( this.mapControl!=null ) {
348
            envelope.setProjection(this.mapControl.getProjection());
353
        MapControl theMapControl = this.getMapControl();
354
        if( theMapControl!=null ) {
355
            envelope.setProjection(theMapControl.getProjection());
349 356
        }
350 357
        return envelope;
351 358
    }
......
438 445
        fireChangeEvent();
439 446
    }
440 447

  
441
    
448

  
449
    private MapControl getMapControl() {
450
        if( this.mapControl == null ) {
451
            return null;
452
        }
453
        return this.mapControl.get();
454
    }
442 455
}

Also available in: Unified diff