@Override
 public void selectionChanged(SelectionChangeEvent event) {
   if (!operatorDescriptor.isHandlingOutputName()) {
     Property targetProperty =
         propertySet.getProperty(ToolAdapterConstants.TOOL_TARGET_PRODUCT_FILE);
     Object value = targetProperty.getValue();
     String productName = "";
     final Product selectedProduct = (Product) event.getSelection().getSelectedValue();
     if (selectedProduct != null) {
       productName = FileUtils.getFilenameWithoutExtension(selectedProduct.getName());
     }
     final TargetProductSelectorModel targetProductSelectorModel =
         targetProductSelector.getModel();
     productName += TARGET_PRODUCT_NAME_SUFFIX;
     targetProductSelectorModel.setProductName(productName);
     if (value != null) {
       File oldValue =
           operatorDescriptor.resolveVariables(
               value instanceof File ? (File) value : new File((String) value));
       if (fileExtension == null) fileExtension = TIF_EXTENSION;
       propertySet.setValue(
           ToolAdapterConstants.TOOL_TARGET_PRODUCT_FILE,
           new File(oldValue.getParentFile().getAbsolutePath(), productName + fileExtension));
     } else {
       File workingDir = operatorDescriptor.resolveVariables(operatorDescriptor.getWorkingDir());
       try {
         targetProperty.setValue(new File(workingDir, productName + TIF_EXTENSION));
       } catch (ValidationException ignored) {
       }
     }
   }
 }
 private void updateTargetProductFields() {
   TargetProductSelectorModel model = targetProductSelector.getModel();
   Property property = propertySet.getProperty(ToolAdapterConstants.TOOL_TARGET_PRODUCT_FILE);
   if (!operatorDescriptor.isHandlingOutputName()) {
     Object value = property.getValue();
     if (value != null) {
       File file = operatorDescriptor.resolveVariables(new File(property.getValueAsText()));
       String productName = FileUtils.getFilenameWithoutExtension(file);
       if (fileExtension == null) {
         fileExtension = FileUtils.getExtension(file);
       }
       model.setProductName(productName);
     }
   } else {
     try {
       model.setProductName("Output Product");
       if (property != null) {
         property.setValue(null);
       }
     } catch (ValidationException e) {
       Logger.getLogger(ToolExecutionForm.class.getName()).severe(e.getMessage());
     }
   }
   model.setSaveToFileSelected(false);
   targetProductSelector.getProductDirTextField().setEnabled(false);
 }
  @Override
  public PropertySet createLayerConfig(LayerContext ctx) {
    final PropertyContainer configuration = new PropertyContainer();

    // Mandatory Parameters

    configuration.addProperty(
        Property.create(PROPERTY_NAME_FEATURE_COLLECTION, FeatureCollection.class));
    configuration.getDescriptor(PROPERTY_NAME_FEATURE_COLLECTION).setTransient(true);

    configuration.addProperty(Property.create(PROPERTY_NAME_SLD_STYLE, Style.class));
    configuration.getDescriptor(PROPERTY_NAME_SLD_STYLE).setDomConverter(new StyleDomConverter());
    configuration.getDescriptor(PROPERTY_NAME_SLD_STYLE).setNotNull(true);

    // Optional Parameters

    configuration.addProperty(
        Property.create(PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY, Geometry.class));
    configuration
        .getDescriptor(PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY)
        .setDomConverter(new GeometryDomConverter());

    configuration.addProperty(Property.create(PROPERTY_NAME_FEATURE_COLLECTION_URL, URL.class));

    configuration.addProperty(
        Property.create(PROPERTY_NAME_FEATURE_COLLECTION_CRS, CoordinateReferenceSystem.class));
    configuration
        .getDescriptor(PROPERTY_NAME_FEATURE_COLLECTION_CRS)
        .setDomConverter(new CRSDomConverter());

    return configuration;
  }
  private void addParameters(
      final OperatorSpi operatorSpi, final AppContext appContext, final String helpID) {
    // OperatorMenu operatorMenu = new OperatorMenu(this.getJDialog(),
    //                                             operatorSpi.getOperatorClass(),
    //                                             parameterSupport,
    //                                             helpID);
    final PropertySet propertyContainer = parameterSupport.getPopertySet();
    final List<SourceProductSelector> sourceProductSelectorList =
        ioParametersPanel.getSourceProductSelectorList();

    sourceProductSelectorList
        .get(0)
        .addSelectionChangeListener(
            new AbstractSelectionChangeListener() {

              @Override
              public void selectionChanged(SelectionChangeEvent event) {
                final Product selectedProduct = (Product) event.getSelection().getSelectedValue();
                if (selectedProduct != null) {
                  final TargetProductSelectorModel targetProductSelectorModel =
                      getTargetProductSelector().getModel();
                  targetProductSelectorModel.setProductName(
                      selectedProduct.getName() + getTargetProductNameSuffix());
                  opUI.setSourceProducts(new Product[] {selectedProduct});
                }
              }
            });

    if (propertyContainer.getProperties().length > 0) {
      if (!sourceProductSelectorList.isEmpty()) {
        Property[] properties = propertyContainer.getProperties();
        List<PropertyDescriptor> rdnTypeProperties =
            new ArrayList<PropertyDescriptor>(properties.length);
        for (Property property : properties) {
          PropertyDescriptor parameterDescriptor = property.getDescriptor();
          if (parameterDescriptor.getAttribute(RasterDataNodeValues.ATTRIBUTE_NAME) != null) {
            rdnTypeProperties.add(parameterDescriptor);
          }
        }
        rasterDataNodeTypeProperties =
            rdnTypeProperties.toArray(new PropertyDescriptor[rdnTypeProperties.size()]);
      }

      final JComponent paremetersPanel =
          opUI.CreateOpTab(operatorName, parameterSupport.getParameterMap(), appContext);

      paremetersPanel.setBorder(new EmptyBorder(4, 4, 4, 4));
      this.form.add("Processing Parameters", new JScrollPane(paremetersPanel));

      // getJDialog().setJMenuBar(operatorMenu.createDefaultMenu());
    }
  }
Exemple #5
0
  private Map<String, Object> convertParameterMap(
      String operatorName, Map<String, String> parameterMap) throws ValidationException {
    HashMap<String, Object> parameters = new HashMap<String, Object>();
    PropertyContainer container =
        ParameterDescriptorFactory.createMapBackedOperatorPropertyContainer(
            operatorName, parameters);
    // explicitly set default values for putting them into the backing map
    container.setDefaultValues();

    // handle xml parameters
    Object parametersObject = metadataResourceEngine.getVelocityContext().get("parameterFile");
    if (parametersObject instanceof Resource) {
      Resource paramatersResource = (Resource) parametersObject;
      if (paramatersResource.isXml()) {
        OperatorSpiRegistry operatorSpiRegistry = GPF.getDefaultInstance().getOperatorSpiRegistry();
        OperatorSpi operatorSpi = operatorSpiRegistry.getOperatorSpi(operatorName);
        Class<? extends Operator> operatorClass = operatorSpi.getOperatorClass();
        DefaultDomConverter domConverter =
            new DefaultDomConverter(operatorClass, new ParameterDescriptorFactory());

        DomElement parametersElement = createDomElement(paramatersResource.getContent());
        try {
          domConverter.convertDomToValue(parametersElement, container);
        } catch (ConversionException e) {
          String msgPattern = "Can not convert XML parameters for operator '%s'";
          throw new RuntimeException(String.format(msgPattern, operatorName));
        }
      }
    }

    for (Entry<String, String> entry : parameterMap.entrySet()) {
      String paramName = entry.getKey();
      String paramValue = entry.getValue();
      final Property property = container.getProperty(paramName);
      if (property != null) {
        property.setValueFromText(paramValue);
      } else {
        throw new RuntimeException(
            String.format("Parameter '%s' is not known by operator '%s'", paramName, operatorName));
      }
    }
    return parameters;
  }
Exemple #6
0
 public void setComponentsEnabled(boolean enabled) {
   if (!enabled) {
     for (Property property : bindingContext.getPropertySet().getProperties()) {
       bindingContext.setComponentsEnabled(property.getName(), enabled);
     }
   } else {
     for (Property property : bindingContext.getPropertySet().getProperties()) {
       if (property.getName().equals("min") || property.getName().equals("max")) {
         bindingContext.setComponentsEnabled(property.getName(), !isAutoMinMax());
       } else {
         bindingContext.setComponentsEnabled(property.getName(), enabled);
       }
     }
   }
 }
  private void editSliderSample(MouseEvent evt, final int sliderIndex) {
    final PropertyContainer vc = new PropertyContainer();
    vc.addProperty(Property.create("sample", getSliderSample(sliderIndex)));
    vc.getDescriptor("sample").setDisplayName("sample");
    vc.getDescriptor("sample").setUnit(getModel().getParameterUnit());
    final ValueRange valueRange;
    if (sliderIndex == 0) {
      valueRange = new ValueRange(Double.NEGATIVE_INFINITY, round(getMaxSliderSample(sliderIndex)));
    } else if (sliderIndex == getSliderCount() - 1) {
      valueRange = new ValueRange(round(getMinSliderSample(sliderIndex)), Double.POSITIVE_INFINITY);
    } else {
      valueRange =
          new ValueRange(
              round(getMinSliderSample(sliderIndex)), round(getMaxSliderSample(sliderIndex)));
    }
    vc.getDescriptor("sample").setValueRange(valueRange);

    final BindingContext ctx = new BindingContext(vc);
    final NumberFormatter formatter = new NumberFormatter(new DecimalFormat("#0.0#"));
    formatter.setValueClass(Double.class); // to ensure that double values are returned
    final JFormattedTextField field = new JFormattedTextField(formatter);
    field.setColumns(11);
    field.setHorizontalAlignment(JFormattedTextField.RIGHT);
    ctx.bind("sample", field);

    showPopup(evt, field);

    ctx.addPropertyChangeListener(
        "sample",
        pce -> {
          hidePopup();
          setSliderSample(sliderIndex, (Double) ctx.getBinding("sample").getPropertyValue());
          computeZoomInToSliderLimits();
          applyChanges();
        });
  }
  @Override
  protected JPanel createPanel(BindingContext context) {
    TableLayout tableLayout = new TableLayout(2);
    tableLayout.setTableAnchor(TableLayout.Anchor.NORTHWEST);
    tableLayout.setTablePadding(new Insets(4, 10, 0, 0));
    tableLayout.setTableFill(TableLayout.Fill.BOTH);
    tableLayout.setColumnWeightX(1, 1.0);
    tableLayout.setCellColspan(0, 0, 2);
    tableLayout.setCellColspan(1, 0, 2);
    tableLayout.setCellColspan(8, 0, 2);

    JPanel pageUI = new JPanel(tableLayout);

    PropertyEditorRegistry registry = PropertyEditorRegistry.getInstance();
    Property computeLatLonSteps =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_RES_AUTO);
    Property avgGridSize =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_RES_PIXELS);
    Property latStep =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_RES_LAT);
    Property lonStep =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_RES_LON);
    Property lineColor =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_LINE_COLOR);
    Property lineWidth =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_LINE_WIDTH);
    Property lineTransparency =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_LINE_TRANSPARENCY);
    Property showTextLabels =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_TEXT_ENABLED);
    Property textFgColor =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_TEXT_FG_COLOR);
    Property textBgColor =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_TEXT_BG_COLOR);
    Property textBgTransparency =
        context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_TEXT_BG_TRANSPARENCY);

    JComponent[] computeLatLonStepsComponents =
        registry
            .findPropertyEditor(computeLatLonSteps.getDescriptor())
            .createComponents(computeLatLonSteps.getDescriptor(), context);
    JComponent[] avgGridSizeComponents =
        registry
            .findPropertyEditor(avgGridSize.getDescriptor())
            .createComponents(avgGridSize.getDescriptor(), context);
    JComponent[] latStepComponents =
        registry
            .findPropertyEditor(latStep.getDescriptor())
            .createComponents(latStep.getDescriptor(), context);
    JComponent[] lonStepComponents =
        registry
            .findPropertyEditor(lonStep.getDescriptor())
            .createComponents(lonStep.getDescriptor(), context);
    JComponent[] lineColorComponents = PreferenceUtils.createColorComponents(lineColor);
    JComponent[] lineWidthComponents =
        registry
            .findPropertyEditor(lineWidth.getDescriptor())
            .createComponents(lineWidth.getDescriptor(), context);
    JComponent[] lineTransparencyComponents =
        registry
            .findPropertyEditor(lineTransparency.getDescriptor())
            .createComponents(lineTransparency.getDescriptor(), context);
    JComponent[] showTextLabelsComponents =
        registry
            .findPropertyEditor(showTextLabels.getDescriptor())
            .createComponents(showTextLabels.getDescriptor(), context);
    textFgColorComponents = PreferenceUtils.createColorComponents(textFgColor);
    textBgColorComponents = PreferenceUtils.createColorComponents(textBgColor);
    JComponent[] textBgTransparencyComponents =
        registry
            .findPropertyEditor(textBgTransparency.getDescriptor())
            .createComponents(textBgTransparency.getDescriptor(), context);

    pageUI.add(computeLatLonStepsComponents[0]);
    addNote(
        pageUI,
        "<html>Note: Deselect this option only very carefully. The latitude and longitude<br>"
            + "steps you enter will be used for low and high resolution products.</html>");
    pageUI.add(avgGridSizeComponents[1]);
    pageUI.add(avgGridSizeComponents[0]);
    pageUI.add(latStepComponents[1]);
    pageUI.add(latStepComponents[0]);
    pageUI.add(lonStepComponents[1]);
    pageUI.add(lonStepComponents[0]);
    pageUI.add(lineColorComponents[0]);
    pageUI.add(lineColorComponents[1]);
    pageUI.add(lineWidthComponents[1]);
    pageUI.add(lineWidthComponents[0]);
    pageUI.add(lineTransparencyComponents[1]);
    pageUI.add(lineTransparencyComponents[0]);
    pageUI.add(showTextLabelsComponents[0]);
    pageUI.add(textFgColorComponents[0]);
    pageUI.add(textFgColorComponents[1]);
    pageUI.add(textBgColorComponents[0]);
    pageUI.add(textBgColorComponents[1]);
    pageUI.add(textBgTransparencyComponents[1]);
    pageUI.add(textBgTransparencyComponents[0]);

    pageUI.add(tableLayout.createVerticalSpacer());

    JPanel parent = new JPanel(new BorderLayout());
    parent.add(pageUI, BorderLayout.CENTER);
    parent.add(Box.createHorizontalStrut(100), BorderLayout.EAST);
    return parent;
  }
  @Override
  protected void initComponents() {
    getAlternativeView().initComponents();
    dataset = new XYIntervalSeriesCollection();
    this.chart =
        ChartFactory.createXYLineChart(
            CHART_TITLE,
            "Path in pixels",
            DEFAULT_SAMPLE_DATASET_NAME,
            dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);
    final XYPlot plot = chart.getXYPlot();

    deviationRenderer = new DeviationRenderer();
    deviationRenderer.setUseFillPaint(true);
    deviationRenderer.setBaseToolTipGenerator(new XYPlotToolTipGenerator());
    deviationRenderer.setSeriesLinesVisible(0, true);
    deviationRenderer.setSeriesShapesVisible(0, false);
    deviationRenderer.setSeriesStroke(0, new BasicStroke(1.0f));
    deviationRenderer.setSeriesPaint(0, StatisticChartStyling.SAMPLE_DATA_PAINT);
    deviationRenderer.setSeriesFillPaint(0, StatisticChartStyling.SAMPLE_DATA_FILL_PAINT);

    pointRenderer = new XYErrorRenderer();
    pointRenderer.setUseFillPaint(true);
    pointRenderer.setBaseToolTipGenerator(new XYPlotToolTipGenerator());
    pointRenderer.setSeriesLinesVisible(0, false);
    pointRenderer.setSeriesShapesVisible(0, true);
    pointRenderer.setSeriesStroke(0, new BasicStroke(1.0f));
    pointRenderer.setSeriesPaint(0, StatisticChartStyling.SAMPLE_DATA_PAINT);
    pointRenderer.setSeriesFillPaint(0, StatisticChartStyling.SAMPLE_DATA_FILL_PAINT);
    pointRenderer.setSeriesShape(0, StatisticChartStyling.SAMPLE_DATA_POINT_SHAPE);

    configureRendererForCorrelativeData(deviationRenderer);
    configureRendererForCorrelativeData(pointRenderer);

    plot.setNoDataMessage(NO_DATA_MESSAGE);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setRenderer(deviationRenderer);

    final AxisChangeListener axisListener =
        new AxisChangeListener() {
          @Override
          public void axisChanged(AxisChangeEvent event) {
            adjustAxisControlComponents();
          }
        };

    final ValueAxis domainAxis = plot.getDomainAxis();
    final ValueAxis rangeAxis = plot.getRangeAxis();
    // allow transfer from bounds into min/max fields, if auto min/maxis enabled
    domainAxis.setAutoRange(true);
    rangeAxis.setAutoRange(true);

    domainAxis.addChangeListener(axisListener);
    rangeAxis.addChangeListener(axisListener);

    intervalMarkers = new HashSet<IntervalMarker>();

    xAxisRangeControl = new AxisRangeControl("X-Axis");
    yAxisRangeControl = new AxisRangeControl("Y-Axis");

    final PropertyChangeListener changeListener =
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals(PROPERTY_NAME_MARK_SEGMENTS)) {
              updateDataSet();
            }
            if (evt.getPropertyName().equals(PROPERTY_NAME_LOG_SCALED)) {
              updateScalingOfYAxis();
            }
            updateUIState();
          }
        };
    xAxisRangeControl.getBindingContext().addPropertyChangeListener(changeListener);
    xAxisRangeControl
        .getBindingContext()
        .getPropertySet()
        .addProperty(Property.create(PROPERTY_NAME_MARK_SEGMENTS, false));
    xAxisRangeControl
        .getBindingContext()
        .getPropertySet()
        .getDescriptor(PROPERTY_NAME_MARK_SEGMENTS)
        .setDescription("Toggle whether to mark segments");

    yAxisRangeControl.getBindingContext().addPropertyChangeListener(changeListener);
    yAxisRangeControl
        .getBindingContext()
        .getPropertySet()
        .addProperty(Property.create(PROPERTY_NAME_LOG_SCALED, false));
    yAxisRangeControl
        .getBindingContext()
        .getPropertySet()
        .getDescriptor(PROPERTY_NAME_LOG_SCALED)
        .setDescription("Toggle whether to use a logarithmic axis");

    dataSourceConfig = new DataSourceConfig();
    final BindingContext bindingContext =
        new BindingContext(PropertyContainer.createObjectBacked(dataSourceConfig));

    JPanel middlePanel = createMiddlePanel(bindingContext);
    createUI(createChartPanel(chart), middlePanel, bindingContext);

    isInitialized = true;

    updateComponents();
  }
 public static PropertySet createLayerConfig() {
   final PropertyContainer configuration = new PropertyContainer();
   configuration.addProperty(
       Property.create(VectorDataLayerType.PROPERTY_NAME_VECTOR_DATA, String.class));
   return configuration;
 }