Package org.codemap.layers

Source Code of org.codemap.layers.SelectionOverlay

package org.codemap.layers;

import org.codemap.Location;
import org.codemap.MapInstance;
import org.codemap.MapSelection;
import org.codemap.resources.MapValues;
import org.eclipse.swt.graphics.GC;


public abstract class SelectionOverlay extends Layer {

    private boolean enabled = true;

    public abstract MapSelection getSelection(MapValues map);

    @Override
    public final void paintMap(MapValues map, GC gc) {
        if (!enabled) return;
        if (map.mapInstance.getValue() == null) return;
       
        paintBefore(map, gc);
        paintChildren(map, gc);
        paintAfter(map, gc);
    }

    /**
     * Hook for stuff to be done before we start painting.
     */
    public void paintBefore(MapValues map, GC gc) {
        // does nothing
    }
   
    /**
     * Hook for stuff to be done after painting.
     */   
    public void paintAfter(MapValues map, GC gc) {
        // does nothing       
    }   

    private final void paintChildren(MapValues map, GC gc) {
        MapSelection selection = this.getSelection(map);
        MapInstance mapInstance = map.mapInstance.getValue();
        if (selection == null || mapInstance == null) return;
        for (Location each: selection.locationsOn(map)) {
            paintChild(map, gc, each);
        }
    }
   
    public void setEnabled(boolean b) {
        enabled  = b;
    }

    public abstract void paintChild(MapValues map, GC gc, Location each);

}
TOP

Related Classes of org.codemap.layers.SelectionOverlay

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.