Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • issue-10-fxmapcontrol
  • issue-13-gpx
  • issue-9-file-menu
  • master
4 results

Target

Select target project
  • bragearn/examples
  • johngu/examples
  • krisschn/examples
  • erikbd/examples
  • helenesm/examples
  • balazor/examples
  • htechter/examples
  • aslakho/examples
  • jonri/examples
  • andreski/examples
  • sigriksc/examples
  • norasbr/examples
  • jannash/examples
  • smledsaa/examples
  • mtorre/examples
  • tdt4140-staff/examples
16 results
Select Git revision
  • issue-10-fxmapcontrol
  • issue-9-file-menu
  • master
  • patch-1
  • patch-2
5 results
Show changes
Showing
with 1142 additions and 119 deletions
[
{
"id" : "1",
"name" : "1",
"locations" : [
{ "latitude" : "63", "longitude" : "10" },
[ "63.1", "10.1" ]
]
},
{
"id" : "2",
"name" : "2",
"path" : "true",
"locations" : [
{ "latitude" : "64", "longitude" : "11" },
......
DROP TABLE person;
DROP TABLE geoLocations;
DROP TABLE geoLocation;
DROP TABLE tag;
CREATE TABLE person (
id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1000) PRIMARY KEY,
name varchar(80) NULL,
email varchar(80) NULL
);
CREATE TABLE geoLocations (
id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1000) PRIMARY KEY,
ownerId int NOT NULL FOREIGN KEY REFERENCES person(id) ON DELETE CASCADE,
path boolean NULL,
name varchar(80) NULL,
description varchar(200) NULL,
date date NULL,
time time NULL,
zone varchar(20) NULL,
);
CREATE TABLE geoLocation (
id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1000) PRIMARY KEY,
ownerId int NOT NULL FOREIGN KEY REFERENCES geoLocations(id) ON DELETE CASCADE,
name varchar(80) NULL,
description varchar(200) NULL,
latitude decimal NOT NULL,
longitude decimal NOT NULL,
elevation int NULL,
date date NULL,
time time NULL,
zone varchar(20) NULL,
);
CREATE TABLE tag (
ownerId int NOT NULL,
ownerType char(3),
tag varchar(15) NULL,
);
package tdt4140.gr1800.app.core;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import tdt4140.gr1800.app.doc.IDocumentStorage;
import tdt4140.gr1800.app.json.GeoLocationsStreamPersistenceTest;
public class AppTest {
private App app;
@Before
public void setUp() {
app = new App();
}
@Test
public void testNewDocument() {
IDocumentStorage<File> documentStorage = app.getDocumentStorage();
documentStorage.newDocument();
Assert.assertFalse(app.getGeoLocationNames().iterator().hasNext());
Assert.assertNull(documentStorage.getDocumentLocation());
}
protected void testLoadDocument(File file) {
IDocumentStorage<File> documentStorage = app.getDocumentStorage();
try {
documentStorage.openDocument(file);
} catch (IOException e) {
Assert.fail("Couldn't open " + file);
}
Assert.assertEquals(file, documentStorage.getDocumentLocation());
GeoLocationsStreamPersistenceTest.testGeoLocationsDotJson(app.getGeoLocations((String[]) null));
}
@Test
public void testLoadDocument() {
URL url = getClass().getResource("geoLocations.json");
Assert.assertEquals("Not file URL", "file", url.getProtocol());
File file = new File(url.getPath());
testLoadDocument(file);
}
@Test
public void testSaveDocument() {
testLoadDocument();
try {
IDocumentStorage<File> documentStorage = app.getDocumentStorage();
File tempFile = File.createTempFile("geoLocations", ".json");
tempFile.deleteOnExit();
documentStorage.setDocumentLocation(tempFile);
documentStorage.saveDocument();
testLoadDocument(tempFile);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
}
}
package tdt4140.gr1800.app.core;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class GeoLocationTest extends TimedTaggedTest {
private GeoLocation geoLocation;
@Before
public void setUp() {
setUp(geoLocation = new GeoLocation());
}
@Test
public void testSetLatLong() {
LatLong latLong = new LatLong(63, 10);
geoLocation.setLatLong(latLong);
Assert.assertEquals(latLong, geoLocation.getLatLong());
}
}
package tdt4140.gr1800.app.core;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class GeoLocationsOwnerTest {
private GeoLocationsOwner owner;
@Before
public void setUp() {
this.owner = new GeoLocationsOwner();
}
private static <T> void check(Iterable<T> iterable, T... ts) {
check(iterable, false, ts);
}
private static <T> void check(Iterable<T> iterable, boolean anyOrder, T... ts) {
Collection<T> all = (anyOrder ? Arrays.asList(ts) : null);
int num = 0;
for (Iterator<T> it = iterable.iterator(); it.hasNext(); num++) {
Assert.assertTrue(num < ts.length);
T next = it.next();
if (anyOrder) {
assertTrue(all.contains(next));
} else {
Assert.assertEquals(ts[num], next);
}
}
Assert.assertTrue(num == ts.length);
}
private static int size(Iterable<?> iterable) {
int size = 0;
for (Iterator<?> it = iterable.iterator(); it.hasNext(); it.next()) {
size++;
}
return size;
}
@Test
public void testGetGeoLocationNames() {
Assert.assertEquals(0, size(owner.getGeoLocationsNames()));
owner.addGeolocations(new GeoLocations("test1"));
check(owner.getGeoLocationsNames(), "test1");
owner.addGeolocations(new GeoLocations("test2"));
check(owner.getGeoLocationsNames(), "test1", "test2");
}
@Test
public void testHasGeoLocations() {
Assert.assertTrue(owner.hasGeoLocations());
Assert.assertFalse(owner.hasGeoLocations("test1"));
owner.addGeolocations(new GeoLocations("test1"));
Assert.assertTrue(owner.hasGeoLocations());
Assert.assertTrue(owner.hasGeoLocations("test1"));
owner.addGeolocations(new GeoLocations("test2"));
Assert.assertTrue(owner.hasGeoLocations());
Assert.assertTrue(owner.hasGeoLocations("test1"));
Assert.assertTrue(owner.hasGeoLocations("test2"));
Assert.assertTrue(owner.hasGeoLocations("test1", "test2"));
}
@Test
public void testGetGeoLocations1() {
Assert.assertNull(owner.getGeoLocations("test1"));
GeoLocations geoLocations11 = new GeoLocations("test1");
owner.addGeolocations(geoLocations11);
Assert.assertSame(geoLocations11, owner.getGeoLocations("test1"));
GeoLocations geoLocations2 = new GeoLocations("test2");
owner.addGeolocations(geoLocations2);
Assert.assertSame(geoLocations11, owner.getGeoLocations("test1"));
Assert.assertSame(geoLocations2, owner.getGeoLocations("test2"));
GeoLocations geoLocations12 = new GeoLocations("test1");
owner.addGeolocations(geoLocations12);
Assert.assertNotNull(owner.getGeoLocations("test1"));
Assert.assertSame(geoLocations2, owner.getGeoLocations("test2"));
}
@Test
public void testGetGeoLocationsN() {
GeoLocations geoLocations11 = new GeoLocations("test1");
owner.addGeolocations(geoLocations11);
Assert.assertEquals(0, owner.getGeoLocations().size());
check(owner.getGeoLocations(new String[]{"test1"}), geoLocations11);
check(owner.getGeoLocations((String[]) null), geoLocations11);
GeoLocations geoLocations2 = new GeoLocations("test2");
owner.addGeolocations(geoLocations2);
Assert.assertEquals(0, owner.getGeoLocations().size());
check(owner.getGeoLocations(new String[]{"test1"}), geoLocations11);
check(owner.getGeoLocations(new String[]{"test2"}), geoLocations2);
check(owner.getGeoLocations((String[]) null), true, geoLocations11, geoLocations2);
GeoLocations geoLocations12 = new GeoLocations("test1");
owner.addGeolocations(geoLocations12);
Assert.assertEquals(0, owner.getGeoLocations().size());
check(owner.getGeoLocations(new String[]{"test1"}), true, geoLocations11, geoLocations12);
Assert.assertEquals(1, owner.getGeoLocations(new String[]{"test2"}).size());
check(owner.getGeoLocations((String[]) null), true, geoLocations11, geoLocations2, geoLocations12);
}
@Test
public void testRemoveGeoLocationsN() {
GeoLocations geoLocations11 = new GeoLocations("test1"), geoLocations2 = new GeoLocations("test2"), geoLocations12 = new GeoLocations("test1");
owner.addGeolocations(geoLocations11);
owner.addGeolocations(geoLocations2);
owner.addGeolocations(geoLocations12);
Assert.assertEquals(3, owner.getGeoLocations((String[]) null).size());
owner.removeGeolocations("test1");
check(owner.getGeoLocations((String[]) null), true, geoLocations2);
owner.removeGeolocations("test2");
Assert.assertEquals(0, owner.getGeoLocations((String[]) null).size());
}
@Test
public void testRemoveGeoLocations1() {
GeoLocations geoLocations11 = new GeoLocations("test1"), geoLocations2 = new GeoLocations("test2"), geoLocations12 = new GeoLocations("test1");
owner.addGeolocations(geoLocations11);
owner.addGeolocations(geoLocations2);
owner.addGeolocations(geoLocations12);
Assert.assertEquals(3, owner.getGeoLocations((String[]) null).size());
owner.removeGeolocations(geoLocations11);
check(owner.getGeoLocations((String[]) null), true, geoLocations12, geoLocations2);
owner.removeGeolocations(geoLocations2);
check(owner.getGeoLocations((String[]) null), geoLocations12);
owner.removeGeolocations(geoLocations12);
Assert.assertEquals(0, owner.getGeoLocations((String[]) null).size());
}
}
package tdt4140.gr1800.app.core;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import tdt4140.gr1800.app.json.GeoLocationsJsonPersistence;
public class GeoLocationsPersistenceTest {
private GeoLocationsPersistence persistence;
@Before
public void setUp() {
persistence = new GeoLocationsJsonPersistence();
}
@Test
public void testLoadLocations() {
testLoadLocations(getClass().getResourceAsStream("geoLocations.json"));
}
private void testLoadLocations(InputStream inputStream) {
try {
Collection<GeoLocations> geoLocations = persistence.loadLocations(inputStream);
Assert.assertEquals(2, geoLocations.size());
Iterator<GeoLocations> it = geoLocations.iterator();
GeoLocationsTest.assertGeoLocations(it.next(), new LatLong(63, 10), new LatLong(63.1, 10.1));
GeoLocationsTest.assertGeoLocations(it.next(), new LatLong(64, 11), new LatLong(64.1, 11.1));
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
@Test
public void testSaveLocations() {
Collection<GeoLocations> geoLocations = new ArrayList<GeoLocations>();
geoLocations.add(new GeoLocations("1", new LatLong(63, 10), new LatLong(63.1, 10.1)));
geoLocations.add(new GeoLocations("2", new LatLong(64, 11), new LatLong(64.1, 11.1)));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
persistence.saveLocations(geoLocations, outputStream);
outputStream.close();
testLoadLocations(new ByteArrayInputStream(outputStream.toByteArray()));
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
}
......@@ -7,13 +7,14 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class GeoLocationsTest {
public class GeoLocationsTest extends TimedTaggedTest {
private GeoLocations geoLocations;
@Override
@Before
public void setUp() {
geoLocations = new GeoLocations();
setUp(geoLocations = new GeoLocations());
}
@Test
......@@ -24,63 +25,76 @@ public class GeoLocationsTest {
Assert.assertEquals(2, new GeoLocations(new LatLong(0, 0), new LatLong(1, 1)).size());
}
private void assertGeoLocations(LatLong...latLongs) {
private void assertGeoLocations(final LatLong...latLongs) {
assertGeoLocations(geoLocations, latLongs);
}
public static void assertGeoLocations(GeoLocations geoLocations, LatLong...latLongs) {
Iterator<LatLong> it = geoLocations.iterator();
public static void assertGeoLocations(final GeoLocations geoLocations, final LatLong...latLongs) {
final Iterator<GeoLocated> it = geoLocations.iterator();
Assert.assertEquals(latLongs.length, geoLocations.size());
int pos = 0;
while (it.hasNext()) {
Assert.assertEquals(latLongs[pos], it.next());
checkGeoLocated(latLongs[pos], it.next());
pos++;
}
}
public static void assertGeoLocations(final GeoLocations geoLocations, final GeoLocations geoLocations2) {
final Iterator<GeoLocated> it = geoLocations.iterator(), it2 = geoLocations2.iterator();
while (it.hasNext()) {
Assert.assertTrue(it2.hasNext());
checkGeoLocated(it2.next(), it.next());
}
Assert.assertFalse(it2.hasNext());
}
@Test
public void testAddLocation() {
Assert.assertEquals(0, geoLocations.size());
LatLong latLong1 = new LatLong(0, 0);
final LatLong latLong1 = new LatLong(0, 0);
geoLocations.addLocation(latLong1);
assertGeoLocations(latLong1);
geoLocations.addLocation(new LatLong(0, 0));
assertGeoLocations(latLong1, latLong1);
LatLong latLong2 = new LatLong(1, 1);
final LatLong latLong2 = new LatLong(1, 1);
geoLocations.addLocation(latLong2);
assertGeoLocations(latLong1, latLong1, latLong2);
}
static void checkGeoLocated(final GeoLocated geoLoc1, final GeoLocated geoLoc2) {
Assert.assertTrue(geoLoc1.getLatLong().toString() + " expected, but was " + geoLoc2.getLatLong(), geoLoc1.equalsLatLong(geoLoc2));
}
@Test
public void testFindLocationsNearby() {
LatLong latLong = new LatLong(0, 0);
final LatLong latLong = new LatLong(0, 0);
Assert.assertTrue(geoLocations.findLocationsNearby(latLong, 0).isEmpty());
geoLocations.addLocation(latLong);
Collection<LatLong> locationsNearby = geoLocations.findLocationsNearby(latLong, 0);
final Collection<GeoLocated> locationsNearby = geoLocations.findLocationsNearby(latLong, 0);
Assert.assertEquals(1, locationsNearby.size());
Assert.assertEquals(latLong, geoLocations.iterator().next());
checkGeoLocated(latLong, geoLocations.iterator().next());
}
@Test
public void testFindNearestLocation() {
LatLong latLong = new LatLong(0, 0);
final LatLong latLong = new LatLong(0, 0);
Assert.assertNull(geoLocations.findNearestLocation(latLong));
geoLocations.addLocation(latLong);
LatLong nearestlocations = geoLocations.findNearestLocation(latLong);
Assert.assertEquals(latLong, nearestlocations);
final GeoLocated nearestlocations = geoLocations.findNearestLocation(latLong);
checkGeoLocated(latLong, nearestlocations);
}
@Test
public void testRemoveSameLocations() {
GeoLocations geoLocations1 = new GeoLocations(new LatLong(0, 0), new LatLong(1, 1));
final GeoLocations geoLocations1 = new GeoLocations(new LatLong(0, 0), new LatLong(1, 1));
Assert.assertEquals(2, geoLocations1.size());
geoLocations1.removeLocations(new LatLong(0, 0), 0.0);
Assert.assertEquals(1, geoLocations1.size());
geoLocations1.removeLocations(new LatLong(1, 1), 0.0);
Assert.assertEquals(0, geoLocations1.size());
GeoLocations geoLocations2 = new GeoLocations(new LatLong(0, 0), new LatLong(0, 0));
final GeoLocations geoLocations2 = new GeoLocations(new LatLong(0, 0), new LatLong(0, 0));
Assert.assertEquals(2, geoLocations2.size());
geoLocations2.removeLocations(new LatLong(0, 0), 0.0);
Assert.assertEquals(0, geoLocations2.size());
......
package tdt4140.gr1800.app.core;
import org.junit.Assert;
import org.junit.Test;
public class LatLongTest {
@Test
public void testToString() {
LatLong latLong = new LatLong(63.0, 10.0);
Assert.assertEquals(Double.toString(63) + "," + Double.toString(10), latLong.toString());
}
@Test
public void testValueOf() {
testLatLong(LatLong.valueOf("63.0, 10.0"), 63.0, 10.0);
testLatLong(LatLong.valueOf("63.0, 10.0", ","), 63.0, 10.0);
testLatLong(LatLong.valueOf("63.0; 10.0", ";"), 63.0, 10.0);
}
private void testLatLong(LatLong latLong, double lat, double lon) {
Assert.assertEquals(lat, latLong.latitude, 0.0);
Assert.assertEquals(lon, latLong.longitude, 0.0);
}
@Test
public void testEquals() {
Assert.assertTrue(new LatLong(63.0, 10.0).equals(new LatLong(63.0, 10.0)));
Assert.assertFalse(new LatLong(10.0, 63.0).equals(new LatLong(63.0, 10.0)));
Assert.assertFalse(new LatLong(10.0, 63.0).equals(null));
Assert.assertFalse(new LatLong(10.0, 63.0).equals("10.0, 63.0"));
}
}
package tdt4140.gr1800.app.core;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Arrays;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class TimedTaggedTest {
private TimedTaggedImpl timedTagged;
protected void setUp(TimedTaggedImpl timedTagged) {
this.timedTagged = timedTagged;
}
@Before
public void setUp() {
setUp(new TimedTaggedImpl());
}
@Test
public void testTaggedSetTime() {
LocalTime now = LocalTime.now();
timedTagged.setTime(now);
Assert.assertEquals(now, timedTagged.getTime());
}
@Test
public void testTaggedSetDate() {
LocalDate now = LocalDate.now();
timedTagged.setDate(now);
Assert.assertEquals(now, timedTagged.getDate());
}
@Test
public void testTaggedSetDateTime() {
LocalDateTime now = LocalDateTime.now();
timedTagged.setDateTime(now);
Assert.assertEquals(now.toLocalDate(), timedTagged.getDate());
Assert.assertEquals(now.toLocalTime(), timedTagged.getTime());
}
@Test
public void testTaggedValueOf() {
Assert.assertEquals("<en, to>", TimedTaggedImpl.valueOf("en; to", "; ").getTags("<", ", ", ">"));
Assert.assertEquals("<en, to>", TimedTaggedImpl.valueOf("en,to").getTags("<", ", ", ">"));
}
@Test
public void testTaggedSet() {
timedTagged.setTags("en", "to");
Assert.assertTrue(timedTagged.hasTags("en"));
Assert.assertTrue(timedTagged.hasTags("to"));
timedTagged.setTags("tre");
Assert.assertFalse(timedTagged.hasTags("en"));
Assert.assertFalse(timedTagged.hasTags("to"));
Assert.assertTrue(timedTagged.hasTags("tre"));
}
@Test
public void testTaggedGet() {
Assert.assertEquals(0, timedTagged.getTags().length);
timedTagged.setTags("en", "to", "to");
String[] tags = timedTagged.getTags();
Assert.assertEquals(2, tags.length);
Arrays.sort(tags);
Arrays.equals(new String[] {"en", "to"}, tags);
}
@Test
public void testTaggedGet2() {
Assert.assertEquals("", timedTagged.getTags(null, null, null));
Assert.assertEquals("<>", timedTagged.getTags("<", null, ">"));
timedTagged.setTags("en", "to", "to");
Assert.assertEquals("ento", timedTagged.getTags(null, null, null));
Assert.assertEquals("<en, to>", timedTagged.getTags("<", ", ", ">"));
}
@Test
public void testTaggedAdd() {
timedTagged.addTags("en", "to");
Assert.assertTrue(timedTagged.hasTags("en"));
Assert.assertTrue(timedTagged.hasTags("to"));
Assert.assertTrue(timedTagged.hasTags("en", "to"));
timedTagged.addTags("tre");
Assert.assertTrue(timedTagged.hasTags("en", "to"));
Assert.assertTrue(timedTagged.hasTags("tre"));
}
@Test
public void testTaggedRemove() {
timedTagged.addTags("en", "en", "to");
timedTagged.removeTags("en");
Assert.assertFalse(timedTagged.hasTags("en"));
Assert.assertTrue(timedTagged.hasTags("to"));
timedTagged.removeTags("to");
Assert.assertFalse(timedTagged.hasTags("to"));
timedTagged.removeTags("tre");
Assert.assertFalse(timedTagged.hasTags("tre"));
}
}
package tdt4140.gr1800.app.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Collection;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import tdt4140.gr1800.app.core.GeoLocations;
import tdt4140.gr1800.app.core.Person;
public class HsqldbAccessTest {
private Connection dbCon;
private AbstractDbAccessImpl dbAccess;
private static int testNum = 0;
@Before
public void setUp() throws Exception {
Class.forName("org.hsqldb.jdbc.JDBCDriver");
dbCon = DriverManager.getConnection("jdbc:hsqldb:mem:" + HsqldbAccessTest.class.getName() + testNum, "SA", "");
final DbAccessImpl dbAccess = new DbAccessImpl(dbCon);
dbAccess.executeStatements("schema.sql", false);
this.dbAccess = dbAccess;
testNum++;
}
@After
public void tearDown() {
if (dbCon != null) {
try {
dbCon.close();
} catch (final SQLException e) {
}
}
}
protected void checkPersonData(final Person hal, final Person dbHal) {
Assert.assertNotNull(dbHal);
Assert.assertEquals(hal.getName(), dbHal.getName());
Assert.assertEquals(hal.getEmail(), dbHal.getEmail());
}
@Test
public void testCreatePersonGetAllPersons() {
final Person hal = dbAccess.createPerson("hal", "hal@ntnu.no");
final Collection<Person> persons = dbAccess.getAllPersons(false);
Assert.assertEquals(1, persons.size());
checkPersonData(hal, persons.iterator().next());
dbAccess.personIds.clear();
final Collection<Person> dbPersons = dbAccess.getAllPersons(true);
Assert.assertEquals(1, dbPersons.size());
checkPersonData(hal, dbPersons.iterator().next());
}
@Test
public void testCreatePersonGetPerson() {
final Person hal = dbAccess.createPerson("hal", "hal@ntnu.no");
final int id = dbAccess.getId(hal);
final Person dbHal = dbAccess.getPerson(id, true);
checkPersonData(hal, dbHal);
Assert.assertSame(dbHal, dbAccess.getPerson(id, false));
}
@Test
public void testCreatePersonGetPersonByName() {
final Person hal = dbAccess.createPerson("hal", "hal@ntnu.no");
final Person dbHal = dbAccess.getPersonByName(hal.getName(), true);
checkPersonData(hal, dbHal);
}
@Test
public void testCreatePersonGetPersonByEmail() {
final Person hal = dbAccess.createPerson("hal", "hal@ntnu.no");
final Person dbHal = dbAccess.getPersonByEmail(hal.getEmail(), true);
checkPersonData(hal, dbHal);
}
@Test
public void testCreatePersonUpdatePerson() {
final Person hal = dbAccess.createPerson("hal", "hal@ntnu.no");
final int id = dbAccess.getId(hal);
hal.setName("Hallvard");
hal.setEmail("hallvard.traetteberg@gmail.com");
dbAccess.updatePersonData(hal);
final Person dbHal = dbAccess.getPerson(id, true);
checkPersonData(hal, dbHal);
}
@Test
public void testCreatePersonDeletePerson() {
final Person hal = dbAccess.createPerson("hal", "hal@ntnu.no");
dbAccess.deletePerson(hal);
final Collection<Person> persons = dbAccess.getAllPersons(true);
Assert.assertEquals(0, persons.size());
}
@Test
public void testCreatePersonCreateGeoLocationsGetGeoLocations() {
final Person hal = dbAccess.createPerson("hal", "hal@ntnu.no");
// no GeoLocations so far
Assert.assertEquals(0, dbAccess.getGeoLocations(hal, false).size());
final GeoLocations geoLocations1 = dbAccess.createGeoLocations(hal);
// check we have one locally
Assert.assertEquals(1, hal.getGeoLocations((String[]) null).size());
final Collection<GeoLocations> geoLocations = dbAccess.getGeoLocations(hal, false);
Assert.assertEquals(1, hal.getGeoLocations((String[]) null).size());
Assert.assertEquals(1, geoLocations.size());
Assert.assertSame(geoLocations1, geoLocations.iterator().next());
dbAccess.geoLocationsIds.clear();
// check we have one in the db
final Collection<GeoLocations> dbGeoLocations = dbAccess.getGeoLocations(hal, true);
Assert.assertEquals(1, hal.getGeoLocations((String[]) null).size());
Assert.assertEquals(1, dbGeoLocations.size());
}
@Test
public void testCreatePersonCreateUpdateGeoLocationsGetGeoLocations() {
final Person hal = dbAccess.createPerson("hal", "hal@ntnu.no");
final GeoLocations geoLocations1 = dbAccess.createGeoLocations(hal);
geoLocations1.setName("geoLocs1");
geoLocations1.setDescription("my first geo-location");
geoLocations1.setDate(LocalDate.of(2018, 3, 14));
geoLocations1.setTime(LocalTime.of(11, 14));
geoLocations1.setZone("Europe/Oslo");
final String[] tags = {"tag1", "tag2"};
geoLocations1.addTags(tags);
dbAccess.updateGeoLocationsData(geoLocations1);
dbAccess.geoLocationsIds.clear();
// check the db
final Collection<GeoLocations> dbGeoLocations = dbAccess.getGeoLocations(hal, true);
Assert.assertEquals(1, hal.getGeoLocations((String[]) null).size());
Assert.assertEquals(1, dbGeoLocations.size());
final GeoLocations dbGeoLocations1 = dbGeoLocations.iterator().next();
Assert.assertEquals(geoLocations1.getName(), dbGeoLocations1.getName());
Assert.assertEquals(geoLocations1.getDescription(), dbGeoLocations1.getDescription());
Assert.assertEquals(geoLocations1.getDate(), dbGeoLocations1.getDate());
Assert.assertEquals(geoLocations1.getTime(), dbGeoLocations1.getTime());
Assert.assertEquals(geoLocations1.getZone(), dbGeoLocations1.getZone());
Assert.assertEquals(2, dbGeoLocations1.getTags().length);
Assert.assertTrue(dbGeoLocations1.hasTags(tags));
}
@Test
public void testCreatePersonCreateGeoLocationsDeleteGeoLocations() {
final Person hal = dbAccess.createPerson("hal", "hal@ntnu.no");
final GeoLocations geoLocations = dbAccess.createGeoLocations(hal);
final Collection<GeoLocations> dbGeoLocations = dbAccess.getGeoLocations(hal, true);
Assert.assertEquals(1, dbGeoLocations.size());
dbAccess.deleteGeoLocations(geoLocations);
}
}
package tdt4140.gr1800.app.gpx;
import java.util.Collection;
import java.util.Iterator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import io.jenetics.jpx.GPX;
import tdt4140.gr1800.app.core.GeoLocations;
import tdt4140.gr1800.app.gpx.GpxDocumentConverter;
import tdt4140.gr1800.app.gpx.GpxDocumentLoader;
public class GpxPersistenceTest {
private GpxDocumentLoader loader;
private GpxDocumentConverter converter;
@Before
public void setUp() {
loader = new GpxDocumentLoader();
converter = new GpxDocumentConverter();
}
@Test
public void testLoadDocument() {
try {
GPX gpx = loader.loadDocument(getClass().getResourceAsStream("sample1.gpx"));
Assert.assertEquals(1, gpx.getTracks().size());
Assert.assertEquals(1, gpx.getTracks().get(0).getSegments().size());
Assert.assertEquals(3, gpx.getTracks().get(0).getSegments().get(0).getPoints().size());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
@Test
public void testConvertSample1() {
try {
GPX gpx = loader.loadDocument(getClass().getResourceAsStream("sample1.gpx"));
Collection<GeoLocations> geoLocations = converter.convert(gpx);
Assert.assertEquals(1, geoLocations.size());
GeoLocations track = geoLocations.iterator().next();
Assert.assertEquals("Example GPX Document", track.getName());
Assert.assertEquals(3, track.size());
Assert.assertTrue(track.isPath());
} catch (Exception e) {
System.err.println(e);
Assert.fail(e.getMessage());
}
}
@Test
public void testConvertAchterbroekRoute() {
try {
GPX gpx = loader.loadDocument(getClass().getResourceAsStream("Achterbroek-route.gpx"));
Collection<GeoLocations> geoLocations = converter.convert(gpx);
Assert.assertEquals(2, geoLocations.size());
Iterator<GeoLocations> iterator = geoLocations.iterator();
GeoLocations route = iterator.next();
Assert.assertEquals("Achterbroek naar De Maatjes 13 km RT", route.getName());
Assert.assertEquals(19, route.size());
Assert.assertTrue(route.isPath());
GeoLocations waypoints = iterator.next();
Assert.assertEquals("Achterbroek naar De Maatjes 13 km RT", route.getName());
Assert.assertEquals(1, waypoints.size());
Assert.assertFalse(waypoints.isPath());
} catch (Exception e) {
System.err.println(e);
Assert.fail(e.getMessage());
}
}
@Test
public void testConvertAchterbroekTrack() {
try {
GPX gpx = loader.loadDocument(getClass().getResourceAsStream("Achterbroek-track.gpx"));
Collection<GeoLocations> geoLocations = converter.convert(gpx);
Assert.assertEquals(2, geoLocations.size());
Iterator<GeoLocations> iterator = geoLocations.iterator();
GeoLocations track = iterator.next();
Assert.assertEquals("Achterbroek naar De Maatjes 13 km TR", track.getName());
Assert.assertEquals(26, track.size());
Assert.assertTrue(track.isPath());
GeoLocations waypoints = iterator.next();
Assert.assertEquals(1, waypoints.size());
Assert.assertFalse(waypoints.isPath());
} catch (Exception e) {
System.err.println(e);
Assert.fail(e.getMessage());
}
}
}
package tdt4140.gr1800.app.json;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import tdt4140.gr1800.app.core.GeoLocations;
import tdt4140.gr1800.app.core.GeoLocationsStreamPersistence;
import tdt4140.gr1800.app.core.GeoLocationsTest;
import tdt4140.gr1800.app.core.LatLong;
public class GeoLocationsStreamPersistenceTest {
private GeoLocationsStreamPersistence persistence;
@Before
public void setUp() {
persistence = new GeoLocationsPersistence();
}
@Test
public void testLoadLocations() {
Collection<GeoLocations> geoLocations = null;
try {
geoLocations = persistence.loadLocations(getClass().getResourceAsStream("geoLocations.json"));
} catch (final Exception e) {
Assert.fail(e.getMessage());
}
testGeoLocationsDotJson(geoLocations);
}
public static Collection<GeoLocations> createGeoLocationsDotJson() {
return Arrays.asList(
new GeoLocations("1", new LatLong(63, 10), new LatLong(63.1, 10.1)),
new GeoLocations("2", new LatLong(64, 11), new LatLong(64.1, 11.1))
);
}
public static void testGeoLocationsDotJson(final Collection<GeoLocations> geoLocations) {
Assert.assertEquals(2, geoLocations.size());
final Iterator<GeoLocations> it = geoLocations.iterator();
GeoLocationsTest.assertGeoLocations(it.next(), new LatLong(63, 10), new LatLong(63.1, 10.1));
GeoLocationsTest.assertGeoLocations(it.next(), new LatLong(64, 11), new LatLong(64.1, 11.1));
}
@Test
public void testSaveLocations() {
final Collection<GeoLocations> geoLocations = createGeoLocationsDotJson();
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Collection<GeoLocations> geoLocations2 = null;
try {
persistence.saveLocations(geoLocations, outputStream);
outputStream.close();
geoLocations2 = persistence.loadLocations(new ByteArrayInputStream(outputStream.toByteArray()));
} catch (final Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
testGeoLocationsDotJson(geoLocations2);
}
}
<?xml version="1.0"?>
<gpx
version="1.0"
creator="VB Net GPS: vermeiren-willy@pandora.be"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
<metadata>
<bounds minlat="51.396017" minlon="4.498043" maxlat="51.430402" maxlon="4.556108"/>
</metadata>
<wpt lat="51.39709" lon="4.501519">
<name>START</name>
</wpt>
<rte>
<name>Achterbroek naar De Maatjes 13 km RT</name>
<rtept lat="51.39709" lon="4.501519">
<name>1</name>
<cmt>1</cmt>
</rtept>
<rtept lat="51.398635" lon="4.502678">
<name>2</name>
<cmt>2</cmt>
</rtept>
<rtept lat="51.405072" lon="4.498043">
<name>3</name>
<cmt>3</cmt>
</rtept>
<rtept lat="51.417346" lon="4.515038">
<name>4</name>
<cmt>4</cmt>
</rtept>
<rtept lat="51.41932" lon="4.513879">
<name>5</name>
<cmt>5</cmt>
</rtept>
<rtept lat="51.421552" lon="4.523535">
<name>6</name>
<cmt>6</cmt>
</rtept>
<rtept lat="51.423011" lon="4.522848">
<name>7</name>
<cmt>7</cmt>
</rtept>
<rtept lat="51.423826" lon="4.5295">
<name>8</name>
<cmt>8</cmt>
</rtept>
<rtept lat="51.427002" lon="4.528513">
<name>9</name>
<cmt>9</cmt>
</rtept>
<rtept lat="51.430402" lon="4.552363">
<name>10</name>
<cmt>10</cmt>
</rtept>
<rtept lat="51.426229" lon="4.555399">
<name>11</name>
<cmt>11</cmt>
</rtept>
<rtept lat="51.426015" lon="4.554734">
<name>12</name>
<cmt>12</cmt>
</rtept>
<rtept lat="51.423569" lon="4.556108">
<name>13</name>
<cmt>13</cmt>
</rtept>
<rtept lat="51.41932" lon="4.546237">
<name>14</name>
<cmt>14</cmt>
</rtept>
<rtept lat="51.410952" lon="4.534092">
<name>15</name>
<cmt>15</cmt>
</rtept>
<rtept lat="51.406231" lon="4.543018">
<name>16</name>
<cmt>16</cmt>
</rtept>
<rtept lat="51.396695" lon="4.515966">
<name>17</name>
<cmt>17</cmt>
</rtept>
<rtept lat="51.396017" lon="4.515853">
<name>18</name>
<cmt>18</cmt>
</rtept>
<rtept lat="51.397133" lon="4.502635">
<name>19</name>
<cmt>19</cmt>
</rtept>
</rte>
</gpx>
<?xml version="1.0"?>
<gpx
version="1.0"
creator="VB Net GPS: vermeiren-willy@pandora.be"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
<metadata>
<bounds minlat="51.396017" minlon="4.498043" maxlat="51.430402" maxlon="4.556108"/>
</metadata>
<wpt lat="51.39709" lon="4.501519">
<name>START</name>
</wpt>
<trk>
<name>Achterbroek naar De Maatjes 13 km TR</name>
<trkseg>
<trkpt lat="51.39709" lon="4.501519">
<name>1</name>
</trkpt>
<trkpt lat="51.397705" lon="4.501452">
<name>2</name>
</trkpt>
<trkpt lat="51.398635" lon="4.502678">
<name>3</name>
</trkpt>
<trkpt lat="51.404042" lon="4.498472">
<name>4</name>
</trkpt>
<trkpt lat="51.405072" lon="4.498043">
<name>5</name>
</trkpt>
<trkpt lat="51.405456" lon="4.499259">
<name>6</name>
</trkpt>
<trkpt lat="51.417346" lon="4.515038">
<name>7</name>
</trkpt>
<trkpt lat="51.41932" lon="4.513879">
<name>8</name>
</trkpt>
<trkpt lat="51.421552" lon="4.523535">
<name>9</name>
</trkpt>
<trkpt lat="51.423011" lon="4.522848">
<name>10</name>
</trkpt>
<trkpt lat="51.423826" lon="4.5295">
<name>11</name>
</trkpt>
<trkpt lat="51.427002" lon="4.528513">
<name>12</name>
</trkpt>
<trkpt lat="51.427131" lon="4.534478">
<name>13</name>
</trkpt>
<trkpt lat="51.426819" lon="4.53744">
<name>14</name>
</trkpt>
<trkpt lat="51.430402" lon="4.552363">
<name>15</name>
</trkpt>
<trkpt lat="51.426229" lon="4.555399">
<name>16</name>
</trkpt>
<trkpt lat="51.426015" lon="4.554734">
<name>17</name>
</trkpt>
<trkpt lat="51.423569" lon="4.556108">
<name>18</name>
</trkpt>
<trkpt lat="51.423097" lon="4.553981">
<name>19</name>
</trkpt>
<trkpt lat="51.41932" lon="4.546237">
<name>20</name>
</trkpt>
<trkpt lat="51.410952" lon="4.534092">
<name>21</name>
</trkpt>
<trkpt lat="51.406231" lon="4.543018">
<name>22</name>
</trkpt>
<trkpt lat="51.396695" lon="4.515966">
<name>23</name>
</trkpt>
<trkpt lat="51.396017" lon="4.515853">
<name>24</name>
</trkpt>
<trkpt lat="51.396858" lon="4.506495">
<name>25</name>
</trkpt>
<trkpt lat="51.397133" lon="4.502635">
<name>26</name>
</trkpt>
</trkseg>
</trk>
</gpx>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="Oregon 400t" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">
<metadata>
<link href="http://www.garmin.com">
<text>Garmin International</text>
</link>
<time>2009-10-17T22:58:43Z</time>
</metadata>
<trk>
<name>Example GPX Document</name>
<trkseg>
<trkpt lat="47.644548" lon="-122.326897">
<ele>4.46</ele>
<time>2009-10-17T18:37:26Z</time>
</trkpt>
<trkpt lat="47.644548" lon="-122.33">
<ele>4.94</ele>
<time>2009-10-17T18:37:31Z</time>
</trkpt>
<trkpt lat="47.65" lon="-122.33">
<ele>6.87</ele>
<time>2009-10-17T18:37:34Z</time>
</trkpt>
</trkseg>
</trk>
</gpx>
# app.ui module - JavaFX app for example project
package tdt4140.gr1800.app.ui;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.Optional;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextInputDialog;
import javafx.stage.FileChooser;
import tdt4140.gr1800.app.core.IDocumentStorage;
import tdt4140.gr1800.app.doc.IDocumentImporter;
import tdt4140.gr1800.app.doc.IDocumentStorage;
public class FileMenuController {
private IDocumentStorage<File> documentStorage;
IDocumentStorage<File> documentStorage;
public void setDocumentStorage(IDocumentStorage<File> documentStorage) {
this.documentStorage = documentStorage;
}
private Consumer<IDocumentStorage<File>> onDocumentChanged;
public void setOnDocumentChanged(Consumer<IDocumentStorage<File>> onDocumentChanged) {
this.onDocumentChanged = onDocumentChanged;
}
@FXML
public void handleNewAction() {
documentStorage.newDocument();
fireDocumentChanged();
}
private void fireDocumentChanged() {
if (onDocumentChanged != null) {
onDocumentChanged.accept(documentStorage);
}
}
private List<File> recentFiles = new ArrayList<File>();
......@@ -58,7 +51,7 @@ public class FileMenuController {
private FileChooser fileChooser;
protected FileChooser getFileChooser() {
FileChooser getFileChooser() {
if (fileChooser == null) {
fileChooser = new FileChooser();
}
......@@ -79,29 +72,40 @@ public class FileMenuController {
selection = fileChooser.showOpenDialog(null);
}
if (selection != null) {
handleOpenAction(selection);
}
}
void handleOpenAction(File selection) {
try {
documentStorage.openDocument(selection);
updateRecentMenu(selection);
fireDocumentChanged();
} catch (IOException e) {
// TODO
}
}
}
@FXML
public void handleSaveAction() {
if (documentStorage.getDocumentLocation() == null) {
handleSaveAsAction();
} else {
try {
documentStorage.saveDocument();
} catch (IOException e) {
// TODO
}
}
}
@FXML
public void handleSaveAsAction() {
FileChooser fileChooser = getFileChooser();
File selection = fileChooser.showSaveDialog(null);
handleSaveAsAction(selection);
}
void handleSaveAsAction(File selection) {
File oldStorage = documentStorage.getDocumentLocation();
try {
documentStorage.setDocumentLocation(selection);
......@@ -116,6 +120,10 @@ public class FileMenuController {
public void handleSaveCopyAsAction() {
FileChooser fileChooser = getFileChooser();
File selection = fileChooser.showSaveDialog(null);
handleSaveCopyAsAction(selection);
}
void handleSaveCopyAsAction(File selection) {
File oldStorage = documentStorage.getDocumentLocation();
try {
documentStorage.setDocumentLocation(selection);
......@@ -126,4 +134,67 @@ public class FileMenuController {
documentStorage.setDocumentLocation(oldStorage);
}
}
@FXML
public void handleFileImportAction() {
FileChooser fileChooser = getFileChooser();
File selection = fileChooser.showOpenDialog(null);
// String path = selection.getPath();
// int pos = path.lastIndexOf('.');
// String ext = (pos > 0 ? path.substring(pos + 1) : null);
handleFileImportAction(selection);
}
void handleFileImportAction(File selection) {
for (IDocumentImporter importer : documentStorage.getDocumentImporters()) {
try (InputStream input = new FileInputStream(selection)) {
importer.importDocument(input);
break;
} catch (Exception e) {
}
}
}
private TextInputDialog inputDialog;
@FXML
public void handleURLImportAction() {
if (inputDialog == null) {
inputDialog = new TextInputDialog();
}
inputDialog.setTitle("Import from URL");
inputDialog.setHeaderText("Enter URL to import from");
inputDialog.setContentText("Enter URL: ");
// https://developer.garmin.com/downloads/connect-api/sample_file.gpx
URL url = null;
while (url == null) {
Optional<String> result = inputDialog.showAndWait();
if (! result.isPresent()) {
return;
}
try {
url = new URL(result.get());
if (handleURLImportAction(url)) {
return;
}
url = null;
inputDialog.setHeaderText("Problems reading it...");
inputDialog.setContentText("Enter another URL: ");
} catch (MalformedURLException e1) {
inputDialog.setContentText("Enter a valid URL: ");
}
}
}
boolean handleURLImportAction(URL url) {
for (IDocumentImporter importer : documentStorage.getDocumentImporters()) {
try (InputStream input = url.openStream()) {
importer.importDocument(input);
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
return false;
}
}
package tdt4140.gr1800.app.ui;
import java.io.File;
import java.util.Collection;
import java.util.Iterator;
import fxmapcontrol.Location;
import fxmapcontrol.MapBase;
import fxmapcontrol.MapItemsControl;
import fxmapcontrol.MapNode;
import fxmapcontrol.MapTileLayer;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Slider;
import tdt4140.gr1800.app.core.App;
import tdt4140.gr1800.app.core.GeoLocated;
import tdt4140.gr1800.app.core.GeoLocations;
import tdt4140.gr1800.app.core.LatLong;
import tdt4140.gr1800.app.doc.IDocumentListener;
import tdt4140.gr1800.app.doc.IDocumentStorage;
public class FxAppController {
public class FxAppController implements IDocumentListener<Collection<GeoLocations>, File> {
@FXML
private FileMenuController fileMenuController;
FileMenuController fileMenuController;
@FXML
private ComboBox<String> geoLocationsSelector;
@FXML
private MapBase mapView;
MapBase mapView;
private MapItemsControl<MapNode> markersParent;
MapItemsControl<MapNode> markersParent;
@FXML
private Slider zoomSlider;
......@@ -34,27 +41,50 @@ public class FxAppController {
@FXML
public void initialize() {
app = new App();
fileMenuController.setDocumentStorage(app.getDocumentStorage());
fileMenuController.setOnDocumentChanged(documentStorage -> initMapMarkers());
IDocumentStorage<File> documentStorage = app.getDocumentStorage();
fileMenuController.setDocumentStorage(documentStorage);
documentStorage.addDocumentStorageListener(this);
geoLocationsSelector.getSelectionModel().selectedItemProperty().addListener((stringProperty, oldValue, newValue) -> updateGeoLocations());
mapView.getChildren().add(MapTileLayer.getOpenStreetMapLayer());
mapView.zoomLevelProperty().bind(zoomSlider.valueProperty());
zoomSlider.valueProperty().addListener((prop, oldValue, newValue) -> {
mapView.setZoomLevel(zoomSlider.getValue());
});
markersParent = new MapItemsControl<MapNode>();
mapView.getChildren().add(markersParent);
}
//
@Override
public void documentLocationChanged(File documentLocation, File oldDocumentLocation) {
}
@Override
public void documentChanged(Collection<GeoLocations> document, Collection<GeoLocations> oldDocument) {
if (Platform.isFxApplicationThread()) {
initMapMarkers();
} else {
Platform.runLater(() -> initMapMarkers());
}
}
//
private Object updateGeoLocations() {
return null;
}
private IMapMarkerProvider mapMarkerProvider = new TagBasedMapMarkerProvider();
private void initMapMarkers() {
markersParent.getItems().clear();
geoLocationsSelector.getItems().clear();
for (String geoLocationName : app.getGeoLocationNames()) {
GeoLocations geoLocations = app.getGeoLocations(geoLocationName);
MapMarker lastMarker = null;
for (LatLong latLong : geoLocations) {
MapMarker mapMarker = new MapMarker(latLong);
for (GeoLocated geoLoc : geoLocations) {
MapMarker mapMarker = mapMarkerProvider.getMapMarker(geoLoc, geoLocations);
markersParent.getItems().add(mapMarker);
if (geoLocations.isPath() && lastMarker != null) {
MapPathLine pathLine = new MapPathLine(lastMarker, mapMarker);
......@@ -62,10 +92,10 @@ public class FxAppController {
}
lastMarker = mapMarker;
}
geoLocationsSelector.getItems().add(geoLocationName);
geoLocationsSelector.getItems().add(geoLocationName + " (" + geoLocations.size() + ")");
}
LatLong center = getCenter(null);
System.out.println("Map markers initialized");
mapView.setCenter(new Location(center.latitude, center.longitude));
}
private LatLong getCenter(GeoLocations geoLocations) {
......@@ -79,8 +109,8 @@ public class FxAppController {
if (names != null) {
geoLocations = app.getGeoLocations(names.next());
}
for (LatLong latLong : geoLocations) {
double lat = latLong.latitude, lon = latLong.longitude;
for (GeoLocated geoLoc : geoLocations) {
double lat = geoLoc.getLatitude(), lon = geoLoc.getLongitude();
latSum += lat;
lonSum += lon;
num++;
......
package tdt4140.gr1800.app.ui;
import tdt4140.gr1800.app.core.GeoLocated;
import tdt4140.gr1800.app.core.GeoLocations;
public interface IMapMarkerProvider {
public MapMarker getMapMarker(GeoLocated geoLoc, GeoLocations geoLocations);
}