diff --git a/simpleexample/src/main/java/fxutil/doc/AbstractDocumentStorageImpl.java b/simpleexample/src/main/java/fxutil/doc/AbstractDocumentStorageImpl.java index 95def60933cc0f2bc2caf7a9bbdd78fe8d82e43d..94fa81aad1d57979b972a2fe62864e8dd4384adc 100644 --- a/simpleexample/src/main/java/fxutil/doc/AbstractDocumentStorageImpl.java +++ b/simpleexample/src/main/java/fxutil/doc/AbstractDocumentStorageImpl.java @@ -13,14 +13,14 @@ import java.util.Collection; * Incomplete implementation of **IDocumentStorage**, to simplify implementing ones for specific * document and location types. The main missing methods are for getting and setting the current * document, creating an empty one and creating an **InputStream** from a location. - * + * * @author hal * * @param <D> the document type * @param <L> the location type */ public abstract class AbstractDocumentStorageImpl<D, L> - implements IDocumentStorage<L>, IDocumentPersistence<D, L> { +implements IDocumentStorage<L>, IDocumentPersistence<D, L> { private L documentLocation = null; @@ -43,14 +43,14 @@ public abstract class AbstractDocumentStorageImpl<D, L> /** * Returns the current document. - * + * * @return the current document */ protected abstract D getDocument(); /** - * Sets the current document - * + * Sets the current document. + * * @param document the new document */ protected abstract void setDocument(D document); @@ -88,7 +88,7 @@ public abstract class AbstractDocumentStorageImpl<D, L> /** * Creates a new and empty document. - * + * * @return */ protected abstract D createDocument(); @@ -99,11 +99,11 @@ public abstract class AbstractDocumentStorageImpl<D, L> } /** - * Creates an ImportStream from a location - * - * @param location - * @return - * @throws IOException + * Creates an InputStream from a location. + * + * @param location the location + * @return the location's InputStream + * @throws IOException when the InputStream cannot be created */ protected abstract InputStream toInputStream(L location) throws IOException; diff --git a/simpleexample/src/main/java/fxutil/doc/FileMenuController.java b/simpleexample/src/main/java/fxutil/doc/FileMenuController.java index 692db2bcb6aabf8e7fa82bce64373b4b754a306e..afe841ce47780cd736f31bc2e3d2659711a70491 100644 --- a/simpleexample/src/main/java/fxutil/doc/FileMenuController.java +++ b/simpleexample/src/main/java/fxutil/doc/FileMenuController.java @@ -79,15 +79,6 @@ public class FileMenuController { } } - private void showExceptionDialog(final String message) { - final Alert alert = new Alert(AlertType.ERROR, message, ButtonType.CLOSE); - alert.showAndWait(); - } - - private void showExceptionDialog(final String message, final Exception e) { - showExceptionDialog(message + ": " + e.getLocalizedMessage()); - } - void handleOpenAction(final File selection) { try { documentStorage.openDocument(selection); @@ -97,6 +88,15 @@ public class FileMenuController { } } + private void showExceptionDialog(final String message) { + final Alert alert = new Alert(AlertType.ERROR, message, ButtonType.CLOSE); + alert.showAndWait(); + } + + private void showExceptionDialog(final String message, final Exception e) { + showExceptionDialog(message + ": " + e.getLocalizedMessage()); + } + private void showSaveExceptionDialog(final File location, final Exception e) { showExceptionDialog("Oops, problem saving to " + location, e); } @@ -177,7 +177,7 @@ public class FileMenuController { private TextInputDialog inputDialog; @FXML - public void handleURLImportAction() { + public void handleUrlImportAction() { if (inputDialog == null) { inputDialog = new TextInputDialog(); } @@ -191,7 +191,7 @@ public class FileMenuController { break; } try { - if (handleURLImportAction(new URL(result.get()))) { + if (handleUrlImportAction(new URL(result.get()))) { break; } inputDialog.setHeaderText("Problems reading it..."); @@ -202,7 +202,7 @@ public class FileMenuController { } } - boolean handleURLImportAction(final URL url) { + boolean handleUrlImportAction(final URL url) { for (final IDocumentImporter importer : documentStorage.getDocumentImporters()) { try (InputStream input = url.openStream()) { importer.importDocument(input); diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentImporter.java b/simpleexample/src/main/java/fxutil/doc/IDocumentImporter.java index 9c7a83974e021401d573127229a4fb1f86b28198..1477a390dcbe9883f10f6e7be5909a02448726a7 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentImporter.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentImporter.java @@ -6,16 +6,16 @@ import java.io.InputStream; /** * An interface with a method for importing domain data from a location. The main use is supporting * an **import** action in a **File** menu. - * + * * @author hal * */ public interface IDocumentImporter { /** * Loads a document from the input stream and sets it as the current document. - * - * @param inputStream - * @throws IOException + * + * @param inputStream the document to import + * @throws IOException when the document cannot imported */ public void importDocument(InputStream inputStream) throws IOException; } diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentLoader.java b/simpleexample/src/main/java/fxutil/doc/IDocumentLoader.java index 5078db2013497373f7e0d84c557c086f2126db1b..586226104aee7306cbc66a234d13b773e55a49fc 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentLoader.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentLoader.java @@ -6,7 +6,7 @@ import java.io.InputStream; * An interface with a method for loading and returning a document (domain data container) from an * InputStream. This allows various ways of loading or importing domain data, with different sources * and formats. - * + * * @author hal * * @param <D> the document type @@ -14,10 +14,10 @@ import java.io.InputStream; public interface IDocumentLoader<D> { /** * Loads and returns a new document from an InputStream - * - * @param inputStream - * @return - * @throws Exception + * + * @param inputStream the InputStream to load from + * @return the loaded document + * @throws Exception when the document couldn't be loaded */ public D loadDocument(InputStream inputStream) throws Exception; } diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentSaver.java b/simpleexample/src/main/java/fxutil/doc/IDocumentSaver.java index 2bca45c1c2374498fd73edc2b62ab1a39625b75a..9bfa7be83c7723eed91e9ca7f96501c2dd923464 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentSaver.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentSaver.java @@ -3,7 +3,7 @@ package fxutil.doc; /** * An interface with a method for saving a document (domain data container) to a location. This * allows various ways of saving or exporting domain data, to different locations and formats. - * + * * @author hal * * @param <D> the document type @@ -12,10 +12,10 @@ package fxutil.doc; public interface IDocumentSaver<D, L> { /** * Saves the provided document to the provided location - * - * @param document - * @param documentLocation - * @throws Exception + * + * @param document the document to save + * @param documentLocation the location to save to + * @throws Exception when the document couldn't be saved */ public void saveDocument(D document, L documentLocation) throws Exception; } diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentStorage.java b/simpleexample/src/main/java/fxutil/doc/IDocumentStorage.java index 331770590165eb60b5aabc66bf871a5a04eca6ba..5eecaa0a3ed84d3f5cb1b98fc8ac0f2c48ebe0a4 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentStorage.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentStorage.java @@ -8,7 +8,7 @@ import java.util.Collection; * representing the document (domain data container) is implicit in the implementation of this * interface. The interface includes methods for getting and setting the location and creating, * opening and saving the (current) document. - * + * * @author hal * * @param <L> The type of the location, typically java.io.File. @@ -16,30 +16,30 @@ import java.util.Collection; public interface IDocumentStorage<L> { /** * Returns the current location (of the current document). - * + * * @return the current location */ public L getDocumentLocation(); /** * Sets the current location (of the current document), can be used by a save-as action. - * - * @param documentLocation + * + * @param documentLocation the new document location */ public void setDocumentLocation(L documentLocation); /** * Adds an IDocumentStorageListener that will be notified when the current location changes. - * - * @param documentStorageListener + * + * @param documentStorageListener the listener to add */ public void addDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener); /** * Removes an IDocumentStorageListener. - * - * @param documentStorageListener + * + * @param documentStorageListener the listener to remove */ public void removeDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener); @@ -61,7 +61,7 @@ public interface IDocumentStorage<L> { /** * Returns the set of IDocumentImporters, can be used by an import action. - * + * * @return */ public Collection<IDocumentImporter> getDocumentImporters(); diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentStorageListener.java b/simpleexample/src/main/java/fxutil/doc/IDocumentStorageListener.java index 15d0e6e6ee6027a1f0c05f5697532eca51c62e87..c5d3f0f94c8467330d40e1044d6a6d32fea03cf6 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentStorageListener.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentStorageListener.java @@ -3,15 +3,15 @@ package fxutil.doc; /** * Listener interface for the (current) location of the (current) document of an IDocumentStorage, * e.g. when a **save-as** action is performed. - * + * * @author hal * - * @param <L> + * @param <L> the document location type */ public interface IDocumentStorageListener<L> { /** * Notifies that the current document location has changed. - * + * * @param documentLocation the new document location * @param oldDocumentLocation the previous document location */ diff --git a/simpleexample/src/main/java/fxutil/doc/SimpleJsonFileStorageImpl.java b/simpleexample/src/main/java/fxutil/doc/SimpleJsonFileStorageImpl.java index 4f2633cbe6a753f719335ea304f232dca59cf9d0..b0817657508ed00de149fa796ee44628427a6f1e 100644 --- a/simpleexample/src/main/java/fxutil/doc/SimpleJsonFileStorageImpl.java +++ b/simpleexample/src/main/java/fxutil/doc/SimpleJsonFileStorageImpl.java @@ -1,16 +1,16 @@ package fxutil.doc; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.util.Collection; import java.util.Collections; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; public abstract class SimpleJsonFileStorageImpl<T> extends AbstractDocumentStorageImpl<T, File> - implements IDocumentStorage<File> { +implements IDocumentStorage<File> { private T document; diff --git a/simpleexample/src/main/java/simpleex/core/LatLong.java b/simpleexample/src/main/java/simpleex/core/LatLong.java index d69923238cf7e7b52d58d41c4c078dd8f1592349..438f188802868f2bf4200941e8dfff80b8e4ddeb 100644 --- a/simpleexample/src/main/java/simpleex/core/LatLong.java +++ b/simpleexample/src/main/java/simpleex/core/LatLong.java @@ -2,7 +2,10 @@ package simpleex.core; public class LatLong { - private final double latitude, longitude; + public static final String SEPARATOR = ","; + + private final double latitude; + private final double longitude; public LatLong(final double latitude, final double longitude) { super(); @@ -10,7 +13,6 @@ public class LatLong { this.longitude = longitude; } - public final static String SEPARATOR = ","; public double getLatitude() { return latitude; diff --git a/simpleexample/src/main/java/simpleex/json/LatLongDeserializer.java b/simpleexample/src/main/java/simpleex/json/LatLongDeserializer.java index f3c48cd12f485904bd69a43c62c18569da910fe8..ddf7f3ba2534dc2a8f7c348df7eee2930036e56b 100644 --- a/simpleexample/src/main/java/simpleex/json/LatLongDeserializer.java +++ b/simpleexample/src/main/java/simpleex/json/LatLongDeserializer.java @@ -1,6 +1,5 @@ package simpleex.json; -import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; @@ -8,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.IOException; import simpleex.core.LatLong; public class LatLongDeserializer extends JsonDeserializer<LatLong> { diff --git a/simpleexample/src/main/java/simpleex/json/LatLongSerializer.java b/simpleexample/src/main/java/simpleex/json/LatLongSerializer.java index 12342fd412b941eb26e66e00bee3eaf56c9f381e..59dfeb6fb57eccbacf6f91b8c16fb0d44d7c2c9a 100644 --- a/simpleexample/src/main/java/simpleex/json/LatLongSerializer.java +++ b/simpleexample/src/main/java/simpleex/json/LatLongSerializer.java @@ -1,9 +1,9 @@ package simpleex.json; -import java.io.IOException; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; import simpleex.core.LatLong; public class LatLongSerializer extends JsonSerializer<LatLong> { diff --git a/simpleexample/src/main/java/simpleex/json/LatLongsDeserializer.java b/simpleexample/src/main/java/simpleex/json/LatLongsDeserializer.java index 4b2508f0ab559c3cde3b73d1b40ec699ae905436..8e14f6bf4e0274920b6f75f43eff6f699d833f99 100644 --- a/simpleexample/src/main/java/simpleex/json/LatLongsDeserializer.java +++ b/simpleexample/src/main/java/simpleex/json/LatLongsDeserializer.java @@ -1,14 +1,14 @@ package simpleex.json; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; import simpleex.core.LatLong; import simpleex.core.LatLongs; diff --git a/simpleexample/src/main/java/simpleex/json/LatLongsSerializer.java b/simpleexample/src/main/java/simpleex/json/LatLongsSerializer.java index 8f5bae8f8943fbb123f347e908422f3f0d5bda09..4812b5288e440a94919182e209afba8d0d459023 100644 --- a/simpleexample/src/main/java/simpleex/json/LatLongsSerializer.java +++ b/simpleexample/src/main/java/simpleex/json/LatLongsSerializer.java @@ -1,9 +1,9 @@ package simpleex.json; -import java.io.IOException; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; import simpleex.core.LatLong; import simpleex.core.LatLongs; diff --git a/simpleexample/src/main/java/simpleex/ui/FxAppController.java b/simpleexample/src/main/java/simpleex/ui/FxAppController.java index 08431b70468a8027a87776e83983b4baa868eece..97506447db830032347f6c1c688ec74d3089e18e 100644 --- a/simpleexample/src/main/java/simpleex/ui/FxAppController.java +++ b/simpleexample/src/main/java/simpleex/ui/FxAppController.java @@ -1,7 +1,5 @@ package simpleex.ui; -import java.io.File; -import java.util.Optional; import fxmapcontrol.Location; import fxmapcontrol.MapBase; import fxmapcontrol.MapItemsControl; @@ -9,6 +7,8 @@ import fxmapcontrol.MapNode; import fxmapcontrol.MapProjection; import fxutil.doc.FileMenuController; import fxutil.doc.IDocumentListener; +import java.io.File; +import java.util.Optional; import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.geometry.Point2D; diff --git a/simpleexample/src/main/java/simpleex/ui/LatLongsApp.java b/simpleexample/src/main/java/simpleex/ui/LatLongsApp.java index 53a4a53c48024c81dd910fa0e8b8c0db1d4a9ec8..df7517b7527c6a182a46cc666bb257ff54bee49d 100644 --- a/simpleexample/src/main/java/simpleex/ui/LatLongsApp.java +++ b/simpleexample/src/main/java/simpleex/ui/LatLongsApp.java @@ -1,5 +1,10 @@ package simpleex.ui; +import fxutil.doc.AbstractDocumentStorageImpl; +import fxutil.doc.IDocumentImporter; +import fxutil.doc.IDocumentLoader; +import fxutil.doc.IDocumentPersistence; +import fxutil.doc.IDocumentStorage; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -9,11 +14,6 @@ import java.io.OutputStream; import java.util.Arrays; import java.util.Collection; import java.util.stream.Collectors; -import fxutil.doc.AbstractDocumentStorageImpl; -import fxutil.doc.IDocumentImporter; -import fxutil.doc.IDocumentLoader; -import fxutil.doc.IDocumentPersistence; -import fxutil.doc.IDocumentStorage; import simpleex.core.LatLongs; public class LatLongsApp { diff --git a/simpleexample/src/main/java/simpleex/ui/LatLongsStorage.java b/simpleexample/src/main/java/simpleex/ui/LatLongsStorage.java index de1caf14b65216b712609cb709ebf3a71c897c46..ede6de21e609859f7d9478cfc99440d41a225bb4 100644 --- a/simpleexample/src/main/java/simpleex/ui/LatLongsStorage.java +++ b/simpleexample/src/main/java/simpleex/ui/LatLongsStorage.java @@ -1,9 +1,9 @@ package simpleex.ui; -import java.io.File; import com.fasterxml.jackson.databind.module.SimpleModule; import fxutil.doc.IDocumentStorage; import fxutil.doc.SimpleJsonFileStorageImpl; +import java.io.File; import simpleex.core.LatLong; import simpleex.core.LatLongs; import simpleex.json.LatLongDeserializer; diff --git a/simpleexample/src/test/java/simpleex/json/AbstractJsonTest.java b/simpleexample/src/test/java/simpleex/json/AbstractJsonTest.java index 4aaed0172ca3158d0516dc5f6e014bba648648da..c6eb616d66c3d89861379b034d7f2f92c726581b 100644 --- a/simpleexample/src/test/java/simpleex/json/AbstractJsonTest.java +++ b/simpleexample/src/test/java/simpleex/json/AbstractJsonTest.java @@ -1,13 +1,13 @@ package simpleex.json; -import java.io.IOException; -import org.junit.Assert; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; +import java.io.IOException; +import org.junit.Assert; public abstract class AbstractJsonTest { diff --git a/simpleexample/src/test/java/simpleex/json/LatLongJsonTest.java b/simpleexample/src/test/java/simpleex/json/LatLongJsonTest.java index 9edcc39db8e84178451b25597c137685d73e56c1..a3c6d4a0cb40073ac120b2aed031936f0bca5f1e 100644 --- a/simpleexample/src/test/java/simpleex/json/LatLongJsonTest.java +++ b/simpleexample/src/test/java/simpleex/json/LatLongJsonTest.java @@ -1,9 +1,9 @@ package simpleex.json; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import com.fasterxml.jackson.databind.ObjectMapper; import simpleex.core.LatLong; public class LatLongJsonTest extends AbstractJsonTest { diff --git a/simpleexample/src/test/java/simpleex/json/LatLongsJsonTest.java b/simpleexample/src/test/java/simpleex/json/LatLongsJsonTest.java index 7b097dec3a9216df864e377003804ebff2096e7c..37f1479f8a9805cfa71707e192b28d39b7ec5c8b 100644 --- a/simpleexample/src/test/java/simpleex/json/LatLongsJsonTest.java +++ b/simpleexample/src/test/java/simpleex/json/LatLongsJsonTest.java @@ -1,10 +1,10 @@ package simpleex.json; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; import simpleex.core.LatLong; import simpleex.core.LatLongs; diff --git a/simpleexample/src/test/java/simpleex/ui/FxAppTest.java b/simpleexample/src/test/java/simpleex/ui/FxAppTest.java index 1be05ec4285bc0f80440fca9479d65e03d658e69..02cd11b949d7f8febd084d41b13536a8f8f742d5 100644 --- a/simpleexample/src/test/java/simpleex/ui/FxAppTest.java +++ b/simpleexample/src/test/java/simpleex/ui/FxAppTest.java @@ -3,14 +3,14 @@ package simpleex.ui; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import fxmapcontrol.Location; +import fxmapcontrol.MapBase; import java.util.ArrayList; import java.util.List; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.testfx.framework.junit.ApplicationTest; -import fxmapcontrol.Location; -import fxmapcontrol.MapBase; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene;