KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > javaee > blueprints > mapviewer > MapBean


1 /*
2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at:
3 * http://developer.sun.com/berkeley_license.html
4 * $Id: MapBean.java,v 1.1 2006/06/20 00:08:59 inder Exp $
5 */

6 /*
7  * MapBean.java
8  *
9  * Created on February 1, 2006, 1:36 PM
10  *
11  * To change this template, choose Tools | Template Manager
12  * and open the template in the editor.
13  */

14
15 package com.sun.javaee.blueprints.mapviewer;
16
17 import com.sun.j2ee.blueprints.ui.geocoder.GeoCoder;
18 import com.sun.j2ee.blueprints.ui.geocoder.GeoPoint;
19 import com.sun.j2ee.blueprints.ui.mapviewer.MapMarker;
20 import com.sun.j2ee.blueprints.ui.mapviewer.MapPoint;
21 import javax.faces.component.UICommand;
22 import javax.faces.component.UIInput;
23 import javax.faces.component.UIForm;
24
25 /**
26  *
27  * @author basler
28  */

29 public class MapBean {
30
31     private MapMarker mapMarker=new MapMarker();
32     private MapPoint mapPoint=new MapPoint();
33     private String JavaDoc location="4150 Network Circle, Santa Clara, CA 95054", foundLocation="", info="Sun's Santa Clara Campus";
34     private String JavaDoc mapReady="true", proxyHost="";
35     private double foundLatitude=0.0d, foundLongitude=0.0d;
36     private int proxyPort=0;
37
38     /** Creates a new instance of MapBean */
39     public MapBean() {
40     }
41     
42     
43     
44     // index.jsp fields
45
public void setProxyHost(String JavaDoc proxyHost) {
46         this.proxyHost=proxyHost;
47     }
48     public String JavaDoc getProxyHost() {
49         return this.proxyHost;
50     }
51     
52     public void setProxyPort(int proxyPort) {
53         this.proxyPort=proxyPort;
54     }
55     public int getProxyPort() {
56         return this.proxyPort;
57     }
58     
59     public void setMapReady(String JavaDoc mapReady) {
60         this.mapReady=mapReady;
61     }
62     public String JavaDoc getMapReady() {
63         return this.mapReady;
64     }
65     
66     public void setInfo(String JavaDoc info) {
67         this.info=info;
68     }
69     public String JavaDoc getInfo() {
70         return this.info;
71     }
72     
73     public void setLocation(String JavaDoc location) {
74         this.location=location;
75     }
76     public String JavaDoc getLocation() {
77         return this.location;
78     }
79     
80     public void setFoundLocation(String JavaDoc foundLocation) {
81         this.foundLocation=foundLocation;
82     }
83     public String JavaDoc getFoundLocation() {
84         return this.foundLocation;
85     }
86
87     public void setFoundLatitude(double foundLatitude) {
88         this.foundLatitude=foundLatitude;
89     }
90     public double getFoundLatitude() {
91         return this.foundLatitude;
92     }
93     
94     public void setFoundLongitude(double foundLongitude) {
95         this.foundLongitude=foundLongitude;
96     }
97     public double getFoundLongitude() {
98         return this.foundLongitude;
99     }
100     
101     
102     
103     
104    // map.jsp fields
105
public void setMapMarker(MapMarker mapMarker) {
106         this.mapMarker=mapMarker;
107     }
108     public MapMarker getMapMarker() {
109         return this.mapMarker;
110     }
111             
112     public void setMapPoint(MapPoint mapPoint) {
113         this.mapPoint=mapPoint;
114     }
115     public MapPoint getMapPoint() {
116         return this.mapPoint;
117     }
118             
119     public MapMarker[] getLocations() {
120         return new MapMarker[]{this.mapMarker};
121     }
122
123     
124     
125     public String JavaDoc findAction() {
126         System.out.println("in findAction - " + getLocation());
127         // Process the button click action. Return value is a navigation
128
// case name where null will return to the same page.
129
GeoCoder geoCoder=new GeoCoder();
130         if(!getProxyHost().equals("")) {
131             // set proxy host and port if it exists
132
// NOTE: This requires write permissions for java.util.PropertyPermission to be granted
133
System.out.println("Setting proxy to " + getProxyHost() + ":" + getProxyPort() + ". Make sure server.policy is updated to allow setting System Properties");
134             geoCoder.setProxyHost(getProxyHost());
135             geoCoder.setProxyPort(getProxyPort());
136         }
137         
138         // use component to get points based on location (this uses Yahoo's map service
139
GeoPoint points[]=geoCoder.geoCode(location);
140         if ((points == null) || (points.length < 1)) {
141              setFoundLocation("No geographic points matched this location OR the Yahoo server can't be reached, please try again");
142             return null;
143         }
144         
145         // more that one point return, just tell user in log
146
if (points.length > 1) {
147            System.out.println("Matched " + points.length + " locations, taking the first one");
148         }
149         
150         // set values to be shown on main lookup page
151
setFoundLocation(points[0].toString());
152         setFoundLatitude(points[0].getLatitude());
153         setFoundLongitude(points[0].getLongitude());
154         
155         // Set up markers for the center and information window
156
mapMarker.setLatitude(points[0].getLatitude());
157         mapMarker.setLongitude(points[0].getLongitude());
158         mapMarker.setMarkup(changeSpaces(points[0].toString()) + "<br>" + changeSpaces(getInfo()));
159
160         // set center point for map
161
mapPoint.setLatitude(points[0].getLatitude());
162         mapPoint.setLongitude(points[0].getLongitude());
163         
164         // enable the "Map It" button so user can go to map page
165
mapReady="false";
166         
167         // return null so navigation will stay on main lookup page
168
return null;
169     }
170     
171
172     public String JavaDoc mapAction() {
173         // return map so navigation will go to map page
174
return "map";
175     }
176     
177     public String JavaDoc changeSpaces(String JavaDoc text) {
178         return text.replaceAll(" ", "&nbsp;");
179     }
180         
181 }
182
Popular Tags