<commit_before>package controller.listener;

import controller.DrawableObjectProcessing;
import controller.DrawingPanelViewController;
import model.drawables.Point;
import model.leveleditor.DashedRoom;
import model.leveleditor.Level;
import model.leveleditor.Room;

import javax.swing.event.MouseInputAdapter;
import java.awt.event.MouseEvent;

import static javax.swing.SwingUtilities.isLeftMouseButton;
import static javax.swing.SwingUtilities.isRightMouseButton;

/**
 * Created by <NAME> on 27/07/2016. Modified by <NAME>
 * 
 * Listener for the Rooms
 */
public class RoomListener extends MouseInputAdapter {

	private Point mousePos;
	private DrawingPanelViewController delegate;
	private Level level;
	private Room room;

	/**
	 * Constructor
	 * 
	 * @param delegate
	 *            The DrawableObjectProcessing of this Listener
	 * @param room
	 *            The Room, to listen
	 * @param level
	 *            The Level, which containts the room
	 */
	public RoomListener(DrawableObjectProcessing delegate, Room room, Level level) {
		this.delegate = (DrawingPanelViewController) delegate;
		this.level = level;
		this.room = room;
	}

	/**
	 * Methode to Handle mouseclicks shows room around Mouseposition. Rotates
	 * Room if already showed
	 * 
	 * @param e
	 *            The Mouseevent, which trigger actions
	 */
	public void mouseClicked(MouseEvent e) {

		// If MousePos isn't set yet
		if (mousePos == null) {
			// Create new MousePos
			mousePos = new Point(e.getX(), e.getY());

			// Sets the new center from the room
			room.setCenter(mousePos);
		} else {

			// Reaction for leftmouseclick
			if (isLeftMouseButton(e)) {
				// Compare ways with all not checked or cleared Level-ways
				if (room.compareWays(level.getWays())) {
					// Add room
					level.addRoom(room);
					level.setWays(room.getWaylist());
					delegate.clearTemporaryDrawableObject();
					delegate.processDrawableObject(room);
					this.delegate.refreshXML();
				}
				// Reaction of rightclick
			} else if (isRightMouseButton(e)) {
				// Rotate Room
				room.rotate();
				System.out.println(room.getcA().getAngle());
				delegate.setTemporaryObject(room);
				// TODO Delegate setzen (nice to have)
			}


		}
	}

	/**
	 * 
	 * Updated Center vom angefassten Raum.
	 *
	 * Übergebe mit Hilfe der aktuellen Mausposition ein DashedRectangle als
	 * temporäres Objekt an das Delegate, sofern bereits ein Mittelpunkt
	 * vorliegt.
	 * 
	 * @param e
	 *            The Event
	 */
	public void mouseMoved(MouseEvent e) {
		// If mousePos was'nt set yet
		if (mousePos != null) {
			// Set MousePos
			mousePos = new Point(e.getX(), e.getY());
			// Set center
			room.setCenter(mousePos);
			// TODO Delegate setzen (nice to have)

			DashedRoom r = new DashedRoom(this.room, mousePos);
			// Temporäres Objekt neu zeichnen
			delegate.setTemporaryDrawableObject(r);

		}
	}

	/**
	 * reset. yeah. megareset. uh. ultrareset. ja also alles auf anfang.
	 * 
	 * @param e
	 *            The MouseEvent
	 */
	public void mouseExited(MouseEvent e) {
		delegate.clearTemporaryDrawableObject();
		mousePos = null;
	}

	/**
	 * Getter for Level
	 * 
	 * @return returns the level
	 */
	public Level getLevel() {
		return this.level;<commit_msg>roomlistener müsste jetzt dashedroom anzeigen und updaten<commit_after>package controller.listener;

import controller.DrawableObjectProcessing;
import controller.DrawingPanelViewController;
import model.drawables.Point;
import model.leveleditor.DashedRoom;
import model.leveleditor.Level;
import model.leveleditor.Room;

import javax.swing.event.MouseInputAdapter;
import java.awt.event.MouseEvent;

import static javax.swing.SwingUtilities.isLeftMouseButton;
import static javax.swing.SwingUtilities.isRightMouseButton;

/**
 * Created by <NAME> on 27/07/2016. Modified by <NAME>
 * 
 * Listener for the Rooms
 */
public class RoomListener extends MouseInputAdapter {

	private Point mousePos;
	private DrawingPanelViewController delegate;
	private Level level;
	private Room room;

	/**
	 * Constructor
	 * 
	 * @param delegate
	 *            The DrawableObjectProcessing of this Listener
	 * @param room
	 *            The Room, to listen
	 * @param level
	 *            The Level, which containts the room
	 */
	public RoomListener(DrawableObjectProcessing delegate, Room room, Level level) {
		this.delegate = (DrawingPanelViewController) delegate;
		this.level = level;
		this.room = room;
	}

	/**
	 * Methode to Handle mouseclicks shows room around Mouseposition. Rotates
	 * Room if already showed
	 * 
	 * @param e
	 *            The Mouseevent, which trigger actions
	 */
	public void mouseClicked(MouseEvent e) {

		// If MousePos isn't set yet
		if (mousePos == null) {
			// Create new MousePos
			mousePos = new Point(e.getX(), e.getY());
			// Sets the new center from the room
			room.setCenter(mousePos);
		} else {
			// Reaction for leftmouseclick
			if (isLeftMouseButton(e)) {
				// Compare ways with all not checked or cleared Level-ways
				if (room.compareWays(level.getWays())) {
					// Add room
					level.addRoom(room);
					level.setWays(room.getWaylist());

					delegate.clearTemporaryDrawableObject();
					delegate.processDrawableObject(room);

					this.delegate.refreshXML();
				}
				// Reaction of rightclick
			} else if (isRightMouseButton(e)) {
				// Rotate Room
				room.rotate();

				DashedRoom r = new DashedRoom(this.room, mousePos);

				delegate.setTemporaryObject(r);
			}


		}
	}

	/**
	 * 
	 * Updated Center vom angefassten Raum.
	 *
	 * Übergebe mit Hilfe der aktuellen Mausposition ein DashedRectangle als
	 * temporäres Objekt an das Delegate, sofern bereits ein Mittelpunkt
	 * vorliegt.
	 * 
	 * @param e
	 *            The Event
	 */
	public void mouseMoved(MouseEvent e) {
		// If mousePos was'nt set yet
		if (mousePos != null) {
			// Set MousePos
			mousePos = new Point(e.getX(), e.getY());
			// Set center
			room.setCenter(mousePos);
			// TODO Delegate setzen (nice to have)

			DashedRoom r = new DashedRoom(this.room, mousePos);
			// Temporäres Objekt neu zeichnen
			delegate.setTemporaryDrawableObject(r);
		}
	}

	/**
	 * reset. yeah. megareset. uh. ultrareset. ja also alles auf anfang.
	 * 
	 * @param e
	 *            The MouseEvent
	 */
	public void mouseExited(MouseEvent e) {
		delegate.clearTemporaryDrawableObject();
		mousePos = null;
	}

	/**
	 * Getter for Level
	 * 
	 * @return returns the level
	 */
	public Level getLevel() {
		return this.level;
{'fraction_non_alphanumeric': 0.09904202719406675, 'fraction_numerical': 0.002472187886279357, 'mean_word_length': 3.1203055378739655, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6639607', 'n_tokens_mistral': 2243, 'n_tokens_neox': 1936, 'n_words': 553}