Ptidej-v5.2-master/PADL Serialiser DB4O Tests/rsc/JHotDraw v5.1/src/CH/ifa/draw/figures/ConnectedTextTool.java
/*
 * @(#)ConnectedTextTool.java 5.1
 *
 */

package CH.ifa.draw.figures;

import java.awt.event.MouseEvent;

import CH.ifa.draw.framework.DrawingView;
import CH.ifa.draw.framework.Figure;
import CH.ifa.draw.standard.TextHolder;

/**
 * Tool to create new or edit existing text figures.
 * A new text figure is connected with the clicked figure.
 *
 * @see TextHolder
 */
public  class ConnectedTextTool extends TextTool {

	boolean     fConnected = false;

	public ConnectedTextTool(DrawingView view, Figure prototype) {
		super(view, prototype);
	}

	/**
	 * If the pressed figure is a TextHolder it can be edited otherwise
	 * a new text figure is created.
	 */
	public void mouseDown(MouseEvent e, int x, int y) {
		super.mouseDown(e, x, y);

	    Figure pressedFigure =  drawing().findFigureInside(x, y);

	    TextHolder textHolder = (TextHolder)createdFigure();
		if (!fConnected && pressedFigure != null &&
					 textHolder != null && pressedFigure != textHolder) {
			textHolder.connect(pressedFigure);
			fConnected = true;
		}
	}

	/**
	 * If the pressed figure is a TextHolder it can be edited otherwise
	 * a new text figure is created.
	 */
	public void activate() {
		fConnected = false;
	}
}

