/** * Draw labels for picking. * * @param dc Current draw context. * @param pickSupport the PickSupport instance to be used. */ protected void doPick(DrawContext dc, PickSupport pickSupport) { GL gl = dc.getGL(); Angle heading = this.rotation; double headingDegrees; if (heading != null) headingDegrees = heading.degrees; else headingDegrees = 0; int x = this.screenPoint.x; int y = this.screenPoint.y; boolean matrixPushed = false; try { if (headingDegrees != 0) { gl.glPushMatrix(); matrixPushed = true; gl.glTranslated(x, y, 0); gl.glRotated(headingDegrees, 0, 0, 1); gl.glTranslated(-x, -y, 0); } for (int i = 0; i < this.lines.length; i++) { Rectangle2D bounds = this.lineBounds[i]; double width = bounds.getWidth(); double height = bounds.getHeight(); x = this.screenPoint.x; if (this.textAlign.equals(AVKey.CENTER)) x = x - (int) (width / 2.0); else if (this.textAlign.equals(AVKey.RIGHT)) x = x - (int) width; y -= this.lineHeight; Color color = dc.getUniquePickColor(); int colorCode = color.getRGB(); PickedObject po = new PickedObject(colorCode, this.getPickedObject(), this.position, false); pickSupport.addPickableObject(po); // Draw line rectangle gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()); try { gl.glBegin(GL.GL_POLYGON); gl.glVertex3d(x, y, 0); gl.glVertex3d(x + width - 1, y, 0); gl.glVertex3d(x + width - 1, y + height - 1, 0); gl.glVertex3d(x, y + height - 1, 0); gl.glVertex3d(x, y, 0); } finally { gl.glEnd(); } y -= this.lineSpacing; } } finally { if (matrixPushed) { gl.glPopMatrix(); } } }
public static void main(String[] args) { int x = 500, y = 80; DrawingKit dk = new DrawingKit("Daffodils", 800, 800); BufferedImage pict = dk.loadPicture("daffodils.jpg"); // get pixel value at location (500, 80) int encodedPixelColor = pict.getRGB(x, y); Color pixelColor = new Color(encodedPixelColor); System.out.println(pixelColor); int red = pixelColor.getRed(); int green = pixelColor.getGreen(); int blue = pixelColor.getBlue(); // change the color of the pixel to be pure red red = 255; green = 0; blue = 0; // update the pixel color in picture Color newPixelColor = new Color(red, green, blue); int newRgbvalue = newPixelColor.getRGB(); pict.setRGB(x, y, newRgbvalue); // display the approximate location of the pixel dk.drawPicture(pict, 0, 0); BasicStroke s = new BasicStroke(3); dk.setStroke(s); Ellipse2D.Float e = new Ellipse2D.Float(x - 3, y - 3, 8, 8); dk.draw(e); dk.drawString("(600, 150)", x - 3, y - 5); }
@Override public int getColor(VisualItem item) { // get value for target attr in item if (item.canGetString(colorAttrName)) { String attrVal = item.getString(colorAttrName); Color attrValColor = catToColorMap.get(attrVal); if (attrValColor == null) { return Color.CYAN.getRGB(); } return attrValColor.getRGB(); } Color white = Color.WHITE; return white.getRGB(); }
public void run(ImageProcessor ip) { if (enlarge && gd.wasOKed()) synchronized (this) { if (!isEnlarged) { enlargeCanvas(); isEnlarged = true; } } if (isEnlarged) { // enlarging may have made the ImageProcessor invalid, also for the parallel // threads int slice = pfr.getSliceNumber(); if (imp.getStackSize() == 1) ip = imp.getProcessor(); else ip = imp.getStack().getProcessor(slice); } ip.setInterpolationMethod(interpolationMethod); if (fillWithBackground) { Color bgc = Toolbar.getBackgroundColor(); if (bitDepth == 8) ip.setBackgroundValue(ip.getBestIndex(bgc)); else if (bitDepth == 24) ip.setBackgroundValue(bgc.getRGB()); } else ip.setBackgroundValue(0); ip.rotate(angle); if (!gd.wasOKed()) drawGridLines(gridLines); if (isEnlarged && imp.getStackSize() == 1) { imp.changes = true; imp.updateAndDraw(); Undo.setup(Undo.COMPOUND_FILTER_DONE, imp); } }
/** * WhiteboardShapeLine constructor. * * @param id String that uniquely identifies this WhiteboardObject. * @param t number of pixels that this object (or its border) should be thick. * @param c WhiteboardShapeLine's color (or rather it's border) * @param startPoint the start coordinates of this line. * @param endPoint the end coordinates of this line. */ public WhiteboardShapeLine( String id, int t, Color c, WhiteboardPoint startPoint, WhiteboardPoint endPoint) { super(id); this.setThickness(t); setColor(c); setColor(c.getRGB()); this.endPoint = endPoint; this.startPoint = startPoint; }
/** * Gets the stroke paint for the specified figure based on the attributes STROKE_GRADIENT, * STROKE_OPACITY, STROKE_PAINT and the bounds of the figure. Returns null if the figure is not * filled. */ public static Paint getStrokePaint(Figure f) { double opacity = STROKE_OPACITY.get(f); if (STROKE_GRADIENT.get(f) != null) { return STROKE_GRADIENT.get(f).getPaint(f, opacity); } Color color = STROKE_COLOR.get(f); if (color != null) { if (opacity != 1) { color = new Color((color.getRGB() & 0xffffff) | (int) (opacity * 255) << 24, true); } } return color; }
/** Returns the color used for "Show All" mode. */ public static Color getShowAllColor() { if (showAllColor != null && showAllColor.getRGB() == 0xff80ffff) showAllColor = Color.cyan; return showAllColor; }
// Rendering public void draw(DrawContext dc) { GL gl = dc.getGL(); boolean attribsPushed = false; boolean modelviewPushed = false; boolean projectionPushed = false; try { gl.glPushAttrib( GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_TEXTURE_BIT | GL.GL_TRANSFORM_BIT | GL.GL_VIEWPORT_BIT | GL.GL_CURRENT_BIT); attribsPushed = true; gl.glDisable(GL.GL_TEXTURE_2D); // no textures gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glDisable(GL.GL_DEPTH_TEST); double width = this.size.width; double height = this.size.height; // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight) // into the GL projection matrix. java.awt.Rectangle viewport = dc.getView().getViewport(); gl.glMatrixMode(javax.media.opengl.GL.GL_PROJECTION); gl.glPushMatrix(); projectionPushed = true; gl.glLoadIdentity(); double maxwh = width > height ? width : height; gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); modelviewPushed = true; gl.glLoadIdentity(); // Scale to a width x height space // located at the proper position on screen double scale = this.computeScale(viewport); Vec4 locationSW = this.computeLocation(viewport, scale); gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z()); gl.glScaled(scale, scale, 1); // Compute scale size in real world Position referencePosition = dc.getViewportCenterPosition(); if (referencePosition != null) { Vec4 groundTarget = dc.getGlobe().computePointFromPosition(referencePosition); Double distance = dc.getView().getEyePoint().distanceTo3(groundTarget); this.pixelSize = dc.getView().computePixelSizeAtDistance(distance); Double scaleSize = this.pixelSize * width * scale; // meter String unitLabel = "m"; if (this.unit.equals(UNIT_METRIC)) { if (scaleSize > 10000) { scaleSize /= 1000; unitLabel = "Km"; } } else if (this.unit.equals(UNIT_IMPERIAL)) { scaleSize *= 3.280839895; // feet unitLabel = "ft"; if (scaleSize > 5280) { scaleSize /= 5280; unitLabel = "mile(s)"; } } // Rounded division size int pot = (int) Math.floor(Math.log10(scaleSize)); if (!Double.isNaN(pot)) { int digit = Integer.parseInt(String.format("%.0f", scaleSize).substring(0, 1)); double divSize = digit * Math.pow(10, pot); if (digit >= 5) divSize = 5 * Math.pow(10, pot); else if (digit >= 2) divSize = 2 * Math.pow(10, pot); double divWidth = width * divSize / scaleSize; // Draw scale if (!dc.isPickingMode()) { // Set color using current layer opacity Color backColor = this.getBackgroundColor(this.color); float[] colorRGB = backColor.getRGBColorComponents(null); gl.glColor4d( colorRGB[0], colorRGB[1], colorRGB[2], (double) backColor.getAlpha() / 255d * this.getOpacity()); gl.glTranslated((width - divWidth) / 2, 0d, 0d); this.drawScale(dc, divWidth, height); colorRGB = this.color.getRGBColorComponents(null); gl.glColor4d(colorRGB[0], colorRGB[1], colorRGB[2], this.getOpacity()); gl.glTranslated(-1d / scale, 1d / scale, 0d); this.drawScale(dc, divWidth, height); // Draw label String label = String.format("%.0f ", divSize) + unitLabel; gl.glLoadIdentity(); gl.glDisable(GL.GL_CULL_FACE); drawLabel( dc, label, locationSW.add3( new Vec4(divWidth * scale / 2 + (width - divWidth) / 2, height * scale, 0))); } else { // Picking this.pickSupport.clearPickList(); this.pickSupport.beginPicking(dc); // Draw unique color across the map Color color = dc.getUniquePickColor(); int colorCode = color.getRGB(); // Add our object(s) to the pickable list this.pickSupport.addPickableObject(colorCode, this, referencePosition, false); gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()); gl.glTranslated((width - divWidth) / 2, 0d, 0d); this.drawRectangle(dc, divWidth, height); // Done picking this.pickSupport.endPicking(dc); this.pickSupport.resolvePick(dc, dc.getPickPoint(), this); } } } } finally { if (projectionPushed) { gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); } if (modelviewPushed) { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); } if (attribsPushed) gl.glPopAttrib(); } }