All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jvnet.lafwidget.utils.FadeIgnoreManager Maven / Gradle / Ivy

Go to download

Laf-Widget provides support for common "feel" widgets in look-and-feel libraries

There is a newer version: 5.0
Show newest version
package org.jvnet.lafwidget.utils;

import java.awt.Component;
import java.io.*;
import java.net.URL;
import java.util.*;

import org.jvnet.lafwidget.LafWidgetRepository;

public class FadeIgnoreManager {
	protected Set ignoreAnimationsOn;

	protected Set cache;

	public FadeIgnoreManager() {
		this.ignoreAnimationsOn = new HashSet();
		this.cache = new HashSet();
	}

	/**
	 * Populates the ignore set. The classpath is scanned for all resources that
	 * match the name META-INF/lafwidget.animations.properties.
	 * 
	 * @see #populateFrom(URL)
	 */
	public void populate() {
		try {
			Enumeration rs = LafWidgetRepository.class.getClassLoader()
					.getResources("META-INF/lafwidget.animations.properties");
			while (rs.hasMoreElements()) {
				URL rUrl = (URL) rs.nextElement();
				this.populateFrom(rUrl);
			}
		} catch (IOException ioe) {
		}
	}

	public void populateFrom(URL url) {
		InputStream is = null;
		BufferedReader br = null;
		try {
			is = url.openStream();
			br = new BufferedReader(new InputStreamReader(is));
			while (true) {
				String line = br.readLine();
				if (line == null)
					break;
				line = line.trim();
				if (line.length() == 0)
					continue;
				this.addToIgnoreAnimations(line);
			}
		} catch (IOException ioe) {
		} finally {
			if (is != null) {
				try {
					is.close();
				} catch (IOException ioe) {
				}
			}
			if (br != null) {
				try {
					br.close();
				} catch (IOException ioe) {
				}
			}
		}
	}

	public void addToIgnoreAnimations(Class clazz) {
		this.ignoreAnimationsOn.add(clazz);
	}

	public void addToIgnoreAnimations(String className) {
		try {
			this.ignoreAnimationsOn.add(Class.forName(className));
		} catch (Exception exc) {
		}
	}

	public synchronized boolean toIgnoreAnimations(Component comp) {
		Component currComp = comp;
		while (currComp != null) {
			Class currClazz = currComp.getClass();
			if (cache.contains(currClazz))
				return true;
			for (Iterator it = this.ignoreAnimationsOn.iterator(); it.hasNext();) {
				Class ignoreAnimationClazz = (Class) it.next();
				if (ignoreAnimationClazz.isAssignableFrom(currClazz)) {
					cache.add(currClazz);
					return true;
				}
			}
			currComp = currComp.getParent();
		}
		return false;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy