📄 gpssetup.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.*;
/**
* GPS setup dialog. Opened from class {@link MapView}.
*
*@author walther
*@version 1.0
*/
public class GPSSetup extends javax.swing.JDialog {
boolean cancelled;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JButton jButtonAutodetect;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
/**
* Creates new form GPSSetup
*
*@param parent Parameter
*@param modal Parameter
*/
public GPSSetup( java.awt.Frame parent, boolean modal )
{
super( parent, modal );
initComponents();
pack();
setSize( 300, 220 );
int i;
int[] bl = GPSDriver.getBaudrateList();
for ( i = 0; i < bl.length; i++ )
{
jComboBox1.addItem( bl[i] + "" );
}
GPSDriver.Configuration cfg = MapView.gpsDriver.getConfiguration();
jLabel1.setText( "Current configuration: " + cfg.port + ", " + cfg.baudRate );
String[] pl = GPSDriver.getPortList();
for ( i = 0; i < pl.length; i++ )
{
jComboBox2.addItem( pl[i] );
}
selectConfiguration( cfg );
cancelled = true;
setLocationRelativeTo( parent );
}
//GEN-LAST:event_closeDialog
/**
*@param args the command line arguments
*/
public static void main( String args[] )
{
new GPSSetup( new javax.swing.JFrame(), true ).show();
}
/**
* Retrieve the GPS configuration settings according to the dialog settings.
*
*@return GPS configuration.
*/
public GPSDriver.Configuration getConfiguration()
{
if ( cancelled == true )
{
return null;
}
String s1 = ( String ) jComboBox1.getSelectedItem();
String s2 = ( String ) jComboBox2.getSelectedItem();
GPSDriver.Configuration c = new GPSDriver.Configuration();
c.port = s1;
c.baudRate = Integer.parseInt( s2 );
return c;
}
//GEN-LAST:event_jButtonAutodetectActionPerformed
void selectConfiguration( GPSDriver.Configuration cfg )
{
if ( cfg != null )
{
int i;
String[] pl = GPSDriver.getPortList();
for ( i = 0; i < pl.length; i++ )
{
if ( pl[i].equals( cfg.port ) )
{
break;
}
}
if (i==pl.length) i=0;
jComboBox2.setSelectedIndex( i );
int[] bl = GPSDriver.getBaudrateList();
for ( i = 0; i < bl.length; i++ )
{
if ( bl[i] == cfg.baudRate )
{
break;
}
}
if (i==bl.length) i=0;
jComboBox1.setSelectedIndex( i );
}
}
/**
* 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
jLabel1 = new javax.swing.JLabel();
jButtonAutodetect = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jComboBox1 = new javax.swing.JComboBox();
jComboBox2 = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
getContentPane().setLayout( null );
setTitle( "Setup GPS Receiver" );
setResizable( false );
addWindowListener(
new java.awt.event.WindowAdapter() {
public void windowClosing( java.awt.event.WindowEvent evt )
{
closeDialog( evt );
}
}
);
jLabel1.setVerticalAlignment( javax.swing.SwingConstants.TOP );
jLabel1.setText( "Current configuration:" );
getContentPane().add( jLabel1 );
jLabel1.setBounds( 10, 0, 280, 30 );
jButtonAutodetect.setText( "Auto-detect configuration" );
jButtonAutodetect.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
jButtonAutodetectActionPerformed( evt );
}
}
);
getContentPane().add( jButtonAutodetect );
jButtonAutodetect.setBounds( 10, 100, 280, 30 );
jButton2.setLabel( "jButton2" );
jButton2.setText( "Cancel" );
jButton2.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
jButton2ActionPerformed( evt );
}
}
);
getContentPane().add( jButton2 );
jButton2.setLocation( 220, 150 );
jButton2.setSize( jButton2.getPreferredSize() );
jButton1.setLabel( "jButton1" );
jButton1.setText( "OK" );
jButton1.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed( java.awt.event.ActionEvent evt )
{
jButton1ActionPerformed( evt );
}
}
);
getContentPane().add( jButton1 );
jButton1.setLocation( 10, 150 );
jButton1.setSize( jButton1.getPreferredSize() );
getContentPane().add( jComboBox1 );
jComboBox1.setLocation( 160, 70 );
jComboBox1.setSize( jComboBox1.getPreferredSize() );
getContentPane().add( jComboBox2 );
jComboBox2.setLocation( 10, 70 );
jComboBox2.setSize( jComboBox2.getPreferredSize() );
jLabel2.setText( "Comm. port:" );
getContentPane().add( jLabel2 );
jLabel2.setBounds( 10, 40, 120, 20 );
jLabel3.setText( "Bitrate:" );
getContentPane().add( jLabel3 );
jLabel3.setBounds( 160, 40, 110, 20 );
jLabel4.setText( "jLabel4" );
getContentPane().add( jLabel4 );
jLabel4.setBounds( 270, 20, 0, -10 );
}
//GEN-END:initComponents
private void jButtonAutodetectActionPerformed( java.awt.event.ActionEvent evt )
{
//GEN-FIRST:event_jButtonAutodetectActionPerformed
GPSDriver.Configuration cfg = GPSDriver.detect();
selectConfiguration( cfg );
}
private void jButton1ActionPerformed( java.awt.event.ActionEvent evt )
{
//GEN-FIRST:event_jButton1ActionPerformed
cancelled = false;
closeDialog( null );
}
//GEN-LAST:event_jButton1ActionPerformed
private void jButton3ActionPerformed( java.awt.event.ActionEvent evt )
{
//GEN-FIRST:event_jButton3ActionPerformed
closeDialog( null );
}
//GEN-LAST:event_jButton3ActionPerformed
private void jButton2ActionPerformed( java.awt.event.ActionEvent evt )
{
//GEN-FIRST:event_jButton2ActionPerformed
cancelled = true;
closeDialog( null );
}
//GEN-LAST:event_jButton2ActionPerformed
/**
* Closes the dialog
*
*@param evt Parameter
*/
private void closeDialog( java.awt.event.WindowEvent evt )
{
//GEN-FIRST:event_closeDialog
setVisible( false );
dispose();
}
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -