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.Rectangle;
|
---|
16 | import java.awt.geom.Point2D;
|
---|
17 | import java.util.ArrayList;
|
---|
18 |
|
---|
19 | import javax.swing.JFrame;
|
---|
20 | import javax.swing.JPanel;
|
---|
21 |
|
---|
22 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
23 |
|
---|
24 | import render.ChartContext;
|
---|
25 | import render.Renderer;
|
---|
26 | import s57.S57map;
|
---|
27 | import s57.S57map.Feature;
|
---|
28 | import s57.S57map.Snode;
|
---|
29 |
|
---|
30 | public class ShowFrame extends JFrame {
|
---|
31 |
|
---|
32 | S57map showMap;
|
---|
33 | Picture picture;
|
---|
34 |
|
---|
35 | class Picture extends JPanel implements ChartContext {
|
---|
36 |
|
---|
37 | public void drawPicture(OsmPrimitive osm, S57map map) {
|
---|
38 | long id;
|
---|
39 | Feature feature;
|
---|
40 |
|
---|
41 | id = osm.getUniqueId();
|
---|
42 | feature = map.index.get(id);
|
---|
43 | showMap = new S57map(true);
|
---|
44 | showMap.nodes = map.nodes;
|
---|
45 | showMap.edges = map.edges;
|
---|
46 | showMap.index = map.index;
|
---|
47 | if (feature != null) {
|
---|
48 | showMap.features.put(feature.type, new ArrayList<Feature>());
|
---|
49 | showMap.features.get(feature.type).add(feature);
|
---|
50 | }
|
---|
51 | repaint();
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public void paintComponent(Graphics g) {
|
---|
56 | Graphics2D g2 = (Graphics2D) g;
|
---|
57 | g2.setBackground(new Color(0xb5d0d0));
|
---|
58 | Rectangle rect = new Rectangle(0, 0, 300, 300);
|
---|
59 | g2.clearRect(rect.x, rect.y, rect.width, rect.height);
|
---|
60 | Renderer.reRender(g2, rect, 16, 32, showMap, this);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public Point2D getPoint(Snode coord) {
|
---|
65 | return new Point2D.Double(150, 150);
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public double mile(Feature feature) {
|
---|
70 | return 1000;
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public boolean clip() {
|
---|
75 | // TODO Auto-generated method stub
|
---|
76 | return false;
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | public Color background(S57map map) {
|
---|
81 | // TODO Auto-generated method stub
|
---|
82 | return null;
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | public RuleSet ruleset() {
|
---|
87 | // TODO Auto-generated method stub
|
---|
88 | return null;
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | public ShowFrame(String title) {
|
---|
93 | super(title);
|
---|
94 | picture = new Picture();
|
---|
95 | picture.setVisible(true);
|
---|
96 | add(picture);
|
---|
97 | pack();
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void showFeature(OsmPrimitive osm, S57map map) {
|
---|
101 | picture.drawPicture(osm, map);
|
---|
102 | }
|
---|
103 | }
|
---|