List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawEntity(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();/* w w w . ja v a2 s . c o m*/ Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AffineTransform originalTransform = g2.getTransform(); Shape transformed = entity; FlatteningPathIterator iter = new FlatteningPathIterator( transformed.getPathIterator(new AffineTransform()), 1); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
From source file:org.amanzi.awe.render.network.NetworkRenderer.java
/** * Draw black border around selected sector * //from w w w.jav a 2 s .co m * @param destination * @param point * @param model * @param sector */ private void renderSelectionBorder(Graphics2D destination, Point point, ISectorElement sector, int index, int count) { Pair<Double, Double> sectorParameters = getSectorParameters(sector, index, count); int size = getSize(); double azimuth = sectorParameters.getLeft(); double beamwidth = sectorParameters.getRight(); GeneralPath path = new GeneralPath(); path.moveTo(getSectorXCoordinate(point, size), getSectorYCoordinate(point, size)); Arc2D a = createSector(point, networkRendererStyle.getLargeElementSize(), getAngle(azimuth, beamwidth), beamwidth); path.append(a.getPathIterator(null), true); path.closePath(); destination .setColor(networkRendererStyle.changeColor(SELECTED_SECTOR_COLOR, networkRendererStyle.getAlpha())); destination.draw(path); destination.drawString(sector.getName(), (int) a.getEndPoint().getX() + 10, (int) a.getEndPoint().getY()); }
From source file:com.alibaba.simpleimage.render.FootnoteDrawTextItem.java
@Override public void drawText(Graphics2D graphics, int width, int height) { if (StringUtils.isBlank(text) || StringUtils.isBlank(domainName)) { return;// w w w. j av a 2 s . c o m } int x = 0, y = 0; int fontsize = ((int) (width * textWidthPercent)) / domainName.length(); if (fontsize < minFontSize) { return; } float fsize = (float) fontsize; Font font = domainFont.deriveFont(fsize); graphics.setFont(font); FontRenderContext context = graphics.getFontRenderContext(); int sw = (int) font.getStringBounds(domainName, context).getWidth(); x = width - sw - fontsize; y = height - fontsize; if (x <= 0 || y <= 0) { return; } if (fontShadowColor != null) { graphics.setColor(fontShadowColor); graphics.drawString(domainName, x + getShadowTranslation(fontsize), y + getShadowTranslation(fontsize)); } graphics.setColor(fontColor); graphics.drawString(domainName, x, y); //draw company name fsize = (float) fontsize; font = defaultFont.deriveFont(fsize); graphics.setFont(font); context = graphics.getFontRenderContext(); sw = (int) font.getStringBounds(text, context).getWidth(); x = width - sw - fontsize; y = height - (int) (fontsize * 2.5); if (x <= 0 || y <= 0) { return; } if (fontShadowColor != null) { graphics.setColor(fontShadowColor); graphics.drawString(text, x + getShadowTranslation(fontsize), y + getShadowTranslation(fontsize)); } graphics.setColor(fontColor); graphics.drawString(text, x, y); }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * {@inheritDoc}//w w w . j av a 2 s . c om */ public BufferedImage createPhylogenyImage(PhylogenyTreeNode phylogenyTree, int imageWidth, int imageHeight) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating phylogeny image for: " + phylogenyTree.resolveToSingleStrainLeafNodes(0.0).toNewickFormat()); } BufferedImage bi = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = bi.createGraphics(); graphics.setStroke(LINE_STROKE); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setColor(Color.BLACK); this.paintPhylogenyTree(graphics, phylogenyTree, imageWidth, imageHeight); return bi; }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawOutline(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();// ww w . j ava 2s.c om Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); Rectangle2D entityBounds = entity.getBounds2D(); double viewX = xAxis.valueToJava2D(entityBounds.getCenterX(), dataArea, xAxisEdge); double viewY = yAxis.valueToJava2D(entityBounds.getCenterY(), dataArea, yAxisEdge); double viewW = xAxis.lengthToJava2D(entityBounds.getWidth(), dataArea, xAxisEdge); double viewH = yAxis.lengthToJava2D(entityBounds.getHeight(), dataArea, yAxisEdge); PlotOrientation orientation = plot.getOrientation(); //transform model to origin (0,0) in model coordinates AffineTransform toOrigin = AffineTransform.getTranslateInstance(-entityBounds.getCenterX(), -entityBounds.getCenterY()); //transform from origin (0,0) to model location AffineTransform toModelLocation = AffineTransform.getTranslateInstance(entityBounds.getCenterX(), entityBounds.getCenterY()); //transform from model scale to view scale double scaleX = viewW / entityBounds.getWidth(); double scaleY = viewH / entityBounds.getHeight(); Logger.getLogger(getClass().getName()).log(Level.FINE, "Scale x: {0} Scale y: {1}", new Object[] { scaleX, scaleY }); AffineTransform toViewScale = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransform toViewLocation = AffineTransform.getTranslateInstance(viewX, viewY); AffineTransform flipTransform = AffineTransform.getScaleInstance(1.0f, -1.0f); AffineTransform modelToView = new AffineTransform(toOrigin); modelToView.preConcatenate(flipTransform); modelToView.preConcatenate(toViewScale); modelToView.preConcatenate(toViewLocation); // // if (orientation == PlotOrientation.HORIZONTAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewY, // viewX); // } else if (orientation == PlotOrientation.VERTICAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewX, // viewY); // } FlatteningPathIterator iter = new FlatteningPathIterator(modelToView.createTransformedShape(entity) .getPathIterator(AffineTransform.getTranslateInstance(0, 0)), 5); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
From source file:net.technicpack.ui.lang.ResourceLoader.java
public BufferedImage getCircleClippedImage(BufferedImage contentImage) { // copy the picture to an image with transparency capabilities BufferedImage outputImage = new BufferedImage(contentImage.getWidth(), contentImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) outputImage.getGraphics(); g2.drawImage(contentImage, 0, 0, null); // Create the area around the circle to cut out Area cutOutArea = new Area(new Rectangle(0, 0, outputImage.getWidth(), outputImage.getHeight())); int diameter = (outputImage.getWidth() < outputImage.getHeight()) ? outputImage.getWidth() : outputImage.getHeight();//w w w . j a va2s. c om cutOutArea.subtract(new Area(new Ellipse2D.Float((outputImage.getWidth() - diameter) / 2, (outputImage.getHeight() - diameter) / 2, diameter, diameter))); // Set the fill color to an opaque color g2.setColor(Color.WHITE); // Set the composite to clear pixels g2.setComposite(AlphaComposite.Clear); // Turn on antialiasing g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Clear the cut out area g2.fill(cutOutArea); // dispose of the graphics object g2.dispose(); return outputImage; }
From source file:business.ImageManager.java
private void doDrawPath(Graphics2D big, Point ori, Point dest, Color color) { //setup para os rastros big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); big.setStroke(new BasicStroke(0.75f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 3f, 5f, 7f, 5f, 11f, 5f, 15f, 5f, 21f, 5f, 27f, 5f, 33f, 5f }, 0f)); big.setColor(color); //draw path//from w w w .j a v a 2 s . co m Path2D.Double path = new Path2D.Double(); path.moveTo(ori.getX(), ori.getY()); path.lineTo(dest.getX(), dest.getY()); //draw on graph big.draw(path); }
From source file:business.ImageManager.java
private void doDrawPathOrdem(Graphics2D big, Point ori, Point dest, Color color) { //setup para os rastros big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); big.setStroke(new BasicStroke(1.75f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 3f, 5f, 7f, 5f, 11f, 5f, 15f, 5f, 21f, 5f, 27f, 5f, 33f, 5f }, 0f)); big.setColor(color); //draw path/* w w w . jav a2 s .c o m*/ Path2D.Double path = new Path2D.Double(); path.moveTo(ori.getX(), ori.getY()); path.curveTo(dest.getX() - 20, dest.getY() + 20, dest.getX() + 20, dest.getY() - 20, dest.getX() + 12, dest.getY()); //path.lineTo(dest.getX(), dest.getY()); //draw on graph big.draw(path); }
From source file:com.rapidminer.gui.plotter.charts.DistributionPlotter.java
@Override public void updatePlotter() { JFreeChart chart = null;// ww w . jav a 2 s . com Attribute attr = null; if (plotColumn != -1 && createFromModel) { attr = model.getTrainingHeader().getAttributes().get(model.getAttributeNames()[plotColumn]); } if (attr != null && attr.isNominal() && attr.getMapping().getValues().size() > MAX_NUMBER_OF_DIFFERENT_NOMINAL_VALUES) { // showing no chart because of too many different values chart = new JFreeChart(new Plot() { private static final long serialVersionUID = 1L; @Override public String getPlotType() { return "empty"; } @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { String msg = I18N.getGUILabel("plotter_panel.too_many_nominals", "Distribution Plotter", DistributionPlotter.MAX_NUMBER_OF_DIFFERENT_NOMINAL_VALUES); g2.setColor(Color.BLACK); g2.setFont(g2.getFont().deriveFont(g2.getFont().getSize() * 1.35f)); g2.drawChars(msg.toCharArray(), 0, msg.length(), 50, (int) (area.getHeight() / 2 + 0.5d)); } }); AbstractChartPanel panel = getPlotterPanel(); // Chart Panel Settings if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { preparePlots(); if (!createFromModel && (groupColumn < 0 || plotColumn < 0)) { CategoryDataset dataset = new DefaultCategoryDataset(); chart = ChartFactory.createBarChart(null, // chart title "Not defined", // x axis label RANGE_AXIS_NAME, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); } else { try { if (model.isDiscrete(translateToModelColumn(plotColumn))) { chart = createNominalChart(); } else { chart = createNumericalChart(); } } catch (Exception e) { // do nothing - just do not draw the chart } } if (chart != null) { chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... Plot commonPlot = chart.getPlot(); commonPlot.setBackgroundPaint(Color.WHITE); if (commonPlot instanceof XYPlot) { XYPlot plot = (XYPlot) commonPlot; plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if (dataTable != null) { if (dataTable.isDate(plotColumn) || dataTable.isDateTime(plotColumn)) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(plotColumn)); domainAxis.setTimeZone(com.rapidminer.tools.Tools.getPreferredTimeZone()); plot.setDomainAxis(domainAxis); } else { NumberAxis numberAxis = new NumberAxis(dataTable.getColumnName(plotColumn)); plot.setDomainAxis(numberAxis); } } plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); // ranging if (dataTable != null) { Range range = getRangeForDimension(plotColumn); if (range != null) { plot.getDomainAxis().setRange(range, true, false); } range = getRangeForName(RANGE_AXIS_NAME); if (range != null) { plot.getRangeAxis().setRange(range, true, false); } } // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } } else if (commonPlot instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) commonPlot; plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); } // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } AbstractChartPanel panel = getPlotterPanel(); // Chart Panel Settings if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } } }
From source file:edu.ku.brc.specify.utilapps.ERDVisualizer.java
/** * //from www . j a va 2 s . co m */ public void generate() { Rectangle rect = getPanel().getParent().getBounds(); System.out.println("MAIN[" + rect + "]"); if (rect.width == 0 || rect.height == 0) { return; } BufferedImage bufImage = new BufferedImage(rect.width, rect.height, (doPNG ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB)); Graphics2D g2 = bufImage.createGraphics(); if (!doPNG) { g2.setColor(Color.WHITE); g2.fillRect(0, 0, rect.width, rect.height); } g2.setRenderingHints(createTextRenderingHints()); g2.setFont(tblTracker.getFont()); getPanel().getParent().paint(g2); g2.dispose(); Component stop = getPanel().getParent(); Point p = new Point(0, 0); calcLoc(p, getPanel().getMainTable(), stop); String name = StringUtils.substringAfterLast(getPanel().getMainTable().getClassName(), "."); DBTableInfo tblInfo = DBTableIdMgr.getInstance().getByShortClassName(name); String fName = schemaDir.getAbsolutePath() + File.separator + name; try { String origName = fName; int i = 1; while (pngNameHash.contains(fName)) { fName = origName + i; } pngNameHash.add(fName); File html = new File(fName + ".html"); BufferedWriter output = new BufferedWriter(new FileWriter(html)); int index = mapTemplate.indexOf(contentTag); String subContent = mapTemplate.substring(0, index); output.write(StringUtils.replace(subContent, "<!-- Title -->", tblInfo.getTitle())); File imgFile = new File(fName + (doPNG ? ".png" : ".jpg")); output.write("<map name=\"schema\" id=\"schema\">\n"); Vector<ERDTable> nList = mainPanel.isRoot() ? tblTracker.getTreeAsList(mainPanel.getMainTable()) : getPanel().getRelTables(); for (ERDTable erdt : nList) { p = new Point(0, 0); calcLoc(p, erdt, stop); Dimension s = erdt.getSize(); String linkname = StringUtils.substringAfterLast(erdt.getClassName(), "."); output.write("<area shape=\"rect\" coords=\"" + p.x + "," + p.y + "," + (p.x + s.width) + "," + (p.y + s.height) + "\" href=\"" + linkname + ".html\"/>\n"); } output.write("</map>\n"); output.write("<img border=\"0\" usemap=\"#schema\" src=\"" + imgFile.getName() + "\"/>\n"); output.write(mapTemplate.substring(index + contentTag.length() + 1, mapTemplate.length())); output.close(); File oFile = new File(schemaDir + File.separator + imgFile.getName()); System.out.println(oFile.getAbsolutePath()); if (doPNG) { ImageIO.write(bufImage, "PNG", oFile); } else { writeJPEG(oFile, bufImage, 0.75f); } //ImageIO.write(bufImage, "JPG", new File(schemaDir + File.separator + imgFile.getName()+".jpg")); } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, e); e.printStackTrace(); } }