List of usage examples for java.awt Graphics2D setFont
public abstract void setFont(Font font);
From source file:edu.ucla.stat.SOCR.chart.gui.ExtendedStackedBarRenderer.java
/** * Draws a stacked bar for a specific item. * * @param g2 the graphics device.// w w w . j av a2 s . co m * @param state the renderer state. * @param dataArea the plot area. * @param plot the plot. * @param domainAxis the domain (category) axis. * @param rangeAxis the range (value) axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // nothing is drawn for null values... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } double value = dataValue.doubleValue(); PlotOrientation orientation = plot.getOrientation(); double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0; double positiveBase = 0.0; double negativeBase = 0.0; for (int i = 0; i < row; i++) { Number v = dataset.getValue(i, column); if (v != null) { double d = v.doubleValue(); if (d > 0) { positiveBase = positiveBase + d; } else { negativeBase = negativeBase + d; } } } double translatedBase; double translatedValue; RectangleEdge location = plot.getRangeAxisEdge(); if (value > 0.0) { translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location); } else { translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location); } double barL0 = Math.min(translatedBase, translatedValue); double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength()); Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } if (value > 0.0) { if (this.showPositiveTotal) { if (isLastPositiveItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); double total = calculateSumOfPositiveValuesForCategory(dataset, column); if (orientation == PlotOrientation.HORIZONTAL) TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) (bar.getMaxX() + 5.0), (float) bar.getCenterY(), TextAnchor.CENTER_LEFT, 0.0, TextAnchor.CENTER_LEFT); else TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) bar.getCenterX(), (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER, 0.0, TextAnchor.BOTTOM_CENTER); } } } else { if (this.showNegativeTotal) { if (isLastNegativeItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); double total = calculateSumOfNegativeValuesForCategory(dataset, column); if (orientation == PlotOrientation.HORIZONTAL) TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) (bar.getMinX() - 5.0), (float) bar.getCenterY(), TextAnchor.CENTER_RIGHT, 0.0, TextAnchor.CENTER_RIGHT); else TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(), (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER); } } } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } }
From source file:paquete.HollywoodUI.java
public void printActores() { this.actoresArray = new ArrayList<>(this.HollyUniverseGraph.getVertices()); try {/*from ww w .j a va2s . c o m*/ int cant_actores = 0; grafico = ImageIO.read(new File("./src/sources/hollywoodUniverseV2.jpg")); Graphics2D g = grafico.createGraphics(); Actor a = null; for (Actor temp_actor : actoresArray) { a = temp_actor; g.setColor(Color.GREEN); g.setFont(new Font("SansSerif", Font.BOLD, 11)); if (cant_actores == 0) { g.drawImage(temp_actor.getFoto_actor(), null, 150, 25); grafico.setRGB(150 + temp_actor.getFoto_actor().getWidth() / 2, 25 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB()); a.setArea(150, 150 + temp_actor.getFoto_actor().getWidth(), 25, 25 + temp_actor.getFoto_actor().getHeight()); g.drawString(a.getNombre(), 150 - 20, 20); a.setLocation(150 + temp_actor.getFoto_actor().getWidth() / 2, 25 + temp_actor.getFoto_actor().getHeight() / 2); } else { if (cant_actores == 1) { g.drawImage(temp_actor.getFoto_actor(), null, 300, 85); grafico.setRGB(300 + temp_actor.getFoto_actor().getWidth() / 2, 85 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB()); a.setArea(300, 300 + temp_actor.getFoto_actor().getWidth(), 85, 85 + temp_actor.getFoto_actor().getHeight()); g.drawString(a.getNombre(), 300, 80); a.setLocation(300 + temp_actor.getFoto_actor().getWidth() / 2, 85 + temp_actor.getFoto_actor().getHeight() / 2); } else { if (cant_actores == 2) { g.drawImage(temp_actor.getFoto_actor(), null, 475, 25); grafico.setRGB(475 + temp_actor.getFoto_actor().getWidth() / 2, 25 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB()); a.setArea(475, 475 + temp_actor.getFoto_actor().getWidth(), 25, 25 + temp_actor.getFoto_actor().getHeight()); g.drawString(a.getNombre(), 475, 25); a.setLocation(475 + temp_actor.getFoto_actor().getWidth() / 2, 25 + temp_actor.getFoto_actor().getHeight() / 2); } else if (cant_actores == 3) { g.drawImage(temp_actor.getFoto_actor(), null, 50, 225); grafico.setRGB(50 + temp_actor.getFoto_actor().getWidth() / 2, 225 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB()); a.setArea(50, 50 + temp_actor.getFoto_actor().getWidth(), 225, 225 + temp_actor.getFoto_actor().getHeight()); g.drawString(a.getNombre(), 50, 220); a.setLocation(50 + temp_actor.getFoto_actor().getWidth() / 2, 225 + temp_actor.getFoto_actor().getHeight() / 2); } else if (cant_actores == 4) { g.drawImage(temp_actor.getFoto_actor(), null, 300, 200); grafico.setRGB(300 + temp_actor.getFoto_actor().getWidth() / 2, 200 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB()); a.setArea(300, 300 + temp_actor.getFoto_actor().getWidth(), 200, 200 + temp_actor.getFoto_actor().getHeight()); g.drawString(a.getNombre(), 300, 195); a.setLocation(300 + temp_actor.getFoto_actor().getWidth() / 2, 200 + temp_actor.getFoto_actor().getHeight() / 2); } else if (cant_actores == 5) { g.drawImage(temp_actor.getFoto_actor(), null, 575, 225); grafico.setRGB(575 + temp_actor.getFoto_actor().getWidth() / 2, 225 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB()); a.setArea(575, 575 + temp_actor.getFoto_actor().getWidth(), 225, 225 + temp_actor.getFoto_actor().getHeight()); g.drawString(a.getNombre(), 575, 220); a.setLocation(575 + temp_actor.getFoto_actor().getWidth() / 2, 225 + temp_actor.getFoto_actor().getHeight() / 2); } else if (cant_actores == 6) { g.drawImage(temp_actor.getFoto_actor(), null, 150, 415); grafico.setRGB(150 + temp_actor.getFoto_actor().getWidth() / 2, 415 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB()); g.drawString(a.getNombre(), 150, 410); a.setArea(150, 150 + temp_actor.getFoto_actor().getWidth(), 425, 415 + temp_actor.getFoto_actor().getHeight()); a.setLocation(150 + temp_actor.getFoto_actor().getWidth() / 2, 415 + temp_actor.getFoto_actor().getHeight() / 2); } else if (cant_actores == 7) { g.drawImage(temp_actor.getFoto_actor(), null, 300, 350); grafico.setRGB(300 + temp_actor.getFoto_actor().getWidth() / 2, 350 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB()); a.setArea(300, 300 + temp_actor.getFoto_actor().getWidth(), 350, 350 + temp_actor.getFoto_actor().getHeight()); g.drawString(a.getNombre(), 300, 345); a.setLocation(300 + temp_actor.getFoto_actor().getWidth() / 2, 350 + temp_actor.getFoto_actor().getHeight() / 2); } else if (cant_actores == 8) { g.drawImage(temp_actor.getFoto_actor(), null, 475, 415); grafico.setRGB(475 + temp_actor.getFoto_actor().getWidth() / 2, 415 + temp_actor.getFoto_actor().getHeight() / 2, Color.WHITE.getRGB()); a.setArea(475, 475 + temp_actor.getFoto_actor().getWidth(), 415, 415 + temp_actor.getFoto_actor().getHeight()); g.drawString(a.getNombre(), 475, 410); a.setLocation(475 + temp_actor.getFoto_actor().getWidth() / 2, 415 + temp_actor.getFoto_actor().getHeight() / 2); } } } cant_actores++; } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Ocurrio un error inesperado en el sistema", "ERROR", JOptionPane.ERROR_MESSAGE); } dibujarAristas(); }
From source file:com.flexoodb.common.FlexUtils.java
static public void createTextBanner(String text, int fontsize, int width, int height, int x, int y, String outputfile) throws Exception { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); img.createGraphics();//ww w .j av a2 s .c om Graphics2D g = (Graphics2D) img.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, img.getWidth(), img.getHeight()); Font font = new Font("Arial", Font.BOLD, fontsize); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); g.setFont(font); g.setColor(Color.BLUE.darker()); g.drawString(text, x, y); ImageIO.write(img, "png", new File(outputfile)); }
From source file:com.flexoodb.common.FlexUtils.java
static public BufferedImage createCaptcha(String text, Color background, Color fontcolor, int fontsize, int width, int height, int x, int y) throws Exception { BufferedImage img = new BufferedImage(width + 10, height, BufferedImage.TYPE_INT_RGB); img.createGraphics();//from w w w . j a va 2s . co m Graphics2D g = (Graphics2D) img.getGraphics(); g.setColor(background); g.fillRect(0, 0, img.getWidth(), img.getHeight()); Font font = new Font("Monospaced", Font.BOLD + Font.ITALIC, fontsize); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); g.setFont(font); g.setColor(fontcolor); char[] c = text.toCharArray(); java.util.Random random = new java.util.Random(); for (int i = 0; i < c.length; i++) { int j = random.nextInt(9); if (j > 5) { j = j - 5; } else { j = -1 * (j - 2); } char[] c1 = new char[1]; c1[0] = c[i]; g.drawChars(c1, 0, 1, x + (i * 16), y + j); } for (int i = -10; i < 20; i++) { int j = random.nextInt(8); g.drawOval((i + j) - 20, ((i * 8) - (j > 3 ? 4 : -4)), width + 20, height); } //ImageIO.write(img,"png",new File(outputfile)); return img; }
From source file:org.jfree.chart.demo.ExtendedStackedBarRenderer.java
/** * Draws a stacked bar for a specific item. * * @param g2 the graphics device.//from w ww . j a v a2s .c o m * @param state the renderer state. * @param dataArea the plot area. * @param plot the plot. * @param domainAxis the domain (category) axis. * @param rangeAxis the range (value) axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). */ public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column) { // nothing is drawn for null values... final Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } final double value = dataValue.doubleValue(); final PlotOrientation orientation = plot.getOrientation(); final double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0; double positiveBase = 0.0; double negativeBase = 0.0; for (int i = 0; i < row; i++) { final Number v = dataset.getValue(i, column); if (v != null) { final double d = v.doubleValue(); if (d > 0) { positiveBase = positiveBase + d; } else { negativeBase = negativeBase + d; } } } final double translatedBase; final double translatedValue; final RectangleEdge location = plot.getRangeAxisEdge(); if (value > 0.0) { translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location); } else { translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location); } final double barL0 = Math.min(translatedBase, translatedValue); final double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength()); Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } final Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } // final CategoryLabelGenerator generator = getLabelGenerator(row, column); // if (generator != null && isItemLabelVisible(row, column)) { // drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); // } if (value > 0.0) { if (this.showPositiveTotal) { if (isLastPositiveItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); final double total = calculateSumOfPositiveValuesForCategory(dataset, column); // RefineryUtilities.drawRotatedString( // this.totalFormatter.format(total), g2, // (float) bar.getCenterX(), // (float) (bar.getMinY() - 4.0), /// TextAnchor.BOTTOM_CENTER, // TextAnchor.BOTTOM_CENTER, // 0.0 // ); } } } else { if (this.showNegativeTotal) { if (isLastNegativeItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); final double total = calculateSumOfNegativeValuesForCategory(dataset, column); /* RefineryUtilities.drawRotatedString( String.valueOf(total), g2, (float) bar.getCenterX(), (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER, 0.0 ); */ } } } // collect entity and tool tip information... if (state.getInfo() != null) { final EntityCollection entities = state.getInfo().getOwner().getEntityCollection(); if (entities != null) { String tip = null; final CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } final CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, row, dataset.getColumnKey(column), column); // entities.addEntity(entity); } } }
From source file:org.trade.ui.chart.renderer.PivotRenderer.java
/** * Draws the annotation.//from ww w . j ava2 s. c o 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 * the plot rendering info. * @param angle * double * @param x * double * @param y * double * @param ledgend * String */ public void drawPivotArrow(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info, double angle, double x, double y, String ledgend) { double tipRadius = DEFAULT_TIP_RADIUS; double baseRadius = DEFAULT_BASE_RADIUS; double arrowLength = DEFAULT_ARROW_LENGTH; double arrowWidth = DEFAULT_ARROW_WIDTH; double labelOffset = DEFAULT_LABEL_OFFSET; Font font = DEFAULT_FONT; Paint paint = DEFAULT_PAINT; boolean outlineVisible = false; Paint outlinePaint = Color.black; Stroke outlineStroke = new BasicStroke(0.5f); TextAnchor textAnchor = DEFAULT_TEXT_ANCHOR; TextAnchor rotationAnchor = DEFAULT_ROTATION_ANCHOR; double rotationAngle = DEFAULT_ROTATION_ANGLE; Stroke arrowStroke = new BasicStroke(1.0f); Paint arrowPaint = Color.black; PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); double j2DX = domainAxis.valueToJava2D(x, dataArea, domainEdge); double j2DY = rangeAxis.valueToJava2D(y, dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { double temp = j2DX; j2DX = j2DY; j2DY = temp; } double startX = j2DX + (Math.cos(angle) * baseRadius); double startY = j2DY + (Math.sin(angle) * baseRadius); double endX = j2DX + (Math.cos(angle) * tipRadius); double endY = j2DY + (Math.sin(angle) * tipRadius); double arrowBaseX = endX + (Math.cos(angle) * arrowLength); double arrowBaseY = endY + (Math.sin(angle) * arrowLength); double arrowLeftX = arrowBaseX + (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth); double arrowLeftY = arrowBaseY + (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth); double arrowRightX = arrowBaseX - (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth); double arrowRightY = arrowBaseY - (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth); GeneralPath arrow = new GeneralPath(); arrow.moveTo((float) endX, (float) endY); arrow.lineTo((float) arrowLeftX, (float) arrowLeftY); arrow.lineTo((float) arrowRightX, (float) arrowRightY); arrow.closePath(); g2.setStroke(arrowStroke); g2.setPaint(arrowPaint); Line2D line = new Line2D.Double(startX, startY, endX, endY); g2.draw(line); g2.fill(arrow); // draw the label double labelX = j2DX + (Math.cos(angle) * (baseRadius + labelOffset)); double labelY = j2DY + (Math.sin(angle) * (baseRadius + labelOffset)); g2.setFont(font); Shape hotspot = TextUtilities.calculateRotatedStringBounds(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle, rotationAnchor); g2.setPaint(paint); TextUtilities.drawRotatedString(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle, rotationAnchor); if (outlineVisible) { g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(hotspot); } // String toolTip = getToolTipText(); // String url = getURL(); // if (toolTip != null || url != null) { // addEntity(info, hotspot, rendererIndex, toolTip, url); // } }
From source file:spinworld.gui.RadarPlot.java
/** * Draws the label for one axis./*w ww.java 2s.c o m*/ * * @param g2 the graphics device. * @param plotArea whole plot drawing area (e.g. including space for labels) * @param plotDrawingArea the plot drawing area (just spanning of axis) * @param value the value of the label (ignored). * @param cat the category (zero-based index). * @param startAngle the starting angle. * @param extent the extent of the arc. */ protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, Rectangle2D plotDrawingArea, double value, int cat, double startAngle, double extent) { FontRenderContext frc = g2.getFontRenderContext(); String label = null; if (this.dataExtractOrder == TableOrder.BY_ROW) { // if series are in rows, then the categories are the column keys label = this.labelGenerator.generateColumnLabel(this.dataset, cat); } else { // if series are in columns, then the categories are the row keys label = this.labelGenerator.generateRowLabel(this.dataset, cat); } double angle = normalize(startAngle); Font font = getLabelFont(); Point2D labelLocation; do { Rectangle2D labelBounds = font.getStringBounds(label, frc); LineMetrics lm = font.getLineMetrics(label, frc); double ascent = lm.getAscent(); labelLocation = calculateLabelLocation(labelBounds, ascent, plotDrawingArea, startAngle); boolean leftOut = angle > 90 && angle < 270 && labelLocation.getX() < plotArea.getX(); boolean rightOut = (angle < 90 || angle > 270) && labelLocation.getX() + labelBounds.getWidth() > plotArea.getX() + plotArea.getWidth(); if (leftOut || rightOut) { font = font.deriveFont(font.getSize2D() - 1); } else { break; } } while (font.getSize() > 8); Composite saveComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.setPaint(getLabelPaint()); g2.setFont(font); g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY()); g2.setComposite(saveComposite); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
protected void paintAnnotations(Graphics2D g2d) { DecimalFormat mz_df = new DecimalFormat("0.0"); // set font//from w w w. ja va2 s . co m Font old_font = g2d.getFont(); Font new_font = new Font(theOptions.ANNOTATION_MZ_FONT, Font.PLAIN, theOptions.ANNOTATION_MZ_SIZE); // compute bboxes PositionManager pman = new PositionManager(); BBoxManager bbman = new BBoxManager(); computeRectangles(pman, bbman); // compute connections computeConnections(); // paint connections for (AnnotationObject a : theDocument.getAnnotations()) { boolean selected = !is_printing && selections.contains(a); // paint arrow Polygon connection = connections.get(a); if (connection != null) { g2d.setColor(theOptions.CONNECTION_LINES_COLOR); g2d.setStroke((selected) ? new BasicStroke((float) (1. + theOptions.ANNOTATION_LINE_WIDTH)) : new BasicStroke((float) theOptions.ANNOTATION_LINE_WIDTH)); g2d.draw(connection); g2d.setStroke(new BasicStroke(1)); } // paint control point if (selected) { g2d.setColor(Color.black); Point2D cp = connections_cp.get(a); if (cp != null) { int s = (int) (2 + theOptions.ANNOTATION_LINE_WIDTH); g2d.fill(new Rectangle((int) cp.getX() - s, (int) cp.getY() - s, 2 * s, 2 * s)); } } } // paint glycans for (AnnotationObject a : theDocument.getAnnotations()) { boolean highlighted = a.isHighlighted(); boolean selected = !is_printing && selections.contains(a); // set scale theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a)); // paint highlighted region if (highlighted) { Rectangle c_bbox = rectangles_complete.get(a); g2d.setColor(theOptions.HIGHLIGHTED_COLOR); g2d.setXORMode(Color.white); g2d.fill(c_bbox); g2d.setPaintMode(); g2d.setColor(Color.black); g2d.draw(c_bbox); } // paint glycan for (Glycan s : a.getStructures()) theGlycanRenderer.paint(g2d, s, null, null, false, false, pman, bbman); // paint MZ text g2d.setFont(new_font); g2d.setColor(theOptions.MASS_TEXT_COLOR); String mz_text = mz_df.format(a.getPeakPoint().getX()); Rectangle mz_bbox = rectangles_text.get(a); g2d.drawString(mz_text, mz_bbox.x, mz_bbox.y + mz_bbox.height); // paint selection if (selected) { // paint rectangle Rectangle c_bbox = rectangles_complete.get(a); g2d.setStroke(new BasicStroke(highlighted ? 2 : 1)); g2d.setColor(Color.black); g2d.draw(c_bbox); g2d.setStroke(new BasicStroke(1)); // paint resize points Polygon p1 = new Polygon(); int cx1 = right(c_bbox); int cy1 = top(c_bbox); p1.addPoint(cx1, cy1); p1.addPoint(cx1 - 2 * theOptions.ANNOTATION_MARGIN / 3, cy1); p1.addPoint(cx1, cy1 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p1); Polygon p2 = new Polygon(); int cx2 = left(c_bbox); int cy2 = top(c_bbox); p2.addPoint(cx2, cy2); p2.addPoint(cx2 + 2 * theOptions.ANNOTATION_MARGIN / 3, cy2); p2.addPoint(cx2, cy2 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p2); } } g2d.setFont(old_font); }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void drawTitle(Graphics2D g2) { final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Color oldColor = g2.getColor(); final Font oldFont = g2.getFont(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final Font titleFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() * 1.5f); final int margin = 5; final FontMetrics titleFontMetrics = g2.getFontMetrics(titleFont); final FontMetrics oldFontMetrics = g2.getFontMetrics(oldFont); final java.text.NumberFormat numberFormat = java.text.NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(2); numberFormat.setMinimumFractionDigits(2); final double totalInvestValue = this.investmentFlowChartJDialog.getTotalInvestValue(); final double totalROIValue = this.investmentFlowChartJDialog.getTotalROIValue(); final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace(); final String invest = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalInvestValue);/* w w w.j a va2s . c o m*/ final String roi = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalROIValue); final double gain = totalROIValue - totalInvestValue; final double percentage = totalInvestValue > 0.0 ? gain / totalInvestValue * 100.0 : 0.0; final String gain_str = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, gain); final String percentage_str = numberFormat.format(percentage); final String SELECTED = this.investmentFlowChartJDialog.getCurrentSelectedString(); final String INVEST = GUIBundle.getString("InvestmentFlowLayerUI_Invest"); final String RETURN = GUIBundle.getString("InvestmentFlowLayerUI_Return"); final String GAIN = (SELECTED.length() > 0 ? SELECTED + " " : "") + GUIBundle.getString("InvestmentFlowLayerUI_Gain"); final String LOSS = (SELECTED.length() > 0 ? SELECTED + " " : "") + GUIBundle.getString("InvestmentFlowLayerUI_Loss"); final int string_width = oldFontMetrics.stringWidth(INVEST + ": ") + titleFontMetrics.stringWidth(invest + " ") + oldFontMetrics.stringWidth(RETURN + ": ") + titleFontMetrics.stringWidth(roi + " ") + oldFontMetrics.stringWidth((gain >= 0 ? GAIN : LOSS) + ": ") + titleFontMetrics.stringWidth(gain_str + " (" + percentage_str + "%)"); int x = (int) (this.investmentFlowChartJDialog.getChartPanel().getWidth() - string_width) >> 1; final int y = margin + titleFontMetrics.getAscent(); g2.setFont(oldFont); g2.drawString(INVEST + ": ", x, y); x += oldFontMetrics.stringWidth(INVEST + ": "); g2.setFont(titleFont); g2.drawString(invest + " ", x, y); x += titleFontMetrics.stringWidth(invest + " "); g2.setFont(oldFont); g2.drawString(RETURN + ": ", x, y); x += oldFontMetrics.stringWidth(RETURN + ": "); g2.setFont(titleFont); g2.drawString(roi + " ", x, y); x += titleFontMetrics.stringWidth(roi + " "); g2.setFont(oldFont); if (gain >= 0) { if (gain > 0) { if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) { g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor()); } else { g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor()); } } g2.drawString(GAIN + ": ", x, y); x += oldFontMetrics.stringWidth(GAIN + ": "); } else { if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) { g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor()); } else { g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor()); } g2.drawString(LOSS + ": ", x, y); x += oldFontMetrics.stringWidth(LOSS + ": "); } g2.setFont(titleFont); g2.drawString(gain_str + " (" + percentage_str + "%)", x, y); g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); g2.setFont(oldFont); }
From source file:org.ietr.preesm.mapper.ui.MyGanttRenderer.java
/** * Draws the tasks/subtasks for one item. * /*from ww w. j a v a 2s.co m*/ * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the data plot area. * @param plot * the plot. * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the data. * @param row * the row index (zero-based). * @param column * the column index (zero-based). */ @Override protected void drawTasks(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) { int count = dataset.getSubIntervalCount(row, column); if (count == 0) { drawTask(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column); } for (int subinterval = 0; subinterval < count; subinterval++) { RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); // value 0 Number value0 = dataset.getStartValue(row, column, subinterval); if (value0 == null) { return; } double translatedValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation); // value 1 Number value1 = dataset.getEndValue(row, column, subinterval); if (value1 == null) { return; } double translatedValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation); if (translatedValue1 < translatedValue0) { double temp = translatedValue1; translatedValue1 = translatedValue0; translatedValue0 = temp; } double rectStart = calculateBarW0(plot, plot.getOrientation(), dataArea, domainAxis, state, row, column); double rectLength = Math.abs(translatedValue1 - translatedValue0); double rectBreadth = state.getBarWidth(); // DRAW THE BARS... RoundRectangle2D bar = null; bar = new RoundRectangle2D.Double(translatedValue0, rectStart, rectLength, rectBreadth, 10.0, 10.0); /* Paint seriesPaint = */getItemPaint(row, column); if (((TaskSeriesCollection) dataset).getSeriesCount() > 0) if (((TaskSeriesCollection) dataset).getSeries(0).getItemCount() > column) if (((TaskSeriesCollection) dataset).getSeries(0).get(column).getSubtaskCount() > subinterval) { g2.setPaint(getRandomBrightColor(((TaskSeriesCollection) dataset).getSeries(0).get(column) .getSubtask(subinterval).getDescription())); } g2.fill(bar); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } // Displaying the tooltip inside the bar if enough space is // available if (getToolTipGenerator(row, column) != null) { // Getting the string to display String tip = getToolTipGenerator(row, column).generateToolTip(dataset, subinterval, column); // Truncting the string if it is too long String subtip = ""; if (rectLength > 0) { double percent = (g2.getFontMetrics().getStringBounds(tip, g2).getWidth() + 10) / rectLength; if (percent > 1.0) { subtip = tip.substring(0, (int) (tip.length() / percent)); } else if (percent > 0) { subtip = tip; } // Setting font and color Font font = new Font("Garamond", Font.BOLD, 12); g2.setFont(font); g2.setColor(Color.WHITE); // Testing width and displaying if (!subtip.isEmpty()) { g2.drawString(subtip, (int) translatedValue0 + 5, (int) rectStart + g2.getFontMetrics().getHeight()); } } } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; if (getToolTipGenerator(row, column) != null) { tip = getToolTipGenerator(row, column).generateToolTip(dataset, subinterval, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } } }