Revision 11271 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/LabelingManager.java

View differences:

LabelingManager.java
156 156
	private JRadioButton rdBtnHeightField;
157 157
	private JRadioButton rdBtnFixedHeight;
158 158
	private JTextField txtHeightField;
159
	private boolean noEvent;
159 160

  
160 161

  
161 162

  
......
279 280
					USER_DEFINED_ITEM,
280 281
					ATTRS_IN_TABLE_ITEM,
281 282
			});
283
			cmbMode.setName("CMBMODE");
282 284
			cmbMode.addActionListener(this);
283 285
		}
284 286

  
......
311 313
		if (txtHeightField == null) {
312 314
			txtHeightField = new JTextField(10);
313 315
			txtHeightField.setText("10");
316
			txtHeightField.setName("TXTHEIGHTFIELD");
314 317
		}
315 318

  
316 319
		return txtHeightField;
......
321 324
			rdBtnFixedHeight = new JRadioButton(PluginServices.getText(this, "fixed_height") + ":");
322 325
			rdBtnFixedHeight.addActionListener(this);
323 326
			rdBtnFixedHeight.setSelected(false);
327
			rdBtnFixedHeight.setName("RDFIXEDHEIGHT");
324 328
		}
325 329

  
326 330
		return rdBtnFixedHeight;
......
331 335
			rdBtnHeightField = new JRadioButton(PluginServices.getText(this, "text_height_field") + ":");
332 336
			rdBtnHeightField.addActionListener(this);
333 337
			rdBtnHeightField.setSelected(true);
338
			rdBtnHeightField.setName("RDHEIGHTFIELD");
334 339
		}
335 340

  
336 341
		return rdBtnHeightField;
......
345 350
			units[units.length-1] = PluginServices.getText(this, "pixels");
346 351
			cmbUnits = new JComboBox(units);
347 352
			cmbUnits.setSelectedIndex(Project.getDefaultDistanceUnits());
353
			cmbUnits.setName("CMBUNITS");
348 354
		}
349 355

  
350 356
		return cmbUnits;
......
355 361
			cmbRotationField = new JComboBox();
356 362
			cmbRotationField.setPreferredSize(new Dimension(200, 20));
357 363
			cmbRotationField.addActionListener(this);
364
			cmbRotationField.setName("CMBROTATIONFIELD");
358 365
		}
359 366
		return cmbRotationField;
360 367
	}
......
363 370
		if (cmbHeightField == null) {
364 371
			cmbHeightField = new JComboBox();
365 372
			cmbHeightField.setPreferredSize(new Dimension(200, 20));
373
			cmbHeightField.setName("CMBHEIGHTFIELD");
366 374
			cmbHeightField.addActionListener(this);
367 375
		}
368 376
		return cmbHeightField;
......
372 380
		if (cmbTextField == null) {
373 381
			cmbTextField = new JComboBox();
374 382
			cmbTextField.setPreferredSize(new Dimension(200, 20));
383
			cmbTextField.setName("CMBTEXTFIELD");
375 384
			cmbTextField.addActionListener(this);
376 385
		}
377 386
		return cmbTextField;
......
447 456
	private Component getBtnSymbol() {
448 457
		if (btnSymbol == null) {
449 458
			btnSymbol = new JButton(PluginServices.getText(this, "symbol"));
459
			btnSymbol.setName("BTNSYMBOL");
450 460
			btnSymbol.addActionListener(this);
451 461
		}
452 462

  
......
456 466
	private JCheckBox getChkApplyLabels() {
457 467
		if (chkApplyLabels == null) {
458 468
			chkApplyLabels = new JCheckBox(PluginServices.getText(this, "enable_labelling"));
469
			chkApplyLabels.setName("CHKAPPLYLABELS");
459 470
			chkApplyLabels.addActionListener(this);
460 471
		}
461 472
		return chkApplyLabels;
......
469 480
		if (btnVisualization == null) {
470 481
			btnVisualization = new JButton(
471 482
					PluginServices.getText(this, "visualization")+"...");
483
			btnVisualization.setName("BTNVISUALIZATION");
472 484
			btnVisualization.addActionListener(this);
473 485
		}
474 486
		return btnVisualization;
......
478 490
		if (btnLabelStyles == null) {
479 491
			btnLabelStyles = new JButton(
480 492
					PluginServices.getText(this, "label_styles")+"...");
493
			btnLabelStyles.setName("BTNLABELSTYLES");
481 494
			btnLabelStyles.addActionListener(this);
482 495
		}
483 496
		return btnLabelStyles;
......
487 500
		if (btnPlacement == null) {
488 501
			btnPlacement = new JButton(
489 502
					PluginServices.getText(this, "placement")+"...");
503
			btnPlacement.setName("BTNPLACEMENT");
490 504
			btnPlacement.addActionListener(this);
491 505
		}
492 506
		return btnPlacement;
......
496 510
		if (btnFont == null) {
497 511
			btnFont = new JButton(
498 512
					PluginServices.getText(this,"fuente")+"...");
513
			btnFont.setName("BTNFONT");
499 514
			btnFont.addActionListener(this);
500 515
		}
501 516
		return btnFont;
......
535 550
			}
536 551
			cmbMethod = new JComboBox(aux.toArray());
537 552
			cmbMethod.setSize(new Dimension(300, 22));
553
			cmbMethod.setName("CMBMETHOD");
538 554
			cmbMethod.addActionListener(this);
539 555
		}
540 556
		return cmbMethod;
......
544 560
		if (btnEditExpression == null) {
545 561
			btnEditExpression = new JButton(
546 562
					PluginServices.getText(this, "edit_expression")+"...");
563
			btnEditExpression.setName("BTNEDITEXPRESSION");
547 564
			btnEditExpression.addActionListener(this);
548 565
		}
549 566
		return btnEditExpression;
......
553 570
		if (cmbExpressions == null) {
554 571
			cmbExpressions = new JComboBox();
555 572
			cmbExpressions.setPreferredSize(new Dimension(150, 20));
573
			cmbExpressions.setName("CMBEXPRESSIONS");
556 574
			cmbExpressions.addActionListener(this);
557 575
		}
558 576
		return cmbExpressions;
......
562 580
	private JButton getBtnSQLQuery() {
563 581
		if (btnSQLQuery == null) {
564 582
			btnSQLQuery = new JButton(PluginServices.getText(this, "SQL_query"));
583
			btnSQLQuery.setName("BTNSQLQUERY");
565 584
			btnSQLQuery.addActionListener(this);
566 585
		}
567 586
		return btnSQLQuery;
......
570 589
	private JButton getBtnRenameClass() {
571 590
		if (btnRenameClass == null) {
572 591
			btnRenameClass = new JButton(PluginServices.getText(this, "remane_class"));
592
			btnRenameClass.setName("BTNRENAMECLASS");
573 593
			btnRenameClass.addActionListener(this);
574 594
		}
575 595
		return btnRenameClass;
......
578 598
	private JButton getBtnDelClass() {
579 599
		if (btnDelClass == null) {
580 600
			btnDelClass = new JButton(PluginServices.getText(this, "delete_class"));
601
			btnDelClass.setName("BTNDELCLASS");
581 602
			btnDelClass.addActionListener(this);
582 603
		}
583 604
		return btnDelClass;
......
586 607
	private JButton getBtnAddClass() {
587 608
		if (btnAddClass == null) {
588 609
			btnAddClass = new JButton(PluginServices.getText(this, "add_class"));
610
			btnAddClass.setName("BTNADDCLASS");
589 611
			btnAddClass.addActionListener(this);
590 612
		}
591 613
		return btnAddClass;
......
595 617
		if (chkLabel == null) {
596 618
			chkLabel = new JCheckBox();
597 619
			chkLabel.setText(PluginServices.getText(this, "label_features_in_this_class"));
620
			chkLabel.setName("CHKLABEL");
598 621
			chkLabel.addActionListener(this);
599 622
		}
600 623
		return chkLabel;
......
604 627
		if (cmbClasses == null) {
605 628
			cmbClasses = new JComboBox();
606 629
			cmbClasses.setPreferredSize(new Dimension(150, 20));
630
			cmbClasses.setName("CMBCLASSES");
607 631
			cmbClasses.addActionListener(this);
608 632
		}
609 633
		return cmbClasses;
......
664 688
				} catch (ReadDriverException e) {
665 689
					strategy = null;
666 690
				}
691
			} else {
692
				setMethod(strategy.getLabelingMethod());
693
				placementConstraints = strategy.getPlacementConstraints();
667 694
			}
668
			if (strategy != null)
669
				setMethod(strategy.getLabelingMethod());
670 695
			setComponentEnabled(this, true);
671 696
			refreshControls();
672 697

  
......
813 838

  
814 839

  
815 840
	private void refreshCmbExpressions() {
841

  
816 842
		ArrayList exp = getExpressions();
843
		noEvent = true;
817 844
		getCmbExpressions().removeAllItems();
818 845
		for (int i = 0; i < exp.size(); i++)
819 846
			getCmbExpressions().addItem(exp.get(i));
820 847
		LabelClass lc = (LabelClass) getCmbClasses().getSelectedItem();
821
		if (lc != null)
822
			getCmbExpressions().setSelectedItem(lc.getLabelExpression());
848
		noEvent = false;
849
		if (lc != null) {
850
			int index = exp.indexOf(lc.getLabelExpression());
851
			getCmbExpressions().setSelectedIndex(index < 0? 0: index);
852
		}
853

  
854

  
823 855
	}
824 856

  
825 857
	private ArrayList getExpressions() {
826 858
		if (expressions == null) {
827 859
			expressions = new ArrayList();
828 860
			try {
829
				String[] n =  ((FLyrVect) layer).getRecordset().getFieldNames();
830
				for (int i = 0; i < n.length; i++) {
831
					expressions.add("[ "+n[i]+" ]");
861
				for (int i = 0; i < fieldNames.length; i++) {
862
					expressions.add("[ "+fieldNames[i]+" ]");
832 863
				}
833 864
			} catch (Exception e) {
834 865
				NotificationManager.addError(
......
840 871
	}
841 872

  
842 873
	public void actionPerformed(ActionEvent e) {
874
		if (noEvent) return;
843 875
		JComponent c = (JComponent)e.getSource();
876
		System.out.println(c.getName());
844 877
		if (c.equals(chkApplyLabels)) {
845 878
			boolean b = chkApplyLabels.isSelected();
846 879
			// enables/disables all components
......
849 882
				if (!c1.equals(c))
850 883
					setComponentEnabled(c1, b);
851 884
			}
852
			if (b) actionPerformed(new ActionEvent(getCmbMethod(), 0, null));
885
//			if (b) actionPerformed(new ActionEvent(getCmbMethod(), 0, null));
853 886

  
854 887
		} else if (c.equals(btnAddClass)) {
855 888
			LabelClass newClass = new LabelClass();
......
923 956
		} else if (c.equals(cmbClasses)) {
924 957
			// refresh expressions
925 958
			LabelClass lc = (LabelClass) cmbClasses.getSelectedItem();
926
			if (lc != null && !getExpressions().contains(lc.getLabelExpression())) {
959
			if (lc != null && lc.getLabelExpression() != null && !getExpressions().contains(lc.getLabelExpression())) {
927 960
				getExpressions().add(0, lc.getLabelExpression());
928 961
			}
929 962
			refreshCmbExpressions();
......
984 1017
			getCmbClasses().addItem(lClasses[i]);
985 1018
		}
986 1019

  
987
		refreshCmbExpressions();
1020
//		refreshCmbExpressions();
988 1021
	}
989 1022

  
990 1023
	private LabelClass getActiveClass() {

Also available in: Unified diff