1 | package nanolog;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.awt.Graphics2D;
|
---|
5 | import java.awt.Point;
|
---|
6 | import java.awt.Rectangle;
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.beans.PropertyChangeListener;
|
---|
9 | import java.io.*;
|
---|
10 | import java.util.ArrayList;
|
---|
11 | import java.util.List;
|
---|
12 | import javax.swing.AbstractAction;
|
---|
13 | import javax.swing.Action;
|
---|
14 | import javax.swing.Icon;
|
---|
15 | import org.openstreetmap.josm.Main;
|
---|
16 | import org.openstreetmap.josm.actions.RenameLayerAction;
|
---|
17 | import org.openstreetmap.josm.actions.SaveAction;
|
---|
18 | import org.openstreetmap.josm.data.Bounds;
|
---|
19 | import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
|
---|
20 | import org.openstreetmap.josm.gui.MapView;
|
---|
21 | import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
|
---|
22 | import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
|
---|
23 | import org.openstreetmap.josm.gui.layer.JumpToMarkerActions;
|
---|
24 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
25 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
26 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
27 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | *
|
---|
31 | * @author zverik
|
---|
32 | */
|
---|
33 | public class NanoLogLayer extends Layer implements JumpToMarkerActions.JumpToMarkerLayer {
|
---|
34 |
|
---|
35 | private List<NanoLogEntry> log;
|
---|
36 | private int selectedEntry;
|
---|
37 |
|
---|
38 | public NanoLogLayer( File file ) throws IOException {
|
---|
39 | super(tr("NanoLog"));
|
---|
40 | log = readNanoLog(file);
|
---|
41 | selectedEntry = -1;
|
---|
42 | }
|
---|
43 |
|
---|
44 | public static List<NanoLogEntry> readNanoLog( File file ) throws IOException {
|
---|
45 | List<NanoLogEntry> result = new ArrayList<NanoLogEntry>();
|
---|
46 | BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));
|
---|
47 | while( r.ready() ) {
|
---|
48 | String line = r.readLine();
|
---|
49 | if( line != null ) {
|
---|
50 | // parse it
|
---|
51 | }
|
---|
52 | }
|
---|
53 | r.close();
|
---|
54 | return result;
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public void paint( Graphics2D g, MapView mv, Bounds box ) {
|
---|
59 | // todo
|
---|
60 | int radius = 4;
|
---|
61 | int width = Main.map.mapView.getWidth();
|
---|
62 | int height = Main.map.mapView.getHeight();
|
---|
63 | Rectangle clip = g.getClipBounds();
|
---|
64 | for( NanoLogEntry entry : log ) {
|
---|
65 | if( entry.getPos() != null ) {
|
---|
66 | Point p = mv.getPoint(entry.getPos());
|
---|
67 | g.setColor(Color.green);
|
---|
68 | g.fillOval(p.x - radius, p.y - radius, radius * 2, radius * 2);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | if( selectedEntry >= 0 && selectedEntry < log.size() ) {
|
---|
72 | Point p = mv.getPoint(log.get(selectedEntry).getPos());
|
---|
73 | g.setColor(Color.red);
|
---|
74 | g.fillOval(p.x - radius, p.y - radius, radius * 2, radius * 2);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | @Override
|
---|
79 | public Icon getIcon() {
|
---|
80 | return ImageProvider.get("nanolog.png");
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | public String getToolTipText() {
|
---|
85 | return tr("NanoLog of {0} entries", log.size());
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public void mergeFrom( Layer from ) {
|
---|
90 | // todo
|
---|
91 | }
|
---|
92 |
|
---|
93 | @Override
|
---|
94 | public boolean isMergable( Layer other ) {
|
---|
95 | return other instanceof NanoLogLayer;
|
---|
96 | }
|
---|
97 |
|
---|
98 | @Override
|
---|
99 | public void visitBoundingBox( BoundingXYVisitor v ) {
|
---|
100 | for( NanoLogEntry entry : log )
|
---|
101 | v.visit(entry.getPos());
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Override
|
---|
105 | public Object getInfoComponent() {
|
---|
106 | StringBuilder b = new StringBuilder();
|
---|
107 | int cnt = 0;
|
---|
108 | for( NanoLogEntry e : log )
|
---|
109 | if( e.getPos() != null )
|
---|
110 | cnt++;
|
---|
111 | b.append(tr("NanoLog of {0} lines, {1} of them with coordinates.", log.size(), cnt));
|
---|
112 | return b.toString();
|
---|
113 | }
|
---|
114 |
|
---|
115 | @Override
|
---|
116 | public Action[] getMenuEntries() {
|
---|
117 | return new Action[] {
|
---|
118 | LayerListDialog.getInstance().createShowHideLayerAction(),
|
---|
119 | LayerListDialog.getInstance().createDeleteLayerAction(),
|
---|
120 | new RenameLayerAction(null, this),
|
---|
121 | SeparatorLayerAction.INSTANCE,
|
---|
122 | new CorrelateEntries(),
|
---|
123 | new SaveLayer(),
|
---|
124 | SeparatorLayerAction.INSTANCE,
|
---|
125 | new LayerListPopup.InfoAction(this)
|
---|
126 | };
|
---|
127 | }
|
---|
128 |
|
---|
129 | public void jumpToNextMarker() {
|
---|
130 | selectedEntry++;
|
---|
131 | if( selectedEntry < 0 )
|
---|
132 | selectedEntry = 0;
|
---|
133 | else if( selectedEntry >= log.size() )
|
---|
134 | selectedEntry = log.size() - 1;
|
---|
135 | Main.map.repaint();
|
---|
136 | }
|
---|
137 |
|
---|
138 | public void jumpToPreviousMarker() {
|
---|
139 | selectedEntry--;
|
---|
140 | if( selectedEntry < 0 )
|
---|
141 | selectedEntry = 0;
|
---|
142 | else if( selectedEntry >= log.size() )
|
---|
143 | selectedEntry = log.size() - 1;
|
---|
144 | Main.map.repaint();
|
---|
145 | }
|
---|
146 |
|
---|
147 | private class CorrelateEntries extends AbstractAction {
|
---|
148 |
|
---|
149 | public void actionPerformed( ActionEvent e ) {
|
---|
150 | // todo
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | private class SaveLayer extends AbstractAction {
|
---|
155 |
|
---|
156 | public void actionPerformed( ActionEvent e ) {
|
---|
157 | // todo
|
---|
158 | }
|
---|
159 | }
|
---|
160 | }
|
---|