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

📄 viewer.java

📁 geotools的源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        highlightMode = flag;
    }
    
    /**
     * set the timeout before displaying a tooltip for a feature
     */
    public void setToolTipTimeout(int t){
        timeout = t;
    }
    
    /**
     * get the timeout before displaying a tooltip for a feature
     */
    public int getToolTipTimeout(){
        return timeout;
    }
    
    
    /**
     * update the contents of the sequenceBuffer
     * may be prossesor intesive!!!
     */
    private void updateSequenceBuffer(){
        Graphics g = null;
        if(sequenceBuffer!=null){
            for(int i = 0;i < sequenceBuffer.length;i++){
                g = sequenceBuffer[i].getGraphics();
                if(staticBuffer != null){
                    g.drawImage(staticBuffer,0,0,this);
                }
                sequenceTheme[i].paintScaled(g,scale);
                sequenceFrameValid[i] = true;
                //setSequenceFrame(i);//experimental, needs a switch as this may not always be desired
            }
        }
    }
    
    private void updateSequenceBuffer(int frame){
        Graphics g = null;
        if(sequenceBuffer!=null){
            g = sequenceBuffer[frame].getGraphics();
            if(staticBuffer != null){
                g.drawImage(staticBuffer,0,0,this);
            }
            sequenceTheme[frame].paintScaled(g,scale);
            sequenceFrameValid[frame] = true;
        }
    }
    
    
    /**
     * clear the up-to-date flags for all of the sequence buffer
     */
    public void invalidateSequenceBuffer(){
        if(sequenceBuffer!=null){
            for(int i = 0;i < sequenceBuffer.length;i++){
                sequenceFrameValid[i] = false;
            }
        }
    }
    public void invalidateStaticBuffer(){
        updateStaticBuffer();
        repaint();
        notifyCompositionChanged(CompositionChangedEvent.VISIBILITY);
    }
    
    
    
    /**
     * Add a new static theme
     * @param t
     */
    public void addStaticTheme(Theme t){
        addStaticTheme(t,0);
    }
    
    public void addStaticTheme(Theme t,int waight){
        themeStack.addTheme(t,waight,true);
        staticThemes.addElement(t);
        visibleThemes.addElement(t);
        themeCount++;
        //if no scale has been set then scale to this theme
        if(t.getBounds().width>0){
            if(debug)System.out.println("V--->"+name+"Adding a theme to Bounds\n"+
            fullMapExtent);
            fullMapExtent.add(t.getBounds());
            if(debug)System.out.println("V--->"+name+"Added a theme to Bounds\n"+
            fullMapExtent);
        }
        if(themeCount==1){ //is this the first?
            setupScale();
        }
        //update the staticBuffer to acount for this addition
        updateStaticBuffer();
        //add theme to those notified when highlight position changes
        addHighlightPositionChangedListener(t);
        addSelectionPositionChangedListener(t);
        addSelectionRegionChangedListener(t);
        t.addThemeChangedListener(this);
        notifyCompositionChanged(CompositionChangedEvent.ADDED);
        // if(debug)System.out.println("New theme added");
    }
    
    private void setupScale(){
        lastSize = getBounds();
        if(scale!=null){
            if(debug)System.out.println("V--->"+name+"Setting up a non null scaler");
            scale.removeScaleChangedListener(this);
        }
        //scale = new Scaler(fullMapExtent,this.getBounds());
        scale.addScaleChangedListener(this);
        scale.setGraphicsExtent(getBounds());
        scale.setMapExtent(fullMapExtent,true);
        
    }
    
    
    /**
     * Called when something has happend that requires the staticBuffer
     * be redrawn
     * this may be a chane in scale or an aditional theme being added
     */
    private synchronized void updateStaticBuffer(){
        Cursor old = this.getCursor();
        if(debug)System.out.println("V--->"+name+"Updating Static Buffer");
        selectionChanged = true;
        this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        if(staticBuffer == null&&getBounds().width>0)
            staticBuffer = this.createImage(getBounds().width,getBounds().height);
        if(staticBuffer == null) {
            this.setCursor(old);
            return;
        }
        Graphics g = staticBuffer.getGraphics();
        Theme t;
        // if(debug)System.out.println("Updating static buffer");
        g.setColor(this.getBackground());
        Rectangle r=this.getBounds();
        g.fillRect(0,0,r.width,r.height);
        //for (Enumeration e = staticThemes.elements() ; e.hasMoreElements() ;) {
        ThemeStack.ThemeInfo[] list = themeStack.getOrderedThemeInfos();
        if(debug)System.out.println("V--->"+name+"Ordered list contains "+list.length+" entries");
        for(int i=0;i<list.length;i++){
            
            if(!list[i].isVisible())continue;
            t = list[i].getTheme();
//while(it.hasNext()){
           // t = (Theme)it.next();
           // if(visibleThemes.contains(t)){
                if(debug)System.out.println("V--->"+name+"Painting theme in updatestatic buffer");
                //if(visibleThemes.contains(t)){
                if(debug)System.out.println("Drawing "+t);
                t.paintScaled(g,scale);
            //}
        }
            /*
        for (Enumeration e = visibleThemes.elements() ; e.hasMoreElements() ;) {
            t=(Theme)e.nextElement();
            if(debug)System.out.println("V--->"+name+"Painting theme in updatestatic buffer");
            //if(visibleThemes.contains(t)){
            if(debug)System.out.println("Drawing "+t);
            t.paintScaled(g,scale);
            //}
        }
             */
        this.setCursor(old);
        //force update of selection buffer to reflect changes in this buffer
        //for now seting flag, but could possibly call updateSelectionBuffer directly?
        this.selectionChanged = true;
        //repaint();
    }
    
    /**
     * Called when something has happend that requires the staticBuffer
     * be redrawn
     * this may be a chane in scale or an aditional theme being added
     */
    private void updateSelectionBuffer(){
        Cursor old = this.getCursor();
        if(debug)System.out.println("V--->"+name+"Updating Selection Buffer");
        selectionChanged = false;
        //this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        if(selectionBuffer == null&&getBounds().width>0)
            //System.out.println("Creating static buffer");
            selectionBuffer = this.createImage(getBounds().width,getBounds().height);
        if(selectionBuffer == null) {
            //System.out.println("Null static buffer");
            return;
        }
        Graphics g = selectionBuffer.getGraphics();
        Theme t;
        //System.out.println("Painting selections");
        g.drawImage(staticBuffer,0,0,this);
        paintSelections(g);
    }
    
    private void paintHighlights(Graphics g){
        Theme t;
        for (Enumeration e = staticThemes.elements() ; e.hasMoreElements() ;) {
            t=(Theme)e.nextElement();
            if(isThemeVisible(t)){
                t.paintHighlight(g,scale);
            }
        }
        try{
            if(sequenceBuffer[frame]!=null)
                sequenceTheme[frame].paintHighlight(g,scale);//experiment
        }catch(Exception e){}
        
    }
    
    private void paintSelections(Graphics g){
        Theme t;
        for (Enumeration e = staticThemes.elements() ; e.hasMoreElements() ;) {
            if(debug){System.out.println("V--->painting themes selections");}
            t=(Theme)e.nextElement();
            t.paintSelection(g,scale);
        }
        try{
            if(sequenceBuffer[frame]!=null)
                sequenceTheme[frame].paintSelection(g,scale);//experiment
        }catch(Exception e){}
        if(debug){System.out.println("V--->Done");}
        selectionChanged = false;
    }
    
    
    /**
     * Gets the map extent that fits round all currently selected features.
     * @since 0.6.5
     * @return GeoRectangle representing the bounding box of the selected features
     */
    public GeoRectangle getSelectionMapExtent(){
        GeoRectangle sme = new GeoRectangle();
        Theme t;
        for (Enumeration e = staticThemes.elements() ; e.hasMoreElements() ;) {
            t=(Theme)e.nextElement();
            sme.add(t.getSelectionMapExtent());
        }
        
        return sme;
    }
    
    /**
     * Scales the map so that the given theme fills the viewer
     * @param bounds A theme that defines the new visible extents
     */
    public void setMapExtent(Theme t){
        if(themeCount >0){
            scale.setMapExtent(t.getBounds());
        }else{
            fullMapExtent.add(t.getBounds());
            setupScale();
        }
    }
    /** sets the maximum mapextent to use for resets and drawing
     * until another theme is added.
     */
    
    public void setMaximumMapExtent(Theme t){
        setMaximumMapExtent(t.getBounds());
    }
    public void setMaximumMapExtent(GeoRectangle r){
        fullMapExtent=r;
    }
    
    /**
     * Scales the map so that the given point is at the center of the view.
     * @param p The point to center on.
     */
    public void centerOnPoint(GeoPoint p){
        GeoRectangle bounds = scale.getMapExtent();
        double xOffset = bounds.width/2;
        double yOffset = bounds.height/2;
        GeoRectangle newBounds = new GeoRectangle(p.x-xOffset,p.y-yOffset,xOffset*2,yOffset*2);
        setMapExtent(newBounds);
    }
    
    
    /**
     * Scales the map so that the given point is at the center of the view, and then zooms to the specified amount
     * @param p The point to center on.
     * @param percent The ammount to zoom in by.
     */
    public void zoomOnPoint(GeoPoint p,double percent){
        GeoRectangle bounds = scale.getMapExtent();
        double newWidth = fullMapExtent.width*(100d/percent);
        double newHeight = fullMapExtent.height*(100d/percent);
        
        double xOffset = newWidth/2d;
        double yOffset = newHeight/2d;
        
        GeoRectangle newBounds = new GeoRectangle(p.x-xOffset,p.y-yOffset,xOffset*2,yOffset*2);
        if(debug)System.out.println("V--->old "+bounds+"\n new "+newBounds);
        setMapExtent(newBounds);
    }
    
    /**
     * Scales the map so that the current center remains whilst the zoom level is set to a percentage of the full size.
     * @param p The point to center on.
     * @param percent The ammount to zoom in by.
     */
    public void zoomPercent(double percent){
        GeoRectangle bounds = scale.getMapExtent();
        GeoPoint p = new GeoPoint(bounds.x+bounds.width/2,bounds.y+bounds.height/2);
        
        double newWidth = fullMapExtent.width*(100d/percent);
        double newHeight = fullMapExtent.height*(100d/percent);
        
        double xOffset = newWidth/2d;
        double yOffset = newHeight/2d;
        
        GeoRectangle newBounds = new GeoRectangle(p.x-xOffset,p.y-yOffset,xOffset*2,yOffset*2);
        
        if(debug)System.out.println("V--->old "+bounds+"\n new "+newBounds);
        setMapExtent(newBounds);
    }
    
    /**
     * Calculates the value of the current zoom level as a percentage of the full map size.
     * return double The current zoom factor as a percentage.
     **/
    public double getZoomAsPercent(){
        return Math.max((100d/scale.getMapExtent().getWidth())*fullMapExtent.width,(100d/scale.getMapExtent().getHeight())*fullMapExtent.height);
    }
    
    /**
     * Scales the map so that the given point is at the center of the view, and then zooms out by the specified amount
     * @param p The point to center on.
     * @param percent The ammount to zoom out by.
     */
    public void zoomOutOnPoint(GeoPoint p,double percent){
        double per = getZoomAsPercent();
        if(debug)System.out.println("Zoom out from "+per);
        per -= (percent/100d)*per;
        if(debug)System.out.println("Zoom out to "+per);
        zoomOnPoint(p,per);
    }
    /**
     * Scales the map so that the given point is at the center of the view, and then zooms in by the specified amount
     * @param p The point to center on.
     * @param percent The ammount to zoom in by.
     */
    public void zoomInOnPoint(GeoPoint p,double percent){
        double per = getZoomAsPercent();
        if(debug)System.out.println("Zoom in from "+per);
        per += (percent/100d)*per;
        if(debug)System.out.println("Zoom in to "+per);
        zoomOnPoint(p,per);
    }
    
    /**
     * Scales the map so that the given rectangle fills the viewer
     * @param bounds A Georectangle that defines the new visible extents
     */
    public void setMapExtent(GeoRectangle bounds){
        setMapExtent(bounds,false);
    }

    /**
     * Scales the map so that the given rectangle fills the viewer
     * @param bounds A Georectangle that defines the new visible extents
     * @param quiet If quiet=true, then do not trigger a repaint */
    public void setMapExtent(GeoRectangle bounds,boolean quiet){
        if(themeCount >0){
            scale.setMapExtent(bounds,quiet);

            // I commented out the following.  When quiet it set=true, the
            // viewer should NOT be updated.  If you want the viewer updated,
            // then set quiet=false.
            // Cameron Shorter 29/10/1
            //
            // I think this is needed to actually change the viewer! (says who?)
            //if(quiet)scaleChanged(new ScaleChangedEvent(scale,1.0));
        }else{
            fullMapExtent.add(bounds);
            setupScale();
        }
    }
    
    /**
     * Set the map extent to fit in all layers
     */
    public void setMapExtentFull(){
        setMapExtentFull(false);
    }
    /**
     * Set the map extent to fit in all layers
     */
    public void setMapExtentFull(boolean quiet){
        if(themeCount >0){
            setMapExtent(fullMapExtent,quiet);
        }
    }
    
    /**
     * Scales the map by the given zoomfactor. The lower bound
     * of zooming is the full map containing all themes. there is

⌨️ 快捷键说明

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