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

📄 viewer.java

📁 geotools的源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    public void repaint(){
        update(this.getGraphics());
    }
    
    public void paintTip(Graphics g,String s){
        s=s.trim();
        int maxr = this.getBounds().width;
        int x = mouseStatus.screen_xy[0];
        int y = mouseStatus.screen_xy[1];
        FontMetrics fm = g.getFontMetrics();
        fm.stringWidth(s);
        int h= fm.getHeight();
        int xOffset = 5;
        int yOffset = -h-2;
        int xPad = 10;
        int yPad = 4;
        x+=xOffset;
        y+=yOffset;
        if(x+fm.stringWidth(s)+xPad>maxr){
            // System.out.print("Correcting "+x);
            int dif = maxr-(x+fm.stringWidth(s)+xPad);
            x=x+dif;
            // System.out.println(" "+x+" "+dif);
        }
        //System.out.println("Painting tip'"+s+"'");
        g.setColor(Color.black);
        g.drawRect(x,y,fm.stringWidth(s)+xPad,h+yPad);
        g.setColor(new Color(.8f,.8f,.4f));
        g.fillRect(x,y,fm.stringWidth(s)+xPad,h+yPad);
        g.setColor(Color.black);
        g.drawString(s,x+(xPad/2),y+h-yPad/2);
    }
    
    
    
    static public void main(String args[]) {
        class DriverFrame extends java.awt.Frame {
            public DriverFrame() {
                addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent event) {
                        dispose();	  // free the system resources
                        System.exit(0); // close the application
                    }
                });
                setLayout(new java.awt.BorderLayout());
                setSize(300,300);
                add(new Viewer());
            }
        }
        
        new DriverFrame().show();
    }
    
    class ViewerMouse extends java.awt.event.MouseAdapter {
        public void mouseEntered(java.awt.event.MouseEvent event) {
            Object object = event.getSource();
            if (object == Viewer.this)
                Viewer_MouseEntered(event);
        }
        
        public void mouseClicked(java.awt.event.MouseEvent event) {
            Object object = event.getSource();
            if (object == Viewer.this)
                //notifyClickEvent();
                Viewer_MouseClicked(event);
        }
        
        public void mouseReleased(java.awt.event.MouseEvent event) {
            Object object = event.getSource();
            if (object == Viewer.this)
                Viewer_MouseRelease(event);
        }
        
        public void mouseExited(java.awt.event.MouseEvent event) {
            Object object = event.getSource();
            if (object == Viewer.this)
                Viewer_MouseExit(event);
        }
    }
    
    void Viewer_MouseExit(java.awt.event.MouseEvent event) {
        if(highlightMode == INSTANT)notifyHighlightPositionChanged(null);
    }
    
    class ViewerMouseMotion extends java.awt.event.MouseMotionAdapter {
        public void mouseMoved(java.awt.event.MouseEvent event) {
            Object object = event.getSource();
            if (object == Viewer.this)
                Viewer_MouseMove(event);
        }
        
        public void mouseDragged(java.awt.event.MouseEvent event) {
            if(themeCount <1){return;}
            tool.update(getToolGraphics(),tool.M_DRAG);
        }
    }
    
    
    void Viewer_MouseRelease(java.awt.event.MouseEvent event) {
        if(themeCount <1){return;}
        tool.update(getToolGraphics(),tool.M_RELEASE);
    }
    
    public void scaleChanged(ScaleChangedEvent sce){
        Scaler s = (Scaler)sce.getSource();
        if(debug)System.out.println("V--->"+name+"Viewer reports that scale has changed");
        if(s==scale){
            if(debug)System.out.println("V--->"+name+" updating due to scale change");
            
            updateStaticBuffer();
            updateSelectionBuffer();
            invalidateSequenceBuffer();
            update(this.getGraphics());
        }
    }
    
    void Viewer_MouseMove(java.awt.event.MouseEvent event) {
        if(themeCount >0){
            tool.update(getToolGraphics(),tool.M_MOVE);
            if(highlightMode == INSTANT)notifyHighlightPositionChanged(mouseStatus.getMapPoint());
            
        }
    }
    
    
    /**
     * three methods to suport IDChangedEvent notification to listeners
     */
    public synchronized void
    addIDChangedListener(IDChangedListener ice) {
        listeners.addElement(ice);
    }
    
    
    public synchronized void
    removeIDChangedListeners(IDChangedListener ice) {
        listeners.removeElement(ice);
    }
    
    protected void notifyIDChanged() {
        Vector l;
        IDChangedEvent ice = new IDChangedEvent(this,currentID);
        synchronized(this) {l = (Vector)listeners.clone(); }
        
        for (int i = 0; i < l.size();i++) {
            ((IDChangedListener)l.elementAt(i)).idChanged(ice);
        }
    }
    
    
    /**
     * Add Highlight Position Changed Listener
     */
    public synchronized void
    addHighlightPositionChangedListener(HighlightPositionChangedListener hpcl) {
        hpcListeners.addElement(hpcl);
    }
    
    
    public synchronized void
    removeHighlightPositionChangedListener(HighlightPositionChangedListener hpcl) {
        hpcListeners.removeElement(hpcl);
    }
    
    protected void notifyHighlightPositionChanged(GeoPoint p) {
        Vector l;
        if(debug)System.out.println("V--->Hilight note "+highlightMode);
        HighlightPositionChangedEvent hpce = new HighlightPositionChangedEvent(this,p);
        synchronized(this) {l = (Vector)hpcListeners.clone(); }
        
        for (int i = 0; i < l.size();i++) {
            ((HighlightPositionChangedListener)l.elementAt(i)).highlightPositionChanged(hpce);
        }
        if(sequenceBuffer!=null && sequenceBuffer[frame]!=null){
            ((HighlightPositionChangedListener)sequenceTheme[frame]).highlightPositionChanged(hpce);
        }
        
    }
    
    
    /**
     * Add Selection Position Changed Listener
     */
    public synchronized void
    addSelectionPositionChangedListener(SelectionPositionChangedListener hpcl) {
        spcListeners.addElement(hpcl);
    }
    
    
    public synchronized void
    removeSelectionPositionChangedListener(SelectionPositionChangedListener hpcl) {
        spcListeners.removeElement(hpcl);
    }
    
    protected void notifySelectionPositionChanged(GeoPoint p) {
        if(debug)System.out.println("V--->Notifying Selection Position changed listerners");
        Vector l;
        if(debug)System.out.println("V--->Hilight note "+highlightMode);
        SelectionPositionChangedEvent spce = new SelectionPositionChangedEvent(this,p);
        synchronized(this) {l = (Vector)spcListeners.clone(); }
        
        for (int i = 0; i < l.size();i++) {
            ((SelectionPositionChangedListener)l.elementAt(i)).selectionPositionChanged(spce);
        }
        if(sequenceBuffer!=null && sequenceBuffer[frame]!=null){
            ((SelectionPositionChangedListener)sequenceTheme[frame]).selectionPositionChanged(spce);
        }
        
    }
    
    
    
    
    
    public synchronized void
    addCompositionChangedListener(CompositionChangedListener hpcl) {
        compositionChangedListeners.addElement(hpcl);
    }
    
    
    public synchronized void
    removeCompositionChangedListener(CompositionChangedListener ccl) {
        compositionChangedListeners.removeElement(ccl);
    }
    
    protected void notifyCompositionChanged(int reason) {
        if(debug)System.out.println("V--->Notifying Composition  changed listerners");
        Vector l;
        if(debug)System.out.println("V--->Composition note "+highlightMode);
        CompositionChangedEvent cce = new CompositionChangedEvent(this,reason);
        synchronized(this) {l = (Vector)compositionChangedListeners.clone(); }
        
        for (int i = 0; i < l.size();i++) {
            ((CompositionChangedListener)l.elementAt(i)).compositionChanged(cce);
        }
        
        
    }
    
    public ThemePanel getThemePanel(){
        ThemePanel tp = new ThemePanel(getThemes(),this);
        addCompositionChangedListener(tp);
        return tp;
    }
    
    
    
    /**
     * Methods to suport ViewerClickedEvent notification to listeners
     */
    public synchronized void
    addViewerClickedListener(ViewerClickedListener vcl) {
        clickedListeners.addElement(vcl);
    }
    
    /**
     * Methods to suport ViewerClickedEvent notification to listeners
     */
    public synchronized void
    removeViewerClickedListener(ViewerClickedListener vcl) {
        clickedListeners.removeElement(vcl);
    }
    
    protected void notifyClickEvent() {
        
        Vector list;
        ViewerClickedEvent vce = new ViewerClickedEvent(this,new GeoPoint(mouseStatus.getMapPoint()));
        synchronized(this) {list = (Vector)clickedListeners.clone(); }
        
        for (int i = 0; i < list.size();i++) {
            ((ViewerClickedListener)list.elementAt(i)).viewerClicked(vce);
        }
    }
    
    void Viewer_MouseClicked(java.awt.event.MouseEvent event) {
        notifyClickEvent();
        tool.update(getToolGraphics(),tool.M_CLICK);
        if(highlightMode==Viewer.REQUEST)notifyHighlightPositionChanged(mouseStatus.getMapPoint());
    }
    
    void Viewer_MouseEntered(java.awt.event.MouseEvent event) {
        // to do: code goes here.
    }
    public void setName(String n){
        name=n;
    }
    public String getName(){
        return name;
    }
    
    public synchronized void
    addSelectionRegionChangedListener(SelectionRegionChangedListener hpcl) {
        srcListeners.addElement(hpcl);
    }
    
    
    public synchronized void
    removeSelectionRegionChangedListener(SelectionRegionChangedListener hpcl) {
        srcListeners.removeElement(hpcl);
    }
    /**
     * a special selection region changed listener that will be notifed only after all other
     * region changed listeners have been notified...
     */
    public void setFinalSelectionRegionChangedListener(SelectionRegionChangedListener selectionregionchangedlistener)
    {
        srcFinal = selectionregionchangedlistener;
    }

    
    
    protected void notifySelectionRegionChanged(GeoRectangle r) {
        Vector l;
        //if(debug)System.out.println("V--->Hilight note "+highlightMode);
        SelectionRegionChangedEvent hpce = new SelectionRegionChangedEvent(this,r);
        synchronized(this) {l = (Vector)srcListeners.clone(); }
        
        for (int i = 0; i < l.size();i++) {
            ((SelectionRegionChangedListener)l.elementAt(i)).selectionRegionChanged(hpce);
        }
        if(sequenceBuffer!=null && sequenceBuffer[frame]!=null){
            ((SelectionRegionChangedListener)sequenceTheme[frame]).selectionRegionChanged(hpce);
        }
        if(srcFinal != null)
            srcFinal.selectionRegionChanged(hpce);

        
    }
    
    public void finalize(){
        if(debug)System.out.println("V--->Cleaning up");
        mouseStatus = null;
    }
    
    
    
    
    class ComponentAdapt extends java.awt.event.ComponentAdapter {
        boolean done = false;
        /**
         * The first time the viewer appears on the screen it is often empty.
         * Once a zoom, reset or pan has been performed the map appears properly.
         * The reasons for this bug are unclear but have something to do with the viewer
         * setting up the scaler before it exists on the screen, making caluclations based on
         * having zero size.  This method gets called when a component is resized, this includes
         * its first appearence on the screen.  As it stands it forces a repaint() of the viewer
         * and updates the static buffers.  This is slow and need not hapen again after the viewer
         * has been displayed for the first time, as internal methods handle the situation if
         * the viewer is resized after its first apperence.<p>
         * This is not a good fix, but it does appear to work.<br>
         */
        public void componentResized(java.awt.event.ComponentEvent event){
            if(done)return;
            updateStaticBuffer();
            repaint();
            done=true;
        }
    }
    
    public void setThemeToBottom(Theme t){
        themeStack.setToBottom(t);
        updateStaticBuffer();//this needs to be automated
        notifyCompositionChanged(CompositionChangedEvent.ORDER);
        repaint();
    }
    
    public void setThemeWaighting(Theme t,int waight){
        themeStack.setWaight(t,waight);
        updateStaticBuffer();//this needs to be automated
        notifyCompositionChanged(CompositionChangedEvent.ORDER);
        repaint();
        //themeWaights.remove(t);
        //themeWaights.put(t,new Integer(waight));
    }
    
    public int getThemeWaighting(Theme t){
        return themeStack.getWaight(t);
        //return ((Integer)themeWaights.get(t)).intValue();
    }
    
    public void swapThemes(Theme a,Theme b){
        themeStack.swapThemes(a,b);
        updateStaticBuffer();//this needs to be automated
        repaint();
        notifyCompositionChanged(CompositionChangedEvent.ORDER);
    }
    
    public void swapThemes(int a,int b){
        themeStack.swapThemes(a,b);
        updateStaticBuffer();//this needs to be automated
        repaint();
        notifyCompositionChanged(CompositionChangedEvent.ORDER);
    }
    
    
}

⌨️ 快捷键说明

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