protected void processMousePressed(MouseEvent e) {

		super.processMousePressed(e);
		model.runMouseScript(MouseEvent.MOUSE_PRESSED, e.getX(), e.getY());

		int x = e.getX();
		int y = e.getY();
		int clickCount = e.getClickCount();

		if (viewer.getNavigationMode()) {
			if (navigator.navigate(x, y))
				return;
		}

		switch (actionID) {
		case DEFA_ID:
			setRotationEnabled(getSelectedElement() == null);
			break;
		case PANN_ID:
			dragPoint.setLocation(x, y);
			break;
		case SLAT_ID:
			int iat = viewer.findNearestAtomIndex(x, y);
			if (iat >= 0) {
				if (e.isShiftDown()) {
					addAtomSelection(iat);
				}
				else {
					multiselectionBitSet.clear();
					multiselectionBitSet.set(iat);
					selectAtom(iat);
				}
			}
			break;
		case PCHG_ID:
			iat = viewer.findNearestAtomIndex(x, y);
			if (iat >= 0) {
				model.getAtom(iat).addCharge(e.isShiftDown() ? -0.1f : 0.1f);
				runJmolScriptImmediatelyWithoutThread("label OFF;select atomno=" + (iat + 1) + "; label "
						+ FORMAT.format(model.getAtom(iat).getCharge()));
				model.notifyChange();
			}
			else {
				runJmolScriptImmediatelyWithoutThread("label OFF");
			}
			break;
		case NCHG_ID:
			iat = viewer.findNearestAtomIndex(x, y);
			if (iat >= 0) {
				model.getAtom(iat).addCharge(e.isShiftDown() ? 0.1f : -0.1f);
				runJmolScriptImmediatelyWithoutThread("label OFF;select atomno=" + (iat + 1) + "; label "
						+ FORMAT.format(model.getAtom(iat).getCharge()));
				model.notifyChange();
			}
			else {
				runJmolScriptImmediatelyWithoutThread("label OFF");
			}
			break;
		case ROTA_ID:
		case TRAN_ID:
		case DUPL_ID:
			dragPoint.setLocation(x, y);
			selectMoleculeOrNot(x, y);
			break;
		case SBOX_ID:
			clickPoint.setLocation(x, y);
			selectedFace = viewer.getSimulationBoxFace(x, y);
			setRotationEnabled(selectedFace < 0);
			switch (selectedFace) {
			case 0x00: // front
			case 0x01: // rear
				clickPoint3D.set(viewer.findPointOnPlane('x', x, y, 0));
				absMax = model.getAbsZmax();
				originalValue = model.getHeight();
				break;
			case 0x02: // top
			case 0x03: // bottom
				clickPoint3D.set(viewer.findPointOnPlane('z', x, y, 0));
				absMax = model.getAbsYmax();
				originalValue = model.getWidth();
				break;
			case 0x04: // right
			case 0x05: // left
				clickPoint3D.set(viewer.findPointOnPlane('y', x, y, 0));
				absMax = model.getAbsXmax();
				originalValue = model.getLength();
				break;
			}
			break;
		case EXOB_ID:
			clickPoint.setLocation(x, y);
			obstacleIndexAndFace = viewer.findNearestObstacleIndexAndFace(x, y);
			if (obstacleIndexAndFace != null && obstacleIndexAndFace[0] >= 0 && obstacleIndexAndFace[1] >= 0) {
				setRotationEnabled(false);
				Obstacle obstacle = model.getObstacle(obstacleIndexAndFace[0]);
				if (obstacle instanceof CuboidObstacle) {
					CuboidObstacle obs = (CuboidObstacle) obstacle;
					switch (obstacleIndexAndFace[1]) {
					case 0x00: // front
					case 0x01: // rear
						clickPoint3D.set(viewer.findPointOnPlane('x', x, y, 0));
						originalCenter = obs.getCenter().z;
						originalCorner = obs.getCorner().z;
						break;
					case 0x02: // top
					case 0x03: // bottom
						clickPoint3D.set(viewer.findPointOnPlane('z', x, y, 0));
						originalCenter = obs.getCenter().y;
						originalCorner = obs.getCorner().y;
						break;
					case 0x04: // right
					case 0x05: // left
						clickPoint3D.set(viewer.findPointOnPlane('y', x, y, 0));
						originalCenter = obs.getCenter().x;
						originalCorner = obs.getCorner().x;
						break;
					}
				}
				else if (obstacle instanceof CylinderObstacle) {
					CylinderObstacle obs = (CylinderObstacle) obstacle;
					switch (obs.getAxis()) {
					case 'x':
						clickPoint3D.set(viewer.findPointOnPlane('y', x, y, 0));
						switch (obstacleIndexAndFace[1]) {
						case 0x00: // top
						case 0x01: // bottom
							originalCenter = obs.getCenter().x;
							originalCorner = 0.5f * obs.getHeight();
							break;
						case 0x02: // lateral
							originalCorner = obs.getRadius();
							break;
						}
						break;
					case 'y':
						clickPoint3D.set(viewer.findPointOnPlane('z', x, y, 0));
						switch (obstacleIndexAndFace[1]) {
						case 0x00: // top
						case 0x01: // bottom
							originalCenter = obs.getCenter().y;
							originalCorner = 0.5f * obs.getHeight();
							break;
						case 0x02: // lateral
							originalCorner = obs.getRadius();
							break;
						}
						break;
					case 'z':
						clickPoint3D.set(viewer.findPointOnPlane('x', x, y, 0));
						switch (obstacleIndexAndFace[1]) {
						case 0x00: // top
						case 0x01: // bottom
							originalCenter = obs.getCenter().z;
							originalCorner = 0.5f * obs.getHeight();
							break;
						case 0x02: // lateral
							originalCorner = obs.getRadius();
							break;
						}
						break;
					}
				}
			}
			else {
				setRotationEnabled(true);
			}
			break;
		case VVEL_ID:
			if (selectedComponent instanceof Atom) {
				Atom at = (Atom) selectedComponent;
				int i = at.getIndex();
				viewer.setIndexOfAtomOfSelectedVelocity(i);
				viewer.setAtomVelocities(i, at.getVx(), at.getVy(), at.getVz());
				clickPoint.setLocation(x, y);
				selectedFace = viewer.getVectorBoxFace(x, y);
				switch (selectedFace) {
				case 0x00: // front
				case 0x01: // rear
					clickPoint3D.set(viewer.findPointOnPlane('x', x, y, 0));
					originalValue = ((Atom) selectedComponent).getVz() * velocityScalingFactor;
					break;
				case 0x02: // top
				case 0x03: // bottom
					clickPoint3D.set(viewer.findPointOnPlane('z', x, y, 0));
					originalValue = ((Atom) selectedComponent).getVy() * velocityScalingFactor;
					break;
				case 0x04: // right
				case 0x05: // left
					clickPoint3D.set(viewer.findPointOnPlane('y', x, y, 0));
					originalValue = ((Atom) selectedComponent).getVx() * velocityScalingFactor;
					break;
				}
				setRotationEnabled(selectedFace < 0);
			}
			break;
		case XADD_ID:
			selectAtomOnDropPlane('x', x, y);
			break;
		case YADD_ID:
			selectAtomOnDropPlane('y', x, y);
			break;
		case ZADD_ID:
			selectAtomOnDropPlane('z', x, y);
			break;
		case XREC_ID:
			Point3f p = viewer.findPointOnDropPlane('x', x, y);
			shapeWithinBounds = Math.abs(2 * p.y) < model.getWidth() + 2 && Math.abs(2 * p.z) < model.getHeight() + 2;
			setRotationEnabled(!shapeWithinBounds);
			if (shapeWithinBounds) {
				if (Math.abs(2 * p.y) > model.getWidth())
					p.y = model.getWidth() * (p.y < 0 ? -0.5f : 0.5f);
				if (Math.abs(2 * p.z) > model.getHeight())
					p.z = model.getHeight() * (p.z < 0 ? -0.5f : 0.5f);
				clickPoint3D.set(p);
				dragPoint3D.set(p);
				viewer.setRectangleVisible(true);
			}
			break;
		case YREC_ID:
			p = viewer.findPointOnDropPlane('y', x, y);
			shapeWithinBounds = Math.abs(2 * p.x) < model.getLength() + 2 && Math.abs(2 * p.z) < model.getHeight() + 2;
			setRotationEnabled(!shapeWithinBounds);
			if (shapeWithinBounds) {
				if (Math.abs(2 * p.x) > model.getLength())
					p.x = model.getLength() * (p.x < 0 ? -0.5f : 0.5f);
				if (Math.abs(2 * p.z) > model.getHeight())
					p.z = model.getHeight() * (p.z < 0 ? -0.5f : 0.5f);
				clickPoint3D.set(p);
				dragPoint3D.set(p);
				viewer.setRectangleVisible(true);
			}
			break;
		case ZREC_ID:
			p = viewer.findPointOnDropPlane('z', x, y);
			shapeWithinBounds = Math.abs(2 * p.x) < model.getLength() + 2 && Math.abs(2 * p.y) < model.getWidth() + 2;
			setRotationEnabled(!shapeWithinBounds);
			if (shapeWithinBounds) {
				if (Math.abs(2 * p.x) > model.getLength())
					p.x = model.getLength() * (p.x < 0 ? -0.5f : 0.5f);
				if (Math.abs(2 * p.y) > model.getWidth())
					p.y = model.getWidth() * (p.y < 0 ? -0.5f : 0.5f);
				clickPoint3D.set(p);
				dragPoint3D.set(p);
				viewer.setRectangleVisible(true);
			}
			break;
		case XOVL_ID:
			p = viewer.findPointOnDropPlane('x', x, y);
			shapeWithinBounds = Math.abs(2 * p.y) < model.getWidth() + 2 && Math.abs(2 * p.z) < model.getHeight() + 2;
			setRotationEnabled(!shapeWithinBounds);
			if (shapeWithinBounds) {
				if (Math.abs(2 * p.y) > model.getWidth())
					p.y = model.getWidth() * (p.y < 0 ? -0.5f : 0.5f);
				if (Math.abs(2 * p.z) > model.getHeight())
					p.z = model.getHeight() * (p.z < 0 ? -0.5f : 0.5f);
				clickPoint3D.set(p);
				dragPoint3D.set(p);
				viewer.setEllipseVisible(true);
			}
			break;
		case YOVL_ID:
			p = viewer.findPointOnDropPlane('y', x, y);
			shapeWithinBounds = Math.abs(2 * p.x) < model.getLength() + 2 && Math.abs(2 * p.z) < model.getHeight() + 2;
			setRotationEnabled(!shapeWithinBounds);
			if (shapeWithinBounds) {
				if (Math.abs(2 * p.x) > model.getLength())
					p.x = model.getLength() * (p.x < 0 ? -0.5f : 0.5f);
				if (Math.abs(2 * p.z) > model.getHeight())
					p.z = model.getHeight() * (p.z < 0 ? -0.5f : 0.5f);
				clickPoint3D.set(p);
				dragPoint3D.set(p);
				viewer.setEllipseVisible(true);
			}
			break;
		case ZOVL_ID:
			p = viewer.findPointOnDropPlane('z', x, y);
			shapeWithinBounds = Math.abs(2 * p.x) < model.getLength() + 2 && Math.abs(2 * p.y) < model.getWidth() + 2;
			setRotationEnabled(!shapeWithinBounds);
			if (shapeWithinBounds) {
				if (Math.abs(2 * p.x) > model.getLength())
					p.x = model.getLength() * (p.x < 0 ? -0.5f : 0.5f);
				if (Math.abs(2 * p.y) > model.getWidth())
					p.y = model.getWidth() * (p.y < 0 ? -0.5f : 0.5f);
				clickPoint3D.set(p);
				dragPoint3D.set(p);
				viewer.setEllipseVisible(true);
			}
			break;
		case SLRT_ID:
		case SLOV_ID:
		case DELR_ID:
		case DELC_ID:
		case FIXR_ID:
		case FIXC_ID:
		case XIFR_ID:
		case XIFC_ID:
		case TSLC_ID:
		case CLST_ID:
		case HIDE_ID:
		case EDIH_ID:
			if (clickCount == 1)
				selectedArea.setLocation(x, y);
			break;
		case RBND_ID:
			if (e.isAltDown()) {
				if (selectedComponent instanceof Atom) {
					int i = viewer.findNearestAtomIndex(x, y);
					if (i >= 0) {
						Atom a1 = (Atom) selectedComponent;
						Atom a2 = model.getAtom(i);
						addRBond(a1, a2);
					}
				}
			}
			else {
				int i = viewer.findNearestAtomIndex(x, y);
				if (i >= 0) {
					selectAtom(-1);
					selectAtom(i);
				}
			}
			break;
		case ABND_ID:
			if (e.isAltDown()) {
				if (selectedComponent instanceof RBond) {
					int i = viewer.findNearestBondIndex(x, y);
					if (i >= 0) {
						RBond rbond1 = (RBond) selectedComponent;
						RBond rbond2 = model.getRBond(i);
						addABond(rbond1, rbond2);
					}
				}
			}
			else {
				int i = viewer.findNearestBondIndex(x, y);
				if (i >= 0)
					selectRBond(i);
			}
			break;
		case TBND_ID:
			if (e.isAltDown()) {
				if (selectedComponent instanceof ABond) {
					int i = viewer.findNearestABondIndex(x, y);
					if (i >= 0) {
						ABond abond1 = (ABond) selectedComponent;
						ABond abond2 = model.getABond(i);
						addTBond(abond1, abond2);
					}
				}
			}
			else {
				int i = viewer.findNearestABondIndex(x, y);
				if (i >= 0)
					selectABond(i);
			}
			break;
		}

		if (showEnergizer && energizer != null) {
			energizer.energize(x, y);
		}

		repaint();

	}