August 28, 2008

Pages


Search Site


Topics


Useful Links

Blogs I Read


Archives

Sending Growl Notifications With Flex Via AIR & Merapi

August 26 2008 by Andrew Powell

The other day, I showed you how to talk to a Garmin GPS with Flex (AIR), Java, and Merapi. Well, today I'm back to talk to you about how to leverage the Java APIs to the growl notification service via Merapi and Flex. Growl is a notification service for OS X that a lot of applications are starting to make use of these days. They have a SDK which includes Java libraries. Using Merapi, you can leverage these libraries and send true Growl notifications directly from AIR applications. Enjoy the screencast below and feel free to drop me a line in the comments if you have any questions.

Posted in Java | Flex | General | Universal Mind | 1 comments

Live GPS Visualizations With AIR & Merapi

August 23 2008 by Andrew Powell

So, my co-worked Adam Flater started up the Merapi Project a while back and asked me to contribute. Up until now, the only thing I've had time to contribute was the name. Well, after seeing the cool stuff that he and Jordan were doing at 360|Flex, I decided it was time to step up to the plate, get my shit together, and produce my own kick-ass Merapi demo.

Anyone who has been following the blogs knows that we at UM are real big into GIS and data visualization. Don't believe me? Take a look at SpatialKey to see what we can do with it.

I recorded a screencast where I walk you through the setups and the code of the application:

Java Code:

package com.universalmind.merapi;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import com.diddlebits.gpslib4j.GPS;
import com.diddlebits.gpslib4j.IDate;
import com.diddlebits.gpslib4j.IGPSlistener;
import com.diddlebits.gpslib4j.IPosition;
import com.diddlebits.gpslib4j.ITime;
import com.diddlebits.gpslib4j.Position;
import com.diddlebits.gpslib4j.PositionRadians;
import com.diddlebits.gpslib4j.Garmin.GarminGPS;
import merapi.Bridge;
import merapi.MerapiObject;
import merapi.messages.Message;
public class GPSReader extends MerapiObject implements IGPSlistener{
   GPS gps;      
   Position position = null;
   IPosition current = null;
   BufferedInputStream input;
   BufferedOutputStream output;
   
   public Bridge bridge;
   
   public static void main( String[] args )
   {
      
      new GPSReader();
   }
   
   public GPSReader()
   {
      super();
      
      bridge = Bridge.getInstance();
      
      CommPort port;
      
      try {
         port = CommPortIdentifier.getPortIdentifier("/dev/tty.USA19H1d1P1.1").open("GPSReader", 3000);
      } catch (NoSuchPortException e) {
         System.out.println("/dev/tty.USA19H1d1P1.1 not found!");
         return;
      } catch (PortInUseException e) {
         System.out.println("Port already in use by " + e.currentOwner);
         return;
      }
      
      try {
         input = new BufferedInputStream(port.getInputStream());
         output = new BufferedOutputStream(port.getOutputStream());         
      } catch (IOException e) {
         System.out.println("Error opening /dev/tty.USA19H1d1P1.1");
         return;
      }      
            
      gps = new GarminGPS(input, output);
      gps.setAutoTransmit(true);
      gps.addGPSlistener(this);
      
   }
   
public double getLat() {return __lat;}
   public void setLat(double lat) {
      this.__lat = lat;
   }
   public double getLon() {return __lon;}
   public void setLon(double lon) {
      this.__lon = lon;
   }
   public String getTime() {return __time;}
   public void setTime(String time) {
      this.__time = time;
   }
   public String getDate() {return __date;}
   public void setDate(String date) {
      this.__date = date;
   }
   
   public void dateReceived(IDate d) {
      String dateString = d.getMonth() + "/" + d.getDay() + "/" + d.getYear();
      System.out.println(dateString);
      this.setDate(dateString);
   }
   public void positionReceived(IPosition pos) {
      current = pos;
      this.setLat(toDecimalDegrees(current.getLatitude()));
      this.setLon(toDecimalDegrees(current.getLongitude()));
      Message message = new Message();
      GPSPoint point = new GPSPoint();
      point.lat = this.getLat();
      point.lon = this.getLon();
      point.date = this.getDate();
      point.time = this.getTime();
      message.setData(point);
      try {
         bridge.sendMessage(message);
      } catch (Exception e) {
         
         System.out.println(e.getMessage());
      }
      
   }
   public void timeReceived(ITime t) {
      String timeString = t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
      this.setTime(timeString);
      System.out.println(timeString);
   }
   
   private double toDecimalDegrees(PositionRadians rads){
      return Math.toDegrees(rads.getRadians());
   }
   
   private double __lat = 0;
private double __lon = 0;
private String __time = "";
private String   __date = "";
}

Flex Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onInitView(event)" xmlns:merapi="merapi.*">
   <mx:Script>
      <![CDATA[
         import com.mapquest.tilemap.controls.ViewControl;
         import com.mapquest.tilemap.controls.LargeZoomControl;
         import com.mapquest.tilemap.pois.Poi;
         import com.universalmind.merapi.GPSPoint;
         import merapi.messages.IMessage;
         import com.mapquest.PointLL;
         import mx.rpc.events.ResultEvent;

         [Bindable] private var _mapquestKey:String = "yourMQKEY";               
         private var _lrgZoomControl:LargeZoomControl = new LargeZoomControl;
         private   var _viewControl:ViewControl = new ViewControl();
         
         private function onInitView(e : Event ) : void
         {
            
            
            //add map controls            _lrgZoomControl.setBackgroundColor(0xA7C58E);
            _lrgZoomControl.setBorderColor(0xffffff);
            _lrgZoomControl.setBorderAlpha(1);
            _lrgZoomControl.setBackgroundEllipseWidth(0);            
            _lrgZoomControl.setBackgroundEllipseHeight(0);
            _lrgZoomControl.setBackgroundAlpha(.9);
            
            this.map.addControl(_lrgZoomControl);
          this.map.addControl(_viewControl);
         }
         
         private function handleResult( e : ResultEvent ) : void
         {
            var gpsPoint:GPSPoint = e.result.data as GPSPoint
            var point:PointLL = new PointLL(gpsPoint.lat,gpsPoint.lon);
            this.map.setCenter(point);   
            var poi:Poi = new Poi(point);
            this.map.addPoi(poi);
         }   
      ]]>
   </mx:Script>
   
   <merapi:BridgeInstance id="bridge" result="handleResult( event )" />
   
   <mq:TilemapComponent id="map" key="{this._mapquestKey}" zoom="3" width="100%" height="100%" xmlns:mq="com.mapquest.tilemap.*" />

</mx:WindowedApplication>

Posted in MapQuest | Java | Flex | General | Adobe | Universal Mind | MapMyPix | Air | 3 comments

360|Flex Session Preview: Implementing BlazeDS

August 17 2008 by Andrew Powell

Excited about BlazeDS, but not really sure what it means for you?  Are you a Java developer coming to Flex who wants to learn how to connect your services to Flex?  Want to see a new spin on the ubiquitous chat application?  Come to my 360|Flex session, Implementing BlazeDS, and you'll get all that and more.  This session is the first of a three-part "Flex/Java Track" that you will get at 360|Flex.  Major topics covered will be:  Remote Objects, Messaging, Integrating Spring & Hibernate, & Binary Remoting without BlazeDS.  Stop on by Monday at 4:00PM if you're interested in learning more.

Posted in LiveCycle ES | Flex | General | Conferences | BlazeDS | JMS | Spring | Adobe | Universal Mind | Hibernate | Hessian | Speaking | 0 comments

Index Your Object Domain Model With Hibernate Search

August 15 2008 by Andrew Powell

Hibernate Search is an addition to the powerful ORM, Hibernate, that allows you to perform full text searches against your domain model.  Under the hood, it's powered by Apache Lucene.  How does it work?  Well, Hibernate Search is smart enough to index your objects as you insert and update your data.  On a delete, it will remove the data from the index.  All this happens transparently.      

There are a few requirements, first is JDK 5, the second is the Hibernate core.  All configuration for Hibernate Search is done via annotations ( I think this is where all the Hibernate config is heading ), so there's no need for lines and lines of XML configs.

Go download it, give it a try and see what you can do with full-text searching of your domain model.

Posted in Java | General | BlazeDS | Spring | Universal Mind | Hibernate | 1 comments

Hibernate: Annotations or XML Mapping?

August 15 2008 by Andrew Powell

Until recently, I've always used the XML mapping files to define my persistence model with Hibernate. I was not real keen on the idea of using meta to define persistence in the objects themselves via annotations. However, I decided to give it a shot recently. My main argument had always been that by using the XML mapping, my persistent objects are not tied to Hibernate, exclusively. When I stopped to think about it though, one thought really hit me hard: I don't use any other ORM for my Java code. Why would it matter if the meta for mappings is in the code?

This being said, I wanted to pose a question: Is there a benefit to using annotations over XML mapping (other than JVM compatibility)? Your thoughts in the comments, please.

Posted in Java | ColdFusion | Spring | Universal Mind | Hibernate | XML | 2 comments