This is an automated email from the ASF dual-hosted git repository.
jsorel pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new aea19ce Portrayal : factorize code between MapContext and MapGroup,
add event listeners
aea19ce is described below
commit aea19ce7317e070def031cbc482547c8cab71f3a
Author: jsorel <[email protected]>
AuthorDate: Fri Dec 20 17:25:39 2019 +0100
Portrayal : factorize code between MapContext and MapGroup, add event
listeners
---
.../java/org/apache/sis/internal/map/MapGroup.java | 66 ----------------------
.../java/org/apache/sis/internal/map/MapItem.java | 52 ++++++++++++++++-
.../java/org/apache/sis/internal/map/MapLayer.java | 27 ++++++++-
.../map/{MapContext.java => MapLayers.java} | 50 ++++++++++++++--
4 files changed, 118 insertions(+), 77 deletions(-)
diff --git
a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapGroup.java
b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapGroup.java
deleted file mode 100644
index be82526..0000000
--- a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapGroup.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.internal.map;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * A collection of layers.
- * Groups are used in map contexts to regroup similar layers under a same node.
- * This allows global actions, like {@linkplain #setVisible(boolean) hiding}
- * background layers in one call.
- *
- * <p>
- * NOTE: this class is a first draft subject to modifications.
- * </p>
- *
- * @author Johann Sorel (Geomatys)
- * @version 1.0
- * @since 1.0
- * @module
- */
-public class MapGroup extends MapItem {
- /**
- * The components in this group.
- */
- private final List<MapItem> components;
-
- /**
- * Creates an initially empty group.
- */
- public MapGroup() {
- components = new ArrayList<>();
- }
-
- /**
- * Gets the modifiable list of components contained in this group.
- * The components in the list are presented in rendering order.
- * This means that the first rendered component, which will be below
- * all other components on the rendered map, is located at index zero.
- *
- * <p>The returned list is modifiable: changes in the returned list will
- * be immediately reflected in this {@code MapGroup}, and conversely.</p>
- *
- * @return modifiable list of components in this group.
- */
- @SuppressWarnings("ReturnOfCollectionOrArrayField")
- public List<MapItem> getComponents() {
- return components;
- }
-}
diff --git
a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapItem.java
b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapItem.java
index c7e64e7..2338a43 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapItem.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapItem.java
@@ -16,6 +16,11 @@
*/
package org.apache.sis.internal.map;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Objects;
+import javax.swing.event.EventListenerList;
+
/**
* Parent class of all map elements.
*
@@ -29,6 +34,14 @@ package org.apache.sis.internal.map;
* @module
*/
public abstract class MapItem {
+
+ /** Identifies a change in the map item title. */
+ public static final String TITLE_PROPERTY = "title";
+ /** Identifies a change in the map item visibility state. */
+ public static final String VISIBLE_PROPERTY = "visible";
+
+ private final EventListenerList listeners = new EventListenerList();
+
/**
* The title of this map item, for display to the user.
*/
@@ -62,7 +75,11 @@ public abstract class MapItem {
* @param title title to be shown to the user, or {@code null} if none.
*/
public void setTitle(CharSequence title) {
- this.title = title;
+ if (!Objects.equals(this.title, title)) {
+ CharSequence old = this.title;
+ this.title = title;
+ firePropertyChange(TITLE_PROPERTY, old, title);
+ }
}
/**
@@ -81,6 +98,37 @@ public abstract class MapItem {
* @param visible {@code false} to hide this item and all it's components.
*/
public void setVisible(boolean visible) {
- this.visible = visible;
+ if (this.visible != visible) {
+ this.visible = visible;
+ firePropertyChange(VISIBLE_PROPERTY, !visible, visible);
+ }
+ }
+
+ /**
+ * Register a property listener.
+ *
+ * @param listener property listener to register
+ */
+ public final void addPropertyChangeListener(PropertyChangeListener
listener) {
+ listeners.add(PropertyChangeListener.class, listener);
+ }
+
+ /**
+ * Unregister a property listener.
+ *
+ * @param listener property listener to register
+ */
+ public final void removePropertyChangeListener(PropertyChangeListener
listener) {
+ listeners.remove(PropertyChangeListener.class, listener);
+ }
+
+ protected void firePropertyChange(final String propertyName, final Object
oldValue, final Object newValue) {
+ final PropertyChangeListener[] listPs =
listeners.getListeners(PropertyChangeListener.class);
+ if (listPs.length == 0) return;
+
+ final PropertyChangeEvent event = new
PropertyChangeEvent(this,propertyName,oldValue,newValue);
+ for (PropertyChangeListener listener : listPs) {
+ listener.propertyChange(event);
+ }
}
}
diff --git
a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapLayer.java
b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapLayer.java
index cae70ea..25be50e 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapLayer.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapLayer.java
@@ -16,6 +16,7 @@
*/
package org.apache.sis.internal.map;
+import java.util.Objects;
import org.apache.sis.storage.Query;
import org.apache.sis.storage.Resource;
import org.opengis.style.Style;
@@ -41,6 +42,14 @@ import org.opengis.style.Style;
* @module
*/
public class MapLayer extends MapItem {
+
+ /** Identifies a change in the layer resource. */
+ public static final String RESOURCE_PROPERTY = "resource";
+ /** Identifies a change in the layer style. */
+ public static final String STYLE_PROPERTY = "style";
+ /** Identifies a change in the layer query. */
+ public static final String QUERY_PROPERTY = "query";
+
/**
* Data to be rendered.
*/
@@ -86,7 +95,11 @@ public class MapLayer extends MapItem {
* @param resource the new data, or {@code null} if unavailable.
*/
public void setResource(Resource resource) {
- this.resource = resource;
+ if (!Objects.equals(this.resource, resource)) {
+ Resource old = this.resource;
+ this.resource = resource;
+ firePropertyChange(RESOURCE_PROPERTY, old, resource);
+ }
}
/**
@@ -106,7 +119,11 @@ public class MapLayer extends MapItem {
* @param style description of data visual appearance, or {@code null}
if unspecified.
*/
public void setStyle(Style style) {
- this.style = style;
+ if (!Objects.equals(this.style, style)) {
+ Style old = this.style;
+ this.style = style;
+ firePropertyChange(STYLE_PROPERTY, old, style);
+ }
}
/**
@@ -129,6 +146,10 @@ public class MapLayer extends MapItem {
* @param query the query for this layer, or {@code null} if unavailable.
*/
public void setQuery(Query query) {
- this.query = query;
+ if (!Objects.equals(this.query, query)) {
+ Query old = this.query;
+ this.query = query;
+ firePropertyChange(QUERY_PROPERTY, old, query);
+ }
}
}
diff --git
a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapContext.java
b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapLayers.java
similarity index 60%
rename from
core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapContext.java
rename to
core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapLayers.java
index 097c9c3..03dc544 100644
---
a/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapContext.java
+++
b/core/sis-portrayal/src/main/java/org/apache/sis/internal/map/MapLayers.java
@@ -16,19 +16,27 @@
*/
package org.apache.sis.internal.map;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
import org.opengis.geometry.Envelope;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
/**
- * Root node of a map.
+ * A collection of layers.
+ * Layers are used to regroup similar layers under a same node.
+ * This allows global actions, like {@linkplain #setVisible(boolean) hiding}
+ * background layers in one call.
*
- * The map context contains all layers to display (given by the {@link
#getComponents() group components})
+ * A map context which is the name given to the root map item node contains
+ * all layers to display (given by the {@link #getComponents() group
components})
* and defines the {@linkplain #getAreaOfInterest() area of interest} which
should be zoomed by default
* when the map is rendered.
*
* <p>
* NOTE: this class is a first draft subject to modifications.
+ * TODO : components events
* </p>
*
* @author Johann Sorel (Geomatys)
@@ -36,16 +44,42 @@ import
org.opengis.referencing.crs.CoordinateReferenceSystem;
* @since 1.0
* @module
*/
-public class MapContext extends MapGroup {
+public class MapLayers extends MapItem {
+
+ /** Identifies a change in the map context area of interest. */
+ public static final String AREAOFINTEREST_PROPERTY = "areaOfInterest";
+
+ /**
+ * The components in this group.
+ */
+ private final List<MapItem> components;
+
/**
* The area of interest.
*/
private Envelope areaOfInterest;
/**
- * Creates an initially empty map context.
+ * Creates an initially empty map layers.
+ */
+ public MapLayers() {
+ components = new ArrayList<>();
+ }
+
+ /**
+ * Gets the modifiable list of components contained in this group.
+ * The components in the list are presented in rendering order.
+ * This means that the first rendered component, which will be below
+ * all other components on the rendered map, is located at index zero.
+ *
+ * <p>The returned list is modifiable: changes in the returned list will
+ * be immediately reflected in this {@code MapGroup}, and conversely.</p>
+ *
+ * @return modifiable list of components in this group.
*/
- public MapContext() {
+ @SuppressWarnings("ReturnOfCollectionOrArrayField")
+ public List<MapItem> getComponents() {
+ return components;
}
/**
@@ -74,6 +108,10 @@ public class MapContext extends MapGroup {
* @param aoi new map area to show by default, or {@code null} is
unspecified.
*/
public void setAreaOfInterest(Envelope aoi) {
- areaOfInterest = aoi;
+ if (!Objects.equals(areaOfInterest, aoi)) {
+ Envelope old = areaOfInterest;
+ areaOfInterest = aoi;
+ firePropertyChange(AREAOFINTEREST_PROPERTY, old, aoi);
+ }
}
}