Example usage for java.awt Graphics2D setComposite

List of usage examples for java.awt Graphics2D setComposite

Introduction

In this page you can find the example usage for java.awt Graphics2D setComposite.

Prototype

public abstract void setComposite(Composite comp);

Source Link

Document

Sets the Composite for the Graphics2D context.

Usage

From source file:MyJava3D.java

public Graphics2D createGraphics2D(int width, int height, BufferedImage bi, Graphics g) {

    Graphics2D g2 = null;

    if (bi != null) {
        g2 = bi.createGraphics();/* w  w w.  j a v  a 2  s .  com*/
    } else {
        g2 = (Graphics2D) g;
    }

    g2.setBackground(getBackground());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, AntiAlias);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, Rendering);

    if (clearSurface || clearOnce) {
        g2.clearRect(0, 0, width, height);
        clearOnce = false;
    }

    if (texture != null) {
        // set composite to opaque for texture fills
        g2.setComposite(AlphaComposite.SrcOver);
        g2.setPaint(texture);
        g2.fillRect(0, 0, width, height);
    }

    if (composite != null) {
        g2.setComposite(composite);
    }

    return g2;
}

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (mTimeFrame == null) {
        renderNoInfoView(g);//  w  ww.ja v  a2s.  co m
    } else {
        updateSize();
        LongRange startRange = mTimeFrame.getStartRange();
        LongRange arriveRange = mTimeFrame.getArriveRange();
        HashMap<LongRange, TimeSpan> startRanges = mTimeFrame
                .startTimespansToRangesMap(AnyTribe.getSingleton());
        HashMap<LongRange, TimeSpan> arriveRanges = mTimeFrame.arriveTimespansToRangesMap(null);
        long minValue = startRange.getMinimumLong();
        long maxValue = arriveRange.getMaximumLong();
        Graphics2D g2d = (Graphics2D) g;
        g2d.setPaint(new TexturePaint(STROKED, new Rectangle(0, 0, 3, 3)));
        g2d.fillRect(0, 0, getWidth(), getHeight());

        //draw frame around the entire range
        renderRange(new LongRange(startRange.getMinimumLong(), arriveRange.getMaximumLong()), startRange,
                arriveRange, false, false, g2d, null, popupInfo);
        g2d.setColor(Constants.DS_BACK);
        popupInfo.clear();
        //fill start range
        renderRange(startRange, startRange, arriveRange, true, false, g2d, null, popupInfo);
        //fill arrive range
        renderRange(arriveRange, startRange, arriveRange, false, true, g2d, null, popupInfo);
        Paint p = g2d.getPaint();
        Iterator<LongRange> rangeKeys = startRanges.keySet().iterator();
        while (rangeKeys.hasNext()) {
            LongRange currentRange = rangeKeys.next();

            TimeSpan spanForRange = startRanges.get(currentRange);
            if (spanForRange != null) {
                if (spanForRange.isValidAtEveryDay()) {
                    g2d.setPaint(new TexturePaint(DAILY_START_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
                } else if (spanForRange.isValidAtExactTime()) {
                    g2d.setPaint(new TexturePaint(EXACT_START_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
                } else {
                    g2d.setPaint(new TexturePaint(ONE_DAY_START_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
                }
            }
            renderRange(currentRange, startRange, arriveRange, false, false, g2d, spanForRange, popupInfo);
        }

        Composite c = g2d.getComposite();
        rangeKeys = arriveRanges.keySet().iterator();
        while (rangeKeys.hasNext()) {
            LongRange currentRange = rangeKeys.next();
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
            g2d.setPaint(new TexturePaint(ARRIVE_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
            TimeSpan spanForRange = arriveRanges.get(currentRange);
            renderRange(currentRange, startRange, arriveRange, false, false, g2d, spanForRange, popupInfo);
        }
        g2d.setComposite(c);
        g2d.setPaint(p);
        renderDayMarkers(minValue, maxValue, g2d);
        renderPopup(popupInfo, g2d);
    }
}

From source file:lucee.runtime.img.Image.java

public void setAlpha(float alpha) throws ExpressionException {
    this.alpha = alpha;
    Graphics2D g = getGraphics();

    Composite alphaComposite;//from  w  w w. jav  a  2s.  c o m
    if (composite == null) {
        if (alpha == 1)
            return;
        composite = g.getComposite();
    }
    if (alpha == 1)
        alphaComposite = composite;
    else
        alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);

    g.setComposite(alphaComposite);
    //graphics.setComposite(originalComposite);   
}

From source file:org.proteosuite.FastScatterPlot.java

/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the 
 * screen or a printer)./*from   w w  w  . ja  v  a 2  s . c o  m*/
 *
 * @param g2  the graphics device.
 * @param area   the area within which the plot (including axis labels)
 *                   should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects chart drawing information (<code>null</code> 
 *              permitted).
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {

    // set up info collection...
    if (info != null) {
        info.setPlotArea(area);
    }

    // adjust the drawing area for plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    AxisSpace space = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);
    Rectangle2D dataArea = space.shrink(area, null);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);

    AxisState domainAxisState = null;
    AxisState rangeAxisState = null;
    if (this.domainAxis != null) {
        domainAxisState = this.domainAxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM,
                info);
    }
    if (this.rangeAxis != null) {
        rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);
    }
    drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());

    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();

    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    render(g2, dataArea, info, null);

    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);

}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void drawInformationBox(Graphics2D g2, Activities activities, Rectangle2D rect, List<String> params,
        List<String> values, String totalParam, double totalValue, Color background_color, Color border_color) {
    final Font oldFont = g2.getFont();
    final Font paramFont = oldFont;
    final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont);
    final Font valueFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() + 1);
    final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont);
    final Font dateFont = oldFont.deriveFont((float) oldFont.getSize() - 1);
    final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont);

    final int x = (int) rect.getX();
    final int y = (int) rect.getY();
    final int width = (int) rect.getWidth();
    final int height = (int) rect.getHeight();

    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Composite oldComposite = g2.getComposite();
    final Color oldColor = g2.getColor();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(border_color);/*from   w  w  w. j  a v  a 2s . co  m*/
    g2.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 15, 15);
    g2.setColor(background_color);
    g2.setComposite(Utils.makeComposite(0.75f));
    g2.fillRoundRect(x, y, width, height, 15, 15);
    g2.setComposite(oldComposite);
    g2.setColor(oldColor);

    final Date date = activities.getDate().getTime();
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy");
    final String dateString = simpleDateFormat.format(date);

    final int padding = 5;

    int yy = y + padding + dateFontMetrics.getAscent();
    g2.setFont(dateFont);
    g2.setColor(COLOR_BLUE);
    g2.drawString(dateString, ((width - dateFontMetrics.stringWidth(dateString)) >> 1) + x, yy);

    int index = 0;
    final int dateInfoHeightMargin = 5;
    final int infoTotalHeightMargin = 5;
    final int paramValueHeightMargin = 0;

    yy += dateFontMetrics.getDescent() + dateInfoHeightMargin
            + Math.max(paramFontMetrics.getAscent(), valueFontMetrics.getAscent());
    for (String param : params) {
        final String value = values.get(index++);
        g2.setColor(Color.BLACK);
        g2.setFont(paramFont);
        g2.drawString(param + ":", padding + x, yy);
        g2.setFont(valueFont);
        g2.drawString(value, width - padding - valueFontMetrics.stringWidth(value) + x, yy);
        // Same as yy += valueFontMetrics.getDescent() + paramValueHeightMargin + valueFontMetrics.getAscent()
        yy += paramValueHeightMargin + Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight());
    }

    if (values.size() > 1) {
        yy -= paramValueHeightMargin;
        yy += infoTotalHeightMargin;
        if (totalValue > 0.0) {
            g2.setColor(JStockOptions.DEFAULT_HIGHER_NUMERICAL_VALUE_FOREGROUND_COLOR);
        } else if (totalValue < 0.0) {
            g2.setColor(JStockOptions.DEFAULT_LOWER_NUMERICAL_VALUE_FOREGROUND_COLOR);
        }

        g2.setFont(paramFont);
        g2.drawString(totalParam + ":", padding + x, yy);
        g2.setFont(valueFont);
        final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace();
        final String totalValueStr = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace,
                totalValue);
        g2.drawString(totalValueStr, width - padding - valueFontMetrics.stringWidth(totalValueStr) + x, yy);
    }

    g2.setColor(oldColor);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    g2.setFont(oldFont);
}

From source file:spinworld.gui.RadarPlot.java

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer)./*from  w  w  w.j a  v  a2s  .c om*/
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {

    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    if (info != null) {
        info.setPlotArea(area);
        info.setDataArea(area);
    }

    drawBackground(g2, area);
    drawOutline(g2, area);

    Shape savedClip = g2.getClip();

    g2.clip(area);
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        int seriesCount = 0, catCount = 0;

        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            seriesCount = this.dataset.getRowCount();
            catCount = this.dataset.getColumnCount();
        } else {
            seriesCount = this.dataset.getColumnCount();
            catCount = this.dataset.getRowCount();
        }

        // ensure we have origin and maximum value for each axis
        ensureBoundaryValues(seriesCount, catCount);

        // Next, setup the plot area

        // adjust the plot area by the interior spacing value

        double gapHorizontal = area.getWidth() * getInteriorGap();
        double gapVertical = area.getHeight() * getInteriorGap();

        double X = area.getX() + gapHorizontal / 2;
        double Y = area.getY() + gapVertical / 2;
        double W = area.getWidth() - gapHorizontal;
        double H = area.getHeight() - gapVertical;

        double headW = area.getWidth() * this.headPercent;
        double headH = area.getHeight() * this.headPercent;

        // make the chart area a square
        double min = Math.min(W, H) / 2;
        X = (X + X + W) / 2 - min;
        Y = (Y + Y + H) / 2 - min;
        W = 2 * min;
        H = 2 * min;

        Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2);
        Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H);

        // draw the axis and category label
        for (int cat = 0; cat < catCount; cat++) {
            double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount);

            Point2D endPoint = getWebPoint(radarArea, angle, 1);
            // 1 = end of axis
            Line2D line = new Line2D.Double(centre, endPoint);
            g2.setPaint(this.axisLinePaint);
            g2.setStroke(this.axisLineStroke);
            g2.draw(line);
            if (isAxisTickVisible()) {
                drawTicks(g2, radarArea, angle, cat);
            }
            drawLabel(g2, area, radarArea, 0.0, cat, angle, 360.0 / catCount);
        }

        // Now actually plot each of the series polygons..
        for (int series = 0; series < seriesCount; series++) {
            drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW);
        }
    } else {
        drawNoDataMessage(g2, area);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, area);
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Draws the label for one axis.//www  .  j  ava  2 s  .  c  om
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area
 * @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, 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);
    }

    Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
    LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
    double ascent = lm.getAscent();

    Point2D labelLocation = calculateLabelLocation(labelBounds, ascent, plotArea, startAngle);

    Composite saveComposite = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    g2.setPaint(getLabelPaint());
    g2.setFont(getLabelFont());
    g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY());
    g2.setComposite(saveComposite);
}

From source file:org.pmedv.blackboard.components.BoardEditor.java

/**
 * Draws the selected item to the graphics context
 * //from www  .  j  a v  a  2  s.  co m
 * @param layer the layer to be drawn
 * @param g2d the graphics context
 */
private void drawLayer(Layer layer, Graphics2D g2d) {
    if (!layer.isVisible())
        return;

    DefaultTransformModel xmodel = null;

    if (zoomLayer != null) {
        TransformUI ui = (TransformUI) (Object) zoomLayer.getUI();
        xmodel = (DefaultTransformModel) ui.getModel();
    }

    if (layer.getName().equalsIgnoreCase("board")) {
        if (backgroundImage != null) {
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity()));
            g2d.drawImage(backgroundImage, 0, 0, this);
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
        } else {
            g2d.setColor(Color.WHITE);
            g2d.fillRect(0, 0, getWidth(), getHeight());
        }

        g2d.setColor(Color.LIGHT_GRAY);
        g2d.setStroke(BoardUtil.stroke_1_0f);

        Boolean dotGrid = (Boolean) Preferences.values
                .get("org.pmedv.blackboard.BoardDesignerPerspective.dotGrid");
        // draw grid
        if (gridVisible) {
            BoardUtil.drawGrid(g2d, raster, model.getWidth(), model.getHeight(), dotGrid.booleanValue());
        }

        return;
    }

    if (layer.getName().equalsIgnoreCase("ratsnest")) {
        if (layer.getImage() != null) {
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity()));
            g2d.drawImage(layer.getImage(), 0, 0, this);
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
        }
        return;
    }

    for (Item item : layer.getItems()) {

        if (xmodel != null)
            item.setMirror(xmodel.isMirror());

        item.setOpacity(layer.getOpacity());

        if (item instanceof Line) {
            Line line = (Line) item;
            if (line.getStroke() != null)
                g2d.setStroke(line.getStroke());
            else
                g2d.setStroke(BoardUtil.stroke_3_0f);
            g2d.setColor(item.getColor());
        }

        item.draw(g2d);

        if (selectedItems.contains(item)) {
            g2d.setColor(Color.GREEN);
            g2d.setStroke(BoardUtil.stroke_1_0f);
            item.drawHandles(g2d, 8);
        }
    }
}

From source file:org.nuclos.client.ui.resplan.header.JHeaderGrid.java

@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;

    super.paintComponent(g2d);

    g2d.setPaint(gridColor);/*from  ww  w.  j a va  2s  .  c  o m*/

    Rectangle clipBounds = g.getClipBounds();

    int[] indices = stripRangeForRect(clipBounds);
    int startIndex = indices[0];
    int endIndex = indices[1];

    Point p1, p2;
    p1 = new Point();
    p2 = new Point(getWidth(), getHeight());
    for (int i = startIndex; i <= endIndex; i++) {
        int gridLine = getGridLine(i);
        orientation.updateCoord(p1, gridLine);
        orientation.updateCoord(p2, gridLine);
        g2d.drawLine(p1.x, p1.y, p2.x, p2.y);
    }

    p1.setLocation(0, 0);
    p2.setLocation(getWidth(), getHeight());
    int groupGridLine = 0;
    for (CategoryView v : groupings) {
        groupGridLine += v.size;
        orientation.opposite().updateCoord(p1, groupGridLine);
        orientation.opposite().updateCoord(p2, groupGridLine);
        g2d.drawLine(p1.x, p1.y, p2.x, p2.y);
        groupGridLine += GRID_SIZE;
    }

    for (int level = 0, levelCount = groupings.length; level < levelCount; level++) {
        for (HeaderCell cell : groupings[level].cells) {
            if (cell.endIndex < startIndex || cell.startIndex >= endIndex)
                continue;
            Rectangle rect = getRect(level, cell.startIndex, cell.endIndex);
            if (clipBounds != null && !clipBounds.intersects(rect))
                continue;
            paintHeaderCell(g2d, rect, cell.levelValue);
        }
    }

    if (cellResizingRange != null) {
        Rectangle rect = new Rectangle(getWidth(), getHeight());
        orientation.updateRange(rect, cellResizingRange);
        rect.grow(orientation.select(GRID_SIZE, 0), orientation.select(0, GRID_SIZE));
        g2d.setColor(new Color(0x9999ff, false));
        g2d.draw(rect);
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
        g2d.fill(rect);
    }
}

From source file:au.org.ala.biocache.web.WMSController.java

/**
 * Method that produces the downloadable map integrated in AVH/OZCAM/Biocache.
 *
 * @param requestParams// ww  w  .  java  2  s . c  om
 * @param format
 * @param extents
 * @param widthMm
 * @param pointRadiusMm
 * @param pradiusPx
 * @param pointColour
 * @param pointOpacity
 * @param baselayer
 * @param scale
 * @param dpi
 * @param outlinePoints
 * @param outlineColour
 * @param fileName
 * @param request
 * @param response
 * @throws Exception
 */
@RequestMapping(value = { "/webportal/wms/image", "/mapping/wms/image" }, method = RequestMethod.GET)
public void generatePublicationMap(SpatialSearchRequestParams requestParams,
        @RequestParam(value = "format", required = false, defaultValue = "jpg") String format,
        @RequestParam(value = "extents", required = true) String extents,
        @RequestParam(value = "widthmm", required = false, defaultValue = "60") Double widthMm,
        @RequestParam(value = "pradiusmm", required = false, defaultValue = "2") Double pointRadiusMm,
        @RequestParam(value = "pradiuspx", required = false) Integer pradiusPx,
        @RequestParam(value = "pcolour", required = false, defaultValue = "FF0000") String pointColour,
        @RequestParam(value = "popacity", required = false, defaultValue = "0.8") Double pointOpacity,
        @RequestParam(value = "baselayer", required = false, defaultValue = "world") String baselayer,
        @RequestParam(value = "scale", required = false, defaultValue = "off") String scale,
        @RequestParam(value = "dpi", required = false, defaultValue = "300") Integer dpi,
        @RequestParam(value = "outline", required = true, defaultValue = "false") boolean outlinePoints,
        @RequestParam(value = "outlineColour", required = true, defaultValue = "#000000") String outlineColour,
        @RequestParam(value = "fileName", required = false) String fileName, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    String[] bb = extents.split(",");

    double long1 = Double.parseDouble(bb[0]);
    double lat1 = Double.parseDouble(bb[1]);
    double long2 = Double.parseDouble(bb[2]);
    double lat2 = Double.parseDouble(bb[3]);

    if (lat1 <= -90) {
        lat1 = -89.999;
    }
    if (lat2 >= 90) {
        lat2 = 89.999;
    }

    int pminx = convertLngToPixel(long1);
    int pminy = convertLatToPixel(lat1);
    int pmaxx = convertLngToPixel(long2);
    int pmaxy = convertLatToPixel(lat2);

    int width = (int) ((dpi / 25.4) * widthMm);
    int height = (int) Math.round(width * ((pminy - pmaxy) / (double) (pmaxx - pminx)));

    if (height * width > MAX_IMAGE_PIXEL_COUNT) {
        String errorMessage = "Image size in pixels " + width + "x" + height + " exceeds "
                + MAX_IMAGE_PIXEL_COUNT + " pixels.  Make the image smaller";
        response.sendError(response.SC_NOT_ACCEPTABLE, errorMessage);
        throw new Exception(errorMessage);
    }

    int pointSize = -1;
    if (pradiusPx != null) {
        pointSize = (int) pradiusPx;
    } else {
        pointSize = (int) ((dpi / 25.4) * pointRadiusMm);
    }

    double[] boundingBox = transformBbox4326To900913(Double.parseDouble(bb[0]), Double.parseDouble(bb[1]),
            Double.parseDouble(bb[2]), Double.parseDouble(bb[3]));

    //"http://biocache.ala.org.au/ws/webportal/wms/reflect?
    //q=macropus&ENV=color%3Aff0000%3Bname%3Acircle%3Bsize%3A3%3Bopacity%3A1
    //&BBOX=12523443.0512,-2504688.2032,15028131.5936,0.33920000120997&WIDTH=256&HEIGHT=256");
    String speciesAddress = baseWsUrl + "/ogc/wms/reflect?" + "ENV=color%3A" + pointColour
            + "%3Bname%3Acircle%3Bsize%3A" + pointSize + "%3Bopacity%3A" + pointOpacity + "&BBOX="
            + boundingBox[0] + "," + boundingBox[1] + "," + boundingBox[2] + "," + boundingBox[3] + "&WIDTH="
            + width + "&HEIGHT=" + height + "&OUTLINE=" + outlinePoints + "&OUTLINECOLOUR=" + outlineColour
            + "&" + request.getQueryString();

    URL speciesURL = new URL(speciesAddress);
    BufferedImage speciesImage = ImageIO.read(speciesURL);

    //"http://spatial.ala.org.au/geoserver/wms/reflect?
    //LAYERS=ALA%3Aworld&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=
    //&FORMAT=image%2Fjpeg&SRS=EPSG%3A900913&BBOX=12523443.0512,-1252343.932,13775787.3224,0.33920000004582&WIDTH=256&HEIGHT=256"
    String layout = "";
    if (!scale.equals("off")) {
        layout += "layout:scale";
    }
    String basemapAddress = geoserverUrl + "/wms/reflect?" + "LAYERS=ALA%3A" + baselayer
            + "&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=" + "&FORMAT=image%2Fpng&SRS=EPSG%3A900913" //specify the mercator projection
            + "&BBOX=" + boundingBox[0] + "," + boundingBox[1] + "," + boundingBox[2] + "," + boundingBox[3]
            + "&WIDTH=" + width + "&HEIGHT=" + height + "&OUTLINE=" + outlinePoints + "&format_options=dpi:"
            + dpi + ";" + layout;

    BufferedImage basemapImage = ImageIO.read(new URL(basemapAddress));

    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D combined = (Graphics2D) img.getGraphics();

    combined.drawImage(basemapImage, 0, 0, Color.WHITE, null);
    //combined.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, pointOpacity.floatValue()));
    combined.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    combined.drawImage(speciesImage, null, 0, 0);
    combined.dispose();

    //if filename supplied, force a download
    if (fileName != null) {
        response.setContentType("application/octet-stream");
        response.setHeader("Content-Description", "File Transfer");
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        response.setHeader("Content-Transfer-Encoding", "binary");
    } else if (format.equalsIgnoreCase("png")) {
        response.setContentType("image/png");
    } else {
        response.setContentType("image/jpeg");
    }

    if (format.equalsIgnoreCase("png")) {
        OutputStream os = response.getOutputStream();
        ImageIO.write(img, format, os);
        os.close();
    } else {
        //handle jpeg + BufferedImage.TYPE_INT_ARGB
        BufferedImage img2;
        Graphics2D c2;
        (c2 = (Graphics2D) (img2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)).getGraphics())
                .drawImage(img, 0, 0, Color.WHITE, null);
        c2.dispose();
        OutputStream os = response.getOutputStream();
        ImageIO.write(img2, format, os);
        os.close();
    }
}