123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package holeg.model;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.logging.Logger;
- import java.util.stream.Stream;
- import holeg.preferences.ImagePreference;
- import holeg.serialize.PostDeserialize;
- public class GroupNode extends AbstractCanvasObject implements PostDeserialize {
- private static final Logger log = Logger.getLogger(AbstractCanvasObject.class.getName());
- private final ArrayList<HolonObject> objectList = new ArrayList<>();
- private final ArrayList<HolonSwitch> switchList = new ArrayList<>();
- private final ArrayList<Node> nodeList = new ArrayList<>();
- private final ArrayList<GroupNode> groupNodeList = new ArrayList<>();
- public GroupNode(String nodeName) {
- super(nodeName);
- }
- @Override
- public String getImagePath() {
- return ImagePreference.Canvas.GroupNode;
- }
- public void addAll(Stream<AbstractCanvasObject> stream) {
- stream.forEach(this::add);
- }
- public void addAll(Collection<AbstractCanvasObject> collection) {
- collection.forEach(this::add);
- }
-
- public void add(AbstractCanvasObject object) {
- if (object instanceof HolonObject hObject) {
- objectList.add(hObject);
- }else if(object instanceof HolonSwitch hSwitch) {
- switchList.add(hSwitch);
- }else if(object instanceof Node node) {
- nodeList.add(node);
- }else if(object instanceof GroupNode groupNode) {
- groupNodeList.add(groupNode);
- }
- object.setGroupNode(this);
- }
-
- public void remove(AbstractCanvasObject object) {
- if (object instanceof HolonObject hObject) {
- objectList.remove(hObject);
- }else if(object instanceof HolonSwitch hSwitch) {
- switchList.remove(hSwitch);
- }else if(object instanceof Node node) {
- nodeList.remove(node);
- }else if(object instanceof GroupNode groupNode) {
- groupNodeList.remove(groupNode);
- }
- object.setGroupNode(null);
- }
- public void removeAll(Stream<AbstractCanvasObject> stream){
- stream.forEach(this::remove);
- }
- public void removeAll(Collection<AbstractCanvasObject> collection){
- collection.forEach(this::remove);
- }
- public Stream<AbstractCanvasObject> getObjectsInThisLayer() {
- return Stream.of(objectList.stream(), switchList.stream(), nodeList.stream(), groupNodeList.stream())
- .flatMap(s -> s);
- }
- public Stream<AbstractCanvasObject> getAllObjectsRecursive() {
- Stream<AbstractCanvasObject> objects = Stream.of(objectList.stream(), switchList.stream(), nodeList.stream())
- .flatMap(s -> s);
- return Stream.concat(objects,
- groupNodeList.stream().flatMap(GroupNode::getObjectsInThisLayer));
- }
- public Stream<HolonObject> getAllHolonObjectsRecursive() {
- return Stream.concat(objectList.stream(),
- groupNodeList.stream().flatMap(GroupNode::getAllHolonObjectsRecursive));
- }
- public Stream<HolonSwitch> getAllSwitchObjectsRecursive() {
- return Stream.concat(switchList.stream(),
- groupNodeList.stream().flatMap(GroupNode::getAllSwitchObjectsRecursive));
- }
- public Stream<Node> getAllNodeObjectsRecursive() {
- return Stream.concat(nodeList.stream(),
- groupNodeList.stream().flatMap(GroupNode::getAllNodeObjectsRecursive));
- }
- public Stream<GroupNode> getAllGroupNodeObjectsRecursive() {
- return Stream.concat(groupNodeList.stream(),
- groupNodeList.stream().flatMap(GroupNode::getAllGroupNodeObjectsRecursive));
- }
-
- public Stream<HolonObject> getHolonObjects() {
- return objectList.stream();
- }
-
- public Stream<HolonSwitch> getSwitches() {
- return switchList.stream();
- }
- public Stream<Node> getNodes() {
- return nodeList.stream();
- }
-
- public Stream<GroupNode> getGroupNodes() {
- return groupNodeList.stream();
- }
- public Stream<HolonElement> getHolonElements(){
- return objectList.stream().flatMap(HolonObject::elementsStream);
- }
- public void clear() {
- objectList.clear();
- switchList.clear();
- nodeList.clear();
- groupNodeList.clear();
- }
- @Override
- public void postDeserialize() {
- getObjectsInThisLayer().forEach(obj -> obj.setGroupNode(this));
- }
- }
|