Revision 107 org.gvsig.legend.vectorfilterexpression.app.mainplugin/trunk/org.gvsig.legend.vectorfilterexpression.app.mainplugin/src/main/java/org/gvsig/symbology/gui/layerproperties/VectorFilterExpressionPanel.java

View differences:

VectorFilterExpressionPanel.java
51 51

  
52 52
import javax.swing.BoxLayout;
53 53
import javax.swing.ImageIcon;
54
import javax.swing.JButton;
54 55
import javax.swing.JCheckBox;
55 56
import javax.swing.JOptionPane;
56 57
import javax.swing.JPanel;
......
77 78
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
78 79
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
79 80
import org.gvsig.gui.beans.swing.JBlank;
80
import org.gvsig.gui.beans.swing.JButton;
81 81
import org.gvsig.i18n.Messages;
82 82
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol;
83 83
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
84 84
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend;
85 85
import org.gvsig.symbology.fmap.rendering.filterexpression.EvaluatorCreator;
86 86
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
87
import org.gvsig.tools.swing.api.ToolsSwingLocator;
88
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
87 89

  
88 90
/**
89 91
 * Implements the JPanel that shows the properties of a
......
95 97
 */
96 98
public class VectorFilterExpressionPanel extends JPanel
97 99
implements ILegendPanel, ActionListener {
98
    
100

  
99 101
    private static final Logger logger = LoggerFactory.getLogger(
100 102
        VectorFilterExpressionPanel.class);
101
    
103

  
102 104
	private static final long serialVersionUID = -7187473609965942511L;
103 105
	private VectorFilterExpressionLegend theLegend;
104 106
	private VectorFilterExpressionLegend auxLegend;
......
116 118
	protected JCheckBox chkdefaultvalues = null;
117 119
	protected JSymbolPreviewButton defaultSymbolPrev;
118 120
	private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
121
	private UsabilitySwingManager usabilitySwingManager = ToolsSwingLocator.getUsabilitySwingManager();
119 122

  
120 123
	/**
121 124
	 * This is the default constructor
......
135 138
		pnlCenter.setLayout(new BorderLayout());
136 139

  
137 140
		JPanel pnlButtons = new JPanel();
138
		btnAddExpression = new JButton(
141
		btnAddExpression = usabilitySwingManager.createJButton(
139 142
		    Messages.getText("new_filter_expression"));
140 143
		btnAddExpression.setActionCommand("NEW_EXPRESSION");
141 144
		btnAddExpression.addActionListener(this);
142 145
		pnlButtons.add(btnAddExpression);
143 146

  
144
		btnModExpression = new JButton(
147
		btnModExpression = usabilitySwingManager.createJButton(
145 148
		    Messages.getText("modify_filter_expression"));
146 149
		btnModExpression.setActionCommand("MODIFY_EXPRESSION");
147 150
		btnModExpression.addActionListener(this);
148 151
		pnlButtons.add(btnModExpression);
149 152

  
150
		btnRemoveExpression = new JButton(
153
		btnRemoveExpression = usabilitySwingManager.createJButton(
151 154
		    Messages.getText("delete_filter_expression"));
152 155
		btnRemoveExpression.setActionCommand("REMOVE");
153 156
		btnRemoveExpression.addActionListener(this);
......
212 215
	private void fillSymbolListFromTable() {
213 216
		Object clave;
214 217
		ISymbol theSymbol;
215
		boolean bRestoValores = false;
216
		int hasta;
217 218

  
218 219
		FLyrVect m = (FLyrVect) layer;
219 220
		try {
......
224 225

  
225 226
				FeatureStore fsto = (FeatureStore) m.getDataStore();
226 227
				FeatureType fty = fsto.getDefaultFeatureType();
227
				FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
228
				
228

  
229 229
				for (int i = 0; i < fNames.length; i++) {
230 230
					fieldTypes[i] = fty.getAttributeDescriptor(fNames[i]).getType();
231 231
				}
......
233 233
				auxLegend.setClassifyingFieldTypes(fieldTypes);
234 234
			}
235 235
		} catch (Exception e) {
236
		    
236

  
237 237
		}
238 238

  
239 239
		auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
240
		if (bRestoValores) {
241
			hasta = symbolTable.getRowCount() - 1;
242
		} else {
243
			hasta = symbolTable.getRowCount();
244
		}
245 240

  
246 241
		for (int row = 0; row < symbolTable.getRowCount(); row++) {
247 242
			clave =  symbolTable.getFieldValue(row, 1);
......
260 255

  
261 256
	}
262 257

  
263
	public Class getLegendClass() {
258
	public Class<VectorFilterExpressionLegend> getLegendClass() {
264 259
		return VectorFilterExpressionLegend.class;
265 260
	}
266 261

  
......
268 263
		return this;
269 264
	}
270 265

  
271
	public Class getParentClass() {
266
	public Class<Categories> getParentClass() {
272 267
		return Categories.class;
273 268
	}
274 269

  
......
317 312

  
318 313

  
319 314
		if (legend instanceof VectorFilterExpressionLegend) {
320
		    
315

  
321 316
            auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend();
322 317
            if (auxLegend.isUseDefaultSymbol()) {
323 318
                // Default must not be in table
324
                fillTableSkipDefault(auxLegend);                
319
                fillTableSkipDefault(auxLegend);
325 320
            } else {
326 321
                symbolTable.fillTableFromSymbolList(
327 322
                    auxLegend.getSymbols(),
328 323
                    auxLegend.getValues(),
329 324
                    auxLegend.getDescriptions());
330 325
            }
331
            
332
			
326

  
327

  
333 328
		} else {
334 329
			auxLegend = new VectorFilterExpressionLegend();
335 330
			auxLegend.setShapeType(shapeType);
......
345 340
			pnlMovBut.add(new JBlank(1, 70));
346 341
			ImageIcon ico = IconThemeHelper.getImageIcon(
347 342
			    "symbol-layer-move-up");
348
			moveUp = new JButton(ico);
343
			moveUp = usabilitySwingManager.createJButton(ico);
349 344
			pnlMovBut.add(moveUp);
350 345
			moveUp.setSize(new Dimension(15,15));
351 346
			pnlMovBut.add(new JBlank(1,10));
352 347
			ico = IconThemeHelper.getImageIcon(
353 348
                "symbol-layer-move-down");
354
			moveDown = new JButton(ico);
349
			moveDown = usabilitySwingManager.createJButton(ico);
355 350
			pnlMovBut.add(moveDown);
356 351
			pnlMovBut.add(new JBlank(1, 70));
357 352
			moveDown.setActionCommand("MOVE-DOWN");
......
363 358
	}
364 359

  
365 360
	public void actionPerformed(ActionEvent e) {
366
	    
361

  
367 362
		int[] indices = null;
368 363
		Feature dummyFeat = null;
369 364

  
......
388 383
		}
389 384

  
390 385
		if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
391
			ArrayList orders = new ArrayList();
386
			ArrayList<String> orders = new ArrayList<String>();
392 387

  
393 388
			for (int i = 0; i < symbolTable.getRowCount(); i++) {
394 389
				orders.add(symbolTable.getFieldValue(i,1).toString());
395 390
			}
396 391
		}
397 392
		if (e.getActionCommand() == "NEW_EXPRESSION") {
398
		    
393

  
399 394
		    FLyrVect vect = (FLyrVect) layer;
400 395
		    FeatureStore fsto = (FeatureStore) vect.getDataStore();
401 396
		    FeatureType fty = null;
402 397
		    int shptype = 0;
403
		    
398

  
404 399
		    try {
405 400
		        fty = fsto.getDefaultFeatureType();
406 401
		        shptype = vect.getGeometryType().getType();
......
411 406
		        return;
412 407
		    }
413 408

  
414
		    EvaluatorWithDescriptions evalu = EvaluatorCreator.getEvaluator(""); 
409
		    EvaluatorWithDescriptions evalu = EvaluatorCreator.getEvaluator("");
415 410
		    MDIManager mm = ApplicationLocator.getManager().getUIManager();
416
		    
411

  
417 412
		    ExpressionSymbolPanel esp = new ExpressionSymbolPanel(
418 413
		        dummyFeat, evalu, shptype, null);
419 414
		    mm.addCentredWindow(esp);
420
		    
415

  
421 416
		    /*
422 417
		     * esp is modal
423 418
		     */
424 419
		    if (!esp.isOkPressed()) {
425 420
		        return;
426 421
		    }
427
		    
422

  
428 423
		    String expr = esp.getExpression();
429 424
		    if (expr == null || expr.length() == 0) {
430 425
		        ApplicationLocator.getManager().messageDialog(
......
433 428
		            JOptionPane.ERROR_MESSAGE);
434 429
		        return;
435 430
		    }
436
		    
431

  
437 432
		    ISymbol sym = esp.getSymbol();
438 433
		    evalu = EvaluatorCreator.getEvaluator(expr);
439 434
		    // Add all fields in the feature type
......
442 437
            auxLegend.addSymbol(expr, sym);
443 438
            symbolTable.removeAllItems();
444 439
            fillTableSkipDefault(auxLegend);
445
            
440

  
446 441
			repaint();
447 442
		}
448 443
		else if (e.getActionCommand() == "MODIFY_EXPRESSION") {
449
		    
444

  
450 445
			if(symbolTable.getSelectedRowElements() == null) {
451 446
				JOptionPane.showMessageDialog(this,
452 447
				    Messages.getText("select_one_row")+".\n");
453 448
			} else {
454
			    
449

  
455 450
		         FLyrVect vect = (FLyrVect) layer;
456 451
		         FeatureStore fsto = (FeatureStore) vect.getDataStore();
457 452
		         FeatureType fty = null;
......
471 466

  
472 467
                EvaluatorWithDescriptions evalu =
473 468
                    EvaluatorCreator.getEvaluator(expression);
474
                
469

  
475 470
                MDIManager mm = ApplicationLocator.getManager().getUIManager();
476 471
                ExpressionSymbolPanel esp = new ExpressionSymbolPanel(
477 472
                    dummyFeat, evalu, shptype, mySymbol);
......
482 477
	            if (!esp.isOkPressed()) {
483 478
	                return;
484 479
	            }
485
	            
480

  
486 481
	            String expr = esp.getExpression();
487 482
	            if (expr == null || expr.length() == 0) {
488 483
	                ApplicationLocator.getManager().messageDialog(
......
491 486
	                    JOptionPane.ERROR_MESSAGE);
492 487
	                return;
493 488
	            }
494
	            
489

  
495 490
	            ISymbol sym = esp.getSymbol();
496 491
	            evalu = EvaluatorCreator.getEvaluator(expr);
497 492
	            // Add all fields in the feature type
......
508 503
		}
509 504

  
510 505
		else if (e.getActionCommand() == "REMOVE") {
511
		    
506

  
512 507
			if(symbolTable.getSelectedRowElements() == null) {
513 508
				JOptionPane.showMessageDialog(this,
514 509
				    Messages.getText("select_one_row"));
......
522 517
			}
523 518
		}
524 519
	}
525
	
526
	
520

  
521

  
527 522
	private void addClassFieldNames(FeatureType ft) {
528
	    
523

  
529 524
	    FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
530 525
	    String[] nn = new String[atts.length];
531 526
	    for (int i=0; i<atts.length; i++) {
......
577 572
	        "legend-overview-vector-filter-expression");
578 573
	    return ii;
579 574
	}
580
	
575

  
581 576
	/**
582 577
	 * This method initializes chkdefaultvalues
583 578
	 *
......
602 597

  
603 598
		return chkdefaultvalues;
604 599
	}
605
	
600

  
606 601
	private void fillTableSkipDefault(VectorFilterExpressionLegend leg) {
607
	    
602

  
608 603
	    Object[] src_expr = leg.getValues();
609
	    List rem_ind = new ArrayList();
604
	    List<Integer> rem_ind = new ArrayList<Integer>();
610 605
	    for (int i=0; i<src_expr.length; i++) {
611 606
	        if (VectorFilterExpressionLegend.I18N_DEFAULT.
612 607
	            compareToIgnoreCase((String) src_expr[i]) == 0) {
......
616 611
        ISymbol[] src_syms = leg.getSymbols();
617 612
        String[] src_descs = leg.getDescriptions();
618 613
        // Object[] src_expr
619
	    
620
        List syms = new ArrayList();
621
        List vals = new ArrayList();
622
        List descs = new ArrayList();
614

  
615
        List<ISymbol> syms = new ArrayList<ISymbol>();
616
        List<Object> vals = new ArrayList<Object>();
617
        List<String> descs = new ArrayList<String>();
623 618
        for (int i=0; i<src_expr.length; i++) {
624 619
            if (!isIn(i, rem_ind)) {
625 620
                syms.add(src_syms[i]);
......
639 634
     * @param rem_ind
640 635
     * @return
641 636
     */
642
    private boolean isIn(int n, List int_list) {
643
        
637
    private boolean isIn(int n, List<Integer> int_list) {
638

  
644 639
        if (int_list == null || int_list.size() == 0) {
645 640
            return false;
646 641
        }
647
        
642

  
648 643
        for (int i=0; i<int_list.size(); i++) {
649 644
            if (int_list.get(i) instanceof Integer) {
650 645
                Integer item = (Integer) int_list.get(i);

Also available in: Unified diff