void attach(Layered c) {
		int n = getModel().getNumberOfParticles();
		int imin = -1;
		double rmin = 100000000;
		double rcur = 0;
		Particle a = null;
		if (c instanceof ImageComponent || c instanceof RectangleComponent || c instanceof EllipseComponent || c instanceof TriangleComponent || c instanceof LineComponent) {
			Point p = c.getCenter();
			for (int i = 0; i < n; i++) {
				a = getModel().getParticle(i);
				if (c.contains(a.getRx(), a.getRy())) {
					rcur = (a.getRx() - p.x) * (a.getRx() - p.x) + (a.getRy() - p.y) * (a.getRy() - p.y);
					if (rcur < rmin) {
						rmin = rcur;
						imin = i;
					}
				}
			}
		} else if (c instanceof TextBoxComponent) {
			if (((TextBoxComponent) c).isCallOut()) {
				Point p = ((TextBoxComponent) c).getCallOutPoint();
				for (int i = 0; i < n; i++) {
					a = getModel().getParticle(i);
					if (a.contains(p.x, p.y)) {
						imin = a.getIndex();
						break;
					}
				}
			} else {
				Point p = c.getCenter();
				for (int i = 0; i < n; i++) {
					a = getModel().getParticle(i);
					if (c.contains(a.getRx(), a.getRy())) {
						rcur = (a.getRx() - p.x) * (a.getRx() - p.x) + (a.getRy() - p.y) * (a.getRy() - p.y);
						if (rcur < rmin) {
							rmin = rcur;
							imin = i;
						}
					}
				}
			}
		}
		if (imin >= 0) {
			c.setHost(getModel().getParticle(imin));
			repaint();
			getModel().notifyChange();
			if (!doNotFireUndoEvent) {
				getModel().getUndoManager().undoableEditHappened(new UndoableEditEvent(getModel(), new UndoableLayeredComponentOperation(UndoAction.ATTACH_LAYERED_COMPONENT, c)));
				updateUndoUIComponents();
			}
		}
	}