List of usage examples for java.awt Graphics2D getClipBounds
public abstract Rectangle getClipBounds();
From source file:com.xauto.ux.Emf2.java
@SuppressWarnings("deprecation") public static void extractPicturesFromDoc(String docName) throws Exception { Document doc = new Document(docName + ".docx"); Integer emfOrWmfIndex = 1; Integer pngOrJpegIndex = 100; Integer bmpOrPictIndex = 10000; Integer otherIndex = 1000; String outDir = "out" + File.separator + docName + File.separator; FileUtils.forceMkdir(new File(outDir)); FileWriter html = new FileWriter(outDir + "out.html"); html.write(/*ww w. j a v a 2 s. c om*/ "<html>\n<head><meta http-equiv=\"x-ua-compatible\" content=\"IE=edge,chrome=1\"></head><body>\n"); for (AsposeDrawingType type : AsposeDrawingType.values()) { Node[] drawArray = doc.getChildNodes(type.code(), true).toArray(); int index = 0; logger.info("type={};count={}", type, drawArray.length); for (Node n : drawArray) { WordDrawing node = null; DrawingML dml = null; Shape s = null; if (n instanceof Shape) { s = (Shape) n; node = new WordDrawing(s); } else if (n instanceof DrawingML) { dml = (DrawingML) n; node = new WordDrawing(dml); } index++; IImageData img = node.getImageData(); BufferedImage bi = img.toImage(); AposeWordImageType asposeWordImageType = AposeWordImageType.fromCode(img.getImageType()); String extn = null; String trimmedDrawingName = node.getName().replace(" ", "") + index; ImageSize is = img.getImageSize(); long resolution = 600; int scale = 1000; Graphics2D gd = bi.createGraphics(); gd.getClipBounds(); int jpegQual = 70; boolean antiAlias = true; boolean highQualityRendering = true; try { extn = FileFormatUtil.imageTypeToExtension(img.getImageType()); } catch (IllegalArgumentException e) { extn = "unknown"; } String drawingName = node.getName(); if (StringUtils.isBlank(drawingName)) { if (node.getNode() instanceof Shape) { Shape s = (Shape) node.getNode(); Node cell = null; Node parent = s.getParentNode(); while (parent.getNodeType() != NodeType.ROW) { if (parent.getNodeType() == NodeType.CELL) { cell = parent; } parent = parent.getParentNode(); } Row picturesRow = (Row) parent; Row captionsRow = (Row) picturesRow.getPreviousSibling(); Node[] currentPicturesRowCells = picturesRow.getChildNodes(NodeType.CELL, true).toArray(); int foundIndex = 0; for (Node n : currentPicturesRowCells) { if (n == cell) { break; } foundIndex++; } Cell captionCell = (Cell) captionsRow.getChild(NodeType.CELL, foundIndex, true); StringBuilder sb = new StringBuilder(); Paragraph[] ps = captionCell.getParagraphs().toArray(); for (Paragraph p : ps) { Run[] rs = p.getRuns().toArray(); for (Run r : rs) { r.getDirectRunAttrsCount(); sb.append(r.getText()); } } drawingName = sb.toString().replace("SEQ Figure \\* ARABIC ", ""); } } logger.debug( "imageType={};name={};hasImage()={};imageByteSize={};isLink={};imageSize.Width={};imageSize.Height={};" + "imageSize.HorRes={};imageSize.VertRes={};imageSize.WPoints={};imageSize.HPoints={};" + "bufferedImageType={}; biHeight={}; biWidth={}; trimmedDrawingName={}; extn={};" + "" + "bufferedImageInfo={};drawInfo={}", asposeWordImageType, drawingName, img.hasImage(), img.getImageBytes() == null ? 0 : img.getImageBytes().length, img.isLink(), is.getWidthPixels(), is.getHeightPixels(), is.getHorizontalResolution(), is.getVerticalResolution(), is.getWidthPoints(), is.getHeightPoints(), AwtImageType.fromCode(bi.getType()), bi.getHeight(), bi.getWidth(), trimmedDrawingName, extn, bi.toString(), node.toString()); if (StringUtils.isBlank(node.getName())) { if (dml != null) { dml.getParentNode(); logger.debug("getAncestor={}", dml.getAncestor(DocumentProperty.class)); } else if (s != null) { s.getExpandedRunPr_IInline(54); logger.debug(s.toTxt() + s.getText()); @SuppressWarnings("unchecked") NodeCollection<Node> ns = s.getChildNodes(); while (ns.iterator().hasNext()) { Node n1 = (Node) ns.iterator().next(); n1.getText(); } logger.debug("shape={}", s.getAncestor(DocumentProperty.class)); s.getParentParagraph(); } } if (asposeWordImageType == AposeWordImageType.UNKNOWN) { otherIndex++; continue; } if (img == null || asposeWordImageType == AposeWordImageType.NO_IMAGE) { continue; } if (asposeWordImageType == AposeWordImageType.EMF || asposeWordImageType == AposeWordImageType.WMF) { ShapeRenderer sr = node.getShapeRenderer(); img.save(outDir + trimmedDrawingName + extn); PngOptions pngOptions = new PngOptions(); if (asposeWordImageType == AposeWordImageType.EMF) { EmfMetafileImage emf = new EmfMetafileImage(outDir + trimmedDrawingName + extn); emf.save(outDir + trimmedDrawingName + "_buffered_emf.png", pngOptions); } else { WmfMetafileImage wmf = new WmfMetafileImage(outDir + trimmedDrawingName + extn); wmf.save(outDir + trimmedDrawingName + "_buffered_emf.png", pngOptions); } trimmedDrawingName += "_" + scale + "_" + resolution + "_" + jpegQual + "_" + antiAlias + "_" + highQualityRendering; ImageSaveOptions pngSave = new ImageSaveOptions(com.aspose.words.SaveFormat.PNG); pngSave.setResolution(resolution); pngSave.setUseHighQualityRendering(highQualityRendering); pngSave.setDmlRenderingMode(DmlRenderingMode.DRAWING_ML); pngSave.setDmlEffectsRenderingMode(DmlEffectsRenderingMode.FINE); pngSave.setUseAntiAliasing(antiAlias); pngSave.setScale((float) scale / 1000); ImageSaveOptions jpgSave = new ImageSaveOptions(SaveFormat.JPEG); jpgSave.setUseHighQualityRendering(true); jpgSave.setResolution(resolution); jpgSave.setJpegQuality(jpegQual); jpgSave.setScale((float) scale / 1000); sr.save(outDir + trimmedDrawingName + ".png", pngSave); BufferedImage savedPNG = ImageIO.read(new File(outDir + trimmedDrawingName + ".png")); BufferedImage resizedFromSaved = Scalr.resize(savedPNG, Method.ULTRA_QUALITY, Mode.FIT_TO_WIDTH, 435); BufferedImage resizedFromBi = Scalr.resize(bi, Method.ULTRA_QUALITY, Mode.FIT_TO_WIDTH, 435); ImageIO.write(bi, "png", new File(outDir + trimmedDrawingName + "_buffered.png")); ImageIO.write(resizedFromSaved, "png", new File(outDir + trimmedDrawingName + "_resized_from_saved_scalr_antialias_435.png")); ImageIO.write(resizedFromBi, "png", new File(outDir + trimmedDrawingName + "_resized_from_bi_scalr_antialias_435.png")); //sr.save(outDir+trimmedDrawingName+".jpg", jpgSave); html.write("\t<div>\n\t\t\n\t\t<br>\n\t\t<hr><p align=center>.SVG figure: " + trimmedDrawingName + "</p>\n\t\t<hr>\n\t\t<br>\n\t\t<br>\n\t\t<img src=\"" + trimmedDrawingName + ".svg\" width=\"100%\" />\n\t</div>\n"); //convertToSVG(outputDir + docId + "\\", trimmedDrawingName, extn); emfOrWmfIndex++; } else if (asposeWordImageType == AposeWordImageType.PNG || asposeWordImageType == AposeWordImageType.JPEG) { ShapeRenderer sr = node.getShapeRenderer(); ImageSaveOptions pngSave = new ImageSaveOptions(com.aspose.words.SaveFormat.PNG); pngSave.setResolution(resolution); pngSave.setUseHighQualityRendering(highQualityRendering); pngSave.setDmlRenderingMode(DmlRenderingMode.DRAWING_ML); pngSave.setDmlEffectsRenderingMode(DmlEffectsRenderingMode.FINE); pngSave.setUseAntiAliasing(antiAlias); pngSave.setScale((float) scale / 1000); img.save(outDir + trimmedDrawingName + extn); sr.save(outDir + trimmedDrawingName + "_DIRECT" + extn, pngSave); if (is.getHeightPoints() > 99) { html.write("\t<div>\n\t\t\n\t\t<br>\n\t\t<hr><p align=center>" + extn.toUpperCase() + " figure: " + trimmedDrawingName + "</p>\n\t\t<hr>\n\t\t<br>\n\t\t<br>\n\t\t<img src=\"" + trimmedDrawingName + extn + "\" width=\"100%\" />\n\t</div>\n"); } pngOrJpegIndex++; } else if (asposeWordImageType == AposeWordImageType.BMP || asposeWordImageType == AposeWordImageType.PICT) { img.save(outDir + bmpOrPictIndex + extn); bmpOrPictIndex++; } else { logger.info( "PICT type={}; isLink={}; isLinkOnly={}; imageSize={}; sourceFileName={}; hasImage={}", asposeWordImageType, img.isLink(), img.isLinkOnly(), img.getImageSize().getHorizontalResolution(), img.getSourceFullName(), img.hasImage()); } } } html.write("</body>\n</html>"); html.close(); }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
private static Rectangle2D createHotspot(Graphics2D g2, double x, double y, double xOffset, Size2D blockSize) { Rectangle bounds = g2.getClipBounds(); bounds = new Rectangle(bounds.x + 2, bounds.y + 2, bounds.width - 4, bounds.height - 4); return createHotspot(bounds, x, y, xOffset, blockSize); }
From source file:com.projity.pm.graphic.network.NetworkRenderer.java
public void paint(Graphics g, Rectangle visibleBounds) { Graphics2D g2 = (Graphics2D) g; Rectangle clipBounds = g2.getClipBounds(); Rectangle svgClip = clipBounds; if (clipBounds == null) { clipBounds = getGraphInfo().getDrawingBounds(); //start at O,O because it's already translated if (visibleBounds == null) clipBounds = new Rectangle(0, 0, clipBounds.width, clipBounds.height); else {//from www . ja v a2s .co m clipBounds = visibleBounds; g2.setClip(clipBounds); } } //Modif for offline graphics GraphicDependency dependency; for (Iterator i = getDependenciesIterator(); i.hasNext();) { dependency = (GraphicDependency) i.next(); paintLink(g2, dependency); } GraphicNode node; Rectangle bounds; for (ListIterator i = graphInfo.getCache().getIterator(); i.hasNext();) { node = (GraphicNode) i.next(); bounds = getBounds(node); if (bounds == null) continue; if (clipBounds.intersects(bounds)) paintNode(g2, node); } if (visibleBounds != null) g2.setClip(svgClip); }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private static void drawBackground(final Graphics2D g, final MindMapPanelConfig cfg) { final Rectangle clipBounds = g.getClipBounds(); if (cfg.isDrawBackground()) { g.setColor(cfg.getPaperColor()); g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); if (cfg.isShowGrid()) { final double scaledGridStep = cfg.getGridStep() * cfg.getScale(); final float minX = clipBounds.x; final float minY = clipBounds.y; final float maxX = clipBounds.x + clipBounds.width; final float maxY = clipBounds.y + clipBounds.height; g.setColor(cfg.getGridColor()); for (float x = 0.0f; x < maxX; x += scaledGridStep) { if (x < minX) { continue; }// w w w. ja va 2s . com final int intx = Math.round(x); g.drawLine(intx, (int) minY, intx, (int) maxY); } for (float y = 0.0f; y < maxY; y += scaledGridStep) { if (y < minY) { continue; } final int inty = Math.round(y); g.drawLine((int) minX, inty, (int) maxX, inty); } } } }
From source file:com.projity.pm.graphic.gantt.GanttRenderer.java
public void paint(Graphics g, Rectangle visibleBounds) { Graphics2D g2 = (Graphics2D) g; //CoordinatesConverter coord=((GanttParams)graphInfo).getCoord(); Rectangle clipBounds = g2.getClipBounds(); Rectangle svgClip = clipBounds; if (clipBounds == null) { clipBounds = ((GanttParams) getGraphInfo()).getGanttBounds(); //start at O,O because it's already translated if (visibleBounds == null) clipBounds = new Rectangle(0, 1, clipBounds.width, clipBounds.height - 2);//1 pixel offset needed for edge // else clipBounds=new Rectangle(visibleBounds.x-clipBounds.x,visibleBounds.y-clipBounds.y,visibleBounds.width,visibleBounds.height); else {/*from w ww . j ava 2 s.c o m*/ clipBounds = visibleBounds; g2.setClip(clipBounds); } } paintNonWorkingDays(g2, clipBounds); //Modif for offline graphics double rowHeight = ((GanttParams) graphInfo).getRowHeight(); int i0 = (int) Math.floor(clipBounds.getY() / rowHeight); int i1; if (visibleBounds == null) i1 = (int) Math.ceil(clipBounds.getMaxY() / rowHeight); else i1 = (int) Math.floor(clipBounds.getMaxY() / rowHeight); //double t0=coord.toTime(clipBounds.getX()); //double t1=coord.toTime(clipBounds.getMaxX()); nodeList.clear(); GraphicNode node; // for (ListIterator i=graph.getModel().getNodeIterator(i0);i.hasNext()&&i.nextIndex()<=i1;){ // node=(GraphicNode)i.next(); // if (!node.isSchedule()) continue; // nodeList.add(node); // node.setRow(i.previousIndex()); // paintNode(g2,node,true); // } //Because row not initialized for some nodes NodeModelCache cache = graphInfo.getCache(); for (ListIterator i = cache.getIterator(); i.hasNext();) { node = (GraphicNode) i.next(); node.setRow(i.previousIndex()); if (i.previousIndex() >= i0 && i.previousIndex() < i1) { if (!node.isSchedule()) continue; nodeList.add(node); paintAnnotation(g2, node); paintNode(g2, node, true); paintHorizontalLine(g2, node); } } GraphicDependency dependency; for (Iterator i = cache.getEdgesIterator(); i.hasNext();) { dependency = (GraphicDependency) i.next(); //if (nodeList.contains(dependency.getPredecessor())||nodeList.contains(dependency.getSuccessor())) paintLink(g2, dependency); } for (ListIterator i = nodeList.listIterator(); i.hasNext();) { node = (GraphicNode) i.next(); paintNode(g2, node, false); } if (visibleBounds != null) g2.setClip(svgClip); }
From source file:gov.sandia.umf.platform.ui.jobs.Raster.java
public JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title null, // x axis label null, // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls );//from w ww . j a va 2 s. com chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setRenderer(new XYDotRenderer() { public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state, java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // Copied from org.jfree.chart.renderer.xy.XYDotRenderer.java and modified. // This would only need to be a couple of lines if they authors of jfreechart had not made dotWidth and dotHeight private members. // Yet another example of textbook OO programming gone awry. (Can anyone hear me scream?) if (!getItemVisible(series, item)) return; int dotWidth = 1; double rasterLines = rangeAxis.getRange().getLength(); int pixels = g2.getClipBounds().height; double height = pixels / rasterLines; if (height > 10) height -= 2; else if (height > 2) height -= 1; int dotHeight = (int) Math.min(20, Math.max(1, Math.floor(height))); double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Double.isNaN(y)) return; double adjx = (dotWidth - 1) / 2.0; double adjy = (dotHeight - 1) / 2.0; RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx; double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy; g2.setPaint(Color.black); PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) g2.fillRect((int) transY, (int) transX, dotHeight, dotWidth); else g2.fillRect((int) transX, (int) transY, dotWidth, dotHeight); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Integer units only return chart; }
From source file:org.bitstrings.maven.plugins.splasher.DrawingUtil.java
public static Rectangle getDrawingBounds(Graphics2D g) { return ObjectUtils.defaultIfNull(g.getClipBounds(), g.getDeviceConfiguration().getBounds()); }
From source file:org.nuclos.client.ui.resplan.header.JHeaderGrid.java
private void paintHeaderCell(Graphics2D g2d, Rectangle rect, Object value) { Rectangle clipBounds = g2d.getClipBounds(); if (clipBounds != null && !clipBounds.intersects(rect)) return;//from w ww . j a va2s. c o m boolean selected = (selectedValue != null && selectedValue.equals(value)); JComponent renderer = setupCellRenderer(value, selected); cellRendererPane.paintComponent(g2d, renderer, this, rect); cellRendererPane.remove(renderer); }
From source file:org.tellervo.desktop.graph.SkeletonPlot.java
public void draw(GraphSettings gInfo, Graphics2D g2, int bottom, Graph g, int thickness, int xscroll) { // cache yearsize, we use this a lot int yearWidth = gInfo.getYearWidth(); // the size of a year, in pixels float unitScale = gInfo.getHundredUnitHeight() / 100.0f; // the size of 1 "unit" in pixels. // set pen/*w w w . j a v a 2 s .co m*/ boolean dotted = (gInfo.isDottedIndexes() && (g.graph instanceof Index)); g2.setStroke(makeStroke(thickness, dotted)); // If it's a chronology, point bones down /*if(g.graph instanceof Sample) { if (((Sample) g.graph).getSeries() instanceof TridasDerivedSeries) { this.areBonesBelowLine = true; } }*/ // left/right int l = g2.getClipBounds().x; int r = l + g2.getClipBounds().width; // no data? stop. if (g.graph.getRingWidthData().isEmpty()) return; // compare g.getClipBounds() to [x,0]..[x+yearSize*data.size(),bottom] tempRect.x = yearWidth * (g.graph.getStart().diff(gInfo.getDrawBounds().getStart()) + g.xoffset); // REDUNDANT! see x later tempRect.y = 0; // - g.yoffset, IF you're sure there are no negative values (but there are) tempRect.width = yearWidth * (g.graph.getRingWidthData().size() - 1); tempRect.height = bottom; // TODO: compute top/bottom as min/max? // REFACTOR: will this be obsolete with the start/end stuff below? if (!tempRect.intersects(g2.getClipBounds())) { // skip this graph, it's off the screen return; } // Draw standard line int x = yearWidth * (g.graph.getStart().diff(gInfo.getDrawBounds().getStart()) + g.xoffset); //int value1 = yTransform((float) getMeanValue(g)); int value1 = yTransform((float) baselineY); int baseYVal = bottom - (int) (value1 * unitScale) - (int) (g.yoffset * unitScale); try { // x-position int x1 = x; int x2 = yearWidth * (g.graph.getStart().diff(gInfo.getDrawBounds().getStart()) + g.xoffset + g.graph.getRingWidthData().size()); // if we're past the end, draw only as far as we need if (x2 > r + yearWidth) { x2 = r + yearWidth; } //log.debug("Drawing mean line: "+x1+", "+meanYVal+", "+x2+", "+meanYVal); g2.drawLine(x1, baseYVal, x2, baseYVal); // Calcs for start/end triangles int YLineHeight = 50; int YTriangleHeight = 25; int XTriangleWidth = 15; if (areBonesBelowLine) { YLineHeight = -50; YTriangleHeight = -25; } // Draw start triangle g2.drawLine(x1, baseYVal, x1, baseYVal - YTriangleHeight); g2.drawLine(x1, baseYVal, x1 - XTriangleWidth, baseYVal - YTriangleHeight); g2.drawLine(x1 - XTriangleWidth, baseYVal - YTriangleHeight, x1, baseYVal - YTriangleHeight); g2.drawLine(x1, baseYVal, x1, baseYVal - YLineHeight); // Draw end triangle g2.drawLine(x2, baseYVal, x2, baseYVal - YTriangleHeight); g2.drawLine(x2, baseYVal, x2 + XTriangleWidth, baseYVal - YTriangleHeight); g2.drawLine(x2 + XTriangleWidth, baseYVal - YTriangleHeight, x2, baseYVal - YTriangleHeight); g2.drawLine(x2, baseYVal, x2, baseYVal - YLineHeight); } catch (ClassCastException cce) { } int value; try { value = ((Number) g.graph.getRingWidthData().get(0)).intValue(); value = yTransform(value * g.scale); } catch (ClassCastException cce) { value = yTransform(0); } int n = g.graph.getRingWidthData().size(); for (int i = 1; i < n; i++) { // new x-position for this point x += yearWidth; // if we're past the end, draw what we've got, and say goodbye // (go +_yearsize so the line going off the screen is visible) if (x > r + yearWidth) { break; } // Extract the window of interest int ringsEitherSideOfFocus = (App.prefs.getIntPref(PrefKey.STATS_SKELETON_PLOT_WINDOW_SIZE, 7) - 1) / 2; // Convert to ArrayList first as its easier to handle ArrayList<Double> ringWidths = new ArrayList<Double>(); for (int z = 0; z < n; z++) { ringWidths.add((double) g.graph.getRingWidthData().get(z).intValue()); } int firstind = i - 1 - ringsEitherSideOfFocus; int lastind = i + ringsEitherSideOfFocus; if (firstind < 0) firstind = 0; if (lastind > n) lastind = n; int size = lastind - firstind; double[] window = new double[size]; int t = 0; for (int w = firstind; w < lastind; w++) { window[t] = ringWidths.get(w); t++; } DescriptiveStatistics windowStats = new DescriptiveStatistics(window); /*if(i<7 ) { log.debug("Stats for ring: "+i); try{ log.debug(" Window 0: "+window[0]); log.debug(" Window 1: "+window[1]); log.debug(" Window 2: "+window[2]); log.debug(" Window 3: "+window[3]); log.debug(" Window 4: "+window[4]); log.debug(" Window 5: "+window[5]); log.debug(" Window 6: "+window[6]); } catch (ArrayIndexOutOfBoundsException e){} log.debug(" Mean is "+i+" - "+(int) windowStats.getMean()); log.debug(" Min is "+i+" - "+(int) windowStats.getMin()); log.debug(" Std is "+i+" - "+(int) windowStats.getStandardDeviation()); log.debug(" Std/2 is "+i+" - "+(int) windowStats.getStandardDeviation()/2); }*/ // y-position for this point try { value = yTransform(((Number) g.graph.getRingWidthData().get(i)).intValue() * g.scale); } catch (ClassCastException cce) { value = yTransform(0); // e.g., if it's being edited, it's still a string // BAD! instead: (1) draw what i've got so far, and (2) NEXT point is a move-to. // -- try to parse String as an integer? } int y = bottom - (int) (value * unitScale) - (int) (g.yoffset * unitScale); // Calculate skeleton category Integer skeletonCateogory = null; String prefAlg = App.prefs.getPref(PrefKey.STATS_SKELETON_PLOT_ALGORITHM, SkeletonPlotAlgorithm.PERCENTILES.toString()); if (prefAlg.equals(SkeletonPlotAlgorithm.PERCENTILES.toString())) { skeletonCateogory = getSkeletonCategoryFromPercentiles(value, windowStats); } else if (prefAlg.equals(SkeletonPlotAlgorithm.CROPPER1979_0POINT5.toString())) { skeletonCateogory = getSkeletonCategoryFromCropper1979(value, windowStats, 0.5); } else if (prefAlg.equals(SkeletonPlotAlgorithm.CROPPER1979_0POINT75.toString())) { skeletonCateogory = getSkeletonCategoryFromCropper1979(value, windowStats, 0.75); } // Draw the skeleton line if (areBonesBelowLine) { g2.drawLine(x, baseYVal, x, baseYVal + (skeletonCateogory * 5)); } else { g2.drawLine(x, baseYVal, x, baseYVal - (skeletonCateogory * 5)); } // Try and paint remark icons try { List<TridasRemark> remarks = g.graph.getTridasValues().get(i).getRemarks(); if (areBonesBelowLine) { Graph.drawRemarkIcons(g2, gInfo, remarks, g.graph.getTridasValues().get(i), x, baseYVal, false); } else { Graph.drawRemarkIcons(g2, gInfo, remarks, g.graph.getTridasValues().get(i), x, baseYVal, true); } } catch (Exception e) { log.error("Exception drawing icons to graph: " + e.getClass()); } } }
From source file:tufts.vue.LWComponent.java
/** * Useful for drawing drag images into an existing graphics buffer, or drawing exportable images. * * @param alpha 0.0 (invisible) to 1.0 (no alpha -- completely opaque) * @param maxSize max dimensions for image. May be null. Image may be smaller than maxSize. * @param fillColor -- if non-null, will be rendered as background for image. * @param zoomRequest -- desired zoom; ignored if maxSize is non-null * also set, background fill will have transparency of alpha^3 to enhance contrast. *//* ww w . j a v a 2s .c o m*/ public void drawImage(Graphics2D g, double alpha, Dimension maxSize, Color fillColor, double zoomRequest) { //if (DEBUG.IMAGE) out("drawImage; size " + maxSize); final boolean drawBorder = false;// this instanceof LWMap; // hack for dragged images of LWMaps final Rectangle2D.Float bounds = getImageBounds(); final Rectangle clip = g.getClipBounds(); final Size fillSize = new Size(bounds); final double zoom = computeZoomAndSize(bounds, maxSize, zoomRequest, fillSize); if (DEBUG.IMAGE) out(TERM_GREEN + "drawImage:" + "\n\t mapBounds: " + fmt(bounds) + "\n\t fill: " + fillColor + "\n\t maxSize: " + maxSize + "\n\t zoomRequest: " + zoomRequest + "\n\t fitZoom: " + zoom + "\n\t fillSize: " + fillSize + "\n\t gc: " + g + "\n\t clip: " + fmt(clip) + "\n\t alpha: " + alpha + TERM_CLEAR); final int width = fillSize.pixelWidth(); final int height = fillSize.pixelHeight(); final DrawContext dc = new DrawContext(g, this); dc.setInteractive(false); if (alpha == OPAQUE) { dc.setPrintQuality(); } else { // if alpha, assume drag image (todo: better specified as an argument) dc.setDraftQuality(); } dc.setBackgroundFill(getRenderFillColor(null)); // sure we want null here? dc.setClipOptimized(false); // always draw all children -- don't bother to check bounds if (DEBUG.IMAGE) out(TERM_GREEN + "drawImage: " + dc + TERM_CLEAR); if (fillColor != null) { // if (false && alpha != OPAQUE) { // Color c = fillColor; // // if we have an alpha and a fill, amplify the alpha on the background fill // // by changing the fill to one that has alpha*alpha, for a total of // // alpha*alpha*alpha given our GC already has an alpha set. // fillColor = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (alpha*alpha*255+0.5)); // } if (alpha != OPAQUE) dc.setAlpha(alpha, AlphaComposite.SRC); // erase any underlying in cache if (DEBUG.IMAGE) out("drawImage: fill=" + fillColor); g.setColor(fillColor); g.fillRect(0, 0, width, height); } else { //if (alpha != OPAQUE) { // we didn't have a fill, but we have an alpha: make sure any cached data is cleared // todo?: if fill is null, we need to clear as well -- it means we have implied alpha on any non-drawn bits // TODO: if this is a selection drag, we usually want to fill with the map color (or ideally, the color // of the common parent, e.g., a slide, if there's one common parent) dc.g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, width, height); } //if (alpha != OPAQUE) dc.setAlpha(alpha, AlphaComposite.SRC); if (DEBUG.IMAGE && DEBUG.META) { // Fill the entire imageable area g.setColor(Color.green); g.fillRect(0, 0, Short.MAX_VALUE, Short.MAX_VALUE); } final AffineTransform rawTransform = g.getTransform(); if (zoom != 1.0) dc.g.scale(zoom, zoom); // translate so that the upper left corner of the map region // we're drawing is at 0,0 on the underlying image g.translate(-bounds.getX(), -bounds.getY()); // GC *must* have a bounds set or we get NPE's in JComponent (textBox) rendering dc.setMasterClip(bounds); if (DEBUG.IMAGE && DEBUG.META) { // fill the clipped area so we can check our clip bounds dc.g.setColor(Color.red); dc.g.fillRect(-Short.MAX_VALUE / 2, -Short.MAX_VALUE / 2, // larger values than this can blow out internal GC code and we get nothing Short.MAX_VALUE, Short.MAX_VALUE); } if (this instanceof LWImage) { // for some reason, raw images don't seem to want to draw unless we fill first dc.g.setColor(Color.white); dc.g.fill(bounds); } // render to the image through the DrawContext/GC pointing to it draw(dc); if (drawBorder) { g.setTransform(rawTransform); //g.setColor(Color.red); //g.fillRect(0,0, Short.MAX_VALUE, Short.MAX_VALUE); if (DEBUG.IMAGE) { g.setColor(Color.black); dc.setAntiAlias(false); } else g.setColor(Color.darkGray); g.drawRect(0, 0, width - 1, height - 1); } if (DEBUG.IMAGE) out(TERM_GREEN + "drawImage: completed\n" + TERM_CLEAR); }