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

📄 jchempaintpanel.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	public void showChemFile(org.openscience.cdk.interfaces.IChemFile chemFile) {		logger.info("Information read from file:");		int chemSequenceCount = chemFile.getChemSequenceCount();		logger.info("  # sequences: " + chemSequenceCount);		for (int i = 0; i < chemSequenceCount; i++) {			org.openscience.cdk.interfaces.IChemSequence chemSequence = chemFile.getChemSequence(i);			int chemModelCount = chemSequence.getChemModelCount();			logger.info("  # model in seq(" + i + "): " + chemModelCount);			for (int j = 0; j < chemModelCount; j++) {				org.openscience.cdk.interfaces.IChemModel chemModel = chemSequence.getChemModel(j);				showChemModel(chemModel);			}		}	}	public void showChemModel(org.openscience.cdk.interfaces.IChemModel chemModel) {		// check for bonds		if (ChemModelManipulator.getBondCount(chemModel) == 0) {			String error = "Model does not have bonds. Cannot depict contents.";			logger.warn(error);			JOptionPane.showMessageDialog(this, error);			return;		}		// check for coordinates		if (!(GeometryTools.has2DCoordinatesNew(chemModel)==0)) {			String error = "Model does not have coordinates. Will ask for coord generation.";			logger.warn(error);			CreateCoordinatesForFileDialog frame = new CreateCoordinatesForFileDialog((ChemModel)chemModel, jchemPaintModel.getRendererModel().getRenderingCoordinates());			frame.pack();			frame.show();			frame.moveToFront();			return;		} else if ((GeometryTools.has2DCoordinatesNew(chemModel)==0)) {			int result=JOptionPane.showConfirmDialog(this,"Model has some 2d coordinates. Do you want to show only the atoms with 2d coordiantes?","Only some 2d cooridantes",JOptionPane.YES_NO_OPTION);			if(result>1){				CreateCoordinatesForFileDialog frame = new CreateCoordinatesForFileDialog(chemModel, jchemPaintModel.getRendererModel().getRenderingCoordinates());				frame.pack();				frame.show();				return;			}else{				for(int i=0;i<chemModel.getMoleculeSet().getAtomContainerCount();i++){					for(int k=0;i<chemModel.getMoleculeSet().getAtomContainer(i).getAtomCount();k++){						if(chemModel.getMoleculeSet().getAtomContainer(i).getAtom(k).getPoint2d()==null)							chemModel.getMoleculeSet().getAtomContainer(i).removeAtomAndConnectedElectronContainers(chemModel.getMoleculeSet().getAtomContainer(i).getAtom(k));					}										}			}		}		setJChemPaintModel(new JChemPaintModel((ChemModel)chemModel),null);	}	/**	 *  Gets the chemModel attribute of the JChemPaint object. This method	 *  implements part of the CDKEditBus interface.	 *	 *@return    The chemModel value	 */	public org.openscience.cdk.interfaces.IChemModel getChemModel() {		return jchemPaintModel.getChemModel();	}	/**	 *  Gets the chemFile attribute of the JChemPaint object. This method	 *  implements part of the CDKEditBus interface.	 *	 *@return    The chemFile value	 */	public org.openscience.cdk.interfaces.IChemFile getChemFile() {		ChemFile file = new ChemFile();		ChemSequence sequence = new ChemSequence();		sequence.addChemModel(getChemModel());		file.addChemSequence(sequence);		return file;	}	/**	 *  Creates a JMenu which can be part of the menu of an application embedding	 *  jcp.	 *	 *@return    The created JMenu	 */	public JMenu getMenuForEmbedded() {		return (menu.getMenuForEmbedded(this));	}	/**	 *  Gets the drawingPanel attribute of the JChemPaintPanel object	 *	 *@return    The drawingPanel value	 */	public JPanel getDrawingPanel() {		return drawingPanel;	}			public String getMenuResourceString(String key) {		String str;		try {			str = JCPPropertyHandler.getInstance().getGUIDefinition().getString(key);		} catch (MissingResourceException mre) {			str = null;		}		return str;	}		/**	 * adds a popupmenu for embedded use of jcp and a mouseListener which lets 	 * pop up a floating jcp-frame with the actual model	 * 	 */	public void addFilePopUpMenu() {		if(guiString.equals("applet"))			return;	    String key = "popupmenubar";		String[] itemKeys = StringHelper.tokenize(getMenuResourceString(key));		JPopupMenu popupMenu = new JPopupMenu();		for (int i = 0; i < itemKeys.length; i++) {			String cmd = itemKeys[i];			if (cmd.equals("-")) {				popupMenu.addSeparator();				continue;			}			String translation = "***" + cmd + "***";			try {				translation = JCPLocalizationHandler.getInstance().getString(cmd);			} catch (MissingResourceException mre) {			}			JMenuItem mi = new JMenuItem(translation);			String astr = JCPPropertyHandler.getInstance().getResourceString(cmd + JCPAction.actionSuffix);			if (astr == null) {				astr = cmd;			}			mi.setActionCommand(astr);			JCPAction action = this.getJCPAction().getAction(this, astr);			if (action != null) {				// sync some action properties with menu				mi.setEnabled(action.isEnabled());				mi.addActionListener(action);			} else {				logger.error("Could not find JCPAction class for:" + astr);				mi.setEnabled(false);			}			popupMenu.add(mi);		}		getDrawingPanel().add(popupMenu);		MouseListener popupListener = new PopupListener(this, popupMenu);		getDrawingPanel().addMouseListener(popupListener);	}    /**     *  For showing the emdedded context menu and      *  sync the JChemPaintModels     *     *@author     thelmus     *@cdk.created    18. Mai 2005     */    class PopupListener extends MouseAdapter {        JPopupMenu popupMenu;    JChemPaintPanel panel;    Container parent;        public PopupListener(JChemPaintPanel panel, JPopupMenu popupMenu){      this.popupMenu = popupMenu;      this.panel = panel;    }        	public void mousePressed(MouseEvent e) {    		maybeShowPopup(e);    	}        	public void mouseReleased(MouseEvent e) {    		//maybeShowPopup(e);    	}        	private void maybeShowPopup(MouseEvent e) {    	    if (e.isPopupTrigger()) {    			popupMenu.show(e.getComponent(),    					e.getX(), e.getY());    		} else {    		    JFrame frame = null;    		    if (e.getButton() == 1 && e.getClickCount() == 2) {    		        if (panel instanceof JChemPaintViewerOnlyPanel) {	    		        frame = new JFrame();	    		        frame.addWindowListener(	    		                new WindowAdapter() {	    		                    public void windowClosing(WindowEvent e) {	    		                        parent.add(panel);	    		                        parent.repaint();	    		                    }	    		                });	    		        parent=panel.getParent();	    		        panel.getParent().remove(panel);	    		        frame.getContentPane().add(panel);	    		           		        }    		        else if (panel instanceof JChemPaintEditorPanel) {    		          panel = (JChemPaintEditorPanel) panel;    		          ChemModel model = (ChemModel)panel.getChemModel();    		          frame =JChemPaintEditorPanel.getNewFrame(new JChemPaintModel(model));    		          JChemPaintEditorPanel newPanel = (JChemPaintEditorPanel) frame.getContentPane().getComponent(0);    		          newPanel.scaleAndCenterMolecule(model);    		          newPanel.addChangeListener(panel);    		          newPanel.setEmbedded();    		          newPanel.setIsOpenedByViewer(true);    		          JViewport viewPort =((JScrollPane) ((Container) panel.getComponent(0)).getComponent(0)).getViewport();    		          DrawingPanel draw = (DrawingPanel) (viewPort.getView());    		          panel.drawingPanel = draw;    		          viewPort.remove(draw);    		        }    		        frame.setVisible(true);    		        frame.pack();    		    }    		}    	}    }	/**	 *  Class for closing jcp	 *	 *@author     steinbeck	 *@cdk.created    February 18, 2004	 */	public final static class AppCloser extends WindowAdapter {		/**		 *  closing Event. Shows a warning if this window has unsaved data and		 *  terminates jvm, if last window.		 *		 *@param  e  Description of the Parameter		 */		public void windowClosing(WindowEvent e) {			JFrame rootFrame = (JFrame) e.getSource();			if (rootFrame.getContentPane().getComponent(0) instanceof JChemPaintEditorPanel) {				JChemPaintEditorPanel panel = (JChemPaintEditorPanel) rootFrame.getContentPane().getComponent(0);				panel.fireChange(JChemPaintEditorPanel.JCP_CLOSING);			}			int clear = ((JChemPaintPanel) ((JFrame) e.getSource()).getContentPane().getComponents()[0]).showWarning();			if (JOptionPane.CANCEL_OPTION != clear) {				for (int i = 0; i < instances.size(); i++) {					if (((JPanel)instances.get(i)).getParent().getParent().getParent().getParent() == (JFrame)e.getSource()) {						instances.remove(i);						break;					}				}				((JFrame) e.getSource()).setVisible(false);				((JFrame) e.getSource()).dispose();				if (instances.size() == 0 && !((JChemPaintPanel)rootFrame.getContentPane().getComponent(0)).isEmbedded()) {					System.exit(0);				}			}		}	}	/**	 *  Closes all currently opened JCP instances.	 */	public static void closeAllInstances() {		Iterator it = instances.iterator();		while (it.hasNext()) {			JFrame frame = (JFrame) ((JPanel)it.next()).getParent().getParent().getParent().getParent();			WindowListener[] wls = (WindowListener[]) (frame.getListeners(WindowListener.class));			wls[0].windowClosing(new WindowEvent(frame, 12));			frame.setVisible(false);			frame.dispose();		}	}	public void registerModel(JChemPaintModel model) {	}	/**	 *  Mandatory because JChemPaint is a ChangeListener. Used by other classes to	 *  update the information in one of the three statusbar fields.	 *	 *@param  e  ChangeEvent	 */	public void stateChanged(ChangeEvent e) {		repaint();	}	// Here are the CDKEditBus methods	/**	 *  Gets the aPIVersion attribute of the JChemPaintPanel object	 *	 *@return    The aPIVersion value	 */	public String getAPIVersion() {		return "1.11";	}	public void runScript(String mimeType, String script) {		logger.error("JChemPaintPanel's CDKEditBus.runScript() implementation called but not implemented!");	}		/**	 * Returns the value of viewerDimension.	 */	public Dimension getViewerDimension()	{		return viewerDimension;	}	/**	 * Sets the value of viewerDimension.	 * @param viewerDimension The value to assign viewerDimension.	 */	public void setViewerDimension(Dimension viewerDimension)	{		this.viewerDimension = viewerDimension;	}    /**     * @return Returns the undoManager.     */    public UndoManager getUndoManager() {        return this.jchemPaintModel.getControllerModel().getUndoManager();    }    /**     * @param undoManager The undoManager to set.     */    public void setUndoManager(UndoManager undoManager) {    	this.jchemPaintModel.getControllerModel().setUndoManager(undoManager);    }    /**     * @return Returns the undoSupport.     */    public UndoableEditSupport getUndoSupport() {        return this.jchemPaintModel.getControllerModel().getUndoSupport();    }    /**     * @param undoSupport The undoSupport to set.     */    public void setUndoSupport(UndoableEditSupport undoSupport) {    	this.jchemPaintModel.getControllerModel().setUndoSupport(undoSupport);    }	public JButton getMoveButton() {		return moveButton;	}	public void setMoveButton(JButton moveButton) {		this.moveButton = moveButton;	}	public JScrollPane getScrollPane() {		return scrollPane;	}	public void setScrollPane(JScrollPane scrollPane) {		this.scrollPane = scrollPane;	}		public boolean isShowscrollbars() {		return showscrollbars;	}}

⌨️ 快捷键说明

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