Example #1
0
  @Override
  protected void initComponents() {
    SnapApp.getDefault()
        .getSelectionSupport(ProductNode.class)
        .addHandler(
            (oldValue, newValue) -> {
              if (newValue != null) {
                handleMasklessProduct(newValue.getProduct());
              }
            });
    SnapApp.getDefault()
        .getProductManager()
        .addListener(
            new ProductManager.Listener() {
              @Override
              public void productAdded(ProductManager.Event event) {
                // do nothing
              }

              @Override
              public void productRemoved(ProductManager.Event event) {
                model.removeStxFromProduct(event.getProduct());
              }
            });
    model = new HistogramPanelModel();
    xAxisRangeControl = new AxisRangeControl("X-Axis");

    histogramPlotConfig = new HistogramPlotConfig();
    bindingContext = new BindingContext(PropertyContainer.createObjectBacked(histogramPlotConfig));
    configChangeListener = new ConfigChangeListener();
    bindingContext.addPropertyChangeListener(configChangeListener);

    createUI();
    updateComponents();
  }
 /**
  * allows the choice of picking directories only
  *
  * @param title
  * @param dirsOnly
  * @param fileFilter
  * @param currentDir
  * @param lastDirPropertyKey
  * @return
  */
 private static File showFileOpenDialog(
     String title,
     boolean dirsOnly,
     FileFilter fileFilter,
     String currentDir,
     String lastDirPropertyKey) {
   final SnapFileChooser fileChooser = new SnapFileChooser();
   fileChooser.setCurrentDirectory(new File(currentDir));
   if (fileFilter != null) {
     fileChooser.setFileFilter(fileFilter);
   }
   fileChooser.setDialogTitle(title);
   fileChooser.setFileSelectionMode(
       dirsOnly ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);
   int result = fileChooser.showOpenDialog(SnapApp.getDefault().getMainFrame());
   if (fileChooser.getCurrentDirectory() != null) {
     final String lastDirPath = fileChooser.getCurrentDirectory().getAbsolutePath();
     if (lastDirPath != null) {
       SnapApp.getDefault().getPreferences().put(lastDirPropertyKey, lastDirPath);
     }
   }
   if (result == JFileChooser.APPROVE_OPTION) {
     File file = fileChooser.getSelectedFile();
     if (file == null || file.getName().isEmpty()) {
       return null;
     }
     return file.getAbsoluteFile();
   }
   return null;
 }
 @Override
 public void actionPerformed(ActionEvent e) {
   final Layer selectedLayer =
       SnapApp.getDefault().getSelectedProductSceneView().getSelectedLayer();
   Layer rootLayer = SnapApp.getDefault().getSelectedProductSceneView().getRootLayer();
   if (selectedLayer != null && rootLayer != selectedLayer) {
     moveUp(selectedLayer);
   }
 }
  private void createXYDisplacementBands(Product product) {
    final SnapApp snapApp = SnapApp.getDefault();
    final Frame mainFrame = snapApp.getMainFrame();
    String dialogTitle = Bundle.CTL_CreateGeoCodingDisplacementBandsDialogTitle();
    final ProgressMonitorSwingWorker swingWorker =
        new ProgressMonitorSwingWorker<Band[], Object>(mainFrame, dialogTitle) {
          @Override
          protected Band[] doInBackground(ProgressMonitor pm) throws Exception {
            final Band[] xyDisplacementBands = createXYDisplacementBands(product, pm);
            UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(product);
            if (undoManager != null) {
              undoManager.addEdit(
                  new UndoableDisplacementBandsCreation(product, xyDisplacementBands));
            }
            return xyDisplacementBands;
          }

          @Override
          public void done() {
            if (snapApp
                .getPreferences()
                .getBoolean(UiBehaviorController.PREFERENCE_KEY_AUTO_SHOW_NEW_BANDS, true)) {
              try {
                Band[] bands = get();
                if (bands == null) {
                  return;
                }
                for (Band band : bands) {
                  Band oldBand = product.getBand(band.getName());
                  if (oldBand != null) {
                    product.removeBand(oldBand);
                  }
                  product.addBand(band);
                }
              } catch (Exception e) {
                Throwable cause = e;
                if (e instanceof ExecutionException) {
                  cause = e.getCause();
                }
                String msg = "An internal error occurred:\n" + e.getMessage();
                if (cause instanceof IOException) {
                  msg = "An I/O error occurred:\n" + e.getMessage();
                }
                SnapDialogs.showError(dialogTitle, msg);
              } finally {
                UIUtils.setRootFrameDefaultCursor(mainFrame);
              }
            }
          }
        };

    swingWorker.execute();
  }
  private void initContentPanel() {

    moreOptionsPane = new MoreOptionsPane(this, formModel.isMoreOptionsFormCollapsedOnInit());

    resetButton = createButton("org/esa/snap/rcp/icons/Undo24.gif");
    resetButton.setName("ResetButton");
    resetButton.setToolTipText("Reset to defaults"); /*I18N*/
    resetButton.addActionListener(wrapWithAutoApplyActionListener(e -> resetToDefaults()));

    multiApplyButton = createButton("org/esa/snap/rcp/icons/MultiAssignBands24.gif");
    multiApplyButton.setName("MultiApplyButton");
    multiApplyButton.setToolTipText("Apply to other bands"); /*I18N*/
    multiApplyButton.addActionListener(e -> applyMultipleColorPaletteDef());

    importButton = createButton("tango/22x22/actions/document-open.png");
    importButton.setName("ImportButton");
    importButton.setToolTipText("Import colour palette from text file."); /*I18N*/
    importButton.addActionListener(
        e -> {
          importColorPaletteDef();
          applyChanges();
        });
    importButton.setEnabled(true);

    exportButton = createButton("tango/22x22/actions/document-save-as.png");
    exportButton.setName("ExportButton");
    exportButton.setToolTipText("Save colour palette to text file."); /*I18N*/
    exportButton.addActionListener(
        e -> {
          exportColorPaletteDef();
          childForm.updateFormModel(getFormModel());
        });
    exportButton.setEnabled(true);

    helpButton = createButton("tango/22x22/apps/help-browser.png");
    helpButton.setToolTipText("Help."); /*I18N*/
    helpButton.setName("helpButton");
    helpButton.addActionListener(e -> toolView.getHelpCtx().display());

    editorPanel = new JPanel(new BorderLayout(4, 4));
    toolButtonsPanel = GridBagUtils.createPanel();

    contentPanel = new JPanel(new BorderLayout(4, 4));
    contentPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    contentPanel.setPreferredSize(new Dimension(320, 200));
    contentPanel.add(editorPanel, BorderLayout.CENTER);
    contentPanel.add(toolButtonsPanel, BorderLayout.EAST);

    setProductSceneView(SnapApp.getDefault().getSelectedProductSceneView());

    SnapApp.getDefault().getSelectionSupport(ProductSceneView.class).addHandler(this);
  }
  public static File GetFilePath(
      final String title,
      final String formatName,
      final String extension,
      final String fileName,
      final String description,
      final boolean isSave,
      final String lastDirPropertyKey,
      final String defaultPath) {
    SnapFileFilter fileFilter = null;
    if (!extension.isEmpty()) {
      fileFilter = new SnapFileFilter(formatName, extension, description);
    }
    File file = null;
    if (isSave) {
      final String lastDir =
          SnapApp.getDefault()
              .getPreferences()
              .get(lastDirPropertyKey, SystemUtils.getUserHomeDir().getPath());
      final File currentDir = new File(lastDir);

      final SnapFileChooser fileChooser = new SnapFileChooser();
      fileChooser.setCurrentDirectory(currentDir);
      fileChooser.addChoosableFileFilter(new SnapFileFilter(formatName, extension, description));
      fileChooser.setAcceptAllFileFilterUsed(false);

      fileChooser.setDialogTitle("Save");
      fileChooser.setCurrentFilename(fileName);
      fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

      final int result = fileChooser.showSaveDialog(SnapApp.getDefault().getMainFrame());
      if (result == JFileChooser.APPROVE_OPTION) {
        file = fileChooser.getSelectedFile();

        final File currentDirectory = fileChooser.getCurrentDirectory();
        if (currentDirectory != null) {
          SnapApp.getDefault().getPreferences().put(lastDirPropertyKey, currentDirectory.getPath());
        }
      }
    } else {
      String lastDir = SnapApp.getDefault().getPreferences().get(lastDirPropertyKey, defaultPath);
      if (fileName == null) {
        file = showFileOpenDialog(title, false, fileFilter, lastDir, lastDirPropertyKey);
      } else {
        file = showFileOpenDialog(title, false, fileFilter, fileName, lastDirPropertyKey);
      }
    }

    return file == null ? null : FileUtils.ensureExtension(file, extension);
  }
 @Override
 protected void initComponents() {
   getAlternativeView().initComponents();
   initParameters();
   createUI();
   SnapApp.getDefault().getProductManager().addListener(productRemovedListener);
 }
Example #8
0
  /**
   * Launches PolSARPro Invoked when a command action is performed.
   *
   * @param event the command event.
   */
  @Override
  public void actionPerformed(ActionEvent event) {
    final Preferences pref = SnapApp.getDefault().getPreferences();

    // find tcl wish
    File tclFile = new File(pref.get(TCLPathStr, ""));

    if (!tclFile.exists()) {
      tclFile = findTCLWish();
      if (tclFile.exists()) pref.put(TCLPathStr, tclFile.getAbsolutePath());
    }

    // find polsar pro
    File polsarProFile = new File(pref.get(PolsarProPathStr, ""));

    if (!polsarProFile.exists()) {
      polsarProFile = findPolsarPro();
    }
    if (!polsarProFile.exists()) {
      // ask for location
      polsarProFile =
          FileFolderUtils.GetFilePath(
              "PolSARPro Location", "tcl", "tcl", null, "PolSARPro File", false);
    }
    if (polsarProFile.exists()) {
      externalExecute(polsarProFile, tclFile);

      // save location
      pref.put(PolsarProPathStr, polsarProFile.getAbsolutePath());
    }
  }
 private void showErrorDialog(final String message) {
   if (message != null && message.trim().length() > 0) {
     if (SnapApp.getDefault() != null) {
       SnapDialogs.showError(message);
     } else {
       JOptionPane.showMessageDialog(
           getToolViewPaneControl(), message, "Error", JOptionPane.ERROR_MESSAGE);
     }
   }
 }
 @Override
 public boolean validatePage() {
   try {
     crsSelectionPanel.getCrs(
         ProductUtils.getCenterGeoPos(SnapApp.getDefault().getSelectedProduct()));
   } catch (FactoryException ignored) {
     return false;
   }
   return true;
 }
  @Override
  public Component createPageComponent() {
    final AppContext snapContext = SnapApp.getDefault().getAppContext();
    final ProductCrsForm productCrsForm =
        new ProductCrsForm(snapContext, SnapApp.getDefault().getSelectedProduct());
    final CustomCrsForm customCrsForm = new CustomCrsForm(snapContext);
    final PredefinedCrsForm predefinedCrsForm = new PredefinedCrsForm(snapContext);

    final TableLayout tableLayout = new TableLayout(1);
    tableLayout.setTablePadding(4, 4);
    tableLayout.setTableWeightX(1.0);
    tableLayout.setTableWeightY(1.0);
    tableLayout.setTableFill(TableLayout.Fill.BOTH);
    final JPanel pageComponent = new JPanel(tableLayout);
    final JLabel label =
        new JLabel("<html><b>No CRS found for ESRI Shapefile. Please specify.</b>");
    crsSelectionPanel = new CrsSelectionPanel(productCrsForm, customCrsForm, predefinedCrsForm);
    pageComponent.add(label);
    pageComponent.add(crsSelectionPanel);
    return pageComponent;
  }
 @Override
 public void actionPerformed(ActionEvent e) {
   final SnapFileFilter filter =
       new SnapFileFilter(
           getVectorDataType(), new String[] {".txt", ".dat", ".csv"}, "Plain text");
   importer =
       new VectorDataNodeImporter(
           getHelpId(),
           filter,
           new DefaultVectorDataNodeReader(),
           "Import CSV file",
           "csv.io.dir");
   importer.importGeometry(SnapApp.getDefault());
 }
Example #13
0
    public void run() {
      try {
        // Product product = CommonReaders.readProduct(productFile);
        // SnapApp.getDefault().getProductManager().addProduct(product);

        final org.esa.snap.rcp.actions.file.ProductOpener opener =
            new org.esa.snap.rcp.actions.file.ProductOpener();
        opener.setFiles(new File[] {productFile});
        opener.setMultiSelectionEnabled(true);
        opener.openProduct();
      } catch (Exception e) {
        SnapApp.getDefault().handleError("Not able to open product:\n" + productFile.getPath(), e);
      }
    }
    @Override
    public void run() {
      try {
        Path sourceBasePath = ResourceInstaller.findModuleCodeBasePath(GridBagUtils.class);
        Path auxdataDir = getColorPalettesDir();
        Path sourceDirPath = sourceBasePath.resolve("auxdata/color_palettes");
        final ResourceInstaller resourceInstaller =
            new ResourceInstaller(sourceDirPath, auxdataDir);

        resourceInstaller.install(".*.cpd", ProgressMonitor.NULL);
        defaultColorPalettesInstalled = true;
      } catch (IOException e) {
        SnapApp.getDefault().handleError("Unable to install colour palettes", e);
      }
    }
 @Override
 public AbstractLayerSourceAssistantPage getNextPage() {
   final LayerSourcePageContext context = getContext();
   try {
     final Product product = SnapApp.getDefault().getSelectedProduct();
     final GeoPos referencePos = ProductUtils.getCenterGeoPos(product);
     final CoordinateReferenceSystem crs = crsSelectionPanel.getCrs(referencePos);
     context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, crs);
     return new ShapefileAssistantPage3();
   } catch (FactoryException e) {
     e.printStackTrace();
     context.showErrorDialog("Could not create CRS:\n" + e.getMessage());
   }
   return null;
 }
  static boolean insertImageLayer(LayerSourcePageContext pageContext) {
    AffineTransform transform =
        (AffineTransform) pageContext.getPropertyValue(PROPERTY_NAME_WORLD_TRANSFORM);
    String imageFilePath = (String) pageContext.getPropertyValue(PROPERTY_NAME_IMAGE_FILE_PATH);

    try {
      ProductSceneView sceneView = SnapApp.getDefault().getSelectedProductSceneView();
      final ImageFileLayerType type = LayerTypeRegistry.getLayerType(ImageFileLayerType.class);
      final PropertySet configuration = type.createLayerConfig(sceneView);
      configuration.setValue(ImageFileLayerType.PROPERTY_NAME_IMAGE_FILE, new File(imageFilePath));
      configuration.setValue(ImageFileLayerType.PROPERTY_NAME_WORLD_TRANSFORM, transform);
      Layer layer = type.createLayer(sceneView, configuration);
      layer.setName(FileUtils.getFileNameFromPath(imageFilePath));
      Layer rootLayer = sceneView.getRootLayer();
      rootLayer.getChildren().add(sceneView.getFirstImageLayerIndex(), layer);
      return true;
    } catch (Exception e) {
      pageContext.showErrorDialog(e.getMessage());
      return false;
    }
  }