📄 compass.java
字号:
// J2ME Compass 4.0
// Copyright (C) 2007 Dana Peters
// http://www.qcontinuum.org/compass
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Floating point calculations performed using:
// henson.midp.Float (C) by Nikolay Klimchuk
// http://henson.newmail.ru
// Global airport database provided by:
// http://www.partow.net/miscellaneous/airportdatabase/
// GlobalAirportDatabase.txt converted to GlobalAirportDatabase.dat
// using script AirportsTxtToDat.vbs
package org.qcontinuum.compass;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
import org.qcontinuum.astro.*;
import henson.midp.Float;
public class Compass extends MIDlet {
final static private int REFRESHMILLIS = 10 * 60 * 1000;
private static Compass sCompass;
private static Display sDisplay;
private static CompassCanvas sCompassCanvas;
private static Preferences sPreferences;
private static Timer sTimer;
private static Date sDate;
private static boolean sRefresh;
public Compass() {
sCompass = this;
}
public void startApp() {
sDisplay = Display.getDisplay(this);
sPreferences = new Preferences();
sCompassCanvas = new CompassCanvas();
sDate = new Date(System.currentTimeMillis());
sTimer = new Timer();
sTimer.schedule(new RefreshTimerTask(), REFRESHMILLIS, REFRESHMILLIS);
display(sCompassCanvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public static void exit() {
sTimer.cancel();
sCompass.destroyApp(true);
sCompass.notifyDestroyed();
sCompass = null;
}
public static void setRefresh(boolean refresh) {
sRefresh = refresh;
}
public static boolean getRefresh() {
return sRefresh;
}
public static Date getDate() {
return sDate;
}
public static void setDate(Date newDate) {
sDate = newDate;
sRefresh = true;
}
public class RefreshTimerTask extends TimerTask {
public void run() {
if (updateDate()) {
if (sCompassCanvas.isShown())
sCompassCanvas.repaint();
}
}
}
public static boolean updateDate() {
long currentTimeMillis = System.currentTimeMillis();
if (Math.abs(currentTimeMillis - sDate.getTime()) < REFRESHMILLIS + 5000) {
setDate(new Date(System.currentTimeMillis()));
return true;
}
return false;
}
public static void display(Displayable displayable) {
sDisplay.setCurrent(displayable);
}
public static void display() {
display(sCompassCanvas);
}
public static void display(Alert alert, Displayable displayable) {
sDisplay.setCurrent(alert, displayable);
}
public static void display(Alert alert) {
display(alert, sCompassCanvas);
}
public static void display(Exception e, Displayable displayable) {
Alert alert = new Alert("Error",
"Exception: " + e.getClass().getName() + " " + e.getMessage(), null, AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
sDisplay.setCurrent(alert, displayable);
}
public static void display(Exception e) {
display(e, sCompassCanvas);
}
public static void display(String text, int seconds, Displayable displayable) {
Alert alert = new Alert("Compass");
alert.setTimeout(seconds == 0 ? Alert.FOREVER : seconds * 1000);
alert.setType(AlertType.INFO);
alert.setString(text);
display(alert, displayable);
}
public static void display(String text, int seconds) {
display(text, seconds, sCompassCanvas);
}
public static void display(String text, Displayable displayable) {
display(text, 0, displayable);
}
public static void display(String text) {
display(text, 0, sCompassCanvas);
}
public static Display getDisplay() {
return sDisplay;
}
public static Preferences getPreferences() {
return sPreferences;
}
public static String getFloat(Float f, int decimals) {
StringBuffer sb = new StringBuffer();
sb.append(Float.Int(f).toLong());
sb.append('.');
int i;
Float n = Float.abs(f);
for (i = 0; i < decimals; i++) {
n = Float.Frac(n).Mul(10);
sb.append(Float.Int(n).toLong());
}
return sb.toString();
}
public static String getTime(UtcDate utcDate) {
StringBuffer sb = new StringBuffer();
if (utcDate == null)
sb.append("none");
else
if (sPreferences.Hour24)
sb.append(utcDate.get24HourTimeString());
else
sb.append(utcDate.get12HourTimeString());
return sb.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -