@Override protected void paintComponent(Graphics graphics) { // Fill in the background: Graphics2D g = (Graphics2D) graphics; Shape clip = g.getClip(); g.setColor(LightZoneSkin.Colors.NeutralGray); g.fill(clip); if (preview == null) { PlanarImage image = currentImage.get(); if (image == null) { engine.update(null, false); } else if (visibleRect != null && getHeight() > 1 && getWidth() > 1) { preview = cropScaleGrayscale(visibleRect, image); } } if (preview != null) { int dx, dy; AffineTransform transform = new AffineTransform(); if (getSize().width > preview.getWidth()) dx = (getSize().width - preview.getWidth()) / 2; else dx = 0; if (getSize().height > preview.getHeight()) dy = (getSize().height - preview.getHeight()) / 2; else dy = 0; transform.setToTranslation(dx, dy); try { g.drawRenderedImage(preview, transform); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void addNotify() { // This method gets called when this Preview is added. engine.update(null, false); super.addNotify(); }
protected synchronized void paintComponent(Graphics gr) { Graphics2D g2d = (Graphics2D) gr; if (bins == null) engine.update(null, false); Dimension bounds = getSize(); final float minx = 0; final float miny = 0; final float width = bounds.width; final float height = bounds.height - 18; g2d.setColor(Color.lightGray); g2d.fill(new Rectangle2D.Float(minx, miny, width, height + 18)); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (bins != null) { final int max = binmax(); class scaler { int yscale(double y) { return (int) (height - (height - 4) * (y / (double) max) + 0.5 + miny); } } scaler s = new scaler(); for (int c = 0; c < bins.length; c++) { Color color = Color.BLACK; if (bins.length > 1) switch (c) { case 0: color = Color.RED; break; case 1: color = Color.GREEN; break; case 2: color = Color.BLUE; break; } g2d.setColor(color); int numBins = bins[c].length; int zeroY = s.yscale(0); float xstep = (width + 1) / numBins; GeneralPath gp = new GeneralPath(); gp.moveTo(minx, zeroY); float lastx = minx; float lasty = zeroY; for (int i = 0; i < numBins; i++) { int y = s.yscale(bins[c][i]); float x = xstep * i + minx; if (lasty != zeroY || y != zeroY) { gp.lineTo(x, y); lastx = x; lasty = y; } } if (lasty != zeroY) gp.lineTo(lastx, zeroY); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f)); g2d.fill(gp); g2d.setComposite(AlphaComposite.SrcOver); g2d.draw(gp); } } float step = width / 16.0f; for (int i = 0; i < 16; i++) { if (i == currentFocusZone) g2d.setColor(Color.yellow); else { float color = (float) ((Math.pow(2, i * 8.0 / (16 - 1)) - 1) / 255.); float[] srgbColor = Functions.fromLinearToCS( JAIContext.systemColorSpace, new float[] {color, color, color}); g2d.setColor( new Color( (int) (255 * srgbColor[0]), (int) (255 * srgbColor[1]), (int) (255 * srgbColor[2]))); } g2d.fill(new Rectangle2D.Float(minx + step * i, height + miny, step + 0.5f, 18)); } }