Changeset 10592 in josm for trunk/src/org/openstreetmap/josm/gui/layer
- Timestamp:
- 2016-07-22T23:39:36+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/LayerPositionStrategy.java
r10271 r10592 3 3 4 4 import java.util.List; 5 import java.util.function.Predicate; 5 6 6 import org.openstreetmap.josm.tools.Predicate;7 7 import org.openstreetmap.josm.tools.Predicates; 8 8 … … 11 11 * @author Michael Zangl 12 12 * @since 10008 13 * @since 10592 functional interface 13 14 */ 14 public abstract class LayerPositionStrategy { 15 @FunctionalInterface 16 public interface LayerPositionStrategy { 15 17 16 18 /** 17 19 * always inserts at the front of the stack. 18 20 */ 19 public static final LayerPositionStrategy IN_FRONT = new LayerPositionStrategy() { 20 @Override 21 public int getPosition(LayerManager manager) { 22 return 0; 23 } 24 }; 21 LayerPositionStrategy IN_FRONT = manager -> 0; 25 22 26 23 /** 27 24 * A GPX layer is added below the lowest data layer. 28 25 */ 29 public static final LayerPositionStrategy AFTER_LAST_DATA_LAYER = afterLast(new Predicate<Layer>() { 30 @Override 31 public boolean evaluate(Layer object) { 32 return object instanceof OsmDataLayer || object instanceof ValidatorLayer; 33 } 34 }); 26 LayerPositionStrategy AFTER_LAST_DATA_LAYER = afterLast( 27 layer -> layer instanceof OsmDataLayer || layer instanceof ValidatorLayer); 35 28 36 29 /** 37 30 * A normal layer is added after all validation layers. 38 31 */ 39 public static final LayerPositionStrategy AFTER_LAST_VALIDATION_LAYER = afterLast(new Predicate<Layer>() { 40 @Override 41 public boolean evaluate(Layer object) { 42 return object instanceof ValidatorLayer; 43 } 44 }); 32 LayerPositionStrategy AFTER_LAST_VALIDATION_LAYER = afterLast( 33 layer -> layer instanceof ValidatorLayer); 45 34 46 35 /** … … 48 37 * If there is none, they are added at the end of the list. 49 38 */ 50 public static final LayerPositionStrategy BEFORE_FIRST_BACKGROUND_LAYER = inFrontOfFirst(new Predicate<Layer>() { 51 @Override 52 public boolean evaluate(Layer object) { 53 return object.isBackgroundLayer(); 54 } 55 }); 39 LayerPositionStrategy BEFORE_FIRST_BACKGROUND_LAYER = inFrontOfFirst( 40 layer -> layer.isBackgroundLayer()); 56 41 57 42 /** … … 60 45 * @return The strategy 61 46 */ 62 publicstatic LayerPositionStrategy inFrontOf(Layer other) {47 static LayerPositionStrategy inFrontOf(Layer other) { 63 48 return inFrontOfFirst(Predicates.equalTo(other)); 64 49 } … … 69 54 * @return The strategy. 70 55 */ 71 public static LayerPositionStrategy inFrontOfFirst(final Predicate<Layer> what) { 72 return new LayerPositionStrategy() { 73 @Override 74 public int getPosition(LayerManager manager) { 75 List<Layer> layers = manager.getLayers(); 76 for (int i = 0; i < layers.size(); i++) { 77 if (what.evaluate(layers.get(i))) { 78 return i; 79 } 56 static LayerPositionStrategy inFrontOfFirst(final Predicate<Layer> what) { 57 return manager -> { 58 List<Layer> layers = manager.getLayers(); 59 for (int i = 0; i < layers.size(); i++) { 60 if (what.test(layers.get(i))) { 61 return i; 80 62 } 81 return layers.size();82 63 } 64 return layers.size(); 83 65 }; 84 66 } … … 89 71 * @return The strategy. 90 72 */ 91 public static LayerPositionStrategy afterLast(final Predicate<Layer> what) { 92 return new LayerPositionStrategy() { 93 @Override 94 public int getPosition(LayerManager manager) { 95 List<Layer> layers = manager.getLayers(); 96 for (int i = layers.size() - 1; i >= 0; i--) { 97 if (what.evaluate(layers.get(i))) { 98 return i + 1; 99 } 73 static LayerPositionStrategy afterLast(final Predicate<Layer> what) { 74 return manager -> { 75 List<Layer> layers = manager.getLayers(); 76 for (int i = layers.size() - 1; i >= 0; i--) { 77 if (what.test(layers.get(i))) { 78 return i + 1; 100 79 } 101 return 0;102 80 } 81 return 0; 103 82 }; 104 83 } … … 109 88 * @return The position in the range 0...layers.size 110 89 */ 111 public abstractint getPosition(LayerManager manager);90 int getPosition(LayerManager manager); 112 91 }
Note:
See TracChangeset
for help on using the changeset viewer.