001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030/** 031 * 032 */ 033package org.openimaj.demos.campusview; 034 035import java.awt.Color; 036import java.awt.Font; 037import java.awt.GridBagConstraints; 038import java.awt.GridBagLayout; 039 040import javax.swing.BorderFactory; 041import javax.swing.JLabel; 042import javax.swing.JPanel; 043 044import org.openimaj.hardware.gps.GPSSerialReader; 045 046/** 047 * @author David Dupplaw (dpd@ecs.soton.ac.uk) 048 * 049 * @created 13 Jul 2011 050 */ 051public class GPSPositionComponent extends JPanel 052{ 053 /** */ 054 private static final long serialVersionUID = 1L; 055 056 /** The GPS device */ 057 private GPSSerialReader gps = new GPSSerialReader( "/dev/cu.usbserial" ); 058 059 private JLabel latLabel = null; 060 private JLabel longLabel = null; 061 062 /** 063 * Default constructor 064 */ 065 public GPSPositionComponent() 066 { 067 new Thread( gps ).start(); 068 setLayout( new GridBagLayout() ); 069 // setBorder( BorderFactory.createBevelBorder(BevelBorder.LOWERED) ); 070 071 latLabel = new JLabel( "No GPS" ); 072 latLabel.setFont( new Font( "Courier", Font.BOLD, 16 ) ); 073 latLabel.setForeground( Color.white ); 074 latLabel.setOpaque( true ); 075 latLabel.setBackground( Color.black ); 076 latLabel.setBorder( BorderFactory.createEmptyBorder( 4,4,4,4 ) ); 077 078 longLabel = new JLabel( "No GPS" ); 079 longLabel.setFont( new Font( "Courier", Font.BOLD, 16 ) ); 080 longLabel.setForeground( Color.white ); 081 longLabel.setBackground( Color.black ); 082 longLabel.setOpaque( true ); 083 longLabel.setBorder( BorderFactory.createEmptyBorder( 4,4,4,4 ) ); 084 085 GridBagConstraints gbc = new GridBagConstraints(); 086 gbc.gridx = gbc.gridy = 0; 087 gbc.fill = GridBagConstraints.BOTH; 088 gbc.weightx = gbc.weighty = 1; 089 090 add( latLabel, gbc ); 091 gbc.gridy++; 092 add( longLabel, gbc ); 093 094 new Thread( new Runnable() 095 { 096 @Override 097 public void run() 098 { 099 while( true ) 100 { 101 try 102 { 103 Thread.sleep( 1000 ); 104 } 105 catch( InterruptedException e ) 106 { 107 e.printStackTrace(); 108 } 109 110 latLabel.setText( "Latitude : "+gps.getLatitude() ); 111 longLabel.setText( "Longitude: "+gps.getLongitude() ); 112 } 113 } 114 }).start(); 115 } 116 117 /** 118 * @return the gps reader 119 */ 120 public GPSSerialReader getGPS() 121 { 122 return gps; 123 } 124}