Skip to content
Snippets Groups Projects
Commit b364bdf3 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Merge branch 'refactoring/3-checkstyle' into 'master'

Refactoring - checkstyle warnings

Closes #3

See merge request it1901/simpleexample2!1
parents b941da2e 8ebe2dcb
Branches
No related tags found
No related merge requests found
Showing
with 193 additions and 65 deletions
##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*
##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
##############################
## Gradle
##############################
bin/
build/
.gradle
.gradletasknamecache
gradle-app.setting
!gradle-wrapper.jar
##############################
## IntelliJ
##############################
out/
.idea/
.idea_modules/
*.iml
*.ipr
*.iws
##############################
## Eclipse
##############################
.settings/
bin/
tmp/
.metadata
.classpath
.project
*.tmp
*.bak
*.swp
*~.nib
local.properties
.loadpath
.factorypath
##############################
## NetBeans
##############################
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
##############################
## Visual Studio Code
##############################
.vscode/
.code-workspace
##############################
## OS X
##############################
.DS_Store
target/
......@@ -48,11 +48,25 @@ public class LatLongDeserializer extends JsonDeserializer<LatLong> {
}
}
if (metaDataNode.has(LatLongSerializer.PROPERTIES_FIELD_NAME)) {
for (JsonNode propertyNode : (ArrayNode) metaDataNode.get(LatLongSerializer.PROPERTIES_FIELD_NAME)) {
String propertyName = (propertyNode instanceof ArrayNode ? ((ArrayNode) propertyNode).get(0)
: ((ObjectNode) propertyNode).get(LatLongSerializer.PROPERTIES_NAME_FIELD_NAME)).asText();
String propertyValue = (propertyNode instanceof ArrayNode ? ((ArrayNode) propertyNode).get(1)
: ((ObjectNode) propertyNode).get(LatLongSerializer.PROPERTIES_VALUE_FIELD_NAME)).asText();
for (JsonNode propertyNode :
(ArrayNode) metaDataNode.get(LatLongSerializer.PROPERTIES_FIELD_NAME)) {
String propertyName;
if (propertyNode instanceof ArrayNode) {
propertyName = (((ArrayNode) propertyNode).get(0)).asText();
} else {
propertyName = (((ObjectNode) propertyNode).get(
LatLongSerializer.PROPERTIES_NAME_FIELD_NAME
)).asText();
}
String propertyValue;
if (propertyNode instanceof ArrayNode) {
propertyValue = (((ArrayNode) propertyNode).get(1)).asText();
} else {
propertyValue = (((ObjectNode) propertyNode).get(
LatLongSerializer.PROPERTIES_VALUE_FIELD_NAME
)).asText();
}
metaData.setProperty(propertyName, propertyValue);
}
}
......
......@@ -76,7 +76,8 @@ public abstract class AbstractFxAppController {
private void initialize() {
// map stuff
// mapView.getChildren().add(MapTileLayer.getOpenStreetMapLayer());
zoomSlider.valueProperty().addListener((prop, oldValue, newValue) -> mapView.setZoomLevel(zoomSlider.getValue()));
zoomSlider.valueProperty()
.addListener((prop, oldValue, newValue) -> mapView.setZoomLevel(zoomSlider.getValue()));
zoomSlider.setValue(8);
markersParent = new MapItemsControl<MapNode>();
mapView.getChildren().add(markersParent);
......
......@@ -28,7 +28,8 @@ public class FxApp extends Application {
serverArgs.add(args.get(1));
}
System.out.println(serverArgs);
// restServer = LatLongGrizzlyApp.startServer(serverArgs.toArray(new String[serverArgs.size()]), 5);
// restServer = LatLongGrizzlyApp.startServer(
// serverArgs.toArray(new String[serverArgs.size()]), 5);
}
final String fxml = (baseUri != null ? "FxAppUsingRest.fxml" : "FxApp.fxml");
final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fxml));
......@@ -83,17 +84,24 @@ public class FxApp extends Application {
latLongWithMetaData.getMetaData().setProperty(MetaData.NAME_PROPERTY, "Awsome place");
latLongWithMetaData.getMetaData().setProperty(MetaData.DESCRIPTION_PROPERTY,
"Lorem ipsum dolor sit amet,"
+ " consectetur adipiscing elit. Nulla placerat urna non aliquet imperdiet. Nullam tincidunt felis "
+ "vel sem blandit viverra. Etiam non volutpat erat. In hac habitasse platea dictumst. In lacus quam, "
+ "rutrum vel malesuada non, molestie eu velit. Donec ut vulputate tortor, id convallis enim. Mauris "
+ "et ipsum volutpat, dictum risus sed, aliquet sapien. Nam congue fermentum porta. Nullam non "
+ "odio consequat, laoreet est eget, egestas dui. Aliquam suscipit elit non nisi sagittis, nec "
+ "ultrices leo condimentum. Maecenas vel ligula nec mi feugiat volutpat. Aenean semper nisi sed"
+ " tortor maximus tristique. Vestibulum at mauris massa. Nulla laoreet, velit eu lobortis efficitur, "
+ "tortor sem molestie massa, at pellentesque tortor elit a nibh. In vel orci vitae magna rhoncus pulvinar "
+ " consectetur adipiscing elit. Nulla placerat urna non aliquet imperdiet."
+ " Nullam tincidunt felis vel sem blandit viverra. "
+ "Etiam non volutpat erat. In hac habitasse platea dictumst. In lacus quam, "
+ "rutrum vel malesuada non, molestie eu velit. Donec ut vulputate tortor, "
+ "id convallis enim. Mauris et ipsum volutpat, dictum risus sed,"
+ " aliquet sapien. Nam congue fermentum porta. Nullam non "
+ "odio consequat, laoreet est eget, egestas dui. Aliquam suscipit "
+ " elit non nisi sagittis, nec ultrices leo condimentum. Maecenas vel "
+ "ligula nec mi feugiat volutpat. Aenean semper nisi sed"
+ " tortor maximus tristique. Vestibulum at mauris massa. Nulla laoreet, "
+ " velit eu lobortis efficitur, tortor sem molestie massa, at pellentesque"
+ " tortor elit a nibh. In vel orci vitae magna rhoncus pulvinar "
+ "sit amet id erat.");
latLongWithMetaData.getMetaData().addTags("tag 1", "tag 2", "a much longer tag 3");
latLongWithMetaData.getMetaData().setProperty("custom property 1", "this is the value for custom property 1");
latLongWithMetaData.getMetaData().setProperty(
"custom property 1",
"this is the value for custom property 1"
);
latLongWithMetaData.getMetaData().setIntegerProperty("custom property 2 (int)", 13);
latLongWithMetaData.getMetaData().setDoubleProperty("custom property 3 (double)", 35.13);
latLongWithMetaData.getMetaData().setBooleanProperty("custom property 4 (boolean)", false);
......
......@@ -36,7 +36,7 @@ public class LatLongCellController {
/**
* The horizontal box containing the coordinates and the add/edit button.
*/
private HBox hBox;
private HBox horizontalBox;
/**
* The button that will allow opening the editor for the selected item.
......@@ -46,7 +46,7 @@ public class LatLongCellController {
/**
* Container for the additional metadata.
*/
private VBox vBox;
private VBox verticalBox;
/**
* The label for the name property.
......@@ -94,15 +94,15 @@ public class LatLongCellController {
* @param selected flag indicating that the item is selected
*/
protected void prepareView(boolean selected) {
this.hBox = new HBox();
this.hBox.setSpacing(3.0);
this.horizontalBox = new HBox();
this.horizontalBox.setSpacing(3.0);
this.coordinatesLabel = new Label(this.latLong.toString());
coordinatesLabel.setPrefWidth(180.0);
this.hBox.getChildren().add(coordinatesLabel);
this.horizontalBox.getChildren().add(coordinatesLabel);
if (this.latLong.hasMetaData()) {
if (this.latLong.getMetaData().hasCustomProperties()) {
this.hBox.getChildren()
this.horizontalBox.getChildren()
.add(new ImageView(new Image(
getClass().getResourceAsStream((selected ? "i_selected.png" : "i.png"))
)));
......@@ -111,17 +111,17 @@ public class LatLongCellController {
if (selected) {
this.editMetadataButton = new Button("...");
this.hBox.getChildren().add(editMetadataButton);
this.horizontalBox.getChildren().add(editMetadataButton);
editMetadataButton.setOnAction(event -> {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MetaDataEditor.fxml"));
Parent root1 = fxmlLoader.load();
MetaDataEditorController metaDataEditorController = fxmlLoader.getController();
metaDataEditorController.setLatLong(this.latLong);
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.initStyle(StageStyle.DECORATED);
stage.setTitle("Location MetaData Editor");
Parent root1 = fxmlLoader.load();
MetaDataEditorController metaDataEditorController = fxmlLoader.getController();
metaDataEditorController.setLatLong(this.latLong);
Scene scene = new Scene(root1);
stage.setScene(scene);
scene.getStylesheets().add(
......@@ -146,14 +146,14 @@ public class LatLongCellController {
}
if (this.latLong.hasMetaData()) {
this.vBox = new VBox();
this.verticalBox = new VBox();
MetaData metaData = this.latLong.getMetaData();
if (metaData.hasProperty(MetaData.NAME_PROPERTY)) {
nameLabel = new Label();
nameLabel.setText(metaData.getProperty(MetaData.NAME_PROPERTY));
vBox.getChildren().add(nameLabel);
verticalBox.getChildren().add(nameLabel);
}
vBox.getChildren().add(this.hBox);
verticalBox.getChildren().add(this.horizontalBox);
if (metaData.hasProperty(MetaData.DESCRIPTION_PROPERTY)) {
descriptionLabel = new Label();
descriptionLabel.setText(metaData.getProperty(MetaData.DESCRIPTION_PROPERTY));
......@@ -161,7 +161,7 @@ public class LatLongCellController {
descriptionLabel.setMaxHeight(50.0);
descriptionLabel.setManaged(true);
descriptionLabel.setMaxWidth(200.0);
vBox.getChildren().add(descriptionLabel);
verticalBox.getChildren().add(descriptionLabel);
}
final Iterator<String> tags = metaData.tags();
if (tags.hasNext()) {
......@@ -174,11 +174,11 @@ public class LatLongCellController {
tagLabel.setPadding(new Insets(0.0, 3.0, 0.0, 3.0));
tagsBox.getChildren().add(tagLabel);
}
vBox.getChildren().add(tagsBox);
verticalBox.getChildren().add(tagsBox);
}
this.root = this.vBox;
this.root = this.verticalBox;
} else {
this.root = this.hBox;
this.root = this.horizontalBox;
}
}
......
......@@ -48,7 +48,7 @@ public class MetaDataEditorController {
private BorderPane rootContainer;
@FXML
private VBox centerVBox;
private VBox centerVerticalBox;
@FXML
private Button saveButton;
......
......@@ -58,7 +58,8 @@ public class RestLatLongsDataAccess implements LatLongsDataAccess {
@Override
public Collection<LatLong> getAllLatLongs() {
final URI requestUri = getRequestUri("");
final HttpRequest request = HttpRequest.newBuilder(requestUri).header("Accept", "application/json").GET().build();
final HttpRequest request = HttpRequest.newBuilder(requestUri)
.header("Accept", "application/json").GET().build();
try {
final HttpResponse<String> response =
HttpClient.newBuilder().build().send(request, HttpResponse.BodyHandlers.ofString());
......@@ -76,10 +77,13 @@ public class RestLatLongsDataAccess implements LatLongsDataAccess {
@Override
public LatLong getLatLong(final int num) {
final HttpRequest request =
HttpRequest.newBuilder(getRequestUri("/" + num)).header("Accept", "application/json").GET().build();
HttpRequest.newBuilder(getRequestUri("/" + num))
.header("Accept", "application/json").GET().build();
try {
final HttpResponse<InputStream> response =
HttpClient.newBuilder().build().send(request, HttpResponse.BodyHandlers.ofInputStream());
HttpClient.newBuilder().build().send(
request, HttpResponse.BodyHandlers.ofInputStream()
);
return getObjectMapper().readValue(response.body(), LatLong.class);
} catch (JsonParseException | JsonMappingException e) {
System.err.println(e.toString());
......@@ -93,10 +97,14 @@ public class RestLatLongsDataAccess implements LatLongsDataAccess {
public void setLatLong(final int index, final LatLong latLong) {
try {
final HttpRequest request = HttpRequest.newBuilder(getRequestUri("/" + index))
.header("Content-Type", "application/json").header("Accept", "application/json")
.PUT(BodyPublishers.ofString(getObjectMapper().writeValueAsString(latLong))).build();
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.PUT(BodyPublishers.ofString(getObjectMapper().writeValueAsString(latLong)))
.build();
final HttpResponse<InputStream> response =
HttpClient.newBuilder().build().send(request, HttpResponse.BodyHandlers.ofInputStream());
HttpClient.newBuilder().build().send(
request, HttpResponse.BodyHandlers.ofInputStream()
);
final int realIndex = getObjectMapper().readValue(response.body(), Integer.class);
if (realIndex < 0) {
throw new IndexOutOfBoundsException(realIndex);
......@@ -112,11 +120,15 @@ public class RestLatLongsDataAccess implements LatLongsDataAccess {
public int addLatLong(final LatLong latLong) {
try {
final LatLongs latLongs = new LatLongs(latLong);
final HttpRequest request = HttpRequest.newBuilder(getRequestUri("")).header("Content-Type", "application/json")
final HttpRequest request = HttpRequest.newBuilder(getRequestUri(""))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.POST(BodyPublishers.ofString(getObjectMapper().writeValueAsString(latLongs))).build();
.POST(BodyPublishers.ofString(getObjectMapper().writeValueAsString(latLongs)))
.build();
final HttpResponse<InputStream> response =
HttpClient.newBuilder().build().send(request, HttpResponse.BodyHandlers.ofInputStream());
HttpClient.newBuilder()
.build()
.send(request, HttpResponse.BodyHandlers.ofInputStream());
final int realIndex = getObjectMapper().readValue(response.body(), Integer.class);
if (realIndex < 0) {
throw new IndexOutOfBoundsException(realIndex);
......
......@@ -18,9 +18,11 @@ public class Snippet extends Application {
public void start(Stage primaryStage) {
// All the musicGenres
List<String> genres = Arrays.asList("50s", "60s", "70s", "80s", "90s", "Adult Contemporary", "African",
"Alternative", "Ambient", "Americana", "Baladas", "Bass", "Big Band", "Big Beat", "Bluegrass", "Blues ",
"Bollywood", "Breakbeat", "Breakcore", "Breaks", "Calypso", "Caribbean", "Celtic", "Chill", "Zouk");
List<String> genres = Arrays.asList("50s", "60s", "70s", "80s", "90s",
"Adult Contemporary", "African", "Alternative", "Ambient", "Americana",
"Baladas", "Bass", "Big Band", "Big Beat", "Bluegrass", "Blues ", "Bollywood",
"Breakbeat", "Breakcore", "Breaks", "Calypso", "Caribbean", "Celtic", "Chill",
"Zouk");
TagsBar tagBar = new TagsBar();
tagBar.getEntries().addAll(genres);
......
......@@ -21,8 +21,8 @@ import javafx.scene.layout.HBox;
*/
public class TagsBar extends HBox {
private HBox hBox = new HBox();
private ScrollPane scrollPane = new ScrollPane(hBox);
private HBox horizontalBox = new HBox();
private ScrollPane scrollPane = new ScrollPane(horizontalBox);
private AutoCompleteTextField field = new AutoCompleteTextField();
/**
......@@ -32,8 +32,8 @@ public class TagsBar extends HBox {
getStyleClass().setAll("tags-bar");
// hBox
hBox.setStyle(" -fx-spacing:3px;");
horizontalBox.setStyle(" -fx-spacing:3px;");
// scrollPane
scrollPane.setVbarPolicy(ScrollBarPolicy.NEVER);
......@@ -46,9 +46,10 @@ public class TagsBar extends HBox {
field.setOnAction(evt -> {
String text = field.getText();
// No Duplicates allowed
if (!text.isEmpty() && /* getEntries().contains(text) && */ !hBox.getChildren().stream()
if (!text.isEmpty() /* && getEntries().contains(text)*/
&& !horizontalBox.getChildren().stream()
.anyMatch(s -> ((Tag) s).getTag().toLowerCase().equals(text.toLowerCase()))) {
hBox.getChildren().add(new Tag(text));
horizontalBox.getChildren().add(new Tag(text));
}
field.clear();
});
......@@ -62,7 +63,7 @@ public class TagsBar extends HBox {
* @return
*/
public ObservableList<Node> getTags() {
return hBox.getChildren();
return horizontalBox.getChildren();
}
/**
......@@ -79,7 +80,7 @@ public class TagsBar extends HBox {
*
*/
public void clearAllTags() {
hBox.getChildren().clear();
horizontalBox.getChildren().clear();
}
/**
......@@ -88,9 +89,9 @@ public class TagsBar extends HBox {
* @param tag the tag to add
*/
public void addTag(String tag) {
if (!hBox.getChildren().stream()
if (!horizontalBox.getChildren().stream()
.anyMatch(s -> ((Tag) s).getTag().toLowerCase().equals(tag.toLowerCase()))) {
hBox.getChildren().add(new Tag(tag));
horizontalBox.getChildren().add(new Tag(tag));
}
}
......@@ -102,7 +103,8 @@ public class TagsBar extends HBox {
public class Tag extends HBox {
private Label textLabel = new Label();
private Label iconLabel = new Label(null, new ImageView(new Image(getClass().getResourceAsStream("x1.png"))));
private Label iconLabel = new Label(
null, new ImageView(new Image(getClass().getResourceAsStream("x1.png"))));
/**
* Constructor.
......@@ -120,7 +122,9 @@ public class TagsBar extends HBox {
ClipboardContent content = new ClipboardContent();
content.putString("#c" + getTag());
db.setDragView(snapshot(null, new WritableImage((int) getWidth(), (int) getHeight())), getWidth() / 2, 0);
db.setDragView(
snapshot(null, new WritableImage((int) getWidth(),
(int) getHeight())), getWidth() / 2, 0);
db.setContent(content);
......@@ -130,7 +134,8 @@ public class TagsBar extends HBox {
// drag over
setOnDragOver((event) -> {
/*
* data is dragged over the target accept it only if it is not dragged from the same imageView and
* data is dragged over the target accept it only if
* it is not dragged from the same imageView and
* if it has a string data
*/
if (event.getGestureSource() != this && event.getDragboard().hasString()) {
......@@ -144,7 +149,8 @@ public class TagsBar extends HBox {
setOnDragDropped(event -> {
boolean sucess = false;
if (event.getDragboard().hasString() && event.getDragboard().getString().startsWith("#c")) {
if (event.getDragboard().hasString()
&& event.getDragboard().getString().startsWith("#c")) {
String currentTag = getTag();
setTag(event.getDragboard().getString().replace("#c", ""));
((Tag) event.getGestureSource()).setTag(currentTag);
......@@ -158,7 +164,8 @@ public class TagsBar extends HBox {
// drag done
setOnDragDone(event -> {
if (event.getTransferMode() == TransferMode.MOVE) {
System.out.println("Source" + event.getGestureSource() + " Target:" + event.getGestureTarget());
System.out.println("Source" + event.getGestureSource()
+ " Target:" + event.getGestureTarget());
}
event.consume();
});
......@@ -170,7 +177,7 @@ public class TagsBar extends HBox {
// iconLabel
iconLabel.setOnMouseReleased(r -> {
hBox.getChildren().remove(this);
horizontalBox.getChildren().remove(this);
});
getChildren().addAll(textLabel, iconLabel);
......
......@@ -25,7 +25,7 @@
</HBox>
</bottom>
<center>
<VBox fx:id="centerVBox" prefHeight="200.0" prefWidth="100.0" spacing="5.0" BorderPane.alignment="CENTER">
<VBox fx:id="centerVerticalBox" prefHeight="200.0" prefWidth="100.0" spacing="5.0" BorderPane.alignment="CENTER">
<children>
<Label text="Name:" />
<TextField fx:id="nameInput" onAction="#onLocationName" promptText="enter a name for this location" />
......
......@@ -100,6 +100,7 @@ public class LatLongsService {
* client -> LatLongsService: PUT /latLongs/0 { "latitude": 64.0, "longitude": 9.1 }
* LatLongsService --> client: 0
* client -> LatLongsService: GET /latLongs
* LatLongsService --> client: [ { "latitude": 64.0, "longitude": 9.1 }, { "latitude": 63.2, "longitude": 11.0 } ]
* LatLongsService --> client: [ { "latitude": 64.0, "longitude": 9.1 },
* { "latitude": 63.2, "longitude": 11.0 } ]
* @enduml
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment