private void drawPalette(Graphics2D g2, ColorPaletteDef colorPaletteDef, Dimension paletteDim) { final int width = paletteDim.width; final int height = paletteDim.height; final ColorPaletteDef cpdCopy = colorPaletteDef.createDeepCopy(); cpdCopy.setDiscrete(discreteDisplay); cpdCopy.setNumColors(width); final ImageInfo imageInfo = new ImageInfo(cpdCopy); imageInfo.setLogScaled(log10Display); Color[] colorPalette = ImageManager.createColorPalette(imageInfo); g2.setStroke(new BasicStroke(1.0f)); for (int x = 0; x < width; x++) { g2.setColor(colorPalette[x]); g2.drawLine(x, 0, x, height); } }
public void actionPerformed(ActionEvent e) { if (shouldFireDiscreteEvent) { parentForm.getImageInfo().getColorPaletteDef().setDiscrete(isSelected()); parentForm.applyChanges(); } } });
@Test public void testCreateLinearColorPalette_Discrete() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(100, Color.WHITE), new ColorPaletteDef.Point(200, Color.BLUE), new ColorPaletteDef.Point(300, Color.RED), new ColorPaletteDef.Point(400, Color.GREEN), }, 7); cpd.setDiscrete(true); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(false); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(255, 255, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(0, 0, 255), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(0, 255, 0), palette[6]); }
@Test public void testCreateLog10ColorPalette_Discrete() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(1, Color.WHITE), new ColorPaletteDef.Point(10, Color.BLUE), new ColorPaletteDef.Point(100, Color.RED), new ColorPaletteDef.Point(1000, Color.GREEN), }, 7); cpd.setDiscrete(true); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(true); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(255, 255, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(0, 0, 255), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(255, 0, 0), palette[5]); assertEquals(new Color(0, 255, 0), palette[6]); } }
@Test public void testCreateClone_andEquals() { //preparation final Point[] points = { new Point(1, Color.black), new Point(2, Color.red), new Point(3, Color.green), new Point(4, Color.blue), new Point(5, Color.white), }; final ColorPaletteDef cpd = new ColorPaletteDef(points, 256); cpd.setDiscrete(true); cpd.setAutoDistribute(true); //execution final ColorPaletteDef clone = (ColorPaletteDef) cpd.clone(); //verification assertTrue(cpd.equals(clone)); }
final ColorPaletteDef currentCPD = currentInfo.getColorPaletteDef(); final ColorPaletteDef deepCopy = selectedCPD.createDeepCopy(); deepCopy.setDiscrete(currentCPD.isDiscrete());