| 1 | /* Copyright 2014 Malcolm Herring
|
|---|
| 2 | *
|
|---|
| 3 | * This is free software: you can redistribute it and/or modify
|
|---|
| 4 | * it under the terms of the GNU General Public License as published by
|
|---|
| 5 | * the Free Software Foundation, version 3 of the License.
|
|---|
| 6 | *
|
|---|
| 7 | * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | package panels;
|
|---|
| 11 |
|
|---|
| 12 | import java.awt.Color;
|
|---|
| 13 | import java.awt.Graphics;
|
|---|
| 14 | import java.awt.Graphics2D;
|
|---|
| 15 | import java.awt.geom.Point2D;
|
|---|
| 16 | import java.util.ArrayList;
|
|---|
| 17 |
|
|---|
| 18 | import javax.swing.JFrame;
|
|---|
| 19 | import javax.swing.JPanel;
|
|---|
| 20 |
|
|---|
| 21 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 22 |
|
|---|
| 23 | import render.MapContext;
|
|---|
| 24 | import render.Renderer;
|
|---|
| 25 | import s57.S57map;
|
|---|
| 26 | import s57.S57map.*;
|
|---|
| 27 |
|
|---|
| 28 | public class ShowFrame extends JFrame {
|
|---|
| 29 |
|
|---|
| 30 | S57map showMap;
|
|---|
| 31 | Picture picture;
|
|---|
| 32 |
|
|---|
| 33 | class Picture extends JPanel implements MapContext {
|
|---|
| 34 |
|
|---|
| 35 | public void drawPicture(OsmPrimitive osm, S57map map) {
|
|---|
| 36 | long id;
|
|---|
| 37 | Feature feature;
|
|---|
| 38 |
|
|---|
| 39 | id = osm.getUniqueId();
|
|---|
| 40 | feature = map.index.get(id);
|
|---|
| 41 | showMap = new S57map();
|
|---|
| 42 | showMap.nodes = map.nodes;
|
|---|
| 43 | showMap.edges = map.edges;
|
|---|
| 44 | showMap.index = map.index;
|
|---|
| 45 | if (feature != null) {
|
|---|
| 46 | showMap.features.put(feature.type, new ArrayList<Feature>());
|
|---|
| 47 | showMap.features.get(feature.type).add(feature);
|
|---|
| 48 | }
|
|---|
| 49 | repaint();
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | public void paintComponent(Graphics g) {
|
|---|
| 53 | Graphics2D g2 = (Graphics2D)g;
|
|---|
| 54 | g2.setBackground(new Color(0xb5d0d0));
|
|---|
| 55 | g2.clearRect(0, 0, 300, 300);
|
|---|
| 56 | Renderer.reRender(g2, 16, 32, showMap, this);
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | public Point2D getPoint(Snode coord) {
|
|---|
| 60 | return new Point2D.Double(150, 150);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | public double mile(Feature feature) {
|
|---|
| 64 | return 1000;
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | public ShowFrame(String title) {
|
|---|
| 69 | super(title);
|
|---|
| 70 | picture = new Picture();
|
|---|
| 71 | picture.setVisible(true);
|
|---|
| 72 | add(picture);
|
|---|
| 73 | pack();
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | public void showFeature(OsmPrimitive osm, S57map map) {
|
|---|
| 77 | picture.drawPicture(osm, map);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 | }
|
|---|