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

📄 gpsinfoview.java

📁 JavaGPS enables access to GPS devices from any Java application. Provides Java API, NMEA0183 parser,
💻 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 javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.util.*;
import java.lang.reflect.*;

/**
 *  GPSInfo display window. Opened from class MapView {@link MapView}.
 *
 *@author    walther
 */
public class GPSInfoView extends JFrame {
	GPSInfo gpsInfo;
	Vector content;


	GPSInfoView()
	{
		super( "GPSInfo Display" );

		content = new Vector();

		gpsInfo = new GPSInfo();

		Class c = gpsInfo.getClass();
		Field[] f = c.getFields();
		getContentPane().setLayout( new BoxLayout( getContentPane(), BoxLayout.Y_AXIS ) );
		Font font = new Font( "courier", Font.PLAIN, 12 );

		for ( int i = 0; i < f.length; i++ )
		{
			try
			{
				String n = f[i].getName();

				if ( !n.endsWith( "Age" ) )
				{
					JLabel l = new JLabel();
					l.setFont( font );
					l.setName( n );
					l.setText( f[i].getName() + "=                    " /*+ f[i].get(gpsInfo)*/ );
					//System.out.println( l.getText() );
					content.addElement( l );
					getContentPane().add( l );
				}
			}
			catch ( Exception e )
			{
			}
		}

		pack();
	}


	/**
	 *  Set the GPSInfo to be displayed.
	 *
	 *@param  info  GPS information to be displayed.
	 */
	public void setGPSInfo( GPSInfo info )
	{
		gpsInfo = info;
		Class c = gpsInfo.getClass();
		Field[] f = c.getFields();
		Component[] co = getContentPane().getComponents();

		for ( int i = 0; i < f.length; i++ )
		{
			try
			{
				String n = f[i].getName();

				if ( n.endsWith( "Age" ) )
				{
					for ( int k = 0; k < co.length; k++ )
					{
						if ( co[k] instanceof JLabel )
						{
							JLabel l = ( JLabel ) co[k];
							if ( n.startsWith( l.getName() ) )
							{
								String t = l.getText();
								int p = t.indexOf( " (" );
								if ( p > 0 )
								{
									t = t.substring( 0, p );
								}
								l.setText( t + " (" + f[i].get( gpsInfo ) + ")" );
							}
						}
					}
				}
				else
				{
					for ( int k = 0; k < co.length; k++ )
					{
						if ( co[k] instanceof JLabel )
						{
							JLabel l = ( JLabel ) co[k];
							if ( n.startsWith( l.getName() ) )
							{
								String t = l.getText();
								int p = t.indexOf( " (" );
								if ( p > 0 )
								{
									t = t.substring( p );
								}
								else
								{
									t = "";
								}
								l.setText( n + "=" + f[i].get( gpsInfo ) + t );
							}
						}
					}

				}
			}
			catch ( Exception e )
			{
			}
		}
	}
}

⌨️ 快捷键说明

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