Revision 23062

View differences:

trunk/extensions/extSymbology/src/org/gvsig/symbology/gui/layerproperties/GeneralLabeling.java
88 88
	private static Hashtable<
89 89
			Class<? extends ILabelingMethod>,
90 90
			Class<? extends AbstractLabelingMethodPanel>
91
		> methods 
91
		> methods
92 92
		= new Hashtable<
93 93
			Class<? extends ILabelingMethod>,
94 94
			Class<? extends AbstractLabelingMethodPanel>
......
103 103
	private FLyrVect targetLayer;
104 104
	private JCheckBox chkAllowLabelOverlapping;
105 105
	private FLyrVect auxLayer;
106
	
106
	private GeneralLabelingStrategy gStr;
107 107
	public GeneralLabeling() {
108 108
		initialize();
109 109
	}
110
	
110

  
111 111
	private void initialize() {
112 112
		setLayout(new BorderLayout());
113 113
		JPanel center = new JPanel(new BorderLayout(10, 10));
......
124 124
			methodPanel = new JPanel(new BorderLayout(10, 0));
125 125
			center.add(methodPanel, BorderLayout.CENTER);
126 126
		add(center, BorderLayout.CENTER);
127
		
127

  
128 128
		JPanel south = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
129 129
			south.setBorder(BorderFactory.createTitledBorder(
130 130
				null, PluginServices.getText(this, "options")));
......
132 132
			south.add(getBtnPlacement());
133 133
			south.add(getChkAllowLabelOverlapping());
134 134
			south.setPreferredSize(new Dimension(612, 60));
135
			
135

  
136 136
		add(south, BorderLayout.SOUTH);
137 137
	}
138 138

  
139
	
139

  
140 140
	private JCheckBox getChkAllowLabelOverlapping() {
141 141
		if (chkAllowLabelOverlapping == null) {
142 142
			chkAllowLabelOverlapping = new JCheckBox(PluginServices.getText(this, "allow_label_overlapping"));
......
149 149
		// fires an event from the methods combo box
150 150
		actionPerformed(new ActionEvent(getCmbMethod(), 0, null));
151 151
	}
152
	
152

  
153 153
	private JButton getBtnVisualization() {
154 154
		if (btnVisualization == null) {
155 155
			btnVisualization = new JButton(
......
207 207
		if (layer instanceof FLyrVect) {
208 208
			try {
209 209
				targetLayer = (FLyrVect) layer;//.cloneLayer();
210
				
210

  
211 211
				VectorialDriver vd = (VectorialDriver) ((FLyrVect) layer).getSource().getDriver();
212
				
212

  
213 213
				auxLayer = (FLyrVect) LayerFactory.createLayer(layer.getName(),vd, layer.getProjection());
214
				
214

  
215 215
				auxLayer.setLegend((IVectorLegend)targetLayer.getLegend());
216
				
217
				
216

  
217

  
218 218
				if (auxLayer.getProjection() == null) {
219 219
					Logger.getLogger(getClass()).debug("Possible bug detected in " +
220 220
							"FLyrVect.cloneLayer() (missing projection in cloned layer)");
221 221
					// this line should be unnecessary (and included in cloneLayer) method);
222 222
					auxLayer.setProjection(targetLayer.getProjection());
223 223
				}
224
				// 
225
				
224
				//
225

  
226 226
				if (str instanceof GeneralLabelingStrategy) {
227
					GeneralLabelingStrategy gStr = (GeneralLabelingStrategy) LabelingFactory.
227
					gStr = (GeneralLabelingStrategy) LabelingFactory.
228 228
						createStrategyFromXML(str.getXMLEntity(), auxLayer/*layer.cloneLayer()*/);
229 229
					auxLayer.setLabelingStrategy(gStr);
230 230
					gStr.setLayer(auxLayer);
......
271 271
	}
272 272

  
273 273
	private ILabelingMethod getMethod() {
274
		AbstractLabelingMethodPanel p = ((AbstractLabelingMethodPanel) getCmbMethod().getSelectedItem());
275
		if (p != null)
276
			return p.getMethod();
274
		if(gStr != null){
275
			return gStr.getLabelingMethod();
276
		}
277

  
277 278
		return new DefaultLabelingMethod();
278 279
	}
279 280

  
......
302 303
						((FLyrVect) auxLayer).getShapeType());
303 304
				PluginServices.getMDIManager().addWindow(pp);
304 305
				placementConstraints = pp.getPlacementConstraints();
305
				
306

  
306 307
				((AbstractLabelingMethodPanel) cmbMethod.getSelectedItem()).
307 308
					propertyChange(new PropertyChangeEvent(
308 309
							this,
309 310
							AbstractLabelingMethodPanel.PLACEMENT_CONSTRAINTS,
310 311
							oldValue,
311 312
							placementConstraints));
313

  
314
				gStr.setPlacementConstraints(placementConstraints);
315

  
312 316
			} catch (ClassCastException ccEx) {
313 317
				NotificationManager.addError(
314 318
						"Placement constraints not prepared for:"
......
336 340
					lsr.getMaxScale() ==-1 && lsr.getMinScale() == -1 ?
337 341
							IZoomConstraints.DEFINED_BY_THE_LAYER :
338 342
							IZoomConstraints.DEFINED_BY_THE_USER);
339
			
343

  
340 344
			((AbstractLabelingMethodPanel) cmbMethod.getSelectedItem()).
341 345
			propertyChange(new PropertyChangeEvent(
342 346
					this,
......
344 348
					oldValue,
345 349
					getZoomConstraints()));
346 350

  
351
			gStr.setZoomConstraints(zoomConstraints);
352

  
347 353
		} else if (c.equals(chkAllowLabelOverlapping)) {
348 354
			boolean newValue = chkAllowLabelOverlapping.isSelected();
349 355
			((AbstractLabelingMethodPanel) cmbMethod.getSelectedItem()).
......
352 358
					AbstractLabelingMethodPanel.ALLOW_OVERLAP,
353 359
					!newValue,
354 360
					newValue));
361

  
362
			gStr.setAllowOverlapping(newValue);
363

  
355 364
		} else if (c.equals(cmbMethod)) {
356 365
			Container cont = methodPanel.getParent();
357 366
			cont.remove(methodPanel);
358 367
			emptyContainer(methodPanel);
359
			
368

  
360 369
			AbstractLabelingMethodPanel p = (AbstractLabelingMethodPanel) cmbMethod.getSelectedItem();
361 370
			try {
371

  
362 372
				p.setModel(getMethod(), auxLayer);
363 373
				methodPanel.add(
364 374
						p,
365 375
						BorderLayout.CENTER);
366
				
376

  
377
				methodPanel.repaint();
367 378
				setVisible(false);
368 379
				setVisible(true);
369 380
			} catch (ReadDriverException e1) {
370 381
				NotificationManager.addInfo(new Date(System.currentTimeMillis()).toString(), e1);
371 382
			}
372 383
			cont.add(methodPanel, BorderLayout.CENTER);
373
		} 
384
		}
374 385
		System.out.println("GeneralLabeling.actionPerformed() exit"+((Component)e.getSource()).getName());
375 386
	}
376 387

  
......
395 406
/*
396 407
class _GeneralLabeling extends JPanel implements ILabelingStrategyPanel, ActionListener {
397 408
	private static final long serialVersionUID = 8864709758980903351L;
398
	private static Hashtable<String, Class<? extends ILabelingMethod>> methods 
409
	private static Hashtable<String, Class<? extends ILabelingMethod>> methods
399 410
		= new Hashtable<String, Class<? extends ILabelingMethod>>();
400 411
	private static int newClassSuffix = 0;
401 412
	private JButton btnVisualization;
......
420 431
	private JScrollPane scrlPan;
421 432
	private LabelClassRenderingProperties labelClassRenderingProperties;
422 433
	private JCheckBox chkAllowLabelOverlapping;
423
	
434

  
424 435
	public _GeneralLabeling() {
425 436
		initialize();
426 437
	}
427
	
438

  
428 439
	private void initialize() {
429 440
		setLayout(new BorderLayout());
430 441
		GridBagLayoutPanel left = new GridBagLayoutPanel();
......
459 470
		aux.setBorder(BorderFactory.createTitledBorder(
460 471
				null, PluginServices.getText(this, "options")));
461 472
		aux.add(getBtnVisualization());
462
		
473

  
463 474
		aux.add(getBtnPlacement());
464 475
		aux.add(getChkAllowLabelOverlapping());
465 476
		aux.setPreferredSize(new Dimension(612, 60));
466
		
467
		left.addComponent(aux);	
468
		
477

  
478
		left.addComponent(aux);
479

  
469 480
		add(left, BorderLayout.CENTER);
470
		
481

  
471 482
		JPanel right = new JPanel(new BorderLayout(15, 15));
472 483
		aux = new JPanel(new BorderLayout(15, 15));
473 484
		aux.add(getChkDefinePriorities(), BorderLayout.NORTH);
......
479 490
		add(right, BorderLayout.EAST);
480 491
	}
481 492

  
482
	
493

  
483 494
	private JCheckBox getChkAllowLabelOverlapping() {
484 495
		if (chkAllowLabelOverlapping == null) {
485 496
			chkAllowLabelOverlapping = new JCheckBox(PluginServices.getText(this, "allow_label_overlapping"));
486
			
497

  
487 498
		}
488 499

  
489 500
		return chkAllowLabelOverlapping;
......
520 531
					}
521 532
				}
522 533
			});
523
			
534

  
524 535
		}
525 536
		return lstClassPriorities;
526 537
	}
......
528 539
	private void refreshControls() {
529 540
		// classes combo box
530 541
		refreshClasses();
531
		
542

  
532 543
		// fires an event from the methods combo box
533 544
		actionPerformed(new ActionEvent(getCmbMethod(), 0, null));
534 545
	}
535
	
546

  
536 547
	private JButton getBtnVisualization() {
537 548
		if (btnVisualization == null) {
538 549
			btnVisualization = new JButton(
......
681 692

  
682 693
				refreshControls();
683 694
				labelClassRenderingProperties.setModel(getActiveClass());
684
				
695

  
685 696
			} catch (ReadDriverException e) {
686 697
				NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e);
687 698
			}
......
700 711
	private ILabelingMethod getMethod() {
701 712
		return ((MethodItem) getCmbMethod().getSelectedItem()).method;
702 713
	}
703
	
714

  
704 715
	private void refreshClasses() {
705 716
		// label classes
706 717
		getCmbClasses().removeAllItems();
707 718
		LabelClass[] lClasses = getMethod().getLabelClasses();
708 719
		for (int i = 0; i < lClasses.length; i++) {
709 720
			getCmbClasses().addItem(lClasses[i]);
710
			
721

  
711 722
		}
712 723

  
713 724
		labelClassRenderingProperties.setModel(
714 725
				(LabelClass) getCmbClasses().getSelectedItem());
715 726
		// expressions combo box
716 727
//		refreshCmbExpressions();
717
		
728

  
718 729
		// panel priorities
719 730
		refreshPnlPriorities();
720
		
731

  
721 732
	}
722 733

  
723 734
	private void refreshPnlPriorities() {
724 735
		TreeSet<LabelClass> ts = new TreeSet<LabelClass>(new LabelClassComparatorByPriority());
725
		
736

  
726 737
		LabelClass[] lClasses = getMethod().getLabelClasses();
727 738
		for (int i = 0; i < lClasses.length; i++) {
728 739
			ts.add(lClasses[i]);
729 740
		}
730
		
741

  
731 742
		// refresh label priority panel
732 743
		getChkDefinePriorities().setSelected(getMethod().definesPriorities());
733 744
		JDnDListModel m = new JDnDListModel();
......
737 748
		getLstClassPriorities().setModel(m);
738 749

  
739 750
	}
740
	
751

  
741 752
	private LabelClass getActiveClass() {
742 753
		return (LabelClass) getCmbClasses().getSelectedItem();
743 754
	}
......
781 792
			if (!query.equals("")) {
782 793
				clazz.setSQLQuery(query);
783 794
			}
784
			
795

  
785 796
		} else  if (c.equals(chkLabel)) {
786 797
			LabelClass lc = (LabelClass) getCmbClasses().getSelectedItem();
787 798
			if (lc == null)
......
823 834
			// multiple class or not enables or disables the class panel
824 835
			setComponentEnabled(classesPanel, getMethod().allowsMultipleClass());
825 836
			refreshClasses();
826
			
837

  
827 838
		} else if (c.equals(chkDefinePriorities)) {
828 839
			getMethod().setDefinesPriorities(chkDefinePriorities.isSelected());
829 840
			refreshPnlPriorities();
830
		} 
841
		}
831 842
	}
832 843

  
833 844
	private void setComponentEnabled(Component c, boolean b) {
......
847 858
	public Class getLabelingStrategyClass() {
848 859
		return GeneralLabelingStrategy.class;
849 860
	}
850
	
861

  
851 862
	private class JComboBoxLabelingMethod extends JComboBox {
852 863
		private static final long serialVersionUID = 5935267402200698145L;
853 864

  
854 865
		public JComboBoxLabelingMethod(MethodItem[] items) {
855 866
			super(items);
856 867
		}
857
		
868

  
858 869
		@Override
859 870
		public void setSelectedItem(Object anObject) {
860 871
			if (anObject instanceof MethodItem) {
......
882 893
		public String toString() {
883 894
			return name;
884 895
		}
885
		
896

  
886 897
		@Override
887 898
		public boolean equals(Object obj) {
888 899
			if (obj != null && obj instanceof MethodItem) {
......
892 903
			return false;
893 904
		}
894 905
	}
895
	
906

  
896 907
}*/
trunk/extensions/extSymbology/src/org/gvsig/symbology/gui/layerproperties/DefaultLabeling.java
91 91
	private String[] fieldNames;
92 92
	private int[] fieldTypes;
93 93
	private boolean allowOverlap;
94
	private IZoomConstraints zoomConstraints; 
94
	private IZoomConstraints zoomConstraints;
95 95
	@Override
96 96
	public Class<? extends ILabelingMethod> getLabelingMethodClass() {
97 97
		return DefaultLabelingMethod.class;
......
116 116
				labeling = new GeneralLabelingStrategy();
117 117
				// (!!)
118 118
				labeling.setLayer(layer);
119
				layer.setLabelingStrategy(labeling); 
120
			}		
119
				layer.setLabelingStrategy(labeling);
120
			}
121 121
			else {
122 122
				labeling = (GeneralLabelingStrategy) layer.getLabelingStrategy();
123 123
			}
......
132 132
		} else {
133 133
			lc = new LabelClass();
134 134
		}
135
		setLabel(lc); 
135
		setLabel(lc);
136 136
	}
137 137

  
138 138
	@Override
139
	protected void initializePanel() { 
139
	protected void initializePanel() {
140 140
		setLayout(new BorderLayout());
141 141
		JSplitPane scrl = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
142 142
		scrl.add(layerPrev = new LayerPreview(), JSplitPane.LEFT);
......
160 160
	public void actionPerformed(ActionEvent e) {
161 161
		if (e.getSource().equals(btnProperties)) {
162 162
			LabelClassProperties lcProp = new LabelClassProperties(fieldNames, fieldTypes);
163
			lcProp.setLabelClass(getMethod().getLabelClasses()[0]);
163
			lcProp.setLabelClass(method.getLabelClasses()[0]);
164 164
			PluginServices.getMDIManager().addWindow(lcProp);
165 165
			setLabel(lcProp.getLabelClass());
166 166
		}
......
183 183
		GeneralLabelingStrategy s = (GeneralLabelingStrategy) layer.
184 184
		getLabelingStrategy();
185 185
		s.setLabelingMethod(newMethodForThePreview(defaultLabel));
186
		s.setPlacementConstraints(placementConstraints);
187
		s.setAllowOverlapping(allowOverlap);
188
		s.setZoomConstraints(zoomConstraints);
186
//		s.setPlacementConstraints(placementConstraints);
187
//		s.setAllowOverlapping(allowOverlap);
188
//		s.setZoomConstraints(zoomConstraints);
189 189

  
190 190
		layer.setIsLabeled(true);
191 191

  
192
		/* If the selected labeling method is OnSelectionLabeled we have to select some rows 
192
		/* If the selected labeling method is OnSelectionLabeled we have to select some rows
193 193
		 * in the previous sample image*/
194 194
		if(s.getLabelingMethod() instanceof OnSelectionLabeled) {
195 195

  
196 196
			try {
197
				
197

  
198 198
				IFeatureIterator it = layer.getSource().getFeatureIterator();
199 199
				SelectionSupport selectionSupport = new SelectionSupport();
200 200
				FBitSet bitSet = new FBitSet();
......
203 203
				for (int i = 0; i <= rowCount/4; i++) {
204 204
					bitSet.set(i);
205 205
				}
206
				
206

  
207 207
				selectionSupport.setSelection(bitSet);
208 208
				layer.getRecordset().setSelectionSupport(selectionSupport);
209
			
209

  
210 210
			} catch (ReadDriverException e) {
211 211
				NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e);
212 212
			}
213
		}	
213
		}
214 214

  
215 215

  
216 216
		try {
......
227 227
	}
228 228

  
229 229
	public void propertyChange(PropertyChangeEvent evt) {
230
		String prop = evt.getPropertyName(); 
230
		String prop = evt.getPropertyName();
231 231
		if (AbstractLabelingMethodPanel.PLACEMENT_CONSTRAINTS.equals(prop)) {
232 232
			placementConstraints = (IPlacementConstraints) evt.getNewValue();
233 233
		} else if (AbstractLabelingMethodPanel.ALLOW_OVERLAP.equals(prop)) {

Also available in: Unified diff