Skip to content

Commit

Permalink
Merge pull request JFXtras#87 from Mario-S/2.2
Browse files Browse the repository at this point in the history
cleanup in map package
  • Loading branch information
mario-s committed Jan 2, 2014
2 parents 0f9bbce + a6b2eb7 commit f603ff6
Show file tree
Hide file tree
Showing 11 changed files with 766 additions and 763 deletions.
1,252 changes: 624 additions & 628 deletions src/main/java/jfxtras/labs/map/MapPane.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/java/jfxtras/labs/map/render/LicenseRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private Text createLicenseText(String attrTxt) {
return txt;
}

private class MouseClickedAdapter implements EventHandler<MouseEvent> {
private static class MouseClickedAdapter implements EventHandler<MouseEvent> {

private String url;

Expand All @@ -153,7 +153,7 @@ public void handle(MouseEvent me) {
}
}

private class MouseEnteredAdapter implements EventHandler<MouseEvent> {
private static class MouseEnteredAdapter implements EventHandler<MouseEvent> {

private Text text;

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/jfxtras/labs/map/render/TileRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,20 @@ public TileRenderer(TileProvideable provider) {
@Override
public int prepareTiles(Moveable mapController) {
provider.setStrategy(new CacheLoadStrategy());
TilesLoadable tileLoader = new TilesLoader(provider);
tileImages = tileLoader.loadTiles(mapController);
loadTiles(mapController);
return tileImages.size();
}

@Override
public void refresh(Moveable mapController) {
provider.setStrategy(new RefreshLoadStrategy());
loadTiles(mapController);
render(mapController.getTilesGroup());
}

private void loadTiles(Moveable mapController) {
TilesLoadable tileLoader = new TilesLoader(provider);
tileImages = tileLoader.loadTiles(mapController);
render(mapController.getTilesGroup());
}

@Override
Expand Down Expand Up @@ -167,10 +170,12 @@ protected Path createBorder(int posx, int posy, int tilesize) {
return path;
}

@Override
public void setMonoChrome(boolean monoChrome) {
this.monoChrome = monoChrome;
}

@Override
public void setTileGridVisible(boolean tileGridVisible) {
this.tileGridVisible = tileGridVisible;
}
Expand Down
117 changes: 58 additions & 59 deletions src/main/java/jfxtras/labs/map/tile/AbstractTileLoadStrategy.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
/**
* AbstractTileLoadStrategy.java
*
* Copyright (c) 2011-2013, JFXtras
* All rights reserved.
*
* Copyright (c) 2011-2013, JFXtras 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.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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 <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* 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. * Neither the name of the <organization> nor the names
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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 <COPYRIGHT HOLDER> 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 jfxtras.labs.map.tile;

import java.util.Objects;
Expand All @@ -37,49 +34,51 @@

/**
* Abstract parent class for tile load commands.
*
* @author Mario Schroeder
*
*/
public abstract class AbstractTileLoadStrategy implements TileLoadStrategy{
protected TileInfoCache cache;

public void setCache(TileInfoCache cache){
this.cache = cache;
}

Tile createTile(String location) {
Tile tile = new Tile(location);
loadImage(tile);
return tile;
}

private void loadImage(Tile tile) {
ChangeListener<Boolean> listener = new ImageLoadedListener(tile);
tile.imageLoadedProperty().addListener(listener);
tile.loadImage();
}

@Override
public String toString() {
return getClass().getSimpleName();
}

@Override
public boolean equals(Object obj) {
boolean equal = false;
if(obj != null && getClass() == obj.getClass()){
equal = Objects.equals(this.toString(), obj.toString());
}
return equal;
}

@Override
public int hashCode() {
return toString().hashCode();
}

private class ImageLoadedListener implements ChangeListener<Boolean> {

public abstract class AbstractTileLoadStrategy implements TileLoadStrategy {

protected TileInfoCache cache;

public void setCache(TileInfoCache cache) {
this.cache = cache;
}

Tile createTile(String location) {
Tile tile = new Tile(location);
loadImage(tile);
return tile;
}

private void loadImage(Tile tile) {
ChangeListener<Boolean> listener = new ImageLoadedListener(tile);
tile.imageLoadedProperty().addListener(listener);
tile.loadImage();
}

@Override
public String toString() {
return getClass().getSimpleName();
}

@Override
public boolean equals(Object obj) {
boolean equal = false;
if (obj != null && getClass() == obj.getClass()) {
equal = Objects.equals(this.toString(), obj.toString());
}
return equal;
}

@Override
public int hashCode() {
return toString().hashCode();
}

private class ImageLoadedListener implements ChangeListener<Boolean> {

private Tile tile;

public ImageLoadedListener(Tile tile) {
Expand All @@ -88,7 +87,7 @@ public ImageLoadedListener(Tile tile) {

@Override
public void changed(
ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
if (newVal.booleanValue()) {
addImage(tile.getLocation(), tile.getImageView().getImage());
}
Expand Down
50 changes: 23 additions & 27 deletions src/main/java/jfxtras/labs/map/tile/CacheLoadStrategy.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
/**
* CacheLoadStrategy.java
*
* Copyright (c) 2011-2013, JFXtras
* All rights reserved.
*
* Copyright (c) 2011-2013, JFXtras 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.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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 <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* 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. * Neither the name of the <organization> nor the names
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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 <COPYRIGHT HOLDER> 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 jfxtras.labs.map.tile;

/**
* This class checks the {@link TileInfoCache} first if the
* {@link Tile} exists and loads it from there.
*
* This class checks the {@link TileInfoCache} first if the {@link Tile} exists
* and loads it from there.
*
* @author Mario Schroeder
*
*/
public class CacheLoadStrategy extends AbstractTileLoadStrategy {

@Override
public Tile execute(String location) {
Tile tile;
TileInfo info = cache.get(location);
@Override
public Tile execute(String location) {
Tile tile;
TileInfo info = cache.get(location);

if (info != null) {
tile = new Tile(location, info.getImage());
} else {
tile = createTile(location);
}
return tile;
}

}
}
50 changes: 23 additions & 27 deletions src/main/java/jfxtras/labs/map/tile/RefreshLoadStrategy.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
/**
* RefreshLoadStrategy.java
*
* Copyright (c) 2011-2013, JFXtras
* All rights reserved.
*
* Copyright (c) 2011-2013, JFXtras 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.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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 <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* 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. * Neither the name of the <organization> nor the names
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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 <COPYRIGHT HOLDER> 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 jfxtras.labs.map.tile;

/**
* This class reloads the {@link Tile} in the {@link TileInfoCache}.
*
*
* @author Mario Schroeder
*
*/
public class RefreshLoadStrategy extends AbstractTileLoadStrategy {

@Override
public Tile execute(String location) {
TileInfo info = cache.get(location);
@Override
public Tile execute(String location) {
TileInfo info = cache.get(location);

if (info != null) {
cache.remove(location);
}

return createTile(location);
}
cache.remove(location);
}

return createTile(location);
}
}
2 changes: 0 additions & 2 deletions src/main/java/jfxtras/labs/map/tile/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public class Tile {

private static volatile Image delayImage;

private static volatile Image errorImage;

private static final String HTTP = "http:";

private static final double COMPLETE = 1.0;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/jfxtras/labs/map/tile/bing/BingTileSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

package jfxtras.labs.map.tile.bing;

import java.util.ArrayList;
import jfxtras.labs.map.tile.Attribution;
import jfxtras.labs.map.tile.AttributtionStringBuilder;
import jfxtras.labs.map.tile.DefaultTileSource;
Expand All @@ -44,7 +45,7 @@
*/
public class BingTileSource extends DefaultTileSource {

private List<Attribution> attributions;
private List<Attribution> attributions = new ArrayList<>();

public BingTileSource(String name, String base_url) {
super(name, base_url);
Expand Down
Loading

0 comments on commit f603ff6

Please sign in to comment.