Skip to content

Commit

Permalink
Working first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
liturner committed Dec 26, 2022
1 parent 3cfe61f commit fd90ad9
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 184 deletions.
29 changes: 22 additions & 7 deletions src/main/java/de/turnertech/frederick/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import java.net.URI;
import java.util.logging.Level;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import de.turnertech.frederick.gui.deployments.DeploymentFrame;
import de.turnertech.frederick.gui.etb.FrederickEtbFrame;
import de.turnertech.frederick.gui.map.MapFrameTake2;
import de.turnertech.frederick.gui.map.MapFrame;
import de.turnertech.frederick.gui.tray.FrederickTrayIcon;

/**
Expand Down Expand Up @@ -41,9 +42,11 @@ public class Application {

private static DeploymentFrame deploymentFrame = null;

private static MapFrameTake2 mapFrame = null;
private static MapFrame mapFrame = null;

private static final Database database = new Database();
private static Database database;

private static Service service;

public static final String CURRENT_USER = System.getProperty("user.name");

Expand All @@ -56,6 +59,8 @@ public static void main(String[] args) {

Logging.initialise();
Printing.initialise();
database = new Database();
service = new Service(database);

//Check the SystemTray is supported
if (!SystemTray.isSupported()) {
Expand All @@ -75,9 +80,15 @@ public static void main(String[] args) {

deploymentFrame = new DeploymentFrame();
etbFrame = new FrederickEtbFrame();
etbFrame.setVisible(true);
mapFrame = new MapFrameTake2();
mapFrame.setVisible(true);
mapFrame = new MapFrame();

// Technically, there is always a depolyment open. This is more a trigger to say "initialisation finished"
database.notifyActionListeners(Database.DEPLOYMENT_OPENED_EVENT);

SwingUtilities.invokeLater(() -> {
etbFrame.setVisible(true);
mapFrame.setVisible(true);
});
}

public static FrederickEtbFrame getEtbFrame() {
Expand All @@ -88,7 +99,7 @@ public static DeploymentFrame getDeploymentFrame() {
return deploymentFrame;
}

public static MapFrameTake2 getMapFrame() {
public static MapFrame getMapFrame() {
return mapFrame;
}

Expand All @@ -100,6 +111,10 @@ public static Database getDatabase() {
return database;
}

public static Service getService() {
return service;
}

/**
* Shows the system web browser with the manual page for a given window.
* For example, if requested for {@link DeploymentFrame} class, then the
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/de/turnertech/frederick/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.swing.SwingUtilities;

import de.turnertech.frederick.data.Deployment;
import de.turnertech.frederick.data.SaveTimerTask;

Expand All @@ -25,11 +27,13 @@ public class Database {

public static final String CURRENT_DEPLOYMENT_FILE_NAME = "Current";

public static final int DEPLOYMENT_OPENED_EVENT = "DEPLOYMENT_OPENED_EVENT".hashCode();

public static final Integer DEPLOYMENT_CLOSED_EVENT = "DEPLOYMENT_CLOSED_EVENT".hashCode();

public static final Integer DEPLOYMENT_SAVED_EVENT = "DEPLOYMENT_SAVED_EVENT".hashCode();

public static final Integer DEPLOYMENT_UPDATED_EVENT = "DEPLOYMENT_UPDATED_EVENT".hashCode();
public static final int DEPLOYMENT_UPDATED_EVENT = "DEPLOYMENT_UPDATED_EVENT".hashCode();

public static final Integer DEPLOYMENT_DELETED_EVENT = "DEPLOYMENT_DELETED_EVENT".hashCode();

Expand Down Expand Up @@ -64,11 +68,13 @@ public void addActionListener(ActionListener actionListener) {
actionListeners.add(actionListener);
}

public void notifyActionListeners(int event) {
ActionEvent actionEvent = new ActionEvent(this, event, "");
for(ActionListener actionListener : actionListeners) {
actionListener.actionPerformed(actionEvent);
}
public void notifyActionListeners(final int event) {
SwingUtilities.invokeLater(() -> {
ActionEvent actionEvent = new ActionEvent(this, event, "");
for(ActionListener actionListener : actionListeners) {
actionListener.actionPerformed(actionEvent);
}
});
}

/**
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/de/turnertech/frederick/Service.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.turnertech.frederick;

import java.time.Instant;
import java.util.Date;
import java.util.Optional;

import de.turnertech.frederick.data.Bullseye;
import de.turnertech.frederick.data.EtbEntry;

/**
* This is the service layer for the application. All actions performed by the GUI
* should come through here. Consider it the API for the application.
*
* This class should not have any dependency on Geotools, or the GUI in general.
*/
public class Service {

final Database database;

Service(final Database database) {
this.database = database;
}

/**
* Sets the current deployments Bullseye position.
*
* @param bullseye Setting to null will clear the bullseye.
* @param logPosition The bullseye coordinates as they should be entered into the ETB.
*/
public void setBullseye(final Bullseye bullseye, final String logPosition) {
database.getCurrentDeployment().setBullseye(bullseye);
EtbEntry etbEntry = new EtbEntry(Date.from(Instant.now()), Application.CURRENT_USER, "Einsatzort festgelegt als " + logPosition);
database.getCurrentDeployment().getEtbEntries().add(etbEntry);
database.notifyActionListeners(Database.DEPLOYMENT_UPDATED_EVENT);
database.saveCurrentDeployment();
}

public Optional<Bullseye> getBullseye() {
return Optional.ofNullable(database.getCurrentDeployment().getBullseye());
}

}
36 changes: 36 additions & 0 deletions src/main/java/de/turnertech/frederick/data/Bullseye.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package de.turnertech.frederick.data;

import java.io.Serializable;

public class Bullseye implements Serializable {

private double x;

private double y;

public Bullseye() {
this(0.0, 0.0);
}

public Bullseye(final double x, final double y) {
this.x = x;
this.y = y;
}

public double getX() {
return x;
}

public void setX(final double x) {
this.x = x;
}

public double getY() {
return y;
}

public void setY(final double y) {
this.y = y;
}

}
13 changes: 11 additions & 2 deletions src/main/java/de/turnertech/frederick/data/Deployment.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package de.turnertech.frederick.data;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "deployment")
public class Deployment implements Serializable {
public class Deployment {

private String name;

private Bullseye bullseye = null;

@XmlElement(name = "etbEntry")
private LinkedList<EtbEntry> etbEntries;

Expand All @@ -32,4 +33,12 @@ public void setName(String name) {
this.name = name;
}

public Bullseye getBullseye() {
return bullseye;
}

public void setBullseye(Bullseye bullseye) {
this.bullseye = bullseye;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void valueChanged(ListSelectionEvent e) {
}
this.setEnabled(!selectionModel.isSelectionEmpty());
this.getDocument().removeDocumentListener(this);
this.setText(tableModel.getValueAt(selectionModel.getLeadSelectionIndex(), EtbTableModel.NOTES).toString());
this.setText((selectionModel.isSelectionEmpty()) ? "" : tableModel.getValueAt(selectionModel.getLeadSelectionIndex(), EtbTableModel.NOTES).toString());
this.getDocument().addDocumentListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public TableColumnModel getColumnModel() {

@Override
public void actionPerformed(ActionEvent e) {
if(Database.DEPLOYMENT_CLOSED_EVENT.equals(e.getID()) || Database.DEPLOYMENT_UPDATED_EVENT.equals(e.getID())) {
if(Database.DEPLOYMENT_CLOSED_EVENT.equals(e.getID()) || Database.DEPLOYMENT_UPDATED_EVENT == e.getID()) {
this.fireTableDataChanged();
}
}
Expand Down
74 changes: 63 additions & 11 deletions src/main/java/de/turnertech/frederick/gui/map/MapFrame.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package de.turnertech.frederick.gui.map;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JFrame;

import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.geometry.DirectPosition2D;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.grid.Lines;
import org.geotools.grid.ortholine.LineOrientation;
Expand All @@ -17,28 +25,36 @@
import org.geotools.styling.FeatureTypeStyle;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.JMapPane;
import org.geotools.swing.MapLayerTable;
import org.geotools.tile.TileService;
import org.geotools.tile.impl.osm.OSMService;
import org.geotools.tile.util.TileLayer;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

import de.turnertech.frederick.Application;
import de.turnertech.frederick.Database;
import de.turnertech.frederick.Logging;
import de.turnertech.frederick.Resources;
import de.turnertech.frederick.gui.map.feature.Bullseye;
import de.turnertech.frederick.gui.map.tool.ContextMenuTool;
import de.turnertech.frederick.gui.map.tool.PanTool;
import de.turnertech.frederick.gui.map.tool.ScrollTool;
import de.turnertech.frederick.gui.status.StatusBar;

public class MapFrame extends JMapFrame {
public class MapFrame extends JFrame implements ActionListener {

private final ReferencedEnvelope germanyEnvelope = new ReferencedEnvelope(5.0, 16, 47.0, 55.0, DefaultGeographicCRS.WGS84);

private final MapToolbar mapToolbar;

public MapFrame() {
this.getContentPane().setLayout(new java.awt.BorderLayout());
Application.getDatabase().addActionListener(this);
MapContent map = new MapContent();
String baseURL = "http://tile.openstreetmap.org/";
TileService service = new OSMService("OSM", baseURL);

//String baseURL = "https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}";
//TileService service = new GoogleHybridService();

TileLayer layer = new TileLayer(service);

try {
Expand All @@ -50,15 +66,36 @@ public MapFrame() {
}

map.addLayer(layer);
map.addLayer(Bullseye.LAYER);
addGrids(map);

this.setTitle("Frederick - Einsatz Karte");
this.setIconImage(Resources.getdeployment24pxIcon().getImage());
this.setMapContent(map);
this.enableStatusBar(true);
this.enableToolBar(true);
this.enableLayerTable(true);
this.initComponents();

JMapPane mapPane = new JMapPane(map);
mapPane.setBackground(Color.WHITE);
mapPane.setBorder(BorderFactory.createLineBorder(Color.BLACK));
mapPane.addMouseListener(new ScrollTool(mapPane));
mapPane.addMouseListener(new PanTool(mapPane));
mapPane.addMouseListener(new ContextMenuTool(mapPane));
this.add(mapPane, BorderLayout.CENTER);

MapLayerTable mapLayerTable = new MapLayerTable(mapPane);
mapLayerTable.setPreferredSize(new Dimension(200, -1));
//JSplitPane splitPane =
// new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, mapLayerTable, mapPane);
//this.add(splitPane, "grow");

mapToolbar = new MapToolbar(mapPane);

this.add(new MapBrowserPanel(mapPane), BorderLayout.LINE_START);
this.add(mapToolbar, BorderLayout.PAGE_START);
this.add(new StatusBar(), BorderLayout.PAGE_END);
//this.setMapContent(map);
//this.enableStatusBar(true);
//this.enableToolBar(true);
//this.enableLayerTable(true);
//this.initComponents();
this.setSize(1024, 768);
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
}
Expand Down Expand Up @@ -99,4 +136,19 @@ private void addGrids(MapContent map) {
map.addLayer(minorGridLayer);
}

@Override
public void actionPerformed(ActionEvent actionEvent) {
if(actionEvent.getID() == Database.DEPLOYMENT_UPDATED_EVENT || actionEvent.getID() == Database.DEPLOYMENT_OPENED_EVENT) {
if(Application.getService().getBullseye().isPresent()) {
de.turnertech.frederick.data.Bullseye bullsFromStorage = Application.getService().getBullseye().get();
Bullseye.set(new DirectPosition2D(DefaultGeographicCRS.WGS84, bullsFromStorage.getX(), bullsFromStorage.getY()));
mapToolbar.setFocusBullseyeActionEnabled(true);
} else {
if(Bullseye.getPosition().isPresent()) {
Bullseye.clear();
}
mapToolbar.setFocusBullseyeActionEnabled(false);
}
}
}
}
Loading

0 comments on commit fd90ad9

Please sign in to comment.