private void fillAreaWithAtoms(Rectangle area, int lattice, int id) {
		Element e = model.getElement(id);
		if (e == null)
			throw new IllegalArgumentException("atom id incorrect");
		double sigma = e.getSigma();
		int k = model.getNumberOfParticles();
		if (k >= atom.length) {
			errorReminder.show(ErrorReminder.EXCEED_CAPACITY);
			return;
		}
		int k0 = k;
		double w = area.width;
		double h = area.height;
		double x = area.x;
		double y = area.y;
		switch (lattice) {
		case SQUARE_LATTICE:
			double spacing = sigma * TWO_TO_ONE_SIXTH;
			int m = (int) Math.round(w / spacing);
			int n = (int) Math.round(h / spacing);
			double rx,
			ry;
			terminate: for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++) {
					rx = x + i * spacing;
					ry = y + j * spacing;
					if (rx - 0.5 * sigma >= x && rx + 0.5 * sigma < x + w && ry - 0.5 * sigma >= y && ry + 0.5 * sigma < y + h) {
						atom[k].setRx(rx);
						atom[k].setRy(ry);
						atom[k].setElement(e);
						atom[k].setCharge(0);
						atom[k].setCustom(0);
						atom[k].setRestraint(null);
						atom[k].setFriction(0);
						atom[k].setRadical(true);
						atom[k].setUserField(null);
						k++;
						if (k >= atom.length) {
							errorReminder.show(ErrorReminder.EXCEED_CAPACITY);
							break terminate;
						}
					}
				}
			}
			break;
		case HEXAGONAL_LATTICE:
			double COS30 = 0.5 * Math.sqrt(3.0);
			double xspacing = sigma * TWO_TO_ONE_SIXTH;
			double yspacing = xspacing * COS30;
			m = (int) Math.round(w / xspacing);
			n = (int) Math.round(h / yspacing);
			terminate: for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (i % 2 == 0) {
						rx = x + j * xspacing;
					} else {
						rx = x + (j + 0.5) * xspacing;
					}
					ry = y + i * yspacing;
					if (rx - 0.5 * sigma >= x && rx + 0.5 * sigma < x + w && ry - 0.5 * sigma >= y && ry + 0.5 * sigma < y + h) {
						atom[k].setRx(rx);
						atom[k].setRy(ry);
						atom[k].setElement(e);
						atom[k].setCharge(0);
						atom[k].setCustom(0);
						atom[k].setRestraint(null);
						atom[k].setFriction(0);
						atom[k].setRadical(true);
						atom[k].setUserField(null);
						k++;
						if (k >= atom.length) {
							errorReminder.show(ErrorReminder.EXCEED_CAPACITY);
							break terminate;
						}
					}
				}
			}
			break;
		}
		model.setNumberOfAtoms(k);
		model.notifyChange();
		if (!doNotFireUndoEvent) {
			model.getUndoManager().undoableEditHappened(new UndoableEditEvent(model, new UndoableInsertion(UndoAction.FILL_AREA_WITH_PARTICLES, x, y, k - k0, area, lattice, id)));
			updateUndoUIComponents();
		}
	}