List of usage examples for java.awt.geom GeneralPath append
abstract void append(float x, float y);
From source file:ro.nextreports.engine.util.chart.CylinderRenderer.java
/** * Draws a cylinder to represent one data item. * //from w w w. ja va 2 s . co m * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area for plotting the data. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @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) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); float barL0 = Math.min(transL0, transL1); float barLength = Math.abs(transL1 - transL0); // draw the bar... GeneralPath bar = new GeneralPath(); if (orientation == PlotOrientation.HORIZONTAL) { bar.moveTo(barL0, (float) barW0); bar.lineTo(barL0, (float) (barW0 + state.getBarWidth())); bar.lineTo(barL0 + barLength, (float) (barW0 + state.getBarWidth())); bar.lineTo(barL0 + barLength, (float) barW0); bar.closePath(); } else { bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2)); bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2)); Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(), getYOffset(), 180, 180, Arc2D.OPEN); bar.append(arc, true); bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2)); arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180, Arc2D.OPEN); bar.append(arc, true); bar.closePath(); } Paint itemPaint = getItemPaint(row, column); if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; itemPaint = getGradientPaintTransformer().transform(gp, bar); } g2.setPaint(itemPaint); g2.fill(bar); Shape bar3dTop = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset()); if (itemPaint instanceof GradientPaint) { g2.setPaint(((GradientPaint) itemPaint).getColor2()); } g2.fill(bar3dTop); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar.getBounds2D(), (value < 0.0)); } // 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.getBounds2D(), tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } }
From source file:ucar.unidata.idv.control.chart.MyScatterPlot.java
/** * Draws the fast scatter plot on a Java 2D graphics device (such as the * screen or a printer)./* w w w.j a v a 2 s. c o m*/ * a * @param g2 the graphics device. * @param dataArea the data area * @param index which data set * @param info collects chart drawing information (<code>null</code> * permitted). * @param crosshairState crosshairState * * @return did something */ public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { if (index >= series.size()) { return false; } XYDataset dataset = getDataset(index); g2.setStroke(new BasicStroke()); // getRendererForDataset(dataset).getSeriesStroke(0)); ScatterPlotChartWrapper.MyRenderer renderer = (ScatterPlotChartWrapper.MyRenderer) getRendererForDataset( dataset); g2.setPaint(renderer.getSeriesPaint(0)); int shape = renderer.shape; PlotOrientation orientation = getOrientation(); int seenCnt = 0; int xx = (int) dataArea.getMinX(); int ww = (int) dataArea.getWidth(); int yy = (int) dataArea.getMaxY(); int hh = (int) dataArea.getHeight(); ValueAxis rangeAxis = getRangeAxisForDataset(index); ValueAxis domainAxis = getDomainAxisForDataset(index); double domainMin = domainAxis.getLowerBound(); double domainLength = domainAxis.getUpperBound() - domainMin; double rangeMin = rangeAxis.getLowerBound(); double rangeLength = rangeAxis.getUpperBound() - rangeMin; int boxWidth = 6; double[][] data = (double[][]) series.get(index); double[] d1 = data[0]; double[] d2 = data[1]; int size = d1.length; Hashtable seen = new Hashtable(); int lastX = 0; int lastY = 0; //TODO: Check for clipping //TODO: Try to create a GeneralPath with the points //and cal g2.draw just once GeneralPath path = new GeneralPath(); long t1 = System.currentTimeMillis(); for (int i = 0; i < size; i++) { int transX = (int) (xx + ww * (d1[i] - domainMin) / domainLength); int transY = (int) (yy - hh * (d2[i] - rangeMin) / rangeLength); Object key = transX + "_" + transY; if (seen.get(key) != null) { seenCnt++; continue; } seen.put(key, key); if (crosshairState != null) { crosshairState.updateCrosshairPoint(d1[i], d2[i], transX, transY, orientation); } switch (shape) { case LineState.SHAPE_VLINE: if (i > 1) { g2.drawLine(lastX, lastY, transX, transY); } lastX = transX; lastY = transY; case LineState.SHAPE_POINT: path.append(new Rectangle((int) transX, (int) transY, 1, 1), false); break; case LineState.SHAPE_LARGEPOINT: path.append(new Rectangle((int) transX, (int) transY, 2, 2), false); break; case LineState.SHAPE_RECTANGLE: path.append( new Rectangle((int) transX - boxWidth / 2, (int) transY - boxWidth / 2, boxWidth, boxWidth), false); break; case LineState.SHAPE_X: g2.drawLine(transX - boxWidth / 2, transY - boxWidth / 2, transX + boxWidth - boxWidth / 2, transY + boxWidth - boxWidth / 2); g2.drawLine(transX + boxWidth - boxWidth / 2, transY - boxWidth / 2, transX - boxWidth / 2, transY + boxWidth - boxWidth / 2); break; case LineState.SHAPE_PLUS: g2.drawLine(transX + boxWidth / 2, transY, transX + boxWidth / 2, transY + boxWidth); g2.drawLine(transX, transY + boxWidth / 2, transX + boxWidth, transY + boxWidth / 2); break; } } g2.fill(path); long t2 = System.currentTimeMillis(); // System.out.println ("time:" + (t2-t1)); return true; }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.MapPNode.java
private void init(JFrame parentFrame, SOMLibFormatInputReader inputReader, CommonSOMViewerStateData state, GrowingLayer growingLayer, boolean inizializeVis) { this.state = state; state.somInputReader = inputReader;/*from w w w .ja va 2 s. c o m*/ this.parentFrame = parentFrame; state.mapPNode = this; state.growingLayer = growingLayer; state.growingSOM = gsom; inputObjects = state.inputDataObjects; gsom.setSharedInputObjects(inputObjects); classInfo = inputObjects.getClassInfo(); dataInfo = inputObjects.getDataInfo(); // rudi: read input mapping shifts. note: has to be done before the units are constructed & displayed SOMVisualisationData inputCorrectionContainer = state.inputDataObjects .getObject(SOMVisualisationData.INPUT_CORRECTIONS); String fileName = inputCorrectionContainer.getFileName(); if (fileName != null && !fileName.trim().equals("")) { try { InputCorrections inputCorrections = new InputCorrections(fileName, growingLayer, state.inputDataObjects.getInputData()); inputCorrectionContainer.setData(inputCorrections); } catch (SOMToolboxException e) { Logger.getLogger("at.tuwien.ifs.somtoolbox").severe(e.getMessage()); } } else if (inputCorrectionContainer.getData() == null) { // create an empty object inputCorrectionContainer.setData(new InputCorrections()); } // create unit nodes units = new GeneralUnitPNode[growingLayer.getXSize()][growingLayer.getYSize()]; unitsNode = new PNode(); unitsNode.addAttribute("type", "unitsNode"); addChild(unitsNode); try { if (inputObjects.getDataWinnerMapping() == null) { state.exactUnitPlacementEnabled = false; } ProgressListener progress = new StdErrProgressWriter(growingLayer.getUnitCount(), "Initialising unit ", 50); for (int j = 0; j < growingLayer.getYSize(); j++) { for (int i = 0; i < growingLayer.getXSize(); i++) { if (growingLayer.getUnit(i, j) != null) { // check needed for mnemonic SOMs (might not have all // units != null) Unit unit = growingLayer.getUnit(i, j); Point[][] locations = null; if (inputObjects.getDataWinnerMapping() != null) { locations = initInputLocations(unit); } units[i][j] = new GeneralUnitPNode(unit, state, classInfo, dataInfo, locations, UNIT_WIDTH, UNIT_HEIGHT); unitsNode.addChild(units[i][j]); } progress.progress(); } } } catch (LayerAccessException e) { Logger.getLogger("at.tuwien.ifs.somtoolbox").severe(e.getMessage()); System.exit(-1); } // if we have a class info on startup, we show classes if (classInfo != null) { state.setClassPiechartMode(SOMViewer.TOGGLE_PIE_CHARTS_SHOW); setClassColors(classInfo.getClassColors()); } // create tooltip object and add event listener // final ToolTipPNode tooltipNode = new ToolTipPNode(); // this.addChild(tooltipNode); // this.addInputEventListener(new MyMapInputEventHandler(tooltipNode, this)); // initialize available visualizations if (inizializeVis) { Visualizations.initVisualizations(inputObjects, inputReader, this); } visualizations = Visualizations.getAvailableVisualizations(); // Angela: add the empty nodes for manually created labels this.addChild(manualLabels); manualLabels.moveToFront(); // add input correction arrows addChild(inputCorrectionsPNode); inputCorrectionsPNode.moveToFront(); // rudi: display linkages between data items if (state.inputDataObjects.getLinkageMap() != null) { Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Drawing constellations."); GeneralPath path = new GeneralPath(); Map<String, String> linkageMap = state.inputDataObjects.getLinkageMap(); for (String beginName : linkageMap.keySet()) { String endName = linkageMap.get(beginName); Point beginPoint = getPointLocation(beginName); Point endPoint = getPointLocation(endName); if (beginPoint != null && endPoint != null) { path.append(new Line2D.Double(beginPoint, endPoint), false); } } inputLinkagePath = new PPath(path); inputLinkagePath.setStrokePaint(new Color(232, 232, 57)); inputLinkagePath.setStroke(new BasicStroke(1.5f)); inputLinkagePath.setPickable(false); if (state.displayInputLinkage) { addChild(inputLinkagePath); inputLinkagePath.moveToBack(); } Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Drawing constellations done."); } // display input mapping shifts. note: has to be done after the units are constructed createInputCorrectionArrows(); imageDataNode = new PNode(); this.addChild(imageDataNode); // if we have a SOM of image types, create image nodes if (gsom.getDataContentType() != null && gsom.getDataContentType().isImage() || org.apache.commons.lang.StringUtils.isNotBlank(CommonSOMViewerStateData.imagePrefix) || org.apache.commons.lang.StringUtils.isNotBlank(CommonSOMViewerStateData.imageSuffix)) { createDataImages(); } }
From source file:com.jhlabs.awt.TextStroke.java
public Shape createStrokedShape(Shape shape) { FontRenderContext frc = new FontRenderContext(null, true, true); GlyphVector glyphVector = font.createGlyphVector(frc, text); GeneralPath result = new GeneralPath(); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); float points[] = new float[6]; float moveX = 0, moveY = 0; float lastX = 0, lastY = 0; float thisX = 0, thisY = 0; int type = 0; float next = 0; int currentChar = 0; int length = glyphVector.getNumGlyphs(); if (length == 0) return result; float factor = stretchToFit ? measurePathLength(shape) / (float) glyphVector.getLogicalBounds().getWidth() : 1.0f;//from w w w . j av a 2 s. c o m float height = (float) glyphVector.getLogicalBounds().getHeight(); float nextAdvance = 0; while (currentChar < length && !it.isDone()) { type = it.currentSegment(points); switch (type) { case PathIterator.SEG_MOVETO: moveX = lastX = points[0]; moveY = lastY = points[1]; result.moveTo(moveX, moveY); nextAdvance = glyphVector.getGlyphMetrics(currentChar).getAdvance() * 0.5f; next = nextAdvance; break; case PathIterator.SEG_CLOSE: points[0] = moveX; points[1] = moveY; // Fall into.... case PathIterator.SEG_LINETO: thisX = points[0]; thisY = points[1]; float dx = thisX - lastX; float dy = thisY - lastY; float distance = (float) FastMath.sqrt(dx * dx + dy * dy); if (distance >= next) { float r = 1.0f / distance; float angle = (float) FastMath.atan2(dy, dx); while (currentChar < length && distance >= next) { Shape glyph = glyphVector.getGlyphOutline(currentChar); Point2D p = glyphVector.getGlyphPosition(currentChar); float px = (float) p.getX(); float py = (float) p.getY(); float x = lastX + next * dx * r; float y = lastY + next * dy * r; float advance = nextAdvance; nextAdvance = currentChar < length - 1 ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f : 0; t.setToTranslation(x, y); t.rotate(angle); t.translate(-px - advance, -py + height * factor / 2.0f); result.append(t.createTransformedShape(glyph), false); next += (advance + nextAdvance) * factor; currentChar++; if (repeat) currentChar %= length; } } next -= distance; lastX = thisX; lastY = thisY; break; } it.next(); } return result; }
From source file:org.amanzi.awe.render.network.NetworkRenderer.java
/** * render sector element on map/* ww w .jav a 2s .c o m*/ * * @param destination * @param point * @param element */ private void renderSector(final Graphics2D destination, final Point point, final double azimuth, final double beamwidth, final IDataElement sector) { int size = getSize(); int x = getSectorXCoordinate(point, size); int y = getSectorYCoordinate(point, size); destination.setColor(networkRendererStyle.changeColor(getColor(sector), networkRendererStyle.getAlpha())); GeneralPath path = new GeneralPath(); path.moveTo(x, y); Arc2D a = createSector(point, networkRendererStyle.getLargeElementSize(), getAngle(azimuth, beamwidth), beamwidth); path.append(a.getPathIterator(null), true); path.closePath(); destination.draw(path); destination.fill(path); // create border destination.setColor(networkRendererStyle.getBorderColor()); destination.draw(path); }
From source file:org.amanzi.awe.render.network.NetworkRenderer.java
/** * Draw black border around selected sector * /*from ww w . ja v a2s . 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:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void drawArc(ArcRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);/*from www .j ava2 s . c o m*/ } // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED final LineAttributes lia = are.getOutline(); if (!validateLineAttributes(are.getSource(), lia)) { return; } // SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL) final Color cFG = (Color) validateEdgeColor(lia.getColor(), are.getBackground(), _ids); if (cFG == null || cFG.getAlpha() == 0) { return; } // DRAW THE ARC Stroke sPrevious = null; Stroke sCurrent = getCachedStroke(lia); if (sCurrent != null) // SOME STROKE DEFINED? { sPrevious = _g2d.getStroke(); _g2d.setStroke(sCurrent); } _g2d.setColor(cFG); if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius()) || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) { Bounds rctOuter = getOuterRectangle(are); Bounds rctInner = getInnerRectangle(are); Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(), rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.OPEN); Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(), rctInner.getHeight(), are.getStartAngle() + are.getAngleExtent(), -are.getAngleExtent(), Arc2D.OPEN); double startAngle = Math.toRadians(-are.getStartAngle()); double stopAngle = Math.toRadians(-are.getStartAngle() - are.getAngleExtent()); double xsOuter = (rctOuter.getLeft() + (Math.cos(startAngle) * 0.5 + 0.5) * rctOuter.getWidth()); double ysOuter = (rctOuter.getTop() + (Math.sin(startAngle) * 0.5 + 0.5) * rctOuter.getHeight()); double xeInner = (rctInner.getLeft() + (Math.cos(stopAngle) * 0.5 + 0.5) * rctInner.getWidth()); double yeInner = (rctInner.getTop() + (Math.sin(stopAngle) * 0.5 + 0.5) * rctInner.getHeight()); GeneralPath gp = new GeneralPath(); gp.append(outerArc, false); gp.lineTo((float) xeInner, (float) yeInner); gp.append(innerArc, false); gp.lineTo((float) xsOuter, (float) ysOuter); Area area = new Area(gp); Shape prevClip = _g2d.getClip(); Area ar2 = new Area(area); if (prevClip != null) { Area ar1 = new Area(prevClip); ar2.intersect(ar1); } _g2d.setClip(ar2); _g2d.draw(area); _g2d.setClip(prevClip); } else { _g2d.draw(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle()))); } if (sPrevious != null) // RESTORE PREVIOUS STROKE { _g2d.setStroke(sPrevious); } }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void drawArea(AreaRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);//from ww w . j a v a 2 s . c o m } // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED final LineAttributes lia = are.getOutline(); if (!validateLineAttributes(are.getSource(), lia)) { return; } // SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL) final Color cFG = (Color) validateEdgeColor(lia.getColor(), are.getBackground(), _ids); // IF UNDEFINED OR TOTALLY TRANSPARENT, EXIT if (cFG == null || cFG.getAlpha() == 0) { return; } // BUILD THE GENERAL PATH STRUCTURE final GeneralPath gp = new GeneralPath(); PrimitiveRenderEvent pre; for (int i = 0; i < are.getElementCount(); i++) { pre = are.getElement(i); if (pre instanceof ArcRenderEvent) { final ArcRenderEvent acre = (ArcRenderEvent) pre; final Arc2D.Double a2d = new Arc2D.Double(acre.getTopLeft().getX(), acre.getTopLeft().getY(), acre.getWidth(), acre.getHeight(), acre.getStartAngle(), acre.getAngleExtent(), toG2dArcType(acre.getStyle())); gp.append(a2d, true); } else if (pre instanceof LineRenderEvent) { final LineRenderEvent lre = (LineRenderEvent) pre; final Line2D.Double l2d = new Line2D.Double(lre.getStart().getX(), lre.getStart().getY(), lre.getEnd().getX(), lre.getEnd().getY()); gp.append(l2d, true); } } // DRAW THE GENERAL PATH Stroke sPrevious = null; Stroke sCurrent = getCachedStroke(lia); if (sCurrent != null) // SOME STROKE DEFINED? { sPrevious = _g2d.getStroke(); _g2d.setStroke(sCurrent); } _g2d.setColor(cFG); _g2d.draw(gp); if (sPrevious != null) // RESTORE PREVIOUS STROKE { _g2d.setStroke(sPrevious); } }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void fillArea(AreaRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);//from w ww.jav a 2 s . c o m } final Fill flBackground = validateMultipleFill(are.getBackground()); if (isFullTransparent(flBackground)) { return; } // SETUP SWING DATA STRUCTURES final GeneralPath gp = new GeneralPath(); PrimitiveRenderEvent pre; for (int i = 0; i < are.getElementCount(); i++) { pre = are.getElement(i); if (pre instanceof ArcRenderEvent) { final ArcRenderEvent acre = (ArcRenderEvent) pre; final Arc2D.Double a2d = new Arc2D.Double(acre.getTopLeft().getX(), acre.getTopLeft().getY(), acre.getWidth(), acre.getHeight(), acre.getStartAngle(), acre.getAngleExtent(), toG2dArcType(acre.getStyle())); gp.append(a2d, true); } else if (pre instanceof LineRenderEvent) { final LineRenderEvent lre = (LineRenderEvent) pre; final Line2D.Double l2d = new Line2D.Double(lre.getStart().getX(), lre.getStart().getY(), lre.getEnd().getX(), lre.getEnd().getY()); gp.append(l2d, true); } } // BEGIN FILLING if (flBackground instanceof ColorDefinition) { _g2d.setColor((Color) _ids.getColor((ColorDefinition) flBackground)); } else if (flBackground instanceof Gradient) { final Gradient g = (Gradient) flBackground; final ColorDefinition cdStart = g.getStartColor(); final ColorDefinition cdEnd = g.getEndColor(); // boolean bCyclic = g.isCyclic(); double dAngleInDegrees = g.getDirection(); final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0); // int iAlpha = g.getTransparency(); Bounds bo = are.getBounds(); /* * if (bCyclic) { } */ if (dAngleInDegrees < -90 || dAngleInDegrees > 90) { throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, "SwingRendererImpl.exception.gradient.angle", //$NON-NLS-1$ new Object[] { new Double(dAngleInDegrees) }, Messages.getResourceBundle(getULocale())); } Point2D.Double p2dStart, p2dEnd; if (dAngleInDegrees == 90) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees == -90) { p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees > 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getHeight() - bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else if (dAngleInDegrees < 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop()); } _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd, (Color) _ids.getColor(cdEnd))); } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) { // TODO TBD } _g2d.fill(gp); }
From source file:org.squidy.designer.util.ImageUtils.java
public static Shape getShapeOfImage(BufferedImage image) { // Get the data Raster data = image.getData(); ////from w w w . jav a 2 s. c om // System.out.println("num of bands = " + data.getNumBands()); // The colour of the pixel looking at // Shoulld have length of 4 (RGBA) int[] lookAt = null; // The map of all the points Point2D[][] pointMap = new Point2D[data.getWidth()][data.getHeight()]; // The from point Point2D from = null; // The general path GeneralPath path = new GeneralPath(); // Go round height for (int y = 0; y < data.getHeight(); y++) { // Go round width for (int x = 0; x < data.getWidth(); x++) { // Get the colour lookAt = data.getPixel(x, y, lookAt); // The alpha int a = lookAt[3]; // If > then 0 if (a > 0) { // Output 1 //System.out.print(1); // Save point pointMap[x][y] = new Point2D.Double(x, y); if (from == null) { from = pointMap[x][y]; } } // 0 else { // Output 0 //System.out.print(0); // Nothing her pointMap[x][y] = null; } } // New line //System.out.println(); } // Move it to the from if (from != null) { path.moveTo(from.getX(), from.getY()); /* * Make the shape */ // Go round height for (int y = 0; y < data.getHeight(); y++) { // Go round width for (int x = 0; x < data.getWidth(); x++) { // If the point is not null if (pointMap[x][y] != null) { // Draw a line to path.append(new Rectangle2D.Double(pointMap[x][y].getX(), pointMap[x][y].getY(), 1, 1), true); // path.lineTo(pointMap[x][y].getX(), pointMap[x][y].getY()); } } } path.closePath(); // TODO: Put in the middle return path; } return null; }