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

📄 statuslayer.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*Copyright (C) 2001, 2008 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.examples.util;import com.sun.opengl.util.j2d.TextRenderer;import com.sun.opengl.util.texture.*;import gov.nasa.worldwind.*;import gov.nasa.worldwind.layers.AbstractLayer;import gov.nasa.worldwind.event.*;import gov.nasa.worldwind.exception.WWRuntimeException;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.geom.coords.*;import gov.nasa.worldwind.render.*;import gov.nasa.worldwind.util.*;import javax.media.opengl.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.awt.geom.*;import java.io.*;import java.util.concurrent.atomic.AtomicBoolean;/** * @author jparsons * @version $Id: StatusLayer.java 10925 2009-05-06 22:22:50Z dcollins $ *//** * Renders statusbar information as a layer. * * Used ScalebarLayer and StatusBar as template * *///TODO//  3. move some methods duplicated in statusbar to a utility class//  6. add ability to put status text on top of windowpublic class StatusLayer extends AbstractLayer implements PositionListener, RenderingListener{    public final static String UNIT_METRIC = "gov.nasa.worldwind.StatusLayer.Metric";    public final static String UNIT_IMPERIAL = "gov.nasa.worldwind.StatusLayer.Imperial";        private String iconFilePath_bg = "images/dot-clockwise-32.png";    private Color color = Color.white;                //text color    private Font defaultFont = Font.decode("Arial-BOLD-12");    protected WorldWindow eventSource;    protected String latDisplay ="";    protected String lonDisplay ="";    protected String elevDisplay="";    protected String altDisplay ="";    private String noNetwork = "";    private String elevationUnit = UNIT_METRIC;    private boolean showNetworkStatus = true;    private AtomicBoolean isNetworkAvailable = new AtomicBoolean(true);    private boolean activatedDownload = false;    private int bgWidth;    private int bgHeight;    private double iconScale = .5d; //adjust icon size    private int iconHeight=16;    private Texture iconTexture;    private double rotated = 0.0d;    private Color backColor = new Color(0f, 0f, 0f, 0.4f);    protected int coordDecimalPlaces = 4;    static int rotationIncrement=60;    private int verticalSpacing=2; //move text off of the botom edge    // Draw it as ordered with an eye distance of 0 so that it shows up in front of most other things.    private OrderedIcon orderedImage = new OrderedIcon();    private class OrderedIcon implements OrderedRenderable    {        public double getDistanceFromEye()        {            return 0;        }        public void pick(DrawContext dc, Point pickPoint)        {            StatusLayer.this.draw(dc);        }        public void render(DrawContext dc)        {            StatusLayer.this.draw(dc);        }    }	public StatusLayer()    {        setPickEnabled(false);        Timer downloadTimer = new Timer(300, new ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent actionEvent)            {                if (!showNetworkStatus)                {                    activatedDownload = false;                    noNetwork = "";                    return;                }                if (!isNetworkAvailable.get())                {                    noNetwork = Logging.getMessage("term.NoNetwork");                    return;                }                else                    noNetwork = "";                if (isNetworkAvailable.get() && WorldWind.getRetrievalService().hasActiveTasks())                {                    activatedDownload = true;                    bumpRotation();                    if (eventSource != null)                        eventSource.redraw();  //smooth graphic                }                else                {                    if (activatedDownload && (eventSource != null) )                    {                        eventSource.redraw();  //force a redraw to clear downloading graphic                    }                    activatedDownload = false;                }            }        });        downloadTimer.start();        Timer netCheckTimer = new Timer(10000, new ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent actionEvent)            {                if (!showNetworkStatus)                    return;                Thread t = new Thread(new Runnable()                {                    public void run()                    {                        isNetworkAvailable.set(!WorldWind.getNetworkStatus().isNetworkUnavailable());                    }                });                t.start();            }        });        netCheckTimer.start();    }    public void setElevationUnits(String units)    {        elevationUnit = units;    }    public Font getDefaultFont()    {        return defaultFont;    }    public void setDefaultFont(Font font)    {        if (font == null)        {            String msg = Logging.getMessage("nullValue.FontIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        this.defaultFont = font;    }    public int getCoordSigDigits()    {        return coordDecimalPlaces;    }    public void setCoordDecimalPlaces(int coordDecimalPlaces)    {        this.coordDecimalPlaces = coordDecimalPlaces;    }    public Color getBackColor()    {        return backColor;    }    public void setBackColor(Color backColor)    {        if ( backColor == null)        {            String msg = Logging.getMessage("nullValue.ColorIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        this.backColor = backColor;    }    protected WorldWindow getEventSource()    {        return eventSource;    }    private double getScaledBGWidth()    {        return this.bgWidth * this.iconScale;    }    private double getScaledBGHeight()    {        return this.bgHeight * this.iconScale;    }    // Rendering    @Override    public void doRender(DrawContext dc)    {        dc.addOrderedRenderable(this.orderedImage);    }    @Override    public void doPick(DrawContext dc, Point pickPoint)    {        // Delegate drawing to the ordered renderable list        dc.addOrderedRenderable(this.orderedImage);    }    public void setEventSource(WorldWindow newEventSource)    {        if ( newEventSource == null)        {            String msg = Logging.getMessage("nullValue.WorldWindow");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if (this.eventSource != null)        {            this.eventSource.removePositionListener(this);            this.eventSource.removeRenderingListener(this);        }        newEventSource.addPositionListener(this);        newEventSource.addRenderingListener(this);        this.eventSource = newEventSource;    }    public void moved(PositionEvent event)    {        this.handleCursorPositionChange(event);    }	// Rendering	public void draw(DrawContext dc)	{		GL gl = dc.getGL();		boolean attribsPushed = false;		boolean modelviewPushed = false;		boolean projectionPushed = false;		try		{			gl.glPushAttrib(GL.GL_DEPTH_BUFFER_BIT					| GL.GL_COLOR_BUFFER_BIT					| GL.GL_ENABLE_BIT					| GL.GL_TEXTURE_BIT					| GL.GL_TRANSFORM_BIT					| GL.GL_VIEWPORT_BIT					| GL.GL_CURRENT_BIT);			attribsPushed = true;			gl.glDisable(GL.GL_TEXTURE_2D);		// no textures			gl.glEnable(GL.GL_BLEND);			gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);			gl.glDisable(GL.GL_DEPTH_TEST);			// Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)			// into the GL projection matrix.			java.awt.Rectangle viewport = dc.getView().getViewport();			gl.glMatrixMode(javax.media.opengl.GL.GL_PROJECTION);			gl.glPushMatrix();			projectionPushed = true;			gl.glLoadIdentity();            String label = String.format("%s   %s   %s   %s", altDisplay, latDisplay, lonDisplay,                                                            elevDisplay);            Dimension size = getTextRenderSize(dc, label);            if (size.width < viewport.getWidth())   //todo more accurate add size of graphic            {                double maxwh = size.width > size.height ? size.width : size.height;                gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);                gl.glMatrixMode(GL.GL_MODELVIEW);                gl.glPushMatrix();                modelviewPushed = true;                gl.glLoadIdentity();                if (backColor != null)                    drawFilledRectangle(dc,new Vec4(0, 0, 0),                                    new Dimension((int)viewport.getWidth(), Math.max((int)size.getHeight(),iconHeight)),

⌨️ 快捷键说明

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