Compare commits

..

3 Commits

Author SHA1 Message Date
344106d17e Fixed merge conflicts 2025-07-02 18:09:31 +03:00
c20c439e6b Added GUI and everything works for TLT 2025-07-02 18:06:53 +03:00
54084a0bc3 init 2025-07-01 23:47:09 +03:00
12 changed files with 260 additions and 0 deletions

28
.gitignore vendored
View File

@ -23,4 +23,32 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

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>

6
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ThoriumBusParser.iml" filepath="$PROJECT_DIR$/ThoriumBusParser.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

12
ThoriumBusParser.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</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.

25
src/DownloadPage.java Normal file
View File

@ -0,0 +1,25 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class DownloadPage {
public static String DownloadPlainData(String inputUrl) throws IOException {
StringBuilder pageData = new StringBuilder();
URL url = new URL(inputUrl);
URLConnection con = url.openConnection();
try (InputStream is = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = br.readLine()) != null) {
pageData.append(line).append("\n");
}
}
return pageData.toString();
}
}

31
src/Main.java Normal file
View File

@ -0,0 +1,31 @@
import javax.swing.*;
import java.util.*;
import java.util.concurrent.*;
public class Main {
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;
}
}

28
src/ParseGpsFile.java Normal file
View File

@ -0,0 +1,28 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
public class ParseGpsFile {
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);
}
}
}