Skip to content

Commit

Permalink
Fixes #2987 and simplifies the management of layers
Browse files Browse the repository at this point in the history
- Introduces the "visible" attribute in LayerData
- Introduces the "visible" facet in all layer statements
- Introduces isVisible() / setVisible(Boolean) in LayerData
- Introduces isItemVisible() in ItemList
- Simplifies LayerManager to only use one list; clearly separates the
computation of facets from the display; takes care of the visibility of
layers.
  • Loading branch information
AlexisDrogoul committed Sep 7, 2021
1 parent 31375f6 commit e79a7b5
Show file tree
Hide file tree
Showing 21 changed files with 2,703 additions and 607 deletions.
24 changes: 10 additions & 14 deletions msi.gama.core/src/msi/gama/common/interfaces/ILayer.java
@@ -1,9 +1,8 @@
/*******************************************************************************************************
*
* msi.gama.common.interfaces.ILayer.java, in plugin msi.gama.core, is part of the source code of the GAMA modeling and
* simulation platform (v. 1.8.1)
* ILayer.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform (v.1.8.2).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
Expand Down Expand Up @@ -56,9 +55,7 @@ public interface ILayer extends INamed, Comparable<ILayer> {
*
* @return a string representing this layer in the layers menu
*/
default String getMenuName() {
return getType() + ItemList.SEPARATION_CODE + getName();
}
default String getMenuName() { return getType() + ItemList.SEPARATION_CODE + getName(); }

/**
* Asks this layer to draw itself on the IGraphics instance passed in parameter.
Expand Down Expand Up @@ -115,7 +112,9 @@ default void firstLaunchOn(final IDisplaySurface surface) {}
* @param surface
* the display surface on which this layer is drawn
*/
default void enableOn(final IDisplaySurface surface) {}
default void enableOn(final IDisplaySurface surface) {
getData().setVisible(true);
}

/**
* Indicates that this layer has been disabled on the surfaces. Useful when layers "hook" on the surface (for
Expand All @@ -125,7 +124,7 @@ default void enableOn(final IDisplaySurface surface) {}
* the display surface on which this layer is drawn
*/
default void disableOn(final IDisplaySurface surface) {
forceRedrawingOnce();
getData().setVisible(false);
}

/**
Expand Down Expand Up @@ -193,6 +192,7 @@ default boolean isProvidingWorldCoordinates() {
* @return true if {x,y} is inside the layer, false otherwise
*/
default boolean containsScreenPoint(final int x, final int y) {
if (!getData().isVisible()) return false;
final Point p = getData().getPositionInPixels();
final Point s = getData().getSizeInPixels();
return x >= p.x && y >= p.y && x <= p.x + s.x && y <= p.y + s.y;
Expand Down Expand Up @@ -281,9 +281,7 @@ default Set<IAgent> collectAgentsAt(final int x, final int y, final IDisplaySurf
*
* @return true if it is an overlay, false otherwise
*/
default boolean isOverlay() {
return false;
}
default boolean isOverlay() { return false; }

/**
* Returns a textual description of the layer that can be reinterpreted by GAML
Expand All @@ -308,8 +306,6 @@ default int compareTo(final ILayer o) {
* @return true by default, false if the layer shouldnt be displayed in the layer side controls
*/

default Boolean isControllable() {
return true;
}
default Boolean isControllable() { return true; }

}
153 changes: 128 additions & 25 deletions msi.gama.core/src/msi/gama/common/interfaces/ItemList.java
@@ -1,12 +1,11 @@
/*******************************************************************************************************
*
* msi.gama.common.interfaces.ItemList.java, in plugin msi.gama.core,
* is part of the source code of the GAMA modeling and simulation platform (v. 1.8.1)
* ItemList.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform (v.1.8.2).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gama.common.interfaces;

Expand All @@ -23,33 +22,137 @@
*/
public interface ItemList<T> {

public static final Character ERROR_CODE = '\u00F7';
public static final Character INFO_CODE = '\u00F8';
public static final Character WARNING_CODE = '\u00FE';
public static final Character SEPARATION_CODE = '\u00FF';

boolean addItem(T obj);
/** The Constant ERROR_CODE. */
Character ERROR_CODE = '\u00F7';

void removeItem(T obj);
/** The Constant INFO_CODE. */
Character INFO_CODE = '\u00F8';

void pauseItem(T obj);
/** The Constant WARNING_CODE. */
Character WARNING_CODE = '\u00FE';

void resumeItem(T obj);
/** The Constant SEPARATION_CODE. */
Character SEPARATION_CODE = '\u00FF';

void focusItem(T obj);

public List<T> getItems();
/**
* Adds the item.
*
* @param obj
* the obj
* @return true, if successful
*/
boolean addItem(T obj);

/**
* Removes the item.
*
* @param obj
* the obj
*/
default void removeItem(final T obj) {}

/**
* Pause item.
*
* @param obj
* the obj
*/
default void pauseItem(final T obj) {}

/**
* Resume item.
*
* @param obj
* the obj
*/
default void resumeItem(final T obj) {}

/**
* Focus item.
*
* @param obj
* the obj
*/
default void focusItem(final T obj) {}

/**
* Gets the items.
*
* @return the items
*/
List<T> getItems();

/**
* Gets the item display name.
*
* @param obj
* the obj
* @param previousName
* the previous name
* @return the item display name
*/
String getItemDisplayName(T obj, String previousName);

void updateItemValues();

void makeItemSelectable(T data, boolean b);

void makeItemVisible(T obj, boolean b);

GamaColor getItemDisplayColor(T data);

Map<String, Runnable> handleMenu(T data, int x, int y);
/**
* Update item values.
*/
default void updateItemValues() {}

/**
* Make item selectable.
*
* @param data
* the data
* @param b
* the b
*/
default void makeItemSelectable(final T data, final boolean b) {}

/**
* Make item visible.
*
* @param obj
* the obj
* @param b
* the b
*/
default void makeItemVisible(final T obj, final boolean b) {}

/**
* Checks if is item visible.
*
* @param obj
* the obj
* @return true, if is item visible
*/
default boolean isItemVisible(final T obj) {
return true;
}

/**
* Gets the item display color.
*
* @param data
* the data
* @return the item display color
*/
default GamaColor getItemDisplayColor(final T data) {
return null;
}

/**
* Handle menu.
*
* @param data
* the data
* @param x
* the x
* @param y
* the y
* @return the map
*/
default Map<String, Runnable> handleMenu(final T data, final int x, final int y) {
return null;
}

}

0 comments on commit e79a7b5

Please sign in to comment.