private void installChildForm() {
    final ColorManipulationChildForm oldForm = childForm;
    ColorManipulationChildForm newForm = emptyForm;
    if (getFormModel().isValid()) {
      if (getFormModel().isContinuous3BandImage()) {
        if (oldForm instanceof Continuous3BandGraphicalForm) {
          newForm = oldForm;
        } else {
          newForm = getContinuous3BandGraphicalForm();
        }
      } else if (getFormModel().isContinuous1BandImage()) {
        if (oldForm instanceof Continuous1BandSwitcherForm) {
          newForm = oldForm;
        } else {
          newForm = getContinuous1BandSwitcherForm();
        }
      } else if (getFormModel().isDiscrete1BandImage()) {
        if (oldForm instanceof Discrete1BandTabularForm) {
          newForm = oldForm;
        } else {
          newForm = getDiscrete1BandTabularForm();
        }
      } else {
        if (oldForm instanceof Continuous1BandSwitcherForm) {
          newForm = oldForm;
        } else {
          newForm = getContinuous1BandSwitcherForm();
        }
      }
    }

    if (newForm != oldForm) {
      childForm = newForm;

      installToolButtons();
      installMoreOptions();

      editorPanel.removeAll();
      editorPanel.add(childForm.getContentPanel(), BorderLayout.CENTER);
      if (!(childForm instanceof EmptyImageInfoForm)) {
        editorPanel.add(moreOptionsPane.getContentPanel(), BorderLayout.SOUTH);
      }
      revalidateToolViewPaneControl();

      if (oldForm != null) {
        oldForm.handleFormHidden(getFormModel());
      }
      childForm.handleFormShown(getFormModel());
    } else {
      childForm.updateFormModel(getFormModel());
    }
  }
 private void importColorPaletteDef() {
   final ImageInfo targetImageInfo = getFormModel().getModifiedImageInfo();
   if (targetImageInfo == null) {
     // Normally this code is unreachable because, the export Button
     // is disabled if the _contrastStretchPane has no ImageInfo.
     return;
   }
   final SnapFileChooser fileChooser = new SnapFileChooser();
   fileChooser.setDialogTitle("Import Colour Palette"); /*I18N*/
   fileChooser.setFileFilter(getOrCreateColorPaletteDefinitionFileFilter());
   fileChooser.setCurrentDirectory(getIODir().toFile());
   final int result = fileChooser.showOpenDialog(getToolViewPaneControl());
   final File file = fileChooser.getSelectedFile();
   if (file != null && file.getParentFile() != null) {
     setIODir(file.getParentFile());
   }
   if (result == JFileChooser.APPROVE_OPTION) {
     if (file != null && file.canRead()) {
       try {
         final ColorPaletteDef colorPaletteDef = ColorPaletteDef.loadColorPaletteDef(file);
         colorPaletteDef.getFirstPoint().setLabel(file.getName());
         applyColorPaletteDef(colorPaletteDef, getFormModel().getRaster(), targetImageInfo);
         getFormModel().setModifiedImageInfo(targetImageInfo);
         childForm.updateFormModel(getFormModel());
         updateMultiApplyState();
       } catch (IOException e) {
         showErrorDialog("Failed to import colour palette:\n" + e.getMessage());
       }
     }
   }
 }
 void installMoreOptions() {
   final MoreOptionsForm moreOptionsForm = childForm.getMoreOptionsForm();
   if (moreOptionsForm != null) {
     moreOptionsForm.updateForm();
     moreOptionsPane.setComponent(moreOptionsForm.getContentPanel());
   }
 }
  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);
  }
 void applyChanges() {
   updateMultiApplyState();
   if (getFormModel().isValid()) {
     try {
       getToolViewPaneControl().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
       if (getFormModel().isContinuous3BandImage()) {
         getFormModel().setRasters(childForm.getRasters());
       } else {
         getFormModel().getRaster().setImageInfo(getFormModel().getModifiedImageInfo());
       }
       getFormModel().applyModifiedImageInfo();
     } finally {
       getToolViewPaneControl().setCursor(Cursor.getDefaultCursor());
     }
   }
   updateMultiApplyState();
 }
  void installToolButtons() {
    toolButtonsPanel.removeAll();
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 1.0;
    gbc.gridy = 0;
    gbc.insets.bottom = 0;
    gbc.gridwidth = 1;
    gbc.gridy++;
    toolButtonsPanel.add(resetButton, gbc);
    toolButtonsPanel.add(multiApplyButton, gbc);
    gbc.gridy++;
    toolButtonsPanel.add(importButton, gbc);
    toolButtonsPanel.add(exportButton, gbc);
    gbc.gridy++;
    AbstractButton[] additionalButtons = childForm.getToolButtons();
    for (int i = 0; i < additionalButtons.length; i++) {
      AbstractButton button = additionalButtons[i];
      toolButtonsPanel.add(button, gbc);
      if (i % 2 == 1) {
        gbc.gridy++;
      }
    }

    gbc.gridy++;
    gbc.fill = GridBagConstraints.VERTICAL;
    gbc.weighty = 1.0;
    gbc.gridwidth = 2;
    toolButtonsPanel.add(new JLabel(" "), gbc); // filler
    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 0.0;
    gbc.gridwidth = 1;
    gbc.gridy++;
    gbc.gridx = 1;
    toolButtonsPanel.add(helpButton, gbc);
  }
 private void resetToDefaults() {
   if (getFormModel().isValid()) {
     getFormModel().setModifiedImageInfo(createDefaultImageInfo());
     childForm.resetFormModel(getFormModel());
   }
 }