@Override public BufferedImage makeIcon( final int width, final int height, final Path2D iconShape, final boolean allowAlpha) { final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = result.createGraphics(); g.setStroke(new BasicStroke(0.05f)); final Color c; if (allowAlpha) { c = new Color( this.color.getRed(), this.color.getGreen(), this.color.getBlue(), this.color.getAlpha()); } else { c = new Color(this.color.getRGB()); } if (iconShape != null) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setColor(c); final Shape path = makeTransformedPathForSize(width, height, iconShape); g.fill(path); } else { g.setColor(c); g.fillRect(0, 0, width, height); } g.dispose(); return result; }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.white); g2.fillRect(0, 0, getWidth(), getHeight()); AffineTransform at = new AffineTransform(0.5, 0, 0, -0.5, 30, getHeight() * 3 / 4); g2.transform(at); g2.setColor(Color.black); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // System.out.println("Showing="+showing); if (showing != null) { showing.draw(g2); } }
@Override public void prerasterizeIcon(final Shape shape) { final Rectangle r = shape.getBounds(); final BufferedImage prerasterized = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = prerasterized.createGraphics(); g.setStroke(new BasicStroke(0.05f)); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setColor(this.color); g.fill(shape); g.dispose(); this.prerasterizedImage = prerasterized; }
/** paint the canvas into a image file of given width and height */ public void writeToImage(String s, int w, int h) { String ext; File f; try { ext = s.substring(s.lastIndexOf(".") + 1); f = new File(s); } catch (Exception e) { System.out.println(e); return; } if (!ext.equals("jpg") && !ext.equals("png")) { System.out.println("Cannot write to file: Illegal extension " + ext); return; } boolean opq = true; if (theOpaque != null) opq = theOpaque; BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setBackground(Color.white); g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1)); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); doBuffer(g2, true, new Rectangle(0, 0, w, h)); try { ImageIO.write(image, ext, f); } catch (Exception e) { System.out.println(e); } }
/** * Returns the specified image as icon. * * @param name name of icon * @return icon */ public static ImageIcon icon(final String name) { ImageIcon ii = ICONS.get(name); if (ii != null) return ii; Image img; if (GUIConstants.scale > 1) { // choose large image or none final URL url = GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null; if (url == null) { // resize low-res image if no hi-res image exists img = get(url(name)); final int w = (int) (img.getWidth(null) * GUIConstants.scale); final int h = (int) (img.getHeight(null) * GUIConstants.scale); final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, 0, 0, w, h, null); g2.dispose(); img = tmp; } else { img = get(url); } } else { img = get(name); } ii = new ImageIcon(img); ICONS.put(name, ii); return ii; }
public static void main(String[] args) { try { if (args.length != 2) { System.err.println("USAGE: java RenderMap map.txt image.png"); System.exit(1); } Game game = new Game(args[0], 100, 0); if (game.Init() == 0) { System.err.println("Error while loading map " + args[0]); System.exit(1); } ArrayList<Color> colors = new ArrayList<Color>(); colors.add(new Color(106, 74, 60)); colors.add(new Color(74, 166, 60)); colors.add(new Color(204, 51, 63)); colors.add(new Color(235, 104, 65)); colors.add(new Color(237, 201, 81)); Color bgColor = new Color(188, 189, 172); Color textColor = Color.BLACK; Font planetFont = new Font("Sans Serif", Font.BOLD, 11); Font fleetFont = new Font("Sans serif", Font.PLAIN, 7); GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); BufferedImage image = gc.createCompatibleImage(640, 480); Graphics2D _g = (Graphics2D) image.createGraphics(); // Turn on AA/Speed _g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); _g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); _g.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); game.Render(640, 480, 0.0, null, colors, bgColor, textColor, planetFont, fleetFont, _g); File file = new File(args[1]); ImageIO.write(image, "png", file); } catch (Exception e) { System.err.println(e); } }
public void paint(Graphics gOld) { if (image == null || xsize != getSize().width || ysize != getSize().height) { xsize = getSize().width; ysize = getSize().height; image = createImage(xsize, ysize); g = (Graphics2D) image.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } // fill background g.setColor(Color.cyan); g.fillRect(0, 0, xsize, ysize); int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)}; int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)}; // fill border g.setColor(Color.black); g.fillPolygon(x, y, 4); // draw border g.setColor(Color.red); g.drawPolyline(x, y, 5); if (animateFirstTime) { gOld.drawImage(image, 0, 0, null); return; } if (gameOver) return; g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this); for (int index = 0; index < missile.length; index++) { if (missile[index].active) { g.setColor(Color.red); drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5); } } if (rocketRight) { drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0); } else { drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0); } for (int index = 0; index < numStars; index++) { g.setColor(Color.yellow); if (starActive[index]) drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5); } g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("Score: " + score, 10, 45); g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("HighScore: " + highScore, 300, 45); g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("Lives: " + rocketLife, 150, 45); if (rocketLife == 0) { g.setColor(Color.red); g.setFont(new Font("Impact", Font.BOLD, 60)); g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2)); } gOld.drawImage(image, 0, 0, null); }
static void paintFocus( Graphics g, int x, int y, int width, int height, int r1, int r2, float grosor, Color color) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Stroke oldStroke = g2d.getStroke(); g2d.setColor(color); g2d.setStroke(new BasicStroke(grosor)); if (r1 == 0 && r2 == 0) { g.drawRect(x, y, width, height); } else { g.drawRoundRect(x, y, width - 1, height - 1, r1, r2); } g2d.setStroke(oldStroke); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setPaint(BACKGROUND); g2.fill( new Rectangle2D.Float( 0f, 0f, (float) g2.getClipBounds().width, (float) g2.getClipBounds().height)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); canvas.paint(g2); }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Turn on antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); drawBackground(g2); drawImageMosaic(g2); drawText(g2); }
public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w, h); g2.drawImage(bi, -x, -y, null); // this); g2.dispose(); return image; }
/** * Esta funcion se usa para pintar la barra de seleccion de los menus. Esta aqui para no repetirla * en todas partes... */ static void pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor) { ButtonModel model = menuItem.getModel(); Color oldColor = g.getColor(); int menuWidth = menuItem.getWidth(); int menuHeight = menuItem.getHeight(); if (menuItem.isOpaque()) { g.setColor(menuItem.getBackground()); g.fillRect(0, 0, menuWidth, menuHeight); } if ((menuItem instanceof JMenu && !(((JMenu) menuItem).isTopLevelMenu()) && model.isSelected()) || model.isArmed()) { RoundRectangle2D.Float boton = new RoundRectangle2D.Float(); boton.x = 1; boton.y = 0; boton.width = menuWidth - 3; boton.height = menuHeight - 1; boton.arcwidth = 8; boton.archeight = 8; GradientPaint grad = new GradientPaint(1, 1, getBrilloMenu(), 0, menuHeight, getSombraMenu()); Graphics2D g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(bgColor); g2D.fill(boton); g.setColor(bgColor.darker()); g2D.draw(boton); g2D.setPaint(grad); g2D.fill(boton); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); } g.setColor(oldColor); }
public static BufferedImage scaleImage(BufferedImage bi, double scale) { int w1 = (int) (Math.round(scale * bi.getWidth())); int h1 = (int) (Math.round(scale * bi.getHeight())); BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w1, h1); g2.drawImage(bi, 0, 0, w1, h1, null); // this); g2.dispose(); return image; }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension asz = this.getSize(); if (fullRefresh) { g2.clearRect(0, 0, asz.width, asz.height); fullRefresh = false; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); big.setColor(Color.black); offset.x = (int) (asz.width - iw) / 2; offset.y = (int) (asz.height - ih) / 2; big.drawImage(img, 0, 0, this); big.setPaint(Color.red); if ((rect.width > 0) && (rect.height > 0)) big.draw(rect); if (selected == 1) shadeExt(big, 0, 0, 0, 64); else if (selected == 2) { shadeExt(big, 0, 0, 0, 255); selected = 1; } g2.drawImage(bi, offset.x, offset.y, this); }
public static BufferedImage rotateImage(BufferedImage bi) { int w = bi.getWidth(); int h = bi.getHeight(); BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); // getBackground()); g2.fillRect(0, 0, h, w); g2.rotate(90 * Math.PI / 180); g2.drawImage(bi, 0, -h, w, h, null); // this); g2.dispose(); return image; }
public Example(BufferedImage image) { // copy image int width = image.getWidth(); int height = image.getHeight(); this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = this.image.createGraphics(); g2.drawImage(image, 0, 0, null); g2.dispose(); // create icon if (Math.max(width, height) > ICON_SIZE) { double scale = Math.min((double) ICON_SIZE / width, (double) ICON_SIZE / height); width *= scale; height *= scale; } BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); g2 = buf.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(image, 0, 0, width, height, null); g2.dispose(); this.icon = new ImageIcon(buf); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(x, y); g2.setStroke(new BasicStroke(BORDER_WIDTH)); g2.setPaint(LINE_COLOR); g2.draw(BORDER); g2.setStroke(new BasicStroke(SLIT_WIDTH)); g2.setColor(UIManager.getColor("Panel.background")); int n = SLIT_NUM + 1; int v = ICON_SIZE / n; int m = n * v; for (int i = 1; i < n; i++) { int a = i * v; g2.drawLine(a, 0, a, m); g2.drawLine(0, a, m, a); } // g2.drawLine(1 * v, 0 * v, 1 * v, 4 * v); // g2.drawLine(2 * v, 0 * v, 2 * v, 4 * v); // g2.drawLine(3 * v, 0 * v, 3 * v, 4 * v); // g2.drawLine(0 * v, 1 * v, 4 * v, 1 * v); // g2.drawLine(0 * v, 2 * v, 4 * v, 2 * v); // g2.drawLine(0 * v, 3 * v, 4 * v, 3 * v); g2.setPaint(LINE_COLOR); Rectangle2D b = ARROW.getBounds(); Point2D p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d); AffineTransform toCenterAT = AffineTransform.getTranslateInstance(ICON_SIZE / 2d - p.getX(), ICON_SIZE / 2d - p.getY()); g2.fill(toCenterAT.createTransformedShape(ARROW)); g2.dispose(); }
public void paintScaledFrameBuffer(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.drawImage(memImage, 0, 0, scaledWidth, scaledHeight, null); }
public void paint(Graphics gOld) { if (image == null || xsize != getSize().width || ysize != getSize().height) { xsize = getSize().width; ysize = getSize().height; image = createImage(xsize, ysize); g = (Graphics2D) image.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } // fill background g.setColor(Color.cyan); g.fillRect(0, 0, xsize, ysize); int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)}; int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)}; // fill border g.setColor(Color.black); g.fillPolygon(x, y, 4); // draw border g.setColor(Color.red); g.drawPolyline(x, y, 5); if (animateFirstTime) { gOld.drawImage(image, 0, 0, null); return; } g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this); g.setColor(Color.yellow); for (int i = 0; i < starNum; i++) { if (!GameOver) drawStar(getX(star[i].getXPos()), getYNormal(star[i].getYPos()), 0.0, 1.0, 1.0); } g.setColor(Color.white); for (int i = 0; i < missle.length; i++) { if (missle[i].getActive() && !GameOver) { drawCircle( getX(missle[i].getXPos()), getYNormal(missle[i].getYPos()), 0.0, 1.0, 1.0, missle[i].getWidth()); } } if (!GameOver) { if (!rocketRight) drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0, 1.0, 1.0); else drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0, -1.0, 1.0); } if (ff) { drawCircle(getX(rocketXPos), getYNormal(rocketYPos), 0, ffsize, ffsize, ffwidth); } g.setColor(Color.BLACK); g.drawString("Lives: " + lives, 115, 43); g.drawString("Score: " + score, 50, 43); if (GameOver) { g.setColor(Color.WHITE); g.drawString("GAMEOVER", getWidth2() / 2, getHeight2() / 2); g.drawString("HighScore: " + highscore, getWidth2() / 2, getHeight2() / 2 - 20); } gOld.drawImage(image, 0, 0, null); }
/** * Activates graphics anti-aliasing. * * @param g graphics reference * @return graphics reference */ public static Graphics2D antiAlias(final Graphics g) { final Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); return g2; }
// also clip, transform, composite, // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;} // --------------------------------------------------------- private void doPaint(Graphics2D g, int s, Object o) { // process an operation from the buffer // System.out.println(s); Object o1 = null, o2 = null, o3 = null, o4 = null, o5 = null, o6 = null, o7 = null, o8 = null, o9 = null, o10 = null, o11 = null; if (o instanceof Object[]) { Object[] a = (Object[]) o; if (a.length > 0) o1 = a[0]; if (a.length > 1) o2 = a[1]; if (a.length > 2) o3 = a[2]; if (a.length > 3) o4 = a[3]; if (a.length > 4) o5 = a[4]; if (a.length > 5) o6 = a[5]; if (a.length > 6) o7 = a[6]; if (a.length > 7) o8 = a[7]; if (a.length > 8) o9 = a[8]; if (a.length > 9) o10 = a[9]; if (a.length > 10) o11 = a[10]; } switch (s) { case clear: paintBackground(g, theBackground); break; // public void addRenderingHints(Map<?,?> hints) // {toBuffer("addRenderingHints",hints );} case addRenderingHints: g.addRenderingHints((Map<?, ?>) o); break; case clip1: g.clip((Shape) o); break; case draw1: g.draw((Shape) o); break; case draw3DRect: g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case drawGlyphVector: g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3); break; case drawImage1: g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4); break; case drawImage2: g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3); break; case drawRenderableImage: g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2); break; case drawRenderedImage: g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2); break; case drawString1: g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3); break; case drawString2: g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3); break; case drawString3: g.drawString((String) o1, (Float) o2, (Float) o3); break; case drawString4: g.drawString((String) o1, (Integer) o2, (Integer) o3); break; case fill: g.fill((Shape) o); break; case fill3DRect: g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case rotate1: g.rotate((Double) o); break; case rotate2: g.rotate((Double) o1, (Double) o2, (Double) o3); break; case scale1: g.scale((Double) o1, (Double) o2); break; case setBackground: g.setBackground( (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/ break; case setComposite: g.setComposite((Composite) o); break; case setPaint: g.setPaint((Paint) o); break; case setRenderingHint: g.setRenderingHint((RenderingHints.Key) o1, o2); break; case setRenderingHints: g.setRenderingHints((Map<?, ?>) o); break; case setStroke: g.setStroke((Stroke) o); break; case setTransform: g.setTransform(makeTransform(o)); break; case shear: g.shear((Double) o1, (Double) o2); break; case transform1: g.transform(makeTransform(o)); break; case translate1: g.translate((Double) o1, (Double) o2); break; case translate2: g.translate((Integer) o1, (Integer) o2); break; case clearRect: g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case copyArea: g.copyArea( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawArc: g.drawArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawBytes: g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawChars: g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawImage4: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5); break; case drawImage5: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4); break; case drawImage6: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Color) o6, (ImageObserver) o7); break; case drawImage7: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6); break; case drawImage8: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (Color) o10, (ImageObserver) o11); break; case drawImage9: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (ImageObserver) o10); break; case drawLine: g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawOval: g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawPolygon1: g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case drawPolygon2: g.drawPolygon((Polygon) o); break; case drawPolyline: g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3); break; case drawRect: g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawRoundRect: g.drawRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillArc: g.fillArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillOval: g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; // {toBuffer("fillPolygon",mkArg(xPoints, yPoints, nPoints) );} case fillPolygon1: g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case fillPolygon2: g.fillPolygon((Polygon) o); break; case fillRect: g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case fillRoundRect: g.fillRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case setClip1: g.setClip((Shape) o); break; case setColor: g.setColor((Color) o); break; case setFont: g.setFont((Font) o); break; case setPaintMode: g.setPaintMode(); break; case setXORMode: g.setXORMode((Color) o); break; case opaque: super.setOpaque((Boolean) o); break; case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break; { FontRenderContext frc = g.getFontRenderContext(); TextLayout tl = new TextLayout((String) o1, g.getFont(), frc); Shape s1 = tl.getOutline(null); AffineTransform af = g.getTransform(); g.translate((Integer) o2, (Integer) o3); g.draw(s1); g.setTransform(af); } ; break; default: System.out.println("Unknown image operation " + s); } }
// Although it presently returns a boolean, that was only needed // during my aborted attempted at animated graphics primitives. // Until those become a reality the boolean value returned by this // routine is unnecessary public /*synchronized*/ boolean execute(int sAt) { // The commented-out variables below are remnants from legacy // code -- they appear to be no longer needed. // String urlTemp=""; // int z=0; // int idx; // int urlid; // boolean showURL=false; animation_done = true; // May be re-set in paintComponent via indirect paintImmediately call at end // Was used in abored attempted to // introduce animated primitives. Now // it's probably excess baggage that // remains because I still have hopes // of eventually having animated // primitives SnapAt = sAt; if (getSize().width != 0 && getSize().height != 0) { my_width = getSize().width; // set dimensions my_height = getSize().height; } else { my_width = GaigsAV.preferred_width; // set dimensions my_height = GaigsAV.preferred_height; } BufferedImage buff = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) buff.getGraphics(); // need a separate object each time? g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE); g2.fillRect(0, 0, my_width, my_height); // Set horizoff and vertoff to properly center the visualization in the // viewing window. This is not quite perfect because visualizations // that are not properly centered within their [0,1] localized // coordinates will not be perfectly centered, but it is much better // than it was previously. // if(no_mouse_drag){ // if(first_paint_call){ // // horizoff = (my_width - (int)(0.25 * my_width) - // // GaigsAV.preferred_width) / 2; // horizoff = (my_width - GaigsAV.preferred_width) / 2; // first_paint_call = false; // }else{ // horizoff = (my_width - GaigsAV.preferred_width) / 2; // no_mouse_drag = false; // } // } if (no_mouse_drag) { horizoff = (my_width - GaigsAV.preferred_width) / 2; vertoff = (my_height - GaigsAV.preferred_height) / 2; } int x; list_of_snapshots.reset(); x = 0; LinkedList lt = new LinkedList(); while (x < SnapAt && list_of_snapshots.hasMoreElements()) { lt = (LinkedList) list_of_snapshots.nextElement(); x++; } lt.reset(); animation_done = true; // System.out.println("before loop " + horizoff); while (lt.hasMoreElements()) { obj tempObj = (obj) lt.nextElement(); animation_done = animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff)); // System.out.println("in loop"); } Shape mask = createMask(buff.getWidth(), buff.getHeight()); g2.setColor(Color.BLACK); g2.fill(mask); my_image = buff; repaint(); return animation_done; }
// Although it presently returns a boolean, that was only needed // during my aborted attempted at animated graphics primitives. // Until those become a reality the boolean value returned by this // routine is unnecessary public boolean animate(int sAt, boolean forward) { int x; LinkedList lt = null; animation_done = true; // May be re-set in paintComponent via indirect paintImmediately call at end // Was used in aborted attempted to // introduce animated primitives. Now // it's probably excess baggage that // remains because I still have hopes // of eventually having animated // primitives if (getSize().width != 0 && getSize().height != 0) { my_width = getSize().width; // set dimensions my_height = getSize().height; } else { my_width = GaigsAV.preferred_width; // set dimensions my_height = GaigsAV.preferred_height; } // First capture the new image in a buffer called image2 SnapAt = sAt; BufferedImage image2 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) image2.getGraphics(); // need a separate object each time? g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE); g2.fillRect(0, 0, my_width, my_height); // Set horizoff and vertoff to properly center the visualization in the // viewing window. This is not quite perfect because visualizations // that are not properly centered within their [0,1] localized // coordinates will not be perfectly centered, but it is much better // than it was previously. if (no_mouse_drag) { horizoff = (my_width - GaigsAV.preferred_width) / 2; vertoff = (my_height - GaigsAV.preferred_height) / 2; } list_of_snapshots.reset(); x = 0; lt = new LinkedList(); while (x < SnapAt && list_of_snapshots.hasMoreElements()) { lt = (LinkedList) list_of_snapshots.nextElement(); x++; } lt.reset(); animation_done = true; // System.out.println("before loop " + horizoff); while (lt.hasMoreElements()) { obj tempObj = (obj) lt.nextElement(); animation_done = animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff)); // System.out.println("in loop"); } // Next capture the image we are coming from in a buffer called image1 SnapAt = (forward ? sAt - 1 : sAt + 1); BufferedImage image1 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB); Graphics2D g1 = (Graphics2D) image1.getGraphics(); // need a separate object each time? g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g1.setColor(Color.WHITE); g1.fillRect(0, 0, my_width, my_height); // Set horizoff and vertoff to properly center the visualization in the // viewing window. This is not quite perfect because visualizations // that are not properly centered within their [0,1] localized // coordinates will not be perfectly centered, but it is much better // than it was previously. if (no_mouse_drag) { horizoff = (my_width - GaigsAV.preferred_width) / 2; vertoff = (my_height - GaigsAV.preferred_height) / 2; } list_of_snapshots.reset(); x = 0; lt = new LinkedList(); while (x < SnapAt && list_of_snapshots.hasMoreElements()) { lt = (LinkedList) list_of_snapshots.nextElement(); x++; } lt.reset(); animation_done = true; // System.out.println("before loop " + horizoff); while (lt.hasMoreElements()) { obj tempObj = (obj) lt.nextElement(); animation_done = animation_done && (tempObj.execute(g1 /*offscreen*/, zoom, vertoff, horizoff)); // System.out.println("in loop"); } // Now slide from image1 to image2 // From the gaff Visualizer by Chris Gaffney // double step = 4; // Adjust this for more/less granularity between images double step = 40; // Adjust this for more/less granularity between images Image buffer = getGraphicsConfiguration().createCompatibleVolatileImage(my_width, my_height); Graphics2D g2d = (Graphics2D) buffer.getGraphics(); AffineTransform trans = AffineTransform.getTranslateInstance(step * (forward ? -1 : 1), 0); // AffineTransform orig = g2d.getTransform(); Shape mask = createMask(my_width, my_height); for (double i = 0; i < my_width; i += step) { if (i + step > my_width) // last time through loop, so adjust transform trans = AffineTransform.getTranslateInstance(((double) (my_width - i)) * (forward ? -1 : 1), 0); g2d.transform(trans); g2d.drawImage(image1, 0, 0, this); g2d.setColor(Color.BLACK); g2d.fill(mask); AffineTransform last = g2d.getTransform(); g2d.transform(AffineTransform.getTranslateInstance(my_width * (-1 * (forward ? -1 : 1)), 0)); g2d.drawImage(image2, 0, 0, this); g2d.setColor(Color.BLACK); g2d.fill(mask); g2d.setTransform(last); this.my_image = buffer; repaint(); try { Thread.sleep(10); } catch (InterruptedException e) { } } Image b = getGraphicsConfiguration().createCompatibleImage(my_width, my_height); b.getGraphics().drawImage(buffer, 0, 0, null); this.my_image = b; return animation_done; }
static void paintShadowTitle( Graphics g, String title, int x, int y, Color frente, Color shadow, int desp, int tipo, int orientation) { // Si hay que rotar la fuente, se rota Font f = g.getFont(); if (orientation == SwingConstants.VERTICAL) { AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); f = f.deriveFont(rotate); } // Si hay que pintar sombra, se hacen un monton de cosas if (shadow != null) { int matrix = (tipo == THIN ? MATRIX_THIN : MATRIX_FAT); Rectangle2D rect = g.getFontMetrics().getStringBounds(title, g); int w, h; if (orientation == SwingConstants.HORIZONTAL) { w = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde h = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP } else { h = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde w = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP } // La sombra del titulo BufferedImage iTitulo = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); BufferedImage iSombra = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = iTitulo.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setFont(f); g2.setColor(shadow); g2.drawString(title, 3 * matrix, 3 * matrix); // La pintamos en el centro ConvolveOp cop = new ConvolveOp((tipo == THIN ? kernelThin : kernelFat), ConvolveOp.EDGE_NO_OP, null); cop.filter(iTitulo, iSombra); // A ditorsionar // Por fin, pintamos el jodio titulo g.drawImage( iSombra, x - 3 * matrix + desp, // Lo llevamos a la posicion original y le sumamos 1 y - 3 * matrix + desp, // para que la sombra quede pelin desplazada null); } // Si hay que pintar el frente, se pinta if (frente != null) { g.setFont(f); g.setColor(frente); g.drawString(title, x, y); } }
private void drawPlot(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2d.setColor(Color.white); g2d.fillRect(0, 0, getWidth(), getHeight()); double activeWidth = getWidth() - leftMargin - rightMargin; double activeHeight = getHeight() - topMargin - bottomMargin; int bottomY = getHeight() - bottomMargin; int rightX = getWidth() - rightMargin; // draw data line int x1, x2, y1, y2; g2d.setColor(Color.red); for (int i = 1; i < numComponents; i++) { x1 = (int) (leftMargin + ((double) (i - 1) / (numComponents - 1)) * activeWidth); y1 = (int) (bottomY - (plotData[i - 1][plotIndex] * 10.0) / 1000 * activeHeight); x2 = (int) (leftMargin + ((double) (i) / (numComponents - 1)) * activeWidth); y2 = (int) (bottomY - (plotData[i][plotIndex] * 10) / 1000 * activeHeight); g2d.drawLine(x1, y1, x2, y2); } // draw data points int radius = 2; for (int i = 0; i < numComponents; i++) { x1 = (int) (leftMargin + ((double) (i) / (numComponents - 1)) * activeWidth); y1 = (int) (bottomY - (plotData[i][plotIndex] * 10.0) / 1000 * activeHeight); g2d.drawOval(x1 - radius - 1, y1 - radius - 1, 2 * radius + 2, 2 * radius + 2); } // draw axes g2d.setColor(Color.black); g2d.drawLine(leftMargin, bottomY, rightX, bottomY); g2d.drawLine(leftMargin, bottomY, leftMargin, topMargin); g2d.drawLine(leftMargin, topMargin, rightX, topMargin); g2d.drawLine(rightX, bottomY, rightX, topMargin); // draw ticks int tickSize = 4; for (int i = 1; i <= numComponents; i++) { x1 = (int) (leftMargin + ((double) (i - 1) / (numComponents - 1)) * activeWidth); g2d.drawLine(x1, bottomY, x1, bottomY + tickSize); } for (int i = 0; i <= 1000; i += 100) { y1 = (int) (bottomY - i / 1000.0 * activeHeight); g2d.drawLine(leftMargin, y1, leftMargin - tickSize, y1); } // labels DecimalFormat df = new DecimalFormat("#,###,###.###"); Font font = new Font("SanSerif", Font.PLAIN, 11); FontMetrics metrics = g.getFontMetrics(font); int hgt, adv; hgt = metrics.getHeight(); // x-axis labels String label; for (int i = 1; i <= numComponents; i++) { label = String.valueOf(i); x1 = (int) (leftMargin + ((double) (i - 1) / (numComponents - 1)) * activeWidth); adv = metrics.stringWidth(label) / 2; g2d.drawString(label, x1 - adv, bottomY + hgt + 4); } label = "Component"; adv = metrics.stringWidth(label); int xAxisMidPoint = (int) (leftMargin + activeWidth / 2); g2d.drawString(label, xAxisMidPoint - adv / 2, bottomY + 2 * hgt + 6); // y-axis labels // rotate the font Font oldFont = g.getFont(); Font f = oldFont.deriveFont(AffineTransform.getRotateInstance(-Math.PI / 2.0)); g2d.setFont(f); int yAxisMidPoint = (int) (topMargin + activeHeight / 2); int offset; label = "Explained Variance (%)"; offset = metrics.stringWidth("100.0") + 12 + hgt; adv = metrics.stringWidth(label); g2d.drawString(label, leftMargin - offset, yAxisMidPoint + adv / 2); // replace the rotated font. g2d.setFont(oldFont); df = new DecimalFormat("0.0"); for (int i = 0; i <= 1000; i += 100) { label = df.format(i / 10); y1 = (int) (bottomY - i / 1000.0 * activeHeight); adv = metrics.stringWidth(label); g2d.drawString(label, leftMargin - adv - 12, y1 + hgt / 2); } // title // bold font oldFont = g.getFont(); font = font = new Font("SanSerif", Font.BOLD, 12); g2d.setFont(font); label = "PCA Scree Plot"; adv = metrics.stringWidth(label); g2d.drawString(label, getWidth() / 2 - adv / 2, topMargin - hgt - 5); g2d.setFont(oldFont); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); int width = getWidth() - rightMargin - leftMargin - 10; int height = getHeight() - topMargin - bottomMargin; if (width <= 0 || height <= 0) { // not enough room to paint anything return; } Color oldColor = g.getColor(); Font oldFont = g.getFont(); Color fg = getForeground(); Color bg = getBackground(); boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200); ((Graphics2D) g) .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (smallFont == null) { smallFont = oldFont.deriveFont(9.0F); } r.x = leftMargin - 5; r.y = topMargin - 8; r.width = getWidth() - leftMargin - rightMargin; r.height = getHeight() - topMargin - bottomMargin + 16; if (border == null) { // By setting colors here, we avoid recalculating them // over and over. border = new BevelBorder( BevelBorder.LOWERED, getBackground().brighter().brighter(), getBackground().brighter(), getBackground().darker().darker(), getBackground().darker()); } border.paintBorder(this, g, r.x, r.y, r.width, r.height); // Fill background color g.setColor(bgColor); g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4); g.setColor(oldColor); long tMin = Long.MAX_VALUE; long tMax = Long.MIN_VALUE; long vMin = Long.MAX_VALUE; long vMax = 1; int w = getWidth() - rightMargin - leftMargin - 10; int h = getHeight() - topMargin - bottomMargin; if (times.size > 1) { tMin = Math.min(tMin, times.time(0)); tMax = Math.max(tMax, times.time(times.size - 1)); } long viewRangeMS; if (viewRange > 0) { viewRangeMS = viewRange * MINUTE; } else { // Display full time range, but no less than a minute viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE); } // Calculate min/max values for (Sequence seq : seqs) { if (seq.size > 0) { for (int i = 0; i < seq.size; i++) { if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) { long val = seq.value(i); if (val > Long.MIN_VALUE) { vMax = Math.max(vMax, val); vMin = Math.min(vMin, val); } } } } else { vMin = 0L; } if (unit == Unit.BYTES || !seq.isPlotted) { // We'll scale only to the first (main) value set. // TODO: Use a separate property for this. break; } } // Normalize scale vMax = normalizeMax(vMax); if (vMin > 0) { if (vMax / vMin > 4) { vMin = 0; } else { vMin = normalizeMin(vMin); } } g.setColor(fg); // Axes // Draw vertical axis int x = leftMargin - 18; int y = topMargin; FontMetrics fm = g.getFontMetrics(); g.drawLine(x, y, x, y + h); int n = 5; if (("" + vMax).startsWith("2")) { n = 4; } else if (("" + vMax).startsWith("3")) { n = 6; } else if (("" + vMax).startsWith("4")) { n = 4; } else if (("" + vMax).startsWith("6")) { n = 6; } else if (("" + vMax).startsWith("7")) { n = 7; } else if (("" + vMax).startsWith("8")) { n = 8; } else if (("" + vMax).startsWith("9")) { n = 3; } // Ticks ArrayList<Long> tickValues = new ArrayList<Long>(); tickValues.add(vMin); for (int i = 0; i < n; i++) { long v = i * vMax / n; if (v > vMin) { tickValues.add(v); } } tickValues.add(vMax); n = tickValues.size(); String[] tickStrings = new String[n]; for (int i = 0; i < n; i++) { long v = tickValues.get(i); tickStrings[i] = getSizeString(v, vMax); } // Trim trailing decimal zeroes. if (decimals > 0) { boolean trimLast = true; boolean removedDecimalPoint = false; do { for (String str : tickStrings) { if (!(str.endsWith("0") || str.endsWith("."))) { trimLast = false; break; } } if (trimLast) { if (tickStrings[0].endsWith(".")) { removedDecimalPoint = true; } for (int i = 0; i < n; i++) { String str = tickStrings[i]; tickStrings[i] = str.substring(0, str.length() - 1); } } } while (trimLast && !removedDecimalPoint); } // Draw ticks int lastY = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { long v = tickValues.get(i); y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin)); g.drawLine(x - 2, y, x + 2, y); String s = tickStrings[i]; if (unit == Unit.PERCENT) { s += "%"; } int sx = x - 6 - fm.stringWidth(s); if (y < lastY - 13) { if (checkLeftMargin(sx)) { // Wait for next repaint return; } g.drawString(s, sx, y + 4); } // Draw horizontal grid line g.setColor(Color.lightGray); g.drawLine(r.x + 4, y, r.x + r.width - 4, y); g.setColor(fg); lastY = y; } // Draw horizontal axis x = leftMargin; y = topMargin + h + 15; g.drawLine(x, y, x + w, y); long t1 = tMax; if (t1 <= 0L) { // No data yet, so draw current time t1 = System.currentTimeMillis(); } long tz = timeDF.getTimeZone().getOffset(t1); long tickInterval = calculateTickInterval(w, 40, viewRangeMS); if (tickInterval > 3 * HOUR) { tickInterval = calculateTickInterval(w, 80, viewRangeMS); } long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval; while (t0 < viewRangeMS) { x = leftMargin + (int) (w * t0 / viewRangeMS); g.drawLine(x, y - 2, x, y + 2); long t = t1 - viewRangeMS + t0; String str = formatClockTime(t); g.drawString(str, x, y + 16); // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) { if ((t + tz) % (1 * DAY) == 0) { str = formatDate(t); g.drawString(str, x, y + 27); } // Draw vertical grid line g.setColor(Color.lightGray); g.drawLine(x, topMargin, x, topMargin + h); g.setColor(fg); t0 += tickInterval; } // Plot values int start = 0; int nValues = 0; int nLists = seqs.size(); if (nLists > 0) { nValues = seqs.get(0).size; } if (nValues == 0) { g.setColor(oldColor); return; } else { Sequence seq = seqs.get(0); // Find starting point for (int p = 0; p < seq.size; p++) { if (times.time(p) >= tMax - viewRangeMS) { start = p; break; } } } // Optimization: collapse plot of more than four values per pixel int pointsPerPixel = (nValues - start) / w; if (pointsPerPixel < 4) { pointsPerPixel = 1; } // Draw graphs // Loop backwards over sequences because the first needs to be painted on top for (int i = nLists - 1; i >= 0; i--) { int x0 = leftMargin; int y0 = topMargin + h + 1; Sequence seq = seqs.get(i); if (seq.isPlotted && seq.size > 0) { // Paint twice, with white and with color for (int pass = 0; pass < 2; pass++) { g.setColor((pass == 0) ? Color.white : seq.color); int x1 = -1; long v1 = -1; for (int p = start; p < nValues; p += pointsPerPixel) { // Make sure we get the last value if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) { p = nValues - 1; } int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS); long v2 = seq.value(p); if (v2 >= vMin && v2 <= vMax) { int y2 = (int) (h * (v2 - vMin) / (vMax - vMin)); if (x1 >= 0 && v1 >= vMin && v1 <= vMax) { int y1 = (int) (h * (v1 - vMin) / (vMax - vMin)); if (y1 == y2) { // fillrect is much faster g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1); } else { Graphics2D g2d = (Graphics2D) g; Stroke oldStroke = null; if (seq.transitionStroke != null) { oldStroke = g2d.getStroke(); g2d.setStroke(seq.transitionStroke); } g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass); if (oldStroke != null) { g2d.setStroke(oldStroke); } } } } x1 = x2; v1 = v2; } } // Current value long v = seq.value(seq.size - 1); if (v >= vMin && v <= vMax) { if (bgIsLight) { g.setColor(seq.color); } else { g.setColor(fg); } x = r.x + r.width + 2; y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin)); // a small triangle/arrow g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3); } g.setColor(fg); } } int[] valueStringSlots = new int[nLists]; for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1; for (int i = 0; i < nLists; i++) { Sequence seq = seqs.get(i); if (seq.isPlotted && seq.size > 0) { // Draw current value // TODO: collapse values if pointsPerPixel >= 4 long v = seq.value(seq.size - 1); if (v >= vMin && v <= vMax) { x = r.x + r.width + 2; y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin)); int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i); g.setFont(smallFont); if (bgIsLight) { g.setColor(seq.color); } else { g.setColor(fg); } String curValue = getFormattedValue(v, true); if (unit == Unit.PERCENT) { curValue += "%"; } int valWidth = fm.stringWidth(curValue); String legend = (displayLegend ? seq.name : ""); int legendWidth = fm.stringWidth(legend); if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) { // Wait for next repaint return; } g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10)); g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3)); // Maybe draw a short line to value if (y2 > y + 3) { g.drawLine(x + 9, y + 2, x + 14, y2); } else if (y2 < y - 3) { g.drawLine(x + 9, y - 2, x + 14, y2); } } g.setFont(oldFont); g.setColor(fg); } } g.setColor(oldColor); }
@Override public void paint(Graphics g) { try { Graphics2D g2d = (Graphics2D) g; if (numPaletteEntries > 50) { g2d.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); } if (paletteFile != null && (paletteFile.toLowerCase().contains("qual") || paletteFile.toLowerCase().contains("categorical"))) { g2d.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); } int width = getWidth(); int height = getHeight(); Image image = null; int numDisplayedPaletteEntries = 0; if (!categorical) { numDisplayedPaletteEntries = paletteData.length; } else { numDisplayedPaletteEntries = (int) (Math.floor((maxValue - minValue + 1) / numPaletteEntries) + (maxValue - minValue + 1) % numPaletteEntries); } int[] imageData = new int[numDisplayedPaletteEntries]; int i, j; int numPaletteEntriesLessOne = numPaletteEntries - 1; if (!isReversed && orientation == VERTICAL_ORIENTATION) { if (!categorical) { for (i = 0; i < numPaletteEntries; i++) { j = (int) ((Math.pow((1 - ((double) (i) / numPaletteEntriesLessOne)), gamma)) * numPaletteEntriesLessOne); imageData[i] = paletteData[j]; } } else { // it is categorical for (i = 0; i < numDisplayedPaletteEntries; i++) { j = (int) (i % numPaletteEntries); imageData[numDisplayedPaletteEntries - 1 - i] = paletteData[j]; } } image = createImage(new MemoryImageSource(1, numDisplayedPaletteEntries, imageData, 0, 1)); } else if (!isReversed && orientation == HORIZONTAL_ORIENTATION) { for (i = 0; i < numPaletteEntries; i++) { j = (int) ((Math.pow(((double) (i) / numPaletteEntriesLessOne), gamma)) * numPaletteEntriesLessOne); imageData[i] = paletteData[j]; } image = createImage(new MemoryImageSource(numPaletteEntries, 1, imageData, 0, 1)); } else if (isReversed && orientation == VERTICAL_ORIENTATION) { if (!categorical) { for (i = 0; i < numPaletteEntries; i++) { j = (int) ((Math.pow(((double) (i) / numPaletteEntriesLessOne), gamma)) * numPaletteEntriesLessOne); imageData[i] = paletteData[j]; } } else { // it is categorical for (i = 0; i < numDisplayedPaletteEntries; i++) { j = (int) (numPaletteEntries - i % numPaletteEntries - 1); imageData[numDisplayedPaletteEntries - 1 - i] = paletteData[j]; } } image = createImage(new MemoryImageSource(1, numDisplayedPaletteEntries, imageData, 0, 1)); } else if (isReversed && orientation == HORIZONTAL_ORIENTATION) { for (i = 0; i < numPaletteEntries; i++) { j = (int) ((Math.pow((1 - ((double) (i) / numPaletteEntriesLessOne)), gamma)) * numPaletteEntriesLessOne); imageData[i] = paletteData[j]; } image = createImage(new MemoryImageSource(imageData.length, 1, imageData, 0, 1)); } g.drawImage(image, 0, 0, width, height, this); if (!isSelected) { g.setColor(Color.black); g.drawRect(0, 0, width - 1, height - 1); } else { g.setColor(Color.white); g.drawRect(1, 1, width - 3, height - 3); g.setColor(Color.red); g.drawRect(0, 0, width - 1, height - 1); } } catch (Exception e) { System.out.println(e.getMessage()); } }
@Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.black); g.fillRect(0, 0, getWidth(), getHeight()); for (Integer id : planetNames.keySet()) { String name = planetNames.get(id); Point p = planetCoordinates.get(id); PartialPlanetBlock planet = getPlanet(id, -2); g.setColor(Color.gray); int rad = 3; if (planet != null) { rad = 6; if (animatorFrame) { Color col = colors.get(planet.owner); if (col == null) col = Color.gray; g.setColor(col); } else { if (planet.owner == settings.playerNr) g.setColor(Color.green); else if (colorize.isSelected() && colors.get(planet.owner) != null) g.setColor(colors.get(planet.owner)); else if (friends.contains(planet.owner)) g.setColor(Color.YELLOW); else if (planet.owner >= 0) g.setColor(Color.red); else rad = 3; } } int x = convertX(p.x); int y = convertY(p.y); double virtualWidth = getWidth() * zoom / 100; double virtualHeight = getHeight() * zoom / 100; int xOffset = (int) (getWidth() - virtualWidth) / 2; int yOffset = (int) (getHeight() - virtualHeight) / 2; x = (int) (xOffset + x * zoom / 100.0 - mariginX * zoom / 100.0); y = (int) (yOffset + y * zoom / 100.0 - mariginY * zoom / 100.0); g.fillOval(x - rad / 2, y - rad / 2, rad, rad); if (names.isSelected()) { g.setFont(g.getFont().deriveFont((float) 10)); g.setColor(Color.gray); int stringWidth = g.getFontMetrics().stringWidth(name); g.drawString(name, x - stringWidth / 2, y + 12); } if (colorize.isSelected() || animatorFrame) { int yy = 20; g.setFont(g.getFont().deriveFont((float) 12)); for (PlayerBlock pb : GalaxyViewer.this.p.players) { if (pb == null) continue; Color col = colors.get(pb.playerNumber); if (animatorFrame && col != null) ; // Ok else if (pb.playerNumber == settings.playerNr) col = Color.green; else if (col == null) col = Color.red; g.setColor(col); String n = new String(pb.nameBytes); // Does not work n = "Player " + (pb.playerNumber + 1); g.drawString(n, 5, yy); // System.out.print(pb.playerNumber+": "); // for (int t = 0; t < pb.nameBytes.length; t++){ // System.out.print((pb.nameBytes[t]&0xff)+" "); // System.out.print((pb.nameBytes[t])+" "); // } // System.out.println(); yy += 14; } } } }