List of usage examples for java.awt Graphics2D setFont
public abstract void setFont(Font font);
From source file:pl.edu.icm.visnow.lib.basic.viewers.Viewer2D.Display2DPanel.java
@Override public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; Font f = g2d.getFont();/*ww w.j a va 2s. c om*/ Color c = g2d.getColor(); Rectangle clear = new Rectangle(0, 0, getWidth(), getHeight()); g2d.setPaint(bgColor); g2d.fill(clear); draw2D(g2d); g2d.setFont(titleFont); g2d.setColor(titleColor); g2d.drawString(titleText, 50, 10 + titleFont.getSize()); g2d.setFont(f); g2d.setColor(c); if (storingFrames && !dontWrite) { if (storingJPEG) { writeImage(controlsFrame.getMovieCreationPanel().getCurrentFrameFileName(), FORMAT_JPEG); } else { writeImage(controlsFrame.getMovieCreationPanel().getGenericFrameFileName(), FORMAT_PNG); } } }
From source file:edu.kit.dama.ui.components.TextImage.java
/** * Get the bytes of the final image./* www.j a v a 2s. c om*/ * * @return The byte array containing the bytes of the resulting image. * * @throws IOException if creating the image fails. */ public byte[] getBytes() throws IOException { Image transparentImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource( new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB).getSource(), new RGBImageFilter() { @Override public final int filterRGB(int x, int y, int rgb) { return (rgb << 8) & 0xFF000000; } })); //create the actual image and overlay it by the transparent background BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = outputImage.createGraphics(); g2d.drawImage(transparentImage, 0, 0, null); //draw the remaining stuff g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setColor(color); g2d.fillRoundRect(0, 0, size, size, 20, 20); g2d.setColor(new Color(Math.round((float) color.getRed() * .9f), Math.round((float) color.getGreen() * .9f), Math.round((float) color.getBlue() * .9f))); g2d.drawRoundRect(0, 0, size - 1, size - 1, 20, 20); Font font = new Font("Dialog", Font.BOLD, size - 4); g2d.setFont(font); g2d.setColor(Color.WHITE); String s = text.toUpperCase().substring(0, 1); FontMetrics fm = g2d.getFontMetrics(); float x = ((float) size - (float) fm.stringWidth(s)) / 2f; float y = ((float) fm.getAscent() + (float) ((float) size - ((float) fm.getAscent() + (float) fm.getDescent())) / 2f) - 1f; g2d.drawString(s, x, y); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ImageIO.write(outputImage, "png", bout); g2d.dispose(); return bout.toByteArray(); }
From source file:net.rptools.maptool.client.ui.ChatTypingNotification.java
/** * This component is only made visible when there are notifications to be displayed. That means the first couple of * IF statements in this method are redundant since paintComponent() will not be called unless the component is * visible, and it will only be visible when there are notifications... *//*from w w w . j a va 2 s . c o m*/ @Override protected void paintComponent(Graphics g) { // System.out.println("Chat panel is painting itself..."); if (AppPreferences.getTypingNotificationDuration() == 0) { return; } LinkedMap chatTypers = MapTool.getFrame().getChatNotificationTimers().getChatTypers(); if (chatTypers == null || chatTypers.isEmpty()) { return; } Boolean showBackground = AppPreferences.getChatNotificationShowBackground(); Graphics2D statsG = (Graphics2D) g.create(); Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD); Font font = AppStyle.labelFont; FontMetrics valueFM = g.getFontMetrics(font); FontMetrics keyFM = g.getFontMetrics(boldFont); int PADDING7 = 7; int PADDING3 = 3; int PADDING2 = 2; BufferedImage img = AppStyle.panelTexture; int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight()); setBorder(null); int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin(); int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin(); statsG.setFont(font); SwingUtil.useAntiAliasing(statsG); Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(), height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width, getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin() + PADDING2); int y = bounds.y + rowHeight; rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight()); setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight)) + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin())); if (showBackground) { g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this); AppStyle.miniMapBorder.paintAround(statsG, bounds); } Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7, AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(), AppStyle.chatImage.getHeight()); Set<?> keySet = chatTypers.keySet(); @SuppressWarnings("unchecked") Set<String> playerTimers = (Set<String>) keySet; for (String playerNamer : playerTimers) { if (showBackground) { statsG.setColor(new Color(249, 241, 230, 140)); statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); statsG.setColor(new Color(175, 163, 149)); statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); } g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(), (int) rightRow.getHeight(), this); // Values statsG.setColor(MapTool.getFrame().getChatTypingLabelColor()); statsG.setFont(boldFont); statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer), bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5); y += PADDING2 + rowHeight; } if (showBackground) { AppStyle.shadowBorder.paintWithin(statsG, bounds); } else { setOpaque(false); } }
From source file:com.celements.photo.image.GenerateThumbnail.java
private void drawCopyright(String copyright, Graphics2D g2d, int width, int height) { int bottomSpace = 5; //space between copyright and bottom border. int rightSpace = 5; //space between copyright and right border. int hSpacing = 3; //horizontal space between background and string. int vSpacing = 2; //vertical space between background and string. int rounding = 5; //rounding of the rect. FontMetrics metrics = calcCopyrightFontSize(copyright, width, g2d); g2d.setFont(metrics.getFont()); int stringHeight = metrics.getHeight(); drawBackground(copyright, width, height, bottomSpace, rightSpace, vSpacing, hSpacing, rounding, stringHeight, metrics, g2d); drawString(copyright, width, height, bottomSpace, rightSpace, vSpacing, hSpacing, metrics, g2d); }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
private void renderDayMarkers(long pStart, long pEnd, Graphics2D pG2D) { Date d = new Date(pStart); d = DateUtils.setHours(d, 0);//from www . j a v a2 s .c om d = DateUtils.setMinutes(d, 0); d = DateUtils.setSeconds(d, 0); d = DateUtils.setMilliseconds(d, 0); for (long mark = d.getTime(); mark <= pEnd; mark += DateUtils.MILLIS_PER_HOUR) { int markerPos = Math.round((mark - pStart) / DateUtils.MILLIS_PER_MINUTE); pG2D.setColor(Color.YELLOW); pG2D.fillRect(markerPos, 20, 2, 10); pG2D.setColor(Color.WHITE); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f)); pG2D.fillRect(markerPos - 5, 15, 12, 10); pG2D.setColor(Color.BLACK); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(mark)); NumberFormat f = NumberFormat.getNumberInstance(); f.setMinimumIntegerDigits(2); f.setMaximumFractionDigits(2); pG2D.drawString(f.format(cal.get(Calendar.HOUR_OF_DAY)), markerPos - 5, 23); } long currentDay = d.getTime(); while (currentDay < pEnd) { currentDay += DateUtils.MILLIS_PER_DAY; int markerPos = Math.round((currentDay - pStart) / DateUtils.MILLIS_PER_MINUTE); pG2D.setColor(new Color(123, 123, 123)); pG2D.fillRect(markerPos, 15, 3, 30); SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy"); String dayLabel = f.format(currentDay); Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(dayLabel, pG2D); pG2D.setColor(Color.YELLOW); int labelWidth = (int) labelBounds.getWidth() + 5; pG2D.fillRect(markerPos - (int) Math.rint(labelWidth / 2), 15, labelWidth, 10); pG2D.setColor(Color.BLACK); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f)); pG2D.drawString(dayLabel, markerPos - (int) Math.rint(labelWidth / 2) + 2, 23); } }
From source file:hudson.util.NoOverlapCategoryAxis.java
@Override protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) { if (state == null) { throw new IllegalArgumentException("Null 'state' argument."); }/*from w w w. jav a2s . c om*/ if (isTickLabelsVisible()) { java.util.List ticks = refreshTicks(g2, state, plotArea, edge); state.setTicks(ticks); // remember the last drawn label so that we can avoid drawing overlapping labels. Rectangle2D r = null; int categoryIndex = 0; Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { CategoryTick tick = (CategoryTick) iterator.next(); g2.setFont(getTickLabelFont(tick.getCategory())); g2.setPaint(getTickLabelPaint(tick.getCategory())); CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge); double x0 = 0.0; double x1 = 0.0; double y0 = 0.0; double y1 = 0.0; if (edge == RectangleEdge.TOP) { x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); y1 = state.getCursor() - this.getCategoryLabelPositionOffset(); y0 = y1 - state.getMax(); } else if (edge == RectangleEdge.BOTTOM) { x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); y0 = state.getCursor() + this.getCategoryLabelPositionOffset(); y1 = y0 + state.getMax(); } else if (edge == RectangleEdge.LEFT) { y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); x1 = state.getCursor() - this.getCategoryLabelPositionOffset(); x0 = x1 - state.getMax(); } else if (edge == RectangleEdge.RIGHT) { y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); x0 = state.getCursor() + this.getCategoryLabelPositionOffset(); x1 = x0 - state.getMax(); } Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0)); if (r == null || !r.intersects(area)) { Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor()); TextBlock block = tick.getLabel(); block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); if (plotState != null && plotState.getOwner() != null) { EntityCollection entities = plotState.getOwner().getEntityCollection(); if (entities != null) { String tooltip = getCategoryLabelToolTip(tick.getCategory()); entities.add(new CategoryLabelEntity(tick.getCategory(), bounds, tooltip, null)); } } r = bounds.getBounds2D(); } categoryIndex++; } if (edge.equals(RectangleEdge.TOP)) { double h = state.getMax(); state.cursorUp(h); } else if (edge.equals(RectangleEdge.BOTTOM)) { double h = state.getMax(); state.cursorDown(h); } else if (edge == RectangleEdge.LEFT) { double w = state.getMax(); state.cursorLeft(w); } else if (edge == RectangleEdge.RIGHT) { double w = state.getMax(); state.cursorRight(w); } } return state; }
From source file:org.csml.tommo.sugar.modules.MappingQuality.java
private void writeImage2HTML(HTMLReportArchive report, LaneCoordinates laneCoordinates, TileNumeration tileNumeration) throws IOException { final MappingQualityTableModel model = new MappingQualityTableModel(this, laneCoordinates, tileNumeration); ZipOutputStream zip = report.zipFile(); StringBuffer b = report.htmlDocument(); StringBuffer d = report.dataDocument(); int imgSize = Options.getHeatmapImageSize() + 1; // add one pixel for internal grid int width = imgSize * model.getColumnCount() + 1; // add one pixel for left border int topBottomSeparator = 50; if (model.getTopBottomSeparatorColumn() > 0) { width += topBottomSeparator; // add top bottom separator }//from www . j av a2 s . c o m int height = imgSize * model.getRowCount() + 1; // add one pixel for top border int yOffset = 10 * model.getTileNumeration().getCycleSize(); // space for column header int xOffset = 50; // space for row header BufferedImage fullImage = new BufferedImage(width + xOffset, height + yOffset, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) fullImage.getGraphics(); Color headerBackground = new Color(0x00, 0x00, 0x80); Color headerForeground = Color.WHITE; // Do the headers d.append("#Tiles: "); d.append("\t"); g2.setColor(headerBackground); g2.fillRect(0, height, width + xOffset, yOffset); g2.fillRect(width, 0, xOffset, height + yOffset); g2.setColor(headerForeground); g2.setFont(g2.getFont().deriveFont(7f).deriveFont(Font.BOLD)); drawColumnHeader(g2, model, imgSize, topBottomSeparator, height, d); g2.setFont(g2.getFont().deriveFont(9f).deriveFont(Font.BOLD)); drawRowHeader(g2, model, imgSize, width, xOffset); long before = System.currentTimeMillis(); for (int r = 0; r < model.getRowCount(); r++) { int separator = 0; for (int c = 0; c < model.getColumnCount(); c++) { TileCoordinates tileCoordinate = model.getCoordinateAt(r, c); MappingQualityMatrix matrix = getMeanQualityMatrix(tileCoordinate); if (matrix != null) { if (r < MappingQualityMatrix.THRESHOLDS.length) { ColorPaintScale paintScale = MappingQualityCellRenderer.getThresholdPaintScale(); BufferedImage image = (BufferedImage) matrix .createBufferedImageForThreshold(MappingQualityMatrix.THRESHOLDS[r], paintScale); g2.drawImage(image, 1 + imgSize * c + separator, 1 + imgSize * r, imgSize * (c + 1) + separator, imgSize * (r + 1), 0, 0, image.getWidth(), image.getHeight(), null); } else { ColorPaintScale paintScale = MappingQualityCellRenderer.getAveragePaintScale(); BufferedImage image = (BufferedImage) matrix.createBufferedImage(paintScale); g2.drawImage(image, 1 + imgSize * c + separator, 1 + imgSize * r, imgSize * (c + 1) + separator, imgSize * (r + 1), 0, 0, image.getWidth(), image.getHeight(), null); } } else { d.append("Missing matrix for: " + tileCoordinate + "\n"); } if (c == model.getTopBottomSeparatorColumn()) { separator = topBottomSeparator; } } } g2.dispose(); String imgFileName = "quality_matrix_" + laneCoordinates.getFlowCell() + "_" + laneCoordinates.getLane() + ".png"; zip.putNextEntry(new ZipEntry(report.folderName() + "/Images/" + imgFileName)); ImageIO.write(fullImage, "png", zip); b.append("<img src=\"Images/" + imgFileName + "\" alt=\"full image\">\n"); long after = System.currentTimeMillis(); d.append("Creating report time: " + (after - before)); }
From source file:org.squidy.designer.knowledgebase.RepositoryItem.java
@Override protected void paintShapeZoomedIn(PPaintContext paintContext) { super.paintShapeZoomedIn(paintContext); Graphics2D g = paintContext.getGraphics(); String information = "N/A"; if (information != null) { PBounds bounds = getBoundsReference(); double x = bounds.getX(); double width = bounds.getWidth(); String source = "Source: " + information; g.setFont(fontName); g.drawString(getProcessableClass().getSimpleName(), (int) (x + 100), 80); g.setFont(fontSource);/*from ww w . ja v a 2 s. c om*/ g.drawString(source, (int) (x + width - FontUtils.getWidthOfText(g.getFontMetrics(), source)) - 20, 130); } }
From source file:business.model.CaptchaModel.java
/** * * @param CaptchaText// w w w .j a v a2s. c o m * @return */ public static BufferedImage CreateCaptchaImageOld(String CaptchaText) { BufferedImage localBufferedImage = new BufferedImage(width, height, 1); try { Graphics2D localGraphics2D = localBufferedImage.createGraphics(); // List<Font> fonts = FontFactory.getListFont(); List<Font> fonts = new ArrayList<Font>(); if (fonts.isEmpty()) { fonts.add(new Font("Nimbus Roman No9 L", 1, 30)); fonts.add(new Font("VN-NTime", 1, 30)); fonts.add(new Font("DT-Times", 1, 30)); fonts.add(new Font("Times New Roman", 1, 30)); fonts.add(new Font("Vni-Book123", 1, 30)); fonts.add(new Font("VNI-Centur", 1, 30)); fonts.add(new Font("DT-Brookly", 1, 30)); } // fonts.add(loadFont("BINHLBI.TTF")); RenderingHints localRenderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); localRenderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); localGraphics2D.setRenderingHints(localRenderingHints); localGraphics2D.fillRect(0, 0, width, height); localGraphics2D.setColor(new Color(50, 50, 50)); Random localRandom = new Random(); int i = 0; int j = 0; for (int k = 0; k < CaptchaText.length(); k++) { i += 25 + Math.abs(localRandom.nextInt()) % 5; j = 25 + Math.abs(localRandom.nextInt()) % 20; int tmp = localRandom.nextInt(fonts.size() - 1); localGraphics2D.setFont(fonts.get(tmp)); localGraphics2D.drawChars(CaptchaText.toCharArray(), k, 1, i, j); } localBufferedImage = getDistortedImage(localBufferedImage); Graphics2D localGraphics2D2 = localBufferedImage.createGraphics(); localGraphics2D2.setRenderingHints(localRenderingHints); // localGraphics2D2.fillRect(0, 0, width, height); localGraphics2D2.setColor(new Color(50, 50, 50)); CubicCurve2D c = new CubicCurve2D.Double();// draw QuadCurve2D.Float with set coordinates for (int l = 0; l < 7; l++) { int x1 = Util.rand(0, width / 2); ; int x2 = Util.rand(width / 2, width); int y1 = Util.rand(0, height); int y2 = Util.rand(0, height); int ctrlx1 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly1 = y1; int ctrlx2 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly2 = y2; c.setCurve(x1, y1, ctrlx2, ctrly2, ctrlx1, ctrly1, x2, y2); localGraphics2D2.draw(c); // localGraphics2D2.drawLine(randomX1(), randomY1(), randomX2(), randomY2()); } localGraphics2D.dispose(); } catch (Exception e) { log.error(e.getMessage(), e); return null; } return localBufferedImage; }
From source file:gda.plots.SimpleXYAnnotation.java
/** * Implements the XYAnnotation interface. This is actually a copy of the superclass method EXCEPT: it adds the shape * to the entity list based on the value of clickable and not whether or not there is a ToolTip; and it save the * hotpsot so that it can recognize when it is the clicked entity. * //www . java2s . co m * @param g2 * the graphics device. * @param plot * the plot. * @param dataArea * the data area. * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param rendererIndex * the renderer index. * @param info * an optional info object that will be populated with entity information. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); float anchorX = (float) domainAxis.valueToJava2D(getX(), dataArea, domainEdge); float anchorY = (float) rangeAxis.valueToJava2D(getY(), dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { float tempAnchor = anchorX; anchorX = anchorY; anchorY = tempAnchor; } g2.setFont(getFont()); g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); hotspot = TextUtilities.calculateRotatedStringBounds(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); String toolTip = getToolTipText(); String url = getURL(); if (clickable || toolTip != null || url != null) { addEntity(info, hotspot, rendererIndex, toolTip, url); } }