private void fillRectangle(int x, int y, int width, int height, int symbolType) { if (!Preferences.monochrome) { setFillColor(symbolType); gRef.fillRect(x, y, width, height); restoreColor(); } }
public void paint(Graphics g) { gRef = (Graphics2D) g; // change size of font gRef.setFont(gRef.getFont().deriveFont(9.0f)); fmRef = g.getFontMetrics(); // Clear background if (Preferences.monochrome) { gRef.setColor(Preferences.whiteColor); } else { gRef.setColor(Preferences.backgroundColor); } gRef.fillRect(0, 0, getWidth(), getHeight()); // set colour to correct drawing colour if (Preferences.monochrome) { gRef.setColor(Preferences.blackColor); } else { gRef.setColor(Preferences.penColor); } gRef.translate(0, margin); // Call c code to draw tree gRef.scale(scale, scale); nativeDrawTree(); }
public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setStroke(new BasicStroke(1.0f)); if (isOpaque()) { g2d.setColor(getBackground()); g2d.fillRect(0, 0, getWidth(), getHeight()); } g2d.setColor(Color.black); g2d.drawLine(0, frameHeight / 2, frameWidth, frameHeight / 2); g2d.drawLine(frameWidth / 2, 0, frameWidth / 2, frameHeight); for (int i = unityX; i < frameWidth / 2; i += unityX) { g2d.drawLine( frameWidth / 2 + i, frameHeight / 2 - 3, frameWidth / 2 + i, frameHeight / 2 + 3); g2d.drawLine( frameWidth / 2 - i, frameHeight / 2 - 3, frameWidth / 2 - i, frameHeight / 2 + 3); } for (int i = unityY; i < frameHeight / 2; i += unityY) { g2d.drawLine( frameWidth / 2 - 3, frameHeight / 2 + i, frameWidth / 2 + 3, frameHeight / 2 + i); g2d.drawLine( frameWidth / 2 - 3, frameHeight / 2 - i, frameWidth / 2 + 3, frameHeight / 2 - i); } g2d.setColor(Color.blue); function.drawFunctionToGraphic(g2d, frameWidth, frameHeight, unityX, unityY); paintCurrentMethodState(g2d); g2d.dispose(); }
// initialize default image private BufferedImage getDefaultImage(int w, int h) { BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = defaultImage.createGraphics(); graphics2D.setColor(new Color(200, 200, 200)); graphics2D.fillRect(0, 0, w, h); graphics2D.setColor(new Color(130, 130, 130)); graphics2D.drawRect(0, 0, w - 1, h - 1); return defaultImage; }
private static int[] makeGradientPallet() { BufferedImage image = new BufferedImage(100, 1, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); Point2D start = new Point2D.Float(0f, 0f); Point2D end = new Point2D.Float(99f, 0f); float[] dist = {0f, .5f, 1f}; Color[] colors = {Color.RED, Color.YELLOW, Color.GREEN}; g2.setPaint(new LinearGradientPaint(start, end, dist, colors)); g2.fillRect(0, 0, 100, 1); g2.dispose(); int width = image.getWidth(null); int[] pallet = new int[width]; PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width); try { pg.grabPixels(); } catch (InterruptedException ex) { ex.printStackTrace(); } return pallet; }
/** Get an image based on index numbers */ public BufferedImage getIndexedImage( int x, int y, int zoom, int cacheZoom, GMapListener listener) { if (listener != null) { if (!getGDataSource().isCached(x, y, zoom)) { listener.updateGMapPainting(); listener.updateGMapMessage(GMap.MESSAGE_DOWNLOADING); } else { listener.updateGMapMessage(GMap.MESSAGE_PAINTING); } } BufferedImage thumbImage = getGDataSource().getImage(x, y, zoom, true); if (thumbImage == null) return defaultImage; // if we dont have to paint cache, return here if (cacheZoom == (GPhysicalPoint.MIN_ZOOM - 1) || cacheZoom >= zoom) return thumbImage; BufferedImage paintedImage = new BufferedImage( GDataSource.sourceSize.width, GDataSource.sourceSize.height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = paintedImage.createGraphics(); graphics2D.drawImage( thumbImage, 0, 0, GDataSource.sourceSize.width, GDataSource.sourceSize.height, null); // now lets move to painting the cache double imageNum = Math.pow(2, zoom - cacheZoom); // draw cache lines int startX = (int) (imageNum * x); int startY = (int) (imageNum * y); // get composite to restore later, set new transparent composite Composite originalComposite = graphics2D.getComposite(); graphics2D.setComposite(opacity40); // draw grid for (int i = 0; i < imageNum; i++) { for (int j = 0; j < imageNum; j++) { // points Point upperLeft = new Point( (int) (GDataSource.sourceSize.width / imageNum) * i, (int) (GDataSource.sourceSize.height / imageNum) * j); Dimension size = new Dimension( (int) (GDataSource.sourceSize.width / imageNum), (int) (GDataSource.sourceSize.height / imageNum)); // draw lines graphics2D.setColor(new Color(100, 100, 100)); graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x + size.width, upperLeft.y); graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x, upperLeft.y + size.height); // check if file exists if (getGDataSource().isCached(startX + i, startY + j, cacheZoom)) graphics2D.setColor(Color.RED); else graphics2D.setColor(new Color(155, 155, 155)); // shade rectangle graphics2D.fillRect(upperLeft.x, upperLeft.y, size.width, size.height); } } // restore composite graphics2D.setComposite(originalComposite); return paintedImage; }
private BufferedImage getSpecificImage( int x, int y, int w, int h, int imgIndexX, int imgIndexY, BufferedImage buffImg, int zoom, int cachedZoom, GMapListener listener, boolean localFilesOnly) { int xIndex = x / GDataSource.sourceSize.width; int yIndex = y / GDataSource.sourceSize.height; xIndex += imgIndexX; yIndex += imgIndexY; BufferedImage image = null; if (!localFilesOnly || getGDataSource().isCached(xIndex, yIndex, zoom)) image = getIndexedImage(xIndex, yIndex, zoom, cachedZoom, listener); int xCoord = x % GDataSource.sourceSize.width; int yCoord = y % GDataSource.sourceSize.height; // Checks for invalid xCoord and yCoord if (xCoord < 0) { xCoord = 0; } if (yCoord < 0) { yCoord = 0; } // get info about the image Dimension imageSize = new Dimension(getGDataSource().sourceSize.width, getGDataSource().sourceSize.height); // find the width of what we CAN paint int initPaintWidth = imageSize.width - xCoord; int initPaintHeight = imageSize.height - yCoord; int paintWidth = initPaintWidth; int paintHeight = initPaintHeight; int rowImages = numOfRows(x, y, h, zoom, cachedZoom); int colImages = numOfCols(x, y, w, zoom, cachedZoom); if (imgIndexX >= colImages || imgIndexY >= rowImages) { return null; } int xImage = 0; int yImage = 0; int xInitCoord = xCoord; int yInitCoord = yCoord; if (imgIndexX > 0) { xImage = initPaintWidth + (imgIndexX - 1) * imageSize.width; xCoord = 0; if (imgIndexX < (colImages - 1)) { paintWidth = imageSize.width; } else { paintWidth = w - ((colImages - 2) * imageSize.width) - (imageSize.width - xInitCoord); } } if (imgIndexY > 0) { yImage = initPaintHeight + (imgIndexY - 1) * imageSize.height; yCoord = 0; if (imgIndexY < (rowImages - 1)) { paintHeight = imageSize.height; } else { paintHeight = h - ((rowImages - 2) * imageSize.height) - (imageSize.height - yInitCoord); } } if (buffImg != null) { Graphics2D g = (Graphics2D) buffImg.getGraphics(); if (image != null) { // System.out.println(xCoord + ":" + yCoord + ":" + paintWidth + ":" + paintHeight); g.drawImage( image.getSubimage(xCoord, yCoord, paintWidth, paintHeight), xImage, yImage, paintWidth, paintHeight, null); } else { Composite originalComposite = g.getComposite(); g.setComposite(opacity40); g.setColor(Color.BLACK); g.fillRect(xImage, yImage, paintWidth, paintHeight); g.setComposite(originalComposite); } } return buffImg; }