private void exportColorPaletteDef() {
   final ImageInfo imageInfo = getFormModel().getModifiedImageInfo();
   if (imageInfo == null) {
     // Normally this code is unreachable because, the export Button should be
     // disabled if the color manipulation form has no ImageInfo.
     return;
   }
   final SnapFileChooser fileChooser = new SnapFileChooser();
   fileChooser.setDialogTitle("Export Colour Palette"); /*I18N*/
   fileChooser.setFileFilter(getOrCreateColorPaletteDefinitionFileFilter());
   fileChooser.setCurrentDirectory(getIODir().toFile());
   final int result = fileChooser.showSaveDialog(getToolViewPaneControl());
   File file = fileChooser.getSelectedFile();
   if (file != null && file.getParentFile() != null) {
     setIODir(file.getParentFile());
   }
   if (result == JFileChooser.APPROVE_OPTION) {
     if (file != null) {
       if (Boolean.TRUE.equals(SnapDialogs.requestOverwriteDecision(titlePrefix, file))) {
         file = FileUtils.ensureExtension(file, FILE_EXTENSION);
         try {
           final ColorPaletteDef colorPaletteDef = imageInfo.getColorPaletteDef();
           ColorPaletteDef.storeColorPaletteDef(colorPaletteDef, file);
         } catch (IOException e) {
           showErrorDialog("Failed to export colour palette:\n" + e.getMessage()); /*I18N*/
         }
       }
     }
   }
 }
 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());
       }
     }
   }
 }