private Boolean getAutoDistribute(ColorPaletteDef colorPaletteDef) { if (colorPaletteDef.isAutoDistribute()) { return Boolean.TRUE; } int answer = JOptionPane.showConfirmDialog(getToolViewPaneControl(), "Automatically distribute points of\n" + "colour palette between min/max?", "Import Colour Palette", JOptionPane.YES_NO_CANCEL_OPTION ); if (answer == JOptionPane.YES_OPTION) { return Boolean.TRUE; } else if (answer == JOptionPane.NO_OPTION) { return Boolean.FALSE; } else { return null; } }
public static void applyPaletteToRaster(ColorPaletteDef cpd, RasterDataNode raster) { removeRasterFromMapping(raster); final ImageInfo imageInfo = raster.getImageInfo(); if (imageInfo == null) { return; } final double minSample; final double maxSample; final boolean autoDistribute; final ColorPaletteDef oldDef = imageInfo.getColorPaletteDef(); if (oldDef != null) { minSample = oldDef.getMinDisplaySample(); maxSample = oldDef.getMaxDisplaySample(); autoDistribute = oldDef.isAutoDistribute(); } else { minSample = cpd.getMinDisplaySample(); maxSample = cpd.getMaxDisplaySample(); autoDistribute = cpd.isAutoDistribute(); } imageInfo.setColorPaletteDef(cpd.createDeepCopy(), minSample, maxSample, autoDistribute); appendRasterToMapping(cpd, raster); }
/** * Stores this color palette definition in the given file * * @param colorPaletteDef thje color palette definition * @param file the file * * @throws IOException if an I/O error occurs */ public static void storeColorPaletteDef(ColorPaletteDef colorPaletteDef, File file) throws IOException { final ColorPaletteDef.Point[] points = colorPaletteDef.getPoints(); final PropertyMap propertyMap = new PropertyMap(); final int numPoints = points.length; propertyMap.setPropertyInt(_PROPERTY_KEY_NUM_POINTS, numPoints); propertyMap.setPropertyBool(_PROPERTY_KEY_AUTODISTRIBUTE, colorPaletteDef.isAutoDistribute()); for (int i = 0; i < numPoints; i++) { propertyMap.setPropertyColor(_PROPERTY_KEY_COLOR + i, points[i].getColor()); propertyMap.setPropertyDouble(_PROPERTY_KEY_SAMPLE + i, points[i].getSample()); } propertyMap.store(file, "BEAM Colour Palette Definition File"); /*I18N*/ }
private static void transferPoints(ColorPaletteDef sourceCPD, double minSample, double maxSample, boolean autoDistribute, ColorPaletteDef targetCPD) { if (autoDistribute || sourceCPD.isAutoDistribute()) { alignNumPoints(sourceCPD, targetCPD); double minDisplaySample = sourceCPD.getMinDisplaySample(); double maxDisplaySample = sourceCPD.getMaxDisplaySample(); double delta1 = (maxSample > minSample) ? maxSample - minSample : 1.0; double delta2 = (maxDisplaySample > minDisplaySample) ? maxDisplaySample - minDisplaySample : 1.0; double b = delta1 / delta2; double a = minSample - minDisplaySample * b; for (int i = 0; i < sourceCPD.getNumPoints(); i++) { targetCPD.getPointAt(i).setSample(a + b * sourceCPD.getPointAt(i).getSample()); targetCPD.getPointAt(i).setColor(sourceCPD.getPointAt(i).getColor()); targetCPD.getPointAt(i).setLabel(sourceCPD.getPointAt(i).getLabel()); } } else { targetCPD.setPoints(sourceCPD.getPoints().clone()); } }