/** * <p>Returns true if the painter should use caching. This method allows subclasses to * specify the heuristics regarding whether to cache or not. If a <code>Painter</code> * has intelligent rules regarding painting times, and can more accurately indicate * whether it should be cached, it could implement that logic in this method.</p> * * @return whether or not a cache should be used */ protected boolean shouldUseCache() { return isCacheable() || filters.length > 0; //NOTE, I can only do this because getFilters() is final }
/** * <p>Returns true if the painter should use caching. This method allows subclasses to * specify the heuristics regarding whether to cache or not. If a <code>Painter</code> * has intelligent rules regarding painting times, and can more accurately indicate * whether it should be cached, it could implement that logic in this method.</p> * * @return whether or not a cache should be used */ protected boolean shouldUseCache() { return isCacheable() || filters.length > 0; //NOTE, I can only do this because getFilters() is final }
/** * <p>Returns true if the painter should use caching. This method allows subclasses to * specify the heuristics regarding whether to cache or not. If a <code>Painter</code> * has intelligent rules regarding painting times, and can more accurately indicate * whether it should be cached, it could implement that logic in this method.</p> * * @return whether or not a cache should be used */ protected boolean shouldUseCache() { return isCacheable() || filters.length > 0; //NOTE, I can only do this because getFilters() is final }
/** * <p>Returns true if the painter should use caching. This method allows subclasses to * specify the heuristics regarding whether to cache or not. If a <code>Painter</code> * has intelligent rules regarding painting times, and can more accurately indicate * whether it should be cached, it could implement that logic in this method.</p> * * @return whether or not a cache should be used */ protected boolean shouldUseCache() { return isCacheable() || filters.length > 0; //NOTE, I can only do this because getFilters() is final }
/** * <p>Returns true if the painter should use caching. This method allows subclasses to * specify the heuristics regarding whether to cache or not. If a <code>Painter</code> * has intelligent rules regarding painting times, and can more accurately indicate * whether it should be cached, it could implement that logic in this method.</p> * * @return whether or not a cache should be used */ protected boolean shouldUseCache() { return isCacheable() || filters.length > 0; //NOTE, I can only do this because getFilters() is final }
/** * <p>Returns true if the painter should use caching. This method allows subclasses to * specify the heuristics regarding whether to cache or not. If a <code>Painter</code> * has intelligent rules regarding painting times, and can more accurately indicate * whether it should be cached, it could implement that logic in this method.</p> * * @return whether or not a cache should be used */ protected boolean shouldUseCache() { return isCacheable() || filters.length > 0; //NOTE, I can only do this because getFilters() is final }
/** * <p>Sets whether this <code>AbstractPainter</code> can be cached as an image. * If true, this is treated as a hint. That is, a cacheable may or may not be used. * The {@link #shouldUseCache} method actually determines whether the cacheable is used. * However, if false, then this is treated as an absolute value. That is, no * cacheable will be used.</p> * * <p>If set to false, then #clearCache is called to free system resources.</p> * * @param cacheable */ public void setCacheable(boolean cacheable) { boolean old = isCacheable(); this.cacheable = cacheable; firePropertyChange("cacheable", old, isCacheable()); if (!isCacheable()) { clearCache(); } }
/** * <p>Sets whether this <code>AbstractPainter</code> can be cached as an image. * If true, this is treated as a hint. That is, a cacheable may or may not be used. * The {@link #shouldUseCache} method actually determines whether the cacheable is used. * However, if false, then this is treated as an absolute value. That is, no * cacheable will be used.</p> * * <p>If set to false, then #clearCache is called to free system resources.</p> * * @param cacheable */ public void setCacheable(boolean cacheable) { boolean old = isCacheable(); this.cacheable = cacheable; firePropertyChange("cacheable", old, isCacheable()); if (!isCacheable()) { clearCache(); } }
/** * <p>Sets whether this <code>AbstractPainter</code> can be cached as an image. * If true, this is treated as a hint. That is, a cacheable may or may not be used. * The {@link #shouldUseCache} method actually determines whether the cacheable is used. * However, if false, then this is treated as an absolute value. That is, no * cacheable will be used.</p> * * <p>If set to false, then #clearCache is called to free system resources.</p> * * @param cacheable */ public void setCacheable(boolean cacheable) { boolean old = isCacheable(); this.cacheable = cacheable; firePropertyChange("cacheable", old, isCacheable()); if (!isCacheable()) { clearCache(); } }
/** * <p>Sets whether this <code>AbstractPainter</code> can be cached as an image. * If true, this is treated as a hint. That is, a cacheable may or may not be used. * The {@link #shouldUseCache} method actually determines whether the cacheable is used. * However, if false, then this is treated as an absolute value. That is, no * cacheable will be used.</p> * * <p>If set to false, then #clearCache is called to free system resources.</p> * * @param cacheable */ public void setCacheable(boolean cacheable) { boolean old = isCacheable(); this.cacheable = cacheable; firePropertyChange("cacheable", old, isCacheable()); if (!isCacheable()) { clearCache(); } }
/** * <p>Call this method to clear the cacheable. This may be called whether there is * a cacheable being used or not. If cleared, on the next call to <code>paint</code>, * the painting routines will be called.</p> * * <p><strong>Subclasses</strong>If overridden in subclasses, you * <strong>must</strong> call super.clearCache, or physical * resources (such as an Image) may leak.</p> */ public void clearCache() { BufferedImage cache = cachedImage == null ? null : cachedImage.get(); if (cache != null) { cache.flush(); } cacheCleared = true; if (!isCacheable()) { cachedImage = null; } }
/** * <p>Call this method to clear the cacheable. This may be called whether there is * a cacheable being used or not. If cleared, on the next call to <code>paint</code>, * the painting routines will be called.</p> * * <p><strong>Subclasses</strong>If overridden in subclasses, you * <strong>must</strong> call super.clearCache, or physical * resources (such as an Image) may leak.</p> */ public void clearCache() { BufferedImage cache = cachedImage == null ? null : cachedImage.get(); if (cache != null) { cache.flush(); } cacheCleared = true; if (!isCacheable()) { cachedImage = null; } }
/** * <p>Call this method to clear the cacheable. This may be called whether there is * a cacheable being used or not. If cleared, on the next call to <code>paint</code>, * the painting routines will be called.</p> * * <p><strong>Subclasses</strong>If overridden in subclasses, you * <strong>must</strong> call super.clearCache, or physical * resources (such as an Image) may leak.</p> */ public void clearCache() { BufferedImage cache = cachedImage == null ? null : cachedImage.get(); if (cache != null) { cache.flush(); } cacheCleared = true; if (!isCacheable()) { cachedImage = null; } }
/** * <p>Call this method to clear the cacheable. This may be called whether there is * a cacheable being used or not. If cleared, on the next call to <code>paint</code>, * the painting routines will be called.</p> * * <p><strong>Subclasses</strong>If overridden in subclasses, you * <strong>must</strong> call super.clearCache, or physical * resources (such as an Image) may leak.</p> */ public void clearCache() { BufferedImage cache = cachedImage == null ? null : cachedImage.get(); if (cache != null) { cache.flush(); } cacheCleared = true; if (!isCacheable()) { cachedImage = null; } }
/** * {@link AbstractPainter} will pass {@code null} objects to * {@link AbstractPainter#doPaint(Graphics2D, Object, int, int) doPaint}. */ @Test public void testPaintWithNullObject() { p.paint(g, null, 10, 10); if (p.isCacheable()) { verify(p).doPaint(any(Graphics2D.class), isNull(), eq(10), eq(10)); } else { verify(p).doPaint(g, null, 10, 10); } }
/** * {@link AbstractPainter} will pass any object to * {@link AbstractPainter#doPaint(Graphics2D, Object, int, int) doPaint}. */ @Test public void testPaintWithAnyObject() { p.paint(g, "yo", 10, 10); if (p.isCacheable()) { verify(p).doPaint(any(Graphics2D.class), eq("yo"), eq(10), eq(10)); } else { verify(p).doPaint(g, "yo", 10, 10); } p.clearCache(); p.paint(g, 1f, 10, 10); if (p.isCacheable()) { verify(p).doPaint(any(Graphics2D.class), eq(1f), eq(10), eq(10)); } else { verify(p).doPaint(g, 1f, 10, 10); } }
@Test public void testDefaults() { assertThat(p.getFilters().length, is(0)); assertThat(p.getInterpolation(), is(AbstractPainter.Interpolation.NearestNeighbor)); assertThat(p.isAntialiasing(), is(true)); assertThat(p.isCacheable(), is(false)); assertThat(p.isCacheCleared(), is(true)); assertThat(p.isDirty(), is(false)); assertThat(p.isInPaintContext(), is(false)); assertThat(p.isVisible(), is(true)); assertThat(p.shouldUseCache(), is(p.isCacheable())); }
/** * Issue #??-swingx: clearCache has no detectable effect. Test was poorly designed. It has had * an effect for a long time, but the member is not bound, so the test was failing erroneously. */ @Test public void testClearCacheDetectable() { p.setCacheable(true); p.paint(g, null, 10, 10); // sanity //when caching we get a different graphics object verify(p).doPaint(any(Graphics2D.class), isNull(), eq(10), eq(10)); assertThat("clean after paint", false, is(p.isDirty())); assertThat("cacheable is enabled", true, is(p.isCacheable())); assertThat("has a cached image", false, is(p.isCacheCleared())); p.clearCache(); assertThat("has a cached image", true, is(p.isCacheCleared())); }
/** * TODO remove when the compound painter does not start dirty */ private void copyOfSuper_testDefaultsWithCorrectedValues() { assertThat(p.getFilters().length, is(0)); assertThat(p.getInterpolation(), is(AbstractPainter.Interpolation.NearestNeighbor)); assertThat(p.isAntialiasing(), is(true)); assertThat(p.isCacheable(), is(false)); assertThat(p.isCacheCleared(), is(true)); //TODO why does CompoundPainter start dirty? assertThat(p.isDirty(), is(true)); assertThat(p.isInPaintContext(), is(false)); assertThat(p.isVisible(), is(true)); assertThat(p.shouldUseCache(), is(false)); }
/** * TODO remove when the compound painter does not start dirty */ private void copyOfSuper_testDefaultsWithCorrectedValues() { assertThat(p.getFilters().length, is(0)); assertThat(p.getInterpolation(), is(AbstractPainter.Interpolation.NearestNeighbor)); assertThat(p.isAntialiasing(), is(true)); assertThat(p.isCacheable(), is(false)); assertThat(p.isCacheCleared(), is(true)); //TODO this is because the constructor calls the setters assertThat(p.isDirty(), is(true)); assertThat(p.isInPaintContext(), is(false)); assertThat(p.isVisible(), is(true)); assertThat(p.shouldUseCache(), is(false)); }