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

📄 gpssatellites.java

📁 GPS Track connects to a GPS and records the path that you travel. Tracks can be uploaded to a web s
💻 JAVA
字号:
// J2ME GPS Track
// Copyright (C) 2006 Dana Peters
// http://www.qcontinuum.org/gpstrack

package org.qcontinuum.gpstrack;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import henson.midp.Float;
import java.util.*;
import org.qcontinuum.astro.*;

class GpsSatellites extends Canvas implements CommandListener {

    private Command mNextCommand, mStopCommand;
    private int mDayColour = 0x0080ff;
    private int mNightColour = 0x808080;

    public GpsSatellites() {
        Preferences preferences = GpsTrack.getPreferences();
        addCommand(mStopCommand = new Command("Stop", Command.STOP, 0));
        addCommand(mNextCommand = new Command("Next", Command.SCREEN, 0));
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d)  {
        if (c == mNextCommand) {
            GpsTrack.display(GpsTrack.getTrackStatus());
        } else if (c == mStopCommand) {
            GpsTrack.stop();
        }
    }

    public void timerTick() {
        repaint();
    }

    public void paint(Graphics g) {
        synchronized (g) {
            Gps gps = GpsTrack.getGps();
            int midX = getWidth() / 2;
            int midY = getHeight() / 2;
            int maxR = Math.min(midX, midY);
            AstroInformation astroInformation = GpsTrack.getAstroInformation();
            HorizontalPosition sunPosition = astroInformation.getSunPosition();
            HorizontalPosition moonPosition = astroInformation.getMoonPosition();
            Float moonPhase = astroInformation.getMoonPhase();
            for (int i = 6; i > 0; i--) {
                int r = maxR * i / 6;
                if (i == 6) {
                    if (sunPosition == null || sunPosition.getElevation() > -10) {
                        g.setColor(0xFFFFFF);
                        g.fillRect(0, 0, getWidth(), getHeight());
                        g.setColor(mDayColour);
                    } else {
                        g.setColor(0x000000);
                        g.fillRect(0, 0, getWidth(), getHeight());
                        g.setColor(mNightColour);
                    }
                    g.fillArc(midX - r, midY - r, r * 2, r * 2, 0, 360);
                    g.setColor(g.getRedComponent()/2, g.getGreenComponent()/2, g.getBlueComponent()/2);
                }
                g.drawArc(midX - r, midY - r, r * 2, r * 2, 0, 360);
            }
            HorizontalPosition lineSkyPosition = new HorizontalPosition(0, 0);
            int step;
            int azimuthOffset = 0;
            Float heading = gps.getHeading();
            Float speed = gps.getSpeed();
            if (heading != null && speed != null && !speed.Less(3))
                azimuthOffset = (int)heading.toLong();
            for (step = 0; step < 8; step++) {
                lineSkyPosition.setAzimuth(step * 45);
                ScreenPosition lineScreenPosition = lineSkyPosition.toScreenPosition(this, azimuthOffset, false);
                g.drawLine(midX, midY, lineScreenPosition.x, lineScreenPosition.y);
            }
            Font boldFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
            Font normalFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);
            g.setFont(boldFont);
            g.setColor(0x000000);
            HorizontalPosition labelSkyPosition = new HorizontalPosition(0, 10);
            String labels[] = {"N", "E", "S", "W"};
            for (int i = 0; i < labels.length; i++) {
                labelSkyPosition.setAzimuth(i * 90);
                ScreenPosition label = labelSkyPosition.toScreenPosition(this, azimuthOffset, false);
                g.drawString(labels[i], label.x, label.y - boldFont.getHeight()/2, g.TOP|g.HCENTER);
            }
            int r = 10;
            int d = r * 2;
            if (moonPosition != null && moonPosition.getElevation() > -5) {
                ScreenPosition moon = moonPosition.toScreenPosition(this, azimuthOffset, false);
                g.setColor(0xffffff);
                g.fillArc(moon.x - r, moon.y - r, d, d, 90, 180);
                g.setColor(0x000000);
                g.fillArc(moon.x - r, moon.y - r, d, d, 270, 180);
                int arcWidth = (int)(moonPhase.Sub(new Float(5, -1)).Mul(d * 2).toLong());
                g.setColor(arcWidth < 0 ? 0x000000 : 0xffffff);
                g.fillArc(moon.x - Math.abs(arcWidth)/2, moon.y - r, Math.abs(arcWidth), d, 0, 360);
                g.setColor(0x000000);
                g.drawArc(moon.x - r, moon.y - r, d, d, 0, 360);
            }
            if (sunPosition != null && sunPosition.getElevation() > -10) {
                ScreenPosition sun = sunPosition.toScreenPosition(this, azimuthOffset, false);
                g.setColor(0xffff00);
                g.fillArc(sun.x - r, sun.y - r, d, d, 0, 360);
                g.setColor(0x000000);
                g.drawArc(sun.x - r, sun.y - r, d, d, 0, 360);
            }
            GpsHorizontalPosition gpsSatellites[] = gps.getSatellites();
            g.setFont(normalFont);
            int radius = Math.max(normalFont.charWidth('0') * 2, normalFont.getHeight())/2;
            for (int i = 0; i < 12; i++) {
                if (gpsSatellites[i].getAzimuth() > 0) {
//                        g.setFont(gpsSatellites[i].getFix() ? boldFont : normalFont);
                    ScreenPosition sat = gpsSatellites[i].toScreenPosition(this, azimuthOffset, false);
                    g.setColor(gpsSatellites[i].getFix() ? 0x00ffff : 0x008080);
                    g.fillRoundRect(sat.x - radius, sat.y - radius, radius * 2, radius * 2, 8, 8);
                    g.setColor(0x000000);
                    g.drawString(Integer.toString(gpsSatellites[i].getSnr()), sat.x, sat.y - normalFont.getHeight()/2, g.TOP|g.HCENTER);
                }
            }
        }
    }
}

⌨️ 快捷键说明

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