Added GUI and everything works for TLT

This commit is contained in:
2025-07-02 18:06:53 +03:00
parent 54084a0bc3
commit c20c439e6b
7 changed files with 158 additions and 20 deletions

9
.idea/libraries/josm_latest.xml generated Normal file
View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="josm-latest">
<CLASSES>
<root url="jar://$PROJECT_DIR$/josm-latest.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -7,5 +7,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="josm-latest" level="project" />
</component>
</module>

BIN
josm-latest.jar Normal file

Binary file not shown.

View File

@ -7,7 +7,7 @@ import java.net.URLConnection;
public class DownloadPage {
public static String main(String inputUrl) throws IOException {
public static String DownloadPlainData(String inputUrl) throws IOException {
StringBuilder pageData = new StringBuilder();
URL url = new URL(inputUrl);
URLConnection con = url.openConnection();

View File

@ -1,7 +1,31 @@
import java.io.IOException;
import javax.swing.*;
import java.util.*;
import java.util.concurrent.*;
public class Main {
public static void main(String[] args) throws IOException {
System.out.println(ParseGpsFile.ParseTLT(DownloadPage.main("https://transport.tallinn.ee/gps.txt")));
public static void main(String[] args) {
List<Map<String, String>> initialData = fetchVehicleData();
TLTVehicleDisplayGUI gui = new TLTVehicleDisplayGUI(initialData);
SwingUtilities.invokeLater(() -> gui.setVisible(true));
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(() -> {
List<Map<String, String>> newData = fetchVehicleData();
SwingUtilities.invokeLater(() -> gui.refreshData(newData));
}, 5, 5, TimeUnit.SECONDS);
}
}
private static List<Map<String, String>> fetchVehicleData() {
List<Map<String, String>> vehicleList = new ArrayList<>();
try {
for (String line : DownloadPage.DownloadPlainData("https://transport.tallinn.ee/gps.txt").split("\\R")) {
Map<String, String> data = ParseGpsFile.ParseTLT(line);
if (data != null) vehicleList.add(data);
}
} catch (Exception e) {
// Handle exceptions silently or log
}
return vehicleList;
}
}

View File

@ -1,23 +1,28 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
public class ParseGpsFile {
public static Map<String, Double> ParseTLT(String GpsFileDataInput) {
String[] GpsFileDataCS = GpsFileDataInput.split(",");
Map<String, Double> dataMap = new HashMap<>();
dataMap.put("VehicleType", Double.parseDouble(GpsFileDataCS[0]));
dataMap.put("VehicleLine", Double.parseDouble(GpsFileDataCS[1]));
dataMap.put("VehicleLongitude", Double.parseDouble(GpsFileDataCS[2]));
dataMap.put("VehicleLatitude", Double.parseDouble(GpsFileDataCS[3]));
dataMap.put("EmptyVal1", Double.parseDouble(GpsFileDataCS[4]));
dataMap.put("VehicleHeading", Double.parseDouble(GpsFileDataCS[5]));
dataMap.put("VehicleTAK", Double.parseDouble(GpsFileDataCS[6]));
dataMap.put("IsVehicleLowGroundVehicle", Double.parseDouble(GpsFileDataCS[7]));
dataMap.put("EmptyVal2", Double.parseDouble(GpsFileDataCS[8]));
dataMap.put("VehicleDestination", Double.parseDouble(GpsFileDataCS[9]));
public static Map<String, String> ParseTLT(String GpsFileDataInput) {
String[] GpsFileDataCS = GpsFileDataInput.split(","); // GpsFileDataC(omma)S(eparated)
Map<String, String> dataMap = new LinkedHashMap<>();
dataMap.put("VehicleType", GpsFileDataCS[0]);
dataMap.put("VehicleLine", GpsFileDataCS[1]);
dataMap.put("VehicleLatitude", GpsFileDataCS[3]);
dataMap.put("VehicleLongitude", GpsFileDataCS[2]);
dataMap.put("VehicleHeading", GpsFileDataCS[5]);
dataMap.put("VehicleTAK", GpsFileDataCS[6]);
String val = GpsFileDataCS[7].toLowerCase(); //
String isLowGround; //
if (Objects.equals(val, "z")) { //
isLowGround = "true"; // Parse from the stupid z=true,false=false system
} else { // TLT uses to true=true,false=false system.
isLowGround = "false"; //
} //
dataMap.put("IsVehicleLowGroundVehicle", isLowGround);
dataMap.put("VehicleDestination", GpsFileDataCS[9]);
return dataMap;
}
}

View File

@ -0,0 +1,99 @@
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.Map;
import org.openstreetmap.gui.jmapviewer.*;
public class TLTVehicleDisplayGUI extends JFrame {
private DefaultTableModel model;
private JTable table;
private JMapViewer map;
private List<Map<String, String>> vehicles;
public TLTVehicleDisplayGUI(List<Map<String, String>> initialVehicles) {
this.vehicles = initialVehicles;
setTitle("ThoriumBusParser v1.0 - (c) 2025 VELENDEU, eetnaviation");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(900, 600);
setLayout(new BorderLayout());
String[] columns = {"Type", "Line", "Latitude", "Longitude",
"Heading", "TAK", "IsLowGround", "Destination"};
model = new DefaultTableModel(columns, 0);
table = new JTable(model);
JScrollPane tableScroll = new JScrollPane(table);
map = new JMapViewer();
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tableScroll, map);
splitPane.setDividerLocation(400);
add(splitPane, BorderLayout.CENTER);
table.getSelectionModel().addListSelectionListener(e -> {
if (!e.getValueIsAdjusting()) {
int index = table.getSelectedRow();
if (index >= 0 && index < map.getMapMarkerList().size()) {
MapMarkerDot marker = (MapMarkerDot) map.getMapMarkerList().get(index);
map.setDisplayPosition(marker.getCoordinate(), 15);
}
}
});
map.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent e) {
Point clickPoint = e.getPoint();
for (int i = 0; i < map.getMapMarkerList().size(); i++) {
MapMarkerDot marker = (MapMarkerDot) map.getMapMarkerList().get(i);
Point markerPos = map.getMapPosition(marker.getCoordinate(), false);
if (markerPos != null && clickPoint.distance(markerPos) <= 10) {
table.setRowSelectionInterval(i, i);
table.scrollRectToVisible(table.getCellRect(i, 0, true));
break;
}
}
}
});
refreshData(vehicles);
}
public void refreshData(List<Map<String, String>> newVehicles) {
this.vehicles = newVehicles;
model.setRowCount(0);
map.removeAllMapMarkers();
for (Map<String, String> vehicle : vehicles) {
String typeStr = vehicle.get("VehicleType");
String typeText = switch (typeStr) {
case "1" -> "Trolleybus";
case "2" -> "Bus";
case "3" -> "Tram";
case "7" -> "Nightbus";
default -> "Unknown";
};
double lat = Integer.parseInt(vehicle.get("VehicleLatitude")) / 1_000_000.0;
double lon = Integer.parseInt(vehicle.get("VehicleLongitude")) / 1_000_000.0;
Object[] row = {
typeText,
vehicle.get("VehicleLine"),
lat,
lon,
vehicle.get("VehicleHeading"),
vehicle.get("VehicleTAK"),
vehicle.get("IsVehicleLowGroundVehicle"),
vehicle.get("VehicleDestination")
};
model.addRow(row);
MapMarkerDot marker = new MapMarkerDot(lat, lon);
marker.setName(typeText + " " + vehicle.get("VehicleLine"));
map.addMapMarker(marker);
}
}
}