Revision 202

View differences:

org.gvsig.toolbox/trunk/org.gvsig.toolbox/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/algorithm/DefaultParametersPanel.java
94 94
/**
95 95
 * A panel to introduce parameters for a geoalgorithm, created automatically based on the parameters needed by that geoalgorithm
96 96
 * If no additional panel is provided for an algorithm, SEXTANTE will use this panel as the default one.
97
 * 
97
 *
98 98
 * @author volaya
99
 * 
99
 *
100 100
 */
101 101
public class DefaultParametersPanel
102 102
         extends
......
399 399

  
400 400
      boolean bAddNotSetField = false;
401 401
      int i, j;
402
      int iShapeType;
403 402
      String sParameterName;
404 403
      final ArrayList childComboBoxIndex = new ArrayList();
405 404
      Parameter parameter;
......
414 413
         parameter = parameters.getParameter(i);
415 414
         if (parameter instanceof ParameterVectorLayer) {
416 415
            try {
417
               iShapeType = ((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getShapeType();
416
               int[] shapeTypes = ((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getShapeTypes();
418 417
               //check for table fields that depend on this vector layer
419 418
               sParameterName = parameter.getParameterName();
420 419
               childComboBoxIndex.clear();
......
426 425
                                 sParameterName)) {
427 426
                           m_iCurrentRow++;
428 427
                           addTitleLabel(pane, "      " + subParameter.getParameterDescription(), m_iCurrentRow, false);
429
                           comboBox = getVectorLayerFieldSelectionComboBox(iShapeType);
428
                           comboBox = getVectorLayerFieldSelectionComboBox(shapeTypes);
430 429
                           childComboBoxIndex.add(new Integer(m_ComboBox.size()));
431 430
                           m_ComboBox.add(comboBox);
432 431
                           pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow));
......
444 443
            }
445 444
            // add vector layer
446 445
            try {
447
               iShapeType = ((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getShapeType();
446
                AdditionalInfoVectorLayer parameterAdditionalInfo = (AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo();
447
//               iShapeType = parameterAdditionalInfo.getShapeType();
448
               int[] shapeTypes = parameterAdditionalInfo.getShapeTypes();
449

  
448 450
               if (((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getIsMandatory()) {
449 451
                  bAddNotSetField = false;
450 452
                  addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow - childComboBoxIndex.size(), false);
......
454 456
                  addTitleLabel(pane, parameter.getParameterDescription() + Sextante.getText("[optional]"),
455 457
                           m_iCurrentRow - childComboBoxIndex.size(), false);
456 458
               }
457
               comboBox = getVectorLayerSelectionComboBox(iShapeType, childComboBoxIndex, bAddNotSetField);
459
               comboBox = getVectorLayerSelectionComboBox(shapeTypes, childComboBoxIndex, bAddNotSetField);
458 460
               if (bAddNotSetField) {
459 461
                  comboBox.setSelectedIndex(0);
460 462
               }
......
1120 1122

  
1121 1123
   }
1122 1124

  
1125
    protected JComboBox<ObjectAndDescription> getVectorLayerSelectionComboBox(int[] shapeTypes, final List childComboBoxes,
1126
        final boolean bAddNotSetField) {
1123 1127

  
1128
        int i;
1129

  
1130
        final Integer[] childsArray = new Integer[childComboBoxes.size()];
1131
        for (i = 0; i < childsArray.length; i++) {
1132
            childsArray[i] = (Integer) childComboBoxes.get(i);
1133
        }
1134

  
1135
        List<IVectorLayer> layers = getVectorLayers(shapeTypes);
1136
        final ObjectAndDescription[] oad = new ObjectAndDescription[layers.size()];
1137
        for (i = 0; i < layers.size(); i++) {
1138
            oad[i] = new ObjectAndDescription(layers.get(i).getName(), layers.get(i));
1139
        }
1140
        final JComboBox cb = new JComboBox(oad);
1141

  
1142
        if (bAddNotSetField) {
1143
            final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel();
1144
            model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0);
1145
        }
1146

  
1147
        cb.addItemListener(new java.awt.event.ItemListener() {
1148

  
1149
            public void itemStateChanged(final java.awt.event.ItemEvent e) {
1150
                int i;
1151
                int iIndex;
1152
                String sNames[] = null;
1153
                DefaultComboBoxModel defaultModel;
1154
                for (i = 0; i < childsArray.length; i++) {
1155
                    iIndex = (childsArray[i]).intValue();
1156
                    final ObjectAndDescription ob = (ObjectAndDescription) cb.getSelectedItem();
1157
                    final IVectorLayer layer = (IVectorLayer) ob.getObject();
1158
                    if (layer != null) {
1159
                        sNames = getVectorLayerFieldNames(layer);
1160
                        if (sNames != null) {
1161
                            defaultModel = new DefaultComboBoxModel(sNames);
1162
                            ((JComboBox) m_ComboBox.get(iIndex)).setModel(defaultModel);
1163
                        }
1164
                    }
1165
                }
1166
            }
1167
        });
1168

  
1169
        return cb;
1170

  
1171
    }
1172

  
1173

  
1174
    /**
1175
     * @param shapeTypes
1176
     * @return
1177
     */
1178
    private List<IVectorLayer> getVectorLayers(int[] shapeTypes) {
1179
        List<IVectorLayer> layers = new ArrayList<IVectorLayer>();
1180
        for (int j = 0; j < shapeTypes.length; j++) {
1181
            IVectorLayer[] layersPerType = SextanteGUI.getInputFactory().getVectorLayers(shapeTypes[j]);
1182
            for (int k = 0; k < layersPerType.length; k++) {
1183
                layers.add(layersPerType[k]);
1184
            };
1185
        }
1186
        return layers;
1187
    }
1188

  
1124 1189
   protected JComboBox getTableSelectionComboBox(final ArrayList childComboBoxes,
1125 1190
                                                 final boolean bAddNotSetField) {
1126 1191

  
......
1220 1285

  
1221 1286
   }
1222 1287

  
1288
   protected JComboBox getVectorLayerFieldSelectionComboBox(final int[] shapeTypes) {
1223 1289

  
1290
      List<IVectorLayer> layers = getVectorLayers(shapeTypes);
1291

  
1292
      if (layers.size() > 0) {
1293
         final JComboBox comboBox = new JComboBox();
1294
         final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getVectorLayerFieldNames(layers.get(0)));
1295
         comboBox.setModel(defaultModel);
1296
         return comboBox;
1297
      }
1298
      else {
1299
         return new JComboBox();
1300
      }
1301

  
1302
   }
1303

  
1304

  
1224 1305
   protected String[] getTableFieldNames(final ITable table) {
1225 1306

  
1226 1307
      return table.getFieldNames();
org.gvsig.toolbox/trunk/org.gvsig.toolbox/org.gvsig.toolbox.algorithm/src/main/java/es/unex/sextante/vectorTools/boundingbox/BoundingBoxAlgorithm.java
15 15
import es.unex.sextante.exceptions.RepeatedParameterNameException;
16 16
import es.unex.sextante.outputs.OutputVectorLayer;
17 17

  
18
import org.gvsig.tools.exception.BaseException;
18 19

  
20

  
19 21
public class BoundingBoxAlgorithm
20 22
         extends
21 23
            GeoAlgorithm {
......
34 36
         layerIn.addFilter(new BoundingBoxFilter(m_AnalysisExtent));
35 37
      }
36 38

  
37
      final IVectorLayer result = getNewVectorLayer(RESULT, Sextante.getText("Bounding Box"), IVectorLayer.SHAPE_TYPE_POLYGON,
38
               layerIn.getFieldTypes(), layerIn.getFieldNames());
39
      int subtype;
40
    try {
41
        subtype = layerIn.getSubType();
42
    } catch (BaseException e) {
43
        subtype = org.gvsig.fmap.geom.Geometry.SUBTYPES.UNKNOWN;
44
    }
45
      IVectorLayer result;
46
        result = getNewVectorLayer(RESULT, Sextante.getText("Bounding Box"), IVectorLayer.SHAPE_TYPE_POLYGON,
47
                   layerIn.getFieldTypes(), layerIn.getFieldNames(), subtype);
39 48

  
40 49
      final IFeatureIterator iter = layerIn.iterator();
41 50
      final int iTotal = layerIn.getShapesCount();
......
60 69
      setUserCanDefineAnalysisExtent(true);
61 70

  
62 71
      try {
63
         m_Parameters.addInputVectorLayer(LAYER, Sextante.getText("Layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
72
            m_Parameters.addInputVectorLayer(
73
                LAYER,
74
                Sextante.getText("Layer"),
75
                new AdditionalInfoVectorLayer(
76
                    true,
77
                    AdditionalInfoVectorLayer.MASK_SHAPE_TYPE_LINE | AdditionalInfoVectorLayer.MASK_SHAPE_TYPE_POLYGON
78
                )
79
            );
64 80
         addOutputVectorLayer(RESULT, Sextante.getText("Bounding_Box"), OutputVectorLayer.SHAPE_TYPE_POLYGON);
65 81
      }
66 82
      catch (final RepeatedParameterNameException e) {
......
71 87

  
72 88

  
73 89
   private Geometry getBBox(final Geometry geometry) {
74

  
75 90
      return geometry.getEnvelope();
76

  
77 91
   }
78 92

  
79 93
}
org.gvsig.toolbox/trunk/org.gvsig.toolbox/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/core/ParametersSet.java
48 48
/**
49 49
 * Set of parameters needed by a GeoAlgorithm. This set is used to specify the requirements of the algorithm and to create a
50 50
 * suitable GUI to get the required information from the user, among other tasks.
51
 * 
51
 *
52 52
 * @author Victor Olaya volaya@unex.es
53
 * 
53
 *
54 54
 */
55 55
public class ParametersSet {
56 56

  
......
64 64

  
65 65

  
66 66
   /**
67
    * 
67
    *
68 68
    * @return the number of parameters in the set
69 69
    */
70 70
   public int getNumberOfParameters() {
......
76 76

  
77 77
   /**
78 78
    * Returns the number of parameters of type raster layer. This does not include multiple inputs of this same type
79
    * 
79
    *
80 80
    * @return the number of parameters requiring raster layers
81
    * 
81
    *
82 82
    */
83 83

  
84 84
   public int getNumberOfRasterLayers() {
......
89 89

  
90 90

  
91 91
   /**
92
    * 
92
    *
93 93
    * @return the number of parameters requiring raster layers
94
    * 
94
    *
95 95
    */
96 96
   public int getNumberOfRasterLayers(final boolean includeMultipleInputs) {
97 97

  
......
132 132

  
133 133
   /**
134 134
    * Returns the number of parameters of type vector layer. This does not include multiple inputs of this same type
135
    * 
135
    *
136 136
    * @return the number of parameters requiring vector layers
137
    * 
137
    *
138 138
    */
139 139
   public int getNumberOfVectorLayers() {
140 140

  
......
145 145

  
146 146
   /**
147 147
    * Returns the number of parameters of type vector layer.
148
    * 
148
    *
149 149
    * @return the number of parameters requiring vector layers
150
    * 
150
    *
151 151
    */
152 152
   public int getNumberOfVectorLayers(final boolean includeMultiInputs) {
153 153

  
......
183 183

  
184 184

  
185 185
   /**
186
    * 
186
    *
187 187
    * @param shapeType
188 188
    *                the type of shape for single input parameter
189 189
    * @param dataType
......
231 231

  
232 232

  
233 233
   /**
234
    * 
234
    *
235 235
    * @return the number of mandatory parameters requiring point vector layers
236 236
    */
237 237
   public int getNumberOfPointVectorLayers() {
......
243 243

  
244 244

  
245 245
   /**
246
    * 
246
    *
247 247
    * @return the number of mandatory parameters requiring line vector layers
248 248
    */
249 249
   public int getNumberOfLineVectorLayers() {
......
255 255

  
256 256

  
257 257
   /**
258
    * 
258
    *
259 259
    * @return the number of mandatory parameters requiring polygon vector layers
260 260
    */
261 261
   public int getNumberOfPolygonVectorLayers() {
......
268 268

  
269 269
   /**
270 270
    * Returns the number of parameters of type table. This does not include multiple inputs of this same type
271
    * 
271
    *
272 272
    * @return the number of parameters of type table
273 273
    */
274 274
   public int getNumberOfTables() {
......
288 288

  
289 289
   /**
290 290
    * Returns the number of parameters of type 3D raster layer
291
    * 
291
    *
292 292
    * @return the number of parameters of type 3D raster layer
293 293
    */
294 294
   public int getNumberOf3DRasterLayers() {
......
308 308

  
309 309
   /**
310 310
    * Returns the number of parameters of type different of Table, Vector or Raster.
311
    * 
311
    *
312 312
    * @return the number of parameters of type different of Table, Vector or Raster.
313 313
    */
314 314
   public int getNumberOfNoDataParameters() {
......
353 353

  
354 354
   /**
355 355
    * Returns the number of TableFields Parameters
356
    * 
356
    *
357 357
    * @return the number of parameters of TableFields.
358 358
    */
359 359
   public int getNumberOfTableFieldsParameters() {
......
374 374

  
375 375
   /**
376 376
    * Returns the number of Bands Parameters
377
    * 
377
    *
378 378
    * @return the number of parameters of Bands.
379 379
    */
380 380
   public int getNumberOfBandsParameters() {
......
395 395

  
396 396
   /**
397 397
    * Returns true if the set contains parameters other than tables or layers
398
    * 
398
    *
399 399
    * @return true if the set contains parameters other than tables or layers (vector or raster)
400 400
    */
401 401
   public boolean requiresNonDataObjects() {
......
421 421

  
422 422
   /**
423 423
    * Returns true if the set contains parameters requiring raster layers
424
    * 
424
    *
425 425
    * @return true if the set contains parameters requiring raster layers
426 426
    */
427 427
   public boolean requiresRasterLayers() {
......
443 443

  
444 444
   /**
445 445
    * Returns true if the set contains parameters requiring 3D raster layers
446
    * 
446
    *
447 447
    * @return true if the set contains parameters requiring 3D raster layers
448 448
    */
449 449
   public boolean requires3DRasterLayers() {
......
455 455

  
456 456
   /**
457 457
    * Returns true if the set contains parameters requiring multiple raster layers
458
    * 
458
    *
459 459
    * @return true if the set contains parameters requiring multiple raster layers
460 460
    */
461 461
   public boolean requiresMultipleRasterLayers() {
......
467 467

  
468 468
   /**
469 469
    * Returns true if the set contains parameters requiring multiple vector layers
470
    * 
470
    *
471 471
    * @return true if the set contains parameters requiring multiple vector layers
472 472
    */
473 473
   public boolean requiresMultipleVectorLayers() {
......
482 482

  
483 483
   /**
484 484
    * Returns true if the set contains parameters requiring multiple tables
485
    * 
485
    *
486 486
    * @return true if the set contains parameters requiring multiple tables
487 487
    */
488 488
   public boolean requiresMultipleTables() {
......
494 494

  
495 495
   /**
496 496
    * Returns true if the set contains parameters requiring multiple raster bands
497
    * 
497
    *
498 498
    * @return true if the set contains parameters requiring multiple raster bands
499 499
    */
500 500
   public boolean requiresMultipleRasterBands() {
......
505 505

  
506 506

  
507 507
   /**
508
    * 
508
    *
509 509
    * @param iType
510 510
    *                the type of multiple input to check, as defined in
511 511
    * @see {@link AdditionalInfoMultipleInput}.
......
541 541

  
542 542
   /**
543 543
    * Returns true if there is any parameter in the set requiring a single raster band
544
    * 
544
    *
545 545
    * @return true if there is any parameter in the set requiring a single raster band
546 546
    */
547 547
   public boolean requiresRasterBands() {
......
560 560

  
561 561
   /**
562 562
    * Returns true if the set contains parameters requiring vector layers
563
    * 
563
    *
564 564
    * @return true if the set contains parameters requiring vector layers
565 565
    */
566 566
   public boolean requiresVectorLayers() {
......
580 580

  
581 581
   /**
582 582
    * Returns true if the set contains parameters requiring point vector layers
583
    * 
583
    *
584 584
    * @return true if the set contains parameters requiring point vector layers
585 585
    */
586 586
   public boolean requiresPointVectorLayers() {
......
600 600

  
601 601
   /**
602 602
    * Returns true if the set contains parameters requiring line vector layers
603
    * 
603
    *
604 604
    * @return true if the set contains parameters requiring line vector layers
605 605
    */
606 606
   public boolean requiresLineVectorLayers() {
......
620 620

  
621 621
   /**
622 622
    * Returns true if the set contains parameters requiring polygon vector layers
623
    * 
623
    *
624 624
    * @return true if the set contains parameters requiring polygon vector layers
625 625
    */
626 626
   public boolean requiresPolygonVectorLayers() {
......
640 640

  
641 641
   /**
642 642
    * Returns true if the set contains parameters requiring tables
643
    * 
643
    *
644 644
    * @return true if the set contains parameters requiring tables
645 645
    */
646 646
   public boolean requiresTables() {
......
660 660

  
661 661
   /**
662 662
    * Returns true if the set contains fixed table parameters
663
    * 
663
    *
664 664
    * @return true if the set contains parameters requiring fixed tables
665 665
    */
666 666
   public boolean requiresFixedTables() {
......
679 679

  
680 680
   /**
681 681
    * Returns true if the set contains table fields parameters
682
    * 
682
    *
683 683
    * @return true if the set contains table fields that depend on other fields.
684 684
    */
685 685
   public boolean requiresTableFields() {
......
699 699

  
700 700
   /**
701 701
    * Returns true if the set contains point parameters.
702
    * 
702
    *
703 703
    * @return true if the set contains point parameters.
704 704
    */
705 705
   public boolean requiresPoints() {
......
719 719

  
720 720
   /**
721 721
    * Adds a new parameter to the set
722
    * 
722
    *
723 723
    * @param parameter
724 724
    *                a parameter
725 725
    * @return true if the parameter was added
......
743 743

  
744 744

  
745 745
   /**
746
    * 
746
    *
747 747
    * @param parameter
748 748
    *                a parameter
749 749
    * @throws WrongParameterIDException
......
758 758

  
759 759

  
760 760
   /**
761
    * 
761
    *
762 762
    * @param sParameterName
763 763
    *                the parameter name
764 764
    * @throws WrongParameterIDException
......
781 781

  
782 782

  
783 783
   /**
784
    * 
784
    *
785 785
    * @param paramClass
786 786
    *                the class of the parameters to retrieve
787 787
    * @return an arrayList with all parameters of the given class
......
804 804

  
805 805

  
806 806
   /**
807
    * 
807
    *
808 808
    * @param sParameterName
809 809
    *                the name of the parameter
810 810
    * @return the parameter
......
827 827

  
828 828

  
829 829
   /**
830
    * 
830
    *
831 831
    * @param iIndex
832 832
    *                the index of the parameter in the set
833 833
    * @return the parameter
......
847 847

  
848 848

  
849 849
   /**
850
    * 
850
    *
851 851
    * @param sParameterName
852 852
    *                the name of the parameter
853 853
    * @return the parameter as an object
......
868 868

  
869 869

  
870 870
   /**
871
    * 
871
    *
872 872
    * @param sParameterName
873 873
    *                the name of the parameter
874 874
    * @return the int value of the parameter
......
891 891

  
892 892

  
893 893
   /**
894
    * 
894
    *
895 895
    * @param sParameterName
896 896
    *                the name of the parameter
897 897
    * @return the value of the parameter as double
......
914 914

  
915 915

  
916 916
   /**
917
    * 
917
    *
918 918
    * @param sParameterName
919 919
    *                the name of the parameter
920 920
    * @return the value of the parameter as a Point2D object
......
937 937

  
938 938

  
939 939
   /**
940
    * 
940
    *
941 941
    * @param sParameterName
942 942
    *                the name of the parameter
943 943
    * @return the boolean value of the parameter
......
960 960

  
961 961

  
962 962
   /**
963
    * 
963
    *
964 964
    * @param sParameterName
965 965
    *                the name of the parameter
966 966
    * @return an array with the value(s) of the parameter
......
984 984

  
985 985

  
986 986
   /**
987
    * 
987
    *
988 988
    * @param sParameterName
989 989
    *                the name of the parameter
990 990
    * @return the value of the parameter as a string
......
1008 1008

  
1009 1009

  
1010 1010
   /**
1011
    * 
1011
    *
1012 1012
    * @param sParameterName
1013 1013
    *                the name of the parameter
1014 1014
    * @return the value of the parameter as a vector layer
......
1032 1032

  
1033 1033

  
1034 1034
   /**
1035
    * 
1035
    *
1036 1036
    * @param sParameterName
1037 1037
    *                the name of the parameter
1038 1038
    * @return the value of the parameter as a raster layer
......
1056 1056

  
1057 1057

  
1058 1058
   /**
1059
    * 
1059
    *
1060 1060
    * @param sParameterName
1061 1061
    *                the name of the parameter
1062 1062
    * @return the value of the parameter as a 3D raster layer
......
1080 1080

  
1081 1081

  
1082 1082
   /**
1083
    * 
1083
    *
1084 1084
    * @param sParameterName
1085 1085
    *                the name of the parameter
1086 1086
    * @return the value of the parameter as a table
......
1104 1104

  
1105 1105
   /**
1106 1106
    * Adds a vector layer to the parameter set
1107
    * 
1107
    *
1108 1108
    * @param sName
1109 1109
    *                the name of the parameter
1110 1110
    * @param sDescription
......
1122 1122
                                   final boolean bIsMandatory) throws RepeatedParameterNameException {
1123 1123

  
1124 1124
      final AdditionalInfoVectorLayer additionalInfo = new AdditionalInfoVectorLayer(iShapeType, bIsMandatory);
1125
      this.addInputVectorLayer(sName, sDescription, additionalInfo);
1126
    }
1125 1127

  
1126
      final ParameterVectorLayer parameter = new ParameterVectorLayer();
1127
      parameter.setParameterName(sName);
1128
      parameter.setParameterDescription(sDescription);
1129
      parameter.setParameterAdditionalInfo(additionalInfo);
1130
      addParameter(parameter);
1128
    /**
1129
     * Adds a vector layer to the parameter set
1130
     *
1131
     * @param sName
1132
     *            the name of the parameter
1133
     * @param sDescription
1134
     *            the description of the parameter
1135
     * @param additionalInfo
1136
     * @throws RepeatedParameterNameException
1137
     *             if a parameter with the same name already exists in the set
1138
     */
1139
    public void addInputVectorLayer(final String sName, final String sDescription,
1140
        final AdditionalInfoVectorLayer additionalInfo) throws RepeatedParameterNameException {
1131 1141

  
1132
   }
1142
        final ParameterVectorLayer parameter = new ParameterVectorLayer();
1143
        parameter.setParameterName(sName);
1144
        parameter.setParameterDescription(sDescription);
1145
        parameter.setParameterAdditionalInfo(additionalInfo);
1146
        addParameter(parameter);
1133 1147

  
1148
    }
1134 1149

  
1150

  
1135 1151
   /*public void addOutputVectorLayer(String sName,
1136 1152
   								 String sDescription,
1137 1153
   								 int iShapeType)
......
1152 1168

  
1153 1169
   /**
1154 1170
    * Adds a raster layer to the parameter set
1155
    * 
1171
    *
1156 1172
    * @param sName
1157 1173
    *                the name of the parameter
1158 1174
    * @param sDescription
......
1179 1195

  
1180 1196
   /**
1181 1197
    * Adds a 3D raster layer to the parameter set
1182
    * 
1198
    *
1183 1199
    * @param sName
1184 1200
    *                the name of the parameter
1185 1201
    * @param sDescription
......
1206 1222

  
1207 1223
   /**
1208 1224
    * Adds a table to the parameter set
1209
    * 
1225
    *
1210 1226
    * @param sName
1211 1227
    *                the name of the parameter
1212 1228
    * @param sDescription
......
1233 1249

  
1234 1250
   /**
1235 1251
    * Adds a multiple input the parameter set
1236
    * 
1252
    *
1237 1253
    * @param sName
1238 1254
    *                the name of the parameter
1239 1255
    * @param sDescription
......
1262 1278

  
1263 1279
   /**
1264 1280
    * Adds a table field to the set. The table field is set as mandatory by default
1265
    * 
1281
    *
1266 1282
    * @param sName
1267 1283
    *                the name of the parameter
1268 1284
    * @param sDescription
......
1285 1301

  
1286 1302
   /**
1287 1303
    * Adds a table field to the set
1288
    * 
1304
    *
1289 1305
    * @param sName
1290 1306
    *                the name of the parameter
1291 1307
    * @param sDescription
......
1341 1357

  
1342 1358
   /**
1343 1359
    * Adds a band to the set
1344
    * 
1360
    *
1345 1361
    * @param sName
1346 1362
    *                the name of the parameter
1347 1363
    * @param sDescription
......
1392 1408

  
1393 1409
   /**
1394 1410
    * Adds a numerical value to the set
1395
    * 
1411
    *
1396 1412
    * @param sName
1397 1413
    *                the name of the parameter
1398 1414
    * @param sDescription
......
1430 1446

  
1431 1447
   /**
1432 1448
    * Adds a numerical value to the set. No min or max values are defined, so the parameter can take any value
1433
    * 
1449
    *
1434 1450
    * @param sName
1435 1451
    *                the name of the parameter
1436 1452
    * @param sDescription
......
1454 1470

  
1455 1471
   /**
1456 1472
    * Add a string to the set
1457
    * 
1473
    *
1458 1474
    * @param sName
1459 1475
    *                the name of the parameter
1460 1476
    * @param sDescription
......
1472 1488

  
1473 1489
   /**
1474 1490
    * Add a string to the set
1475
    * 
1491
    *
1476 1492
    * @param sName
1477 1493
    *                the name of the parameter
1478 1494
    * @param sDescription
......
1501 1517

  
1502 1518
   /**
1503 1519
    * Adds a filepath to the set
1504
    * 
1520
    *
1505 1521
    * @param sName
1506 1522
    *                the name of the parameter
1507 1523
    * @param sDescription
......
1514 1530
    *                the extensions allowed
1515 1531
    * @throws RepeatedParameterNameException
1516 1532
    *                 if a parameter with the same name already exists in the set
1517
    * 
1533
    *
1518 1534
    */
1519 1535
   public void addFilepath(final String sName,
1520 1536
                           final String sDescription,
......
1536 1552

  
1537 1553
   /**
1538 1554
    * Adds a filepath to the set. This version accepts only a single user-defined
1539
    * File extension (primarily for simplified use in the graphical modeler). 
1540
    * 
1555
    * File extension (primarily for simplified use in the graphical modeler).
1556
    *
1541 1557
    * @param sName
1542 1558
    *                the name of the parameter
1543 1559
    * @param sDescription
......
1550 1566
    *                the extension allowed
1551 1567
    * @throws RepeatedParameterNameException
1552 1568
    *                 if a parameter with the same name already exists in the set
1553
    * 
1569
    *
1554 1570
    */
1555 1571
   public void addFilepath(final String sName,
1556 1572
                           final String sDescription,
......
1572 1588

  
1573 1589
   /**
1574 1590
    * Adds a boolean value to the set
1575
    * 
1591
    *
1576 1592
    * @param sName
1577 1593
    *                the name of the parameter
1578 1594
    * @param sDescription
......
1598 1614

  
1599 1615
   /**
1600 1616
    * Add a selection index (to choose from a list) to the set
1601
    * 
1617
    *
1602 1618
    * @param sName
1603 1619
    *                the name of the parameter
1604 1620
    * @param sDescription
......
1626 1642

  
1627 1643
   /**
1628 1644
    * Adds a fixed table to the set
1629
    * 
1645
    *
1630 1646
    * @param sName
1631 1647
    *                the name of the parameter
1632 1648
    * @param sDescription
......
1659 1675

  
1660 1676
   /**
1661 1677
    * Add a point to the set
1662
    * 
1678
    *
1663 1679
    * @param sName
1664 1680
    *                the name of the parameter
1665 1681
    * @param sDescription
......
1683 1699

  
1684 1700
   /**
1685 1701
    * Returns a new instance of the parameter set
1686
    * 
1702
    *
1687 1703
    * @return a new instance of the parameter set
1688 1704
    */
1689 1705
   public ParametersSet getNewInstance() {
......
1703 1719

  
1704 1720
   /**
1705 1721
    * Returns true if all parameters in the set have valid values
1706
    * 
1722
    *
1707 1723
    * @return true if all parameters in the set have valid values
1708 1724
    */
1709 1725
   public boolean areParameterValuesCorrect() {
org.gvsig.toolbox/trunk/org.gvsig.toolbox/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/parameters/ParameterVectorLayer.java
20 20

  
21 21
/**
22 22
 * A parameter representing a vector layer
23
 * 
23
 *
24 24
 * @author volaya
25
 * 
25
 *
26 26
 */
27 27
public class ParameterVectorLayer
28 28
         extends
......
96 96
   @Override
97 97
   public boolean setParameterValue(final Object value) {
98 98

  
99
      if (value instanceof IVectorLayer) {
100
         final AdditionalInfoVectorLayer ai = (AdditionalInfoVectorLayer) m_ParameterAdditionalInfo;
101
         final int iType = ai.getShapeType();
102
         if ((iType == AdditionalInfoVectorLayer.SHAPE_TYPE_ANY) || (iType == ((IVectorLayer) value).getShapeType())) {
103
            m_ParameterValue = value;
104
            return true;
105
         }
106
         else {
107
            return false;
108
         }
109
      }
99
        if (value instanceof IVectorLayer) {
100
            final AdditionalInfoVectorLayer ai = (AdditionalInfoVectorLayer) m_ParameterAdditionalInfo;
101
            if (ai.isAvailableForShapeType(((IVectorLayer) value).getShapeType())) {
102
                m_ParameterValue = value;
103
                return true;
104
            } else {
105
                return false;
106
            }
107
        }
110 108
      else if (value == null) {
111 109
         if (((AdditionalInfoVectorLayer) m_ParameterAdditionalInfo).getIsMandatory()) {
112 110
            return false;
org.gvsig.toolbox/trunk/org.gvsig.toolbox/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/additionalInfo/AdditionalInfoVectorLayer.java
1 1
package es.unex.sextante.additionalInfo;
2 2

  
3
public class AdditionalInfoVectorLayer
4
         extends
5
            AdditionalInfoDataObject {
3
import java.util.ArrayList;
4
import java.util.Iterator;
5
import java.util.List;
6 6

  
7
   public static final int SHAPE_TYPE_POINT   = 0;
8
   public static final int SHAPE_TYPE_LINE    = 1;
9
   public static final int SHAPE_TYPE_POLYGON = 2;
10
   public static final int SHAPE_TYPE_ANY     = -1;
7
import es.unex.sextante.dataObjects.IVectorLayer;
11 8

  
12
   private int             m_iShapeType       = -1;
13
   //true, if this is a 3D raster (=voxel data)
14
   private boolean         m_bIs3d            = false;
9
public class AdditionalInfoVectorLayer extends AdditionalInfoDataObject {
15 10

  
11
    public static final int SHAPE_TYPE_POINT = 0;
12
    public static final int SHAPE_TYPE_LINE = 1;
13
    public static final int SHAPE_TYPE_POLYGON = 2;
14
    public static final int SHAPE_TYPE_ANY = -1;
16 15

  
17
   public AdditionalInfoVectorLayer(final int iShapeType,
18
                                    final boolean bIsMandatory) {
16
    public static final int MASK_NOTAPPLY = 0;
17
    public static final int MASK_SHAPE_TYPE_POINT = 1;
18
    public static final int MASK_SHAPE_TYPE_LINE = 2;
19
    public static final int MASK_SHAPE_TYPE_POLYGON = 4;
20
    public static final int MASK_SHAPE_TYPE_ANY = 7;
19 21

  
20
      super(bIsMandatory);
22
    private int m_iShapeType = SHAPE_TYPE_ANY;
23
    private int m_maskShapeType = MASK_SHAPE_TYPE_ANY;
24
    // true, if this is a 3D raster (=voxel data)
25
    private boolean m_bIs3d = false;
21 26

  
22
      m_iShapeType = iShapeType;
27
    public AdditionalInfoVectorLayer(final int iShapeType, final boolean bIsMandatory) {
28
        this(iShapeType, bIsMandatory, MASK_NOTAPPLY);
29
    }
23 30

  
24
   }
31
    public AdditionalInfoVectorLayer(final int iShapeType, final boolean bIsMandatory, int maskShapeType) {
25 32

  
33
        super(bIsMandatory);
26 34

  
27
   /**
28
    * Checks whether the vector layer is 3D.
29
    * 
30
    * @return true if it is a 3D layer.
31
    * 
32
    */
33
   public boolean getIs3d() {
34
      return m_bIs3d;
35
   }
35
        m_iShapeType = iShapeType;
36
        m_maskShapeType = maskShapeType;
36 37

  
38
    }
37 39

  
38
   /**
39
    * Sets whether the vector layer is 3D.
40
    * 
41
    * @param is3d
42
    *                true if it is a 3D layer.
43
    */
44
   public void setIs3d(final boolean is3d) {
45
      m_bIs3d = is3d;
46
   }
40
    public AdditionalInfoVectorLayer(final boolean bIsMandatory, int maskShapeType) {
41
        super(bIsMandatory);
42
        m_maskShapeType = maskShapeType;
47 43

  
44
        if(maskShapeType == MASK_SHAPE_TYPE_POINT){
45
            m_iShapeType = SHAPE_TYPE_POINT;
46
        } else if(maskShapeType == MASK_SHAPE_TYPE_LINE){
47
            m_iShapeType = SHAPE_TYPE_LINE;
48
        } else if(maskShapeType == MASK_SHAPE_TYPE_POLYGON){
49
            m_iShapeType = SHAPE_TYPE_POLYGON;
50
        } else {
51
            m_iShapeType = SHAPE_TYPE_ANY;
52
        }
53
    }
48 54

  
49
   public void setShapeType(final int iShapeType) {
55
    /**
56
     *
57
     * @param shapeType of IVectorLayer
58
     * @return
59
     */
60
    public boolean isAvailableForShapeType(int shapeType){
61
        if(m_maskShapeType == MASK_NOTAPPLY){
62
            return ((m_iShapeType == AdditionalInfoVectorLayer.SHAPE_TYPE_ANY) || (m_iShapeType == shapeType));
63
        }
50 64

  
51
      m_iShapeType = iShapeType;
65
        if((m_maskShapeType & MASK_SHAPE_TYPE_POINT) == MASK_SHAPE_TYPE_POINT && shapeType == IVectorLayer.SHAPE_TYPE_POINT){
66
            return true;
67
        }
52 68

  
53
   }
69
        if((m_maskShapeType & MASK_SHAPE_TYPE_LINE) == MASK_SHAPE_TYPE_LINE && shapeType == IVectorLayer.SHAPE_TYPE_LINE){
70
            return true;
71
        }
72
        if((m_maskShapeType & MASK_SHAPE_TYPE_POLYGON) == MASK_SHAPE_TYPE_POLYGON && shapeType == IVectorLayer.SHAPE_TYPE_POLYGON){
73
            return true;
74
        }
54 75

  
76
        return false;
55 77

  
56
   public int getShapeType() {
57 78

  
58
      return m_iShapeType;
59
   }
79
    }
60 80

  
81
    /**
82
     * Checks whether the vector layer is 3D.
83
     *
84
     * @return true if it is a 3D layer.
85
     *
86
     */
87
    public boolean getIs3d() {
88
        return m_bIs3d;
89
    }
61 90

  
62
   public String getTextDescription() {
63
      // TODO Auto-generated method stub
64
      return null;
65
   }
91
    /**
92
     * Sets whether the vector layer is 3D.
93
     *
94
     * @param is3d
95
     *            true if it is a 3D layer.
96
     */
97
    public void setIs3d(final boolean is3d) {
98
        m_bIs3d = is3d;
99
    }
66 100

  
101
    public void setShapeType(final int iShapeType) {
102

  
103
        m_iShapeType = iShapeType;
104

  
105
    }
106

  
107
    public int getShapeType() {
108

  
109
        return m_iShapeType;
110

  
111
    }
112

  
113
    public int[] getShapeTypes() {
114
        List<Integer> types = new ArrayList();
115
        if(isAvailableForShapeType(SHAPE_TYPE_ANY)){
116
            types.add(SHAPE_TYPE_ANY);
117
        } else {
118
            if (isAvailableForShapeType(SHAPE_TYPE_POINT)) {
119
                types.add(SHAPE_TYPE_POINT);
120
            }
121
            if (isAvailableForShapeType(SHAPE_TYPE_LINE)) {
122
                types.add(SHAPE_TYPE_LINE);
123
            }
124
            if (isAvailableForShapeType(SHAPE_TYPE_POLYGON)) {
125
                types.add(SHAPE_TYPE_POLYGON);
126
            }
127
        }
128
        int[] shapeTypes = new int[types.size()];
129

  
130
        int i=0;
131
        for (Iterator iterator = types.iterator(); iterator.hasNext();) {
132
            Integer integer = (Integer) iterator.next();
133
            shapeTypes[i++]=integer.intValue();
134
        }
135

  
136
        return shapeTypes;
137
    }
138

  
139

  
140
    public String getTextDescription() {
141
        // TODO Auto-generated method stub
142
        return null;
143
    }
144

  
67 145
}

Also available in: Unified diff