Revision 1763 branches/gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/iver/cit/gvsig/gui/cad/CadMapControl.java

View differences:

CadMapControl.java
57 57
import java.awt.event.MouseEvent;
58 58
import java.awt.event.MouseMotionListener;
59 59
import java.awt.image.MemoryImageSource;
60
import java.beans.PropertyChangeListener;
60 61
import java.util.HashMap;
61 62

  
62 63
import javax.swing.AbstractAction;
64
import javax.swing.Action;
65
import javax.swing.FocusManager;
66
import javax.swing.JComponent;
63 67
import javax.swing.JMenuItem;
64 68
import javax.swing.JPanel;
65 69
import javax.swing.JPopupMenu;
66 70
import javax.swing.JSplitPane;
67 71
import javax.swing.KeyStroke;
68 72

  
73
import com.iver.andami.PluginServices;
69 74
import com.iver.cit.gvsig.fmap.FMap;
70 75
import com.iver.cit.gvsig.fmap.MapControl;
71 76
import com.iver.cit.gvsig.fmap.layers.CancelationException;
......
96 101
import com.iver.cit.gvsig.gui.cad.tools.SymmetryCadTool;
97 102
import com.iver.cit.gvsig.gui.cad.tools.StretchingCadTool;
98 103
import com.iver.utiles.console.JConsole;
104
import com.iver.utiles.console.ResponseListener;
99 105
public class CadMapControl extends JPanel {
100 106
	private HashMap namesCadTools = new HashMap();
101
	private CADToolAdapter cadToolAdapter = new CADToolAdapter();
107
	private CADToolAdapter cadToolAdapter = new ViewCADToolAdapter();
102 108
	private LayerEditionListener layerEditionListener = new LayerEditionListener();
103 109
	private LayerColListener layerListener = new LayerColListener();
104 110
	private MapControl mapControl = null;
105
	private JConsole jConsole = null;
106
	private JSplitPane jSplitPane = null;
111
	private JPanel jSplitPane = null;
107 112
	
108 113
	//Menu contextual
109 114
	private JPopupMenu popup = new JPopupMenu();
......
124 129
        // Herramienta de edici?n de CAD
125 130
        getMapControl().addMapTool("cadEdition", cadToolAdapter);
126 131
        
127
        cadToolAdapter.setConsole(getConsole());
128 132
        cadToolAdapter.setCadMapControl(this);
129 133
        
130 134
        //Herramienta de CAD de a?adir punto
......
181 185
        
182 186
        this.setLayout(new BorderLayout());
183 187
		this.setSize(300,200);
184
		this.add(getJSplitPane(), java.awt.BorderLayout.CENTER);
185

  
188
		this.add(getMapControl(), java.awt.BorderLayout.CENTER);
189
		
186 190
        this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "elimina");
187 191
        this.getActionMap().put("elimina", new MyAction("eliminar"));
188 192
        this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
189 193
        this.getActionMap().put("escape", new MyAction("escape"));
194
        
195
        registerKeyStrokes();
196
        
197
        PluginServices.getMainFrame().addConsoleListener("cad", new ResponseListener() {
198
			public void acceptResponse(String response) {
199
				cadToolAdapter.textEntered(response);
200
				FocusManager fm=FocusManager.getCurrentManager();
201
				fm.focusPreviousComponent(mapControl);
202
			}
203
		});
190 204
	}
191 205
	
206
	class KeyAction extends AbstractAction{
207

  
208
		private String key;
209
		
210
		public KeyAction(String key){
211
			this.key = key;
212
		}
213
		
214
		/* (non-Javadoc)
215
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
216
		 */
217
		public void actionPerformed(ActionEvent e) {
218
			PluginServices.getMainFrame().focusConsole(key);
219
		}
220
		
221
	}
222
	
192 223
	class MyAction extends AbstractAction{
193 224
		private String actionCommand;
194 225
		
......
205 236
		
206 237
	}
207 238
	
239
	private void registerKeyStrokes(){
240
		for (char key = '0'; key <= '9'; key++){
241
			Character keyChar = new Character(key);
242
			this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key), keyChar);
243
			this.getActionMap().put(keyChar, new KeyAction(keyChar+""));
244
		}
245
		for (char key = 'a'; key <= 'z'; key++){
246
			Character keyChar = new Character(key);
247
			this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key), keyChar);
248
			this.getActionMap().put(keyChar, new KeyAction(keyChar+""));
249
		}
250
		for (char key = 'A'; key <= 'Z'; key++){
251
			Character keyChar = new Character(key);
252
			this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key), keyChar);
253
			this.getActionMap().put(keyChar, new KeyAction(keyChar+""));
254
		}
255
		//this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
256
        //this.getActionMap().put("enter", new MyAction("enter"));
257
		Character keyChar = new Character(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0).getKeyChar());
258
		this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),keyChar);
259
		this.getActionMap().put(keyChar, new KeyAction(""));
260
	}
261
	
208 262
	/**
209 263
	 * This method initializes mapControl	
210 264
	 * 	
......
241 295
		}
242 296
		return mapControl;
243 297
	}
298
	
244 299
	/**
245
	 * This method initializes jConsole	
246
	 * 	
247
	 * @return com.iver.utiles.console.JConsole	
248
	 */    
249
	public JConsole getConsole() {
250
		if (jConsole == null) {
251
			jConsole = new JConsole();
252
			jConsole.setPreferredSize(new java.awt.Dimension(3,35));
253
			jConsole.addFocusListener(new FocusListener() {
254
				public void focusGained(FocusEvent e) {
255
				}
256

  
257
				public void focusLost(FocusEvent e) {
258
					jConsole.requestFocus();
259
					jConsole.requestFocusInWindow();
260
				}
261
			});
262
			jConsole.requestFocus();
263
			jConsole.requestFocusInWindow();
264
		}
265
		return jConsole;
266
	}
267
	/**
268 300
	 * This method initializes jSplitPane	
269 301
	 * 	
270 302
	 * @return javax.swing.JSplitPane	
271 303
	 */    
272
	private JSplitPane getJSplitPane() {
304
	private JPanel getJSplitPane() {
273 305
		if (jSplitPane == null) {
274
			jSplitPane = new JSplitPane();
275
			jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
276
			jSplitPane.setTopComponent(getMapControl());
277
			jSplitPane.setBottomComponent(getConsole());
278
			jSplitPane.setDividerLocation(130);
279
			jSplitPane.setResizeWeight(0.85);
306
			jSplitPane = new JPanel();
307
			jSplitPane.add(getMapControl());
280 308
		}
281 309
		return jSplitPane;
282 310
	}

Also available in: Unified diff