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

📄 mapview.java

📁 JavaGPS enables access to GPS devices from any Java application. Provides Java API, NMEA0183 parser,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				if ( simDT > 1.0 )
				{
					simDT = 1.0;
				}

				xx /= l;
				yy /= l;
				double deg = Math.toDegrees( Math.atan2( xx, yy ) );
				if ( deg < 0.0 )
				{
					deg += 360.0;
				}
				dirPanel.setDirection( deg );

				//System.out.println("simX="+simX+" simY="+simY+" simDX="+simDX+" simDY="+simDY+" simDT="+simDT);

				// start simulation thread
				simulateMovement = new Thread( this, "SIM" );
				simulateMovement.start();
			}
			else
			{
				setLocation( pos2.x, pos2.y, zoom );
			}
		}
	}
	//GEN-LAST:event_formMouseClicked


	private void menuReplayLogActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_menuReplayLogActionPerformed

		if ( menuReplayLog.getText().startsWith( "Disable" ) )
		{
			menuReplayLog.setText( "Replay GPS log" );
			/*
		try
		{
		gpsDriver.close();
	} catch (Exception e)
	{}
	try
	{
		gpsDriver.open( gpsConfig );
	}catch (Exception e)
	{}
*/
			gpsDriver.disableLogging();
			gpsDriver.enableHardware();
		}
		else
		{
			JFileChooser chooser = new JFileChooser();

			chooser.setFileFilter(
				new javax.swing.filechooser.FileFilter() {
					public String getDescription()
					{
						return "GPS Log Files";
					}


					public boolean accept( File f )
					{
						return f.isDirectory() || f.getName().endsWith( ".gpslog" );
					}
				} );

//		chooser.setCurrentDirectory( new File(".") );

			String name = null;

			if ( chooser.showOpenDialog( this ) == JFileChooser.APPROVE_OPTION )
			{
				name = chooser.getSelectedFile().getAbsolutePath();
			}
			/*
		try
		{
		gpsDriver.close();
	} catch (Exception e)
	{}
	try
	{
		gpsDriver.open( new FileInputStream( name ) );
	} catch (Exception e)
	{}
*/
			try
			{
				gpsDriver.disableHardware();
				gpsDriver.enableReplay( new FileInputStream( name ) );

				menuReplayLog.setText( "Disable Replay" );
			}
			catch ( Exception e )
			{
				gpsDriver.disableReplay();
				gpsDriver.enableHardware();
			}
		}
	}
	//GEN-LAST:event_menuReplayLogActionPerformed


	private void menuDisableLogActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_menuDisableLogActionPerformed
		gpsDriver.disableLogging();
	}
	//GEN-LAST:event_menuDisableLogActionPerformed


	private void menuLogActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_menuLogActionPerformed

		JFileChooser chooser = new JFileChooser();

		chooser.setFileFilter(
			new javax.swing.filechooser.FileFilter() {
				public String getDescription()
				{
					return "GPS Log files";
				}


				public boolean accept( File f )
				{
					return f.isDirectory() || f.getName().endsWith( ".gpslog" );
				}
			} );

		chooser.setCurrentDirectory( new File( "." ) );

		String name = null;

		if ( chooser.showSaveDialog( this ) == JFileChooser.APPROVE_OPTION )
		{
			name = chooser.getSelectedFile().getAbsolutePath();
			if ( name.endsWith( ".gpslog" ) == false && name.indexOf( '.' ) < 0 )
			{
				name += ".gpslog";
			}
		}

		try
		{
			gpsDriver.enableLogging( new FileOutputStream( name ) );
		}
		catch ( Exception e )
		{
			e.printStackTrace();
		}

	}
	//GEN-LAST:event_menuLogActionPerformed


	private void checkboxFollowGPSActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_checkboxFollowGPSActionPerformed
		// Add your handling code here:
		if ( !checkboxFollowGPS.isSelected() )
		{
			if ( followGPS )
			{
				//followGPS.stop();
				followGPS = false;

				gpsDriver.removeGPSListener( this );

				gpsInfoView.hide();
			}

			jButtonN.setEnabled( true );
			jButtonS.setEnabled( true );
			jButtonE.setEnabled( true );
			jButtonW.setEnabled( true );

			dirPanel.setEnabled( true );

			textLatitude.setEnabled( true );
			textLongitude.setEnabled( true );
			textGaussX.setEnabled( true );
			textGaussY.setEnabled( true );

			mapImg.setDilution( 2.0, 1.5 );
		}
		else
		{
			if ( gpsDriver!=null && gpsDriver.isAlive() )
			{

				gpsDriver.addGPSListener( this );
				followGPS = true;
//				followGPS = new Thread(this, "GPS");
//				followGPS.start();

				gpsInfoView.show();
				gpsInfoView.toFront();
				jButtonN.setEnabled( false );
				jButtonS.setEnabled( false );
				jButtonE.setEnabled( false );
				jButtonW.setEnabled( false );

				dirPanel.setEnabled( false );

				textLatitude.setEnabled( false );
				textLongitude.setEnabled( false );
				textGaussX.setEnabled( false );
				textGaussY.setEnabled( false );
			}
			else
			{
				checkboxFollowGPS.setSelected( false );
			}
		}
	}
	//GEN-LAST:event_checkboxFollowGPSActionPerformed


	private void menuFileExitActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_menuFileExitActionPerformed
		int pressed = JOptionPane.showConfirmDialog( this, "Do you really want to quit?",
				"WhereAmI", JOptionPane.YES_NO_OPTION
				 );
		if ( pressed == 0 )
		{
			this.setVisible( false );
			this.dispose();
			Thread.currentThread().getThreadGroup().stop();
		}

	}
	//GEN-LAST:event_menuFileExitActionPerformed


	private void menuGPSSetupActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_menuGPSSetupActionPerformed
		// Add your handling code here:
		GPSDriver.Configuration current = null;
		if ( MapView.gpsDriver != null )
		{
			try
			{
				current = MapView.gpsDriver.getConfiguration();
				MapView.gpsDriver.close();
			}
			catch ( Exception e )
			{
			}
		}

		JDialog gpsSetup = new GPSSetup( this, true );
		gpsSetup.show();

		if ( MapView.gpsDriver != null )
		{
			try
			{
				MapView.gpsDriver.open( current );
			}
			catch ( Exception e )
			{
			}
		}

	}
	//GEN-LAST:event_menuGPSSetupActionPerformed


	private void savePosition( String name )
	{
		if ( name != null )
		{
			System.out.println( "Save " + name );

			GPSPosition p = new GPSPosition();
			p.mapLat = p.lat = lat;
			p.mapLon = p.lon = lon;
			p.mapZoom = zoom;
			p.angle = dirPanel.getDirection();

			try
			{
				Config.saveObject( name, p );
			}
			catch ( Exception e )
			{
				e.printStackTrace();
			}
		}
	}


	private void menuFileSaveActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_menuFileSaveActionPerformed
		// Add your handling code here:
		JFileChooser chooser = new JFileChooser();

		chooser.setFileFilter(
			new javax.swing.filechooser.FileFilter() {
				public String getDescription()
				{
					return "GPS Position Files";
				}


				public boolean accept( File f )
				{
					return f.isDirectory() || f.getName().endsWith( ".gpspos" );
				}
			} );

		chooser.setCurrentDirectory( new File( "." ) );

		String name = null;

		if ( chooser.showSaveDialog( this ) == JFileChooser.APPROVE_OPTION )
		{
			name = chooser.getSelectedFile().getAbsolutePath();
			if ( name.endsWith( ".gpspos" ) == false && name.indexOf( '.' ) < 0 )
			{
				name += ".gpspos";
			}
		}

		savePosition( name );

	}
	//GEN-LAST:event_menuFileSaveActionPerformed


	private void loadPosition( String name )
	{
		if ( name != null )
		{
			System.out.println( "Load " + name );

			GPSPosition p = new GPSPosition();

			try
			{
				Config.loadObject( name, p );

				//NMEA.printAll(p);
			}
			catch ( Exception e )
			{
				e.printStackTrace();
			}

			setLocation( p.mapLat, p.mapLon, p.mapZoom );
			dirPanel.setDirection( p.angle );
		}
	}


	private void menuFileLoadActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_menuFileLoadActionPerformed
		// Add your handling code here:
		JFileChooser chooser = new JFileChooser();

		chooser.setFileFilter(
			new javax.swing.filechooser.FileFilter() {
				public String getDescription()
				{
					return "GPS Position Files";
				}


				public boolean accept( File f )
				{
					return  f.isDirectory() || f.getName().endsWith( ".gpspos" );
				}
			} );

		chooser.setCurrentDirectory( new File( "." ) );

		String name = null;

		if ( chooser.showOpenDialog( this ) == JFileChooser.APPROVE_OPTION )
		{
			name = chooser.getSelectedFile().getAbsolutePath();
		}

		loadPosition( name );
	}
	//GEN-LAST:event_menuFileLoadActionPerformed


	private void textGaussYActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_textGaussYActionPerformed
		// Add your handling code here:
		XY res = convertToGK( lat, lon );
		res.y = Double.parseDouble( textGaussY.getText() );
		XY latlon = convertToLL( res.x, res.y );
		setLocation( latlon.x, latlon.y, zoom );
	}
	//GEN-LAST:event_textGaussYActionPerformed


	private void textGaussXActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_textGaussXActionPerformed
		// Add your handling code here:
		XY res = convertToGK( lat, lon );
		res.x = Double.parseDouble( textGaussX.getText() );
		XY latlon = convertToLL( res.x, res.y );
		setLocation( latlon.x, latlon.y, zoom );
	}
	//GEN-LAST:event_textGaussXActionPerformed


	private void textLongitudeActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_textLongitudeActionPerformed
		setLocation( lat, Double.parseDouble( textLongitude.getText() ), zoom );
	}
	//GEN-LAST:event_textLongitudeActionPerformed


	private void textLatitudeActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_textLatitudeActionPerformed
		setLocation( Double.parseDouble( textLatitude.getText() ), lon, zoom );
	}
	//GEN-LAST:event_textLatitudeActionPerformed


	private void jButton7ActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_jButton7ActionPerformed
		//System.out.println("ZoomOut");
		try
		{
			setLocation( lat, lon, zoom * 2 );
		}
		catch ( Exception e )
		{
		}

	}
	//GEN-LAST:event_jButton7ActionPerformed


	private void jButton6ActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_jButton6ActionPerformed
		//System.out.println("ZoomIn");

		try
		{
			setLocation( lat, lon, zoom / 2 );
		}
		catch ( Exception e )
		{
		}
	}


	private void jButton5ActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_jButton5ActionPerformed
		// Add your handling code here:
		//System.out.println("Right");
		moveMap( 1, 0 );
	}
	//GEN-LAST:event_jButton5ActionPerformed


	private void jButton3ActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_jButton3ActionPerformed
		// Add your handling code here:
		//System.out.println("Down");
		moveMap( 0, -1 );
	}
	//GEN-LAST:event_jButton3ActionPerformed


	private void jButton4ActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_jButton4ActionPerformed
		// Add your handling code here:
		//System.out.println("Left");
		moveMap( -1, 0 );
	}
	//GEN-LAST:event_jButton4ActionPerformed


	private void jButton2ActionPerformed( java.awt.event.ActionEvent evt )
	{
		//GEN-FIRST:event_jButton2ActionPerformed
		// Add your handling code here:
		//System.out.println("Up");
		moveMap( 0, 1 );
	}


	/**
	 *  Description of the Class
	 *
	 *@author    walther
	 */
	class GPSPosition {
		// map parameters
		public double mapLat, mapLon, mapZoom;

		// GPS position parameters
		public double lat, lon, height, angle;
	}
	// End of variables declaration//GEN-END:variables

}

⌨️ 快捷键说明

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