View Javadoc

1   /*
2    * Copyright 2010 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id: VisitorPanel.java 5462 2011-05-10 20:23:49Z pether $
17   *  $HeadURL: https://cia.svn.sourceforge.net/svnroot/cia/trunk/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/page/user/VisitorPanel.java $
18  */
19  package com.hack23.cia.web.impl.ui.page.user;
20  
21  import java.awt.geom.Point2D;
22  
23  import org.vaadin.hezamu.googlemapwidget.GoogleMap;
24  import org.vaadin.hezamu.googlemapwidget.GoogleMap.MapControl;
25  
26  import com.hack23.cia.service.api.GeoIpCountryService.IpLocation;
27  import com.hack23.cia.web.impl.ui.common.ApplicationUserStateHolder;
28  import com.hack23.cia.web.impl.ui.page.common.panel.AbstractPanel;
29  import com.vaadin.Application;
30  import com.vaadin.terminal.gwt.server.WebApplicationContext;
31  import com.vaadin.terminal.gwt.server.WebBrowser;
32  import com.vaadin.ui.GridLayout;
33  import com.vaadin.ui.Label;
34  import com.vaadin.ui.VerticalLayout;
35  
36  /**
37   * The Class VisitorPanel.
38   */
39  public final class VisitorPanel extends AbstractPanel {
40  
41  	/** The connent. */
42  	private final VerticalLayout content = new VerticalLayout();
43  
44  	/** The Constant serialVersionUID. */
45  	private static final long serialVersionUID = 1L;
46  
47  	/**
48  	 * Instantiates a new visitor panel.
49  	 */
50  	public VisitorPanel() {
51  		super();
52  		final WebBrowser browser = ((WebApplicationContext) ((Application) getUserState()).getContext()).getBrowser();
53  		final IpLocation location = getUserState().getApplicationManager().getGeoIpCountryService().getLocation(browser.getAddress());
54  		setContent(content);
55  		content.setSizeFull();
56  		content.setSpacing(true);
57  		content.setMargin(true);
58  
59  		final GridLayout gridLayout = new GridLayout(2,1);
60  		content.addComponent(gridLayout);
61  		gridLayout.setSizeFull();
62  
63  		final VerticalLayout details =new VerticalLayout();
64  		details.addComponent(new Label(translateFromEnglish("url") +":" + ((Application) getUserState()).getURL()));
65  		details.addComponent(new Label(translateFromEnglish("ip") +":" + browser.getAddress()));
66  		details.addComponent(new Label(translateFromEnglish("browser") +":" + browser.getBrowserApplication()));
67  		details.addComponent(new Label(translateFromEnglish("screen height") +":" + browser.getScreenHeight()));
68  		details.addComponent(new Label(translateFromEnglish("screen width") +":" + browser.getScreenWidth()));
69  		details.addComponent(new Label(translateFromEnglish("locale") +":" + browser.getLocale()));
70  
71  
72  		if (location != null) {
73  			details.addComponent(new Label(translateFromEnglish("City") +":" + location.getCity()));
74  			details.addComponent(new Label(translateFromEnglish("Region") +":" + location.getRegion()));
75  			details.addComponent(new Label(translateFromEnglish("Country") +":" + location.getCountryName()));
76  			details.addComponent(new Label(translateFromEnglish("Country code") +":" + location.getCountryCode()));
77  			details.addComponent(new Label(translateFromEnglish("Latitude") +":" + location.getLatitude()));
78  			details.addComponent(new Label(translateFromEnglish("Longitude") +":" + location.getLongitude()));
79  			gridLayout.addComponent(details, 0, 0,0,0);
80  			details.setSizeFull();
81  
82  			final GoogleMap googleMap = new GoogleMap((Application) ApplicationUserStateHolder.getUserState(),new Point2D.Double(location.getLongitude(),location.getLatitude()),8,"ABQIAAAAagA4tNdqcS8SXcZ_cgTm_RQivw8bcKxPPx7tIHHiFwHV7JsBShRkP80wfGiF4WJMBTHoFKIMAx_ohg");
83  			gridLayout.addComponent(googleMap,1,0,1,0);
84  			googleMap.addControl(MapControl.MenuMapTypeControl);
85  
86  			googleMap.setSizeFull();
87  
88  		} else {
89  			gridLayout.addComponent(details, 0, 0,1,0);
90  			details.setSizeFull();
91  		}
92  
93  		setCaption(translateFromEnglish("Visitor info"));
94  	}
95  
96  }