I can display a map with the notion of bundle
The code for this application is:
for the class: JGoogleMapEditorPan.java
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
/**
* Afficher une carte GoogleMap dans un JEditorPane
* @author fobec 2010
*/
public class JGoogleMapEditorPan extends JEditorPane {
private int zoomFactor = 7;
private String ApiKey = "";
private String roadmap = "roadmap";
public final String viewTerrain = "terrain";
public final String viewSatellite = "satellite";
public final String viewHybrid = "hybrid";
public final String viewRoadmap = "roadmap";
/**
* Constructeur: initialisation du EditorKit
*/
public JGoogleMapEditorPan() {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument htmlDoc = (HTMLDocument) kit.createDefaultDocument();
this.setEditable(false);
this.setContentType("text/html");
this.setEditorKit(kit);
this.setDocument(htmlDoc);
}
/**
* Fixer le zoom
* @param zoom valeur de 0 à 21
*/
public void setZoom(int zoom) {
this.zoomFactor = zoom;
}
/**
* Fixer la clé de developpeur
* @param key APIKey fourni par Google
*/
public void setApiKey(String key) {
this.ApiKey = key;
}
/**
* Fixer le type de vue
* @param roadMap
*/
public void setRoadmap(String roadMap) {
this.roadmap = roadMap;
}
/**
* Afficher la carte d'après des coordonnées GPS
* @param latitude
* @param longitude
* @param width
* @param height
* @throws Exception erreur si la APIKey est non renseignée
*/
public void showCoordinate(String latitude, String longitude, int width,
int height) throws Exception {
this.setMap(latitude, longitude, width, height);
}
/**
* Afficher la carte d'après une ville et son pays
* @param city
* @param country
* @param width
* @param height
* @throws Exception erreur si la APIKey est non renseignée
*/
public void showLocation(String city, String country, int width, int
height) throws Exception {
this.setMap(city, country, width, height);
}
/**
* Assembler l'url et Générer le code HTML
* @param x
* @param y
* @param width
* @param height
* @throws Exception
*/
private void setMap(String x, String y, Integer width, Integer height)
throws Exception {
if (this.ApiKey.isEmpty()) {
throw new Exception("Developper API Key not set !!!!");
}
String url = "http://maps.google.com/maps/api/staticmap?";
url += "center=" + x + "," + y;
url += "&zoom=" + this.zoomFactor;
url += "&size=" + width.toString() + "x" + height.toString();
url += "&maptype=" + this.roadmap;
url += "&markers=color:blue" + x + "," + y;
url += "&sensor=false";
url += "&key=" + this.ApiKey;
String html = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01
Transitional//EN'>";
html += "<html><head></head><body>";
html += " " + url + " ";
html += "</body></html>";
this.setText(html);
}
}
and for the class Activator.java
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
JGoogleMapEditorPan googleMap = new JGoogleMapEditorPan();
try {
googleMap.setApiKey("maCleGoogleMap");
// googleMap.setRoadmap(googleMap.viewHybrid);
/**
Afficher la ville de Strabourg
*/
googleMap.showLocation("strasbourg", "france", 390, 400);
/**
* Afficher Paris en fonction ses coordonnées GPS
*/
// googleMap.showCoordinate("48.8667", "2.3333",390, 400);
} catch (Exception ex) {
Logger.getLogger(JGoogleMapEditorPan.class.getName()).log(Level.SEVERE,
null, ex);
}
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(googleMap);
frame.setSize(400, 420);
frame.setLocation(200, 200);
frame.setVisible(true);
}
public void stop(BundleContext context) throws Exception {
}
}
and for MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Mybundle
Bundle-SymbolicName: com.test.mybundle
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.test.mybundle.Activator
Bundle-Vendor: TEST
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
import-Package: org.osgi.framework;version="1.3.0"
but the problem is if I made the execution of this application:
RUN AS -> OSGI Framwork the map is displayed
but the goal is to display the map if I type "START" in the console
and close the map if I type "STOP"
for the moment if I type "START" the answer is:
osgi> start
No bundle (s) specified!
thank you in advance
--
View this message in context:
http://karaf.922171.n3.nabble.com/create-first-bundle-tp3637715p3640145.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.