diff --git a/src/de/frosch95/geofrogger/fx/GeoFroggerFXMain.java b/src/de/frosch95/geofrogger/fx/GeoFroggerFXMain.java index df18425..4754004 100644 --- a/src/de/frosch95/geofrogger/fx/GeoFroggerFXMain.java +++ b/src/de/frosch95/geofrogger/fx/GeoFroggerFXMain.java @@ -30,8 +30,11 @@ import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; import javafx.scene.text.Font; import javafx.stage.Stage; +import org.scenicview.ScenicView; import java.util.ResourceBundle; @@ -48,6 +51,12 @@ public class GeoFroggerFXMain extends Application { Scene scene = new Scene(root); stage.setScene(scene); stage.show(); + + scene.setOnKeyPressed(keyEvent -> { + if (isScenicViewShortcutPressed(keyEvent)) { + ScenicView.show(scene); + } + }); } private void loadCustomFonts() { @@ -63,6 +72,10 @@ public class GeoFroggerFXMain extends Application { Font.loadFont(GeoFroggerFXMain.class.getResource("/fonts/FiraSansOT-RegularItalic.otf").toExternalForm(), 12); } + private boolean isScenicViewShortcutPressed(final KeyEvent keyEvent) { + return keyEvent.isAltDown() && keyEvent.isControlDown() && keyEvent.getCode().equals(KeyCode.V); + } + @Override public void stop() throws Exception { System.out.println("stop"); diff --git a/src/de/frosch95/geofrogger/fx/cachelist/CacheListController.java b/src/de/frosch95/geofrogger/fx/cachelist/CacheListController.java index 3ffb0d1..dff20f9 100644 --- a/src/de/frosch95/geofrogger/fx/cachelist/CacheListController.java +++ b/src/de/frosch95/geofrogger/fx/cachelist/CacheListController.java @@ -25,17 +25,22 @@ */ package de.frosch95.geofrogger.fx.cachelist; +import de.frosch95.geofrogger.application.ServiceManager; import de.frosch95.geofrogger.application.SessionContext; import de.frosch95.geofrogger.application.SessionContextListener; import de.frosch95.geofrogger.fx.components.CacheListCell; +import de.frosch95.geofrogger.fx.components.IconManager; import de.frosch95.geofrogger.model.Cache; +import de.frosch95.geofrogger.service.CacheService; +import de.frosch95.geofrogger.service.CacheSortField; +import de.frosch95.geofrogger.service.SortDirection; 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.control.*; +import javafx.scene.image.ImageView; import javafx.util.Callback; import java.net.URL; @@ -43,6 +48,8 @@ import java.util.List; import java.util.ResourceBundle; import static de.frosch95.geofrogger.fx.utils.JavaFXUtils.addClasses; +import static de.frosch95.geofrogger.service.CacheSortField.*; +import static de.frosch95.geofrogger.service.SortDirection.*; /** * FXML Controller class @@ -53,6 +60,9 @@ public class CacheListController implements Initializable, SessionContextListene private static final String CACHE_LIST_ACTION_ICONS = "cache-list-action-icons"; private final SessionContext sessionContext = SessionContext.getInstance(); + private final CacheService cacheService = ServiceManager.getInstance().getCacheService(); + private CacheSortField currentSortField = NAME; + private SortDirection currentSortDirection = ASC; @FXML private ListView cacheListView; @@ -61,10 +71,7 @@ public class CacheListController implements Initializable, SessionContextListene private Label cacheNumber; @FXML - private Label filterIcon; - - @FXML - private Label sortIcon; + private MenuButton menuIcon; /** * Initializes the controller class. @@ -73,6 +80,7 @@ public class CacheListController implements Initializable, SessionContextListene * @param rb */ @Override + @SuppressWarnings("unchecked") public void initialize(URL url, ResourceBundle rb) { setSessionListener(); setCellFactory(); @@ -82,11 +90,11 @@ public class CacheListController implements Initializable, SessionContextListene sessionContext.setData("current-cache", newValue) ); - addClasses(filterIcon, CACHE_LIST_ACTION_ICONS); - addClasses(sortIcon, CACHE_LIST_ACTION_ICONS); + initListMenuButton(rb); } @Override + @SuppressWarnings("unchecked") public void sessionContextChanged() { List caches = (List) sessionContext.getData("cache-list"); Platform.runLater(() -> { @@ -105,4 +113,33 @@ public class CacheListController implements Initializable, SessionContextListene sessionContext.addListener("cache-list", this); } + private void initListMenuButton(final ResourceBundle rb) { + addClasses(menuIcon, CACHE_LIST_ACTION_ICONS); + menuIcon.setGraphic(new ImageView(IconManager.getIcon("/icons/iconmonstr-menu-icon.png", IconManager.IconSize.SMALL))); + menuIcon.getItems().addAll(createSortMenu(rb)); + } + + private Menu createSortMenu(final ResourceBundle rb) { + Menu sortMenu = new Menu(rb.getString("menu.title.sort")); + sortMenu.getItems().addAll( + createSortButton(rb, NAME), + createSortButton(rb, TYPE), + createSortButton(rb, DIFFICULTY), + createSortButton(rb, TERRAIN), + createSortButton(rb, OWNER), + createSortButton(rb, PLACEDBY)); + return sortMenu; + } + + private MenuItem createSortButton(final ResourceBundle rb, final CacheSortField field) { + MenuItem button = new MenuItem(rb.getString("sort.cache."+field.getFieldName())); + button.setOnAction(actionEvent -> { + currentSortDirection = (field.equals(currentSortField) && currentSortDirection.equals(ASC)) ? DESC : ASC; + currentSortField = field; + sessionContext.setData("cache-list", cacheService.getAllCaches(currentSortField, currentSortDirection)); + }); + return button; + } + + } diff --git a/src/de/frosch95/geofrogger/fx/cachelist/cache_list.fxml b/src/de/frosch95/geofrogger/fx/cachelist/cache_list.fxml index 295f787..92ad7d3 100644 --- a/src/de/frosch95/geofrogger/fx/cachelist/cache_list.fxml +++ b/src/de/frosch95/geofrogger/fx/cachelist/cache_list.fxml @@ -12,18 +12,11 @@ - diff --git a/src/de/frosch95/geofrogger/fx/geofrogger.css b/src/de/frosch95/geofrogger/fx/geofrogger.css index 19b3050..664c0eb 100644 --- a/src/de/frosch95/geofrogger/fx/geofrogger.css +++ b/src/de/frosch95/geofrogger/fx/geofrogger.css @@ -58,4 +58,12 @@ .slider:disabled { -fx-opacity: 0.8; +} + +.menu-button.cache-list-action-icons { + -fx-padding: 0 0 0 0; +} + +.menu-button.cache-list-action-icons .label{ + -fx-padding: 2 2 2 2; } \ No newline at end of file diff --git a/src/de/frosch95/geofrogger/fx/geofrogger/GeofroggerController.java b/src/de/frosch95/geofrogger/fx/geofrogger/GeofroggerController.java index ada6a80..d3d42cc 100644 --- a/src/de/frosch95/geofrogger/fx/geofrogger/GeofroggerController.java +++ b/src/de/frosch95/geofrogger/fx/geofrogger/GeofroggerController.java @@ -31,6 +31,8 @@ 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 de.frosch95.geofrogger.service.CacheSortField; +import de.frosch95.geofrogger.service.SortDirection; import javafx.application.Platform; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; @@ -54,6 +56,9 @@ import java.util.ResourceBundle; import java.util.logging.Level; import java.util.logging.Logger; +import static de.frosch95.geofrogger.service.CacheSortField.*; +import static de.frosch95.geofrogger.service.SortDirection.*; + /** * FXML Controller class * @@ -170,7 +175,7 @@ public class GeofroggerController implements Initializable { @Override protected Void call() throws Exception { updateStatus("Load caches from database.", ProgressIndicator.INDETERMINATE_PROGRESS); - sessionContext.setData("cache-list", cacheService.getAllCaches()); + sessionContext.setData("cache-list", cacheService.getAllCaches(NAME, ASC)); updateStatus("All caches loaded.", 0); return null; } @@ -209,7 +214,7 @@ public class GeofroggerController implements Initializable { updateStatus("All caches are stored in database", 0); updateStatus("Load caches from database.", ProgressIndicator.INDETERMINATE_PROGRESS); - sessionContext.setData("cache-list", cacheService.getAllCaches()); + sessionContext.setData("cache-list", cacheService.getAllCaches(NAME, ASC)); updateStatus("All caches loaded.", 0); } } catch (IOException ex) { diff --git a/src/de/frosch95/geofrogger/fx/geofrogger_de.properties b/src/de/frosch95/geofrogger/fx/geofrogger_de.properties index adcb7ad..54ef470 100644 --- a/src/de/frosch95/geofrogger/fx/geofrogger_de.properties +++ b/src/de/frosch95/geofrogger/fx/geofrogger_de.properties @@ -4,6 +4,9 @@ menu.title.quit = Beenden menu.title.help = Hilfe menu.title.about = \u00dcber GeoFroggerFX +menu.title.sort = Sortieren +menu.title.filter = Filtern + label.text.cache.list=Caches label.text.name=Name: label.text.difficulty=Schwierigkeit: @@ -18,4 +21,11 @@ label.text.htmldescription=HTML Beschreibung label.text.longdescription=Lange Beschreibung: tab.text.descriptions=Beschreibungen -tab.text.general=Allgemein \ No newline at end of file +tab.text.general=Allgemein + +sort.cache.name = GC Code +sort.cache.type = Art +sort.cache.difficulty = Schwierigkeitsgrad +sort.cache.terrain = Gel\u00E4nde +sort.cache.placedBy = Platziert von +sort.cache.owner = Betreut von \ No newline at end of file diff --git a/src/de/frosch95/geofrogger/fx/geofrogger_en.properties b/src/de/frosch95/geofrogger/fx/geofrogger_en.properties index b1b87e0..ff0968b 100644 --- a/src/de/frosch95/geofrogger/fx/geofrogger_en.properties +++ b/src/de/frosch95/geofrogger/fx/geofrogger_en.properties @@ -4,6 +4,9 @@ menu.title.quit = Quit menu.title.help = Help menu.title.about = About GeoFroggerFX +menu.title.sort = Sort +menu.title.filter = Filter + label.text.cache.list=Caches label.text.name=Name: label.text.difficulty=Difficulty: @@ -18,4 +21,11 @@ label.text.htmldescription=HTML Description label.text.longdescription=Long description: tab.text.descriptions=Descriptions -tab.text.general=General \ No newline at end of file +tab.text.general=General + +sort.cache.name = GC Code +sort.cache.type = Type +sort.cache.difficulty = Difficulty +sort.cache.terrain = Terrain +sort.cache.placedBy = Placed by +sort.cache.owner = Owner \ No newline at end of file diff --git a/src/de/frosch95/geofrogger/service/CacheService.java b/src/de/frosch95/geofrogger/service/CacheService.java index 071a4a2..c57fdfc 100644 --- a/src/de/frosch95/geofrogger/service/CacheService.java +++ b/src/de/frosch95/geofrogger/service/CacheService.java @@ -36,7 +36,7 @@ import java.util.List; public interface CacheService { void storeCaches(List caches); - List getAllCaches(); + List getAllCaches(CacheSortField sortField, SortDirection direction); void addListener(ProgressListener listener); } diff --git a/src/de/frosch95/geofrogger/service/CacheServiceImpl.java b/src/de/frosch95/geofrogger/service/CacheServiceImpl.java index 45ab32b..14139a0 100644 --- a/src/de/frosch95/geofrogger/service/CacheServiceImpl.java +++ b/src/de/frosch95/geofrogger/service/CacheServiceImpl.java @@ -74,13 +74,20 @@ public class CacheServiceImpl implements CacheService { } @Override - public List getAllCaches() { + @SuppressWarnings("unchecked") + public List getAllCaches(CacheSortField sortField, SortDirection direction) { - EntityManager em = dbService.getEntityManager(); List caches = new ArrayList<>(); - List result = em.createQuery("select c from Cache c").getResultList(); - if (result != null) { - caches = result; + try { + EntityManager em = dbService.getEntityManager(); + String query = "select c from Cache c order by c."+sortField.getFieldName()+" "+direction.toString(); + System.out.println("query: "+query); + List result = em.createQuery(query).getResultList(); + if (result != null) { + caches = result; + } + } catch (Exception e) { + e.printStackTrace(); } return caches; diff --git a/src/de/frosch95/geofrogger/service/CacheSortField.java b/src/de/frosch95/geofrogger/service/CacheSortField.java new file mode 100644 index 0000000..da3d03e --- /dev/null +++ b/src/de/frosch95/geofrogger/service/CacheSortField.java @@ -0,0 +1,25 @@ +package de.frosch95.geofrogger.service; + +/** + * Sort fields on cache object + * + * @author abi + */ +public enum CacheSortField { + NAME("name"), + TYPE("type"), + DIFFICULTY("difficulty"), + TERRAIN("terrain"), + PLACEDBY("placedBy"), + OWNER("owner"); + + private String fieldName; + + private CacheSortField(String fieldName) { + this.fieldName = fieldName; + } + + public String getFieldName() { + return fieldName; + } +} diff --git a/src/de/frosch95/geofrogger/service/SortDirection.java b/src/de/frosch95/geofrogger/service/SortDirection.java new file mode 100644 index 0000000..97977b7 --- /dev/null +++ b/src/de/frosch95/geofrogger/service/SortDirection.java @@ -0,0 +1,11 @@ +package de.frosch95.geofrogger.service; + +/** + * direction of sorting + * + * @author abi + */ +public enum SortDirection { + ASC, + DESC +}