Example usage for java.lang.ref WeakReference WeakReference

List of usage examples for java.lang.ref WeakReference WeakReference

Introduction

In this page you can find the example usage for java.lang.ref WeakReference WeakReference.

Prototype

public WeakReference(T referent) 

Source Link

Document

Creates a new weak reference that refers to the given object.

Usage

From source file:com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutor.java

/**
 * Register a window with the eventLoop.
 * @param newWindow the new web window//from ww w . j a v a 2s  . c  om
 */
public synchronized void addWindow(final WebWindow newWindow) {
    final JavaScriptJobManager jobManager = newWindow.getJobManager();
    if (jobManager != null && !contains(jobManager)) {
        jobManagerList_.add(new WeakReference<JavaScriptJobManager>(jobManager));
        startThreadIfNeeded();
    }
}

From source file:charva.awt.Component.java

/**
 * Set the parent container of this component.  This is intended to
 * be called by Container objects only./* w  w w  .j  av a 2 s .c o  m*/
 * Note that we use a WeakReference so that the parent can be garbage-
 * collected when there are no more strong references to it.
 */
public void setParent(Container container_) {
    _parent = new WeakReference(container_);

    // If this component's colors have not been set yet, inherit
    // the parent container's colors.
    if (getForeground() == null)
        setForeground(container_.getForeground());

    if (getBackground() == null)
        setBackground(container_.getBackground());
}

From source file:disko.HTMLDocument.java

public synchronized String load() {
    String rawText = htmlText == null ? super.load() : htmlText;
    annotations.addAll(htmlAnnotate(rawText));
    for (Ann a : annotations)
        if (a instanceof MarkupAnn && ((MarkupAnn) a).getTag().equals(HTMLElementName.TITLE))
            setTitle(rawText.substring(a.getInterval().getStart(), a.getInterval().getEnd()).trim());
    return (fullText = new WeakReference<String>(rawText)).get();
}

From source file:com.alta189.cyborg.api.util.config.ConfigurationNode.java

protected void setParent(ConfigurationNodeSource parent) {
    if (parent == this) {
        throw new IllegalArgumentException(
                "Attempted circular inheritance between child" + getPath() + " and parent.");
    }/*from www .ja va 2 s .c  o  m*/
    Set<ConfigurationNodeSource> visited = new HashSet<ConfigurationNodeSource>();
    ConfigurationNodeSource oldParent = getParent();
    while (oldParent != null) {
        if (visited.contains(oldParent)) {
            throw new IllegalArgumentException(
                    "Attempted circular inheritance between child " + getPath() + " and parent "
                            + (oldParent instanceof ConfigurationNode
                                    ? ((ConfigurationNode) oldParent).getPath()
                                    : "root")
                            + ".");
        }
        visited.add(oldParent);
        oldParent = oldParent instanceof ConfigurationNode ? ((ConfigurationNode) oldParent).getParent() : null;
    }
    this.parent = new WeakReference<ConfigurationNodeSource>(parent);
}

From source file:com.alibaba.android.layoutmanager.layoutmanager.StaggeredGridLayoutHelper.java

@Override
public void beforeLayout(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutManagerHelper helper) {
    super.beforeLayout(recycler, state, helper);

    int availableWidth;
    if (helper.getOrientation() == VERTICAL) {
        availableWidth = helper.getContentWidth() - helper.getPaddingLeft() - helper.getPaddingRight()
                - getHorizontalMargin() - getHorizontalPadding();
    } else {/*from   www. j  a  va 2 s  .  c  o m*/
        availableWidth = helper.getContentHeight() - helper.getPaddingTop() - helper.getPaddingBottom()
                - getVerticalMargin() - getVerticalPadding();
    }
    mColLength = (int) ((availableWidth - mHGap * (mNumLanes - 1)) / mNumLanes + 0.5);
    int totalGaps = availableWidth - mColLength * mNumLanes;

    if (mNumLanes <= 1) {
        mEachGap = mLastGap = 0;
    } else if (mNumLanes == 2) {
        mEachGap = totalGaps;
        mLastGap = totalGaps;
    } else {
        mEachGap = mLastGap = helper.getOrientation() == VERTICAL ? mHGap : mVGap;
    }

    if (mLayoutManager == null || mLayoutManager.get() == null || mLayoutManager.get() != helper) {
        if (helper instanceof VirtualLayoutManager) {
            mLayoutManager = new WeakReference<VirtualLayoutManager>((VirtualLayoutManager) helper);
        }
    }
}

From source file:com.ushahidi.android.presentation.view.ui.fragment.MapPostFragment.java

private void setUpClusterer() {
    if (mMap != null) {
        mClusterManager = new ClusterManager<>(getActivity(), mMap);
        final PostModelRenderer postModelRenderer = new PostModelRenderer(getActivity().getApplicationContext(),
                new WeakReference<>(mMap), new WeakReference<>(mClusterManager), new WeakReference<>(markers));
        mClusterManager.setRenderer(postModelRenderer);
        mMap.setOnCameraChangeListener(mClusterManager);
        mMap.setOnMarkerClickListener(mClusterManager);
        mMap.setOnInfoWindowClickListener(mClusterManager);
        //mMap.getUiSettings().setZoomControlsEnabled(true);
        mClusterManager.setOnClusterInfoWindowClickListener(this);
        mClusterManager.setOnClusterItemInfoWindowClickListener(this);
    }/*from  w  ww  . j av  a2 s .  c o m*/
}

From source file:com.biggun.drawbitmapmesh.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;/*from   w w w .  j a va2s  . c o m*/
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }

            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}

From source file:cn.golden.pinchzoomcanvasview.PinchZoomCanvasViewAttacher.java

public PinchZoomCanvasViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;//w  ww  .  j  a  v  a2 s .  c  o  m
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }
                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    //        mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}

From source file:com.dubsar_dictionary.Dubsar.model.Model.java

/**
 * Set the context to use for all model instances when
 * converting strings, e.g.//w  w  w.  j  a va  2  s  .  c  o m
 * @param context the context
 */
public static void setContext(Context context) {
    sContextReference = new WeakReference<Context>(context);
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;/*from  w  w  w . j a  v  a  2  s . c  o m*/
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}