mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Removed PMetadata class
This commit is contained in:
@@ -10341,7 +10341,7 @@ public class PApplet extends Applet
|
||||
* @param renderer The PGraphics renderer associated to the image
|
||||
* @param storage The metadata required by the renderer
|
||||
*/
|
||||
public void setCache(PGraphics renderer, PMetadata storage) {
|
||||
public void setCache(PGraphics renderer, Object storage) {
|
||||
if (recorder != null) recorder.setCache(renderer, storage);
|
||||
g.setCache(renderer, storage);
|
||||
}
|
||||
@@ -10355,7 +10355,7 @@ public class PApplet extends Applet
|
||||
* @param renderer The PGraphics renderer associated to the image
|
||||
* @return metadata stored for the specified renderer
|
||||
*/
|
||||
public PMetadata getCache(PGraphics renderer) {
|
||||
public Object getCache(PGraphics renderer) {
|
||||
return g.getCache(renderer);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ package processing.core;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
@@ -157,7 +158,7 @@ public class PFont implements PConstants {
|
||||
|
||||
|
||||
/** for subclasses that need to store metadata about the font */
|
||||
protected HashMap<PGraphics, PMetadata> cacheMap;
|
||||
protected HashMap<PGraphics, Object> cacheMap;
|
||||
|
||||
|
||||
public PFont() { } // for subclasses
|
||||
@@ -380,8 +381,20 @@ public class PFont implements PConstants {
|
||||
if (!keySet.isEmpty()) {
|
||||
Object[] keys = keySet.toArray();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
PMetadata data = getCache((PGraphics)keys[i]);
|
||||
data.delete();
|
||||
Object data = getCache((PGraphics)keys[i]);
|
||||
Method del = null;
|
||||
|
||||
try {
|
||||
Class<?> c = data.getClass();
|
||||
del = c.getMethod("delete", new Class[] {});
|
||||
} catch (Exception e) {}
|
||||
|
||||
if (del != null) {
|
||||
// The metadata have a delete method. We try running it.
|
||||
try {
|
||||
del.invoke(data, new Object[] {});
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -667,8 +680,8 @@ public class PFont implements PConstants {
|
||||
* @param renderer The PGraphics renderer associated to the font
|
||||
* @param storage The metadata required by the renderer
|
||||
*/
|
||||
public void setCache(PGraphics renderer, PMetadata storage) {
|
||||
if (cacheMap == null) cacheMap = new HashMap<PGraphics, PMetadata>();
|
||||
public void setCache(PGraphics renderer, Object storage) {
|
||||
if (cacheMap == null) cacheMap = new HashMap<PGraphics, Object>();
|
||||
cacheMap.put(renderer, storage);
|
||||
}
|
||||
|
||||
@@ -681,7 +694,7 @@ public class PFont implements PConstants {
|
||||
* @param renderer The PGraphics renderer associated to the font
|
||||
* @return metadata stored for the specified renderer
|
||||
*/
|
||||
public PMetadata getCache(PGraphics renderer) {
|
||||
public Object getCache(PGraphics renderer) {
|
||||
if (cacheMap == null) return null;
|
||||
return cacheMap.get(renderer);
|
||||
}
|
||||
|
||||
@@ -816,7 +816,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ {
|
||||
}
|
||||
|
||||
|
||||
class ImageCache extends PMetadata {
|
||||
class ImageCache {
|
||||
PImage source;
|
||||
boolean tinted;
|
||||
int tintedColor;
|
||||
|
||||
@@ -26,6 +26,7 @@ package processing.core;
|
||||
|
||||
import java.awt.image.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -104,7 +105,7 @@ public class PImage implements PConstants, Cloneable {
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
/** for renderers that need to store info about the image */
|
||||
protected HashMap<PGraphics, PMetadata> cacheMap;
|
||||
protected HashMap<PGraphics, Object> cacheMap;
|
||||
|
||||
/** for renderers that need to store parameters about the image */
|
||||
protected HashMap<PGraphics, PParameters> paramMap;
|
||||
@@ -269,9 +270,21 @@ public class PImage implements PConstants, Cloneable {
|
||||
Set<PGraphics> keySet = cacheMap.keySet();
|
||||
if (!keySet.isEmpty()) {
|
||||
Object[] keys = keySet.toArray();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
PMetadata data = getCache((PGraphics)keys[i]);
|
||||
data.delete();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
Object data = getCache((PGraphics)keys[i]);
|
||||
Method del = null;
|
||||
|
||||
try {
|
||||
Class<?> c = data.getClass();
|
||||
del = c.getMethod("delete", new Class[] {});
|
||||
} catch (Exception e) {}
|
||||
|
||||
if (del != null) {
|
||||
// The metadata have a delete method. We try running it.
|
||||
try {
|
||||
del.invoke(data, new Object[] {});
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,8 +303,8 @@ public class PImage implements PConstants, Cloneable {
|
||||
* @param renderer The PGraphics renderer associated to the image
|
||||
* @param storage The metadata required by the renderer
|
||||
*/
|
||||
public void setCache(PGraphics renderer, PMetadata storage) {
|
||||
if (cacheMap == null) cacheMap = new HashMap<PGraphics, PMetadata>();
|
||||
public void setCache(PGraphics renderer, Object storage) {
|
||||
if (cacheMap == null) cacheMap = new HashMap<PGraphics, Object>();
|
||||
cacheMap.put(renderer, storage);
|
||||
}
|
||||
|
||||
@@ -304,7 +317,7 @@ public class PImage implements PConstants, Cloneable {
|
||||
* @param renderer The PGraphics renderer associated to the image
|
||||
* @return metadata stored for the specified renderer
|
||||
*/
|
||||
public PMetadata getCache(PGraphics renderer) {
|
||||
public Object getCache(PGraphics renderer) {
|
||||
if (cacheMap == null) return null;
|
||||
return cacheMap.get(renderer);
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-08 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General
|
||||
Public License along with this library; if not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
/**
|
||||
* Abstract class to store metadata of some kind associated to a
|
||||
* specific renderer.
|
||||
*
|
||||
*/
|
||||
abstract public class PMetadata {
|
||||
|
||||
public PMetadata() {}
|
||||
|
||||
/**
|
||||
* To allow for manual resource release.
|
||||
*
|
||||
*/
|
||||
abstract public void delete();
|
||||
}
|
||||
Reference in New Issue
Block a user