Example usage for android.graphics Paint setAlpha

List of usage examples for android.graphics Paint setAlpha

Introduction

In this page you can find the example usage for android.graphics Paint setAlpha.

Prototype

public void setAlpha(int a) 

Source Link

Document

Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.

Usage

From source file:net.line2soft.preambul.views.SlippyMapActivity.java

/**
 * Creates a {@link Paint} object with a certain color
 * @param color The wanted color//w ww .j a  v a 2  s  .c o  m
 * @param alpha The alpha channel
 * @return The created Paint object
 */
private Paint createPaint(int color, int alpha) {
    Paint pnt = new Paint(Paint.ANTI_ALIAS_FLAG);
    pnt.setColor(color);
    pnt.setAlpha(alpha);
    pnt.setStyle(Paint.Style.STROKE);
    pnt.setStrokeWidth(7);
    pnt.setStrokeJoin(Paint.Join.ROUND);
    pnt.setStrokeCap(Paint.Cap.ROUND);
    //pnt.setPathEffect(new DashPathEffect(new float[] { 20, 20 }, 0));
    return pnt;
}

From source file:com.waz.zclient.pages.main.conversation.LocationFragment.java

private Bitmap getMarker() {
    if (marker != null) {
        return marker;
    }/*from www  .  j a v a  2s .c o m*/
    int size = getResources().getDimensionPixelSize(R.dimen.share_location__current_location_marker__size);
    int outerCircleRadius = getResources()
            .getDimensionPixelSize(R.dimen.share_location__current_location_marker__outer_ring_radius);
    int midCircleRadius = getResources()
            .getDimensionPixelSize(R.dimen.share_location__current_location_marker__mid_ring_radius);
    int innerCircleRadius = getResources()
            .getDimensionPixelSize(R.dimen.share_location__current_location_marker__inner_ring_radius);

    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setColor(getControllerFactory().getAccentColorController().getColor());
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setAlpha(
            getResources().getInteger(R.integer.share_location__current_location_marker__outer_ring_alpha));
    canvas.drawCircle(size / 2, size / 2, outerCircleRadius, paint);
    paint.setAlpha(
            getResources().getInteger(R.integer.share_location__current_location_marker__mid_ring_alpha));
    canvas.drawCircle(size / 2, size / 2, midCircleRadius, paint);
    paint.setAlpha(
            getResources().getInteger(R.integer.share_location__current_location_marker__inner_ring_alpha));
    canvas.drawCircle(size / 2, size / 2, innerCircleRadius, paint);
    marker = bitmap;
    return marker;
}

From source file:fr.magistry.taigime.CandidateView.java

/**
 * If the canvas is null, then only touch calculations are performed to pick the target
 * candidate./*from   w ww.  j a  va  2 s.com*/
 */
@Override
protected void onDraw(Canvas canvas) {
    if (canvas != null) {
        super.onDraw(canvas);
    }
    mTotalWidth = 0;
    if (mSuggestions == null)
        return;

    if (mBgPadding == null) {
        mBgPadding = new Rect(0, 0, 0, 0);
        if (getBackground() != null) {
            getBackground().getPadding(mBgPadding);
        }
    }
    int x = 0;
    final int count = mSuggestions.size();
    final int height = getHeight();
    final Rect bgPadding = mBgPadding;
    final Paint paint = mPaint;
    final int touchX = mTouchX;
    final int scrollX = getScrollX();
    final boolean scrolled = mScrolled;
    final int y; //= (int) ( - mPaint.ascent() + mVerticalPadding);
    final int y2; //= (int) (height - mPaintTRS.descent()); // (y - mVerticalPadding - mPaint.descent() - mPaintTRS.ascent()) ;
    final float initialTRSsize = mPaintTRS.getTextSize();
    if (mOutputTRS) {
        y2 = (int) (-mPaintTRS.ascent() + mVerticalPadding);
        y = (int) (height - mPaint.descent());

    } else {
        y = (int) (-mPaint.ascent() + mVerticalPadding);
        y2 = (int) (height - mPaintTRS.descent());

    }
    for (int i = 0; i < count; i++) {
        Candidate suggestion = mSuggestions.get(i);
        String hanji = suggestion.getWord().getHanji();
        String trs = "";
        switch (ROMANISATION_OUTPUT_MODE) {
        case 0:
            trs = suggestion.getWord().getTailuo();
            break;
        case 1:
            trs = suggestion.getWord().getPOJ();
            break;
        case 2:
            trs = suggestion.getWord().getPOJ_safe();
            break;
        default:
            trs = suggestion.getWord().getTailuo();
        }
        float textWidth;
        if (i == 0) {
            hanji = "";
            trs = "";//hanji;//TODO: conversion?
            //if(mOutputTRS){
            trs = suggestion.getWord().getBopomo();
            if (trs != "")
                textWidth = mPaintBPM.measureText(trs);
            else
                textWidth = 3;
            //}
            //else {
            //   hanji = suggestion.getWord().getBopomo();
            //   textWidth = paint.measureText(hanji);
            //}
        } else
            textWidth = paint.measureText(hanji);
        if (textWidth == 0.0)
            textWidth = paint.measureText(" ");

        final int wordWidth = (int) textWidth + X_GAP * 2;
        mWordX[i] = x;
        mWordWidth[i] = wordWidth;
        mPaintTRS.setTextSize(initialTRSsize);
        mPaintTRS.setTextSize(reduceTextSizeFromWidth(mPaintTRS, trs, textWidth));
        paint.setColor(mColorNormal);
        if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) {
            if (canvas != null) {
                canvas.translate(x, 0);
                mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height);
                mSelectionHighlight.draw(canvas);
                canvas.translate(-x, 0);
            }
            mSelectedIndex = i;
        }

        if (canvas != null) {
            Paint activePaint = null;
            Paint secondPaint = null;
            if (mOutputTRS) {
                activePaint = mPaintTRS;
                secondPaint = paint;
            } else {
                activePaint = paint;
                secondPaint = mPaintTRS;
            }
            if (i == 0) {
                activePaint = mPaintBPM;
            }
            secondPaint.setAlpha(150);
            if ((i == mCursor)) {
                activePaint.setFakeBoldText(true);
                activePaint.setColor(mColorRecommended);
            } else if (i != 0) {
                activePaint.setColor(mColorOther);
            }
            if (i == 0) {
                canvas.drawText(trs, x + X_GAP, y2, mPaintBPM);
            } else {
                canvas.drawText(hanji, x + X_GAP, y, paint);
                canvas.drawText(trs, x + X_GAP, y2, mPaintTRS);
            }
            activePaint.setColor(mColorOther);
            canvas.drawLine(x + wordWidth + 0.5f, bgPadding.top, x + wordWidth + 0.5f, height + 1, paint);
            activePaint.setFakeBoldText(false);
            secondPaint.setAlpha(255);
        }
        x += wordWidth;
        mPaintTRS.setTextSize(initialTRSsize);
    }
    mTotalWidth = x;
    if (mTargetScrollX != getScrollX()) {
        scrollToTarget();
    }
}

From source file:fr.mathieu.berengere.safdemo.CameraActivity.java

public Bitmap makeTransparent(Bitmap src, int value) {
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap transBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(transBitmap);
    canvas.drawARGB(0, 0, 0, 0);/*  w  w w.  j  a va2s.com*/
    // config paint
    final Paint paint = new Paint();
    paint.setAlpha(value);
    canvas.drawBitmap(src, 0, 0, paint);
    return transBitmap;
}

From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java

private Bitmap RenderBarGraph(int CritCount, int ErrCount, int WarnCount) {

    //Log.i("Counts", Integer.toString(CritCount) + " / " + Integer.toString(ErrCount) + " / " + Integer.toString(WarnCount));
    Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888);

    int width = emptyBmap.getWidth();
    int height = emptyBmap.getHeight();
    Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(charty);
    //final int color = 0xff0B0B61; 
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);/* w w w .j ava 2s.  c o  m*/

    //y
    canvas.drawLine(25, 0, 25, 289, paint);
    //x
    canvas.drawLine(25, 149, 289, 149, paint);

    paint.setAntiAlias(true);
    int Max = 0;

    if (CritCount > ErrCount && CritCount > WarnCount)
        Max = CritCount;
    else if (ErrCount > CritCount && ErrCount > WarnCount)
        Max = ErrCount;
    else if (WarnCount > CritCount && WarnCount > ErrCount)
        Max = WarnCount;
    else
        Max = CritCount;

    if (Max > 0)
        canvas.drawText(Integer.toString(Max), 0, 10, paint);

    if (Max > 1)
        canvas.drawText(Integer.toString(Max / 2), 0, 75, paint);

    canvas.drawText("0", 0, 148, paint);

    double divisor = 148 / (double) Max;

    paint.setAlpha(128);

    Rect rect = new Rect(32, (int) (148 - (divisor * CritCount)), 64, 148);
    paint.setColor(Color.argb(200, 208, 0, 0)); //red

    if (CritCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    rect = new Rect(128, (int) (148 - (divisor * ErrCount)), 160, 148);
    paint.setColor(Color.argb(200, 255, 102, 0));//orange

    if (ErrCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    rect = new Rect(224, (int) (148 - (divisor * WarnCount)), 256, 148);
    paint.setColor(Color.argb(200, 255, 224, 57)); //yellow
    if (WarnCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    //Return
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    charty.compress(CompressFormat.PNG, 50, out);

    return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size());
}

From source file:com.nextgis.maplibui.overlay.EditLayerOverlay.java

protected Bitmap getMarker() {
    float scaledDensity = mContext.getResources().getDisplayMetrics().scaledDensity;
    int size = (int) (12 * scaledDensity);
    Bitmap marker = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(marker);
    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
    //noinspection deprecation
    p.setColor(mContext.getResources().getColor(R.color.accent));
    p.setAlpha(128);
    c.drawOval(new RectF(0, 0, size * 3 / 4, size * 3 / 4), p);
    return marker;
}

From source file:net.droidsolutions.droidcharts.core.renderer.AbstractCategoryItemRenderer.java

/**
 * Draws a marker for the domain axis.//www.  jav  a2s  .  com
 * 
 * @param g2
 *            the graphics device (not <code>null</code>).
 * @param plot
 *            the plot (not <code>null</code>).
 * @param axis
 *            the range axis (not <code>null</code>).
 * @param marker
 *            the marker to be drawn (not <code>null</code>).
 * @param dataArea
 *            the area inside the axes (not <code>null</code>).
 * 
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *      Rectangle2D)
 */
public void drawDomainMarker(Canvas g2, CategoryPlot plot, CategoryAxis axis, CategoryMarker marker,
        Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    Paint paint = marker.getPaint();
    paint.setAlpha(marker.getAlpha());

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex, dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
        } else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
        }

        paint.setStrokeWidth(marker.getStroke());
        g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(),
                paint);
        bounds = line.getBounds2D();
    } else {
        double v0 = axis.getCategoryStart(columnIndex, dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex, dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0, dataArea.getWidth(), (v1 - v0));
        } else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(), (v1 - v0), dataArea.getHeight());
        }
        Paint p = marker.getPaint();
        p.setStyle(Paint.Style.FILL);
        g2.drawRect((float) area.getMinX(), (float) area.getMinY(), (float) area.getMaxX(),
                (float) area.getMaxY(), p);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        // g2.setFont(labelFont);
        // g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, bounds,
                marker.getLabelOffset(), marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor(), marker.getLabelPaint());
    }
    // g2.setComposite(savedComposite);
}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java

private void setButtonImages(View view, BrowserButton buttonProps, int disabledAlpha) {
    Drawable normalDrawable = null;//from  ww w . j a v a2 s . com
    Drawable disabledDrawable = null;
    Drawable pressedDrawable = null;

    CharSequence description = view.getContentDescription();

    if (buttonProps.image != null || buttonProps.wwwImage != null) {
        try {
            normalDrawable = getImage(buttonProps.image, buttonProps.wwwImage, buttonProps.wwwImageDensity);
            ViewGroup.LayoutParams params = view.getLayoutParams();
            params.width = normalDrawable.getIntrinsicWidth();
            params.height = normalDrawable.getIntrinsicHeight();
        } catch (Resources.NotFoundException e) {
            emitError(ERR_LOADFAIL,
                    String.format("Image for %s, %s, failed to load", description, buttonProps.image));
        } catch (IOException ioe) {
            emitError(ERR_LOADFAIL,
                    String.format("Image for %s, %s, failed to load", description, buttonProps.wwwImage));
        }
    } else {
        emitWarning(WRN_UNDEFINED,
                String.format("Image for %s is not defined. Button will not be shown", description));
    }

    if (buttonProps.imagePressed != null || buttonProps.wwwImagePressed != null) {
        try {
            pressedDrawable = getImage(buttonProps.imagePressed, buttonProps.wwwImagePressed,
                    buttonProps.wwwImageDensity);
        } catch (Resources.NotFoundException e) {
            emitError(ERR_LOADFAIL, String.format("Pressed image for %s, %s, failed to load", description,
                    buttonProps.imagePressed));
        } catch (IOException e) {
            emitError(ERR_LOADFAIL, String.format("Pressed image for %s, %s, failed to load", description,
                    buttonProps.wwwImagePressed));
        }
    } else {
        emitWarning(WRN_UNDEFINED, String.format("Pressed image for %s is not defined.", description));
    }

    if (normalDrawable != null) {
        // Create the disabled state drawable by fading the normal state
        // drawable. Drawable.setAlpha() stopped working above Android 4.4
        // so we gotta bring out some bitmap magic. Credit goes to:
        // http://stackoverflow.com/a/7477572
        Bitmap enabledBitmap = ((BitmapDrawable) normalDrawable).getBitmap();
        Bitmap disabledBitmap = Bitmap.createBitmap(normalDrawable.getIntrinsicWidth(),
                normalDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(disabledBitmap);

        Paint paint = new Paint();
        paint.setAlpha(disabledAlpha);
        canvas.drawBitmap(enabledBitmap, 0, 0, paint);

        Resources activityRes = cordova.getActivity().getResources();
        disabledDrawable = new BitmapDrawable(activityRes, disabledBitmap);
    }

    StateListDrawable states = new StateListDrawable();
    if (pressedDrawable != null) {
        states.addState(new int[] { android.R.attr.state_pressed }, pressedDrawable);
    }
    if (normalDrawable != null) {
        states.addState(new int[] { android.R.attr.state_enabled }, normalDrawable);
    }
    if (disabledDrawable != null) {
        states.addState(new int[] {}, disabledDrawable);
    }

    setBackground(view, states);
}

From source file:net.droidsolutions.droidcharts.core.renderer.AbstractCategoryItemRenderer.java

/**
 * Draws a marker for the range axis./*from w  w  w.  j a v  a2  s .  c  o m*/
 * 
 * @param g2
 *            the graphics device (not <code>null</code>).
 * @param plot
 *            the plot (not <code>null</code>).
 * @param axis
 *            the range axis (not <code>null</code>).
 * @param marker
 *            the marker to be drawn (not <code>null</code>).
 * @param dataArea
 *            the area inside the axes (not <code>null</code>).
 * 
 * @see #drawDomainMarker(Graphics2D, CategoryPlot, CategoryAxis,
 *      CategoryMarker, Rectangle2D)
 */
public void drawRangeMarker(Canvas g2, CategoryPlot plot, ValueAxis axis, Marker marker, Rectangle2D dataArea) {

    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = axis.getRange();

        if (!range.contains(value)) {
            return;
        }

        PlotOrientation orientation = plot.getOrientation();
        double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
        } else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
        }

        Paint p = marker.getPaint();
        p.setAlpha(vm.getAlpha());
        p.setStrokeWidth(marker.getStroke());
        g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), p);

        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            // g2.setFont(labelFont);

            Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea,
                    line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), marker.getLabelPaint());
        }
        // g2.setComposite(savedComposite);
        p.setAlpha(255);
    } else if (marker instanceof IntervalMarker) {
        IntervalMarker im = (IntervalMarker) marker;
        double start = im.getStartValue();
        double end = im.getEndValue();
        Range range = axis.getRange();
        if (!(range.intersects(start, end))) {
            return;
        }

        double start2d = axis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge());
        double end2d = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());
        double low = Math.min(start2d, end2d);
        double high = Math.max(start2d, end2d);

        PlotOrientation orientation = plot.getOrientation();
        Rectangle2D rect = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            // clip left and right bounds to data area
            low = Math.max(low, dataArea.getMinX());
            high = Math.min(high, dataArea.getMaxX());
            rect = new Rectangle2D.Double(low, dataArea.getMinY(), high - low, dataArea.getHeight());
        } else if (orientation == PlotOrientation.VERTICAL) {
            // clip top and bottom bounds to data area
            low = Math.max(low, dataArea.getMinY());
            high = Math.min(high, dataArea.getMaxY());
            rect = new Rectangle2D.Double(dataArea.getMinX(), low, dataArea.getWidth(), high - low);
        }
        Paint p = marker.getPaint();
        p.setAlpha((int) marker.getAlpha() * 100);// TODO ALPHA
        p.setStyle(Paint.Style.FILL);

        g2.drawRect((float) rect.getMinX(), (float) rect.getMinY(), (float) rect.getMaxX(),
                (float) rect.getMinY(), p);

        // now draw the outlines, if visible...
        if (im.getOutlinePaint() != null && im.getOutlineStroke() != 0.0f) {
            if (orientation == PlotOrientation.VERTICAL) {
                Line2D line = new Line2D.Double();
                double x0 = dataArea.getMinX();
                double x1 = dataArea.getMaxX();
                Paint paint = im.getOutlinePaint();
                paint.setStrokeWidth(im.getOutlineStroke());

                if (range.contains(start)) {
                    line.setLine(x0, start2d, x1, start2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), paint);
                }
                if (range.contains(end)) {
                    line.setLine(x0, end2d, x1, end2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), paint);
                }
            } else { // PlotOrientation.HORIZONTAL
                Line2D line = new Line2D.Double();
                double y0 = dataArea.getMinY();
                double y1 = dataArea.getMaxY();
                Paint paint = im.getOutlinePaint();
                paint.setStrokeWidth(im.getOutlineStroke());
                if (range.contains(start)) {
                    line.setLine(start2d, y0, start2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), paint);
                }
                if (range.contains(end)) {
                    line.setLine(end2d, y0, end2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), paint);
                }
            }
        }

        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            // g2.setFont(labelFont);
            Paint pp = marker.getLabelPaint();
            // g2.setPaint(marker.getLabelPaint());
            Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, rect,
                    marker.getLabelOffset(), marker.getLabelOffsetType(), anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), pp);
        }
        p.setAlpha(255);
    }
}

From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java

/**
 * Draws a vertical line on the chart to represent a 'range marker'.
 *
 * @param g2  the graphics device.//from ww w  .ja v  a2 s  .co m
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param marker  the marker line.
 * @param dataArea  the axis data area.
 */
public void drawDomainMarker(Canvas g2, XYPlot plot, ValueAxis domainAxis, Marker marker,
        Rectangle2D dataArea) {

    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = domainAxis.getRange();
        if (!range.contains(value)) {
            return;
        }

        double v = domainAxis.valueToJava2D(value, dataArea, plot.getDomainAxisEdge());

        PlotOrientation orientation = plot.getOrientation();
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
        } else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
        }

        Paint paint = marker.getPaint();
        int oldAlpha = paint.getAlpha();
        paint.setAlpha(marker.getAlpha());
        Float stroke = marker.getStroke();

        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(stroke);

        g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(),
                paint);

        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();

            Paint lPaint = marker.getLabelPaint();
            lPaint.setTypeface(labelFont.getTypeFace());
            lPaint.setTextSize(labelFont.getSize());
            int lOldAlpha = lPaint.getAlpha();
            lPaint.setAlpha(marker.getAlpha());
            Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea,
                    line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), lPaint);
            lPaint.setAlpha(lOldAlpha);
        }
        paint.setAlpha(oldAlpha);
    } else if (marker instanceof IntervalMarker) {
        IntervalMarker im = (IntervalMarker) marker;
        double start = im.getStartValue();
        double end = im.getEndValue();
        Range range = domainAxis.getRange();
        if (!(range.intersects(start, end))) {
            return;
        }

        double start2d = domainAxis.valueToJava2D(start, dataArea, plot.getDomainAxisEdge());
        double end2d = domainAxis.valueToJava2D(end, dataArea, plot.getDomainAxisEdge());
        double low = Math.min(start2d, end2d);
        double high = Math.max(start2d, end2d);

        PlotOrientation orientation = plot.getOrientation();
        Rectangle2D rect = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            // clip top and bottom bounds to data area
            low = Math.max(low, dataArea.getMinY());
            high = Math.min(high, dataArea.getMaxY());
            rect = new Rectangle2D.Double(dataArea.getMinX(), low, dataArea.getWidth(), high - low);
        } else if (orientation == PlotOrientation.VERTICAL) {
            // clip left and right bounds to data area
            low = Math.max(low, dataArea.getMinX());
            high = Math.min(high, dataArea.getMaxX());
            rect = new Rectangle2D.Double(low, dataArea.getMinY(), high - low, dataArea.getHeight());
        }

        Paint p = marker.getPaint();
        int oldAlpha = p.getAlpha();
        p.setAlpha(marker.getAlpha());
        p.setStyle(Paint.Style.FILL);

        g2.drawRect((float) rect.getMinX(), (float) rect.getMinY(), (float) rect.getMaxX(),
                (float) rect.getMaxY(), p);
        p.setAlpha(oldAlpha);
        // now draw the outlines, if visible...
        if (im.getOutlinePaint() != null && im.getOutlineStroke() != null) {
            if (orientation == PlotOrientation.VERTICAL) {
                Line2D line = new Line2D.Double();
                double y0 = dataArea.getMinY();
                double y1 = dataArea.getMaxY();
                Paint oPiant = im.getOutlinePaint();
                oPiant.setStyle(Paint.Style.STROKE);
                int oOldAlpha = oPiant.getAlpha();
                oPiant.setAlpha(marker.getAlpha());
                oPiant.setStrokeWidth(im.getOutlineStroke());

                if (range.contains(start)) {
                    line.setLine(start2d, y0, start2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                if (range.contains(end)) {
                    line.setLine(end2d, y0, end2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                oPiant.setAlpha(oOldAlpha);
            } else { // PlotOrientation.HORIZONTAL
                Line2D line = new Line2D.Double();
                double x0 = dataArea.getMinX();
                double x1 = dataArea.getMaxX();
                Paint oPiant = im.getOutlinePaint();
                oPiant.setStyle(Paint.Style.STROKE);
                int oOldAlpha = oPiant.getAlpha();
                oPiant.setAlpha(marker.getAlpha());
                oPiant.setStrokeWidth(im.getOutlineStroke());
                if (range.contains(start)) {
                    line.setLine(x0, start2d, x1, start2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                if (range.contains(end)) {
                    line.setLine(x0, end2d, x1, end2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                oPiant.setAlpha(oOldAlpha);
            }
        }

        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            Paint paint = marker.getLabelPaint();
            paint.setTypeface(labelFont.getTypeFace());
            paint.setTextSize(labelFont.getSize());
            Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, rect,
                    marker.getLabelOffset(), marker.getLabelOffsetType(), anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), paint);
        }

    }

}