Initial commit

The initial commit on GitHub
This commit is contained in:
Andreas Billmann
2013-09-18 20:44:20 +02:00
parent 6c7c5de92d
commit 54aafa6120
157 changed files with 4603 additions and 5 deletions

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.application;
/**
* @author Andreas
*/
public class ProgressEvent {
public enum State {INITIALIZED, STARTED, RUNNING, FINISHED}
;
public static final double INDETERMINATE_PROGRESS = -1.0;
private final String module;
private final State state;
private final String message;
private final Double progress;
public ProgressEvent(String module, State state, String message) {
this(module, state, message, INDETERMINATE_PROGRESS);
}
public ProgressEvent(String module, State state, String message, Double progress) {
this.module = module;
this.state = state;
this.message = message;
this.progress = progress;
}
public String getModule() {
return module;
}
public State getState() {
return state;
}
public String getMessage() {
return message;
}
public Double getProgress() {
return progress;
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.application;
/**
* @author Andreas
*/
public interface ProgressListener {
void progress(ProgressEvent event);
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.application;
import de.frosch95.geofrogger.gpx.GPXReader;
import de.frosch95.geofrogger.gpx.GroundspeakGPXReader;
import de.frosch95.geofrogger.service.CacheService;
import de.frosch95.geofrogger.service.CacheServiceImpl;
import de.frosch95.geofrogger.sql.DatabaseService;
import de.frosch95.geofrogger.sql.DatabaseServiceImpl;
/**
* @author Andreas
*/
public class ServiceManager {
private static final ServiceManager INSTANCE = new ServiceManager();
private GPXReader gpxReader;
private DatabaseService databaseService;
private CacheService cacheService;
private ServiceManager() {
// private for singleton pattern
}
public static ServiceManager getInstance() {
return INSTANCE;
}
public synchronized GPXReader getGPXReader() {
if (gpxReader == null) {
gpxReader = new GroundspeakGPXReader();
}
return gpxReader;
}
public synchronized DatabaseService getDatabaseService() {
if (databaseService == null) {
databaseService = new DatabaseServiceImpl();
}
return databaseService;
}
public synchronized CacheService getCacheService() {
if (cacheService == null) {
cacheService = new CacheServiceImpl();
}
return cacheService;
}
}

View File

@@ -0,0 +1,90 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.application;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Andreas
*/
public class SessionContext {
private static final SessionContext INSTANCE = new SessionContext();
private final Map<String, Object> map = new ConcurrentHashMap<>();
private final Map<String, List<SessionContextListener>> sessionListeners = new HashMap<>();
private SessionContext() {
}
public static SessionContext getInstance() {
return INSTANCE;
}
public void setData(String key, Object value) {
if (value == null && map.containsKey(key)) {
map.remove(key);
} else if (value != null) {
map.put(key, value);
}
fireSessionEvent(key);
}
public Object getData(String key) {
if (map.containsKey(key)) {
return map.get(key);
} else {
return null;
}
}
public void addListener(String key, SessionContextListener sessionListener) {
List<SessionContextListener> listenerList;
if (sessionListeners.containsKey(key)) {
listenerList = sessionListeners.get(key);
} else {
listenerList = new ArrayList<>();
sessionListeners.put(key, listenerList);
}
if (!listenerList.contains(sessionListener)) {
listenerList.add(sessionListener);
}
}
private void fireSessionEvent(String key) {
if (sessionListeners.containsKey(key)) {
final List<SessionContextListener> listenerList = sessionListeners.get(key);
for (final SessionContextListener listener : listenerList) {
listener.sessionContextChanged();
}
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.application;
/**
* @author Andreas
*/
public interface SessionContextListener {
void sessionContextChanged();
}

View File

@@ -0,0 +1,246 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx;
import de.frosch95.geofrogger.application.SessionContext;
import de.frosch95.geofrogger.application.SessionContextListener;
import de.frosch95.geofrogger.fx.components.GeocachingIcons;
import de.frosch95.geofrogger.fx.components.IconManager;
import de.frosch95.geofrogger.model.Cache;
import javafx.animation.FadeTransition;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.util.Duration;
import jfxtras.labs.map.render.ImageMapMarker;
import jfxtras.labs.map.render.MapMarkable;
import java.net.URL;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.ResourceBundle;
/**
* FXML Controller class
*
* @author Andreas
*/
public class CacheDetailsController implements Initializable, SessionContextListener {
@FXML
private AnchorPane cacheDetailPane;
@FXML
private Label cacheNameHeader;
@FXML
private Label detailsIconHeader;
@FXML
private TextField cacheName;
@FXML
private Slider difficultySlider;
@FXML
private Slider terrainSlider;
@FXML
private TextField placedByTextfield;
@FXML
private TextField ownerTextfield;
@FXML
private MapPaneWrapper mapPaneWrapper;
@FXML
private DatePicker date;
@FXML
private TextField typeTextfield;
@FXML
private TextField containerTextfield;
@FXML
private BorderPane shortDescriptionPane;
@FXML
private BorderPane longDescriptionPane;
@FXML
private CheckBox shortDescriptionHtml;
@FXML
private CheckBox longDescriptionHtml;
private ImageView icon;
private FadeTransition ft;
private TextArea shortDescriptionField;
private TextArea longDescriptionField;
private WebView shortDescriptionWebView;
private WebView longDescriptionWebView;
private final SessionContext sessionContext = SessionContext.getInstance();
/**
* Initializes the controller class.
*
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
setSessionListener();
cacheNameHeader.textProperty().bind(cacheName.textProperty());
detailsIconHeader.getStyleClass().add("cache-list-icon");
icon = new ImageView();
detailsIconHeader.setGraphic(icon);
cacheDetailPane.setOpacity(0.3);
shortDescriptionWebView = new WebView();
longDescriptionWebView = new WebView();
shortDescriptionField = new TextArea();
longDescriptionField = new TextArea();
editableForm(false);
initFading();
}
@Override
public void sessionContextChanged() {
Cache currentCache = (Cache) sessionContext.getData("current-cache");
if (currentCache != null) {
fillForm(currentCache);
fadeIn();
} else {
resetForm();
fadeOut();
}
}
private void setSessionListener() {
sessionContext.addListener("current-cache", this);
}
private void initFading() {
ft = new FadeTransition(Duration.millis(1000), cacheDetailPane);
ft.setCycleCount(1);
ft.setAutoReverse(false);
}
private void fadeIn() {
ft.setFromValue(0.3);
ft.setToValue(1.0);
ft.playFromStart();
}
private void fadeOut() {
ft.setFromValue(1.0);
ft.setToValue(0.3);
ft.playFromStart();
}
private void resetForm() {
cacheName.setText("");
difficultySlider.setValue(1.0);
terrainSlider.setValue(1.0);
detailsIconHeader.setText("");
placedByTextfield.setText("");
ownerTextfield.setText("");
date.setValue(LocalDate.now());
typeTextfield.setText("");
containerTextfield.setText("");
shortDescriptionPane.setCenter(null);
longDescriptionPane.setCenter(null);
// final double lat = currentCache.getMainWayPoint().getLatitude();
// final double lon = currentCache.getMainWayPoint().getLongitude();
// mapPaneWrapper.setDisplayPositionByLatLon(lat, lon, 15);
//
// MapMarkable marker = new ImageMapMarker(GeocachingIcons.getMapIcon(currentCache, IconManager.IconSize.BIG), lat, lon);
// mapPaneWrapper.setMapMarkerList(Arrays.asList(marker));
}
private void fillForm(Cache currentCache) throws NumberFormatException {
cacheName.setText(currentCache.getName());
difficultySlider.setValue(Double.parseDouble(currentCache.getDifficulty()));
terrainSlider.setValue(Double.parseDouble(currentCache.getTerrain()));
icon.setImage(GeocachingIcons.getIcon(currentCache));
placedByTextfield.setText(currentCache.getPlacedBy());
ownerTextfield.setText(currentCache.getOwner().getName());
date.setValue(currentCache.getMainWayPoint().getTime().toLocalDate());
typeTextfield.setText(currentCache.getType());
containerTextfield.setText(currentCache.getContainer());
fillShortDescription(currentCache);
fillLongDescription(currentCache);
fillMap(currentCache);
}
private void fillMap(Cache currentCache) {
final double lat = currentCache.getMainWayPoint().getLatitude();
final double lon = currentCache.getMainWayPoint().getLongitude();
mapPaneWrapper.setDisplayPositionByLatLon(lat, lon, 15);
MapMarkable marker = new ImageMapMarker(GeocachingIcons.getMapIcon(currentCache, IconManager.IconSize.BIG), lat, lon);
mapPaneWrapper.setMapMarkerList(Arrays.asList(marker));
}
private void fillShortDescription(Cache currentCache) {
Node shortDescriptionNode;
if (currentCache.isShortDescriptionHtml()) {
final WebEngine webEngine = shortDescriptionWebView.getEngine();
webEngine.loadContent(currentCache.getShortDescription());
shortDescriptionNode = shortDescriptionWebView;
} else {
shortDescriptionField.setText(currentCache.getShortDescription());
shortDescriptionNode = shortDescriptionField;
}
shortDescriptionPane.setCenter(shortDescriptionNode);
shortDescriptionHtml.setSelected(currentCache.isShortDescriptionHtml());
}
private void fillLongDescription(Cache currentCache) {
Node longDescriptionNode;
if (currentCache.isLongDescriptionHtml()) {
final WebEngine webEngine = longDescriptionWebView.getEngine();
webEngine.loadContent(currentCache.getLongDescription());
longDescriptionNode = longDescriptionWebView;
} else {
longDescriptionField.setText(currentCache.getLongDescription());
longDescriptionNode = longDescriptionField;
}
longDescriptionPane.setCenter(longDescriptionNode);
longDescriptionHtml.setSelected(currentCache.isLongDescriptionHtml());
}
private void editableForm(boolean editable) {
cacheName.setEditable(editable);
difficultySlider.setDisable(!editable);
terrainSlider.setDisable(!editable);
placedByTextfield.setEditable(editable);
ownerTextfield.setEditable(editable);
date.setDisable(!editable);
typeTextfield.setEditable(editable);
containerTextfield.setEditable(editable);
shortDescriptionHtml.setDisable(!editable);
longDescriptionHtml.setDisable(!editable);
shortDescriptionField.setEditable(editable);
longDescriptionField.setEditable(editable);
}
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx;
import de.frosch95.geofrogger.application.SessionContext;
import de.frosch95.geofrogger.application.SessionContextListener;
import de.frosch95.geofrogger.fx.components.AwesomeIcons;
import de.frosch95.geofrogger.fx.components.CacheListCell;
import de.frosch95.geofrogger.model.Cache;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.util.Callback;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import static de.frosch95.geofrogger.fx.JavaFXUtils.addClasses;
/**
* FXML Controller class
*
* @author Andreas
*/
public class CacheListController implements Initializable, SessionContextListener {
private static final String FONT_AWESOME = "FontAwesome";
private static final String CACHE_LIST_ACTION_ICONS = "cache-list-action-icons";
private final SessionContext sessionContext = SessionContext.getInstance();
@FXML
private ListView cacheListView;
@FXML
private Label cacheNumber;
@FXML
private Label filterIcon;
@FXML
private Label sortIcon;
/**
* Initializes the controller class.
*
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
setSessionListener();
setCellFactory();
cacheListView.getSelectionModel().selectedItemProperty().addListener(
(ChangeListener<Cache>) (ObservableValue<? extends Cache> ov, Cache oldValue, Cache newValue) ->
{
sessionContext.setData("current-cache", newValue);
}
);
filterIcon.setFont(Font.font(FONT_AWESOME, FontWeight.NORMAL, 16));
filterIcon.setText(AwesomeIcons.ICON_FILTER.toString());
addClasses(filterIcon, CACHE_LIST_ACTION_ICONS);
sortIcon.setFont(Font.font(FONT_AWESOME, FontWeight.NORMAL, 16));
sortIcon.setText(AwesomeIcons.ICON_SORT.toString());
addClasses(sortIcon, CACHE_LIST_ACTION_ICONS);
}
@Override
public void sessionContextChanged() {
List<Cache> caches = (List<Cache>) sessionContext.getData("cache-list");
Platform.runLater(() -> {
cacheNumber.setText("(" + caches.size() + ")");
cacheListView.getItems().setAll(caches);
});
}
private void setCellFactory() {
cacheListView.setCellFactory(
(Callback<ListView<Cache>, CacheListCell>)
(ListView<Cache> p) -> new CacheListCell());
}
private void setSessionListener() {
sessionContext.addListener("cache-list", this);
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx;
import de.frosch95.geofrogger.application.ServiceManager;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Andreas
*/
public class GeoFroggerFXMain extends Application {
@Override
public void start(Stage stage) throws Exception {
Font.loadFont(GeoFroggerFXMain.class.getResource("/fonts/fontawesome-webfont.ttf").toExternalForm(), 12);
Parent root = FXMLLoader.load(getClass().getResource("geofrogger.fxml"), ResourceBundle.getBundle("de.frosch95.geofrogger.fx.geofrogger"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@Override
public void stop() throws Exception {
try {
ServiceManager.getInstance().getDatabaseService().getConnection().close();
} catch (SQLException ex) {
Logger.getLogger(GeofroggerController.class.getName()).log(Level.SEVERE, null, ex);
}
super.stop();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}

View File

@@ -0,0 +1,232 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx;
import de.frosch95.geofrogger.application.ProgressEvent;
import de.frosch95.geofrogger.application.ServiceManager;
import de.frosch95.geofrogger.application.SessionContext;
import de.frosch95.geofrogger.gpx.GPXReader;
import de.frosch95.geofrogger.model.Cache;
import de.frosch95.geofrogger.service.CacheService;
import javafx.application.Platform;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TextArea;
import javafx.stage.FileChooser;
import org.controlsfx.dialog.Dialog;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* FXML Controller class
*
* @author Andreas
*/
public class GeofroggerController implements Initializable {
private static final String LICENSE = "/*\n" +
" * Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>\n" +
" * All rights reserved.\n" +
" *\n" +
" * Redistribution and use in source and binary forms, with or without\n" +
" * modification, are permitted provided that the following conditions are met:\n" +
" *\n" +
" * * Redistributions of source code must retain the above copyright notice, this\n" +
" * list of conditions and the following disclaimer.\n" +
" * * Redistributions in binary form must reproduce the above copyright notice,\n" +
" * this list of conditions and the following disclaimer in the documentation\n" +
" * and/or other materials provided with the distribution.\n" +
" *\n" +
" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n" +
" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n" +
" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n" +
" * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n" +
" * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n" +
" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n" +
" * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n" +
" * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n" +
" * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n" +
" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n" +
" * POSSIBILITY OF SUCH DAMAGE.\n" +
" */";
private static final String MASTHEAD_TEXT = "GeoFroggerFX by Andreas Billmann <abi@geofroggerfx.de>";
private static final String ABOUT_TEXT = "Used libs:\n"
+ "\t- JFXtras 8.0 r1\n"
+ "\t- ControlsFX 8.0.2 developer preview 1\n"
+ "\t- jdom 2.x\n"
+ "\t- H2 1.3.173\n"
+ "\t- Font Awesome by Dave Gandy\n"
+ "\t- Icons by http://iconmonstr.com/\n";
private final SessionContext sessionContext = SessionContext.getInstance();
private final LoadCachesFromFileService loadService = new LoadCachesFromFileService();
private final LoadCachesFromDatabaseService loadFromDBService = new LoadCachesFromDatabaseService();
private final GPXReader gpxReader = ServiceManager.getInstance().getGPXReader();
private final CacheService cacheService = ServiceManager.getInstance().getCacheService();
@FXML
private Label leftStatus;
@FXML
private ProgressBar progress;
/**
* Initializes the controller class.
*
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
gpxReader.addListener((ProgressEvent event) -> {
updateStatus(event.getMessage(), event.getProgress());
});
cacheService.addListener((ProgressEvent event) -> {
updateStatus(event.getMessage(), event.getProgress());
});
loadFromDBService.start();
}
@FXML
public void importGpx(ActionEvent actionEvent) {
final FileChooser fileChooser = new FileChooser();
//Set extension filter
final FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("GPX files (*.gpx)", "*.gpx");
fileChooser.getExtensionFilters().add(extFilter);
//Show open file dialog
final File file = fileChooser.showOpenDialog(null);
loadService.setFile(file);
loadService.restart();
}
@FXML
public void showAboutDialog(ActionEvent actionEvent) {
Dialog dialog = new Dialog(null, "About");
dialog.setMasthead(MASTHEAD_TEXT);
dialog.setContent(ABOUT_TEXT);
dialog.setExpandableContent(new TextArea(LICENSE));
dialog.show();
}
@FXML
public void exit(ActionEvent actionEvent) {
try {
ServiceManager.getInstance().getDatabaseService().getConnection().close();
} catch (SQLException ex) {
Logger.getLogger(GeofroggerController.class.getName()).log(Level.SEVERE, null, ex);
}
Platform.exit();
}
private void updateStatus(String text, double progressValue) {
Platform.runLater(() -> {
leftStatus.setText(text);
progress.setProgress(progressValue);
});
}
private class LoadCachesFromDatabaseService extends Service {
@Override
protected Task createTask() {
return new Task() {
@Override
protected Void call() throws Exception {
updateStatus("Load caches from database.", ProgressIndicator.INDETERMINATE_PROGRESS);
sessionContext.setData("cache-list", cacheService.getAllCaches());
updateStatus("All caches loaded.", 0);
return null;
}
};
}
}
private class LoadCachesFromFileService extends Service {
private final ObjectProperty<File> file = new SimpleObjectProperty();
public final void setFile(File value) {
file.set(value);
}
public final File getFile() {
return file.get();
}
public final ObjectProperty<File> fileProperty() {
return file;
}
@Override
protected Task createTask() {
return new Task() {
@Override
protected Void call() throws Exception {
try {
final List<Cache> cacheList = gpxReader.load(file.get().getAbsolutePath());
if (cacheList != null && !cacheList.isEmpty()) {
updateStatus("Store caches in database", ProgressIndicator.INDETERMINATE_PROGRESS);
cacheService.storeCaches(cacheList);
updateStatus("All caches are stored in database", 0);
updateStatus("Load caches from database.", ProgressIndicator.INDETERMINATE_PROGRESS);
sessionContext.setData("cache-list", cacheService.getAllCaches());
updateStatus("All caches loaded.", 0);
}
} catch (IOException ex) {
Logger.getLogger(GeofroggerController.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
};
}
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx;
import javafx.scene.Node;
import java.util.List;
/**
* @author Andreas Billmann <abi@geofroggerfx.de>
*/
public class JavaFXUtils {
public static void addClasses(Node node, String... classes) {
for (String styleClass : classes) {
List<String> nodeClasses = node.getStyleClass();
if (!nodeClasses.contains(styleClass)) {
nodeClasses.add(styleClass);
}
}
}
public static void removeClasses(Node node, String... classes) {
for (String styleClass : classes) {
List<String> nodeClasses = node.getStyleClass();
if (nodeClasses.contains(styleClass)) {
nodeClasses.remove(styleClass);
}
}
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.layout.Pane;
import jfxtras.labs.map.MapPane;
import jfxtras.labs.map.render.MapMarkable;
import jfxtras.labs.map.tile.OsmTileSourceFactory;
import java.util.List;
/**
* @author Andreas Billmann <abi@geofroggerfx.de>
*/
public class MapPaneWrapper extends Pane {
public static final String MAP_PANE_WRAPPER_CLASS = "map-pane-wrapper";
private final MapPane mapPane;
public MapPaneWrapper() {
mapPane = new MapPane(new OsmTileSourceFactory().create());
JavaFXUtils.addClasses(this, MAP_PANE_WRAPPER_CLASS);
setSizeListener();
this.getChildren().add(mapPane);
setDisplayPositionByLatLon(32.81729, -117.215905, 9);
mapPane.setMapMarkerVisible(true);
}
public final void setDisplayPositionByLatLon(double lat, double lon, int zoom) {
mapPane.setDisplayPositionByLatLon(lat, lon, zoom);
}
public final void setMapMarkerList(List<MapMarkable> mapMarkerList) {
mapPane.setMapMarkerList(mapMarkerList);
}
private void setSizeListener() {
this.widthProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
Double width = (Double) newValue;
mapPane.setMapWidth(width);
}
});
this.heightProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
Double height = (Double) newValue;
mapPane.setMapHeight(height);
}
});
}
}

View File

@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import de.frosch95.geofrogger.fx.MapPaneWrapper?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<?import java.net.URL?>
<AnchorPane fx:id="cacheDetailPane" styleClass="details-pane" xmlns:fx="http://javafx.com/fxml"
fx:controller="de.frosch95.geofrogger.fx.CacheDetailsController">
<children>
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="-1.0" styleClass="details-header"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label fx:id="cacheNameHeader" maxWidth="1.7976931348623157E308" text="" textFill="WHITE" underline="false"
HBox.hgrow="ALWAYS">
<font>
<Font size="16.0"/>
</font>
</Label>
<Label fx:id="detailsIconHeader" alignment="CENTER_RIGHT" maxWidth="-1.0" text="" textAlignment="LEFT"
wrapText="false" HBox.hgrow="ALWAYS"/>
</children>
<padding>
<Insets left="16.0" right="16.0"/>
</padding>
</HBox>
<TabPane side="BOTTOM" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="40.0">
<Tab closable="false" text="%tab.text.general">
<content>
<AnchorPane>
<GridPane alignment="TOP_LEFT" gridLinesVisible="false" hgap="16.0" snapToPixel="true" styleClass="form"
vgap="16.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<children>
<Label text="%label.text.name" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<TextField fx:id="cacheName" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="0"/>
<Label text="%label.text.difficulty" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<Slider fx:id="difficultySlider" blockIncrement="0.5" majorTickUnit="1.0" max="5.0" min="1.0"
minorTickCount="1" showTickLabels="true" showTickMarks="true" snapToTicks="true" value="1.0"
GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label text="%label.text.terrain" GridPane.columnIndex="2" GridPane.rowIndex="1"/>
<Slider fx:id="terrainSlider" blockIncrement="0.5" majorTickUnit="1.0" max="5.0" min="1.0"
minorTickCount="1" showTickLabels="true" showTickMarks="true" snapToTicks="true"
GridPane.columnIndex="3" GridPane.rowIndex="1"/>
<Label text="%label.text.placedBy" GridPane.columnIndex="0" GridPane.rowIndex="2">
<labelFor>
<TextField fx:id="placedByTextfield" prefWidth="200.0" GridPane.columnIndex="1"
GridPane.rowIndex="2"/>
</labelFor>
</Label>
<fx:reference source="placedByTextfield"/>
<Label text="%label.text.owner" GridPane.columnIndex="2" GridPane.rowIndex="2">
<labelFor>
<TextField fx:id="ownerTextfield" prefWidth="200.0" GridPane.columnIndex="3" GridPane.rowIndex="2"/>
</labelFor>
</Label>
<fx:reference source="ownerTextfield"/>
<Label text="%label.text.date" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
<DatePicker fx:id="date" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Label text="%label.text.type" GridPane.columnIndex="0" GridPane.rowIndex="4">
<labelFor>
<TextField fx:id="typeTextfield" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
</labelFor>
</Label>
<fx:reference source="typeTextfield"/>
<Label text="%label.text.container" GridPane.columnIndex="2" GridPane.rowIndex="4">
<labelFor>
<TextField fx:id="containerTextfield" prefWidth="200.0" GridPane.columnIndex="3"
GridPane.rowIndex="4"/>
</labelFor>
</Label>
<fx:reference source="containerTextfield"/>
</children>
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="NEVER" prefWidth="-1.0"/>
<ColumnConstraints fillWidth="true" hgrow="ALWAYS"/>
<ColumnConstraints halignment="RIGHT" hgrow="NEVER" prefWidth="-1.0"/>
<ColumnConstraints fillWidth="true" hgrow="ALWAYS"/>
</columnConstraints>
<padding>
<Insets bottom="16.0" left="16.0" right="16.0" top="16.0"/>
</padding>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="TOP" vgrow="NEVER"/>
<RowConstraints minHeight="-Infinity" prefHeight="-1.0" valignment="TOP" vgrow="NEVER"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="TOP" vgrow="NEVER"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="TOP" vgrow="NEVER"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="TOP" vgrow="NEVER"/>
</rowConstraints>
</GridPane>
<MapPaneWrapper fx:id="mapPaneWrapper" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="18.0"
AnchorPane.leftAnchor="18.0" AnchorPane.rightAnchor="18.0" AnchorPane.topAnchor="260.0"/>
</AnchorPane>
</content>
</Tab>
<Tab closable="false" text="%tab.text.descriptions">
<content>
<GridPane alignment="TOP_LEFT" gridLinesVisible="false" hgap="16.0" snapToPixel="true" styleClass="form"
vgap="16.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<children>
<Label text="%label.text.shortdescription" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<CheckBox fx:id="shortDescriptionHtml" text="%label.text.htmldescription" GridPane.columnIndex="1"
GridPane.rowIndex="0"/>
<BorderPane fx:id="shortDescriptionPane" GridPane.columnSpan="2" GridPane.columnIndex="0"
GridPane.rowIndex="1"/>
<Label text="%label.text.longdescription" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
<CheckBox fx:id="longDescriptionHtml" text="%label.text.htmldescription" GridPane.columnIndex="1"
GridPane.rowIndex="2"/>
<BorderPane fx:id="longDescriptionPane" GridPane.columnSpan="2" GridPane.columnIndex="0"
GridPane.rowIndex="3"/>
</children>
<columnConstraints>
<ColumnConstraints fillWidth="true" hgrow="NEVER"/>
<ColumnConstraints fillWidth="true" hgrow="ALWAYS"/>
</columnConstraints>
<padding>
<Insets bottom="16.0" left="16.0" right="16.0" top="16.0"/>
</padding>
<rowConstraints>
<RowConstraints minHeight="16" valignment="TOP" vgrow="NEVER"/>
<RowConstraints minHeight="150" valignment="TOP" vgrow="ALWAYS"/>
<RowConstraints minHeight="16" valignment="TOP" vgrow="NEVER"/>
<RowConstraints minHeight="350" valignment="TOP" vgrow="ALWAYS"/>
</rowConstraints>
</GridPane>
</content>
</Tab>
</TabPane>
</children>
<stylesheets>
<URL value="@geofrogger.css"/>
</stylesheets>
</AnchorPane>

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<?import java.net.URL?>
<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="de.frosch95.geofrogger.fx.CacheListController">
<children>
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="-1.0" styleClass="cache-header"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label alignment="CENTER_LEFT" minWidth="60.0" prefWidth="-1.0" style="&#10;" text="%label.text.cache.list"
textAlignment="LEFT" textFill="WHITE" wrapText="false">
<font>
<Font size="16.0" fx:id="x1"/>
</font>
</Label>
<Label fx:id="cacheNumber" alignment="CENTER_LEFT" minWidth="60.0" prefWidth="-1.0" maxWidth="Infinity"
style="&#10;" text="(0)" textAlignment="LEFT" textFill="WHITE" wrapText="false" HBox.hgrow="ALWAYS">
<font>
<Font size="16.0" fx:id="x1"/>
</font>
</Label>
<Label fx:id="sortIcon"/>
<Label fx:id="filterIcon"/>
</children>
<padding>
<Insets left="16.0" right="16.0" fx:id="x2"/>
</padding>
</HBox>
<ListView fx:id="cacheListView" prefHeight="507.0" prefWidth="221.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0"/>
</children>
<stylesheets>
<URL value="@geofrogger.css"/>
</stylesheets>
</AnchorPane>

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx.components;
import de.frosch95.geofrogger.model.Cache;
/**
* @author Andreas
*/
public class AwesomeGeocachingIcons {
public static AwesomeIcons getIcon(Cache cache) {
AwesomeIcons icon = AwesomeIcons.ICON_TAG;
switch (cache.getType()) {
case "Multi-cache":
icon = AwesomeIcons.ICON_TAGS;
break;
case "Traditional Cache":
icon = AwesomeIcons.ICON_TAG;
break;
case "Unknown Cache":
icon = AwesomeIcons.ICON_QUESTION_SIGN;
break;
case "Earthcache":
icon = AwesomeIcons.ICON_GLOBE;
break;
case "Letterbox Hybrid":
icon = AwesomeIcons.ICON_INBOX;
break;
case "Event Cache":
icon = AwesomeIcons.ICON_CALENDAR;
break;
case "Whereigo Cache":
icon = AwesomeIcons.ICON_PLAY_SIGN;
break;
case "Webcam Cache":
icon = AwesomeIcons.ICON_CAMERA;
break;
case "Virtual Cache":
icon = AwesomeIcons.ICON_LAPTOP;
break;
default:
System.out.println(cache.getType());
}
return icon;
}
}

View File

@@ -0,0 +1,299 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx.components;
/**
* @author Andreas
*/
public enum AwesomeIcons {
ICON_GLASS('\uf000'),
ICON_MUSIC('\uf001'),
ICON_SEARCH('\uf002'),
ICON_ENVELOPE('\uf003'),
ICON_HEART('\uf004'),
ICON_STAR('\uf005'),
ICON_STAR_EMPTY('\uf006'),
ICON_USER('\uf007'),
ICON_FILM('\uf008'),
ICON_TH_LARGE('\uf009'),
ICON_TH('\uf00a'),
ICON_TH_LIST('\uf00b'),
ICON_OK('\uf00c'),
ICON_REMOVE('\uf00d'),
ICON_ZOOM_IN('\uf00e'),
ICON_ZOOM_OUT('\uf010'),
ICON_OFF('\uf011'),
ICON_SIGNAL('\uf012'),
ICON_COG('\uf013'),
ICON_TRASH('\uf014'),
ICON_HOME('\uf015'),
ICON_FILE('\uf016'),
ICON_TIME('\uf017'),
ICON_ROAD('\uf018'),
ICON_DOWNLOAD_ALT('\uf019'),
ICON_DOWNLOAD('\uf01a'),
ICON_UPLOAD('\uf01b'),
ICON_INBOX('\uf01c'),
ICON_PLAY_CIRCLE('\uf01d'),
ICON_PLAY_SIGN('\uf144'),
ICON_REPEAT('\uf01e'),
ICON_REFRESH('\uf021'),
ICON_LIST_ALT('\uf022'),
ICON_LOCK('\uf023'),
ICON_FLAG('\uf024'),
ICON_HEADPHONES('\uf025'),
ICON_VOLUME_OFF('\uf026'),
ICON_VOLUME_DOWN('\uf027'),
ICON_VOLUME_UP('\uf028'),
ICON_QRCODE('\uf029'),
ICON_BARCODE('\uf02a'),
ICON_TAG('\uf02b'),
ICON_TAGS('\uf02c'),
ICON_BOOK('\uf02d'),
ICON_BOOKMARK('\uf02e'),
ICON_PRINT('\uf02f'),
ICON_CAMERA('\uf030'),
ICON_FONT('\uf031'),
ICON_BOLD('\uf032'),
ICON_ITALIC('\uf033'),
ICON_TEXT_HEIGHT('\uf034'),
ICON_TEXT_WIDTH('\uf035'),
ICON_ALIGN_LEFT('\uf036'),
ICON_ALIGN_CENTER('\uf037'),
ICON_ALIGN_RIGHT('\uf038'),
ICON_ALIGN_JUSTIFY('\uf039'),
ICON_LIST('\uf03a'),
ICON_INDENT_LEFT('\uf03b'),
ICON_INDENT_RIGHT('\uf03c'),
ICON_FACETIME_VIDEO('\uf03d'),
ICON_PICTURE('\uf03e'),
ICON_PENCIL('\uf040'),
ICON_MAP_MARKER('\uf041'),
ICON_ADJUST('\uf042'),
ICON_TINT('\uf043'),
ICON_EDIT('\uf044'),
ICON_SHARE('\uf045'),
ICON_CHECK('\uf046'),
ICON_MOVE('\uf047'),
ICON_STEP_BACKWARD('\uf048'),
ICON_FAST_BACKWARD('\uf049'),
ICON_BACKWARD('\uf04a'),
ICON_PLAY('\uf04b'),
ICON_PAUSE('\uf04c'),
ICON_STOP('\uf04d'),
ICON_FORWARD('\uf04e'),
ICON_FAST_FORWARD('\uf050'),
ICON_STEP_FORWARD('\uf051'),
ICON_EJECT('\uf052'),
ICON_CHEVRON_LEFT('\uf053'),
ICON_CHEVRON_RIGHT('\uf054'),
ICON_PLUS_SIGN('\uf055'),
ICON_MINUS_SIGN('\uf056'),
ICON_REMOVE_SIGN('\uf057'),
ICON_OK_SIGN('\uf058'),
ICON_QUESTION_SIGN('\uf059'),
ICON_QUESTION('\uf128'),
ICON_INFO_SIGN('\uf05a'),
ICON_SCREENSHOT('\uf05b'),
ICON_REMOVE_CIRCLE('\uf05c'),
ICON_OK_CIRCLE('\uf05d'),
ICON_BAN_CIRCLE('\uf05e'),
ICON_ARROW_LEFT('\uf060'),
ICON_ARROW_RIGHT('\uf061'),
ICON_ARROW_UP('\uf062'),
ICON_ARROW_DOWN('\uf063'),
ICON_SHARE_ALT('\uf064'),
ICON_RESIZE_FULL('\uf065'),
ICON_RESIZE_SMALL('\uf066'),
ICON_PLUS('\uf067'),
ICON_MINUS('\uf068'),
ICON_ASTERISK('\uf069'),
ICON_EXCLAMATION_SIGN('\uf06a'),
ICON_GIFT('\uf06b'),
ICON_LEAF('\uf06c'),
ICON_FIRE('\uf06d'),
ICON_EYE_OPEN('\uf06e'),
ICON_EYE_CLOSE('\uf070'),
ICON_WARNING_SIGN('\uf071'),
ICON_PLANE('\uf072'),
ICON_CALENDAR('\uf073'),
ICON_RANDOM('\uf074'),
ICON_COMMENT('\uf075'),
ICON_MAGNET('\uf076'),
ICON_CHEVRON_UP('\uf077'),
ICON_CHEVRON_DOWN('\uf078'),
ICON_RETWEET('\uf079'),
ICON_SHOPPING_CART('\uf07a'),
ICON_FOLDER_CLOSE('\uf07b'),
ICON_FOLDER_OPEN('\uf07c'),
ICON_RESIZE_VERTICAL('\uf07d'),
ICON_RESIZE_HORIZONTAL('\uf07e'),
ICON_BAR_CHART('\uf080'),
ICON_TWITTER_SIGN('\uf081'),
ICON_FACEBOOK_SIGN('\uf082'),
ICON_CAMERA_RETRO('\uf083'),
ICON_KEY('\uf084'),
ICON_COGS('\uf085'),
ICON_COMMENTS('\uf086'),
ICON_THUMBS_UP('\uf087'),
ICON_THUMBS_DOWN('\uf088'),
ICON_STAR_HALF('\uf089'),
ICON_HEART_EMPTY('\uf08a'),
ICON_SIGNOUT('\uf08b'),
ICON_LINKEDIN_SIGN('\uf08c'),
ICON_PUSHPIN('\uf08d'),
ICON_EXTERNAL_LINK('\uf08e'),
ICON_SIGNIN('\uf090'),
ICON_TROPHY('\uf091'),
ICON_GITHUB_SIGN('\uf092'),
ICON_UPLOAD_ALT('\uf093'),
ICON_LEMON('\uf094'),
ICON_PHONE('\uf095'),
ICON_CHECK_EMPTY('\uf096'),
ICON_BOOKMARK_EMPTY('\uf097'),
ICON_PHONE_SIGN('\uf098'),
ICON_TWITTER('\uf099'),
ICON_FACEBOOK('\uf09a'),
ICON_GITHUB('\uf09b'),
ICON_UNLOCK('\uf09c'),
ICON_CREDIT_CARD('\uf09d'),
ICON_RSS('\uf09e'),
ICON_HDD('\uf0a0'),
ICON_BULLHORN('\uf0a1'),
ICON_BELL('\uf0a2'),
ICON_CERTIFICATE('\uf0a3'),
ICON_HAND_RIGHT('\uf0a4'),
ICON_HAND_LEFT('\uf0a5'),
ICON_HAND_UP('\uf0a6'),
ICON_HAND_DOWN('\uf0a7'),
ICON_CIRCLE_ARROW_LEFT('\uf0a8'),
ICON_CIRCLE_ARROW_RIGHT('\uf0a9'),
ICON_CIRCLE_ARROW_UP('\uf0aa'),
ICON_CIRCLE_ARROW_DOWN('\uf0ab'),
ICON_GLOBE('\uf0ac'),
ICON_WRENCH('\uf0ad'),
ICON_TASKS('\uf0ae'),
ICON_FILTER('\uf0b0'),
ICON_BRIEFCASE('\uf0b1'),
ICON_FULLSCREEN('\uf0b2'),
ICON_GROUP('\uf0c0'),
ICON_LINK('\uf0c1'),
ICON_CLOUD('\uf0c2'),
ICON_BEAKER('\uf0c3'),
ICON_CUT('\uf0c4'),
ICON_COPY('\uf0c5'),
ICON_PAPER_CLIP('\uf0c6'),
ICON_SAVE('\uf0c7'),
ICON_SIGN_BLANK('\uf0c8'),
ICON_REORDER('\uf0c9'),
ICON_LIST_UL('\uf0ca'),
ICON_LIST_OL('\uf0cb'),
ICON_STRIKETHROUGH('\uf0cc'),
ICON_UNDERLINE('\uf0cd'),
ICON_TABLE('\uf0ce'),
ICON_MAGIC('\uf0d0'),
ICON_TRUCK('\uf0d1'),
ICON_PINTEREST('\uf0d2'),
ICON_PINTEREST_SIGN('\uf0d3'),
ICON_GOOGLE_PLUS_SIGN('\uf0d4'),
ICON_GOOGLE_PLUS('\uf0d5'),
ICON_MONEY('\uf0d6'),
ICON_CARET_DOWN('\uf0d7'),
ICON_CARET_UP('\uf0d8'),
ICON_CARET_LEFT('\uf0d9'),
ICON_CARET_RIGHT('\uf0da'),
ICON_COLUMNS('\uf0db'),
ICON_SORT('\uf0dc'),
ICON_SORT_DOWN('\uf0dd'),
ICON_SORT_UP('\uf0de'),
ICON_ENVELOPE_ALT('\uf0e0'),
ICON_LINKEDIN('\uf0e1'),
ICON_UNDO('\uf0e2'),
ICON_LEGAL('\uf0e3'),
ICON_DASHBOARD('\uf0e4'),
ICON_COMMENT_ALT('\uf0e5'),
ICON_COMMENTS_ALT('\uf0e6'),
ICON_BOLT('\uf0e7'),
ICON_SITEMAP('\uf0e8'),
ICON_UMBRELLA('\uf0e9'),
ICON_PASTE('\uf0ea'),
ICON_LIGHTBULB('\uf0eb'),
ICON_EXCHANGE('\uf0ec'),
ICON_CLOUD_DOWNLOAD('\uf0ed'),
ICON_CLOUD_UPLOAD('\uf0ee'),
ICON_USER_MD('\uf0f0'),
ICON_STETHOSCOPE('\uf0f1'),
ICON_SUITCASE('\uf0f2'),
ICON_BELL_ALT('\uf0f3'),
ICON_COFFEE('\uf0f4'),
ICON_FOOD('\uf0f5'),
ICON_FILE_ALT('\uf0f6'),
ICON_BUILDING('\uf0f7'),
ICON_HOSPITAL('\uf0f8'),
ICON_AMBULANCE('\uf0f9'),
ICON_MEDKIT('\uf0fa'),
ICON_FIGHTER_JET('\uf0fb'),
ICON_BEER('\uf0fc'),
ICON_H_SIGN('\uf0fd'),
ICON_PLUS_SIGN_ALT('\uf0fe'),
ICON_DOUBLE_ANGLE_LEFT('\uf100'),
ICON_DOUBLE_ANGLE_RIGHT('\uf101'),
ICON_DOUBLE_ANGLE_UP('\uf102'),
ICON_DOUBLE_ANGLE_DOWN('\uf103'),
ICON_ANGLE_LEFT('\uf104'),
ICON_ANGLE_RIGHT('\uf105'),
ICON_ANGLE_UP('\uf106'),
ICON_ANGLE_DOWN('\uf107'),
ICON_DESKTOP('\uf108'),
ICON_LAPTOP('\uf109'),
ICON_TABLET('\uf10a'),
ICON_MOBILE_PHONE('\uf10b'),
ICON_CIRCLE_BLANK('\uf10c'),
ICON_QUOTE_LEFT('\uf10d'),
ICON_QUOTE_RIGHT('\uf10e'),
ICON_SPINNER('\uf110'),
ICON_CIRCLE('\uf111'),
ICON_REPLY('\uf112'),
ICON_GITHUB_ALT('\uf113'),
ICON_FOLDER_CLOSE_ALT('\uf114'),
ICON_FOLDER_OPEN_ALT('\uf115');
private final Character character;
private AwesomeIcons(Character character) {
this.character = character;
}
public Character character() {
return character;
}
@Override
public String toString() {
return character.toString();
}
}

View File

@@ -0,0 +1,138 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx.components;
import de.frosch95.geofrogger.model.Cache;
import de.frosch95.geofrogger.model.CacheUtils;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.image.ImageView;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import static de.frosch95.geofrogger.fx.JavaFXUtils.addClasses;
import static de.frosch95.geofrogger.fx.JavaFXUtils.removeClasses;
/**
* @author Andreas
*/
public class CacheListCell extends ListCell<Cache> {
private static final String CACHE_LIST_FOUND_CLASS = "cache-list-found";
private static final String CACHE_LIST_NOT_FOUND_CLASS = "cache-list-not-found";
private static final String CACHE_LIST_NAME_CLASS = "cache-list-name";
private static final String CACHE_LIST_DT_CLASS = "cache-list-dt";
private static final String CACHE_LIST_ICON_CLASS = "cache-list-icon";
private final GridPane grid = new GridPane();
private final ImageView icon = new ImageView();
private final Label name = new Label();
private final Label dt = new Label();
private final ImageView foundIcon = new ImageView();
private final ImageView favoriteIcon = new ImageView();
public CacheListCell() {
configureGrid();
configureIcon();
configureName();
configureDifficultyTerrain();
addControlsToGrid();
}
@Override
public void updateItem(Cache cache, boolean empty) {
super.updateItem(cache, empty);
if (empty) {
clearContent();
} else {
addContent(cache);
}
}
private void configureGrid() {
grid.setHgap(10);
grid.setVgap(4);
grid.setPadding(new Insets(0, 10, 0, 10));
ColumnConstraints column1 = new ColumnConstraints(32);
ColumnConstraints column2 = new ColumnConstraints(100, 100, Double.MAX_VALUE);
column2.setHgrow(Priority.ALWAYS);
ColumnConstraints column3 = new ColumnConstraints(32);
grid.getColumnConstraints().addAll(column1, column2, column3);
}
private void configureIcon() {
icon.getStyleClass().add(CACHE_LIST_ICON_CLASS);
}
private void configureName() {
name.getStyleClass().add(CACHE_LIST_NAME_CLASS);
}
private void configureDifficultyTerrain() {
dt.getStyleClass().add(CACHE_LIST_DT_CLASS);
}
private void addControlsToGrid() {
grid.add(icon, 0, 0, 1, 2);
grid.add(name, 1, 0);
grid.add(dt, 1, 1);
grid.add(foundIcon, 2, 0);
grid.add(favoriteIcon, 2, 1);
}
private void clearContent() {
setText(null);
setGraphic(null);
}
private void addContent(Cache cache) {
setText(null);
icon.setImage(GeocachingIcons.getIcon(cache));
name.setText(cache.getName());
dt.setText("D: " + cache.getDifficulty() + " / T:" + cache.getTerrain());
if (CacheUtils.hasUserFoundCache(cache, new Long(3906456))) {
foundIcon.setImage(IconManager.getIcon("/icons/iconmonstr-check-mark-11-icon.png", IconManager.IconSize.SMALL));
} else {
foundIcon.setImage(null);
}
setStyleClassDependingOnFoundState(cache);
setGraphic(grid);
}
private void setStyleClassDependingOnFoundState(Cache cache) {
if (CacheUtils.hasUserFoundCache(cache, new Long(3906456))) {
addClasses(this, CACHE_LIST_FOUND_CLASS);
removeClasses(this, CACHE_LIST_NOT_FOUND_CLASS);
} else {
addClasses(this, CACHE_LIST_NOT_FOUND_CLASS);
removeClasses(this, CACHE_LIST_FOUND_CLASS);
}
}
}

View File

@@ -0,0 +1,97 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx.components;
import de.frosch95.geofrogger.model.Cache;
import javafx.scene.image.Image;
/**
* @author Andreas
*/
public class GeocachingIcons {
public static Image getIcon(Cache cache) {
return getIcon(cache, IconManager.IconSize.MIDDLE);
}
public static Image getIcon(Cache cache, IconManager.IconSize size) {
String iconName = "/icons/iconmonstr-map-5-icon.png";
switch (cache.getType()) {
case "Multi-cache":
iconName = "/icons/iconmonstr-map-6-icon.png";
break;
case "Traditional Cache":
iconName = "/icons/iconmonstr-map-5-icon.png";
break;
case "Unknown Cache":
iconName = "/icons/iconmonstr-help-3-icon.png";
break;
case "Earthcache":
iconName = "/icons/iconmonstr-globe-4-icon.png";
break;
case "Letterbox Hybrid":
iconName = "/icons/iconmonstr-email-4-icon.png";
break;
case "Event Cache":
iconName = "/icons/iconmonstr-calendar-4-icon.png";
break;
case "Wherigo Cache":
iconName = "/icons/iconmonstr-navigation-6-icon.png";
break;
case "Webcam Cache":
iconName = "/icons/iconmonstr-webcam-3-icon.png";
break;
case "Virtual Cache":
iconName = "/icons/iconmonstr-network-2-icon.png";
break;
default:
System.out.println(cache.getType());
}
return IconManager.getIcon(iconName, size);
}
public static Image getMapIcon(Cache cache) {
return getMapIcon(cache, IconManager.IconSize.MIDDLE);
}
public static Image getMapIcon(Cache cache, IconManager.IconSize size) {
String iconName = "/icons/iconmonstr-location-icon.png";
return IconManager.getIcon(iconName, size);
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx.components;
import de.frosch95.geofrogger.model.Cache;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import jfxtras.labs.map.MapControlable;
import jfxtras.labs.map.render.MapMarkable;
import java.awt.*;
import java.util.Collections;
import java.util.List;
/**
* @author Andreas
*/
public class GeocachingMapMarker implements MapMarkable {
private double lat;
private double lon;
private Label iconLabel;
private Cache cache;
public GeocachingMapMarker(Cache cache, double lat, double lon) {
this.lat = lat;
this.lon = lon;
this.cache = cache;
this.iconLabel = new Label();
iconLabel.setFont(Font.font("FontAwesome", FontWeight.BOLD, 24));
iconLabel.setText(AwesomeGeocachingIcons.getIcon(cache).toString());
}
@Override
public double getLat() {
return lat;
}
@Override
public double getLon() {
return lon;
}
@Override
public void render(MapControlable mapController) {
Point postion = mapController.getMapPoint(lat, lon, true);
if (postion != null) {
Group tilesGroup = mapController.getTilesGroup();
ObservableList<Node> children = tilesGroup.getChildren();
List<? extends Node> nodes = createChildren(postion);
for (Node node : nodes) {
if (!children.contains(node)) {
children.add(node);
}
}
}
}
List<? extends Node> createChildren(Point position) {
iconLabel.setTranslateX(position.x);
iconLabel.setTranslateY(position.y);
return Collections.singletonList(iconLabel);
}
@Override
public Node getNode() {
return iconLabel;
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.fx.components;
import javafx.scene.image.Image;
import java.util.HashMap;
import java.util.Map;
/**
* @author Andreas
*/
public class IconManager {
private static final Map<String, Image> container = new HashMap<>();
public enum IconSize {
SMALL(16.0),
MIDDLE(32.0),
BIG(64.0);
private final double size;
private IconSize(double size) {
this.size = size;
}
public double getValue() {
return size;
}
}
;
public static Image getIcon(String iconName, IconSize size) {
final Image image;
String key = iconName + "_" + size;
if (container.containsKey(key)) {
image = container.get(key);
} else {
image = new Image(iconName, size.getValue(), size.getValue(), true, true);
container.put(key, image);
}
return image;
}
}

View File

@@ -0,0 +1,65 @@
/*
* Empty Stylesheet file.
*/
.mainFxmlClass {
}
.menu-bar {
-fx-background-color: #aeb5ba, linear-gradient(to bottom, #ecf4fa 0%, #ced4d9 100%);
-fx-background-insets: 0, 0 0 1 0;
}
.menu-bar .menu .label {
-fx-text-fill: #2d3e4c;
}
.split-pane > .split-pane-divider {
-fx-background-color: linear-gradient(to right, #ecf4fa 0%, #ced4d9 100%);
-fx-padding: 0 3 0 3;
}
.scroll-pane {
-fx-background-insets: 0, 0;
-fx-padding: 0;
}
.form {
-fx-background-color: #aeb5ba, linear-gradient(to bottom, #ecf4fa 0%, #ced4d9 100%);
}
.details-header,
.cache-header {
-fx-background-color: linear-gradient(to bottom, #aaaaaa 0%, #888888 100%);
}
.cache-list-name {
-fx-font-size: 1.2em;
}
.cache-list-icon {
-fx-text-fill: #444444;
-fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.4), 3, 0.0, 1, 1);
}
.cache-list-found .cache-list-icon {
-fx-text-fill: #669900;
}
.cache-list-action-icons {
-fx-padding: 4;
-fx-margin: 0 8;
-fx-text-fill: #ffffff;
}
.text-input:readonly,
.combo-box-base:disabled,
.text-input:disabled {
-fx-opacity: 0.9;
-fx-background-color: linear-gradient(to bottom, #eeeeee 0%, #dddddd 100%);
}
.slider:disabled {
-fx-opacity: 0.8;
}

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.Color?>
<?import javafx.scene.text.Font?>
<?import java.net.URL?>
<VBox prefHeight="800.0" prefWidth="1280.0" minHeight="600.0" minWidth="800.0" xmlns:fx="http://javafx.com/fxml"
fx:controller="de.frosch95.geofrogger.fx.GeofroggerController">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>
<Menu mnemonicParsing="false" text="%menu.title.file">
<items>
<MenuItem mnemonicParsing="false" onAction="#importGpx" text="%menu.title.import.gpx"/>
<SeparatorMenuItem mnemonicParsing="false"/>
<MenuItem mnemonicParsing="false" onAction="#exit" text="%menu.title.quit"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="%menu.title.help">
<items>
<MenuItem mnemonicParsing="false" onAction="#showAboutDialog" text="%menu.title.about"/>
</items>
</Menu>
</menus>
</MenuBar>
<SplitPane dividerPositions="0.3779342723004695" focusTraversable="true" prefHeight="-1.0" prefWidth="-1.0"
VBox.vgrow="ALWAYS">
<items>
<fx:include source="cache_list.fxml" fx:id="cacheListContent"/>
<ScrollPane fitToHeight="true" fitToWidth="true" pannable="false" prefHeight="-1.0" prefWidth="-1.0">
<content>
<fx:include source="cache_details.fxml" fx:id="cacheDetailsContent"/>
</content>
</ScrollPane>
</items>
</SplitPane>
<HBox id="HBox" alignment="CENTER_LEFT" spacing="5.0" VBox.vgrow="NEVER">
<children>
<Pane prefHeight="-1.0" prefWidth="-1.0" HBox.hgrow="ALWAYS"/>
<Label fx:id="leftStatus" maxHeight="1.7976931348623157E308" maxWidth="-1.0" text="" HBox.hgrow="ALWAYS">
<font>
<Font size="11.0" fx:id="x3"/>
</font>
<textFill>
<Color blue="0.625" green="0.625" red="0.625" fx:id="x4"/>
</textFill>
</Label>
<ProgressBar fx:id="progress" prefWidth="300.0" progress="0" HBox.hgrow="ALWAYS"/>
</children>
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0"/>
</padding>
</HBox>
</children>
<stylesheets>
<URL value="@geofrogger.css"/>
</stylesheets>
</VBox>

View File

@@ -0,0 +1,21 @@
menu.title.import.gpx = Importiere GPX
menu.title.file = Datei
menu.title.quit = Beenden
menu.title.help = Hilfe
menu.title.about = \u00dcber GeoFroggerFX
label.text.cache.list=Caches
label.text.name=Name:
label.text.difficulty=Schwierigkeit:
label.text.terrain=Gel\u00E4nde
label.text.placedBy=Platziert von:
label.text.owner=Betreut von:
label.text.date=Datum:
label.text.type=Typ:
label.text.container=Gr\u00F6\u00dfe:
label.text.shortdescription=Kurze Beschreibung:
label.text.htmldescription=HTML Beschreibung
label.text.longdescription=Lange Beschreibung:
tab.text.descriptions=Beschreibungen
tab.text.general=Allgemein

View File

@@ -0,0 +1,21 @@
menu.title.import.gpx = Import GPX
menu.title.file = File
menu.title.quit = Quit
menu.title.help = Help
menu.title.about = About GeoFroggerFX
label.text.cache.list=Caches
label.text.name=Name:
label.text.difficulty=Difficulty:
label.text.terrain=Terrain:
label.text.placedBy=Placed By:
label.text.owner=Owner:
label.text.date=Date:
label.text.type=Type:
label.text.container=Container:
label.text.shortdescription=Short description:
label.text.htmldescription=HTML Description
label.text.longdescription=Long description:
tab.text.descriptions=Descriptions
tab.text.general=General

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.gpx;
import de.frosch95.geofrogger.application.ProgressListener;
import de.frosch95.geofrogger.model.Cache;
import java.io.IOException;
import java.util.List;
/**
* TODO: describe the class
*
* @author Andreas Billmann
*/
public interface GPXReader {
List<Cache> load(final String fileName) throws IOException;
void addListener(ProgressListener listener);
}

View File

@@ -0,0 +1,474 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.gpx;
import de.frosch95.geofrogger.application.ProgressEvent;
import de.frosch95.geofrogger.application.ProgressListener;
import de.frosch95.geofrogger.model.Attribute;
import de.frosch95.geofrogger.model.*;
import org.jdom2.*;
import org.jdom2.input.SAXBuilder;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* TODO: describe the class
*
* @author Andreas Billmann
*/
public class GroundspeakGPXReader implements GPXReader {
public static final String LAT = "lat";
public static final String LON = "lon";
public static final String TIME = "time";
public static final String NAME = "name";
public static final String DESC = "desc";
public static final String WPT = "wpt";
public static final String URL = "url";
public static final String URLNAME = "urlname";
public static final String SYM = "sym";
public static final String TYPE = "type";
public static final String CACHE = "cache";
public static final String GROUNDSPEAK = "groundspeak";
public static final String ID = "id";
public static final String AVAILABLE = "available";
public static final String ARCHIVED = "archived";
public static final String PLACED_BY = "placed_by";
public static final String OWNER = "owner";
public static final String CONTAINER = "container";
public static final String ATTRIBUTES = "attributes";
public static final String ATTRIBUTE = "attribute";
public static final String INC = "inc";
public static final String DIFFICULTY = "difficulty";
public static final String TERRAIN = "terrain";
public static final String COUNTRY = "country";
public static final String STATE = "state";
public static final String SHORT_DESCRIPTION = "short_description";
public static final String HTML = "html";
public static final String LONG_DESCRIPTION = "long_description";
public static final String ENCODED_HINTS = "encoded_hints";
public static final String LOGS = "logs";
public static final String LOG = "log";
public static final String DATE = "date";
public static final String FINDER = "finder";
public static final String ENCODED = "encoded";
public static final String TRAVELBUGS = "travelbugs";
public static final String TRAVELBUG = "travelbug";
public static final String TEXT = "text";
public static final String REF = "ref";
public static final String DEFAULT_NAMESPACE_URL = "http://www.topografix.com/GPX/1/0";
public static final String GROUNDSPEAK_NAMESPACE_URL = "http://www.groundspeak.com/cache/1/0/1";
private final List<ProgressListener> listeners = new ArrayList<>();
private final Map<Long, User> userCache = new HashMap<>();
private File gpxFile;
private Document content;
private List<Cache> modelList;
private Namespace defaultNamespace;
private Namespace groundspeakNamespace;
@Override
public void addListener(ProgressListener listener) {
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
@Override
public List<Cache> load(final String filename) throws IOException {
checkIfParameterIsNull(filename);
instantiateFileAndAssignToMember(filename);
checkIfFileExists();
readFileContent();
setNamespaces();
parseContent();
return modelList;
}
private void setNamespaces() {
defaultNamespace = Namespace.getNamespace(DEFAULT_NAMESPACE_URL);
groundspeakNamespace = Namespace.getNamespace(GROUNDSPEAK, GROUNDSPEAK_NAMESPACE_URL);
}
private void checkIfParameterIsNull(String filename) {
if (filename == null) {
throw new IllegalArgumentException("filename should not be null");
}
}
private void instantiateFileAndAssignToMember(String filename) {
gpxFile = new File(filename);
}
private void checkIfFileExists() throws FileNotFoundException {
if (!gpxFile.exists()) {
throw new FileNotFoundException("file does not exist");
}
}
private void readFileContent() throws IOException {
fireEvent(new ProgressEvent("GPX Reader",
ProgressEvent.State.STARTED,
"Load File " + gpxFile.getName() + " started."));
countLineNumbers();
final SAXBuilder saxBuilder = new SAXBuilder();
try {
content = saxBuilder.build(gpxFile);
} catch (JDOMException e) {
throw new IOException(e.getMessage(), e);
}
fireEvent(new ProgressEvent("GPX Reader",
ProgressEvent.State.FINISHED,
"Load File " + gpxFile.getName() + " finished."));
}
private void parseContent() {
modelList = new ArrayList<>();
final Element root = content.getRootElement();
final List<Element> waypoints = root.getChildren(WPT, defaultNamespace);
int totalNumberOfCaches = waypoints.size();
int currentNumber = 0;
for (final Element waypointElement : waypoints) {
currentNumber++;
fireEvent(new ProgressEvent("GPX Reader",
ProgressEvent.State.RUNNING,
"Parse " + currentNumber + " of " + totalNumberOfCaches + " caches.",
(double) currentNumber / (double) totalNumberOfCaches));
final Cache cache = parseWaypointElement(waypointElement);
modelList.add(cache);
}
}
private Cache parseWaypointElement(Element waypointElement) {
final Cache cache = new Cache();
final Waypoint mainWaypoint = new Waypoint();
cache.setMainWayPoint(mainWaypoint);
try {
setLatitudeAndLongitude(waypointElement, mainWaypoint);
setTime(waypointElement, mainWaypoint);
setWaypointName(waypointElement, mainWaypoint);
setDescription(waypointElement, mainWaypoint);
setUrl(waypointElement, mainWaypoint);
setUrlName(waypointElement, mainWaypoint);
setSym(waypointElement, mainWaypoint);
setType(waypointElement, mainWaypoint);
final Element cacheElement = waypointElement.getChild(CACHE, groundspeakNamespace);
parseCacheElement(cacheElement, cache);
} catch (DataConversionException | MalformedURLException e) {
// TODO: do some batch error handling
e.printStackTrace();
}
return cache;
}
private void parseCacheElement(Element cacheElement, Cache cache) throws DataConversionException {
setId(cacheElement, cache);
setAvailable(cacheElement, cache);
setArchived(cacheElement, cache);
setName(cacheElement, cache);
setPlacedBy(cacheElement, cache);
setOwner(cacheElement, cache);
setType(cacheElement, cache);
setContainer(cacheElement, cache);
setAttributes(cacheElement, cache);
setDifficulty(cacheElement, cache);
setTerrain(cacheElement, cache);
setCountry(cacheElement, cache);
setState(cacheElement, cache);
setShortDescription(cacheElement, cache);
setLongDescription(cacheElement, cache);
setEncodedHints(cacheElement, cache);
setLogs(cacheElement, cache);
setTravelBugs(cacheElement, cache);
}
private void setTravelBugs(Element cacheElement, Cache cache) throws DataConversionException {
final Element travelBugsElement = cacheElement.getChild(TRAVELBUGS, groundspeakNamespace);
if (travelBugsElement != null) {
final List<TravelBug> travelBugs = new ArrayList<>();
cache.setTravelBugs(travelBugs);
for (Element travelBugElement : travelBugsElement.getChildren()) {
final TravelBug travelBug = new TravelBug();
travelBugs.add(travelBug);
setId(travelBugElement, travelBug);
setRef(travelBugElement, travelBug);
setName(travelBugElement, travelBug);
}
}
}
private void setName(Element travelBugElement, TravelBug travelBug) {
travelBug.setName(travelBugElement.getChild(NAME, groundspeakNamespace).getTextTrim());
}
private void setRef(Element travelBugElement, TravelBug travelBug) {
travelBug.setRef(travelBugElement.getAttribute(REF).getValue());
}
private void setId(Element travelBugElement, TravelBug travelBug) throws DataConversionException {
travelBug.setId(travelBugElement.getAttribute(ID).getLongValue());
}
private void setLogs(Element cacheElement, Cache cache) throws DataConversionException {
final Element logsElement = cacheElement.getChild(LOGS, groundspeakNamespace);
if (logsElement != null) {
final List<Log> logs = new ArrayList<>();
cache.setLogs(logs);
for (Element logElement : logsElement.getChildren()) {
final Log log = new Log();
logs.add(log);
setId(logElement, log);
setDate(logElement, log);
setType(logElement, log);
setText(logElement, log);
setFinder(logElement, log);
}
}
}
private void setFinder(Element logElement, Log log) throws DataConversionException {
final Element finderElement = logElement.getChild(FINDER, groundspeakNamespace);
if (finderElement != null) {
final Long finderId = finderElement.getAttribute(ID).getLongValue();
User finder = userCache.get(finderId);
if (finder == null) {
finder = new User();
setId(finderElement, finder);
setName(finderElement, finder);
}
log.setFinder(finder);
}
}
private void setText(Element logElement, Log log) throws DataConversionException {
final Element textElement = logElement.getChild(TEXT, groundspeakNamespace);
log.setText(textElement.getTextTrim());
log.setTextEncoded(textElement.getAttribute(ENCODED).getBooleanValue());
}
private void setType(Element logElement, Log log) {
log.setType(logElement.getChild(TYPE, groundspeakNamespace).getTextTrim());
}
private void setId(Element logElement, Log log) throws DataConversionException {
log.setId(logElement.getAttribute(ID).getLongValue());
}
private void setDate(Element logElement, Log log) {
final String dateText = logElement.getChild(DATE, groundspeakNamespace).getTextTrim();
final LocalDateTime date = LocalDateTime.parse(dateText, DateTimeFormatter.ISO_DATE_TIME);
log.setDate(date);
}
private void setEncodedHints(Element cacheElement, Cache cache) {
cache.setEncodedHints(cacheElement.getChild(ENCODED_HINTS, groundspeakNamespace).getTextTrim());
}
private void setLongDescription(Element cacheElement, Cache cache) throws DataConversionException {
final Element longDescription = cacheElement.getChild(LONG_DESCRIPTION, groundspeakNamespace);
cache.setLongDescription(longDescription.getTextTrim());
cache.setLongDescriptionHtml(longDescription.getAttribute(HTML).getBooleanValue());
}
private void setShortDescription(Element cacheElement, Cache cache) throws DataConversionException {
final Element shortDescription = cacheElement.getChild(SHORT_DESCRIPTION, groundspeakNamespace);
cache.setShortDescription(shortDescription.getTextTrim());
cache.setShortDescriptionHtml(shortDescription.getAttribute(HTML).getBooleanValue());
}
private void setState(Element cacheElement, Cache cache) {
cache.setState(cacheElement.getChild(STATE, groundspeakNamespace).getTextTrim());
}
private void setCountry(Element cacheElement, Cache cache) {
cache.setCountry(cacheElement.getChild(COUNTRY, groundspeakNamespace).getTextTrim());
}
private void setTerrain(Element cacheElement, Cache cache) {
cache.setTerrain(cacheElement.getChild(TERRAIN, groundspeakNamespace).getTextTrim());
}
private void setDifficulty(Element cacheElement, Cache cache) {
cache.setDifficulty(cacheElement.getChild(DIFFICULTY, groundspeakNamespace).getTextTrim());
}
private void setAttributes(Element cacheElement, Cache cache) throws DataConversionException {
final Element attributesElement = cacheElement.getChild(ATTRIBUTES, groundspeakNamespace);
if (attributesElement != null) {
final List attributes = new ArrayList<>();
cache.setAttributes(attributes);
for (Element attributeElement : attributesElement.getChildren()) {
final Attribute attribute = new Attribute();
attributes.add(attribute);
setId(attributeElement, attribute);
setInc(attributeElement, attribute);
setText(attributeElement, attribute);
}
}
}
private void setText(Element attributeElement, Attribute attribute) {
attribute.setText(attributeElement.getTextTrim());
}
private void setInc(Element attributeElement, Attribute attribute) throws DataConversionException {
attribute.setInc(attributeElement.getAttribute(INC).getBooleanValue());
}
private void setId(Element attributeElement, Attribute attribute) throws DataConversionException {
attribute.setId(attributeElement.getAttribute(ID).getIntValue());
}
private void setContainer(Element cacheElement, Cache cache) {
cache.setContainer(cacheElement.getChild(CONTAINER, groundspeakNamespace).getTextTrim());
}
private void setType(Element cacheElement, Cache cache) {
cache.setType(cacheElement.getChild(TYPE, groundspeakNamespace).getTextTrim());
}
private void setOwner(Element cacheElement, Cache cache) throws DataConversionException {
final Element ownerElement = cacheElement.getChild(OWNER, groundspeakNamespace);
if (ownerElement != null) {
final Long userId = ownerElement.getAttribute(ID).getLongValue();
User owner = userCache.get(userId);
if (owner == null) {
owner = new User();
setId(ownerElement, owner);
setName(ownerElement, owner);
}
cache.setOwner(owner);
}
}
private void setId(Element userElement, User user) throws DataConversionException {
user.setId(userElement.getAttribute(ID).getLongValue());
}
private void setName(Element userElement, User user) {
user.setName(userElement.getTextTrim());
}
private void setPlacedBy(Element cacheElement, Cache cache) {
cache.setPlacedBy(cacheElement.getChild(PLACED_BY, groundspeakNamespace).getTextTrim());
}
private void setArchived(Element cacheElement, Cache cache) throws DataConversionException {
cache.setArchived(cacheElement.getAttribute(ARCHIVED).getBooleanValue());
}
private void setAvailable(Element cacheElement, Cache cache) throws DataConversionException {
cache.setAvailable(cacheElement.getAttribute(AVAILABLE).getBooleanValue());
}
private void setId(Element cacheElement, Cache cache) throws DataConversionException {
cache.setId(cacheElement.getAttribute(ID).getLongValue());
}
private void setType(Element cacheElement, Waypoint waypoint) {
waypoint.setType(cacheElement.getChild(TYPE, defaultNamespace).getTextTrim());
}
private void setSym(Element cacheElement, Waypoint waypoint) {
waypoint.setSymbol(cacheElement.getChild(SYM, defaultNamespace).getTextTrim());
}
private void setUrlName(Element cacheElement, Waypoint waypoint) throws MalformedURLException {
waypoint.setUrlName(cacheElement.getChild(URLNAME, defaultNamespace).getTextTrim());
}
private void setUrl(Element cacheElement, Waypoint waypoint) throws MalformedURLException {
waypoint.setUrl(new URL(cacheElement.getChild(URL, defaultNamespace).getTextTrim()));
}
private void setDescription(Element cacheElement, Waypoint waypoint) {
waypoint.setDescription(cacheElement.getChild(DESC, defaultNamespace).getTextTrim());
}
private void setWaypointName(Element cacheElement, Waypoint waypoint) {
waypoint.setName(cacheElement.getChild(NAME, defaultNamespace).getTextTrim());
}
private void setLatitudeAndLongitude(Element cacheElement, Waypoint waypoint) throws DataConversionException {
waypoint.setLatitude(cacheElement.getAttribute(LAT).getDoubleValue());
waypoint.setLongitude(cacheElement.getAttribute(LON).getDoubleValue());
}
private void setTime(Element cacheElement, Waypoint waypoint) {
final String timeText = cacheElement.getChild(TIME, defaultNamespace).getTextTrim();
final LocalDateTime date = LocalDateTime.parse(timeText, DateTimeFormatter.ISO_DATE_TIME);
waypoint.setTime(date);
}
private void setName(Element cacheElement, Cache cache) {
cache.setName(cacheElement.getChild(NAME, groundspeakNamespace).getTextTrim());
}
private void fireEvent(ProgressEvent event) {
listeners.stream().forEach((l) -> {
l.progress(event);
});
}
private void countLineNumbers() {
int totalNumberOfLines = 0;
Charset charset = Charset.forName("UTF-8");
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = Files.newBufferedReader(gpxFile.toPath(), charset)) {
String line = null;
while ((line = reader.readLine()) != null) {
totalNumberOfLines++;
}
fireEvent(new ProgressEvent("GPX Reader",
ProgressEvent.State.RUNNING,
totalNumberOfLines + " lines to read!"));
} catch (IOException x) {
x.printStackTrace();
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.model;
/**
* @author Andreas Billmann
*/
public class Attribute {
private Integer id;
private boolean inc;
private String text;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public boolean isInc() {
return inc;
}
public void setInc(boolean inc) {
this.inc = inc;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

View File

@@ -0,0 +1,231 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.model;
import java.util.List;
/**
* @author Andreas Billmann
*/
public class Cache {
private Long id;
private boolean available;
private boolean archived;
private String name;
private String placedBy;
private User owner;
private String type;
private String container;
private List<Attribute> attributes;
private String difficulty;
private String terrain;
private String country;
private String state;
private String shortDescription;
private boolean shortDescriptionHtml;
private String longDescription;
private boolean longDescriptionHtml;
private String encodedHints;
private List<Log> logs;
private List<TravelBug> travelBugs;
private Waypoint mainWayPoint;
public Waypoint getMainWayPoint() {
return mainWayPoint;
}
public void setMainWayPoint(Waypoint mainWayPoint) {
this.mainWayPoint = mainWayPoint;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
public boolean isArchived() {
return archived;
}
public void setArchived(boolean archived) {
this.archived = archived;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPlacedBy() {
return placedBy;
}
public void setPlacedBy(String placedBy) {
this.placedBy = placedBy;
}
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getContainer() {
return container;
}
public void setContainer(String container) {
this.container = container;
}
public List<Attribute> getAttributes() {
return attributes;
}
public void setAttributes(List<Attribute> attributes) {
this.attributes = attributes;
}
public String getDifficulty() {
return difficulty;
}
public void setDifficulty(String difficulty) {
this.difficulty = difficulty;
}
public String getTerrain() {
return terrain;
}
public void setTerrain(String terrain) {
this.terrain = terrain;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getShortDescription() {
return shortDescription;
}
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
public boolean isShortDescriptionHtml() {
return shortDescriptionHtml;
}
public void setShortDescriptionHtml(boolean shortDescriptionHtml) {
this.shortDescriptionHtml = shortDescriptionHtml;
}
public String getLongDescription() {
return longDescription;
}
public void setLongDescription(String longDescription) {
this.longDescription = longDescription;
}
public boolean isLongDescriptionHtml() {
return longDescriptionHtml;
}
public void setLongDescriptionHtml(boolean longDescriptionHtml) {
this.longDescriptionHtml = longDescriptionHtml;
}
public String getEncodedHints() {
return encodedHints;
}
public void setEncodedHints(String encodedHints) {
this.encodedHints = encodedHints;
}
public List<Log> getLogs() {
return logs;
}
public void setLogs(List<Log> logs) {
this.logs = logs;
}
public List<TravelBug> getTravelBugs() {
return travelBugs;
}
public void setTravelBugs(List<TravelBug> travelBugs) {
this.travelBugs = travelBugs;
}
@Override
public String toString() {
return "Cache{"
+ "name='" + name + '\''
+ '}';
}
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.model;
import java.util.List;
/**
* @author Andreas Billmann <abi@geofroggerfx.de>
*/
public class CacheUtils {
public static final String FOUND_IT = "Found it";
public static boolean hasUserFoundCache(Cache cache, Long currentUser) {
boolean foundIt = false;
if (currentUser != null) {
List<Log> logs = cache.getLogs();
if (logs != null) {
for (Log log : logs) {
if (isCurrentUserLogUser(log, currentUser) && isLogTypeFoundIt(log)) {
foundIt = true;
break;
}
}
}
}
return foundIt;
}
private static boolean isCurrentUserLogUser(Log log, Long currentUser) {
return log.getFinder().getId().equals(currentUser);
}
private static boolean isLogTypeFoundIt(Log log) {
return log.getType().equals(FOUND_IT);
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.model;
import java.time.LocalDateTime;
/**
* @author Andreas Billmann
*/
public class Log {
private Long id;
private LocalDateTime date;
private String type;
private User finder;
private boolean textEncoded;
private String text;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public LocalDateTime getDate() {
return date;
}
public void setDate(LocalDateTime date) {
this.date = date;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public User getFinder() {
return finder;
}
public void setFinder(User finder) {
this.finder = finder;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public boolean isTextEncoded() {
return textEncoded;
}
public void setTextEncoded(boolean textEncoded) {
this.textEncoded = textEncoded;
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.model;
/**
* @author Andreas Billmann
*/
public class TravelBug {
private Long id;
private String ref;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getRef() {
return ref;
}
public void setRef(String ref) {
this.ref = ref;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.model;
/**
* @author Andreas Billmann
*/
public class User {
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.model;
import java.net.URL;
import java.time.LocalDateTime;
/**
* @author Andreas Billmann
*/
public class Waypoint {
private Long id;
private double latitude;
private double longitude;
private String name;
private LocalDateTime time;
private String description;
private URL url;
private String urlName;
private String symbol;
private String type;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public void setTime(LocalDateTime time) {
this.time = time;
}
public LocalDateTime getTime() {
return time;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public URL getUrl() {
return url;
}
public void setUrl(URL url) {
this.url = url;
}
public String getUrlName() {
return urlName;
}
public void setUrlName(String urlName) {
this.urlName = urlName;
}
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.service;
import de.frosch95.geofrogger.application.ProgressListener;
import de.frosch95.geofrogger.model.Cache;
import java.util.List;
/**
* @author Andreas
*/
public interface CacheService {
void storeCaches(List<Cache> caches);
List<Cache> getAllCaches();
void addListener(ProgressListener listener);
}

View File

@@ -0,0 +1,325 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.frosch95.geofrogger.service;
import de.frosch95.geofrogger.application.ProgressEvent;
import de.frosch95.geofrogger.application.ProgressListener;
import de.frosch95.geofrogger.application.ServiceManager;
import de.frosch95.geofrogger.model.Cache;
import de.frosch95.geofrogger.model.User;
import de.frosch95.geofrogger.model.Waypoint;
import de.frosch95.geofrogger.sql.DatabaseService;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Andreas
*/
public class CacheServiceImpl implements CacheService {
private static final String SAVE_CACHE = "INSERT INTO geocache("
+ "id,"
+ "available,"
+ "archived,"
+ "name,"
+ "placedBy,"
+ "ownerId,"
+ "type,"
+ "container,"
+ "difficulty,"
+ "terrain,"
+ "country,"
+ "state,"
+ "shortDescription,"
+ "shortDescriptionHtml,"
+ "longDescription,"
+ "longDescriptionHtml,"
+ "encodedHints,"
+ "mainWaypointId"
+ ") values ("
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?"
+ ")";
private static final String SAVE_WAYPOINT = "INSERT INTO waypoint("
+ "id,"
+ "latitude,"
+ "longitude,"
+ "name,"
+ "time,"
+ "description,"
+ "url,"
+ "urlName,"
+ "symbol,"
+ "type"
+ ") values ("
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?,"
+ "?"
+ ")";
private static final String COUNT_ALL_CACHES = "SELECT count(*) FROM geocache";
private static final String LOAD_ALL_CACHES = "SELECT * FROM geocache ORDER BY ID";
private static final String LOAD_CACHE_BY_ID = "SELECT * FROM geocache WHERE ID = ?";
private static final String LOAD_ALL_WAYPOINTS = "SELECT * FROM waypoint ORDER BY ID";
private final DatabaseService dbService = ServiceManager.getInstance().getDatabaseService();
private final List<ProgressListener> listeners = new ArrayList<>();
@Override
public void addListener(ProgressListener listener) {
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
@Override
public void storeCaches(List<Cache> caches) {
Connection connection = null;
try {
connection = dbService.getConnection();
try (PreparedStatement cacheStatement = connection.prepareStatement(SAVE_CACHE)) {
try (PreparedStatement waypointStatement = connection.prepareStatement(SAVE_WAYPOINT)) {
int currentCacheNumber = 0;
int numberOfCaches = caches.size();
for (Cache cache : caches) {
currentCacheNumber++;
fireEvent(new ProgressEvent("Database",
ProgressEvent.State.RUNNING,
"Save caches to Database " + currentCacheNumber + " / " + numberOfCaches,
(double) currentCacheNumber / (double) numberOfCaches));
if (!doesCacheExist(cache.getId())) {
saveCacheObject(cacheStatement, cache);
saveWaypointObject(waypointStatement, cache);
}
}
}
}
connection.commit();
} catch (SQLException ex) {
Logger.getLogger(CacheServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
if (connection != null) {
try {
connection.rollback();
} catch (SQLException ex1) {
Logger.getLogger(CacheServiceImpl.class.getName()).log(Level.SEVERE, null, ex1);
}
}
}
}
private boolean doesCacheExist(Long id) {
boolean exists = false;
try {
try (PreparedStatement cacheStatement = dbService.getConnection().prepareStatement(LOAD_CACHE_BY_ID)) {
cacheStatement.setLong(1, id);
try (ResultSet cacheResultSet = cacheStatement.executeQuery()) {
exists = cacheResultSet.next();
}
}
} catch (SQLException ex) {
Logger.getLogger(CacheServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return exists;
}
@Override
public List<Cache> getAllCaches() {
List<Cache> caches = new ArrayList<>();
Connection connection;
try {
connection = dbService.getConnection();
try (PreparedStatement cacheStatement = connection.prepareStatement(LOAD_ALL_CACHES)) {
caches = resultSetToCacheList(cacheStatement, connection);
}
connection.commit();
} catch (SQLException ex) {
Logger.getLogger(CacheServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return caches;
}
private void saveCacheObject(PreparedStatement cacheStatement, Cache cache) throws SQLException {
cacheStatement.setLong(1, cache.getId());
cacheStatement.setBoolean(2, cache.isAvailable());
cacheStatement.setBoolean(3, cache.isArchived());
cacheStatement.setString(4, cache.getName());
cacheStatement.setString(5, cache.getPlacedBy());
cacheStatement.setLong(6, cache.getOwner().getId()); // ownerid
cacheStatement.setString(7, cache.getType()); // type
cacheStatement.setString(8, cache.getContainer()); //container
cacheStatement.setString(9, cache.getDifficulty()); //difficulty
cacheStatement.setString(10, cache.getTerrain()); //terrain
cacheStatement.setString(11, cache.getCountry()); //country
cacheStatement.setString(12, cache.getState()); //state
cacheStatement.setString(13, cache.getShortDescription()); //shortDescription
cacheStatement.setBoolean(14, cache.isShortDescriptionHtml()); //shortDescriptionHtml
cacheStatement.setString(15, cache.getLongDescription()); //longDescription
cacheStatement.setBoolean(16, cache.isLongDescriptionHtml()); //longDescriptionHtml
cacheStatement.setString(17, cache.getEncodedHints()); //encodedHints
cacheStatement.setLong(18, cache.getId()); //mainWaypointId
cacheStatement.execute();
}
private void saveWaypointObject(PreparedStatement waypointStatement, Cache cache) throws SQLException {
waypointStatement.setLong(1, cache.getId());
waypointStatement.setDouble(2, cache.getMainWayPoint().getLatitude()); // latitude
waypointStatement.setDouble(3, cache.getMainWayPoint().getLongitude()); //longitude,"
waypointStatement.setString(4, cache.getMainWayPoint().getName()); //name,"
waypointStatement.setTimestamp(5, Timestamp.valueOf(cache.getMainWayPoint().getTime())); //time,"
waypointStatement.setString(6, cache.getMainWayPoint().getDescription()); //description,"
waypointStatement.setString(7, cache.getMainWayPoint().getUrl().toExternalForm()); //url,"
waypointStatement.setString(8, cache.getMainWayPoint().getUrlName()); //urlName,"
waypointStatement.setString(9, cache.getMainWayPoint().getSymbol()); //symbol,"
waypointStatement.setString(10, cache.getMainWayPoint().getType()); //type"
waypointStatement.execute();
}
private List<Cache> resultSetToCacheList(final PreparedStatement cacheStatement, Connection connection) throws SQLException {
final List<Cache> caches = new ArrayList<>();
int numberOfCaches = 0;
try (PreparedStatement countStatement = connection.prepareStatement(COUNT_ALL_CACHES)) {
try (ResultSet countResultSet = countStatement.executeQuery()) {
if (countResultSet.next()) {
numberOfCaches = countResultSet.getInt(1);
}
}
}
try (ResultSet cacheResultSet = cacheStatement.executeQuery()) {
int currentCacheNumber = 0;
while (cacheResultSet.next()) {
currentCacheNumber++;
fireEvent(new ProgressEvent("Database",
ProgressEvent.State.RUNNING,
"Load caches from Database " + currentCacheNumber + " / " + numberOfCaches,
(double) currentCacheNumber / (double) numberOfCaches));
createCacheObject(cacheResultSet, caches);
}
}
final List<Waypoint> waypoints = new ArrayList<>();
try (PreparedStatement waypointStatement = connection.prepareStatement(LOAD_ALL_WAYPOINTS)) {
try (ResultSet waypointResultSet = waypointStatement.executeQuery()) {
int currentWaypointNumber = 0;
while (waypointResultSet.next()) {
currentWaypointNumber++;
fireEvent(new ProgressEvent("Database",
ProgressEvent.State.RUNNING,
"Load waypoints from Database " + currentWaypointNumber + " / " + numberOfCaches,
(double) currentWaypointNumber / (double) numberOfCaches));
createWaypointObject(waypointResultSet, waypoints);
}
}
}
int cacheSize = caches.size();
int waypointSize = waypoints.size();
assert cacheSize == waypointSize : "size of waypoints and size of caches have to be the same!!";
for (int i = 0; i < cacheSize; i++) {
final Cache cache = caches.get(i);
final Waypoint waypoint = waypoints.get(i);
assert cache.getId().equals(waypoint.getId());
fireEvent(new ProgressEvent("Database",
ProgressEvent.State.RUNNING,
"Add waypoints to caches " + i + " / " + cacheSize,
(double) i / (double) cacheSize));
cache.setMainWayPoint(waypoint);
}
return caches;
}
private void fireEvent(ProgressEvent event) {
listeners.stream().forEach((l) -> {
l.progress(event);
});
}
private void createCacheObject(final ResultSet cacheResultSet, final List<Cache> caches) throws SQLException {
Cache cache = new Cache();
cache.setId(cacheResultSet.getLong("id"));
cache.setAvailable(cacheResultSet.getBoolean("available"));
cache.setAvailable(cacheResultSet.getBoolean("archived"));
cache.setName(cacheResultSet.getString("name"));
cache.setPlacedBy(cacheResultSet.getString("placedBy"));
cache.setType(cacheResultSet.getString("type"));
cache.setContainer(cacheResultSet.getString("container"));
cache.setDifficulty(cacheResultSet.getString("difficulty"));
cache.setTerrain(cacheResultSet.getString("terrain"));
cache.setCountry(cacheResultSet.getString("country"));
cache.setState(cacheResultSet.getString("state"));
cache.setShortDescription(cacheResultSet.getString("shortDescription"));
cache.setShortDescriptionHtml(cacheResultSet.getBoolean("shortDescriptionHtml"));
cache.setLongDescription(cacheResultSet.getString("longDescription"));
cache.setLongDescriptionHtml(cacheResultSet.getBoolean("longDescriptionHtml"));
cache.setEncodedHints(cacheResultSet.getString("encodedHints"));
User user = new User();
user.setName("aus der DB");
user.setId(cacheResultSet.getLong("ownerId"));
cache.setOwner(user);
caches.add(cache);
}
private void createWaypointObject(final ResultSet waypointResultSet, final List<Waypoint> waypoints) throws SQLException {
Waypoint waypoint = new Waypoint();
//cache.setMainWayPoint(waypoint);
waypoint.setId(waypointResultSet.getLong("id"));
waypoint.setLatitude(waypointResultSet.getDouble("latitude"));
waypoint.setLongitude(waypointResultSet.getDouble("longitude"));
waypoint.setName(waypointResultSet.getString("name"));
waypoint.setTime(waypointResultSet.getTimestamp("time").toLocalDateTime());
waypoint.setDescription(waypointResultSet.getString("description"));
try {
waypoint.setUrl(new URL(waypointResultSet.getString("url")));
} catch (MalformedURLException ex) {
Logger.getLogger(CacheServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
waypoint.setUrlName(waypointResultSet.getString("urlName"));
waypoint.setSymbol(waypointResultSet.getString("symbol"));
waypoint.setType(waypointResultSet.getString("type"));
waypoints.add(waypoint);
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.service;
/**
* @author Andreas
*/
public interface UserService {
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.sql;
import java.sql.Connection;
import java.sql.SQLException;
/**
* @author Andreas
*/
public interface DatabaseService {
Connection getConnection() throws SQLException;
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.frosch95.geofrogger.sql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Andreas
*/
public class DatabaseServiceImpl implements DatabaseService {
private static final String CREATE_GEOCACHE_TABLE =
"CREATE TABLE geocache ("
+ "id BIGINT,"
+ "available BOOLEAN,"
+ "archived BOOLEAN,"
+ "name VARCHAR(255),"
+ "placedBy VARCHAR(255),"
+ "ownerId BIGINT,"
+ "type VARCHAR(255),"
+ "container VARCHAR(255),"
+ "difficulty VARCHAR(10),"
+ "terrain VARCHAR(10),"
+ "country VARCHAR(255),"
+ "state VARCHAR(255),"
+ "shortDescription CLOB,"
+ "shortDescriptionHtml BOOLEAN,"
+ "longDescription CLOB,"
+ "longDescriptionHtml BOOLEAN,"
+ "encodedHints CLOB,"
+ "mainWaypointId BIGINT"
+ ");";
private static final String WAYPOINT_TABLE =
"CREATE TABLE waypoint ("
+ "id BIGINT,"
+ "latitude DECIMAL(9,6),"
+ "longitude DECIMAL(9,6),"
+ "name VARCHAR(255),"
+ "time TIMESTAMP,"
+ "description CLOB,"
+ "url VARCHAR(255),"
+ "urlName VARCHAR(255),"
+ "symbol VARCHAR(255),"
+ "type VARCHAR(255)"
+ ");";
private Connection con;
public DatabaseServiceImpl() {
try {
con = DriverManager.getConnection("jdbc:h2:./geofroggerfxdb;IFEXISTS=TRUE", "sa", "sa");
con.setAutoCommit(false);
} catch (SQLException ex) {
setupDatabase();
}
}
@Override
public Connection getConnection() throws SQLException {
if (con == null) {
throw new SQLException("no connection available");
}
return con;
}
private void setupDatabase() {
Statement statement = null;
try {
Class.forName("org.h2.Driver");
con = DriverManager.getConnection("jdbc:h2:./geofroggerfxdb", "sa", "sa");
con.setAutoCommit(false);
statement = con.createStatement();
statement.execute(CREATE_GEOCACHE_TABLE);
statement.execute(WAYPOINT_TABLE);
con.commit();
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(DatabaseServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (statement != null) try {
statement.close();
} catch (SQLException ex) {
Logger.getLogger(DatabaseServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}