⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 theme.java

📁 geotools的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package uk.ac.leeds.ccg.geotools;

import java.lang.*;
import java.awt.*;
import java.util.*;
import java.io.*;

/**
 * A theme holds all of the information needed by a viewer to display a thematic map, including a layer, shadeing and highlightng scheem.
 * A theme acts as a container for all of the aspects that make up a thematic display of a geographic feature.  It
 * also handles all of the comunication between viewers, layers and some highlights.
 * Any clicks in the viewer can be set to pass to a theme where it will be converted to an ID from the layer and then finaly set in the highlightManager.
 * Once constructed a theme can be added to multiple viewers without problems.<p>
 * There are a number of parts that make up a theme, and this is reflected by the
 * number of constructers, the following is a list of all the parts. <br>
 * Constructors that lack parts will make their own as needed.<p>
 * The main parts that make up a <b>full</b> theme are:
 * <ul>
 * <li><b>layer: </b>Contains the geographic features for this theme.
 * <li><b>shade: </b>Defines the shading scheme to use when displaying.
 * <li><b>data: </b>The GeoData that will provide data to the layer.
 * <li><b>style: </b>Defines how a feature should be painted.
 * <li><b>highlightStyle: </b>Defines how highlighting should look.
 * <li><b>selectionStyle: </b>Defines how selections should look.
 * <li><b>highlight: </b>A highlight manager, probably shared with other themes
 * <li><b>selectionMgr: </b>A selection manager, can be shared with other themes
 * <li><b>name: </b>A name for this theme.
 * </ul>
 */
public class Theme extends Object implements FilterChangedListener,SelectionPositionChangedListener,HighlightPositionChangedListener,HighlightChangedListener,LayerChangedListener, SelectionChangedListener, SelectionRegionChangedListener,ShaderChangedListener,Serializable{
private final static boolean DEBUG=false;
protected Layer layer;
protected Shader shade = new MonoShader(Color.lightGray);
protected Filter filter = null; //i.e. no filtering
protected GeoData data = new SimpleGeoData();
protected GeoData tipData = new SimpleGeoData();
protected GeoData[] complexTipData;
protected String tipformat;
protected ShadeStyle style = new ShadeStyle();
protected ShadeStyle highlightStyle = new ShadeStyle(true, true, Color.red,Color.red,false);
protected ShadeStyle selectionStyle = new ShadeStyle(true, true, Color.blue,Color.blue,false);
protected HighlightManager highlight;
protected Vector listeners;
protected SelectionManager selectionMgr;
protected String name = "Unknown";
public static final String cvsid = "$Id: Theme.java,v 1.20 2001/11/15 13:49:07 jmacgill Exp $";
    /**
     * A full constructor for a theme, requiering the provision of all parts.
     * @param l The layer containing the geographic features.
     * @param s The shader to use when colouring in the layer.
     * @param n A String describing or nameing this theme.
     * @param hm A HighlightManager, clicks in the viewer converted into highlight requests.
     * @param d The GeoData object to base link feature IDs in the layer with attribute values.
     * @param t The GeoData object to base link feature IDs in the layer with ToolTip info.
     * @param style A ShadeStyle object to pass to the layer.
     */
    public Theme(Layer l,Shader s,String n,HighlightManager hm,GeoData d,GeoData t,ShadeStyle style){
		if(DEBUG)System.out.println("---->uk.ac.leeds.ccg.geotools.Theme constructed. Will identify itself as T--->");
		layer = l;
        if(s!=null){
            shade = s;
        }
        shade.addShaderChangedListener(this);
        //shade = s;
        name = n;
        if(d!=null){
            data = d;
        }
        if(t!=null){
            tipData = t;
        }
        /*else{
            tipData = data;
        }*/
        if(style!=null){
            this.style = style;
        }
        else
        {
            if(l instanceof LineLayer){
                this.style.setLineColorFromShader(true);
                if(s==null){shade = new MonoShader(Color.black);}
            }
        }
        
        setHighlightManager(hm);
        listeners = new Vector();
        layer.addLayerChangedListener(this);  
    }
    
    /**
     * A full constructor for a theme, requiering the provision of all parts except the new tipData .
     * @param l The layer containing the geographic features.
     * @param s The shader to use when colouring in the layer.
     * @param n A String describing or nameing this theme.
     * @param hm A HighlightManager, clicks in the viewer converted into highlight requests.
     * @param d The GeoData object to base link feature IDs in the layer with attribute values.
     * @param style A ShadeStyle object to pass to the layer.
     */
    public Theme(Layer l,Shader s,String n,HighlightManager hm,GeoData d,ShadeStyle style){
        this(l,s,n,hm,d,null,null);
    }
    
    /**
     * The old full constructor for a theme, requiering the provision of all parts except the style object
     * @param l The layer containing the geographic features.
     * @param s The shader to use when colouring in the layer.
     * @param n A String describing or nameing this theme.
     * @param hm A HighlightManager, clicks in the viewer converted into highlight requests.
     * @param d The GeoData object to base link feature IDs in the layer with attribute values.
     */
    public Theme(Layer l,Shader s,String n,HighlightManager hm,GeoData d){
        this(l,s,n,hm,d,null);
    }
    

    /**
     * The default constructor lacks too many of the requred paramiters to be of general use.
     */
    public Theme(){
        //shade = new MonoShader(Color.lightGray);
        listeners = new Vector();
    }

    /**
     * Constructs a very simple mono shaded (lightGray) theme from the given layer.
     * It will have no name,highlightManager or data and all features will be shaded light gray
     * @param l the Layer to base this theme on.
     */
    public Theme(Layer l){
        this(l,null,"Unknown",null,null);
    }
    
    /**
     * Constructs a simple theme from a layer and a shader.
     * As this theme has no GeoData object this constructor only makes sence
     * if the layer has its own built in data or if the shader is designed to give
     * sensible shading from the feature IDs alone.
     * @param l The layer to base this theme on.
     * @param s A shader for this theme.
     */
    public Theme(Layer l,Shader s){
        this(l,s,"Unknown",null,null);
    }
    
    /**
     * Constructs a simple named theme from a layer and a shader.
     * As this theme has no GeoData object this constructor only makes sence
     * if the layer has its own built in data or if the shader is designed to give
     * sensible shading from the feature IDs alone.
     * @param l The layer to base this theme on.
     * @param s A shader for this theme.
     * @param n A String that names this shader
     */
    public Theme(Layer l,Shader s,String n){
        this(l,s,n,null,null);
    }
    
    /**
     * Constructs a named theme from a layer and a shader.
     * Linked displays can be constructed if a theme in a different viewer
     * shares the same HighlightManager.
     * @param l The layer to base this theme on.
     * @param s A shader for this theme.
     * @param n A String that names this shader
     * @param hm The HighlightManager to comunicarte highlight requests through.
     */
    public Theme(Layer l,Shader s,String n,HighlightManager hm){
        this(l,s,n,hm,null);  
    }
    
   
    /**
     * Gets the current HighlightManager that can be used to set up linked views to this theme.
     */
    public HighlightManager getHighlightManager(){
        return highlight;
    }
    
    /**
     * Gets the current SelectionManager that can be used to set up linked views to this theme.
     */
    public SelectionManager getSelectionManager(){
        return this.selectionMgr;
    }

    /**
     * Sets the current shader for this theme
     * @param shader The Shader to use.
     */
    public void setShader(Shader s){
        if(shade!=null)shade.removeShaderChangedListener(this);
        shade=s;
        if(layer instanceof PolygonLayer){
            s.setKeyStyle(Shader.BOX);
            System.out.println("Set style as box");
        }
        if(layer instanceof LineLayer){
            s.setKeyStyle(Shader.LINE);
            System.out.println("Set style as line");
        }
        if(layer instanceof PointLayer){
            s.setKeyStyle(Shader.POINT);
            System.out.println("Set style as point");
        }
        shade.addShaderChangedListener(this);
        notifyThemeChangedListeners(ThemeChangedEvent.SHADE);
        
    }
    
    /**
     * Called when the properties of the current shader have changed
     * @param shader The Shader to use.
     */
    public void shaderChanged(ShaderChangedEvent e){
        if(DEBUG)System.out.println("T--->("+name+")The shader has been modified");
        notifyThemeChangedListeners(ThemeChangedEvent.SHADE);
    }
        
    
    /**
     * Get a key for this theme from its shader
     * @return Key the key object for this themes shader
     */
     public Key getKey(){
        return shade.getKey();
     }
    
    /**
     * Sets the ShadeStyle for this theme
     * @param style The ShadeStyle for this themes layer to use.
     */
    public void setStyle(ShadeStyle style){
        this.style = style;
    }
    
    /**
     * Gets the ShadeStyle currently in use by this theme
     * @return ShadeStyle the ShadeStyle object
     */
    public ShadeStyle getShadeStyle(){
        return this.style;
    }
    
    /**
     * Sets the HighlightShadeStyle for this theme
     * @param style The ShadeStyle for this themes layer to use.
     */
    public void setHighlightStyle(ShadeStyle style){
        this.highlightStyle = style;
    }
    
    /**
     * Gets the HighlightShadeStyle currently in use by this theme
     * @return ShadeStyle the HighlightShadeStyle object
     */
    public ShadeStyle getHighlightShadeStyle(){
        return this.highlightStyle;
    }    
    
        
    /**
     * Sets the SelectionShadeStyle for this theme
     * @param style The ShadeStyle for this themes layer to use.
     */
    public void setSelectionStyle(ShadeStyle style){
        this.selectionStyle = style;
    }

    /**
     * Gets the HighlightShadeStyle currently in use by this theme
     * @return ShadeStyle the HighlightShadeStyle object
     */
    public ShadeStyle getSelectionShadeStyle(){
        return this.selectionStyle;
    }        
    
    /**
     * Sets the highlightManager for this theme.  The theme will then take care of 
     * highlight comunication with its layer.
     * @param h A HighlightManager.
     */
    public void setHighlightManager(HighlightManager h){
        if(highlight!=null){
            highlight.removeHighlightChangedListener(this);
        }
        highlight = h;
        if(highlight !=null){
            highlight.addHighlightChangedListener(this);
        }
    }
    
    /**
     * Sets the selectionManager for this theme.  The theme will then take care of 
     * selection comunication with its layer.
     * @param s A SelectionManager.
     */
    public void setSelectionManager(SelectionManager s){
        if(selectionMgr!=null){
            selectionMgr.removeSelectionChangedListener(this);
        }
        selectionMgr = s;
        if(selectionMgr !=null){
            selectionMgr.addSelectionChangedListener(this);
        }
    }
    
    
    /**
     * Sets the GeoData for this theme, any viwers containing this theme will be 
     * notifed in order to repaint and display the new information.
     * @param d A GeoData containing the new data for this theme.
     */
    public void setGeoData(GeoData d){
        if(data!=d){
            data=d;
            notifyThemeChangedListeners(ThemeChangedEvent.GEOGRAPHY);
        }
        //???change this to .DATA
    }
    
    /**
     * Viewers have the ability to display short popup messages
     * in the form of tool tips when the users mouse rests over features
     * in the map.<p>
     * By setting the TipData for a theme it is posible to set what this string
     * should be for each feature.<br>
     * The GeoData supplied to this method sould assosiate feature ids found in this
     * theme with numeric or string values to display in the tool tips.<p>
     *
     * An example of use might be:<br>
     * <code>theme.setTipData(shapefileReader.readData("Names"));<br>
     * </code>
     * 
     * @author James Macgill
     * @see #getTipText
     * @param d A GeoData containing the new Tool Tip data for this theme.
     */
    public void setTipData(GeoData t){
        if(tipData!=t){
            tipData=t;
          //  notifyThemeChangedListeners(ThemeChangedEvent.GEOGRAPHY);
        }
        //???change this to .DATA
    } 
    
     /**
     * Viewers have the ability to display short popup messages
     * in the form of tool tips when the users mouse rests over features
     * in the map.<p>
     * This method provides flexible tooltips at the expence of being a little less
     * straight forward than setTipData().<br>
     * To construct setup a tooltip this method needs a format string wich is a string
     * containing special characters that will be parsed, and an array of GeoData columns
     * to be put into the formatstring when the tooltip is shown<p>
     *
     * An example of use might be:<br>
     * <code>
     *      TooltipArray[0]=shapefileReader.readData("Country");
     *      TooltipArray[1]=shapefileReader.readData("Population");
     *      theme.setComplexTipData(TooltipArray, "%s: %s");<br>
     * </code>
     * This would produce tooltips of the form "Norway: 40000000" when run. Note that more than 
     * one element can be used, and static strings can be a part of the tooltip.
     *
     * 
     * @author Kjetil Thuen
     * @see #setTipData
     * @see #getTipText
     * @param t An array of GeoDatas containing the new Tool Tip data for this theme.
     * @param ts A formatstring. 
     */
    public void setComplexTipData(GeoData t[], String ts) {
      if (complexTipData != t) {
         complexTipData = t;
      }
      tipformat = ts;
    }
    
    
    /**
     * gets the current geoData.
     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -