List of usage examples for java.awt Graphics2D drawRect
public void drawRect(int x, int y, int width, int height)
From source file:it.smartcommunitylab.parking.management.web.manager.MarkerIconStorage.java
private void generateMarkerWithFlag(String basePath, String company, String entity, String color) throws IOException { BufferedImage templateIcon = ImageIO.read(new File(getIconFolder(basePath, ICON_FOLDER) + TEMPLATE_FILE)); BufferedImage icon = new BufferedImage(templateIcon.getWidth(), templateIcon.getHeight() + ICON_INCR_HEIGHT, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = icon.createGraphics(); graphics.setColor(new Color(Integer.parseInt(color, 16))); graphics.drawRect(0, 0, icon.getWidth(), COLOR_RECT_HEIGHT); graphics.fillRect(0, 0, icon.getWidth(), COLOR_RECT_HEIGHT); graphics.drawImage(templateIcon, 0, ICON_INCR_HEIGHT, null); graphics.dispose();// w w w .j a v a 2s .c o m ImageIO.write(icon, ICON_TYPE, new File(getIconFolder(basePath, ICON_FOLDER_CACHE) + company + "-" + entity + "-" + color + ICON_EXTENSION)); }
From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java
/** * Draw the corner boxes and their values as calculated by apa overlayed above the existing heat map * * @param g2 graphics2D oObject * @param map heat map object * @param regionCellDimensions dimensions for the corner regions to be plotted in units of cells, not pixels * where each cell corresponds to a data point, usually 20px-by-20px (default) * @param regionAPAValues apa results for each region in order of TL TR BL BR *///from w ww .j a v a 2 s .co m private static void drawCornerRegions(Graphics2D g2, HeatChart map, Dimension regionCellDimensions, double[] regionAPAValues) { // retrieve corners of heat map Point topLeft = map.getHeatMapTL(); Point topRight = map.getHeatMapTR(); Point bottomLeft = map.getHeatMapBL(); Point bottomRight = map.getHeatMapBR(); // calculate dimensions of corner regions Dimension cellSize = map.getCellSize(); int cornerWidth = regionCellDimensions.width * cellSize.width, cornerHeight = regionCellDimensions.height * cellSize.height; // slide to top left corner within each region topRight.translate(-cornerWidth, 0); bottomLeft.translate(0, -cornerHeight); bottomRight.translate(-cornerWidth, -cornerHeight); // plot the four region TL TR BL BR and their values Point[] points = { topLeft, topRight, bottomLeft, bottomRight }; g2.setColor(Color.black); for (int i = 0; i < 4; i++) { // plot rectangle from upper left corner Point currPoint = points[i]; g2.drawRect(currPoint.x, currPoint.y, cornerWidth, cornerHeight); // translate to center of rectangle currPoint.translate(cornerWidth / 2, cornerHeight / 2); drawCenteredDouble(g2, regionAPAValues[i], currPoint); } }
From source file:IconDemoApp.java
public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.WHITE);// ww w .j a v a 2 s. c o m g2d.fillRect(x + 1, y + 1, width - 2, height - 2); g2d.setColor(Color.BLACK); g2d.drawRect(x + 1, y + 1, width - 2, height - 2); g2d.setColor(Color.RED); g2d.setStroke(stroke); g2d.drawLine(x + 10, y + 10, x + width - 10, y + height - 10); g2d.drawLine(x + 10, y + height - 10, x + width - 10, y + 10); g2d.dispose(); }
From source file:com.ricemap.spateDB.operations.Plot.java
public static void drawShape(Graphics2D graphics, Shape s, Prism fileMbr, int imageWidth, int imageHeight, double scale) { if (s instanceof Point3d) { Point3d pt = (Point3d) s; int x = (int) ((pt.x - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1)); int y = (int) ((pt.y - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1)); if (x >= 0 && x < imageWidth && y >= 0 && y < imageHeight) graphics.fillRect(x, y, 1, 1); } else if (s instanceof Prism) { Prism r = (Prism) s;/*from w w w .java2 s . c o m*/ int s_x1 = (int) ((r.x1 - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1)); int s_y1 = (int) ((r.y1 - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1)); int s_x2 = (int) (((r.x2) - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1)); int s_y2 = (int) (((r.y2) - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1)); graphics.drawRect(s_x1, s_y1, s_x2 - s_x1 + 1, s_y2 - s_y1 + 1); } else { LOG.warn("Cannot draw a shape of type: " + s.getClass()); Prism r = s.getMBR(); int s_x1 = (int) ((r.x1 - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1)); int s_y1 = (int) ((r.y1 - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1)); int s_x2 = (int) (((r.x2) - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1)); int s_y2 = (int) (((r.y2) - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1)); if (s_x1 >= 0 && s_x1 < imageWidth && s_y1 >= 0 && s_y1 < imageHeight) graphics.drawRect(s_x1, s_y1, s_x2 - s_x1 + 1, s_y2 - s_y1 + 1); } }
From source file:com.joliciel.jochre.search.highlight.ImageSnippet.java
public BufferedImage getImage() { try {//from w ww . j av a 2 s. c o m BufferedImage originalImage = ImageIO.read(imageFile); BufferedImage imageSnippet = new BufferedImage(this.rectangle.getWidth(), this.rectangle.getHeight(), BufferedImage.TYPE_INT_ARGB); originalImage = originalImage.getSubimage(this.rectangle.getLeft(), this.rectangle.getTop(), this.rectangle.getWidth(), this.rectangle.getHeight()); Graphics2D graphics2D = imageSnippet.createGraphics(); graphics2D.drawImage(originalImage, 0, 0, this.rectangle.getWidth(), this.rectangle.getHeight(), null); int extra = 2; for (Rectangle rect : this.highlights) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setPaint(Color.BLACK); graphics2D.drawRect(rect.getLeft() - this.rectangle.getLeft() - extra, rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2), rect.getHeight() + (extra * 2)); graphics2D.setColor(new Color(255, 255, 0, 127)); graphics2D.fillRect(rect.getLeft() - this.rectangle.getLeft() - extra, rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2), rect.getHeight() + (extra * 2)); } return imageSnippet; } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:Main.java
public void render(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.WHITE);// w ww.ja v a2s . c o m Font font = new Font("Verdana", Font.PLAIN, 20); g2d.setFont(font); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); FontMetrics fm = g2d.getFontMetrics(); String option = "This is a test"; int x = (getWidth() - fm.stringWidth(option)) / 2; int y = ((getHeight() - fm.getHeight()) / 2); g2d.drawString(option, x, y + fm.getAscent()); g2d.drawRect((int) x - 20, (int) y - 10, (int) fm.stringWidth(option) + 40, (int) fm.getHeight() + 20); }
From source file:edu.umn.cs.spatialHadoop.operations.GeometricPlot.java
/** * Draws an image that can be used as a scale for heat maps generated using * Plot or PlotPyramid.// ww w . j a v a 2 s . c o m * @param output - Output path * @param valueRange - Range of values of interest * @param width - Width of the generated image * @param height - Height of the generated image * @throws IOException */ public static void drawScale(Path output, MinMax valueRange, int width, int height) throws IOException { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setBackground(Color.BLACK); g.clearRect(0, 0, width, height); // fix this part to work according to color1, color2 and gradient type for (int y = 0; y < height; y++) { Color color = NASARectangle.calculateColor(y); g.setColor(color); g.drawRect(width * 3 / 4, y, width / 4, 1); } int fontSize = 24; g.setFont(new Font("Arial", Font.BOLD, fontSize)); int step = (valueRange.maxValue - valueRange.minValue) * fontSize * 10 / height; step = (int) Math.pow(10, Math.round(Math.log10(step))); int min_value = valueRange.minValue / step * step; int max_value = valueRange.maxValue / step * step; for (int value = min_value; value <= max_value; value += step) { int y = fontSize + (height - fontSize) - value * (height - fontSize) / (valueRange.maxValue - valueRange.minValue); g.setColor(Color.WHITE); g.drawString(String.valueOf(value), 5, y); } g.dispose(); FileSystem fs = output.getFileSystem(new Configuration()); FSDataOutputStream outStream = fs.create(output, true); ImageIO.write(image, "png", outStream); outStream.close(); }
From source file:common.utils.ImageUtils.java
/** * * @param src images to draw, they must be resized to an appropriate size * @param dst image where given images will be drawen */// w w w. j av a 2 s .c om public static void draw4on1(BufferedImage[] src, BufferedImage dst) { Graphics2D g2 = dst.createGraphics(); g2.setColor(java.awt.Color.WHITE); g2.fillRect(0, 0, dst.getWidth(), dst.getHeight()); int dxi; int dyi = 0; int x0 = dst.getWidth() - 5; int y0 = 5; int x = x0; int y = y0; for (int i = 0; i < src.length; i++) { if (i % 2 == 0) { dxi = -10; } else { dxi = 0; } //g2.draw3DRect(dx - 1 , dy-tmp_bi.getHeight() - 1, tmp_bi.getWidth() + 1 , tmp_bi.getHeight() + 1, true); g2.drawImage(src[i], x - src[i].getWidth() + dxi, y + dyi, null); g2.drawString("#" + i, x - src[i].getWidth() + dxi, y + dyi + 20); //g2.rotate(Math.toRadians(4)); y = y + src[i].getHeight() / 2; if (y > dst.getHeight() - src[i].getHeight()) { y = y0; if (dyi == 0) dyi = 10; else dyi = 0; if (x < src[i].getWidth()) { x = dst.getWidth(); } x = x - src[i].getWidth() / 2; } } g2.setColor(Color.gray); g2.drawRect(0, 0, dst.getWidth() - 1, dst.getHeight() - 1); g2.dispose(); }
From source file:com.us.servlet.AuthCode.java
protected void service(HttpServletRequest request, HttpServletResponse response) { final CodeAuth bean = AppHelper.CODE_AUTH; int width = NumberUtils.toInt(request.getParameter("width"), bean.getWidth()); int height = NumberUtils.toInt(request.getParameter("height"), bean.getHeight()); int x = width / (bean.getLength() + 1); int codeY = height - 4; int fontHeight = height - 2; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = image.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); if (StringUtil.hasText(request.getParameter("bgcolor"))) { graphics.setBackground(ColorHelper.hex2RGB(request.getParameter("bgcolor"))); }/*w w w . j a v a 2 s . c o m*/ graphics.fillRect(0, 0, width, height); graphics.setFont(new Font(bean.getFont(), Font.BOLD, fontHeight)); graphics.drawRect(0, 0, width - 1, height - 1); // if (bean.isBreakLine()) { for (int i = 0; i < 15; i++) { int x1 = RandomUtils.nextInt(width); int y1 = RandomUtils.nextInt(height); int x2 = RandomUtils.nextInt(12); int y2 = RandomUtils.nextInt(12); graphics.drawLine(x1, y1, x + x2, y1 + y2); } } char[] CHARSET_AREA = null; if (bean.getType().charAt(0) == '1') { CHARSET_AREA = ArrayUtils.addAll(CHARSET_AREA, BIG_LETTERS); } if (bean.getType().charAt(1) == '1') { CHARSET_AREA = ArrayUtils.addAll(CHARSET_AREA, SMALL_LETTER); } if (bean.getType().charAt(2) == '1') { CHARSET_AREA = ArrayUtils.addAll(CHARSET_AREA, NUMBERS); } StringBuilder randomCode = new StringBuilder(); for (int i = 0; i < bean.getLength(); i++) { String rand = String.valueOf(CHARSET_AREA[RandomUtils.nextInt(CHARSET_AREA.length)]); graphics.setColor(ColorHelper.color(RandomUtils.nextInt(255), RandomUtils.nextInt(255), RandomUtils.nextInt(255))); graphics.drawString(rand, (i + 1) * x, codeY); randomCode.append(rand); } HttpSession session = request.getSession(); session.setAttribute(bean.getSessionKey(), randomCode.toString()); // ? response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/png"); try { // Servlet? ServletOutputStream sos = response.getOutputStream(); ImageIO.write(image, "png", sos); sos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:edworld.pdfreader4humans.PDFReader.java
private void draw(Component component, Graphics2D graphics, Color inkColor, Color backgroundColor, boolean showStructure, Map<String, Font> fonts) { for (Component child : component.getChildren()) draw(child, graphics, inkColor, backgroundColor, showStructure, fonts); if (component instanceof BoxComponent && showStructure) { graphics.setColor(boxColor(backgroundColor)); graphics.drawRect((int) component.getFromX(), (int) component.getFromY(), (int) component.getWidth(), (int) component.getHeight()); graphics.setColor(inkColor);/* ww w. jav a2s . c o m*/ } else if (component instanceof GroupComponent && showStructure) { graphics.setColor(groupColor(backgroundColor)); graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); graphics.setColor(inkColor); } else if (component instanceof MarginComponent && showStructure) { graphics.setColor(marginColor(backgroundColor)); graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); graphics.setColor(inkColor); } else if (component.getType().equals("line")) graphics.drawLine(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getToX()), Math.round(component.getToY())); else if (component.getType().equals("rect")) graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); else if (component instanceof TextComponent) { graphics.setFont(font((TextComponent) component, fonts)); graphics.drawString(((TextComponent) component).getText(), component.getFromX(), component.getToY()); } }