?? vrmitest.java
字號:
/***********************************************************************
* J a v a G P S - GPS access library and Java API *
* Copyright (C) 2001 Ulrich Walther *
* *
* 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 of *
* 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 *
***********************************************************************/
package org.iu.gps;
import java.io.*;
/**
* VRMITest is the test class for the VRMI module. VRMI is a higher layer above
* the GPSDriver and allows for different kinds of triggers: - periodic
* reporting - distance-based reporting - region-based reporting
*
*@author walther
*/
public class VRMITest
implements VRMITriggerListener {
/**
* Create new instance of VRMITest. Installs periodic, distance and region
* triggers.
*
*@param gpsd Parameter
*@exception Exception Exception
*/
public VRMITest( GPSDriver gpsd ) throws Exception
{
// create VRMI interface that uses the GPS driver
VRMI vrmi = new VRMI( gpsd );
// Send periodic trigger every 3 seconds = 3000 ms
vrmi.addPeriodicTrigger( this, true, 3000 );
// Send trigger if distance varies more than 100 meters OR
// (if user did not move that far) after 20 seconds = 20000 ms
vrmi.addDistanceTrigger( this, true, 100.0, 20000 );
// The following coordinates define the crossing between
// "Kirrlacher Strasse" and "Kapellenstrasse".
double region[][] = new double[][]{
{3472795.9, 5454247.85},
{3472868.22, 5454247.85},
{3472868.22, 5454150.53},
{3472795.9, 5454150.53}};
// Send trigger if the user enters or exits the given region
vrmi.addRegionTrigger( this, true, region, true, true );
}
/**
* Main method. VRMI test method. Creates a new map display, and installs
* VRMITest with several triggers that print diagnostical information to
* stdout.
*
*@param argv User arguments (ignored).
*@exception Exception Exception
*/
public static void main( String argv[] ) throws Exception
{
// create a new GPS map form
MapView mv = new MapView();
mv.show();
// create our VRMITest callback class
VRMITest vt = new VRMITest( mv.gpsDriver );
}
/**
* Trigger callback from VRMI. Handles all the different callbacks.
*
*@param ti Parameter
*@param gi Parameter
*/
public void trigger( TriggerInfo ti, GPSInfo gi )
{
System.out.println( "Trigger id=" + ti.id + " at X=" + gi.X + ", Y=" + gi.Y );
if ( ti instanceof RegionTriggerInfo )
{
RegionTriggerInfo rt = ( RegionTriggerInfo ) ti;
System.out.print( "Region Trigger " );
if ( rt.inside )
{
System.out.println( "entered." );
}
else
{
System.out.println( "exited." );
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -