📄 mapview.java
字号:
void updateGPSInfo( double gaussx, double gaussy )
{
if ( !followGPS )
{
GPSInfo gi = new GPSInfo();
NMEA.infiniteAge( gi );
gi.X = gaussx;
//Double.parseDouble( textGaussX.getText() );
gi.Y = gaussy;
//Double.parseDouble( textGaussY.getText() );
XY gk = convertToLL( gi.X, gi.Y );
gi.latitude = gk.x;
gi.longitude = gk.y;
gi.latitudeAge = gi.longitudeAge = gi.XAge = gi.YAge = 0;
gi.courseOverGround = dirPanel.getDirection();
gi.courseOverGroundAge = 0;
gi.speedOverGround = 0;
gi.speedOverGroundAge = 0;
gi.GPSModel = "GPS Simulator V0.1";
gi.GPSModelAge = 0;
gi.EPE = gi.HPE = gi.VPE = 10.0;
gi.horDilution = gi.verDilution = 1.0;
gi.EPEAge = gi.HPEAge = gi.VPEAge = 0;
gi.horDilutionAge = gi.verDilutionAge = 0;
gpsDriver.setSimulationInfo( gi );
}
}
//GEN-LAST:event_jButton6ActionPerformed
XY addDelta( double dx, double dy )
{
XY result = COORD.convertToGaussKrueger( lat, lon );
result.x += dx;
result.y += dy;
return COORD.convertToLatLong( result.x, result.y );
}
void moveMap( double dx, double dy )
{
try
{
double f = ( 250 * zoom ) / 5000;
XY pos = addDelta( f * dx, f * dy );
setLocation( pos.x, pos.y, zoom );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the FormEditor.
*/
private void initComponents()
{
//GEN-BEGIN:initComponents
jMenuBar1 = new javax.swing.JMenuBar();
menuFile = new javax.swing.JMenu();
menuFileLoad = new javax.swing.JMenuItem();
menuFileSave = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
menuFileExit = new javax.swing.JMenuItem();
menuGPS = new javax.swing.JMenu();
menuGPSSetup = new javax.swing.JMenuItem();
menuLog = new javax.swing.JMenuItem();
menuDisableLog = new javax.swing.JMenuItem();
menuReplayLog = new javax.swing.JMenuItem();
menuCoord = new javax.swing.JMenu();
menuGPSEarthDatum = new javax.swing.JMenu();
jPanelMapContainer = new javax.swing.JPanel();
jPanelNavigate = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jButtonN = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
jButtonW = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jButtonE = new javax.swing.JButton();
jPanel5 = new javax.swing.JPanel();
jButtonS = new javax.swing.JButton();
jPanelZoom = new javax.swing.JPanel();
checkboxFollowGPS = new javax.swing.JCheckBox();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jPanelDirection = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
jPanelLatLong = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
textLatitude = new java.awt.TextField();
textLongitude = new java.awt.TextField();
jPanelGaussKrueger = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
textGaussX = new java.awt.TextField();
textGaussY = new java.awt.TextField();
menuFile.setText( "File" );
menuFileLoad.setText( "Load Position" );
menuFileLoad.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
menuFileLoadActionPerformed( evt );
}
}
);
menuFile.add( menuFileLoad );
menuFileSave.setText( "Save Position" );
menuFileSave.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
menuFileSaveActionPerformed( evt );
}
}
);
menuFile.add( menuFileSave );
menuFile.add( jSeparator1 );
menuFileExit.setText( "Exit" );
menuFileExit.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
menuFileExitActionPerformed( evt );
}
}
);
menuFile.add( menuFileExit );
jMenuBar1.add( menuFile );
menuGPS.setText( "GPS" );
menuGPSSetup.setText( "Setup GPS Receiver" );
menuGPSSetup.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
menuGPSSetupActionPerformed( evt );
}
}
);
menuGPS.add( menuGPSSetup );
menuLog.setText( "Log GPS data to file" );
menuLog.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
menuLogActionPerformed( evt );
}
}
);
menuGPS.add( menuLog );
menuDisableLog.setText( "Disable Logging" );
menuDisableLog.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
menuDisableLogActionPerformed( evt );
}
}
);
menuGPS.add( menuDisableLog );
menuReplayLog.setText( "Replay logfile" );
menuReplayLog.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
menuReplayLogActionPerformed( evt );
}
}
);
menuGPS.add( menuReplayLog );
jMenuBar1.add( menuGPS );
menuCoord.setLabel( "Coordinate System" );
menuCoord.setActionCommand( "menuCoord" );
menuCoord.setText( "Coordinate Settings" );
menuGPSEarthDatum.setToolTipText( "" );
menuGPSEarthDatum.setLabel( "Set GPS Earth Datum" );
menuGPSEarthDatum.setActionCommand( "menuGPSEarthDatum" );
menuGPSEarthDatum.setText( "Set GPS Earth Datum" );
menuCoord.add( menuGPSEarthDatum );
jMenuBar1.add( menuCoord );
getContentPane().setLayout( new java.awt.GridBagLayout() );
java.awt.GridBagConstraints gridBagConstraints1;
setTitle( "GPSManager (C) 2000-2002 U.Walther" );
setDefaultCloseOperation( javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE );
addMouseListener(
new java.awt.event.MouseAdapter() {
public void mouseClicked( java.awt.event.MouseEvent evt )
{
formMouseClicked( evt );
}
}
);
jPanelMapContainer.setLayout( new java.awt.FlowLayout( 1, 0, 0 ) );
jPanelMapContainer.setPreferredSize( new java.awt.Dimension( 512, 384 ) );
jPanelMapContainer.setMinimumSize( new java.awt.Dimension( 512, 384 ) );
jPanelMapContainer.setDoubleBuffered( false );
gridBagConstraints1 = new java.awt.GridBagConstraints();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH;
getContentPane().add( jPanelMapContainer, gridBagConstraints1 );
jPanelNavigate.setLayout( new java.awt.GridLayout( 3, 3 ) );
jPanelNavigate.add( jPanel2 );
jButtonN.setText( "N" );
jButtonN.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
jButtonNActionPerformed( evt );
}
}
);
jPanelNavigate.add( jButtonN );
jPanelNavigate.add( jPanel3 );
jButtonW.setLabel( "E" );
jButtonW.setText( "W" );
jButtonW.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
jButtonWActionPerformed( evt );
}
}
);
jPanelNavigate.add( jButtonW );
jPanelNavigate.add( jPanel4 );
jButtonE.setText( "E" );
jButtonE.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
jButtonEActionPerformed( evt );
}
}
);
jPanelNavigate.add( jButtonE );
jPanelNavigate.add( jPanel5 );
jButtonS.setText( "S" );
jButtonS.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
jButtonSActionPerformed( evt );
}
}
);
jPanelNavigate.add( jButtonS );
gridBagConstraints1 = new java.awt.GridBagConstraints();
gridBagConstraints1.insets = new java.awt.Insets( 0, 5, 0, 5 );
getContentPane().add( jPanelNavigate, gridBagConstraints1 );
jPanelZoom.setLayout( new java.awt.GridLayout( 3, 1 ) );
checkboxFollowGPS.setText( "Follow GPS" );
checkboxFollowGPS.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
checkboxFollowGPSActionPerformed( evt );
}
}
);
jPanelZoom.add( checkboxFollowGPS );
jButton6.setText( "In" );
jButton6.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
jButton6ActionPerformed( evt );
}
}
);
jPanelZoom.add( jButton6 );
jButton7.setText( "Out" );
jButton7.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
jButton7ActionPerformed( evt );
}
}
);
jPanelZoom.add( jButton7 );
gridBagConstraints1 = new java.awt.GridBagConstraints();
gridBagConstraints1.insets = new java.awt.Insets( 0, 0, 0, 5 );
getContentPane().add( jPanelZoom, gridBagConstraints1 );
jPanelDirection.setLayout( new java.awt.BorderLayout() );
jLabel4.setText( "Direction" );
jPanelDirection.add( jLabel4, java.awt.BorderLayout.NORTH );
gridBagConstraints1 = new java.awt.GridBagConstraints();
gridBagConstraints1.insets = new java.awt.Insets( 0, 0, 0, 5 );
getContentPane().add( jPanelDirection, gridBagConstraints1 );
jPanelLatLong.setLayout( new java.awt.GridLayout( 3, 1 ) );
jLabel2.setText( "Long/Lat" );
jPanelLatLong.add( jLabel2 );
textLatitude.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
textLatitudeActionPerformed( evt );
}
}
);
jPanelLatLong.add( textLatitude );
textLongitude.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
textLongitudeActionPerformed( evt );
}
}
);
jPanelLatLong.add( textLongitude );
gridBagConstraints1 = new java.awt.GridBagConstraints();
gridBagConstraints1.insets = new java.awt.Insets( 0, 0, 0, 5 );
getContentPane().add( jPanelLatLong, gridBagConstraints1 );
jPanelGaussKrueger.setLayout( new java.awt.GridLayout( 3, 1 ) );
jLabel3.setText( "Gauss-Kr\u00fcger" );
jPanelGaussKrueger.add( jLabel3 );
textGaussX.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
textGaussXActionPerformed( evt );
}
}
);
jPanelGaussKrueger.add( textGaussX );
textGaussY.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
textGaussYActionPerformed( evt );
}
}
);
jPanelGaussKrueger.add( textGaussY );
gridBagConstraints1 = new java.awt.GridBagConstraints();
gridBagConstraints1.insets = new java.awt.Insets( 0, 0, 0, 5 );
getContentPane().add( jPanelGaussKrueger, gridBagConstraints1 );
setJMenuBar( jMenuBar1 );
}
//GEN-END:initComponents
private void jButtonEActionPerformed( java.awt.event.ActionEvent evt )
{
//GEN-FIRST:event_jButtonEActionPerformed
moveMap( 1, 0 );
}
//GEN-LAST:event_jButtonEActionPerformed
private void jButtonWActionPerformed( java.awt.event.ActionEvent evt )
{
//GEN-FIRST:event_jButtonWActionPerformed
moveMap( -1, 0 );
}
//GEN-LAST:event_jButtonWActionPerformed
private void jButtonSActionPerformed( java.awt.event.ActionEvent evt )
{
//GEN-FIRST:event_jButtonSActionPerformed
moveMap( 0, -1 );
}
//GEN-LAST:event_jButtonSActionPerformed
private void jButtonNActionPerformed( java.awt.event.ActionEvent evt )
{
//GEN-FIRST:event_jButtonNActionPerformed
moveMap( 0, 1 );
}
//GEN-LAST:event_jButtonNActionPerformed
private void formMouseClicked( java.awt.event.MouseEvent evt )
{
//GEN-FIRST:event_formMouseClicked
// if GPS driver data is displayed, don't change position manually!!!
if ( checkboxFollowGPS.isSelected() )
{
return;
}
// if there is still a movement running, stop it!!
if ( simulateMovement != null )
{
// there is still a thread running, kill it
simulateMovement.stop();
simulateMovement = null;
}
boolean simulate = false;
if ( ( evt.getModifiers() & java.awt.event.MouseEvent.BUTTON3_MASK ) > 0 )
{
// right click --> simulate walk
int opt = JOptionPane.showOptionDialog( this,
"Do you want to simulate the movement to the\n" +
"point you clicked at?\n" +
"The current speed setting is " + simSpeed + " [meters/second]",
"Simulate Movement",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{"Simulate",
"Setup",
"Set w/o Sim",
"Cancel"},
"Simulate"
);
if ( opt == 3 )
{
// cancel
return;
}
if ( opt == 1 )
{
// change settings
String in = JOptionPane.showInputDialog( this, "Input the speed to use for the movement\n" +
"[in meters/second]" );
simSpeed = Double.parseDouble( in );
}
if ( opt != 2 )
{
XY gk = convertToGK( lat, lon );
simX = gk.x;
simY = gk.y;
simulate = true;
}
}
Point _rpos = getRootPane().getLocation();
Point _cpos = getContentPane().getLocation();
Point _pos = jPanelMapContainer.getLocation();
_pos.translate( _rpos.x, _rpos.y );
_pos.translate( _cpos.x, _cpos.y );
Point _pos2 = evt.getPoint();
_pos2.translate( -_pos.x, -_pos.y );
int x = _pos2.x;
int y = _pos2.y;
// int y0 = this.getContentPane().getBounds().y + jMenuBar1.getBounds().height;
// y -= y0;
Rectangle r = mapImg.getBounds();
Point loc = mapImg.getLocationPixels();
// click on map: change location (only if non follow-GPS mode)
if ( r.contains( x, y ) && !checkboxFollowGPS.isSelected() )
{
int dx = x - r.x - loc.x;
int dy = -( y - r.y - loc.y );
XY pos = convertToGK( lat, lon );
pos.x += mapImg.metersPerPixel() * dx;
pos.y += mapImg.metersPerPixel() * dy;
XY pos2 = convertToLL( pos.x, pos.y );
if ( simulate )
{
// calculate the sim parameters
double xx = simDX = pos.x - simX;
double yy = simDY = pos.y - simY;
simT = 0.0;
double l = Math.sqrt( xx * xx + yy * yy );
simDT = 1.0 / ( l / simSpeed );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -