List of usage examples for java.lang.ref SoftReference SoftReference
public SoftReference(T referent)
From source file:org.sleuthkit.autopsy.corecomponents.ThumbnailViewNode.java
@Override @NbBundle.Messages({ "# {0} - file name", "ThumbnailViewNode.progressHandle.text=Generating thumbnail for {0}" }) public Image getIcon(int type) { Image icon = null;/*from ww w .j a v a 2 s . c o m*/ if (iconCache != null) { icon = iconCache.get(); } if (icon != null) { return icon; } else { final Content content = this.getLookup().lookup(Content.class); if (content == null) { return ImageUtils.getDefaultThumbnail(); } if (swingWorker == null || swingWorker.isDone()) { swingWorker = new SwingWorker<Image, Object>() { final private ProgressHandle progressHandle = ProgressHandle .createHandle(Bundle.ThumbnailViewNode_progressHandle_text(content.getName())); @Override protected Image doInBackground() throws Exception { progressHandle.start(); return ImageUtils.getThumbnail(content, iconSize); } @Override protected void done() { super.done(); try { iconCache = new SoftReference<>(super.get()); fireIconChange(); } catch (InterruptedException | ExecutionException ex) { Logger.getLogger(ThumbnailViewNode.class.getName()).log(Level.SEVERE, "Error getting thumbnail icon for " + content.getName(), ex); //NON-NLS } finally { progressHandle.finish(); if (timer != null) { timer.stop(); timer = null; } swingWorker = null; } } }; swingWorker.execute(); } if (timer == null) { timer = new Timer(100, (ActionEvent e) -> { fireIconChange(); }); timer.start(); } return waitingIcon; } }
From source file:com.sqkj.engine.image.ImageCache.java
private void init(ImageCacheParams cacheParams) { mCacheParams = cacheParams;//from w ww. j av a 2s. c om if (mCacheParams.memoryCacheEnabled) { WaterDropsLog.v("Memory cache created (size = " + mCacheParams.memCacheSize + ")"); if (SdkUtils.hasHoneycomb()) { mReusableBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>()); } mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) { @Override protected void entryRemoved(boolean evicted, String key, BitmapDrawable oldValue, BitmapDrawable newValue) { if (RecyclingBitmapDrawable.class.isInstance(oldValue)) { ((RecyclingBitmapDrawable) oldValue).setIsCached(false); } else { if (SdkUtils.hasHoneycomb()) { mReusableBitmaps.add(new SoftReference<Bitmap>(oldValue.getBitmap())); } } } @Override protected int sizeOf(String key, BitmapDrawable value) { final int bitmapSize = getBitmapSize(value) / 1024; WaterDropsLog.d("@@@@@@Bitmap Size==>" + bitmapSize); return bitmapSize == 0 ? 1 : bitmapSize; } }; } }
From source file:ProxyFactory.java
private synchronized Constructor getConstructor() { Constructor ctor = ctorRef == null ? null : (Constructor) ctorRef.get(); if (ctor == null) { try {/*from ww w . j a va2 s . co m*/ ctor = Proxy.getProxyClass(getClass().getClassLoader(), interfaces) .getConstructor(new Class[] { InvocationHandler.class }); } catch (NoSuchMethodException e) { throw new InternalError(e.toString()); } ctorRef = new SoftReference(ctor); } return ctor; }
From source file:com.pironet.tda.LogFileContent.java
/** * read the content in the soft reference object, currently used * StringBuffer to maintain 1.4 compability. Should be switched * to StringReader if switched to 1.5 for better performance as * synchronization is not needed here./* w w w . ja va 2s .c om*/ */ private void readContent() { final StringBuffer contentReader = new StringBuffer(); BufferedReader br = null; try { br = new BufferedReader(new FileReader(getLogfile())); while (br.ready()) { contentReader.append(br.readLine()); contentReader.append('\n'); } } catch (IOException ex) { ex.printStackTrace(); contentReader.append("The Logfile unavailable! ").append(ex.getMessage()); } finally { IOUtils.closeQuietly(br); } content = new SoftReference<>(contentReader); }
From source file:be.fedict.trust.crl.CachedCrlRepository.java
private X509CRL refreshCrl(URI crlUri, X509Certificate issuerCertificate, Date validationDate) { X509CRL crl = this.crlRepository.findCrl(crlUri, issuerCertificate, validationDate); this.crlCache.put(crlUri, new SoftReference<X509CRL>(crl)); return crl;// ww w . j ava 2 s . c o m }
From source file:edu.usc.goffish.gofs.formats.gml.KeyValuePair.java
@Override public final String ValueAsString() { if (_cachedString != null) { String s = _cachedString.get(); if (s != null) { return s; }/*from ww w . j ava2 s .c o m*/ } boolean foundAmpersand = false; for (int i = 0; i < _value.length; i++) { if (_value[i] == '&') { foundAmpersand = true; break; } } String value = new String(_value); if (foundAmpersand) { value = StringEscapeUtils.unescapeHtml(value); } _cachedString = new SoftReference<String>(value); return value; }
From source file:org.appcelerator.titanium.view.TiDrawableReference.java
public TiDrawableReference(Activity activity, DrawableReferenceType type) { this.type = type; softActivity = new SoftReference<Activity>(activity); ApplicationInfo appInfo;/*from w w w. j av a2 s . c om*/ if (activity != null) { appInfo = activity.getApplicationInfo(); } else { appInfo = TiApplication.getInstance().getApplicationInfo(); } anyDensityFalse = (appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) == 0; }
From source file:org.codehaus.groovy.grails.commons.metaclass.WeakGenericDynamicProperty.java
public Object get(Object object) { String propertyKey = System.identityHashCode(object) + getPropertyName(); SoftReference<Object> ref = propertyToInstanceMap.get(propertyKey); Object val = (ref != null) ? ref.get() : null; if (val != null) { return val; } else if (this.initialValueGenerator != null) { final Object value = this.initialValueGenerator.execute(object); propertyToInstanceMap.put(propertyKey, new SoftReference<Object>(value)); return value; } else if (this.initialValue != null) { propertyToInstanceMap.put(propertyKey, new SoftReference<Object>(this.initialValue)); return this.initialValue; }/*from w w w . j ava 2s . co m*/ return null; }
From source file:pl.otros.logview.gui.LogViewPanelWrapper.java
public LogViewPanelWrapper(String name, Stoppable stoppable, TableColumns[] visibleColumns, LogDataTableModel logDataTableModel, DataConfiguration configuration, OtrosApplication otrosApplication) { this.name = name; this.configuration = configuration; this.otrosApplication = otrosApplication; this.addHierarchyListener(new HierarchyListener() { @Override/*w ww. j av a2 s . co m*/ public void hierarchyChanged(HierarchyEvent e) { if (e.getChangeFlags() == 1 && e.getChanged().getParent() == null) { LOGGER.info("Log view panel is removed from view. Clearing data table for GC"); dataTableModel.clear(); } } }); if (visibleColumns == null) { visibleColumns = TableColumns.ALL_WITHOUT_LOG_SOURCE; } fillDefaultConfiguration(); stopableReference = new SoftReference<Stoppable>(stoppable); // this.statusObserver = statusObserver; dataTableModel = logDataTableModel == null ? new LogDataTableModel() : logDataTableModel; logViewPanel = new LogViewPanel(dataTableModel, visibleColumns, otrosApplication); cardLayout = new CardLayout(); JPanel panelLoading = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(10, 10, 10, 10); c.anchor = GridBagConstraints.PAGE_START; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; c.ipadx = 1; c.ipady = 1; c.weightx = 10; c.weighty = 1; JLabel label = new JLabel("Loading file " + name); panelLoading.add(label, c); c.gridy++; c.weighty = 3; loadingProgressBar = new JProgressBar(); loadingProgressBar.setIndeterminate(false); loadingProgressBar.setStringPainted(true); loadingProgressBar.setString("Connecting..."); panelLoading.add(loadingProgressBar, c); statsTable = new JTable(); c.gridy++; c.weighty = 1; c.weightx = 2; panelLoading.add(statsTable, c); c.gridy++; c.weightx = 1; stopButton = new JButton("Stop, you have imported already enough!"); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Stoppable stoppable = stopableReference.get(); if (stoppable != null) { stoppable.stop(); } } }); panelLoading.add(stopButton, c); setLayout(cardLayout); add(panelLoading, CARD_LAYOUT_LOADING); add(logViewPanel, CARD_LAYOUT_CONTENT); cardLayout.show(this, CARD_LAYOUT_LOADING); }
From source file:net.sf.maltcms.chromaui.charts.tooltips.RTIXYTooltipGenerator.java
/** * * @param xyd//from www.j a v a2 s . c o m * @param i * @param i1 * @return */ @Override public String generateToolTip(XYDataset xyd, int i, int i1) { Point p = new Point(i, i1); if (hm.containsKey(p)) { SoftReference<String> sr = hm.get(p); if (sr.get() != null) { return sr.get(); } } else { StringBuilder sb = new StringBuilder(); int x = (int) xyd.getXValue(i, i1); int y = (int) xyd.getYValue(i, i1); double z = Double.NaN; if (xyd instanceof XYZDataset) { z = ((XYZDataset) xyd).getZValue(i, i1); } if (x >= 0 && x < lookup.length && y >= 0 && y < scansPerModulation) { sb.append("[ SCAN1: "); sb.append(x); sb.append(", SCAN2: " + y + " ]"); sb.append(" at [ RT1: "); sb.append(lookup[x]); sb.append(" s, RT2: "); float off = (this.modulationTime * ((float) y / (float) (this.scansPerModulation))); sb.append(lookup[x] + off); sb.append("s ]"); if (xyd instanceof XYZDataset) { sb.append(" = "); sb.append(z); } String s = sb.toString(); SoftReference<String> sr = new SoftReference<>(s); hm.put(p, sr); return s; } return ""; } return null; }