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

📄 jchempainteditorpanel.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*  $RCSfile$ *  $Author: shk3 $ *  $Date: 2007-09-02 18:43:36 +0200 (Sun, 02 Sep 2007) $ *  $Revision: 8845 $ * *  Copyright (C) 1997-2007  The JChemPaint project * *  Contact: jchempaint-devel@lists.sourceforge.net * *  This program is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public License *  as published by the Free Software Foundation; either version 2.1 *  of the License, or (at your option) any later version. *  All we ask is that proper credit is given for our work, which includes *  - but is not limited to - adding the above copyright notice to the beginning *  of your source code files, and to any copyright notice that you may distribute *  with programs based on this work. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */package org.openscience.cdk.applications.jchempaint;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Graphics2D;import java.awt.Image;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.util.Calendar;import java.util.Enumeration;import java.util.EventObject;import java.util.HashMap;import java.util.Iterator;import java.util.StringTokenizer;import javax.swing.JFrame;import javax.swing.JScrollPane;import javax.swing.JToolBar;import javax.swing.JViewport;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.event.EventListenerList;import javax.vecmath.Point2d;import javax.vecmath.Vector2d;import org.openscience.cdk.Atom;import org.openscience.cdk.Bond;import org.openscience.cdk.ChemModel;import org.openscience.cdk.DefaultChemObjectBuilder;import org.openscience.cdk.PseudoAtom;import org.openscience.cdk.Reaction;import org.openscience.cdk.applications.jchempaint.dnd.JCPTransferHandler;import org.openscience.cdk.applications.undoredo.JCPUndoRedoHandler;import org.openscience.cdk.controller.PopupController2D;import org.openscience.cdk.dict.DictionaryDatabase;import org.openscience.cdk.event.ICDKChangeListener;import org.openscience.cdk.geometry.GeometryTools;import org.openscience.cdk.interfaces.IAtomContainer;import org.openscience.cdk.interfaces.IChemModel;import org.openscience.cdk.interfaces.IMoleculeSet;import org.openscience.cdk.renderer.Renderer2D;import org.openscience.cdk.renderer.Renderer2DModel;import org.openscience.cdk.smiles.SmilesParser;import org.openscience.cdk.tools.LoggingTool;import org.openscience.cdk.tools.manipulator.ChemModelManipulator;import org.openscience.cdk.tools.manipulator.MoleculeSetManipulator;import org.openscience.cdk.tools.manipulator.ReactionManipulator;import org.openscience.cdk.validate.BasicValidator;import org.openscience.cdk.validate.CDKValidator;import org.openscience.cdk.validate.DictionaryValidator;import org.openscience.cdk.validate.PDBValidator;import org.openscience.cdk.validate.ValencyValidator;import org.openscience.cdk.validate.ValidatorEngine;/** *  This class implements an editing JChemPaintPanel. * *@author        steinbeck *@cdk.created       16. Februar 2005 *@cdk.module    jchempaint *@see           JChemPaintViewerOnlyPanel */public class JChemPaintEditorPanel extends JChemPaintPanel		 implements ChangeListener, ICDKChangeListener{	private static final long serialVersionUID = -5369372292013788887L;	static String JCP_MODEL_CHANGED = "1";	static String JCP_CLOSING = "2";		String lastEventReason;			String recentSymbol = "C";	private static DictionaryDatabase dictdb = null;	private static ValidatorEngine engine = null;	private static LoggingTool logger;	boolean showMenuBar = true;	boolean showToolBar = true;	boolean showStatusBar = true;    boolean showInsertTextField = true;    protected EventListenerList changeListeners = null;    /**     *  Constructor for the panel     *     */    public JChemPaintEditorPanel(){    this(1, null);  }	public JChemPaintEditorPanel(int lines, Dimension panelDimension) {	    this(lines, panelDimension, false, "stable");	}    public JChemPaintEditorPanel(int lines, Dimension panelDimension, String guiString) {        this(lines, panelDimension, false, guiString);    }	/**	 *  Constructor for the panel	 *	 *@param  lines  How many lines should the horizontal toolbar have?	 */	public JChemPaintEditorPanel(int lines, Dimension panelDimension,                                  boolean isEmbedded, String guiString)	{		super();		if (isEmbedded == true) {		    this.setEmbedded();		}		this.guiString = guiString;        customizeView();        super.setJChemPaintModel(new JChemPaintModel(),null);		setShowToolBar(true, lines);		if(!guiString.equals("applet")){			setShowInsertTextField(true);					}        if (logger == null)		{			logger = new LoggingTool(this);		}		this.setTransferHandler(new JCPTransferHandler("JCPPanel"));		logger.debug("JCPPanel set and done...");		if (panelDimension != null && this.isEmbedded()) {			super.getJChemPaintModel().getRendererModel().setBackgroundDimension(panelDimension);			viewerDimension = new Dimension(((int) panelDimension.getWidth()) + 10, ((int) panelDimension.getHeight() + 10));			super.setPreferredSize(viewerDimension);		}	}	/**	 *  Tells if a menu is shown	 *	 *@return    The showMenu value	 */	public boolean getShowMenuBar() {		return showMenuBar;	}	/**	 *  Sets if a menu is shown	 *	 *@param  showMenuBar  The new showMenuBar value	 */	public void setShowMenuBar(boolean showMenuBar) {		this.showMenuBar = showMenuBar;		customizeView();	}	/**	 *  Tells if a status bar is shown	 *	 *@return    The showStatusBar value	 */	public boolean getShowStatusBar() {		return showStatusBar;	}    /**     * Indicates whether the insert text field is shown.     *     * @return true is the text field widget is to be shown, false otherwise     */    public boolean getShowInsertTextField() {        return showInsertTextField;    }	public void customizeView() {		if (showMenuBar) {			if (menu == null) {				menu = new JChemPaintMenuBar(this, this.guiString);			}			add(menu, BorderLayout.NORTH);			revalidate();		} else {			try {				remove(menu);				revalidate();			} catch (Exception exc) {               logger.debug("Error in removing menu");			}		}		if (showStatusBar) {			if (statusBar == null) {				statusBar = new StatusBar();			}			add(statusBar, BorderLayout.SOUTH);			revalidate();		} else {			try {				remove(statusBar);				revalidate();			} catch (Exception exc) {               logger.debug("Error in removing status bar");			}		}	}	void setupIfModelNotEmpty()	{		IAtomContainer ac = jchemPaintModel.getChemModel().getBuilder().newAtomContainer();		Iterator containers = ChemModelManipulator.getAllAtomContainers(jchemPaintModel.getChemModel()).iterator();		while (containers.hasNext()) ac.add((IAtomContainer)containers.next());		Renderer2DModel rendererModel = jchemPaintModel.getRendererModel();		if (ac.getAtomCount() != 0)		{			logger.info("ChemModel is already non-empty! Sizing things to get it visible!");			// do some magic to get it all in one page			Dimension oneMoleculeDimension = new Dimension(600, 400);			// should be based on molecule/reaction size!			Dimension dimension = makeChemModelFit(					oneMoleculeDimension, jchemPaintModel.getChemModel()					);			rendererModel.setBackgroundDimension(dimension);			/*			 *  this code ensures that the molecule ends up somewhere in the model			 *  of the view screen			 */			GeometryTools.translateAllPositive(ac,rendererModel.getRenderingCoordinates());			double scaleFactor = GeometryTools.getScaleFactor(ac, rendererModel.getBondLength(),jchemPaintModel.getRendererModel().getRenderingCoordinates());			GeometryTools.scaleMolecule(ac, scaleFactor,rendererModel.getRenderingCoordinates());			layoutInTable(oneMoleculeDimension, jchemPaintModel.getChemModel(),jchemPaintModel.getRendererModel());			// GeometryTools.center(ac, getPreferredSize());			// GeometryTools.center(ac, new Dimension(300,200));		}	}	public void registerModel(JChemPaintModel model)	{        String filename = "org/openscience/cdk/applications/jchempaint/resources/text/funcgroups.txt";        InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);                HashMap funcgroups=new HashMap();        SmilesParser sp=new SmilesParser(DefaultChemObjectBuilder.getInstance());		StringBuffer sb=new StringBuffer();		InputStreamReader isr = new InputStreamReader(ins);		try{			while(true){				int i=isr.read();				if(i==-1){					break;				}else if(((char)i)=='\n' || ((char)i)=='\r'){					if(!sb.toString().equals("")){						StringTokenizer st=new StringTokenizer(sb.toString());						String key=(String)st.nextElement();						String value=(String)st.nextElement();						funcgroups.put(key, sp.parseSmiles(value));						sb=new StringBuffer();					}				}else{					sb.append((char)i);				}			}			if(!sb.toString().equals("")){				StringTokenizer st=new StringTokenizer(sb.toString());				String key=(String)st.nextElement();				String value=(String)st.nextElement();				funcgroups.put(key, sp.parseSmiles(value));			}		}catch(Exception ex){			ex.printStackTrace();			logger.error("cannot instantiate funcgroupsmap",ex.getMessage());		}        		PopupController2D inputAdapter = new PopupController2D(model.getChemModel(), model.getRendererModel(),model.getControllerModel(), lastAction, this.moveButton, funcgroups);		JCPUndoRedoHandler undoRedoHandler=new JCPUndoRedoHandler(model.getControllerModel());		inputAdapter.setUndoRedoHandler(undoRedoHandler);		setupPopupMenus(inputAdapter);		Renderer2DModel rendererModel = model.getRendererModel();		model.getControllerModel().setBondPointerLength(rendererModel.getBondLength());		model.getControllerModel().setRingPointerLength(rendererModel.getBondLength());		model.getRendererModel().addCDKChangeListener(this);		inputAdapter.addCDKChangeListener(model);		//drawingPanel.setJChemPaintModel(model);		drawingPanel.addMouseListener(inputAdapter);		drawingPanel.addMouseMotionListener(inputAdapter);		//Somehow this registration does not work. If it would, element symbols could be changed via keyboard		drawingPanel.addKeyListener(inputAdapter);	}		/**	 *  Returns the value of showToolbar.	 *	 *@return    The showToolbar value	 */	public boolean getShowToolBar()	{		return showToolBar;	}			/**	 * Returns the value of lastEventReason.	 */	public String getLastEventReason()	{		return lastEventReason;	}	/**	 * Sets the value of lastEventReason.	 * @param lastEventReason The value to assign lastEventReason.	 */	public void setLastEventReason(String lastEventReason)	{		this.lastEventReason = lastEventReason;	}	/**	 *  Sets the value of showToolbar.	 *	 *@param  showToolBar  The value to assign showToolbar.	 */	public void setShowToolBar(boolean showToolBar)	{    setShowToolBar(showToolBar, 1);  }	/**	 *  Sets if statusbar should be shown	 *	 *@param  showStatusBar  The value to assign showStatusBar.	 */	public void setShowStatusBar(boolean showStatusBar) {		this.showStatusBar = showStatusBar;		customizeView();	}    /**     * Set to indicate whetehr the insert text field should be used.     *     * @param showInsertTextField true is the text entry widget is to be shown     */    public void setShowInsertTextField(boolean showInsertTextField) {        this.showInsertTextField = showInsertTextField;        if (showInsertTextField) {            if (insertTextPanel == null) insertTextPanel = new InsertTextPanel(this,null);            topContainer.add(insertTextPanel, BorderLayout.SOUTH);        } else {            topContainer.remove(insertTextPanel);        }        mainContainer.revalidate();    }    /**	 *  Sets the value of showToolbar.	 *	 *@param  showToolBar  The value to assign showToolbar.	 */    public void setShowToolBar(boolean showToolBar, int lines) {        this.showToolBar = showToolBar;        if (showToolBar) {            if (toolBar == null) {                toolBar = ToolBarMaker.getToolbar(this, lines);            }            topContainer.add(toolBar, BorderLayout.NORTH);            mainContainer.revalidate();        } else {            try {                topContainer.remove(toolBar);                mainContainer.revalidate();            } catch (Exception exc) {                logger.debug("Error in removing tool bar");            }        }    }	/**	 *  Overwrites the default background color and returns the color taken from	 *  the Renderer2DModel.	 *	 *@return    The background value	 */	public Color getBackground()	{

⌨️ 快捷键说明

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