Revision 30337 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/view/toolListeners/snapping/gui/SnapConfig.java

View differences:

SnapConfig.java
57 57

  
58 58
import org.gvsig.andami.PluginServices;
59 59
import org.gvsig.fmap.mapcontrol.MapControl;
60
import org.gvsig.fmap.mapcontrol.MapControlLocator;
61
import org.gvsig.fmap.mapcontrol.MapControlManager;
60 62
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper;
61 63
import java.util.TreeMap;
62 64

  
......
75 77
	private JPanel jPanel = null;
76 78
	private JScrollPane jScrollPane = null;
77 79

  
78
//	private ArrayList snappers;
80
	//	private ArrayList snappers;
79 81
	private MapControl mc;
82
	private static MapControlManager mapControlManager = MapControlLocator.getMapControlManager();
80 83

  
81 84
	/**
82 85
	 * @author fjp
......
87 90
	 */
88 91
	class MyTableModel extends AbstractTableModel {
89 92

  
90
		public ArrayList mySnappers;
91

  
92
		public MyTableModel(ArrayList snappers)
93
		public MyTableModel()
93 94
		{
94
			this.mySnappers = snappers;
95
			
95 96
		}
96 97

  
97 98
		public int getColumnCount() {
......
99 100
		}
100 101

  
101 102
		public int getRowCount() {
102
			return mySnappers.size();
103
			return mapControlManager.getSnapperCount();
103 104
		}
104 105

  
105 106
		public boolean isCellEditable(int rowIndex, int columnIndex) {
......
109 110
		}
110 111

  
111 112
		public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
112
			ISnapper snap = (ISnapper) mySnappers.get(rowIndex);
113
			ISnapper snap = mapControlManager.getSnapperAt(rowIndex);
113 114
			switch (columnIndex)
114 115
			{
115 116
			case 0://CheckBox
......
122 123
		}
123 124

  
124 125
		public Object getValueAt(int rowIndex, int columnIndex) {
125
			ISnapper snap = (ISnapper) mySnappers.get(rowIndex);
126
			ISnapper snap = mapControlManager.getSnapperAt(rowIndex);
126 127
			switch (columnIndex)
127 128
			{
128 129
			case 0:
......
174 175

  
175 176
	}
176 177

  
177
	 class MyCellRenderer extends JCheckBox implements ListCellRenderer {
178
	class MyCellRenderer extends JCheckBox implements ListCellRenderer {
178 179

  
179
	     // This is the only method defined by ListCellRenderer.
180
	     // We just reconfigure the JLabel each time we're called.
180
		// This is the only method defined by ListCellRenderer.
181
		// We just reconfigure the JLabel each time we're called.
181 182

  
182
	     public Component getListCellRendererComponent(
183
	       JList list,
184
	       Object value,            // value to display
185
	       int index,               // cell index
186
	       boolean isSelected,      // is the cell selected
187
	       boolean cellHasFocus)    // the list and the cell have the focus
188
	     {
189
	    	 ISnapper snapper = (ISnapper) value;
190
	         String s = snapper.getToolTipText();
191
	         setText(s);
183
		public Component getListCellRendererComponent(
184
				JList list,
185
				Object value,            // value to display
186
				int index,               // cell index
187
				boolean isSelected,      // is the cell selected
188
				boolean cellHasFocus)    // the list and the cell have the focus
189
		{
190
			ISnapper snapper = (ISnapper) value;
191
			String s = snapper.getToolTipText();
192
			setText(s);
192 193

  
193
	   	   if (isSelected) {
194
	             setBackground(list.getSelectionBackground());
195
		       setForeground(list.getSelectionForeground());
196
		   }
197
	         else {
198
		       setBackground(list.getBackground());
199
		       setForeground(list.getForeground());
200
		   }
201
		   setEnabled(list.isEnabled());
202
		   setFont(list.getFont());
203
	         setOpaque(true);
204
	         return this;
205
	     }
194
			if (isSelected) {
195
				setBackground(list.getSelectionBackground());
196
				setForeground(list.getSelectionForeground());
197
			}
198
			else {
199
				setBackground(list.getBackground());
200
				setForeground(list.getForeground());
201
			}
202
			setEnabled(list.isEnabled());
203
			setFont(list.getFont());
204
			setOpaque(true);
205
			return this;
206
		}
206 207

  
207 208
		public void doClick() {
208 209
			super.doClick();
......
210 211
		}
211 212

  
212 213

  
213
	 }
214
	}
214 215

  
215 216

  
216 217
	/**
......
228 229
	 *
229 230
	 */
230 231
	private void initialize() {
231
        this.setLayout(null);
232
        this.setSize(new java.awt.Dimension(463,239));
233
        this.setPreferredSize(new java.awt.Dimension(463,239));
234
        this.add(getJChkBoxRefentActive(), null);
235
        this.add(getJPanel(), null);
232
		this.setLayout(null);
233
		this.setSize(new java.awt.Dimension(463,239));
234
		this.setPreferredSize(new java.awt.Dimension(463,239));
235
		this.add(getJChkBoxRefentActive(), null);
236
		this.add(getJPanel(), null);
236 237

  
237 238
	}
238 239

  
......
292 293
		return jScrollPane;
293 294
	}
294 295

  
295
//	public ArrayList getSnappers() {
296
//		return snappers;
297
//	}
296
	//	public ArrayList getSnappers() {
297
	//		return snappers;
298
	//	}
298 299

  
299
	public void setSnappers(ArrayList snappers) {
300
		mc.getMapContext().setSnappers(snappers);
301
		MyTableModel listModel = new MyTableModel(snappers);
300
	public void setSnappers() {		
301
		MyTableModel listModel = new MyTableModel();
302 302
		getJListSnappers().setModel(listModel);
303 303
		TableColumn tc=getJListSnappers().getColumnModel().getColumn(0);
304 304
		setUpSymbolColumn(getJListSnappers().getColumnModel().getColumn(1));
305 305
		setUpPropertyColumn(getJListSnappers().getColumnModel().getColumn(4));
306 306
		getJListSnappers().setCellSelectionEnabled(false);
307 307
		tc.setMaxWidth(40);
308
        tc.setMinWidth(20);
308
		tc.setMinWidth(20);
309 309
	}
310 310
	public TableModel getTableModel() {
311 311
		return getJListSnappers().getModel();
......
315 315
	}
316 316

  
317 317

  
318
	public void selectSnappers(TreeMap selected) {
319
		ArrayList snappers=mc.getMapContext().getSnappers();
320
		for (int i=0;i<snappers.size();i++) {
321
			Boolean b=(Boolean)selected.get(snappers.get(i));
322
			if (b!=null)
323
				getTableModel().setValueAt(b,i,0);
324
			else
325
				getTableModel().setValueAt(new Boolean(false),i,0);
318
	public void selectSnappers() {
319
		for (int i=0;i<mapControlManager.getSnapperCount();i++) {
320
			getTableModel().setValueAt(mapControlManager.getSnapperAt(i).isEnabled(),i,0);			
326 321
		}
327 322

  
328 323
	}
324

  
329 325
	public void setApplySnappers(boolean applySnappers) {
330 326
		getJChkBoxRefentActive().setSelected(applySnappers);
331 327
	}
328

  
332 329
	public void setUpSymbolColumn(TableColumn column) {
333
		ArrayList snappers=mc.getMapContext().getSnappers();
334
	    DrawSnapCellRenderer symbolCellRenderer = new DrawSnapCellRenderer(snappers);
335
        column.setCellRenderer(symbolCellRenderer);
336
    }
337
	 public void setUpPropertyColumn(TableColumn column) {
338
		 ArrayList snappers=mc.getMapContext().getSnappers();
339
	        PropertySnapCellEditor propertyeditor = new PropertySnapCellEditor(snappers);
340
	        column.setCellEditor(propertyeditor);
330
		DrawSnapCellRenderer symbolCellRenderer = new DrawSnapCellRenderer();
331
		column.setCellRenderer(symbolCellRenderer);
332
	}
333
	public void setUpPropertyColumn(TableColumn column) {
341 334

  
342
	        PropertySnapCellRenderer renderer = new PropertySnapCellRenderer(snappers);
343
	        column.setCellRenderer(renderer);
344
	    }
335
		PropertySnapCellEditor propertyeditor = new PropertySnapCellEditor();
336
		column.setCellEditor(propertyeditor);
337

  
338
		PropertySnapCellRenderer renderer = new PropertySnapCellRenderer();
339
		column.setCellRenderer(renderer);
340
	}
345 341
}  //  @jve:decl-index=0:visual-constraint="10,10"
346 342

  
347 343

  

Also available in: Unified diff