Code example for ArrayList

Methods: add, clear, get, size

0
        baseLayer.setClip(getClip());
        // reset mClip in case there was one. 
        mClip = null;
 
        // replace whatever current layers we have with this. 
        mLayers.clear();
        mLayers.add(baseLayer);
 
    } 
 
    public void translate(float dx, float dy) {
        if (mLayers.size() > 0) {
            for (Layer layer : mLayers) {
                layer.getGraphics().translate(dx, dy);
            } 
        } else { 
            if (mTransform == null) {
                mTransform = new AffineTransform();
            } 
            mTransform.translate(dx, dy);
        } 
    } 
 
    public void rotate(double radians) {
        if (mLayers.size() > 0) {
            for (Layer layer : mLayers) {
                layer.getGraphics().rotate(radians);
            } 
        } else { 
            if (mTransform == null) {
                mTransform = new AffineTransform();
            } 
            mTransform.rotate(radians);
        } 
    } 
 
    public void scale(float sx, float sy) {
        if (mLayers.size() > 0) {
            for (Layer layer : mLayers) {
                layer.getGraphics().scale(sx, sy);
            } 
        } else { 
            if (mTransform == null) {
                mTransform = new AffineTransform();
            } 
            mTransform.scale(sx, sy);
        } 
    } 
 
    public AffineTransform getTransform() { 
        if (mLayers.size() > 0) {
            // all graphics2D in the list have the same transform 
            return mLayers.get(0).getGraphics().getTransform();
        } else { 
            if (mTransform == null) {
                mTransform = new AffineTransform();
            } 
            return mTransform;
        } 
    } 
 
    public void setTransform(AffineTransform transform) {
        if (mLayers.size() > 0) {
            for (Layer layer : mLayers) {
                layer.getGraphics().setTransform(transform);
            } 
        } else { 
            if (mTransform == null) {
                mTransform = new AffineTransform();
            } 
            mTransform.setTransform(transform);
        } 
    } 
 
    public boolean clip(Shape shape, int regionOp) {
        // Simple case of intersect with existing layers. 
        // Because Graphics2D#setClip works a bit peculiarly, we optimize 
        // the case of clipping by intersection, as it's supported natively. 
        if (regionOp == Region.Op.INTERSECT.nativeInt && mLayers.size() > 0) {
            for (Layer layer : mLayers) {
                layer.clip(shape);
            } 
 
            Shape currentClip = getClip();
            return currentClip != null && currentClip.getBounds().isEmpty() == false;
        } 
 
        Area area = null;
 
        if (regionOp == Region.Op.REPLACE.nativeInt) {
            area = new Area(shape);
        } else { 
            area = Region_Delegate.combineShapes(getClip(), shape, regionOp);
        } 
 
        assert area != null;
 
        if (mLayers.size() > 0) {
            if (area != null) {
                for (Layer layer : mLayers) {
                    layer.setClip(area);
                } 
            } 
 
            Shape currentClip = getClip();
            return currentClip != null && currentClip.getBounds().isEmpty() == false;
        } else { 
            if (area != null) {
                mClip = area;
            } else { 
                mClip = new Area();
            } 
 
            return mClip.getBounds().isEmpty() == false;
        } 
    } 
 
    public boolean clipRect(float left, float top, float right, float bottom, int regionOp) {
        return clip(new Rectangle2D.Float(left, top, right - left, bottom - top), regionOp);
    } 
 
    /** 
     * Returns the current clip, or null if none have been setup. 
     */ 
    public Shape getClip() {
        if (mLayers.size() > 0) {
            // they all have the same clip 
            return mLayers.get(0).getGraphics().getClip();
        } else { 
            return mClip;
        } 
    }