alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is Forte for Java, Community Edition. The Initial
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
 * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.looks;

import org.netbeans.spi.looks.LookSelector;

import java.util.*;

/** Event fired from the LookSelector when it's content changes.
 *
 * @see org.netbeans.spi.looks.LookSelector
 * @see org.netbeans.spi.looks.SelectorListener
 * @author  Petr Hrebejk, Jaroslav Tulach
 */
public class SelectorEvent extends EventObject {
    
    private SelectorImpl impl;
    private HashMap oldCache;
    
    /** Creates a new instance of SelectorEvent 
     * @param source LookSelector whose content was changed
     */
    public SelectorEvent( LookSelector source ) {        
        super( source );
        impl = Accessor.DEFAULT.getSelectorImpl( source );
        oldCache = impl.getCache();
    }
    
    /** Determines whether the change in the content of the LookSelector 
     * affects nodes which are used for visualisation of given represented 
     * object.
     * 

* The default implementation returns true for all objects. If extending * LookSelector the implementor is responsible for keeping semantics of * looking for Looks/LookSelectors in sync with the semantics of decision * whether objects are affected or node. * @param representedObject The represented object of node which may be * affected by the change of LookSelector content. * @return True if node with given represented object is affected * false otherwise. */ public boolean affectsObject( Object representedObject ) { return true; } public Collection getAddedLooks( Object representedObject ) { if ( oldCache == null ) { // No cache, no problem return Collections.EMPTY_SET; } Object key = impl.getKey4Object( representedObject ); Set diff[] = getDiff4Key( key ); if ( diff == null ) { return Collections.EMPTY_SET; } else { return diff[0]; } } public Collection getRemovedLooks( Object representedObject ) { if ( oldCache == null ) { // No cache, no problem return Collections.EMPTY_SET; } Object key = impl.getKey4Object( representedObject ); Set diff[] = getDiff4Key( key ); if ( diff == null ) { return Collections.EMPTY_SET; } else { return diff[1]; } } // Private methods --------------------------------------------------------- /** Computes diff for given key. When the diff is computed for the first * time it will put ito the old cache instad of the original CacheItem */ private Set[] getDiff4Key( Object key ) { Object o = oldCache.get( key ); if ( key instanceof Set[] ) { // It was already computed, just return return (Set[])o; } else { // We have to compute, And put it back into the cache Set[] diff = new Set[2]; SelectorImplFactory.CacheItem oldItem = (SelectorImplFactory.CacheItem)oldCache.get( key ); Collection oldLooks = oldItem.getCachedLooks( false ); Collection newLooks = Collections.list( impl.getLooks4Key( key ) ); // Newly added looks diff[0] = new HashSet( newLooks ); diff[0].removeAll( oldLooks ); // Removed looks diff[1] = new HashSet( oldLooks ); diff[1].removeAll( newLooks ); return diff; } } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.