public void init() {
// tells the openmap to be an applet
Environment.init(this);
// applet size, matches 640x480 by factor 1.1
setSize(704, 528);
// createTestCursor();
// setCursor(c);
Cursor normal = new Cursor(Cursor.DEFAULT_CURSOR);
setCursor(normal);
// setLayout(null);
// notwendig
// addMouseMotionListener(this);
// addMouseListener(this);
start_button = new JButton("Start/Continue");
start_button.addActionListener(this);
jSlider = new JSlider(0, 10, 0);
jSlider.setMinorTickSpacing(1);
jSlider.setMajorTickSpacing(10);
jSlider.setName("Level");
jSlider.setPaintTicks(true);
jSlider.setSnapToTicks(true);
jSlider.setPaintTrack(true);
jSlider.setPaintLabels(true);
info = new JLabel();
nickname = new JLabel();
checkboxGroupMaps = new ButtonGroup();
checkboxEu = new JRadioButton("Europe");
checkboxEu.setSelected(true);
checkboxWorld = new JRadioButton("World");
checkboxGroupMaps.add(checkboxEu);
checkboxGroupMaps.add(checkboxWorld);
DatabaseHandler.getInstance().createDBConnection();
DatabaseHandler.getInstance().calcNumberOfLocationsWorld();
DatabaseHandler.getInstance().calcNumberOfLocationsEurope();
// System.out.print(DatabaseHandler.getInstance().numberOfLocationsEurope+"\n");
// because the map shows basically the world
DatabaseHandler.getInstance().loadCidsOfEurope();
gameLogic = new GameLogic();
// appletUpdater = new AppletUpdater(this);
gameLogic.setSounds(null, null, null);
gameLogic.setGameEntry(this);
gameLogic.setLevel(0);
gameLogic.setMap(true);
gameLogic.setMapHeight(mapHeight);
gameLogic.setMapWidth(mapWidth);
gameLogic.setScale(worldScale);// default
gameLogic.setCenter(worldCenter);// default
// Cursor cursor = new Cursor(Cursor.DEFAULT_CURSOR);
// setCursor(cursor);
// setSize(640, 480);
// setLayout(new FlowLayout());
/*
* The BasicMapPanel automatically creates many default components,
* including the MapBean and the MapHandler.
*/
MapPanel mapPanel = new BasicMapPanel();
MapHandler mapHandler = mapPanel.getMapHandler();
mapBean = mapPanel.getMapBean();
// LatLonPoint p2; //= new LatLonPoint(getDecFromLatOrLong(48, (float)
// 12,
// //(float) 0), getDecFromLatOrLong(16, (float) 22, (float) 0));
// //System.out.print("DIS " + llp.distance(p2) + "\n");
// //london
// p2 = new LatLonPoint(51.48791122f, -0.177998126f);
//
// //graz
// LatLonPoint p1 = new LatLonPoint(47.06492233f,15.43110085f);
// float dist = Length.KM.fromRadians(p1.distance(p2));
// System.out.print("dist="+dist+"\n");
mapBean.setSize(mapWidth, mapHeight);
// Set the map's default center
mapBean.setCenter(worldCenter);
// Set the map's default scale
mapBean.setScale(worldScale);
// mapBean.setScale(worldScale);
// default
// gameLogic.setScale(europeScale);
// gameLogic.setScale(worldScale);
// funktioniert nicht richtig
// oder in mousemove() setScale()??
mapBean.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
System.out.println("do nothing");
// mapBean.setScale(5000000f);
// mapBean.
// mapBean.repaint();
}
});
System.out.print("listensteners"
+ mapBean.getMouseWheelListeners().length + "\n");
MouseDelegator mouseDelegator = new MouseDelegator();
mapHandler.add(mouseDelegator);
SelectMouseMode selectMouseMode = new SelectMouseMode();
// map cursor
cursor = new Cursor(Cursor.CROSSHAIR_CURSOR);
selectMouseMode.setModeCursor(cursor);
mapHandler.add(selectMouseMode);
mouseDelegator.setActive(selectMouseMode);
/*
* Create and add a LayerHandler to the MapHandler. The LayerHandler
* manages Layers, whether they are part of the map or not.
* layer.setVisible(true) will add it to the map. The LayerHandler has
* methods to do this, too. The LayerHandler will find the MapBean in
* the MapHandler.
*/
// mapHandler.add(new LayerHandler());
//
// // Add a route layer.
// RouteLayer routeLayer = new RouteLayer();
// routeLayer.setVisible(true);
// // The LayerHandler will find the Layer in the MapHandler.
final MyMapMouseListener myMapMouseListener = new MyMapMouseListener();
ShapeLayer shapeLayer = new ShapeLayer() {
//
// When asked for the mouse listener, return my version.
//
public synchronized MapMouseListener getMapMouseListener() {
return myMapMouseListener;
}
};
Properties shapeLayerProps = new Properties();
shapeLayerProps.put("prettyName", "Political Solid");
shapeLayerProps.put("lineColor", "000000");
shapeLayerProps.put("fillColor", "BDDE83");
shapeLayerProps.put("shapeFile", "maps/cntry02.shp");
// shapeLayerProps.put("shapeFile", "maps/dcwpo-browse.shp");
// shapeLayerProps.put("spatialIndex", "maps/dcwpo-browse.ssx");
shapeLayerProps.put("spatialIndex", "maps/cntry02.ssx");
shapeLayer.setProperties(shapeLayerProps);
shapeLayer.setVisible(true);
mapBean.add(shapeLayer);
JPanel jPanel = new JPanel();
jPanel.setLayout(null);
// JButton button = new JButton("muh");
// button.addActionListener(this);
//
// JButton button1 = new JButton("muh1");
// button1.addActionListener(this);
// Container container;
// container = getContentPane();
// container.setLayout(null);
// c.setLayout(new FlowLayout());
// c.add(jPanel);
// System.out.print(jPanel.size() + "\n");
// // c.add(mapBean);
// c.add(jPanel2);
// mapHandler.add(frame);
// // Last on top.
// mapHandler.add(shapeLayer);
// mapHandler.add(new GraticuleLayer());
// mapHandler.add(routeLayer);
// mapBean.setBounds(0, 150, 640, 480);
// c.add(mapBean);
// add(mapBean);
// JPanel jPanel = new JPanel();
// //jPanel.setLayout(new FlowLayout());
// jPanel.setBounds(0,480 , 800,600);
// // JPanel jPanel2 = new JPanel();
// // jPanel2.setLayout(new FlowLayout());
// jPanel.setLayout(new FlowLayout());
// jPanel.add(mapBean);
// jPanel2.add(button1);
// button.setBounds(0, 0, 50, 50);
mapBean.setBounds(0, 0, 640, 480);
// container.add(button);
// container.add(mapBean);
checkboxEu.setBounds(0, mapBean.getHeight(), 100,
(this.getHeight() - mapBean.getHeight()) / 2);
checkboxWorld.setBounds(0,
mapBean.getHeight() + checkboxEu.getHeight(), 100,
(this.getHeight() - mapBean.getHeight()) / 2);
jSlider.setBounds(checkboxEu.getWidth(), mapBean.getHeight(), 200,
this.getHeight() - mapBean.getHeight());
info.setBounds(jSlider.getWidth() + checkboxEu.getWidth(),
mapBean.getHeight(), 100,
(this.getHeight() - mapBean.getHeight()) / 2);
info.setText("INFO:");
// label.setAlignmentX(JLabel.CENTER);
// nickname.setBounds(jSlider.getWidth() + checkboxEu.getWidth(),
// mapBean.getHeight() + info.getHeight(), 100,
// (this.getHeight() - mapBean.getHeight()) / 2);
// nickname.setText("Name:");
// // nickname.setAlignmentX(JLabel.CENTER);
// location = new JLabel();
//
// location.setBounds(
// jSlider.getWidth() + checkboxEu.getWidth() + info.getWidth(),
// mapBean.getHeight(), 200,
// this.getHeight() - mapBean.getHeight());
// location.setText("hallo");
// label.setBounds(checkboxEu.getWidth(), mapBean.getHeight(), 300, 50);
// jPanel.add(label);
// jPanel.add(start_button);
// jPanel.add(checkboxEu);
// jPanel.add(checkboxWorld);
// jPanel.setCursor(nc);
// jPanel.setVisible(true);
jPanel.add(mapBean);
jPanel.add(checkboxEu);
jPanel.add(checkboxWorld);
jPanel.add(jSlider);// jSlider.setVisible(true);
jPanel.add(info);
// jPanel.add(nickname);
// jPanel.add(location);
// jPanel.add(start_button);
// setVisible(true);
// container.add(jLabel);
// this.pack();
System.out.print("Init done\n");
// appletThread = new Thread(this);
// appletThread.start();
// jPanel.setVisible(true);
add(jPanel);
}