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

📄 statuslayer.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                        this.backColor);                drawLabel(dc, label, new Vec4(1, verticalSpacing, 0), this.color);                if (noNetwork.length() > 0)                {                    size = getTextRenderSize(dc, noNetwork);                    double x = viewport.getWidth() - size.getWidth();                    drawLabel(dc, noNetwork, new Vec4(x, verticalSpacing, 0), Color.RED);                }                else if (activatedDownload)                {                    //draw background image                    if (iconTexture == null)                        initBGTexture();                    double width = this.getScaledBGWidth();                    double height =this.getScaledBGHeight();                    if (iconTexture != null)                    {                        gl.glTranslated(viewport.getWidth() - width, 0, 0d);                        gl.glTranslated(width / 2, height / 2, 0);                        gl.glRotated(rotated, 0d, 0d, 1d);                        gl.glTranslated(-width / 2, -height / 2, 0);                        if (iconTexture != null)                        {                            gl.glEnable(GL.GL_TEXTURE_2D);                            iconTexture.bind();                            gl.glColor4d(1d, 1d, 1d, this.getOpacity());                            gl.glEnable(GL.GL_BLEND);                            gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);                            TextureCoords texCoords = iconTexture.getImageTexCoords();                            gl.glScaled(width, height, 1d);                            dc.drawUnitQuad(texCoords);                        }                    }                }            }        }		finally		{			if (projectionPushed)			{				gl.glMatrixMode(GL.GL_PROJECTION);				gl.glPopMatrix();			}			if (modelviewPushed)			{				gl.glMatrixMode(GL.GL_MODELVIEW);				gl.glPopMatrix();			}			if (attribsPushed)				gl.glPopAttrib();		}	}    private void bumpRotation()    {        if (rotated > rotationIncrement)            rotated = rotated - rotationIncrement;        else            rotated=360;    }    public void stageChanged(RenderingEvent event)    {        if (!event.getStage().equals(RenderingEvent.BEFORE_BUFFER_SWAP))            return;        EventQueue.invokeLater(new Runnable()        {            public void run()            {                if (eventSource.getView() != null && eventSource.getView().getEyePosition() != null)                    altDisplay = makeEyeAltitudeDescription(                        eventSource.getView().getEyePosition().getElevation());                else                    altDisplay = (Logging.getMessage("term.Altitude"));            }        });    }    private Dimension getTextRenderSize(DrawContext dc, String text)    {        TextRenderer textRenderer = dc.getTextRendererCache().getOrCreate(this.defaultFont);		Rectangle2D nameBound = textRenderer.getBounds(text);        return nameBound.getBounds().getSize();    }    // Draw the label    private void drawLabel(DrawContext dc, String text, Vec4 screenPoint, Color textColor)    {        int x = (int) screenPoint.x();        int y = (int) screenPoint.y();        TextRenderer textRenderer = dc.getTextRendererCache().getOrCreate(this.defaultFont);        textRenderer.begin3DRendering();        textRenderer.setColor(this.getBackgroundColor(textColor));        textRenderer.draw(text, x + 1, y - 1);        textRenderer.setColor(textColor);        textRenderer.draw(text, x, y);        textRenderer.end3DRendering();	}	private final float[] compArray = new float[4];    // Compute background color for best contrast    private Color getBackgroundColor(Color color)    {        Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), compArray);        if (compArray[2] > 0.5)            return new Color(0, 0, 0, 0.7f);        else            return new Color(1, 1, 1, 0.7f);    }    protected Position previousPos;    private void handleCursorPositionChange(PositionEvent event)    {        Position newPos = event.getPosition();        if (newPos != null)        {            latDisplay = makeAngleDescription("Lat", newPos.getLatitude(), coordDecimalPlaces);            lonDisplay = makeAngleDescription("Lon", newPos.getLongitude(), coordDecimalPlaces);            elevDisplay = makeCursorElevationDescription(                eventSource.getModel().getGlobe().getElevation(newPos.getLatitude(), newPos.getLongitude()));            //Need to force an extra draw.  without this the displayed value lags the actual when just moving cursor            if ((previousPos != null) && (previousPos.getLatitude().compareTo(newPos.getLatitude()) != 0)                                        && (previousPos.getLongitude().compareTo(newPos.getLongitude()) != 0))                this.eventSource.redraw();        }        else        {            latDisplay = "";            lonDisplay = Logging.getMessage("term.OffGlobe");            elevDisplay= "";        }        previousPos=newPos;    }    private void initBGTexture()    {        try        {            InputStream iconStream = this.getClass().getResourceAsStream("/" + iconFilePath_bg);            if (iconStream == null)            {                File iconFile = new File(iconFilePath_bg);                if (iconFile.exists())                {                    iconStream = new FileInputStream(iconFile);                }            }            iconTexture = TextureIO.newTexture(iconStream, false, null);            iconTexture.bind();            this.bgWidth = iconTexture.getWidth();            this.bgHeight = iconTexture.getHeight();        }        catch (IOException e)        {            String msg = Logging.getMessage("layers.IOExceptionDuringInitialization");            Logging.logger().severe(msg);            throw new WWRuntimeException(msg, e);        }    }    private void drawFilledRectangle(DrawContext dc, Vec4 origin, Dimension dimension, Color color)    {        GL gl = dc.getGL();        gl.glColor4ub((byte) color.getRed(), (byte) color.getGreen(),            (byte) color.getBlue(), (byte) color.getAlpha());        gl.glDisable(GL.GL_TEXTURE_2D);        // no textures        gl.glBegin(GL.GL_POLYGON);        gl.glVertex3d(origin.x, origin.y, 0);        gl.glVertex3d(origin.x + dimension.getWidth(), origin.y, 0);        gl.glVertex3d(origin.x + dimension.getWidth(), origin.y + dimension.getHeight(), 0);        gl.glVertex3d(origin.x, origin.y + dimension.getHeight(), 0);        gl.glVertex3d(origin.x, origin.y, 0);        gl.glEnd();    }    protected String makeAngleDescription(String label, Angle angle, int places)    {        return String.format("%s %s", label, angle.toDecimalDegreesString(places));    }    protected String makeEyeAltitudeDescription(double metersAltitude)    {        String altitude = Logging.getMessage("term.Altitude");        if (UNIT_IMPERIAL.equals(elevationUnit))            return String.format("%s %,d mi",altitude, (int) Math.round(WWMath.convertMetersToMiles(metersAltitude)));        else // Default to metric units.            return String.format("%s %,d km",altitude, (int) Math.round(metersAltitude / 1e3));    }    protected String makeCursorElevationDescription(double metersElevation)    {        String elev = Logging.getMessage("term.Elev");        if (UNIT_IMPERIAL.equals(elevationUnit))            return String.format("%s %,d feet", elev, (int) Math.round(WWMath.convertMetersToFeet(metersElevation)));        else // Default to metric units.            return String.format("%s %,d meters", elev, (int) Math.round(metersElevation));    }	@Override	public String toString()	{		return Logging.getMessage("layers.StatusLayer.Name");	}    public static class StatusUTMLayer extends StatusLayer    {        public void moved(PositionEvent event)        {            this.handleCursorPositionChange(event);        }        private void handleCursorPositionChange(PositionEvent event)        {            Position newPos = event.getPosition();            if (newPos != null)            {                //merge lat & lon into one field to display UMT coordinates in lon field                String las = makeAngleDescription("Lat", newPos.getLatitude(), coordDecimalPlaces) + " "                    + makeAngleDescription("Lon", newPos.getLongitude(), coordDecimalPlaces);                String els = makeCursorElevationDescription(                    getEventSource().getModel().getGlobe().getElevation(newPos.getLatitude(), newPos.getLongitude()));                String los;                try                {                    UTMCoord UTM = UTMCoord.fromLatLon(newPos.getLatitude(), newPos.getLongitude(),                        getEventSource().getModel().getGlobe());                    los = UTM.toString();                }                catch (Exception e)                {                    los = "";                }                latDisplay = las;                lonDisplay = los;                elevDisplay = els;                if ((previousPos != null) && (previousPos.getLatitude().compareTo(newPos.getLatitude()) != 0)                    && (previousPos.getLongitude().compareTo(newPos.getLongitude()) != 0))                    this.eventSource.redraw();            }            else            {                latDisplay = "";                lonDisplay = Logging.getMessage("term.OffGlobe");                elevDisplay = "";            }        }    }    public static class StatusMGRSLayer extends StatusLayer    {        public void moved(PositionEvent event)        {            this.handleCursorPositionChange(event);        }        private void handleCursorPositionChange(PositionEvent event)        {            Position newPos = event.getPosition();            if (newPos != null)            {                //merge lat & lon into one field to display MGRS in lon field                String las = makeAngleDescription("Lat", newPos.getLatitude(), coordDecimalPlaces) + " "                    + makeAngleDescription("Lon", newPos.getLongitude(), coordDecimalPlaces);                String els = makeCursorElevationDescription(                    getEventSource().getModel().getGlobe().getElevation(newPos.getLatitude(), newPos.getLongitude()));                String los;                try                {                    MGRSCoord MGRS = MGRSCoord.fromLatLon(newPos.getLatitude(), newPos.getLongitude(),                        getEventSource().getModel().getGlobe());                    los = MGRS.toString();                }                catch (Exception e)                {                    los = "";                }                latDisplay = las;                lonDisplay = los;                elevDisplay = els;                if ((previousPos != null) && (previousPos.getLatitude().compareTo(newPos.getLatitude()) != 0)                    && (previousPos.getLongitude().compareTo(newPos.getLongitude()) != 0))                    this.eventSource.redraw();            }            else            {                latDisplay = "";                lonDisplay = Logging.getMessage("term.OffGlobe");                elevDisplay = "";            }        }    }}

⌨️ 快捷键说明

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