⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractcontroller2d.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			// update atoms			updateAtom(atomCon, newAtom1);			chemModel.getMoleculeSet().addAtomContainer(atomCon);			//FIXME undoredo			IAtomContainer undoRedoContainer= chemModel.getBuilder().newAtomContainer();			undoRedoContainer.addAtom(newAtom1);			UndoableEdit  edit = new AddAtomsAndBondsEdit(chemModel, undoRedoContainer, "Add Atom",c2dm);			undoRedoHandler.postEdit(edit);			this.updateMoleculeCoordinates();			r2dm.fireChange();			fireChange();		}	}	private void changeSymbol() {		IAtom atomInRange = r2dm.getHighlightedAtom();		if (atomInRange != null)		{			if (currentCommonElement.get(atomInRange) == null)			{				currentCommonElement.put(atomInRange, new Integer(1));			}			int oldCommonElement = ((Integer) currentCommonElement.get(atomInRange)).intValue();			String symbol = (String) commonElements.elementAt(oldCommonElement);			if (!(atomInRange.getSymbol().equals(symbol)))			{				// only change symbol if needed                String formerSymbol = atomInRange.getSymbol();				atomInRange.setSymbol(symbol);				// configure the atom, so that the atomic number matches the symbol				try				{					IsotopeFactory.getInstance(atomInRange.getBuilder()).configure(atomInRange);				} catch (Exception exception)				{					logger.error("Error while configuring atom");					logger.debug(exception);				}				// update atom				IAtomContainer container = ChemModelManipulator.getRelevantAtomContainer(chemModel, atomInRange);				updateAtom(container, atomInRange);				/*				 *  PRESERVE THIS. This notifies the				 *  the listener responsible for				 *  undo and redo storage that it				 *  should store this change of an atom symbol				 */				isUndoableChange = true;				/*				 *  ---				 */                UndoableEdit  edit = new ChangeAtomSymbolEdit(atomInRange, formerSymbol, symbol);                undoRedoHandler.postEdit(edit);				r2dm.fireChange();				fireChange();			}			oldCommonElement++;			if (oldCommonElement == commonElements.size())			{				oldCommonElement = 0;			}			currentCommonElement.put(atomInRange, new Integer(oldCommonElement));		}	}	/**	 *  Makes a ring aromatic	 *	 *@param  ring  The ring to be made aromatic	 */	private void makeRingAromatic(IRing ring)	{		Iterator atoms = ring.atoms();		while (atoms.hasNext()) {			((IAtom)atoms.next()).setFlag(CDKConstants.ISAROMATIC, true);		}		Iterator bonds = ring.bonds();		while (bonds.hasNext()) {			((IBond)bonds.next()).setFlag(CDKConstants.ISAROMATIC, true);		}	}	/**	 *  manages all actions that will be invoked when a mouse button is clicked	 *	 *@param  e  MouseEvent object	 */	public void mouseClicked(MouseEvent e)	{		// logger.debug("Mouse clicked");	}	/**	 *  manages all actions that will be invoked when a mouse enters a component	 *	 *@param  e  MouseEvent object	 */	public void mouseEntered(MouseEvent e)	{		// logger.debug("Mouse entered");	}	/**	 *  manages all actions that will be invoked when a mouse exits a component	 *	 *@param  e  MouseEvent object	 */	public void mouseExited(MouseEvent e)	{		// logger.debug("Mouse exited");	}	/**	 *  manages all actions that will be invoked when a key is released	 *	 *@param  e  MouseEvent object	 */	public void keyReleased(KeyEvent e)	{		logger.debug("Key released");	}	/**	 *  manages all actions that will be invoked when a key is typed	 *	 *@param  e  MouseEvent object	 */	public void keyTyped(KeyEvent e)	{		try{			logger.debug("Key typed");			if(r2dm.getHighlightedAtom()!=null){				IsotopeFactory ifa=IsotopeFactory.getInstance(r2dm.getHighlightedAtom().getBuilder());				IIsotope iso=ifa.getMajorIsotope(e.getKeyChar());				if(iso!=null)					r2dm.getHighlightedAtom().setSymbol(e.getKeyChar()+"");			}		}catch(Exception ex){			logger.debug("Exception "+ex.getMessage()+" in keyPressed in AbstractController");		}	}	/**	 *  manages all actions that will be invoked when a key is pressed	 *	 *@param  e  MouseEvent object	 */	public void keyPressed(KeyEvent e)	{		logger.debug("Key pressed");	}	/*	 *  Start of private methods	 */	/**	 *  Updates an array of atoms with respect to its hydrogen count	 *	 *@param  container  The AtomContainer to work on	 *@param  atoms       The Atoms to update	 */	private void updateAtoms(IAtomContainer container, java.util.Iterator atoms)	{		while (atoms.hasNext())		{			updateAtom(container, (IAtom)atoms.next());		}	}	/**	 *  Updates an atom with respect to its hydrogen count	 *	 *@param  container  The AtomContainer to work on	 *@param  atom       The Atom to update	 */	public void updateAtom(IAtomContainer container, IAtom atom)	{		if (c2dm.getAutoUpdateImplicitHydrogens())		{			atom.setHydrogenCount(0);			try			{				hydrogenAdder.addImplicitHydrogensToSatisfyValency(container, atom);			} catch (Exception exception)			{				logger.error(exception.getMessage());				logger.debug(exception);			}		}	}	/**	 *  No idea what this does	 *	 *@param  angle  Some kind of angle	 *@return        Don't know what	 */	private double snapAngle(double angle)	{		double div = (Math.PI / 180) * c2dm.getSnapAngle();		return (Math.rint(angle / div)) * div;	}	/**	 *  Gets the chemObjectInRange attribute of the Controller2D object	 *	 *@param  X  Current mouse x	 *@param  Y  Current mouse x	 *@return    The chemObjectInRange value	 */	public IChemObject getChemObjectInRange(int X, int Y)	{		IChemObject objectInRange = getAtomInRange(X, Y);		if (objectInRange != null)		{			// logger.debug("Returning nearest Atom: " + objectInRange);			return objectInRange;		}		objectInRange = getBondInRange(X, Y);		if (objectInRange != null)		{			// logger.debug("Returning nearest Bond: " + objectInRange);			return objectInRange;		}		objectInRange = getReactionInRange(X, Y);		if (objectInRange != null)		{			// logger.debug("Returning nearest Reaction: " + objectInRange);			return objectInRange;		}		/*		 *  chemModel covers whole of editing window, and if nothing		 *  more interesting is near, then them model is in range.		 */		// logger.debug("Returning nearest ChemModel: " + chemModel);		return chemModel;	}	/**	 *  Returns an Atom if it is in a certain range of the given point. Used to	 *  highlight an atom that is near the cursor. <p>	 *	 *  <b>Important: the coordinates must be given in world coordinates and not in	 *  screen coordinates!	 *	 *@param  X  The x world coordinate of the point	 *@param  Y  The y world coordinate of the point	 *@return    An Atom if it is in a certain range of the given point	 */	private IAtom getAtomInRange(int X, int Y)	{		return getAtomInRange(X,Y,null);	}			/**	 *  Returns an Atom if it is in a certain range of the given point. Used to	 *  highlight an atom that is near the cursor. <p>	 *	 *  <b>Important: the coordinates must be given in world coordinates and not in	 *  screen coordinates!	 *	 *@param  X  The x world coordinate of the point	 *@param  Y  The y world coordinate of the point	 *@return    An Atom if it is in a certain range of the given point	 */	private IAtom getAtomInRange(int X, int Y, IAtom ignore)	{		double highlightRadius = r2dm.getHighlightRadius();		IAtom closestAtom = GeometryTools.getClosestAtom(X, Y, chemModel, ignore, r2dm.getRenderingCoordinates());		if (closestAtom != null)		{			//logger.debug("getAtomInRange(): An atom is near");			if (!(Math.sqrt(Math.pow(r2dm.getRenderingCoordinate(closestAtom).x - X, 2) +					Math.pow(r2dm.getRenderingCoordinate(closestAtom).y - Y, 2)) < highlightRadius))			{				closestAtom = null;			} else {				// we got a winner!				// set the associated AtomContainer, for use by JCP's Molecule Properties action                // COMMENTED OUT: causes cloning trouble/*				closestAtom.setProperty(					SimpleController2D.MATCHING_ATOMCONTAINER,					ChemModelManipulator.getRelevantAtomContainer(chemModel, closestAtom)				);*/			}		}		return closestAtom;	}	private IAtomContainer getBondInRangeTemporaryAtomContainer = null;	/**	 *  Returns a Bond if it is in a certain range of the given point. Used to	 *  highlight a bond that is near the cursor. <p>	 *	 *  <b>Important: the coordinates must be given in world coordinates and not in	 *  screen coordinates!	 *	 *@param  X  The x world coordinate of the point	 *@param  Y  The y world coordinate of the point	 *@return    An Atom if it is in a certain range of the given point	 */	private IBond getBondInRange(int X, int Y) {		if (getBondInRangeTemporaryAtomContainer == null) {			getBondInRangeTemporaryAtomContainer = chemModel.getBuilder().newAtomContainer();		} else {			getBondInRangeTemporaryAtomContainer.removeAllElements();		}        double highlightRadius = r2dm.getHighlightRadius();		Iterator atomCons = ChemModelManipulator.getAllAtomContainers(chemModel).iterator();		while (atomCons.hasNext()) {			getBondInRangeTemporaryAtomContainer.add((IAtomContainer)atomCons.next());		}        if (getBondInRangeTemporaryAtomContainer.getBondCount() != 0) {            IBond closestBond = GeometryTools.getClosestBond(X, Y, getBondInRangeTemporaryAtomContainer,r2dm.getRenderingCoordinates());    		if (closestBond == null)    		{    			return null;    		}    		// logger.debug("closestBond  "+ closestBond);    		int[] coords = GeometryTools.distanceCalculator(    				GeometryTools.getBondCoordinates(closestBond, r2dm.getRenderingCoordinates()), highlightRadius);    		int[] xCoords = {coords[0], coords[2], coords[4], coords[6]};    		int[] yCoords = {coords[1], coords[3], coords[5], coords[7]};    		if ((new Polygon(xCoords, yCoords, 4)).contains(new Point(X, Y)))    		{    			return closestBond;    		}        }		return null;	}	abstract IReaction getReactionInRange(int X, int Y);	/**	 *  Returns an AtomContainer that contains the atom or the the bond with its	 *  two atoms that are highlighted at the moment.	 *	 *@return    An AtomContainer containig the highlighted atom\atoms\bond	 */	 IAtomContainer getHighlighted()	{		IAtomContainer highlighted = chemModel.getBuilder().newAtomContainer();		IAtom highlightedAtom = r2dm.getHighlightedAtom();		IBond highlightedBond = r2dm.getHighlightedBond();		if (highlightedAtom != null)		{			highlighted.addAtom(highlightedAtom);		} else if (highlightedBond != null)		{			highlighted.addBond(highlightedBond);			for (int i = 0; i < highlightedBond.getAtomCount(); i++)			{				highlighted.ad

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -