<commit_before>/*
*
* Copyright 2008,2009 Newcastle University
*
* This file is part of Workcraft.
*
* Workcraft is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Workcraft is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Workcraft.  If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.workcraft.dom.visual;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.workcraft.dom.Container;
import org.workcraft.dom.DefaultGroupImpl;
import org.workcraft.dom.Node;
import org.workcraft.dom.visual.connections.VisualConnection;
import org.workcraft.gui.Coloriser;
import org.workcraft.gui.graph.tools.ContainerDecoration;
import org.workcraft.gui.graph.tools.Decoration;
import org.workcraft.gui.propertyeditor.PropertyDeclaration;
import org.workcraft.observation.HierarchyObserver;
import org.workcraft.observation.ObservableHierarchy;
import org.workcraft.observation.TransformChangedEvent;
import org.workcraft.observation.TransformChangingEvent;
import org.workcraft.plugins.shared.CommonVisualSettings;
import org.workcraft.util.Hierarchy;


public class VisualGroup extends VisualTransformableNode implements Drawable, Collapsible, Container, ObservableHierarchy {
	public static final int HIT_COMPONENT = 1;
	public static final int HIT_CONNECTION = 2;
	public static final int HIT_GROUP = 3;

	protected double size = CommonVisualSettings.getBaseSize();
	protected final double margin = 0.20;

	private boolean isCurrentLevelInside = false;
	private boolean isCollapsed = false;
	private boolean isExcited = false;
	DefaultGroupImpl groupImpl = new DefaultGroupImpl(this);

	public VisualGroup() {
		super();
		addPropertyDeclarations();
	}

	private void addPropertyDeclarations() {
		addPropertyDeclaration(new PropertyDeclaration<VisualGroup, Boolean>(
				this, "Is collapsed", Boolean.class) {

			@Override
			protected void setter(VisualGroup object, Boolean value) {
				object.setIsCollapsed(value);
			}
			@Override
			protected Boolean getter(VisualGroup object) {
				return object.getIsCollapsed();
			}
		});
	}

	@Override
	public void setIsCurrentLevelInside(boolean value) {
		if (isCurrentLevelInside != value) {
			sendNotification(new TransformChangingEvent(this));
			this.isCurrentLevelInside = value;
			sendNotification(new TransformChangedEvent(this));
		}
	}

	public boolean isCurrentLevelInside() {
		return isCurrentLevelInside;
	}

	@Override
	public void setIsCollapsed(boolean value) {
		if (isCollapsed != value) {
			sendNotification(new TransformChangingEvent(this));
			isCollapsed = value;
			Point2D centre = TransformHelper.getSnappedCentre(getChildren());
			setPosition(new Point2D.Double(getX() + centre.getX(), getY() + centre.getY()));
			sendNotification(new TransformChangedEvent(this));
		}
	}

	@Override
	public boolean getIsCollapsed() {
		return (isCollapsed && !isExcited);
	}

	@Override
	public void setIsExcited(boolean value) {
		if (isExcited != value) {
			sendNotification(new TransformChangingEvent(this));
			isExcited = value;
			sendNotification(new TransformChangedEvent(this));
		}
	}

	@Override
	public void draw(DrawRequest r) {<commit_msg>Fix for copy-pasting collapsed groups.<commit_after>/*
*
* Copyright 2008,2009 Newcastle University
*
* This file is part of Workcraft.
*
* Workcraft is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Workcraft is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Workcraft.  If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.workcraft.dom.visual;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.workcraft.dom.Container;
import org.workcraft.dom.DefaultGroupImpl;
import org.workcraft.dom.Node;
import org.workcraft.dom.visual.connections.VisualConnection;
import org.workcraft.gui.Coloriser;
import org.workcraft.gui.graph.tools.ContainerDecoration;
import org.workcraft.gui.graph.tools.Decoration;
import org.workcraft.gui.propertyeditor.PropertyDeclaration;
import org.workcraft.observation.HierarchyObserver;
import org.workcraft.observation.ObservableHierarchy;
import org.workcraft.observation.TransformChangedEvent;
import org.workcraft.observation.TransformChangingEvent;
import org.workcraft.plugins.shared.CommonVisualSettings;
import org.workcraft.util.Hierarchy;


public class VisualGroup extends VisualTransformableNode implements Drawable, Collapsible, Container, ObservableHierarchy {
	public static final int HIT_COMPONENT = 1;
	public static final int HIT_CONNECTION = 2;
	public static final int HIT_GROUP = 3;

	protected double size = CommonVisualSettings.getBaseSize();
	protected final double margin = 0.20;

	private boolean isCurrentLevelInside = false;
	private boolean isCollapsed = false;
	private boolean isExcited = false;
	DefaultGroupImpl groupImpl = new DefaultGroupImpl(this);

	public VisualGroup() {
		super();
		addPropertyDeclarations();
	}

	private void addPropertyDeclarations() {
		addPropertyDeclaration(new PropertyDeclaration<VisualGroup, Boolean>(
				this, "Is collapsed", Boolean.class) {

			@Override
			protected void setter(VisualGroup object, Boolean value) {
				object.setIsCollapsed(value);
			}
			@Override
			protected Boolean getter(VisualGroup object) {
				return object.getIsCollapsed();
			}
		});
	}

	@Override
	public void setIsCurrentLevelInside(boolean value) {
		if (isCurrentLevelInside != value) {
			sendNotification(new TransformChangingEvent(this));
			this.isCurrentLevelInside = value;
			sendNotification(new TransformChangedEvent(this));
		}
	}

	public boolean isCurrentLevelInside() {
		return isCurrentLevelInside;
	}

	@Override
	public void setIsCollapsed(boolean value) {
		if (isCollapsed != value) {
			sendNotification(new TransformChangingEvent(this));
			isCollapsed = value;
			sendNotification(new TransformChangedEvent(this));
		}
	}

	@Override
	public boolean getIsCollapsed() {
		return (isCollapsed && !isExcited);
	}

	@Override
	public void setIsExcited(boolean value) {
		if (isExcited != value) {
			sendNotification(new TransformChangingEvent(this));
			isExcited = value;
			sendNotification(new TransformChangedEvent(this));
		}
	}

	@Override
	public void draw(DrawRequest r) {
{'fraction_non_alphanumeric': 0.08819575154611455, 'fraction_numerical': 0.005377789728421619, 'mean_word_length': 5.251260504201681, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1690905', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2128, 'n_words': 604}