public void run() { // Run the animated solution over and over until the status // variable is set to TERMINATED. When this happens, the // delay() method will throw an IllegalArgumentException // and the run() method will be terminated. try { while (true) { tower = null; if (OSC != null) { Graphics g = OSC.getGraphics(); drawCurrentFrame(g); g.dispose(); } repaint(); delay(2000); synchronized (this) { tower = new int[3][10]; for (int i = 0; i < 10; i++) tower[0][i] = 10 - i; towerHeight = new int[3]; towerHeight[0] = 10; if (OSC != null) { Graphics g = OSC.getGraphics(); drawCurrentFrame(g); g.dispose(); } repaint(); delay(2000); } solve(10, 0, 1, 2); delay(4000); } } catch (IllegalArgumentException e) { } }
public void move() { Graphics g = canvas.getGraphics(); g.setColor(canvas.getBackground()); g.fillOval(x, y, XSIZE, YSIZE); x += dx; y += dy; Dimension d = canvas.getSize(); if (x < 0) { x = 0; dx = -dx; } if (x + XSIZE >= d.width) { x = d.width - XSIZE; dx = -dx; } if (y < 0) { y = 0; dy = -dy; } if (y + YSIZE >= d.height) { y = d.height - YSIZE; dy = -dy; } g.setColor(color); g.fillOval(x, y, XSIZE, YSIZE); g.dispose(); }
@SuppressWarnings("deprecation") public final void runOneComponent( Component comp, Rectangle bounds, Graphics g, Shape clip, int weightFlags) { if (comp == null || comp.getPeer() == null || !comp.isVisible()) { return; } boolean lightweight = comp.isLightweight(); if ((lightweight && (weightFlags & LIGHTWEIGHTS) == 0) || (!lightweight && (weightFlags & HEAVYWEIGHTS) == 0)) { return; } if (bounds == null) { bounds = comp.getBounds(); } if (clip == null || clip.intersects(bounds)) { Graphics cg = g.create(); try { constrainGraphics(cg, bounds); cg.setFont(comp.getFont()); cg.setColor(comp.getForeground()); if (cg instanceof Graphics2D) { ((Graphics2D) cg).setBackground(comp.getBackground()); } else if (cg instanceof Graphics2Delegate) { ((Graphics2Delegate) cg).setBackground(comp.getBackground()); } run(comp, cg); } finally { cg.dispose(); } } }
public Image getScreenshot() { BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = image.getGraphics(); paint(g); g.dispose(); return image; }
public static void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g = g.create(x, y, width, height); // corners TL.paintIcon(c, g, x, y); BL.paintIcon(c, g, x, y + height - BL.getIconHeight()); TR.paintIcon(c, g, x + width - TR.getIconWidth(), y); BR.paintIcon(c, g, x + width - BR.getIconWidth(), y + height - BR.getIconHeight()); // top and bottom lines int xOffset = x + TL.getIconWidth(); int stop = x + width - TR.getIconWidth(); int top = y; int bottom = y + height - B.getIconHeight(); g.setClip(xOffset, y, width - L.getIconWidth() - R.getIconWidth(), height); while (xOffset < stop) { T.paintIcon(c, g, xOffset, top); B.paintIcon(c, g, xOffset, bottom); xOffset += T.getIconWidth(); } // left and right lines int left = x; int right = x + width - R.getIconWidth(); int yOffset = y + T.getIconHeight(); stop = y + height - B.getIconHeight(); g.setClip(x, yOffset, width, height - T.getIconHeight() - B.getIconHeight()); while (yOffset < stop) { L.paintIcon(c, g, left, yOffset); R.paintIcon(c, g, right, yOffset); yOffset += L.getIconHeight(); } g.dispose(); }
/** * Converts an image (RGB, RGBA, ... whatever) to a binary one based on given threshold * * @param image the image to convert. Remains untouched. * @param threshold the threshold in [0,255] * @return a new BufferedImage instance of TYPE_BYTE_GRAY with only 0'S and 255's */ private static BufferedImage thresholdImage(Image imgIn, Image imgOut, int threshold) { if (imgOut.getBufferedImage().getType() != BufferedImage.TYPE_BYTE_GRAY) { final BufferedImage result = new BufferedImage(imgIn.getWidth(), imgIn.getHeight(), BufferedImage.TYPE_BYTE_GRAY); final Graphics g = result.getGraphics(); g.drawImage(imgIn.getBufferedImage(), 0, 0, null); g.dispose(); imgOut.setBufferedImage(result); System.err.println("Image was converted into BufferedImage.TYPE_BYTE_GRAY type"); } BufferedImage result = imgOut.getBufferedImage(); result.getGraphics().drawImage(imgIn.getBufferedImage(), 0, 0, null); WritableRaster raster = result.getRaster(); int[] pixels = new int[imgIn.getWidth()]; for (int y = 0; y < imgIn.getHeight(); y++) { raster.getPixels(0, y, imgIn.getWidth(), 1, pixels); for (int i = 0; i < pixels.length; i++) { pixels[i] = (pixels[i] < threshold) ? 0 : 255; } raster.setPixels(0, y, imgIn.getWidth(), 1, pixels); } return result; }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (drawOverlay) { g = g.create(); AntialiasingManager.activateAntialiasing(g); try { // Paint a roll over fade out. FadeTracker fadeTracker = FadeTracker.getInstance(); float visibility = 0.0f; if (fadeTracker.isTracked(this, FadeKind.ROLLOVER)) { visibility = fadeTracker.getFade(this, FadeKind.ROLLOVER); visibility /= 4; } else visibility = 0.5f; // Draw black overlay g.setColor(new Color(0.0f, 0.0f, 0.0f, visibility)); g.fillRoundRect(1, 1, width - 2, height - 2, 10, 10); // Draw arrow g.setColor(Color.WHITE); int[] arrowX = new int[] {width - 17, width - 7, width - 12}; int[] arrowY = new int[] {height - 12, height - 12, height - 7}; g.fillPolygon(arrowX, arrowY, arrowX.length); } finally { g.dispose(); } } }
/** Overrides <code>Graphics.drawChars</code>. */ public void drawChars(char data[], int offset, int length, int x, int y) { DebugGraphicsInfo info = info(); Font font = graphics.getFont(); if (debugLog()) { info().log(toShortString() + " Drawing chars at " + new Point(x, y)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawChars(data, offset, length, x, y); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.drawChars(data, offset, length, x, y); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.drawChars(data, offset, length, x, y); }
/** Overrides <code>Graphics.fill3DRect</code>. */ public void fill3DRect(int x, int y, int width, int height, boolean raised) { DebugGraphicsInfo info = info(); if (debugLog()) { info() .log( toShortString() + " Filling 3D rect: " + new Rectangle(x, y, width, height) + " Raised bezel: " + raised); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.fill3DRect(x, y, width, height, raised); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.fill3DRect(x, y, width, height, raised); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.fill3DRect(x, y, width, height, raised); }
/** Overrides <code>Graphics.fillArc</code>. */ public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { DebugGraphicsInfo info = info(); if (debugLog()) { info() .log( toShortString() + " Filling arc: " + new Rectangle(x, y, width, height) + " startAngle: " + startAngle + " arcAngle: " + arcAngle); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.fillArc(x, y, width, height, startAngle, arcAngle); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.fillArc(x, y, width, height, startAngle, arcAngle); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.fillArc(x, y, width, height, startAngle, arcAngle); }
/** * Calls <code>setBoundsForFrame</code> with the new values. * * @param f the component to be resized * @param newX the new x-coordinate * @param newY the new y-coordinate * @param newWidth the new width * @param newHeight the new height */ public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) { if (dragMode == DEFAULT_DRAG_MODE || dragMode == FASTER_DRAG_MODE) { setBoundsForFrame(f, newX, newY, newWidth, newHeight); } else { JDesktopPane desktopPane = getDesktopPane(f); if (desktopPane != null) { Graphics g = JComponent.safelyGetGraphics(desktopPane); g.setXORMode(Color.white); if (currentBounds != null) { g.drawRect( currentBounds.x, currentBounds.y, currentBounds.width - 1, currentBounds.height - 1); } g.drawRect(newX, newY, newWidth - 1, newHeight - 1); // Work around for 6635462, see comment in dragFrame() sun.java2d.SurfaceData sData = ((sun.java2d.SunGraphics2D) g).getSurfaceData(); if (!sData.isSurfaceLost()) { currentBounds = new Rectangle(newX, newY, newWidth, newHeight); } g.setPaintMode(); g.dispose(); } } }
/** Overrides <code>Graphics.drawOval</code>. */ public void drawOval(int x, int y, int width, int height) { DebugGraphicsInfo info = info(); if (debugLog()) { info().log(toShortString() + " Drawing oval: " + new Rectangle(x, y, width, height)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawOval(x, y, width, height); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.drawOval(x, y, width, height); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.drawOval(x, y, width, height); }
/** * Moves the visible location of the frame being dragged to the location specified. The means by * which this occurs can vary depending on the dragging algorithm being used. The actual logical * location of the frame might not change until <code>endDraggingFrame</code> is called. */ public void dragFrame(JComponent f, int newX, int newY) { if (dragMode == OUTLINE_DRAG_MODE) { JDesktopPane desktopPane = getDesktopPane(f); if (desktopPane != null) { Graphics g = JComponent.safelyGetGraphics(desktopPane); g.setXORMode(Color.white); if (currentLoc != null) { g.drawRect(currentLoc.x, currentLoc.y, f.getWidth() - 1, f.getHeight() - 1); } g.drawRect(newX, newY, f.getWidth() - 1, f.getHeight() - 1); /* Work around for 6635462: XOR mode may cause a SurfaceLost on first use. * Swing doesn't expect that its XOR drawRect did * not complete, so believes that on re-entering at * the next update location, that there is an XOR rect * to draw out at "currentLoc". But in fact * it's now got a new clean surface without that rect, * so drawing it "out" in fact draws it on, leaving garbage. * So only update/set currentLoc if the draw completed. */ sun.java2d.SurfaceData sData = ((sun.java2d.SunGraphics2D) g).getSurfaceData(); if (!sData.isSurfaceLost()) { currentLoc = new Point(newX, newY); } g.dispose(); } } else if (dragMode == FASTER_DRAG_MODE) { dragFrameFaster(f, newX, newY); } else { setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight()); } }
public void clear() { Graphics g = this.image.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, this.image.getWidth(null), this.image.getHeight(null)); g.dispose(); repaint(); }
/** Overrides <code>Graphics.drawLine</code>. */ public void drawLine(int x1, int y1, int x2, int y2) { DebugGraphicsInfo info = info(); if (debugLog()) { info() .log( toShortString() + " Drawing line: from " + pointToString(x1, y1) + " to " + pointToString(x2, y2)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawLine(x1, y1, x2, y2); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.drawLine(x1, y1, x2, y2); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.drawLine(x1, y1, x2, y2); }
/** Overrides <code>Graphics.drawString</code>. */ public void drawString(AttributedCharacterIterator iterator, int x, int y) { DebugGraphicsInfo info = info(); if (debugLog()) { info().log(toShortString() + " Drawing text: \"" + iterator + "\" at: " + new Point(x, y)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawString(iterator, x, y); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.drawString(iterator, x, y); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.drawString(iterator, x, y); }
/** Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int x, int y, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, observer); }
protected void computeGeometry() { pictHalfWidth = Width.getInt() / 2; pictWidth = pictHalfWidth + pictHalfWidth - 1; pictHeight = Height.getInt(); xLoc = -pictHalfWidth; yLoc = -pictHeight / 2; setFramesPerCycle(pictWidth - 1); setFrameIncrement(FrameIncrement.getInt()); // System.out.println("width = " + pictWidth); // System.out.println(" x = " + xLoc); // System.out.println(" y = " + yLoc); PxlColor[] ramp = AColor.getPxlColor().sinusoidalRampTo(BColor.getPxlColor(), pictHalfWidth); // System.out.println("w=" + (4*pictHalfWidth-1) + ", h=" + pictHeight); int ibWidth = 4 * pictHalfWidth - 1; if ((imageBuffer == null) || (imageBuffer.getWidth() != ibWidth) || (imageBuffer.getHeight() != pictHeight)) { imageBuffer = new BufferedImage(ibWidth, pictHeight, BufferedImage.TYPE_INT_RGB); } Graphics g = imageBuffer.getGraphics(); for (int x = 0; x < pictHalfWidth; x++) { g.setColor(ramp[x].dev()); g.drawLine(x, 0, x, pictHeight - 1); if (x < (pictHalfWidth - 1)) g.drawLine(pictWidth - x - 1, 0, pictWidth - x - 1, pictHeight - 1); if (x > 0) g.drawLine(pictWidth + x - 1, 0, pictWidth + x - 1, pictHeight - 1); if ((x > 0) && (x < (pictHalfWidth - 1))) g.drawLine(4 * pictHalfWidth - 4 - x, 0, 4 * pictHalfWidth - 4 - x, pictHeight - 1); } g.dispose(); BitMapElement p = (BitMapElement) getDisplayElement(pictElement); p.setImage(imageBuffer); p.setLocation(xLoc, yLoc); p.setClipRect(xLoc, yLoc, pictWidth, pictHeight); }
public void collect() { for (int i = 0; i < variable_list.size(); i++) { ((NslVariable) variable_list.elementAt(i)).collect(); } Graphics gr = getGraphics(); paint_partial(gr); gr.dispose(); }
/** This internal method begins a new line */ protected void newline() { charnum = 0; // Reset character number to 0 linenum++; // Increment line number if (linenum >= lines_per_page) { // If we've reached the end of the page page.dispose(); // send page to printer page = null; // but don't start a new page yet. } }
public static BufferedImage copyImage(BufferedImage source, int type) { BufferedImage copy = new BufferedImage(source.getWidth(), source.getHeight(), type); Graphics gfx = copy.getGraphics(); gfx.drawImage(source, 0, 0, null); gfx.dispose(); return copy; }
public static BufferedImage imageToBufferedImage(Image im) { BufferedImage bi = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics bg = bi.getGraphics(); bg.drawImage(im, 0, 0, null); bg.dispose(); return bi; }
public static BufferedImage copyImage(BufferedImage source) { BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_BYTE_GRAY); Graphics g = b.getGraphics(); g.drawImage(source, 0, 0, null); g.dispose(); return b; }
private void scaleImage() { Image img = back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH); back = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = back.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); }
/** This method creates the off-screen canvas and fills it with the current fill color. */ private void createOSC() { OSC = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); Graphics osg = OSC.getGraphics(); Color fillColor = new Color(0, 0, 0); fillColor = Color.WHITE; osg.setColor(fillColor); osg.fillRect(0, 0, getWidth(), getHeight()); osg.dispose(); }
public void repaint() { text = tf.getText(); Graphics g = getGraphics(); if (g != null) { recalcPositions(g); g.dispose(); } super.repaint(); }
/** * Paint a background for all groups and a round blue border and background when a cell is * selected. * * @param g the <tt>Graphics</tt> object */ public void paintComponent(Graphics g) { Graphics g2 = g.create(); try { internalPaintComponent(g2); } finally { g2.dispose(); } super.paintComponent(g); }
private void drawLine(JComponent c, int x, int y) { _xedit = x; _yedit = y; Graphics g = c.getGraphics(); g.setColor(Color.BLACK); g.setXORMode(c.getBackground()); g.drawLine(_xdown, _ydown, _xedit, _yedit); g.dispose(); }
private void replaceSurfaceData( int newBackBufferCount, BufferCapabilities newBackBufferCaps, boolean blit) { synchronized (surfaceDataLock) { final SurfaceData oldData = getSurfaceData(); surfaceData = platformWindow.replaceSurfaceData(); // TODO: volatile image // VolatileImage oldBB = backBuffer; BufferedImage oldBB = backBuffer; backBufferCount = newBackBufferCount; backBufferCaps = newBackBufferCaps; final Rectangle size = getSize(); if (getSurfaceData() != null && oldData != getSurfaceData()) { clearBackground(size.width, size.height); } if (blit) { blitSurfaceData(oldData, getSurfaceData()); } if (oldData != null && oldData != getSurfaceData()) { // TODO: drop oldData for D3D/WGL pipelines // This can only happen when this peer is being created oldData.flush(); } // TODO: volatile image // backBuffer = (VolatileImage)delegate.createBackBuffer(); backBuffer = (BufferedImage) platformWindow.createBackBuffer(); if (backBuffer != null) { Graphics g = backBuffer.getGraphics(); try { Rectangle r = getBounds(); if (g instanceof Graphics2D) { ((Graphics2D) g).setComposite(AlphaComposite.Src); } g.setColor(nonOpaqueBackground); g.fillRect(0, 0, r.width, r.height); if (g instanceof SunGraphics2D) { ((SunGraphics2D) g).constrain(0, 0, r.width, r.height, getRegion()); } if (!isTextured()) { g.setColor(getBackground()); g.fillRect(0, 0, r.width, r.height); } if (oldBB != null) { // Draw the old back buffer to the new one g.drawImage(oldBB, 0, 0, null); oldBB.flush(); } } finally { g.dispose(); } } } flushOnscreenGraphics(); }
public void paint(Graphics g) { putClientProperty("JTree.lineStyle", "None"); Graphics g1 = g.create(); g1.translate(0, -myVisibleRow * getRowHeight()); super.paint(g1); g1.dispose(); if (myBorder != null) { myBorder.paintBorder(this, g, 0, 0, myTreeTable.getWidth(), getRowHeight()); } }