From: <an...@us...> - 2009-12-19 20:53:37
|
Revision: 15213 http://cdk.svn.sourceforge.net/cdk/?rev=15213&view=rev Author: annulen Date: 2009-12-19 20:53:29 +0000 (Sat, 19 Dec 2009) Log Message: ----------- added menuTextMaker as member of AbstarctJChemPaintPanel Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPopupMenu.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java 2009-12-19 20:51:12 UTC (rev 15212) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java 2009-12-19 20:53:29 UTC (rev 15213) @@ -106,6 +106,7 @@ private static ILoggingTool logger = LoggingToolFactory.createLoggingTool(AbstractJChemPaintPanel.class); protected static String appTitle = ""; + protected JCPMenuTextMaker menuTextMaker = null; /** * @@ -170,24 +171,24 @@ * Update the menu bars and toolbars to current language. */ public void updateMenusWithLanguage() { - JCPMenuTextMaker.getInstance(guistring).init(guistring); + menuTextMaker.init(guistring); Iterator<String> it = buttons.keySet().iterator(); while(it.hasNext()){ String key = it.next(); JButton button = buttons.get(key); - button.setToolTipText(JCPMenuTextMaker.getInstance(guistring).getText(key + JCPAction.TIPSUFFIX)); + button.setToolTipText(menuTextMaker.getText(key + JCPAction.TIPSUFFIX)); } it = menus.keySet().iterator(); while(it.hasNext()){ String key = it.next(); JMenuItem button = menus.get(key); - button.setText(JCPMenuTextMaker.getInstance(guistring).getText(key)); + button.setText(menuTextMaker.getText(key)); } it = popupmenuitems.keySet().iterator(); while(it.hasNext()){ String key = it.next(); JChemPaintPopupMenu button = popupmenuitems.get(key); - ((JMenuItem)button.getComponent(0)).setText(JCPMenuTextMaker.getInstance(guistring).getText(key.substring(0,key.length()-5) + "MenuTitle")); + ((JMenuItem)button.getComponent(0)).setText(menuTextMaker.getText(key.substring(0,key.length()-5) + "MenuTitle")); } if(insertTextPanel!=null){ insertTextPanel.updateLanguage(); @@ -635,4 +636,8 @@ public boolean isModified() { return modified; } + + public JCPMenuTextMaker getMenuTextMaker() { + return menuTextMaker; + } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java 2009-12-19 20:51:12 UTC (rev 15212) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java 2009-12-19 20:53:29 UTC (rev 15213) @@ -157,6 +157,7 @@ } try { + // TODO: use getMenuTextMaker? String tip = JCPMenuTextMaker.getInstance("applet").getText(key + JCPAction.TIPSUFFIX); if (tip != null) { Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java 2009-12-19 20:51:12 UTC (rev 15212) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java 2009-12-19 20:53:29 UTC (rev 15213) @@ -89,7 +89,7 @@ */ protected JComponent createMenu(AbstractJChemPaintPanel jcpPanel, String key, boolean isPopup, String guiString) { logger.debug("Creating menu: ", key); - JMenu menu = new JMenu(JCPMenuTextMaker.getInstance(jcpPanel.getGuistring()).getText(key)); + JMenu menu = new JMenu(jcpPanel.getMenuTextMaker().getText(key)); menu.setName(key); return createMenu(jcpPanel, key, isPopup, guiString, menu); } @@ -225,7 +225,7 @@ } String translation = "***" + cmd + "***"; try { - translation = JCPMenuTextMaker.getInstance(jcpPanel.getGuistring()).getText(cmd); + translation = jcpPanel.getMenuTextMaker().getText(cmd); logger.debug("Found translation: ", translation); } catch (MissingResourceException mre) { logger.error("Could not find translation for: " + cmd); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2009-12-19 20:51:12 UTC (rev 15212) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2009-12-19 20:53:29 UTC (rev 15213) @@ -5,6 +5,7 @@ * $Revision: 7634 $ * * Copyright (C) 1997-2008 Stefan Kuhn + * Some portions Copyright (C) 2009 Konstantin Tokarev * * Contact: cdk...@li... * @@ -49,6 +50,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.TransferHandler; import org.openscience.cdk.Atom; import org.openscience.cdk.Bond; @@ -78,7 +80,11 @@ private static final long serialVersionUID = 7810772571955039160L; public static List<JChemPaintPanel> instances = new ArrayList<JChemPaintPanel>(); private String lastSelectId; + TransferHandler th; + public JChemPaintPanel() { + } + /** * Builds a JCPPanel with a certain model and a certain gui * @@ -89,16 +95,25 @@ */ public JChemPaintPanel(IChemModel chemModel, String gui, boolean debug) { this.guistring = gui; + menuTextMaker = JCPMenuTextMaker.getInstance(guistring); this.debug = debug; - this.setLayout(new BorderLayout()); - topContainer = new JPanel(new BorderLayout()); - topContainer.setLayout(new BorderLayout()); - this.add(topContainer, BorderLayout.NORTH); try { renderPanel = new RenderPanel(chemModel, getWidth(), getHeight(), false, debug); } catch (IOException e) { announceError(e); } + if (gui.equals("stable")) { + setAppTitle(" - JChemPaint"); + } + init(); + } + + protected void init() { + this.setLayout(new BorderLayout()); + topContainer = new JPanel(new BorderLayout()); + topContainer.setLayout(new BorderLayout()); + this.add(topContainer, BorderLayout.NORTH); + renderPanel.getHub().addChangeModeListener(this); renderPanel.setName("renderpanel"); centerContainer=new JPanel(); @@ -126,11 +141,9 @@ JChemPaintPanel.this.get2DHub().updateView(); } }); - if (gui.equals("stable")) { - setAppTitle(" - JChemPaint"); - } + th = renderPanel.getTransferHandler(); } - + public void setTitle(String title) { Container topLevelContainer = this.getTopLevelContainer(); if (topLevelContainer instanceof JFrame) { @@ -369,5 +382,53 @@ } return allinone; } + + /** + * Drag&Drop support + * + *@author Konstantin Tokarev + * + */ + /*private TransferHandler handler = new TransferHandler() { + public boolean canImport(TransferHandler.TransferSupport support) { + if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { + return false; + } + if (copyItem.isSelected()) { + boolean copySupported = (COPY & support.getSourceDropActions()) == COPY; + + if (!copySupported) { + return false; + } + + support.setDropAction(COPY); + } + + return true; + } + + public boolean importData(TransferHandler.TransferSupport support) { + if (!canImport(support)) { + return false; + } + + Transferable t = support.getTransferable(); + + try { + java.util.List<File> l = + (java.util.List<File>)t.getTransferData(DataFlavor.javaFileListFlavor); + + for (File f : l) { + new Doc(f); + } + } catch (UnsupportedFlavorException e) { + return false; + } catch (IOException e) { + return false; + } + + return true; + } + };*/ } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPopupMenu.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPopupMenu.java 2009-12-19 20:51:12 UTC (rev 15212) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPopupMenu.java 2009-12-19 20:53:29 UTC (rev 15213) @@ -61,7 +61,7 @@ */ JChemPaintPopupMenu(JChemPaintPanel jcpPanel, String type, String guiString) { - String menuTitle = JCPMenuTextMaker.getInstance(jcpPanel.getGuistring()).getText(type + "MenuTitle"); + String menuTitle = jcpPanel.getMenuTextMaker().getText(type + "MenuTitle"); JMenuItem titleMenuItem = new JMenuItem(menuTitle); titleMenuItem.setEnabled(false); titleMenuItem.setArmed(false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2009-12-22 12:33:58
|
Revision: 15221 http://cdk.svn.sourceforge.net/cdk/?rev=15221&view=rev Author: mark_rynbeek Date: 2009-12-22 12:33:51 +0000 (Tue, 22 Dec 2009) Log Message: ----------- Added PAHs to template menu bar Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_stable.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2009-12-22 12:13:26 UTC (rev 15220) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2009-12-22 12:33:51 UTC (rev 15221) @@ -42,264 +42,264 @@ * */ public class JCPMenuTextMaker { - private static JCPMenuTextMaker instance=null; - protected Map<String,String> entries=new HashMap<String,String>(); - - /** - * The constructor. Protected since class is a singleton. - */ - protected JCPMenuTextMaker(String guistring){ - init(guistring); - } - - public void init(String guistring){ - entries.clear(); - entries.put("file", GT._("File")); - entries.put("new", GT._("New")); - entries.put("atomMenuTitle", GT._("Atom Popup Menu")); - entries.put("pseudoMenuTitle", GT._("Pseudo Atom Popup Menu")); - entries.put("open", GT._("Open")); - entries.put("saveAs", GT._("Save As...")); - entries.put("view", GT._("View")); - entries.put("print", GT._("Print...")); - entries.put("export", GT._("Save As Image...")); - entries.put("save", GT._("Save")); - entries.put("edit", GT._("Edit")); - entries.put("report", GT._("Report")); - entries.put("close", GT._("Close")); - entries.put("exit", GT._("Exit")); - entries.put("undo", GT._("Undo")); - entries.put("redo", GT._("Redo")); - entries.put("selectAll", GT._("Select All")); - entries.put("copy", GT._("Copy")); - entries.put("copyAsSmiles", GT._("Copy As SMILES")); - entries.put("eraser", GT._("Delete")); - entries.put("paste", GT._("Paste")); - entries.put("pasteTemplate", GT._("All Templates")); - entries.put("cut", GT._("Cut")); - entries.put("atomMenu", GT._("Atom")); - entries.put("bondMenu", GT._("Bond")); - entries.put("tools", GT._("Tools")); - entries.put("templates", GT._("Templates")); - entries.put("radical", GT._("Radical")); - entries.put("bond", GT._("Single")); - entries.put("double_bond", GT._("Double")); - entries.put("triple_bond", GT._("Triple")); - entries.put("quad_bond", GT._("Quadruple")); - entries.put("down_bond", GT._("Stereo Down")); - entries.put("up_bond", GT._("Stereo Up")); - entries.put("undefined_bond", GT._("Undefined Stereo")); - entries.put("undefined_stereo_bond", GT._("Undefined E/Z")); - entries.put("formalCharge", GT._("Charge")); - entries.put("plus", GT._("Plus")); - entries.put("minus", GT._("Minus")); - entries.put("hydrogen", GT._("Implicit Hydrogens")); - entries.put("flip", GT._("Flip")); - entries.put("cleanup", GT._("Clean Structure")); - entries.put("toolbar", GT._("Toolbar")); - entries.put("statusbar", GT._("Statusbar")); - entries.put("menubar", GT._("Menubar")); - entries.put("insertstructure", GT._("Direct Entry as SMILES/InChI/CAS")); - entries.put("zoomin", GT._("Zoom In")); - entries.put("zoomout", GT._("Zoom Out")); - entries.put("zoomoriginal", GT._("Zoom 100%")); - entries.put("options", GT._("Preferences...")); - entries.put("createSMILES", GT._("Create SMILES")); - entries.put("createInChI", GT._("Create InChI")); - entries.put("help", GT._("Help")); - entries.put("tutorial", GT._("Tutorial")); - entries.put("feedback", GT._("Report Feedback")); - entries.put("license", GT._("License")); - entries.put("about", GT._("About")); - entries.put("hydroon", GT._("On All")); - entries.put("hydrooff", GT._("Off")); - entries.put("flipHorizontal", GT._("Horizontal")); - entries.put("flipVertical", GT._("Vertical")); - entries.put("selectFromChemObject", GT._("Select")); - entries.put("symbolChange", GT._("Change Element")); - entries.put("periodictable", GT._("Periodic Table")); - entries.put("enterelement", GT._("Custom")); - entries.put("isotopeChange", GT._("Isotopes")); - entries.put("convertToRadical", GT._("Add Electron Pair")); - entries.put("convertFromRadical", GT._("Remove Electron Pair")); - entries.put("showChemObjectProperties", GT._("Properties")); - entries.put("showACProperties", GT._("Molecule Properties")); - entries.put("makeNormal", GT._("Convert to Regular Atom")); - entries.put("commonSymbols", GT._("Common Elements")); - entries.put("halogenSymbols", GT._("Halogens")); - entries.put("nobelSymbols", GT._("Nobel Gases")); - entries.put("alkaliMetals", GT._("Alkali Metals")); - entries.put("alkaliEarthMetals", GT._("Alkali Earth Metals")); - entries.put("transitionMetals", GT._("Transition Metals")); - entries.put("metals", GT._("Metals")); - entries.put("metalloids", GT._("Metalloids")); - entries.put("Transition m", GT._("Non-Metals")); - entries.put("pseudoSymbols", GT._("Pseudo Atoms")); - entries.put("majorPlusThree", GT._("Major Plus {0}","3")); - entries.put("majorPlusTwo", GT._("Major Plus {0}","2")); - entries.put("majorPlusOne", GT._("Major Plus {0}","1")); - entries.put("major", GT._("Major Isotope")); - entries.put("majorMinusOne", GT._("Major Minus {0}","1")); - entries.put("majorMinusTwo", GT._("Major Minus {0}","2")); - entries.put("majorMinusThree", GT._("Major Minus {0}","3")); - entries.put("valence", GT._("Valence")); - entries.put("valenceOff", GT._("Valence Off")); - entries.put("valence1", GT._("Valence {0}","1")); - entries.put("valence2", GT._("Valence {0}","2")); - entries.put("valence3", GT._("Valence {0}","3")); - entries.put("valence4", GT._("Valence {0}","4")); - entries.put("valence5", GT._("Valence {0}","5")); - entries.put("valence6", GT._("Valence {0}","6")); - entries.put("valence7", GT._("Valence {0}","7")); - entries.put("valence8", GT._("Valence {0}","8")); - entries.put("symbolC", GT._("C")); - entries.put("symbolO", GT._("O")); - entries.put("symbolN", GT._("N")); - entries.put("symbolH", GT._("H")); - entries.put("symbolP", GT._("P")); - entries.put("symbolS", GT._("S")); - entries.put("symbolF", GT._("F")); - entries.put("symbolCl", GT._("Cl")); - entries.put("symbolBr", GT._("Br")); - entries.put("symbolI", GT._("I")); - entries.put("symbolHe", GT._("He")); - entries.put("symbolNe", GT._("Ne")); - entries.put("symbolAr", GT._("Ar")); - entries.put("symbolB", GT._("B")); - entries.put("symbolP", GT._("P")); - entries.put("symbolLi", GT._("Li")); - entries.put("symbolBe", GT._("Be")); - entries.put("symbolNa", GT._("Na")); - entries.put("symbolMg", GT._("Mg")); - entries.put("symbolAl", GT._("Al")); - entries.put("symbolSi", GT._("Si")); - entries.put("symbolFe", GT._("Fe")); - entries.put("symbolCo", GT._("Co")); - entries.put("symbolAg", GT._("Ag")); - entries.put("symbolPt", GT._("Pt")); - entries.put("symbolAu", GT._("Au")); - entries.put("symbolHg", GT._("Hg")); - entries.put("symbolCu", GT._("Cu")); - entries.put("symbolNi", GT._("Ni")); - entries.put("symbolZn", GT._("Zn")); - entries.put("symbolSn", GT._("Sn")); - entries.put("symbolK", GT._("K")); - entries.put("symbolRb", GT._("Rb")); - entries.put("symbolCs", GT._("Cs")); - entries.put("symbolFr", GT._("Fr")); - entries.put("symbolCa", GT._("Ca")); - entries.put("symbolSr", GT._("Sr")); - entries.put("symbolBa", GT._("Ba")); - entries.put("symbolRa", GT._("Ra")); - entries.put("symbolSc", GT._("Sc")); - entries.put("symbolTi", GT._("Ti")); - entries.put("symbolV", GT._("V")); - entries.put("symbolCr", GT._("Cr")); - entries.put("symbolMn", GT._("Mn")); - entries.put("symbolY", GT._("Y")); - entries.put("symbolZr", GT._("Zr")); - entries.put("symbolNb", GT._("Nb")); - entries.put("symbolMo", GT._("Mo")); - entries.put("symbolTc", GT._("Tc")); - entries.put("symbolRu", GT._("Ru")); - entries.put("symbolRh", GT._("Rh")); - entries.put("symbolPd", GT._("Pd")); - entries.put("symbolCd", GT._("Cd")); - entries.put("symbolHf", GT._("Hf")); - entries.put("symbolTa", GT._("Ta")); - entries.put("symbolW", GT._("W")); - entries.put("symbolRe", GT._("Re")); - entries.put("symbolOs", GT._("Os")); - entries.put("symbolIr", GT._("Ir")); - entries.put("symbolRf", GT._("Rf")); - entries.put("symbolDb", GT._("Db")); - entries.put("symbolSg", GT._("Sg")); - entries.put("symbolBh", GT._("Bh")); - entries.put("symbolHs", GT._("Hs")); - entries.put("symbolMt", GT._("Mt")); - entries.put("symbolDs", GT._("Ds")); - entries.put("symbolRg", GT._("Rg")); - entries.put("symbolGa", GT._("Ga")); - entries.put("symbolIn", GT._("In")); - entries.put("symbolTl", GT._("Tl")); - entries.put("symbolPb", GT._("Pb")); - entries.put("symbolBi", GT._("Bi")); - entries.put("symbolGe", GT._("Ge")); - entries.put("symbolAs", GT._("As")); - entries.put("symbolSb", GT._("Sb")); - entries.put("symbolTe", GT._("Te")); - entries.put("symbolPo", GT._("Po")); - entries.put("pseudoStar", GT._("Variable Attachment Point *")); - entries.put("pseudoR", GT._("R")); - entries.put("pseudoRX", GT._("R..")); - entries.put("pseudoR1", GT._("R1")); - entries.put("pseudoR2", GT._("R2")); - entries.put("pseudoR3", GT._("R3")); - entries.put("pseudoR4", GT._("R4")); - entries.put("bondTooltip", GT._("Draw Bonds and Atoms")); - entries.put("cyclesymbolTooltip", GT._("Change the Atom's Symbol")); - entries.put("periodictableTooltip", GT._("Select new drawing symbol from periodic table")); - entries.put("enterelementTooltip", GT._("Enter an element symbol via keyboard")); - entries.put("up_bondTooltip", GT._("Make the Bonds Stereo Up")); - entries.put("down_bondTooltip", GT._("Make the Bonds Stereo Down")); - entries.put("plusTooltip", GT._("Increase the charge on an Atom")); - entries.put("minusTooltip", GT._("Decrease the charge on an Atom")); - entries.put("eraserTooltip", GT._("Delete atoms and bonds")); - entries.put("lassoTooltip", GT._("Select atoms and bonds in a free-form region")); - entries.put("selectTooltip", GT._("Select atoms and bonds in a rectangular region")); - entries.put("triangleTooltip", GT._("Add a propane ring")); - entries.put("squareTooltip", GT._("Add a butane ring")); - entries.put("pentagonTooltip", GT._("Add a pentane ring")); - entries.put("hexagonTooltip", GT._("Add a hexane ring")); - entries.put("heptagonTooltip", GT._("Add a heptane ring")); - entries.put("octagonTooltip", GT._("Add a octane ring")); - entries.put("benzeneTooltip", GT._("Add a benzene ring")); - entries.put("cleanupTooltip", GT._("Relayout the structures")); - if(guistring.equals(JChemPaintEditorApplet.GUI_APPLET)) - entries.put("newTooltip", GT._("Clear")); - else + private static JCPMenuTextMaker instance=null; + protected Map<String,String> entries=new HashMap<String,String>(); + + /** + * The constructor. Protected since class is a singleton. + */ + protected JCPMenuTextMaker(String guistring){ + init(guistring); + } + + public void init(String guistring){ + entries.clear(); + entries.put("file", GT._("File")); + entries.put("new", GT._("New")); + entries.put("atomMenuTitle", GT._("Atom Popup Menu")); + entries.put("pseudoMenuTitle", GT._("Pseudo Atom Popup Menu")); + entries.put("open", GT._("Open")); + entries.put("saveAs", GT._("Save As...")); + entries.put("view", GT._("View")); + entries.put("print", GT._("Print...")); + entries.put("export", GT._("Save As Image...")); + entries.put("save", GT._("Save")); + entries.put("edit", GT._("Edit")); + entries.put("report", GT._("Report")); + entries.put("close", GT._("Close")); + entries.put("exit", GT._("Exit")); + entries.put("undo", GT._("Undo")); + entries.put("redo", GT._("Redo")); + entries.put("selectAll", GT._("Select All")); + entries.put("copy", GT._("Copy")); + entries.put("copyAsSmiles", GT._("Copy As SMILES")); + entries.put("eraser", GT._("Delete")); + entries.put("paste", GT._("Paste")); + entries.put("pasteTemplate", GT._("All Templates")); + entries.put("cut", GT._("Cut")); + entries.put("atomMenu", GT._("Atom")); + entries.put("bondMenu", GT._("Bond")); + entries.put("tools", GT._("Tools")); + entries.put("templates", GT._("Templates")); + entries.put("radical", GT._("Radical")); + entries.put("bond", GT._("Single")); + entries.put("double_bond", GT._("Double")); + entries.put("triple_bond", GT._("Triple")); + entries.put("quad_bond", GT._("Quadruple")); + entries.put("down_bond", GT._("Stereo Down")); + entries.put("up_bond", GT._("Stereo Up")); + entries.put("undefined_bond", GT._("Undefined Stereo")); + entries.put("undefined_stereo_bond", GT._("Undefined E/Z")); + entries.put("formalCharge", GT._("Charge")); + entries.put("plus", GT._("Plus")); + entries.put("minus", GT._("Minus")); + entries.put("hydrogen", GT._("Implicit Hydrogens")); + entries.put("flip", GT._("Flip")); + entries.put("cleanup", GT._("Clean Structure")); + entries.put("toolbar", GT._("Toolbar")); + entries.put("statusbar", GT._("Statusbar")); + entries.put("menubar", GT._("Menubar")); + entries.put("insertstructure", GT._("Direct Entry as SMILES/InChI/CAS")); + entries.put("zoomin", GT._("Zoom In")); + entries.put("zoomout", GT._("Zoom Out")); + entries.put("zoomoriginal", GT._("Zoom 100%")); + entries.put("options", GT._("Preferences...")); + entries.put("createSMILES", GT._("Create SMILES")); + entries.put("createInChI", GT._("Create InChI")); + entries.put("help", GT._("Help")); + entries.put("tutorial", GT._("Tutorial")); + entries.put("feedback", GT._("Report Feedback")); + entries.put("license", GT._("License")); + entries.put("about", GT._("About")); + entries.put("hydroon", GT._("On All")); + entries.put("hydrooff", GT._("Off")); + entries.put("flipHorizontal", GT._("Horizontal")); + entries.put("flipVertical", GT._("Vertical")); + entries.put("selectFromChemObject", GT._("Select")); + entries.put("symbolChange", GT._("Change Element")); + entries.put("periodictable", GT._("Periodic Table")); + entries.put("enterelement", GT._("Custom")); + entries.put("isotopeChange", GT._("Isotopes")); + entries.put("convertToRadical", GT._("Add Electron Pair")); + entries.put("convertFromRadical", GT._("Remove Electron Pair")); + entries.put("showChemObjectProperties", GT._("Properties")); + entries.put("showACProperties", GT._("Molecule Properties")); + entries.put("makeNormal", GT._("Convert to Regular Atom")); + entries.put("commonSymbols", GT._("Common Elements")); + entries.put("halogenSymbols", GT._("Halogens")); + entries.put("nobelSymbols", GT._("Nobel Gases")); + entries.put("alkaliMetals", GT._("Alkali Metals")); + entries.put("alkaliEarthMetals", GT._("Alkali Earth Metals")); + entries.put("transitionMetals", GT._("Transition Metals")); + entries.put("metals", GT._("Metals")); + entries.put("metalloids", GT._("Metalloids")); + entries.put("Transition m", GT._("Non-Metals")); + entries.put("pseudoSymbols", GT._("Pseudo Atoms")); + entries.put("majorPlusThree", GT._("Major Plus {0}","3")); + entries.put("majorPlusTwo", GT._("Major Plus {0}","2")); + entries.put("majorPlusOne", GT._("Major Plus {0}","1")); + entries.put("major", GT._("Major Isotope")); + entries.put("majorMinusOne", GT._("Major Minus {0}","1")); + entries.put("majorMinusTwo", GT._("Major Minus {0}","2")); + entries.put("majorMinusThree", GT._("Major Minus {0}","3")); + entries.put("valence", GT._("Valence")); + entries.put("valenceOff", GT._("Valence Off")); + entries.put("valence1", GT._("Valence {0}","1")); + entries.put("valence2", GT._("Valence {0}","2")); + entries.put("valence3", GT._("Valence {0}","3")); + entries.put("valence4", GT._("Valence {0}","4")); + entries.put("valence5", GT._("Valence {0}","5")); + entries.put("valence6", GT._("Valence {0}","6")); + entries.put("valence7", GT._("Valence {0}","7")); + entries.put("valence8", GT._("Valence {0}","8")); + entries.put("symbolC", GT._("C")); + entries.put("symbolO", GT._("O")); + entries.put("symbolN", GT._("N")); + entries.put("symbolH", GT._("H")); + entries.put("symbolP", GT._("P")); + entries.put("symbolS", GT._("S")); + entries.put("symbolF", GT._("F")); + entries.put("symbolCl", GT._("Cl")); + entries.put("symbolBr", GT._("Br")); + entries.put("symbolI", GT._("I")); + entries.put("symbolHe", GT._("He")); + entries.put("symbolNe", GT._("Ne")); + entries.put("symbolAr", GT._("Ar")); + entries.put("symbolB", GT._("B")); + entries.put("symbolP", GT._("P")); + entries.put("symbolLi", GT._("Li")); + entries.put("symbolBe", GT._("Be")); + entries.put("symbolNa", GT._("Na")); + entries.put("symbolMg", GT._("Mg")); + entries.put("symbolAl", GT._("Al")); + entries.put("symbolSi", GT._("Si")); + entries.put("symbolFe", GT._("Fe")); + entries.put("symbolCo", GT._("Co")); + entries.put("symbolAg", GT._("Ag")); + entries.put("symbolPt", GT._("Pt")); + entries.put("symbolAu", GT._("Au")); + entries.put("symbolHg", GT._("Hg")); + entries.put("symbolCu", GT._("Cu")); + entries.put("symbolNi", GT._("Ni")); + entries.put("symbolZn", GT._("Zn")); + entries.put("symbolSn", GT._("Sn")); + entries.put("symbolK", GT._("K")); + entries.put("symbolRb", GT._("Rb")); + entries.put("symbolCs", GT._("Cs")); + entries.put("symbolFr", GT._("Fr")); + entries.put("symbolCa", GT._("Ca")); + entries.put("symbolSr", GT._("Sr")); + entries.put("symbolBa", GT._("Ba")); + entries.put("symbolRa", GT._("Ra")); + entries.put("symbolSc", GT._("Sc")); + entries.put("symbolTi", GT._("Ti")); + entries.put("symbolV", GT._("V")); + entries.put("symbolCr", GT._("Cr")); + entries.put("symbolMn", GT._("Mn")); + entries.put("symbolY", GT._("Y")); + entries.put("symbolZr", GT._("Zr")); + entries.put("symbolNb", GT._("Nb")); + entries.put("symbolMo", GT._("Mo")); + entries.put("symbolTc", GT._("Tc")); + entries.put("symbolRu", GT._("Ru")); + entries.put("symbolRh", GT._("Rh")); + entries.put("symbolPd", GT._("Pd")); + entries.put("symbolCd", GT._("Cd")); + entries.put("symbolHf", GT._("Hf")); + entries.put("symbolTa", GT._("Ta")); + entries.put("symbolW", GT._("W")); + entries.put("symbolRe", GT._("Re")); + entries.put("symbolOs", GT._("Os")); + entries.put("symbolIr", GT._("Ir")); + entries.put("symbolRf", GT._("Rf")); + entries.put("symbolDb", GT._("Db")); + entries.put("symbolSg", GT._("Sg")); + entries.put("symbolBh", GT._("Bh")); + entries.put("symbolHs", GT._("Hs")); + entries.put("symbolMt", GT._("Mt")); + entries.put("symbolDs", GT._("Ds")); + entries.put("symbolRg", GT._("Rg")); + entries.put("symbolGa", GT._("Ga")); + entries.put("symbolIn", GT._("In")); + entries.put("symbolTl", GT._("Tl")); + entries.put("symbolPb", GT._("Pb")); + entries.put("symbolBi", GT._("Bi")); + entries.put("symbolGe", GT._("Ge")); + entries.put("symbolAs", GT._("As")); + entries.put("symbolSb", GT._("Sb")); + entries.put("symbolTe", GT._("Te")); + entries.put("symbolPo", GT._("Po")); + entries.put("pseudoStar", GT._("Variable Attachment Point *")); + entries.put("pseudoR", GT._("R")); + entries.put("pseudoRX", GT._("R..")); + entries.put("pseudoR1", GT._("R1")); + entries.put("pseudoR2", GT._("R2")); + entries.put("pseudoR3", GT._("R3")); + entries.put("pseudoR4", GT._("R4")); + entries.put("bondTooltip", GT._("Draw Bonds and Atoms")); + entries.put("cyclesymbolTooltip", GT._("Change the Atom's Symbol")); + entries.put("periodictableTooltip", GT._("Select new drawing symbol from periodic table")); + entries.put("enterelementTooltip", GT._("Enter an element symbol via keyboard")); + entries.put("up_bondTooltip", GT._("Make the Bonds Stereo Up")); + entries.put("down_bondTooltip", GT._("Make the Bonds Stereo Down")); + entries.put("plusTooltip", GT._("Increase the charge on an Atom")); + entries.put("minusTooltip", GT._("Decrease the charge on an Atom")); + entries.put("eraserTooltip", GT._("Delete atoms and bonds")); + entries.put("lassoTooltip", GT._("Select atoms and bonds in a free-form region")); + entries.put("selectTooltip", GT._("Select atoms and bonds in a rectangular region")); + entries.put("triangleTooltip", GT._("Add a propane ring")); + entries.put("squareTooltip", GT._("Add a butane ring")); + entries.put("pentagonTooltip", GT._("Add a pentane ring")); + entries.put("hexagonTooltip", GT._("Add a hexane ring")); + entries.put("heptagonTooltip", GT._("Add a heptane ring")); + entries.put("octagonTooltip", GT._("Add a octane ring")); + entries.put("benzeneTooltip", GT._("Add a benzene ring")); + entries.put("cleanupTooltip", GT._("Relayout the structures")); + if(guistring.equals(JChemPaintEditorApplet.GUI_APPLET)) + entries.put("newTooltip", GT._("Clear")); + else entries.put("newTooltip", GT._("Create new file")); entries.put("openTooltip", GT._("Open existing file")); entries.put("saveTooltip", GT._("Save current file")); entries.put("printTooltip", GT._("Print current file")); - entries.put("redoTooltip", GT._("Redo Action")); - entries.put("saveAsTooltip", GT._("Save to a file")); - entries.put("undoTooltip", GT._("Undo Action")); - entries.put("zoominTooltip", GT._("Zoom in")); - entries.put("zoomoutTooltip", GT._("Zoom out")); - entries.put("undefined_bondTooltip", GT._("Stereo up or stereo down bond")); - entries.put("undefined_stereo_bondTooltip", GT._("Any stereo bond")); - entries.put("rotateTooltip", GT._("Rotate selection")); + entries.put("redoTooltip", GT._("Redo Action")); + entries.put("saveAsTooltip", GT._("Save to a file")); + entries.put("undoTooltip", GT._("Undo Action")); + entries.put("zoominTooltip", GT._("Zoom in")); + entries.put("zoomoutTooltip", GT._("Zoom out")); + entries.put("undefined_bondTooltip", GT._("Stereo up or stereo down bond")); + entries.put("undefined_stereo_bondTooltip", GT._("Any stereo bond")); + entries.put("rotateTooltip", GT._("Rotate selection")); entries.put("rotate3dTooltip", GT._("Rotate selection in space")); - entries.put("cutTooltip", GT._("Cut selection")); - entries.put("copyTooltip", GT._("Copy selection to clipboard")); - entries.put("pasteTooltip", GT._("Paste from clipboard")); - entries.put("flipVerticalTooltip", GT._("Flip vertical")); - entries.put("flipHorizontalTooltip", GT._("Flip horizontal")); - entries.put("pasteTemplateTooltip", GT._("Choose from complex templates")); - entries.put("bondMenuTitle", GT._(" Menu")); - entries.put("chemmodelMenuTitle", GT._("ChemModel Popup Menu")); - entries.put("Enter Element or Group", GT._("Enter Element or Group")); - entries.put("Add Atom Or Change Element", GT._("Add Atom Or Change Element")); - entries.put("Draw Bond", GT._("Draw Bond")); - entries.put("Ring 3", GT._("Ring {0}","3")); - entries.put("Ring 4", GT._("Ring {0}","4")); - entries.put("Ring 5", GT._("Ring {0}","5")); - entries.put("Ring 6", GT._("Ring {0}","6")); - entries.put("Ring 7", GT._("Ring {0}","7")); - entries.put("Ring 8", GT._("Ring {0}","8")); - entries.put("Add or convert to bond up", GT._("Add or convert to bond up")); - entries.put("Add or convert to bond down", GT._("Add or convert to bond down")); - entries.put("Decrease Charge", GT._("Decrease Charge")); - entries.put("Increase Charge", GT._("Increase Charge")); - entries.put("Cycle Symbol", GT._("Cyclic change of symbol")); - entries.put("Delete", GT._("Delete")); - entries.put("Move", GT._("Move")); + entries.put("cutTooltip", GT._("Cut selection")); + entries.put("copyTooltip", GT._("Copy selection to clipboard")); + entries.put("pasteTooltip", GT._("Paste from clipboard")); + entries.put("flipVerticalTooltip", GT._("Flip vertical")); + entries.put("flipHorizontalTooltip", GT._("Flip horizontal")); + entries.put("pasteTemplateTooltip", GT._("Choose from complex templates")); + entries.put("bondMenuTitle", GT._(" Menu")); + entries.put("chemmodelMenuTitle", GT._("ChemModel Popup Menu")); + entries.put("Enter Element or Group", GT._("Enter Element or Group")); + entries.put("Add Atom Or Change Element", GT._("Add Atom Or Change Element")); + entries.put("Draw Bond", GT._("Draw Bond")); + entries.put("Ring 3", GT._("Ring {0}","3")); + entries.put("Ring 4", GT._("Ring {0}","4")); + entries.put("Ring 5", GT._("Ring {0}","5")); + entries.put("Ring 6", GT._("Ring {0}","6")); + entries.put("Ring 7", GT._("Ring {0}","7")); + entries.put("Ring 8", GT._("Ring {0}","8")); + entries.put("Add or convert to bond up", GT._("Add or convert to bond up")); + entries.put("Add or convert to bond down", GT._("Add or convert to bond down")); + entries.put("Decrease Charge", GT._("Decrease Charge")); + entries.put("Increase Charge", GT._("Increase Charge")); + entries.put("Cycle Symbol", GT._("Cyclic change of symbol")); + entries.put("Delete", GT._("Delete")); + entries.put("Move", GT._("Move")); entries.put("Rotate", GT._("Rotate")); entries.put("Rotate in space", GT._("Rotate in space")); - entries.put("Benzene", GT._("Benzene")); - entries.put("Select in Free Form", GT._("Select in Free Form")); - entries.put("Select Square", GT._("Select Rectangle")); + entries.put("Benzene", GT._("Benzene")); + entries.put("Select in Free Form", GT._("Select in Free Form")); + entries.put("Select Square", GT._("Select Rectangle")); entries.put("CTooltip", GT._("Change drawing symbol to {0}", "C")); entries.put("HTooltip", GT._("Change drawing symbol to {0}", "H")); entries.put("OTooltip", GT._("Change drawing symbol to {0}", "O")); @@ -327,31 +327,32 @@ entries.put("nucleosides", GT._("Nucleosides")); entries.put("porphyrins", GT._("Porphyrins")); entries.put("steroids", GT._("Steroids")); + entries.put("pahs", GT._("PAHs")); entries.put("language", GT._("Language")); } - - /** - * Gives the text for an item. - * - * @param key The key for the text - * @return The text in current language - */ - public String getText(String key){ - if(entries.get(key)==null) - return key; - else - return entries.get(key); - } - - /** - * Gives an instance of JCPMenuTextMaker. - * - * @return The instance - */ - public static JCPMenuTextMaker getInstance(String guistring){ - if(instance==null){ - instance=new JCPMenuTextMaker(guistring); - } - return instance; - } + + /** + * Gives the text for an item. + * + * @param key The key for the text + * @return The text in current language + */ + public String getText(String key){ + if(entries.get(key)==null) + return key; + else + return entries.get(key); + } + + /** + * Gives an instance of JCPMenuTextMaker. + * + * @return The instance + */ + public static JCPMenuTextMaker getInstance(String guistring){ + if(instance==null){ + instance=new JCPMenuTextMaker(guistring); + } + return instance; + } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties 2009-12-22 12:13:26 UTC (rev 15220) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties 2009-12-22 12:33:51 UTC (rev 15221) @@ -51,7 +51,7 @@ tools=cleanup - createSMILES createInChI help=help tutorial - feedback about license templates=pasteTemplate - alkaloids beta_lactams carbohydrates inositols \ - lipids nucleosides porphyrins steroids miscellaneous + lipids nucleosides porphyrins steroids pahs miscellaneous hydrogen=hydroon hydrooff language= Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_stable.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_stable.properties 2009-12-22 12:13:26 UTC (rev 15220) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_stable.properties 2009-12-22 12:33:51 UTC (rev 15221) @@ -62,7 +62,7 @@ tools=cleanup - createSMILES createInChI help=help tutorial - feedback about license templates=pasteTemplate - alkaloids beta_lactams carbohydrates inositols \ - lipids nucleosides porphyrins steroids miscellaneous + lipids nucleosides porphyrins steroids pahs miscellaneous hydrogen=hydroon hydrooff language= Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2009-12-22 12:13:26 UTC (rev 15220) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2009-12-22 12:33:51 UTC (rev 15221) @@ -270,6 +270,7 @@ porphyrinsAction=org.openscience.jchempaint.action.CopyPasteAction@pasteTemplate_Porphyrins steroidsAction=org.openscience.jchempaint.action.CopyPasteAction@pasteTemplate_Steroids beta_lactamsAction=org.openscience.jchempaint.action.CopyPasteAction@pasteTemplate_Beta_Lactams +pahsAction=org.openscience.jchempaint.action.CopyPasteAction@pasteTemplate_PAHs # Help menu helpAction=org.openscience.jchempaint.action.HelpAction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2009-12-29 13:11:25
|
Revision: 15238 http://cdk.svn.sourceforge.net/cdk/?rev=15238&view=rev Author: shk3 Date: 2009-12-29 13:11:14 +0000 (Tue, 29 Dec 2009) Log Message: ----------- moved a method from JChemPaintAbstractApplet to JChemPaint to keep interface of applet clean Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/InsertTextPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/InsertTextPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/InsertTextPanel.java 2009-12-29 13:00:30 UTC (rev 15237) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/InsertTextPanel.java 2009-12-29 13:11:14 UTC (rev 15238) @@ -55,6 +55,7 @@ import org.openscience.cdk.interfaces.IMolecule; import org.openscience.cdk.smiles.SmilesParser; import org.openscience.jchempaint.applet.JChemPaintAbstractApplet; +import org.openscience.jchempaint.application.JChemPaint; import org.openscience.jchempaint.inchi.StdInChIParser; /** @@ -115,7 +116,7 @@ IMolecule molecule = getMolecule(); if (molecule == null) return; - JChemPaintAbstractApplet.generateModel(jChemPaintPanel, molecule, true, false); + JChemPaint.generateModel(jChemPaintPanel, molecule, true, false); if (closeafter != null) closeafter.setVisible(false); } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java 2009-12-29 13:00:30 UTC (rev 15237) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java 2009-12-29 13:11:14 UTC (rev 15238) @@ -80,6 +80,7 @@ import org.openscience.jchempaint.GT; import org.openscience.jchempaint.JChemPaintPanel; import org.openscience.jchempaint.applet.JChemPaintAbstractApplet; +import org.openscience.jchempaint.application.JChemPaint; import org.openscience.jchempaint.controller.ControllerHub; import org.openscience.jchempaint.controller.MoveModule; import org.openscience.jchempaint.controller.RemoveModule; @@ -499,7 +500,7 @@ //somehow, in case of single atoms, there are no coordinates if(toPaste.getAtomCount()==1 && toPaste.getAtom(0).getPoint2d()==null) toPaste.getAtom(0).setPoint2d(new Point2d(0,0)); - JChemPaintAbstractApplet.generateModel(jcpPanel, toPaste, false,true); + JChemPaint.generateModel(jcpPanel, toPaste, false,true); jcpPanel.get2DHub().fireStructureChangedEvent(); //We select the inserted structure Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2009-12-29 13:00:30 UTC (rev 15237) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2009-12-29 13:11:14 UTC (rev 15238) @@ -404,7 +404,7 @@ .toString())); IMolecule cdkmol = (IMolecule) reader.read(DefaultChemObjectBuilder .getInstance().newMolecule()); - generateModel(theJcpp, cdkmol, false,false); + JChemPaint.generateModel(theJcpp, cdkmol, false,false); theJcpp.get2DHub().updateView(); // the newly opened file should nicely fit the screen theJcpp.getRenderPanel().setFitToScreen(true); @@ -574,71 +574,4 @@ theJcpp.setChemModel(chemModel); theJcpp.get2DHub().updateView(); } - - public static void generateModel(AbstractJChemPaintPanel chemPaintPanel, IMolecule molecule, boolean generateCoordinates, boolean shiftPasted) { - if (molecule == null) return; - - // get relevant bits from active model - IChemModel chemModel = chemPaintPanel.getChemModel(); - IMoleculeSet moleculeSet = chemModel.getMoleculeSet(); - if (moleculeSet == null) { - moleculeSet = new MoleculeSet(); - } - - // On copy & paste on top of an existing drawn structure, prevent the - // pasted section to be drawn exactly on top or to far away from the - // original by shifting it to a fixed position next to it. - if (shiftPasted && moleculeSet.getAtomContainer(0)!=null && moleculeSet.getAtomContainer(0).getAtomCount()!=0) { - // where is the right border of the current structure? - double maxXCurr = Double.NEGATIVE_INFINITY; - for (IAtom atom : moleculeSet.getAtomContainer(0).atoms()) { - if(atom.getPoint2d().x>maxXCurr) - maxXCurr = atom.getPoint2d().x; - } - // where is the left border of the pasted structure? - double minXPaste = Double.POSITIVE_INFINITY; - for (IAtom atom : molecule.atoms()) { - if(atom.getPoint2d().x<minXPaste) - minXPaste = atom.getPoint2d().x; - } - // shift the pasted structure to be nicely next to the existing one. - final int MARGIN=1; - final double SHIFT = maxXCurr - minXPaste; - for (IAtom atom : molecule.atoms()) { - atom.setPoint2d(new Point2d (atom.getPoint2d().x+MARGIN+SHIFT, atom.getPoint2d().y )); - } - } - - if(generateCoordinates){ - // now generate 2D coordinates - StructureDiagramGenerator sdg = new StructureDiagramGenerator(); - sdg.setTemplateHandler(new TemplateHandler(moleculeSet.getBuilder())); - try { - sdg.setMolecule(molecule); - sdg.generateCoordinates(new Vector2d(0, 1)); - molecule = sdg.getMolecule(); - } catch (Exception exc) { - exc.printStackTrace(); - } - } - - if(moleculeSet.getAtomContainer(0).getAtomCount()==0) - moleculeSet.getAtomContainer(0).add(molecule); - else - moleculeSet.addAtomContainer(molecule); - - IUndoRedoFactory i= chemPaintPanel.get2DHub().getUndoRedoFactory(); - UndoRedoHandler ih= chemPaintPanel.get2DHub().getUndoRedoHandler(); - if (i!=null) { - IUndoRedoable undoredo = i.getAddAtomsAndBondsEdit(chemPaintPanel.get2DHub().getIChemModel(), - molecule, null, "Paste", chemPaintPanel.get2DHub()); - ih.postEdit(undoredo); - } - - //moleculeSet.addMolecule(molecule); // don't create another atom container... - ControllerHub.avoidOverlap(chemModel); - chemPaintPanel.getChemModel().setMoleculeSet(moleculeSet); - chemPaintPanel.get2DHub().updateView(); - } - } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2009-12-29 13:00:30 UTC (rev 15237) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2009-12-29 13:11:14 UTC (rev 15238) @@ -49,6 +49,8 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.UIManager; +import javax.vecmath.Point2d; +import javax.vecmath.Vector2d; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; @@ -86,6 +88,7 @@ import org.openscience.cdk.io.SMILESReader; import org.openscience.cdk.io.IChemObjectReader.Mode; import org.openscience.cdk.layout.StructureDiagramGenerator; +import org.openscience.cdk.layout.TemplateHandler; import org.openscience.cdk.tools.CDKHydrogenAdder; import org.openscience.cdk.tools.manipulator.ChemModelManipulator; import org.openscience.cdk.tools.manipulator.ReactionSetManipulator; @@ -94,6 +97,9 @@ import org.openscience.jchempaint.JCPPropertyHandler; import org.openscience.jchempaint.JChemPaintPanel; import org.openscience.jchempaint.controller.ControllerHub; +import org.openscience.jchempaint.controller.undoredo.IUndoRedoFactory; +import org.openscience.jchempaint.controller.undoredo.IUndoRedoable; +import org.openscience.jchempaint.controller.undoredo.UndoRedoHandler; import org.openscience.jchempaint.dialog.WaitDialog; import org.openscience.jchempaint.inchi.StdInChIReader; import org.openscience.jchempaint.io.JCPFileFilter; @@ -512,6 +518,73 @@ return chemModel; } + + public static void generateModel(AbstractJChemPaintPanel chemPaintPanel, IMolecule molecule, boolean generateCoordinates, boolean shiftPasted) { + if (molecule == null) return; + + // get relevant bits from active model + IChemModel chemModel = chemPaintPanel.getChemModel(); + IMoleculeSet moleculeSet = chemModel.getMoleculeSet(); + if (moleculeSet == null) { + moleculeSet = new MoleculeSet(); + } + + // On copy & paste on top of an existing drawn structure, prevent the + // pasted section to be drawn exactly on top or to far away from the + // original by shifting it to a fixed position next to it. + if (shiftPasted && moleculeSet.getAtomContainer(0)!=null && moleculeSet.getAtomContainer(0).getAtomCount()!=0) { + // where is the right border of the current structure? + double maxXCurr = Double.NEGATIVE_INFINITY; + for (IAtom atom : moleculeSet.getAtomContainer(0).atoms()) { + if(atom.getPoint2d().x>maxXCurr) + maxXCurr = atom.getPoint2d().x; + } + // where is the left border of the pasted structure? + double minXPaste = Double.POSITIVE_INFINITY; + for (IAtom atom : molecule.atoms()) { + if(atom.getPoint2d().x<minXPaste) + minXPaste = atom.getPoint2d().x; + } + // shift the pasted structure to be nicely next to the existing one. + final int MARGIN=1; + final double SHIFT = maxXCurr - minXPaste; + for (IAtom atom : molecule.atoms()) { + atom.setPoint2d(new Point2d (atom.getPoint2d().x+MARGIN+SHIFT, atom.getPoint2d().y )); + } + } + + if(generateCoordinates){ + // now generate 2D coordinates + StructureDiagramGenerator sdg = new StructureDiagramGenerator(); + sdg.setTemplateHandler(new TemplateHandler(moleculeSet.getBuilder())); + try { + sdg.setMolecule(molecule); + sdg.generateCoordinates(new Vector2d(0, 1)); + molecule = sdg.getMolecule(); + } catch (Exception exc) { + exc.printStackTrace(); + } + } + + if(moleculeSet.getAtomContainer(0).getAtomCount()==0) + moleculeSet.getAtomContainer(0).add(molecule); + else + moleculeSet.addAtomContainer(molecule); + + IUndoRedoFactory i= chemPaintPanel.get2DHub().getUndoRedoFactory(); + UndoRedoHandler ih= chemPaintPanel.get2DHub().getUndoRedoHandler(); + if (i!=null) { + IUndoRedoable undoredo = i.getAddAtomsAndBondsEdit(chemPaintPanel.get2DHub().getIChemModel(), + molecule, null, "Paste", chemPaintPanel.get2DHub()); + ih.postEdit(undoredo); + } + + //moleculeSet.addMolecule(molecule); // don't create another atom container... + ControllerHub.avoidOverlap(chemModel); + chemPaintPanel.getChemModel().setMoleculeSet(moleculeSet); + chemPaintPanel.get2DHub().updateView(); + } + private static void setReactionIDs(IChemModel chemModel) { // we give all reactions an ID, in case they have none // IDs are needed for handling in JCP This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2009-12-31 22:57:47
|
Revision: 15251 http://cdk.svn.sourceforge.net/cdk/?rev=15251&view=rev Author: annulen Date: 2009-12-31 22:57:32 +0000 (Thu, 31 Dec 2009) Log Message: ----------- Added cross-platform drag&drop support Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java Added Paths: ----------- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPTransferHandler.java Added: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPTransferHandler.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPTransferHandler.java (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPTransferHandler.java 2009-12-31 22:57:32 UTC (rev 15251) @@ -0,0 +1,218 @@ +package org.openscience.jchempaint; + +import javax.swing.TransferHandler; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; +import javax.swing.JComponent; +import javax.swing.JOptionPane; + +import org.openscience.jchempaint.application.JChemPaint; +import org.openscience.jchempaint.JChemPaintPanel; +import org.openscience.jchempaint.applet.JChemPaintEditorApplet; +import org.openscience.jchempaint.renderer.selection.LogicalSelection; +import org.openscience.jchempaint.controller.undoredo.IUndoRedoable; + +import org.openscience.cdk.interfaces.IChemModel; + +public class JCPTransferHandler extends TransferHandler { + private static final long serialVersionUID = 1L; + + private static final String URI_LIST_MIME_TYPE = "text/uri-list;class=java.lang.String"; + + private DataFlavor fileFlavor, stringFlavor; + private DataFlavor uriListFlavor; + + private JChemPaintPanel jcpPanel; + + public JCPTransferHandler(JChemPaintPanel panel) { + + fileFlavor = DataFlavor.javaFileListFlavor; + stringFlavor = DataFlavor.stringFlavor; + + try { + uriListFlavor = new DataFlavor(URI_LIST_MIME_TYPE); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + + jcpPanel = panel; + } + + @Override + public boolean importData(JComponent c, Transferable t) { + + if (!canImport(c, t.getTransferDataFlavors())) { + return false; + } + + try { + // Windows + if (hasFileFlavor(t.getTransferDataFlavors())) { + + final java.util.List files = (java.util.List) t + .getTransferData(fileFlavor); + + process(files); + + return true; + + // Linux + }else if(hasURIListFlavor(t.getTransferDataFlavors())){ + + final List<File> files = textURIListToFileList((String) t.getTransferData(uriListFlavor)); + + if(files.size()>0){ + + process(files); + } + + }else if (hasStringFlavor(t.getTransferDataFlavors())) { + + String str = ((String) t.getTransferData(stringFlavor)); + + System.out.println(str); + + return true; + } + } catch (UnsupportedFlavorException ufe) { + System.out.println("importData: unsupported data flavor"); + } catch (IOException ieo) { + System.out.println("importData: I/O exception"); + } + return false; + } + + @Override + public int getSourceActions(JComponent c) { + return COPY; + } + + @Override + public boolean canImport(JComponent c, DataFlavor[] flavors) { + if (hasFileFlavor(flavors)) { + return true; + } + if (hasStringFlavor(flavors)) { + return true; + } + return false; + } + + private boolean hasFileFlavor(DataFlavor[] flavors) { + for (int i = 0; i < flavors.length; i++) { + if (fileFlavor.equals(flavors[i])) { + return true; + } + } + return false; + } + + private boolean hasStringFlavor(DataFlavor[] flavors) { + for (int i = 0; i < flavors.length; i++) { + if (stringFlavor.equals(flavors[i])) { + return true; + } + } + return false; + } + + private void process(java.util.List<File> l){ + for (File f : l) { + // Taken from OpenAction with small changes + if (jcpPanel.getGuistring().equals( + JChemPaintEditorApplet.GUI_APPLET) || + JChemPaintPanel.getAllAtomContainersInOne(jcpPanel.getChemModel()).getAtomCount()==0) { + int clear = jcpPanel.showWarning(); + if (clear == JOptionPane.YES_OPTION) { + try { + IChemModel chemModel = null; + chemModel = JChemPaint.readFromFile(f, null); + if (jcpPanel.get2DHub().getUndoRedoFactory() != null + && jcpPanel.get2DHub().getUndoRedoHandler() != null) { + IUndoRedoable undoredo = jcpPanel.get2DHub() + .getUndoRedoFactory().getLoadNewModelEdit( + jcpPanel.getChemModel(), + jcpPanel.getChemModel() + .getMoleculeSet(), + jcpPanel.getChemModel() + .getReactionSet(), + chemModel.getMoleculeSet(), + chemModel.getReactionSet(), + "Load " + + f.getName()); + jcpPanel.get2DHub().getUndoRedoHandler().postEdit( + undoredo); + } + jcpPanel.getChemModel().setMoleculeSet( + chemModel.getMoleculeSet()); + jcpPanel.getChemModel().setReactionSet(chemModel.getReactionSet()); + jcpPanel.getRenderPanel().getRenderer() + .getRenderer2DModel().setSelection( + new LogicalSelection( + LogicalSelection.Type.NONE)); + + // the newly opened file should nicely fit the screen + jcpPanel.getRenderPanel().setFitToScreen(true); + + jcpPanel.getRenderPanel().update( + jcpPanel.getRenderPanel().getGraphics()); + + // enable zooming by removing constraint + jcpPanel.getRenderPanel().setFitToScreen(false); + + + + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + jcpPanel.announceError(e1); + + } + } + } else { + JChemPaint.showInstance(f, null, null, jcpPanel.isDebug()); + } + } + } + + private boolean hasURIListFlavor(DataFlavor[] flavors) { + for (int i = 0; i < flavors.length; i++) { + if (uriListFlavor.equals(flavors[i])) { + return true; + } + } + return false; + } + + private static List<File> textURIListToFileList(String data) { + List<File> list = new ArrayList<File>(1); + for (StringTokenizer st = new StringTokenizer(data, "\r\n"); st.hasMoreTokens();) { + String s = st.nextToken(); + if (s.startsWith("#")) { + // the line is a comment (as per the RFC 2483) + continue; + } + try { + URI uri = new URI(s); + File file = new File(uri); + list.add(file); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + return list; + } + +} + Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2009-12-30 17:24:35 UTC (rev 15250) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2009-12-31 22:57:32 UTC (rev 15251) @@ -40,6 +40,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.EventObject; @@ -50,7 +51,6 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.TransferHandler; import org.openscience.cdk.Atom; import org.openscience.cdk.Bond; @@ -80,7 +80,7 @@ private static final long serialVersionUID = 7810772571955039160L; public static List<JChemPaintPanel> instances = new ArrayList<JChemPaintPanel>(); private String lastSelectId; - TransferHandler th; + private JCPTransferHandler handler; public JChemPaintPanel() { } @@ -141,7 +141,8 @@ JChemPaintPanel.this.get2DHub().updateView(); } }); - th = renderPanel.getTransferHandler(); + handler = new JCPTransferHandler(this); + renderPanel.setTransferHandler(handler); } public void setTitle(String title) { @@ -383,52 +384,5 @@ return allinone; } - /** - * Drag&Drop support - * - *@author Konstantin Tokarev - * - */ - /*private TransferHandler handler = new TransferHandler() { - public boolean canImport(TransferHandler.TransferSupport support) { - if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { - return false; - } - - if (copyItem.isSelected()) { - boolean copySupported = (COPY & support.getSourceDropActions()) == COPY; - - if (!copySupported) { - return false; - } - - support.setDropAction(COPY); - } - - return true; - } - - public boolean importData(TransferHandler.TransferSupport support) { - if (!canImport(support)) { - return false; - } - - Transferable t = support.getTransferable(); - - try { - java.util.List<File> l = - (java.util.List<File>)t.getTransferData(DataFlavor.javaFileListFlavor); - - for (File f : l) { - new Doc(f); - } - } catch (UnsupportedFlavorException e) { - return false; - } catch (IOException e) { - return false; - } - - return true; - } - };*/ + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2010-01-08 15:43:26
|
Revision: 15286 http://cdk.svn.sourceforge.net/cdk/?rev=15286&view=rev Author: mark_rynbeek Date: 2010-01-08 15:43:19 +0000 (Fri, 08 Jan 2010) Log Message: ----------- Changes for getting the ring start angle correct with upside down patch from Arvid. Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/AddRingModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/EnterElementSwingModule.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/AddRingModule.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/AddRingModule.java 2010-01-08 14:55:50 UTC (rev 15285) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/AddRingModule.java 2010-01-08 15:43:19 UTC (rev 15286) @@ -24,6 +24,9 @@ */ package org.openscience.jchempaint.controller; +import java.util.HashMap; +import java.util.Map; + import javax.vecmath.Point2d; import org.openscience.cdk.interfaces.IAtom; @@ -172,7 +175,9 @@ ring.getBond(4).setOrder(IBond.Order.DOUBLE); } double bondLength = ((ControllerHub)this.chemModelRelay).calculateAverageBondLength(this.chemModelRelay.getIChemModel().getMoleculeSet()); - ringPlacer.placeRing(ring, worldCoord, bondLength); + + ringPlacer.placeRing(ring, worldCoord, bondLength, RingPlacer.jcpAngles); + for(IAtom atom : ring.atoms()) this.chemModelRelay.addPhantomAtom(atom); for(IBond atom : ring.bonds()) Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-01-08 14:55:50 UTC (rev 15285) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-01-08 15:43:19 UTC (rev 15286) @@ -1113,7 +1113,7 @@ public IRing addRing(int ringSize, Point2d worldcoord, boolean undoable) { IRing ring = chemModel.getBuilder().newRing(ringSize, "C"); double bondLength = calculateAverageBondLength(chemModel.getMoleculeSet()); - ringPlacer.placeRing(ring, worldcoord, bondLength); + ringPlacer.placeRing(ring, worldcoord, bondLength, RingPlacer.jcpAngles); IMoleculeSet set = chemModel.getMoleculeSet(); // the molecule set should not be null, but just in case... @@ -1145,7 +1145,7 @@ makeRingAromatic(ring); double bondLength = calculateAverageBondLength(chemModel.getMoleculeSet()); - ringPlacer.placeRing(ring, worldcoord, bondLength); + ringPlacer.placeRing(ring, worldcoord, bondLength,RingPlacer.jcpAngles); IMoleculeSet set = chemModel.getMoleculeSet(); // the molecule set should not be null, but just in case... @@ -1255,7 +1255,7 @@ */ bondLength = calculateAverageBondLength(chemModel.getMoleculeSet()); Point2d ringCenter = new Point2d(atom.getPoint2d()); - ringPlacer.placeRing(newRing, ringCenter, bondLength); + ringPlacer.placeRing(newRing, ringCenter, bondLength,RingPlacer.jcpAngles); } else { bondLength = GeometryTools.getBondLengthAverage(sourceContainer); Point2d conAtomsCenter = getConnectedAtomsCenter(sharedAtoms, chemModel); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/EnterElementSwingModule.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/EnterElementSwingModule.java 2010-01-08 14:55:50 UTC (rev 15285) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/EnterElementSwingModule.java 2010-01-08 15:43:19 UTC (rev 15286) @@ -56,7 +56,6 @@ import org.openscience.jchempaint.GT; import org.openscience.jchempaint.controller.ControllerModuleAdapter; import org.openscience.jchempaint.controller.IChemModelRelay; -import org.openscience.jchempaint.controller.IControllerModel; import org.openscience.jchempaint.controller.undoredo.IUndoRedoable; public class EnterElementSwingModule extends ControllerModuleAdapter { @@ -170,7 +169,7 @@ ap.distributePartners(lastplaced, placedNeighbours, GeometryTools.get2DCenter(placedNeighbours), unplacedNeighbours, 1.4); IRingSet ringset=new SSSRFinder(container).findSSSR(); for(IAtomContainer ring:ringset.atomContainers()){ - ringPlacer.placeRing((IRing)ring, GeometryTools.get2DCenter(container), chemModelRelay.getRenderer().getRenderer2DModel().getBondLength() / chemModelRelay.getRenderer().getRenderer2DModel().getScale()); + ringPlacer.placeRing((IRing)ring, GeometryTools.get2DCenter(container), chemModelRelay.getRenderer().getRenderer2DModel().getBondLength() / chemModelRelay.getRenderer().getRenderer2DModel().getScale(), RingPlacer.jcpAngles); } lastplaced=container.getAtom(counter); counter++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-01-12 13:26:35
|
Revision: 15293 http://cdk.svn.sourceforge.net/cdk/?rev=15293&view=rev Author: shk3 Date: 2010-01-12 13:26:28 +0000 (Tue, 12 Jan 2010) Log Message: ----------- the layout lays out reactions as well Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2010-01-12 12:29:49 UTC (rev 15292) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2010-01-12 13:26:28 UTC (rev 15293) @@ -232,14 +232,14 @@ */ @Override public void start() { + // Parameter parsing goes here + loadModelFromParam(); RendererModel rendererModel = theJcpp.get2DHub().getRenderer() .getRenderer2DModel(); IChemModel chemModel = theJcpp.getChemModel(); IControllerModel controllerModel = theJcpp.get2DHub() .getController2DModel(); - // Parameter parsing goes here - loadModelFromParam(); String atomNumbers = getParameter("atomNumbersVisible"); if (atomNumbers != null) { if (atomNumbers.equals("true")) Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2010-01-12 12:29:49 UTC (rev 15292) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2010-01-12 13:26:28 UTC (rev 15293) @@ -674,9 +674,9 @@ // frame.pack(); // frame.show(); - IMoleculeSet set = chemModel.getMoleculeSet(); WaitDialog.showDialog(); - chemModel.setMoleculeSet(generate2dCoordinates(set)); + List<IAtomContainer> acs=ChemModelManipulator.getAllAtomContainers(chemModel); + generate2dCoordinates(acs); WaitDialog.hideDialog(); return; } @@ -709,11 +709,10 @@ * @param molecules * @throws Exception */ - private static IMoleculeSet generate2dCoordinates(IMoleculeSet molecules) { - IMoleculeSet molSet2Dcalculated = new MoleculeSet(); + private static void generate2dCoordinates(List<IAtomContainer> molecules) { StructureDiagramGenerator sdg = new StructureDiagramGenerator(); - for (int atIdx = 0; atIdx < molecules.getAtomContainerCount(); atIdx++) { - IAtomContainer mol = molecules.getAtomContainer(atIdx); + for (int atIdx = 0; atIdx < molecules.size(); atIdx++) { + IAtomContainer mol = molecules.get(atIdx); sdg.setMolecule(mol.getBuilder().newMolecule(mol)); try { sdg.generateCoordinates(); @@ -721,9 +720,10 @@ e.printStackTrace(); } IAtomContainer ac = sdg.getMolecule(); - molSet2Dcalculated.addAtomContainer(ac); + for(int i=0;i<ac.getAtomCount();i++){ + mol.getAtom(i).setPoint2d(ac.getAtom(i).getPoint2d()); + } } - return molSet2Dcalculated; } public static JChemPaintPanel showInstance(IChemModel chemModel, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2010-01-18 21:23:05
|
Revision: 15310 http://cdk.svn.sourceforge.net/cdk/?rev=15310&view=rev Author: annulen Date: 2010-01-18 21:22:57 +0000 (Mon, 18 Jan 2010) Log Message: ----------- Added Pseudoatom (RX) button to JCP application GUI Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/ConvertToPseudoAtomAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties Added Paths: ----------- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/apponly/R.png Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2010-01-18 21:21:30 UTC (rev 15309) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2010-01-18 21:22:57 UTC (rev 15310) @@ -312,6 +312,7 @@ entries.put("ClTooltip", GT._("Change drawing symbol to {0}", "Cl")); entries.put("BrTooltip", GT._("Change drawing symbol to {0}", "Br")); entries.put("ITooltip", GT._("Change drawing symbol to {0}", "I")); + entries.put("enterRTooltip", GT._("Draw any functional group")); entries.put("reaction", GT._("Reaction")); entries.put("addReactantToNewReaction", GT._("Make Reactant in New Reaction")); entries.put("addReactantToExistingReaction", GT._("Make Reactant in Existing Reaction")); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java 2010-01-18 21:21:30 UTC (rev 15309) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java 2010-01-18 21:22:57 UTC (rev 15310) @@ -132,10 +132,17 @@ newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddAtomModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond()); else newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), IBond.Stereo.NONE); + if(symbol.equals("RX")) { + jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(true); + symbol = JOptionPane.showInputDialog(GT._("Enter label"), "R"); + if (symbol == null) + symbol = "R"; + } else { + jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(false); + } newActiveModule.setID(symbol); jcpPanel.get2DHub().getController2DModel().setDrawElement(symbol); - jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(0); - jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(false); + jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(0); } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ConvertToPseudoAtomAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ConvertToPseudoAtomAction.java 2010-01-18 21:21:30 UTC (rev 15309) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ConvertToPseudoAtomAction.java 2010-01-18 21:22:57 UTC (rev 15310) @@ -41,6 +41,7 @@ import org.openscience.cdk.interfaces.IChemObject; import org.openscience.jchempaint.controller.AddAtomModule; import org.openscience.jchempaint.controller.AddBondDragModule; +import org.openscience.jchempaint.GT; ; /** @@ -73,7 +74,7 @@ return; String x = type; if(type.equals("RX")) { - x = JOptionPane.showInputDialog("Enter label", "R"); + x = JOptionPane.showInputDialog(GT._("Enter label"), "R"); if (x == null) x = "R"; } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties 2010-01-18 21:21:30 UTC (rev 15309) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties 2010-01-18 21:22:57 UTC (rev 15310) @@ -111,6 +111,6 @@ uppertoolbar=new open save print select lasso eraser zoomin zoomout undo redo \ cut copy paste flipHorizontal flipVertical rotate rotate3d -lowertoolbar=C H O N P S F Cl Br I plus minus enterelement periodictable +lowertoolbar=C H O N P S F Cl Br I enterR plus minus enterelement periodictable righttoolbar=triangle square pentagon hexagon benzene octagon pasteTemplate lefttoolbar=bond up_bond down_bond undefined_bond undefined_stereo_bond Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2010-01-18 21:21:30 UTC (rev 15309) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2010-01-18 21:22:57 UTC (rev 15310) @@ -95,6 +95,7 @@ BrImage=resources/small-bin/Br.gif OImage=resources/small-bin/O.gif NImage=resources/small-bin/N.gif +enterRImage=resources/apponly/R.png ####################################################### # Action definition # @@ -301,6 +302,7 @@ moveAction=org.openscience.jchempaint.action.ChangeModeAction@move periodictableAction=org.openscience.jchempaint.action.ChangeAtomSymbolAction@periodictable enterelementAction=org.openscience.jchempaint.action.ChangeAtomSymbolAction@enterelement +enterRAction=org.openscience.jchempaint.action.ChangeAtomSymbolAction@RX plusAction=org.openscience.jchempaint.action.ChargeAction@plus minusAction=org.openscience.jchempaint.action.ChargeAction@minus triangleAction=org.openscience.jchempaint.action.ChangeModeAction@triangle Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/apponly/R.png =================================================================== (Binary files differ) Property changes on: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/apponly/R.png ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2010-01-20 17:59:15
|
Revision: 15322 http://cdk.svn.sourceforge.net/cdk/?rev=15322&view=rev Author: annulen Date: 2010-01-20 17:58:58 +0000 (Wed, 20 Jan 2010) Log Message: ----------- Highlight for 'R' button Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2010-01-20 17:49:19 UTC (rev 15321) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2010-01-20 17:58:58 UTC (rev 15322) @@ -388,6 +388,9 @@ buttons.get("periodictable").setBackground(Color.GRAY); lastSecondaryButton = buttons.get("periodictable"); } + } else if (actionid.equals("RX")) { + this.buttons.get("enterR").setBackground(Color.GRAY); + lastSecondaryButton = this.buttons.get("enterR"); } if(JCPToolBar.getToolbarResourceString("lowertoolbar", getGuistring()).indexOf(newActiveModule.getID())>-1){ //the newActiveModule should always be an AddAtomModule, but we still check Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java 2010-01-20 17:49:19 UTC (rev 15321) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java 2010-01-20 17:58:58 UTC (rev 15322) @@ -137,10 +137,11 @@ symbol = JOptionPane.showInputDialog(GT._("Enter label"), "R"); if (symbol == null) symbol = "R"; + newActiveModule.setID("RX"); } else { - jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(false); - } - newActiveModule.setID(symbol); + jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(false); + newActiveModule.setID(symbol); + } jcpPanel.get2DHub().getController2DModel().setDrawElement(symbol); jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(0); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2010-01-25 10:15:06
|
Revision: 15333 http://cdk.svn.sourceforge.net/cdk/?rev=15333&view=rev Author: annulen Date: 2010-01-25 10:14:58 +0000 (Mon, 25 Jan 2010) Log Message: ----------- Drawing of double&triple bonds from toolbar Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeBondAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/AddBondDragModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IAtomBondEdits.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeBondAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeBondAction.java 2010-01-25 10:13:23 UTC (rev 15332) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeBondAction.java 2010-01-25 10:14:58 UTC (rev 15333) @@ -50,8 +50,13 @@ public void actionPerformed(ActionEvent event) { + + String s = event.getActionCommand(); + String type = s.substring(s.indexOf("@") + 1); + //first switch mode - AddBondDragModule newActiveModule = new AddBondDragModule(jcpPanel.get2DHub(),IBond.Stereo.NONE, true); + //AddBondDragModule newActiveModule = new AddBondDragModule(jcpPanel.get2DHub(),IBond.Stereo.NONE, true); + AddBondDragModule newActiveModule = null; if(type.equals("down_bond")){ newActiveModule = new AddBondDragModule(jcpPanel.get2DHub(),IBond.Stereo.DOWN, true); }else if(type.equals("up_bond")){ @@ -60,16 +65,30 @@ newActiveModule = new AddBondDragModule(jcpPanel.get2DHub(),IBond.Stereo.UP_OR_DOWN, true); }else if(type.equals("undefined_stereo_bond")){ newActiveModule = new AddBondDragModule(jcpPanel.get2DHub(),IBond.Stereo.E_OR_Z, true); + }else if(type.equals("bondTool")){ + newActiveModule = new AddBondDragModule(jcpPanel.get2DHub(),IBond.Stereo.NONE, true); + }else if(type.equals("double_bondTool")){ + newActiveModule = new AddBondDragModule(jcpPanel.get2DHub(),IBond.Order.DOUBLE, true); + }else if(type.equals("triple_bondTool")){ + newActiveModule = new AddBondDragModule(jcpPanel.get2DHub(),IBond.Order.TRIPLE, true); } - newActiveModule.setID(type); - jcpPanel.get2DHub().setActiveDrawModule(newActiveModule); + if (newActiveModule != null) { // null means that menu was used => don't change module + newActiveModule.setID(type); + jcpPanel.get2DHub().setActiveDrawModule(newActiveModule); + } + + // xxxTool -> xxx + int l = type.length(); + if (type.substring(l-4,l).equals("Tool")) + type = type.substring(0,l-4); + //then handle selection or highlight if there is one IChemObject object = getSource(event); Iterator<IBond> bondsInRange = null; if (object == null){ - //this means the main menu was used + //this means the main menu or toolbar was used if(jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel().getSelection()!=null && jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel().getSelection().isFilled()) bondsInRange=jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel().getSelection().getConnectedAtomContainer().bonds().iterator(); @@ -87,8 +106,7 @@ if(bondsInRange==null) return; - String s = event.getActionCommand(); - String type = s.substring(s.indexOf("@") + 1); + while(bondsInRange.hasNext()){ IBond bond = bondsInRange.next(); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/AddBondDragModule.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/AddBondDragModule.java 2010-01-25 10:13:23 UTC (rev 15332) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/AddBondDragModule.java 2010-01-25 10:14:58 UTC (rev 15333) @@ -61,6 +61,7 @@ private double bondLength; private String ID; IBond.Stereo stereoForNewBond; + IBond.Order orderForNewBond; //if this is true, initally a bond will be drawn, if not, just an atom boolean makeInitialBond; @@ -76,9 +77,17 @@ public AddBondDragModule(IChemModelRelay chemModelRelay, IBond.Stereo stereoForNewBond,boolean makeInitialBond) { super( chemModelRelay ); this.stereoForNewBond = stereoForNewBond; + this.orderForNewBond = IBond.Order.SINGLE; this.makeInitialBond = makeInitialBond; } + public AddBondDragModule(IChemModelRelay chemModelRelay, IBond.Order orderForNewBond,boolean makeInitialBond) { + super( chemModelRelay ); + this.stereoForNewBond = IBond.Stereo.NONE; + this.orderForNewBond = orderForNewBond; + this.makeInitialBond = makeInitialBond; + } + private IChemObjectBuilder getBuilder() { return chemModelRelay.getIChemModel().getBuilder(); } @@ -123,7 +132,7 @@ } else if (singleSelection instanceof IBond) { if(stereoForNewBond==IBond.Stereo.NONE){ - chemModelRelay.cycleBondValence((IBond) singleSelection); + chemModelRelay.cycleBondValence((IBond) singleSelection, orderForNewBond); }else{ IChemModelRelay.Direction direction = Direction.DOWN; if(stereoForNewBond==IBond.Stereo.UP) @@ -155,7 +164,7 @@ dest = null; }else if (merge != null) { // set bond - chemModelRelay.addPhantomBond( getBuilder().newBond(source,merge, CDKConstants.BONDORDER_SINGLE, stereoForNewBond) ); + chemModelRelay.addPhantomBond( getBuilder().newBond(source,merge, orderForNewBond, stereoForNewBond) ); dest = null; //we also remember the merge atom in the merges in the rendererModel, //in case an application uses these. @@ -163,7 +172,7 @@ }else { dest = roundAngle( start, worldCoordTo, bondLength ); IAtom atom = getBuilder().newAtom( chemModelRelay.getController2DModel().getDrawElement(), dest ); - IBond bond = getBuilder().newBond( source,atom, CDKConstants.BONDORDER_SINGLE, stereoForNewBond ); + IBond bond = getBuilder().newBond( source,atom, orderForNewBond, stereoForNewBond ); chemModelRelay.addPhantomBond( bond ); // update phantom } @@ -207,12 +216,12 @@ if(merge!=null) { chemModelRelay.getRenderer().getRenderer2DModel().getMerge().remove(merge); removedContainer = ChemModelManipulator.getRelevantAtomContainer(chemModelRelay.getIChemModel(), merge); - IBond newBond = chemModelRelay.addBond( newAtom , merge, stereoForNewBond ); + IBond newBond = chemModelRelay.addBond( newAtom , merge, stereoForNewBond, orderForNewBond ); containerForUndoRedo.addBond(newBond); } else { if(start.distance( worldCoord )<getHighlightDistance()) { if(!newSource) { - IAtom undoRedoAtom=chemModelRelay.addAtomWithoutUndo(chemModelRelay.getController2DModel().getDrawElement(), newAtom, stereoForNewBond, chemModelRelay.getController2DModel().getDrawPseudoAtom() ); + IAtom undoRedoAtom=chemModelRelay.addAtomWithoutUndo(chemModelRelay.getController2DModel().getDrawElement(), newAtom, stereoForNewBond, orderForNewBond, chemModelRelay.getController2DModel().getDrawPseudoAtom() ); containerForUndoRedo.addAtom(undoRedoAtom); IAtomContainer atomCon = ChemModelManipulator.getRelevantAtomContainer(chemModelRelay.getIChemModel(), undoRedoAtom); @@ -223,12 +232,12 @@ new Point2d(newAtom.getPoint2d().x+1.5,newAtom.getPoint2d().y), chemModelRelay.getController2DModel().getDrawPseudoAtom()); containerForUndoRedo.addAtom(undoRedoAtom); - containerForUndoRedo.addBond(chemModelRelay.addBond(newAtom, undoRedoAtom, stereoForNewBond)); + containerForUndoRedo.addBond(chemModelRelay.addBond(newAtom, undoRedoAtom, stereoForNewBond, orderForNewBond)); } }else { IAtom atom = chemModelRelay.addAtomWithoutUndo(chemModelRelay.getController2DModel().getDrawElement(), dest, chemModelRelay.getController2DModel().getDrawPseudoAtom() ); containerForUndoRedo.addAtom(atom); - IBond newBond = chemModelRelay.addBond( newAtom, atom, stereoForNewBond ); + IBond newBond = chemModelRelay.addBond( newAtom, atom, stereoForNewBond, orderForNewBond ); containerForUndoRedo.addBond(newBond); } } @@ -243,8 +252,12 @@ } public String getDrawModeString() { - - return "Draw Bond"; + if (orderForNewBond == IBond.Order.DOUBLE) + return "Draw Double Bond"; + else if (orderForNewBond == IBond.Order.TRIPLE) + return "Draw Triple Bond"; + else + return "Draw Bond"; } public String getID() { Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-01-25 10:13:23 UTC (rev 15332) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-01-25 10:14:58 UTC (rev 15333) @@ -523,14 +523,22 @@ /* (non-Javadoc) * @see org.openscience.cdk.controller.IChemModelRelay#addAtomWithoutUndo(java.lang.String, org.openscience.cdk.interfaces.IAtom, int) */ - public IAtom addAtomWithoutUndo(String atomType, IAtom atom, IBond.Stereo stereo, boolean makePseudoAtom) { + public IAtom addAtomWithoutUndo(String atomType, IAtom atom, IBond.Stereo stereo, Order order, boolean makePseudoAtom) { IAtom newAtom; if (makePseudoAtom) { newAtom = chemModel.getBuilder().newPseudoAtom(atomType); } else { newAtom = chemModel.getBuilder().newAtom(atomType); } - IBond newBond = chemModel.getBuilder().newBond(atom, newAtom, CDKConstants.BONDORDER_SINGLE, stereo); + IBond newBond; + if (order == IBond.Order.DOUBLE) { + newBond = chemModel.getBuilder().newBond(atom, newAtom, CDKConstants.BONDORDER_DOUBLE, stereo); + } else if (order == IBond.Order.TRIPLE) { + newBond = chemModel.getBuilder().newBond(atom, newAtom, CDKConstants.BONDORDER_TRIPLE, stereo); + } else { + newBond = chemModel.getBuilder().newBond(atom, newAtom, CDKConstants.BONDORDER_SINGLE, stereo); + } + IAtomContainer atomCon = ChemModelManipulator.getRelevantAtomContainer(chemModel, atom); if (atomCon == null) { @@ -600,6 +608,10 @@ return newAtom; } + public IAtom addAtomWithoutUndo(String atomType, IAtom atom, IBond.Stereo stereo, boolean makePseudoAtom) { + return addAtomWithoutUndo(atomType, atom, stereo, IBond.Order.SINGLE, makePseudoAtom); + } + //OK public void addNewBond(Point2d worldCoordinate, boolean makePseudoAtom) { IAtomContainer undoRedoContainer = @@ -632,6 +644,10 @@ //OK public void cycleBondValence(IBond bond) { + cycleBondValence(bond, IBond.Order.SINGLE); + } + + public void cycleBondValence(IBond bond, IBond.Order order) { IBond.Order[] orders=new IBond.Order[2]; IBond.Stereo[] stereos=new IBond.Stereo[2]; orders[1]=bond.getOrder(); @@ -639,14 +655,23 @@ // special case : reset stereo bonds if (bond.getStereo() != IBond.Stereo.NONE) { bond.setStereo(IBond.Stereo.NONE); + bond.setOrder(order); }else{ - // cycle the bond order up to maxOrder - IBond.Order maxOrder = getController2DModel().getMaxOrder(); - if (BondManipulator.isLowerOrder(bond.getOrder(), maxOrder)) { - BondManipulator.increaseBondOrder(bond); + if (order == IBond.Order.SINGLE) { + // cycle the bond order up to maxOrder + IBond.Order maxOrder = getController2DModel().getMaxOrder(); + if (BondManipulator.isLowerOrder(bond.getOrder(), maxOrder)) { + BondManipulator.increaseBondOrder(bond); + } else { + bond.setOrder(IBond.Order.SINGLE); + } } else { - bond.setOrder(IBond.Order.SINGLE); - } + if (bond.getOrder() != order) { + bond.setOrder(order); + } else { + bond.setOrder(IBond.Order.SINGLE); + } + } } orders[0]=bond.getOrder(); stereos[0]=bond.getStereo(); @@ -756,9 +781,9 @@ /* (non-Javadoc) * @see org.openscience.cdk.controller.IChemModelRelay#addBond(org.openscience.cdk.interfaces.IAtom, org.openscience.cdk.interfaces.IAtom, int) */ - public IBond addBond(IAtom fromAtom, IAtom toAtom, IBond.Stereo stereo) { + public IBond addBond(IAtom fromAtom, IAtom toAtom, IBond.Stereo stereo, IBond.Order order) { IBond newBond = chemModel.getBuilder().newBond(fromAtom, toAtom, - CDKConstants.BONDORDER_SINGLE, stereo); + order, stereo); IAtomContainer fromContainer = ChemModelManipulator.getRelevantAtomContainer(chemModel, fromAtom); IAtomContainer toContainer = ChemModelManipulator.getRelevantAtomContainer(chemModel, toAtom); //we need to check if this merges two atomconainers or not @@ -773,12 +798,16 @@ return newBond; } + public IBond addBond(IAtom fromAtom, IAtom toAtom, IBond.Stereo stereo) { + return addBond(fromAtom, toAtom, stereo, IBond.Order.SINGLE); + } + //OK /* (non-Javadoc) * @see org.openscience.cdk.controller.IChemModelRelay#addBond(org.openscience.cdk.interfaces.IAtom, org.openscience.cdk.interfaces.IAtom) */ public IBond addBond(IAtom fromAtom, IAtom toAtom) { - return addBond(fromAtom, toAtom, IBond.Stereo.NONE); + return addBond(fromAtom, toAtom, IBond.Stereo.NONE, IBond.Order.SINGLE); } //OK Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IAtomBondEdits.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IAtomBondEdits.java 2010-01-25 10:13:23 UTC (rev 15332) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IAtomBondEdits.java 2010-01-25 10:14:58 UTC (rev 15333) @@ -69,7 +69,8 @@ public void moveTo(IBond bond, Point2d point); public void changeBond(IBond bond, IBond.Order order, IBond.Stereo stereo); public void addNewBond(Point2d worldCoordinate, boolean makePseudoAtom); - public void cycleBondValence(IBond bond); + //public void cycleBondValence(IBond bond); + public void cycleBondValence(IBond bond, IBond.Order order); public void makeBondStereo(IBond bond, Direction desiredDirection); public IBond makeNewStereoBond(IAtom atom, Direction desiredDirection); } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java 2010-01-25 10:13:23 UTC (rev 15332) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java 2010-01-25 10:14:58 UTC (rev 15333) @@ -38,6 +38,7 @@ import org.openscience.cdk.interfaces.IPseudoAtom; import org.openscience.cdk.interfaces.IRing; import org.openscience.cdk.interfaces.IBond.Stereo; +import org.openscience.cdk.interfaces.IBond.Order; import org.openscience.jchempaint.controller.undoredo.IUndoRedoFactory; import org.openscience.jchempaint.controller.undoredo.UndoRedoHandler; import org.openscience.jchempaint.renderer.IRenderer; @@ -188,8 +189,11 @@ public IUndoRedoFactory getUndoRedoFactory(); public UndoRedoHandler getUndoRedoHandler(); - public IBond addBond(IAtom fromAtom, IAtom toAtom, IBond.Stereo stereo); - public IAtom addAtomWithoutUndo(String drawElement, IAtom newAtom, Stereo stereoForNewBond, boolean makePseudoAtom); + public IBond addBond(IAtom fromAtom, IAtom toAtom, Stereo stereo, Order order); + //public IBond addBond(IAtom fromAtom, IAtom toAtom, IBond.Stereo stereo); + //public IAtom addAtomWithoutUndo(String drawElement, IAtom newAtom, Stereo stereoForNewBond, boolean makePseudoAtom); + public IAtom addAtomWithoutUndo(String drawElement, IAtom newAtom, + Stereo stereo, Order order, boolean makePseudoAtom); public void setValence(IAtom atom, Integer newValence); public IAtom addAtom(String drawElement, int drawIsotopeNumber, Point2d start, boolean makePseudoAtom); public void removeBondAndLoneAtoms(IBond bond); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2010-01-27 08:24:27
|
Revision: 15352 http://cdk.svn.sourceforge.net/cdk/?rev=15352&view=rev Author: annulen Date: 2010-01-27 08:24:19 +0000 (Wed, 27 Jan 2010) Log Message: ----------- if toolbar definition missing, don't show it Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java 2010-01-26 08:26:56 UTC (rev 15351) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java 2010-01-27 08:24:19 UTC (rev 15352) @@ -431,19 +431,27 @@ if (uppertoolbar == null) { uppertoolbar = JCPToolBar.getToolbar(this, "uppertoolbar", SwingConstants.HORIZONTAL); } - topContainer.add(uppertoolbar, BorderLayout.SOUTH); + if (uppertoolbar != null) { + topContainer.add(uppertoolbar, BorderLayout.SOUTH); + } if (lefttoolbar == null) { lefttoolbar = JCPToolBar.getToolbar(this, "lefttoolbar", SwingConstants.VERTICAL); } - centerContainer.add(lefttoolbar, BorderLayout.WEST); + if (lefttoolbar != null) { + centerContainer.add(lefttoolbar, BorderLayout.WEST); + } if (righttoolbar == null) { righttoolbar = JCPToolBar.getToolbar(this, "righttoolbar", SwingConstants.VERTICAL); } - centerContainer.add(righttoolbar, BorderLayout.EAST); + if (righttoolbar != null) { + centerContainer.add(righttoolbar, BorderLayout.EAST); + } if (lowertoolbar == null) { lowertoolbar = JCPToolBar.getToolbar(this, "lowertoolbar", SwingConstants.HORIZONTAL); } - centerContainer.add(lowertoolbar, BorderLayout.SOUTH); + if (lowertoolbar != null) { + centerContainer.add(lowertoolbar, BorderLayout.SOUTH); + } } else { topContainer.remove(uppertoolbar); centerContainer.remove(lowertoolbar); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java 2010-01-26 08:26:56 UTC (rev 15351) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java 2010-01-27 08:24:19 UTC (rev 15352) @@ -200,7 +200,10 @@ public static Component createToolbar(int orientation, String kind, AbstractJChemPaintPanel chemPaintPanel, int lines) { JToolBar toolbar2 = new JToolBar(orientation); - String[] toolKeys = StringHelper.tokenize(getToolbarResourceString(kind, chemPaintPanel.getGuistring())); + String resource_string = getToolbarResourceString(kind, chemPaintPanel.getGuistring()); + if (resource_string == null) + return null; + String[] toolKeys = StringHelper.tokenize(resource_string); JButton button = null; Box box=null; int counter=0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-03-11 11:50:48
|
Revision: 15482 http://cdk.svn.sourceforge.net/cdk/?rev=15482&view=rev Author: shk3 Date: 2010-03-11 11:50:42 +0000 (Thu, 11 Mar 2010) Log Message: ----------- A few changes for the layout of reactions Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-03-11 08:45:13 UTC (rev 15481) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-03-11 11:50:42 UTC (rev 15482) @@ -1056,20 +1056,33 @@ if(chemModel.getReactionSet()!=null){ for(IReaction reaction : chemModel.getReactionSet().reactions()){ usedBounds = null; + double gap=0; + double centerY=0; for (IAtomContainer container : ReactionManipulator.getAllAtomContainers(reaction)) { // now move it so that they don't overlap Rectangle2D bounds = BoundsCalculator.calculateBounds(container); if (usedBounds != null) { - double bondLength = GeometryTools.getBondLengthAverage(container); + if(gap==0){ + gap = GeometryTools.getBondLengthAverage(container); + } Rectangle2D shiftedBounds = GeometryTools.shiftContainer( - container, bounds, usedBounds, bondLength); + container, bounds, usedBounds, gap*2); + double yshift=centerY - bounds.getCenterY(); + Vector2d shift = new Vector2d(0.0, yshift); + GeometryTools.translate2D(container, shift); usedBounds = usedBounds.createUnion(shiftedBounds); } else { usedBounds = bounds; + centerY = bounds.getCenterY(); } } + //we shift the products an extra bit to make a larget gap between products and reactants + for(IAtomContainer container : reaction.getProducts().atomContainers()){ + Vector2d shift = new Vector2d(gap*2, 0.0); + GeometryTools.translate2D(container, shift); + } } } //TODO overlaps of molecules in molecule set and reactions (ok, not too common, but still...) Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-03-11 08:45:13 UTC (rev 15481) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-03-11 11:50:42 UTC (rev 15482) @@ -635,11 +635,11 @@ } public static Rectangle2D calculateBounds(IMoleculeSet moleculeSet) { - Rectangle2D totalBounds = new Rectangle2D.Double(); + Rectangle2D totalBounds = null; for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) { IAtomContainer ac = moleculeSet.getAtomContainer(i); Rectangle2D acBounds = Renderer.calculateBounds(ac); - if (totalBounds.isEmpty()) { + if (totalBounds==null) { totalBounds = acBounds; } else { Rectangle2D.union(totalBounds, acBounds, totalBounds); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-03-22 19:57:48
|
Revision: 15493 http://cdk.svn.sourceforge.net/cdk/?rev=15493&view=rev Author: shk3 Date: 2010-03-22 19:57:41 +0000 (Mon, 22 Mar 2010) Log Message: ----------- The frames around reactions can be switched on/off in properties editor Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/PropertiesModelEditor.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RenderingParameters.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/PropertiesModelEditor.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/PropertiesModelEditor.java 2010-03-21 19:30:09 UTC (rev 15492) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/PropertiesModelEditor.java 2010-03-22 19:57:41 UTC (rev 15493) @@ -93,7 +93,7 @@ //private JCheckBox showToolTip; - //private JCheckBox showReactionBoxes; + private JCheckBox showReactionBoxes; //private JCheckBox useAntiAliasing; @@ -211,8 +211,8 @@ //showToolTip = new JCheckBox(); //addField(GT._("Show tooltips"), showToolTip); - //showReactionBoxes = new JCheckBox(); - //addField(GT._("Show boxes around reactions"), showReactionBoxes); + showReactionBoxes = new JCheckBox(GT._("Show boxes around reactions")); + options1.add(showReactionBoxes); isFitToScreen = new JCheckBox(GT._("Set fit to screen")); @@ -359,7 +359,7 @@ colorAtomsByType.setSelected(model.getColorAtomsByType()); //useAntiAliasing.setSelected(model.getUseAntiAliasing()); //showToolTip.setSelected(model.getShowTooltip()); - //showReactionBoxes.setSelected(model.getShowReactionBoxes()); + showReactionBoxes.setSelected(model.getShowReactionBoxes()); isFitToScreen.setSelected(model.isFitToScreen()); atomRadius.setValue((int)model.getAtomRadius()); @@ -411,7 +411,7 @@ model.setColorAtomsByType(colorAtomsByType.isSelected()); //model.setUseAntiAliasing(useAntiAliasing.isSelected()); //model.setShowTooltip(showToolTip.isSelected()); - //model.setShowReactionBoxes(showReactionBoxes.isSelected()); + model.setShowReactionBoxes(showReactionBoxes.isSelected()); model.setIsCompact(!nonCompactShape.isSelected()); model.setFitToScreen(isFitToScreen.isSelected()); @@ -446,7 +446,7 @@ props.setProperty("ColorAtomsByType",String.valueOf(colorAtomsByType.isSelected())); //props.setProperty("UseAntiAliasing",String.valueOf(useAntiAliasing.isSelected())); //props.setProperty("ShowTooltip",String.valueOf(showToolTip.isSelected())); - //props.setProperty("ShowReactionBoxes",String.valueOf(showReactionBoxes.isSelected())); + props.setProperty("ShowReactionBoxes",String.valueOf(showReactionBoxes.isSelected())); props.setProperty("IsCompact",String.valueOf(!nonCompactShape.isSelected())); props.setProperty("FitToScreen",String.valueOf(isFitToScreen.isSelected())); @@ -476,7 +476,7 @@ throw new Exception("wrong number"); props.setProperty("General.UndoStackSize", undoStackSize.getText()); - //TODO here apply to current app + jcpPanel.getRenderPanel().getUndoManager().setLimit(size); }catch(Exception ex){ JOptionPane.showMessageDialog(this, GT._("Number of undoable operations")+" "+GT._("must be a number from 1 to 100"), GT._("Number of undoable operations"), JOptionPane.WARNING_MESSAGE); } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RenderingParameters.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RenderingParameters.java 2010-03-21 19:30:09 UTC (rev 15492) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RenderingParameters.java 2010-03-22 19:57:41 UTC (rev 15493) @@ -68,6 +68,8 @@ .getJCPProperties().getProperty("ShowAromaticity")); wedgeWidth = Double.parseDouble(JCPPropertyHandler.getInstance(useUserSettings) .getJCPProperties().getProperty("WedgeWidth")); + showReactionBoxes = Boolean.parseBoolean(JCPPropertyHandler.getInstance(useUserSettings) + .getJCPProperties().getProperty("ShowReactionBoxes")); } /** @@ -226,7 +228,7 @@ private boolean showMoleculeTitle = false; - private boolean showReactionBoxes = true; + private boolean showReactionBoxes = false; private boolean showTooltip = false; Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2010-03-21 19:30:09 UTC (rev 15492) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2010-03-22 19:57:41 UTC (rev 15493) @@ -355,3 +355,4 @@ ShowImplicitHydrogens=true DrawNumbers=false WedgeWidth=5.0 +ShowReactionBoxes=false \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-03-24 18:41:49
|
Revision: 15494 http://cdk.svn.sourceforge.net/cdk/?rev=15494&view=rev Author: shk3 Date: 2010-03-24 18:41:41 +0000 (Wed, 24 Mar 2010) Log Message: ----------- The window title is now taken from the JCPGUI_application.properties file, where the property was already in. Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java 2010-03-22 19:57:41 UTC (rev 15493) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java 2010-03-24 18:41:41 UTC (rev 15494) @@ -66,7 +66,7 @@ * @param guiString The string identifying the gui to build (i. e. the properties file to use) * @return The resource string */ - protected String getMenuResourceString(String key, String guiString) { + public String getMenuResourceString(String key, String guiString) { String str; try { str = JCPPropertyHandler.getInstance(true).getGUIDefinition(guiString).getString(key); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2010-03-22 19:57:41 UTC (rev 15493) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2010-03-24 18:41:41 UTC (rev 15494) @@ -120,7 +120,7 @@ } if (gui.equals("application")) { setAppTitle(" - "+ - JCPPropertyHandler.getInstance(true).getJCPProperties().getProperty("Title")); + new JChemPaintMenuHelper().getMenuResourceString("Title", guistring)); } init(); } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2010-03-22 19:57:41 UTC (rev 15493) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2010-03-24 18:41:41 UTC (rev 15494) @@ -95,6 +95,7 @@ import org.openscience.jchempaint.AbstractJChemPaintPanel; import org.openscience.jchempaint.GT; import org.openscience.jchempaint.JCPPropertyHandler; +import org.openscience.jchempaint.JChemPaintMenuHelper; import org.openscience.jchempaint.JChemPaintPanel; import org.openscience.jchempaint.controller.ControllerHub; import org.openscience.jchempaint.controller.undoredo.IUndoRedoFactory; @@ -739,7 +740,8 @@ public static JChemPaintPanel showInstance(IChemModel chemModel, String title, boolean debug) { - JFrame f = new JFrame(title + " - JChemPaint"); + JFrame f = new JFrame(title + " - "+ + new JChemPaintMenuHelper().getMenuResourceString("Title", GUI_APPLICATION)); chemModel.setID(title); f.addWindowListener(new JChemPaintPanel.AppCloser()); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2010-03-31 11:02:27
|
Revision: 15497 http://cdk.svn.sourceforge.net/cdk/?rev=15497&view=rev Author: mark_rynbeek Date: 2010-03-31 11:02:19 +0000 (Wed, 31 Mar 2010) Log Message: ----------- Changes for R-group queries Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java jchempaint/trunk/src/main/org/openscience/jchempaint/JCPTransferHandler.java jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPopupMenu.java jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/SwingPopupModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/ConvertToPseudoAtomAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/HelpAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/NewAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/OpenAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/SaveAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/SaveAsAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/UndoAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/AddBondDragModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/MoveModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/RemoveModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/undoredo/AddAtomsAndBondsEdit.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/undoredo/IUndoRedoFactory.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/undoredo/MergeMoleculesEdit.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/undoredo/RemoveAtomsAndBondsEdit.java jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/FieldTablePanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/ChemObjectPropertyDialog.java jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/PseudoAtomEditor.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/AtomContainerRenderer.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/IRenderer.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/elements/TextElement.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/AtomContainerTitleGenerator.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/BasicBondGenerator.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/visitor/AWTDrawVisitor.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/referenceGuide.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/tutorial.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/jcp.html jchempaint/trunk/src/main/org/openscience/jchempaint/undoredo/SwingMergeMoleculesEdit.java jchempaint/trunk/src/main/org/openscience/jchempaint/undoredo/SwingUndoRedoFactory.java Added Paths: ----------- jchempaint/trunk/src/main/org/openscience/jchempaint/action/RGroupAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/undoredo/RGroupEdit.java jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/RGroupEditor.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/RGroupGenerator.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/large-bin/rdemo1.png jchempaint/trunk/src/main/org/openscience/jchempaint/resources/large-bin/rgroup-config.png jchempaint/trunk/src/main/org/openscience/jchempaint/resources/large-bin/rgroup.png jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/rgroup_tutorial.html jchempaint/trunk/src/main/org/openscience/jchempaint/rgroups/ jchempaint/trunk/src/main/org/openscience/jchempaint/rgroups/RGroupHandler.java jchempaint/trunk/src/main/org/openscience/jchempaint/undoredo/SwingRGroupEdit.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/AbstractJChemPaintPanel.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -101,6 +101,7 @@ protected JMenuItem redoMenu; protected JMenu atomMenu; protected JMenu bondMenu; + protected JMenu rgroupMenu; protected boolean debug=false; protected boolean modified = false; private File isAlreadyAFile; @@ -492,7 +493,7 @@ } /** - * Enables or disables all JMenuItems in a JMenu recursivly. + * Enables or disables all JMenuItems in a JMenu. * * @param root The JMenu to search in. * @param b Enable or disable. @@ -500,7 +501,7 @@ protected void enOrDisableMenus(JMenu root, boolean b) { for(int i=0;i<root.getItemCount();i++){ if(root.getItem(i) instanceof JMenu){ - this.enOrDisableMenus((JMenu)root.getItem(i), b); + ((JMenu)root.getItem(i)).setEnabled(b); }else if(root.getItem(i) instanceof JMenuItem){ ((JMenuItem)root.getItem(i)).setEnabled(b); } @@ -646,13 +647,6 @@ ((JFrame) c).setTitle('*' + id + this.getAppTitle()); else ((JFrame) c).setTitle(id + this.getAppTitle()); -/* - if (title == null) { - title = renderPanel.getChemModel().getID(); - } - if (title.charAt(0) == '*') { - title = title.substring(1); - }*/ } } @@ -663,4 +657,5 @@ public JCPMenuTextMaker getMenuTextMaker() { return menuTextMaker; } + } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -107,7 +107,8 @@ entries.put("createSMILES", GT._("Create SMILES")); entries.put("createInChI", GT._("Create InChI")); entries.put("help", GT._("Help")); - entries.put("tutorial", GT._("Tutorial")); + entries.put("tutorial", GT._("Basic Tutorial")); + entries.put("rgpTutorial", GT._("R-group Tutorial")); entries.put("feedback", GT._("Report Feedback")); entries.put("license", GT._("License")); entries.put("about", GT._("About")); @@ -339,6 +340,19 @@ entries.put("steroids", GT._("Steroids")); entries.put("pahs", GT._("PAHs")); entries.put("language", GT._("Language")); + entries.put("rgroup", GT._("R-groups")); + entries.put("rgroupMenu", GT._("R-groups")); + entries.put("rgroupAtomMenu", GT._("R-group attachment")); + entries.put("rgroupBondMenu", GT._("R-group attachment")); + entries.put("setRoot", GT._("Define as Root Structure")); + entries.put("setSubstitute", GT._("Define as Substituent")); + entries.put("setAtomApoAction1", GT._("Set as first attachment point")); + entries.put("setAtomApoAction2", GT._("Set as second attachment point")); + entries.put("setBondApoAction1", GT._("Set as bond for first attachment point")); + entries.put("setBondApoAction2", GT._("Set as bond for second attachment point")); + entries.put("rgpAdvanced", GT._("Advanced R-group logic")); + entries.put("rgpGenerate", GT._("Generate possible configurations (sdf) ")); + entries.put("clearRgroup", GT._("Remove R-group aspects")); } /** Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPTransferHandler.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPTransferHandler.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPTransferHandler.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -135,7 +135,7 @@ if (clear == JOptionPane.YES_OPTION) { try { IChemModel chemModel = null; - chemModel = JChemPaint.readFromFile(f, null); + chemModel = JChemPaint.readFromFile(f, null, jcpPanel); if (jcpPanel.get2DHub().getUndoRedoFactory() != null && jcpPanel.get2DHub().getUndoRedoHandler() != null) { IUndoRedoable undoredo = jcpPanel.get2DHub() Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -131,6 +131,7 @@ jcpPanel.bondMenu=(JMenu)menu; jcpPanel.enOrDisableMenus((JMenu)menu, false); } + if(key.equals("isotopeChange")){ ((JMenu)menu).addMenuListener(new MenuListener(){ public void menuCanceled(MenuEvent arg0) { Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -82,6 +82,7 @@ import org.openscience.jchempaint.controller.MoveModule; import org.openscience.jchempaint.renderer.RendererModel; import org.openscience.jchempaint.renderer.selection.AbstractSelection; +import org.openscience.jchempaint.renderer.selection.IChemObjectSelection; public class JChemPaintPanel extends AbstractJChemPaintPanel implements IChemModelEventRelayHandler, ICDKChangeListener, KeyListener, IChangeModeListener { @@ -266,19 +267,21 @@ */ public void selectionChanged() { updateStatusBar(); - if(this.getRenderPanel().getRenderer().getRenderer2DModel().getSelection()!=null - && this.getRenderPanel().getRenderer().getRenderer2DModel().getSelection().getConnectedAtomContainer()!=null - && this.getRenderPanel().getRenderer().getRenderer2DModel().getSelection().getConnectedAtomContainer().getAtomCount()>0) - enOrDisableMenus(atomMenu,true); - else - enOrDisableMenus(atomMenu,false); - if(this.getRenderPanel().getRenderer().getRenderer2DModel().getSelection()!=null - && this.getRenderPanel().getRenderer().getRenderer2DModel().getSelection().getConnectedAtomContainer()!=null - && this.getRenderPanel().getRenderer().getRenderer2DModel().getSelection().getConnectedAtomContainer().getBondCount()>0) - enOrDisableMenus(bondMenu,true); - else - enOrDisableMenus(bondMenu,false); - //move focus + + if(this.getRenderPanel().getRenderer().getRenderer2DModel().getSelection()!=null) { + IChemObjectSelection selection = this.getRenderPanel().getRenderer().getRenderer2DModel().getSelection(); + + if (selection.getConnectedAtomContainer()!=null && selection.getConnectedAtomContainer().getAtomCount()>0) + enOrDisableMenus(atomMenu,true); + else + enOrDisableMenus(atomMenu,false); + + if (selection.getConnectedAtomContainer()!=null && selection.getConnectedAtomContainer().getBondCount()>0) + enOrDisableMenus(bondMenu,true); + else + enOrDisableMenus(bondMenu,false); + + } this.requestFocusInWindow(); } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPopupMenu.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPopupMenu.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPopupMenu.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -67,7 +67,10 @@ titleMenuItem.setArmed(false); this.add(titleMenuItem); this.addSeparator(); + this.setLabel(type); menuHelper.createMenu(jcpPanel, type + "popup", true, guiString, this); } + + } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -47,11 +47,9 @@ import javax.swing.undo.UndoManager; import javax.swing.undo.UndoableEdit; -import org.openscience.cdk.config.IsotopeFactory; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IChemModel; -import org.openscience.cdk.interfaces.IMolecularFormula; import org.openscience.cdk.interfaces.IMoleculeSet; import org.openscience.cdk.tools.manipulator.ChemModelManipulator; import org.openscience.cdk.tools.manipulator.MolecularFormulaManipulator; @@ -81,6 +79,7 @@ import org.openscience.jchempaint.renderer.generators.MappingGenerator; import org.openscience.jchempaint.renderer.generators.MergeAtomsGenerator; import org.openscience.jchempaint.renderer.generators.ProductsBoxGenerator; +import org.openscience.jchempaint.renderer.generators.RGroupGenerator; import org.openscience.jchempaint.renderer.generators.RadicalGenerator; import org.openscience.jchempaint.renderer.generators.ReactantsBoxGenerator; import org.openscience.jchempaint.renderer.generators.ReactionArrowGenerator; @@ -205,6 +204,7 @@ if (debug) { generators.add(new AtomContainerBoundsGenerator()); } + generators.add(new RGroupGenerator()); generators.add(new RingGenerator()); generators.add(new ExtendedAtomGenerator()); generators.add(new LonePairGenerator()); @@ -243,6 +243,8 @@ if (isValidChemModel(chemModel)) { Rectangle2D modelBounds = Renderer.calculateBounds(chemModel); Rectangle bounds = renderer.calculateScreenBounds(modelBounds); + bounds.height *=1.1; + bounds.width *=1.1; Image image = GraphicsEnvironment.getLocalGraphicsEnvironment() .getScreenDevices()[0].getDefaultConfiguration() .createCompatibleImage(bounds.width, bounds.height); @@ -336,13 +338,6 @@ if (isNewChemModel) { renderer.setup(chemModel, screen); } - // for (IBond b : - // chemModel.getMoleculeSet().getAtomContainer(0).bonds()){ - // System.out.println("bond "+b.getOrder()+" aromatic "+b.getFlag(CDKConstants.ISAROMATIC)); - // } - // System.out.println("atoms : "+chemModel.getMoleculeSet().getAtomContainer(0).getAtomCount()); - // System.out.println("bonds : "+chemModel.getMoleculeSet().getAtomContainer(0).getBondCount()); - // System.out.println("-----------------------"); Rectangle diagram = renderer.calculateDiagramBounds(chemModel); isNewChemModel = false; @@ -475,8 +470,9 @@ public Rectangle shift(Rectangle screenBounds, Rectangle diagramBounds) { - int screenMaxX = screenBounds.x + screenBounds.width; - int screenMaxY = screenBounds.y + screenBounds.height; + final int LABEL_MARGIN=50; // prevents text or labels from dropping off screen + int screenMaxX = screenBounds.x + screenBounds.width-LABEL_MARGIN; + int screenMaxY = screenBounds.y + screenBounds.height-LABEL_MARGIN; int diagramMaxX = diagramBounds.x + diagramBounds.width; int diagramMaxY = diagramBounds.y + diagramBounds.height; int leftOverlap = screenBounds.x - diagramBounds.x; Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/SwingPopupModule.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/SwingPopupModule.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/SwingPopupModule.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -31,9 +31,13 @@ import java.awt.Rectangle; import java.util.Hashtable; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.MenuElement; import javax.vecmath.Point2d; import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IBond; import org.openscience.cdk.interfaces.IChemObject; import org.openscience.cdk.interfaces.IReactionSet; import org.openscience.cdk.tools.ILoggingTool; @@ -81,7 +85,6 @@ SwingPopupModule.popupMenus.put(someClass.getName(), jchemPaintPopupMenu); } - /** * Returns the popup menu for this IChemObject if it is set, and null * otherwise. @@ -89,12 +92,30 @@ *@param someClass Description of the Parameter *@return The popupMenu value */ - public JChemPaintPopupMenu getPopupMenu(Class classSearched) { + public JChemPaintPopupMenu getPopupMenu(Class classSearched,IChemObject objectInRange) { logger.debug("Searching popup for: ", classSearched.getName()); while (classSearched.getName().startsWith("org.openscience.cdk")) { logger.debug("Searching popup for: ", classSearched.getName()); if (SwingPopupModule.popupMenus.containsKey(classSearched.getName())) { - return (JChemPaintPopupMenu) SwingPopupModule.popupMenus.get(classSearched.getName()); + JChemPaintPopupMenu pop =(JChemPaintPopupMenu) SwingPopupModule.popupMenus.get(classSearched.getName()); + + //R-Group handling: pop up is conditional, only valid for atoms/bond in certain positions + for(int x=0; x<pop.getComponentCount(); x++) { + if (pop.getComponent(x).getName()!=null && pop.getComponent(x).getName().equals("rgroupBondMenu")) { + pop.getComponent(x).setEnabled(false); + if(chemModelRelay.getRGroupHandler()!=null && objectInRange instanceof IBond) { + pop.getComponent(x).setEnabled(chemModelRelay.getRGroupHandler().isRGroupRootBond((IBond)objectInRange)); + } + } + if (pop.getComponent(x).getName()!=null && pop.getComponent(x).getName().equals("rgroupAtomMenu")) { + pop.getComponent(x).setEnabled(false); + if(chemModelRelay.getRGroupHandler()!=null && objectInRange instanceof IAtom) { + pop.getComponent(x).setEnabled(chemModelRelay.getRGroupHandler().isAtomPartOfSubstitute((IAtom)objectInRange)); + } + } + } + return pop; + } else { logger.debug(" recursing into super class"); classSearched = classSearched.getSuperclass(); @@ -131,7 +152,7 @@ if (objectInRange instanceof IAtom) lastAtomPopupedFor = (IAtom)objectInRange; - JChemPaintPopupMenu popupMenu = getPopupMenu(objectInRange.getClass()); + JChemPaintPopupMenu popupMenu = getPopupMenu(objectInRange.getClass(), objectInRange); if (popupMenu != null) { popupMenu.setSource(objectInRange); logger.debug("Set popup menu source to: ", objectInRange); @@ -140,8 +161,7 @@ logger.warn("Popup menu is null! Could not set source!"); } } - - + public String getID() { return ID; } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeAtomSymbolAction.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -132,20 +132,12 @@ newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddAtomModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond()); else newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), IBond.Stereo.NONE); - if(symbol.equals("RX")) { - jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(true); - symbol = JOptionPane.showInputDialog(GT._("Enter label"), "R"); - if (symbol == null) - symbol = "R"; - newActiveModule.setID("RX"); - } else { - jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(false); - newActiveModule.setID(symbol); - } + + jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(false); + newActiveModule.setID(symbol); jcpPanel.get2DHub().getController2DModel().setDrawElement(symbol); jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(0); } - if(symbol!=null && symbol.length()>0){ Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ConvertToPseudoAtomAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ConvertToPseudoAtomAction.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ConvertToPseudoAtomAction.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -39,6 +39,7 @@ import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IBond; import org.openscience.cdk.interfaces.IChemObject; +import org.openscience.cdk.isomorphism.matchers.RGroupQuery; import org.openscience.jchempaint.controller.AddAtomModule; import org.openscience.jchempaint.controller.AddBondDragModule; import org.openscience.jchempaint.GT; @@ -72,12 +73,22 @@ } if(atomsInRange==null) return; - String x = type; + String label = type; if(type.equals("RX")) { - x = JOptionPane.showInputDialog(GT._("Enter label"), "R"); - if (x == null) - x = "R"; + boolean inputOkay=false; + do { + label = JOptionPane.showInputDialog(GT._("Enter label"), "R"); + if (label == null) + return; + if(label.startsWith("R") && label.length()>1 && !RGroupQuery.isValidRgroupQueryLabel(label)) + JOptionPane.showMessageDialog(null, GT._("This is not a valid R-group label.\nPlease label in range R1 .. R32")); + else + inputOkay=true; + } + while (!inputOkay); } + + range: while(atomsInRange.hasNext()){ IAtom atom = atomsInRange.next(); if(type.equals("normal")){ @@ -86,31 +97,19 @@ normal.setSymbol("C"); jcpPanel.get2DHub().replaceAtom(normal,pseudo); }else { - setTo(atom,x); - } + jcpPanel.get2DHub().convertToPseudoAtom(atom,label); + AddAtomModule newActiveModule = new AddAtomModule(jcpPanel.get2DHub(), IBond.Stereo.NONE); + if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddBondDragModule) + newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddBondDragModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond()); + else if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddAtomModule) + newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddAtomModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond()); + newActiveModule.setID(label); + jcpPanel.get2DHub().setActiveDrawModule(newActiveModule); + jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(true); + jcpPanel.get2DHub().getController2DModel().setDrawElement(label); + jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(0); } } jcpPanel.get2DHub().updateView(); } - /** - * Converts atom to a pseudo atom with label and sets active draw module to - * AddAtomModule drawing pseudo atoms with label. - * - * @param atom The atom to convert. - * @param label The label to use. - */ - private void setTo(IAtom atom, String label){ - jcpPanel.get2DHub().convertToPseudoAtom(atom,label); - AddAtomModule newActiveModule = new AddAtomModule(jcpPanel.get2DHub(), IBond.Stereo.NONE); - if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddBondDragModule) - newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddBondDragModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond()); - else if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddAtomModule) - newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddAtomModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond()); - newActiveModule.setID(label); - jcpPanel.get2DHub().setActiveDrawModule(newActiveModule); - jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(true); - jcpPanel.get2DHub().getController2DModel().setDrawElement(label); - jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(0); - - } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/HelpAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/HelpAction.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/HelpAction.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -47,24 +47,32 @@ public void actionPerformed(ActionEvent e) { - - String helpRoot = "org/openscience/jchempaint/resources/userhelp_jcp/"; - String language = GT.getLanguage(); - URL helpURL = HelpDialog.class.getClassLoader().getResource(helpRoot + language + "/jcp.html"); - if (helpURL == null) { - language = "en_US"; - } + + String helpRoot = "org/openscience/jchempaint/resources/userhelp_jcp/"; + String language = GT.getLanguage(); + URL helpURL = HelpDialog.class.getClassLoader().getResource(helpRoot + language + "/jcp.html"); + if (helpURL == null) { + language = "en_US"; + } + if (type.equals("tutorial")) { new HelpDialog(null, helpRoot+language+"/contain/tutorial.html", GT._("JChemPaint Help")).setVisible(true); - } else if (type.equals("feedback")) - { - new HelpDialog(null, helpRoot+language+"/contain/feedback.html", GT._("JChemPaint Help")).setVisible(true); - } else if (type.equals("license")) - { - new HelpDialog(null, helpRoot+language+"/license.html", GT._("JChemPaint License")).setVisible(true); - } else + } + else if (type.equals("rgpTutorial")) { + new HelpDialog(null, helpRoot+language+"/contain/rgroup_tutorial.html", GT._("JChemPaint Help")).setVisible(true); + } + else if (type.equals("feedback")) + { + new HelpDialog(null, helpRoot+language+"/contain/feedback.html", GT._("JChemPaint Help")).setVisible(true); + } + else if (type.equals("license")) + { + new HelpDialog(null, helpRoot+language+"/license.html", GT._("JChemPaint License")).setVisible(true); + } + else + { new HelpDialog(null, helpRoot+language+"/jcp.html", GT._("JChemPaint Help")).setVisible(true); } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/NewAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/NewAction.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/NewAction.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -56,6 +56,7 @@ if (jcpPanel.getGuistring().equals(JChemPaintEditorApplet.GUI_APPLET)) { int clear = jcpPanel.showWarning(); if (clear == JOptionPane.YES_OPTION) { + jcpPanel.get2DHub().unsetRGroupHandler(); jcpPanel.get2DHub().zap(); jcpPanel.get2DHub().updateView(); jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel() Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/OpenAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/OpenAction.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/OpenAction.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -94,11 +94,12 @@ if (clear == JOptionPane.YES_OPTION) { try { IChemModel chemModel = null; + jcpPanel.get2DHub().unsetRGroupHandler(); chemModel = JChemPaint .readFromFileReader(chooser .getSelectedFile().toURI().toURL(), chooser.getSelectedFile().toURI() - .toString(), type); + .toString(), type, jcpPanel); if (jcpPanel.get2DHub().getUndoRedoFactory() != null && jcpPanel.get2DHub().getUndoRedoHandler() != null) { IUndoRedoable undoredo = jcpPanel.get2DHub() Added: jchempaint/trunk/src/main/org/openscience/jchempaint/action/RGroupAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/RGroupAction.java (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/RGroupAction.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -0,0 +1,569 @@ +/* + * Copyright (C) 2010 Mark Rijnbeek + * + * Contact: cdk...@li... + * + * 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.jchempaint.action; + +import java.awt.HeadlessException; +import java.awt.event.ActionEvent; +import java.io.File; +import java.io.FileWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; + +import org.junit.Assert; +import org.openscience.cdk.Atom; +import org.openscience.cdk.CDKConstants; +import org.openscience.cdk.Molecule; +import org.openscience.cdk.MoleculeSet; +import org.openscience.cdk.PseudoAtom; +import org.openscience.cdk.Reaction; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemObject; +import org.openscience.cdk.interfaces.IMoleculeSet; +import org.openscience.cdk.io.SDFWriter; +import org.openscience.cdk.isomorphism.matchers.IRGroupQuery; +import org.openscience.cdk.isomorphism.matchers.RGroup; +import org.openscience.cdk.isomorphism.matchers.RGroupList; +import org.openscience.cdk.isomorphism.matchers.RGroupQuery; +import org.openscience.cdk.tools.manipulator.ChemModelManipulator; +import org.openscience.jchempaint.GT; +import org.openscience.jchempaint.controller.IChemModelRelay; +import org.openscience.jchempaint.controller.undoredo.IUndoRedoable; +import org.openscience.jchempaint.dialog.editor.AtomEditor; +import org.openscience.jchempaint.dialog.editor.BondEditor; +import org.openscience.jchempaint.dialog.editor.ChemObjectEditor; +import org.openscience.jchempaint.dialog.editor.ChemObjectPropertyDialog; +import org.openscience.jchempaint.dialog.editor.PseudoAtomEditor; +import org.openscience.jchempaint.dialog.editor.RGroupEditor; +import org.openscience.jchempaint.dialog.editor.ReactionEditor; +import org.openscience.jchempaint.io.JCPFileView; +import org.openscience.jchempaint.renderer.selection.IChemObjectSelection; +import org.openscience.jchempaint.rgroups.RGroupHandler; + +/** + * Deals with user actions on creating/editing R-groups. + * + */ +public class RGroupAction extends JCPAction { + + private static final long serialVersionUID = 7387274752039316786L; + + /** + * Handles the user action, such as defining a root structure, substitutes, + * attachment atoms and bonds. + * + * @see org.openscience.jchempaint.action.JCPAction#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent event) + { + System.out.println("action iz "+type); + IChemObject eventSource = getSource(event); + + IChemObjectSelection selection = jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel().getSelection(); + if(selection ==null || !selection.isFilled() + &&(type.equals("setRoot")||type.equals("setSubstitute")) ) { + JOptionPane.showMessageDialog(jcpPanel, GT._("You have not selected any atoms or bonds.")); + return; + } + + IChemModelRelay hub = jcpPanel.get2DHub(); + boolean isNewRgroup=false; + RGroupHandler rGroupHandler=null; + Map<IAtom,IAtomContainer> existingAtomDistr = new HashMap<IAtom,IAtomContainer>(); + Map<IBond,IAtomContainer> existingBondDistr= new HashMap<IBond,IAtomContainer>(); + IAtomContainer existingRoot=null; + Map<IAtom, Map<Integer, IBond>> existingRootAttachmentPoints = null; + Map<RGroup, Map<Integer,IAtom>> existingRGroupApo=null; + Map<Integer,RGroupList> existingRgroupLists =null; + + IRGroupQuery rgrpQuery=null; + Molecule molecule=null; + + /* User action: generate possible configurations for the R-group */ + if(type.equals("rgpGenerate")) { + if((jcpPanel.get2DHub().getRGroupHandler()==null)) { + JOptionPane.showMessageDialog(jcpPanel, GT._("Please define an R-group (root and substituents) first.")); + return; + } + try { + JFileChooser chooser = new JFileChooser(); + chooser.setCurrentDirectory(jcpPanel.getCurrentWorkDirectory()); + chooser.setFileView(new JCPFileView()); + chooser.showSaveDialog(jcpPanel); + File outFile = chooser.getSelectedFile(); + System.out.println(outFile); + List<IAtomContainer> molecules= jcpPanel.get2DHub().getRGroupHandler().getrGroupQuery().getAllConfigurations(); + IMoleculeSet molSet = new MoleculeSet(); + for (IAtomContainer mol : molecules) { + molSet.addAtomContainer(mol); + } + SDFWriter sdfWriter = new SDFWriter(new FileWriter(outFile)); + sdfWriter.write(molSet); + sdfWriter.close(); + + } catch (Exception e) { + e.printStackTrace(); + JOptionPane.showMessageDialog(jcpPanel, GT._("There was an error generating the configurations {0}",e.getMessage())); + return; + } + + } + /* User action: advanced R-group logic */ + else if(type.equals("rgpAdvanced")) { + + if((jcpPanel.get2DHub().getRGroupHandler()==null)) { + JOptionPane.showMessageDialog(jcpPanel, GT._("Please define an R-group (root and substituent) first.")); + return; + } + jcpPanel.get2DHub().getRGroupHandler().cleanUpRGroup(jcpPanel.get2DHub().getChemModel().getMoleculeSet()); + ChemObjectEditor editor = new RGroupEditor(hub); + editor.setChemObject((org.openscience.cdk.ChemObject)hub.getRGroupHandler().getrGroupQuery()); + ChemObjectPropertyDialog frame = new ChemObjectPropertyDialog(JOptionPane.getFrameForComponent(editor), jcpPanel.get2DHub(),editor); + frame.pack(); + frame.setVisible(true); + jcpPanel.get2DHub().updateView(); + } + + + //FOLLOWING actions involve undo/redo + + else + { + + /* User action: generate possible configurations for the R-group */ + if(type.equals("clearRgroup")) { + if((jcpPanel.get2DHub().getRGroupHandler()==null)) { + JOptionPane.showMessageDialog(jcpPanel, GT._("There is no R-group defined")); + return; + } + rGroupHandler=hub.getRGroupHandler(); + hub.unsetRGroupHandler(); + jcpPanel.get2DHub().updateView(); + + } + + /* User has indicated that a certain atom in a substituent needs to become attachment point 1 or 2 */ + else if (type.startsWith("setAtomApoAction")) { + rGroupHandler=hub.getRGroupHandler(); + IAtom apoAtom = (IAtom) eventSource; + apoLoop: + for (Iterator<Integer> rnumItr=rGroupHandler.getrGroupQuery().getRGroupDefinitions().keySet().iterator(); rnumItr.hasNext();) { + for (RGroup rgrp: rGroupHandler.getrGroupQuery().getRGroupDefinitions().get(rnumItr.next()).getRGroups()) { + if(rgrp.getGroup().contains(apoAtom)) { + existingRGroupApo= new HashMap <RGroup,Map<Integer,IAtom>>(); + HashMap<Integer,IAtom> map = new HashMap<Integer,IAtom>(); + map.put(1, rgrp.getFirstAttachmentPoint()); + map.put(2, rgrp.getSecondAttachmentPoint()); + existingRGroupApo.put(rgrp,map); + + boolean firstApo = type.endsWith("1"); + if (firstApo) { + rgrp.setFirstAttachmentPoint(apoAtom); + } + else { + rgrp.setSecondAttachmentPoint(apoAtom); + } + break apoLoop; + } + } + } + } + + /* User action : certain bond in the root needs to become attachment bond 1 or 2 */ + else if (type.startsWith("setBondApoAction")) { + rGroupHandler=hub.getRGroupHandler(); + IBond apoBond = (IBond) eventSource; + Map<Integer, IBond> apoBonds=null; + + //Undo/redo business______ + IAtom pseudo=null; + if (apoBond.getAtom(0) instanceof PseudoAtom) + pseudo=apoBond.getAtom(0); + else + pseudo=apoBond.getAtom(1); + Map<Integer, IBond> keepApoBonds = new HashMap<Integer, IBond>(); + if (rGroupHandler.getrGroupQuery().getRootAttachmentPoints()!=null && + rGroupHandler.getrGroupQuery().getRootAttachmentPoints().get(pseudo)!=null) { + apoBonds= rGroupHandler.getrGroupQuery().getRootAttachmentPoints().get(pseudo); + for (Iterator<Integer> apoItr =apoBonds.keySet().iterator(); apoItr.hasNext();) { + int apoNum=apoItr.next(); + keepApoBonds.put(apoNum,apoBonds.get(apoNum)); + } + } + existingRootAttachmentPoints = new HashMap<IAtom, Map<Integer, IBond>>(); + existingRootAttachmentPoints.put(pseudo, keepApoBonds); + //________________________ + + + //Set the new Root APO + if (rGroupHandler.getrGroupQuery().getRootAttachmentPoints()==null) { + rGroupHandler.getrGroupQuery().setRootAttachmentPoints(new HashMap<IAtom, Map<Integer, IBond>>()); + } + Map<IAtom, Map<Integer, IBond>> rootApo=rGroupHandler.getrGroupQuery().getRootAttachmentPoints(); + if (rootApo.get(pseudo)==null) { + apoBonds=new HashMap<Integer,IBond>(); + rootApo.put(pseudo, apoBonds); + } + else + apoBonds=rGroupHandler.getrGroupQuery().getRootAttachmentPoints().get(pseudo); + + if (type.endsWith("1")) { + apoBonds.put(1, apoBond); + if (apoBonds.get(2)!=null && apoBonds.get(2).equals(apoBond)) + apoBonds.remove(2); + } + if (type.endsWith("2")) { + apoBonds.put(2, apoBond); + if (apoBonds.get(1)!=null && apoBonds.get(1).equals(apoBond)) + apoBonds.remove(1); + } + + } + + + /* User action: certain atom+bond selection is to be the root structure. */ + else if (type.equals("setRoot")) { + + IAtomContainer atc =selection.getConnectedAtomContainer(); + if (!isProperSelection(atc)) { + JOptionPane.showMessageDialog(jcpPanel, GT._("Please do not make a fragmented selection.")); + return; + } + + molecule = createMolecule (atc,existingAtomDistr,existingBondDistr); + hub.getChemModel().getMoleculeSet().addAtomContainer(molecule); + + if (hub.getRGroupHandler() == null) { + isNewRgroup=true; + rgrpQuery = newRGroupQuery(); + rGroupHandler = new RGroupHandler(rgrpQuery); + hub.setRGroupHandler(rGroupHandler); + } + else { + rGroupHandler=hub.getRGroupHandler(); + rgrpQuery = hub.getRGroupHandler().getrGroupQuery(); + if(rgrpQuery.getRootStructure()!=null) { + existingRoot=rgrpQuery.getRootStructure(); + rgrpQuery.getRootStructure().removeProperty(CDKConstants.TITLE); + } + } + molecule.setProperty(CDKConstants.TITLE,RGroup.ROOT_LABEL); + rgrpQuery.setRootStructure(molecule); + + //Remove old root apo's + existingRootAttachmentPoints = rgrpQuery.getRootAttachmentPoints(); + rgrpQuery.setRootAttachmentPoints(null); + + //Define new root apo's + Map<IAtom, Map<Integer, IBond>> apoBonds= new HashMap<IAtom, Map<Integer, IBond>>(); + for (IAtom atom : molecule.atoms()) { + if (atom instanceof PseudoAtom) { + PseudoAtom pseudo = (PseudoAtom)atom; + if (pseudo.getLabel()!=null && RGroupQuery.isValidRgroupQueryLabel(pseudo.getLabel())) { + chooseRootAttachmentBonds(pseudo,molecule,apoBonds); + } + } + } + rgrpQuery.setRootAttachmentPoints(apoBonds); + + } + + /* User action: certain atom+bond selection is to be a substituent. */ + else if (type.equals("setSubstitute")) { + + if (hub.getRGroupHandler() == null || hub.getRGroupHandler().getrGroupQuery()==null || + hub.getRGroupHandler().getrGroupQuery().getRootStructure()==null) { + JOptionPane.showMessageDialog(jcpPanel, GT._("Please define a root structure first.")); + return; + } + + IAtomContainer atc =selection.getConnectedAtomContainer(); + if (!isProperSelection(atc)) { + JOptionPane.showMessageDialog(jcpPanel, GT._("Please do not make a fragmented selection.")); + return; + } + + // Check - are there any R-groups -> collect them so that user input can be validated + Map<Integer,Integer> validRnumChoices=new HashMap<Integer,Integer>(); + for (IAtom atom : hub.getRGroupHandler().getrGroupQuery().getRootStructure().atoms()) { + if (atom instanceof PseudoAtom) { + PseudoAtom pseudo = (PseudoAtom)atom; + if (pseudo.getLabel()!=null && RGroupQuery.isValidRgroupQueryLabel(pseudo.getLabel())) { + int bondCnt=0; + int rNum=new Integer(pseudo.getLabel().substring(1)); + for (IBond b : hub.getRGroupHandler().getrGroupQuery().getRootStructure().bonds()) + if (b.contains(atom)) + bondCnt++; + + if ((!validRnumChoices.containsKey(rNum))|| + validRnumChoices.containsKey(rNum)&& validRnumChoices.get(rNum)<bondCnt) + validRnumChoices.put(rNum,bondCnt); + } + } + } + // Here we test: the user wants to define a substitute, but are there any R1..R32 groups to begin with? + if (validRnumChoices.size()==0) { + JOptionPane.showMessageDialog(jcpPanel, GT._("There are no numbered R-atoms in the root structure to refer to.")); + return; + } + + //Now get user input to determine which R# atom to hook up with the substituent + boolean inputOkay=false; + String userInput=null; + Integer rNum=0; + do { + userInput = JOptionPane.showInputDialog(GT._("Enter an R-group number "),validRnumChoices.get(0)); + if (userInput == null) + return; + try { + rNum = new Integer(userInput); + if(!validRnumChoices.containsKey(rNum)) + JOptionPane.showMessageDialog(null, GT._("The number you entered has no corresponding R-group in the root.")); + else + inputOkay=true; + } catch (NumberFormatException e) { + JOptionPane.showMessageDialog(null, GT._("This is not a valid R-group label.\nPlease label in range R1 .. R32")); + } + } + while (!inputOkay); + rGroupHandler=hub.getRGroupHandler(); + + rgrpQuery = hub.getRGroupHandler().getrGroupQuery(); + if (rgrpQuery.getRGroupDefinitions()==null) { + rgrpQuery.setRGroupDefinitions(new HashMap<Integer, RGroupList>()); + } + + if (rgrpQuery.getRGroupDefinitions().get(rNum)==null) { + RGroupList rList = new RGroupList(rNum); + rList.setRGroups(new ArrayList<RGroup>()); + rgrpQuery.getRGroupDefinitions().put(rNum, rList); + } + + molecule = createMolecule (atc,existingAtomDistr,existingBondDistr); + existingRgroupLists = new HashMap<Integer,RGroupList>(); + + // Now see if the user's choice for a substituent has overlaps with already defined existing + // substitutes. If so, these existing ones get thrown out (we can't have multiple substituents + // defined for the same atoms. + for(Iterator<Integer> itr=rgrpQuery.getRGroupDefinitions().keySet().iterator();itr.hasNext();) { + int rgrpNum=itr.next(); + RGroupList rgrpList = rgrpQuery.getRGroupDefinitions().get(rgrpNum); + if(rgrpList!=null) { + existingRgroupLists.put(rgrpNum, makeClone(rgrpList)); + List<RGroup> cleanList = new ArrayList<RGroup>(); + for (int j=0; j<rgrpList.getRGroups().size(); j++){ + RGroup subst= rgrpList.getRGroups().get(j); + boolean remove=false; + removeCheck: + for(IAtom atom : molecule.atoms()) { + if (subst.getGroup().contains(atom)) { + remove=true; + break removeCheck; + } + } + if (!remove) { + cleanList.add(subst); + } + } + rgrpList.setRGroups(cleanList); + } + } + + hub.getChemModel().getMoleculeSet().addAtomContainer(molecule); + molecule.setProperty(CDKConstants.TITLE,RGroup.makeLabel(rNum)); + + RGroup rgrp = new RGroup(); + rgrp.setGroup(molecule); + rgrpQuery.getRGroupDefinitions().get(rNum).getRGroups().add(rgrp); + + //Set default APO atoms (randomly picked) for the new substitute + int apoCount=validRnumChoices.get(rNum); + int apoSet=0; + apoBreak: + for(IAtom atom : molecule.atoms()) { + if (apoSet==apoCount) + break apoBreak; + if (apoSet==0) { + rgrp.setFirstAttachmentPoint(atom); + } + if (apoSet==1) { + rgrp.setSecondAttachmentPoint(atom); + } + apoSet++; + } + } + + + if (hub.getUndoRedoFactory() != null && jcpPanel.get2DHub().getUndoRedoHandler() != null) { + IUndoRedoable undoredo = jcpPanel.get2DHub().getUndoRedoFactory().getRGroupEdit + ( type, isNewRgroup, hub,rGroupHandler, existingAtomDistr, existingBondDistr, + existingRoot, existingRootAttachmentPoints, existingRGroupApo, existingRgroupLists,molecule); + jcpPanel.get2DHub().getUndoRedoHandler().postEdit(undoredo); + } + + jcpPanel.get2DHub().updateView(); + } + } + + /** + * Initializes an empty RGroupQuery. + * + * @return a new empty RGroupQuery + */ + private IRGroupQuery newRGroupQuery() { + IRGroupQuery rgrpQuery = new RGroupQuery(); + rgrpQuery.setRootStructure(new Molecule()); + rgrpQuery + .setRootAttachmentPoints(new HashMap<IAtom, Map<Integer, IBond>>()); + rgrpQuery.setRGroupDefinitions(new HashMap<Integer, RGroupList>()); + return rgrpQuery; + } + + /** + * Chooses (picks) one or more attachment bonds for a (new) R# atom that is + * a root member. + * + * @param rAtom + * @param root + * @param rootAttachmentPoints + */ + private void chooseRootAttachmentBonds(IAtom rAtom, IAtomContainer root, + Map<IAtom, Map<Integer, IBond>> rootAttachmentPoints) { + int apoIdx = 1; + Map<Integer, IBond> apoBonds = new HashMap<Integer, IBond>(); + Iterator<IBond> bonds = root.bonds().iterator(); + // Pick up to two apo bonds randomly + while (bonds.hasNext() && apoIdx <= 2) { + IBond bond = bonds.next(); + if (bond.contains(rAtom)) { + apoBonds.put((apoIdx), bond); + apoIdx++; + } + } + rootAttachmentPoints.put(rAtom, apoBonds); + } + + /** + * Determines if a user has made a proper selection for R-Group + * manipulation. Proper means: make a selection that includes all + * atoms/bonds that are bound together in a structure, not leaving any + * orphans dangling. + * + * @param atc + * @return + */ + private boolean isProperSelection(IAtomContainer atc) { + boolean properSelection = true; + completeSelection: for (IAtom atom : atc.atoms()) { + + IAtomContainer modelAtc = ChemModelManipulator + .getRelevantAtomContainer(jcpPanel.getChemModel(), atom); + List<IAtom> connectedAtoms = new ArrayList<IAtom>(); + findConnectedAtoms(atom, modelAtc, connectedAtoms); + for (IAtom modelAt : connectedAtoms) { + if (!atc.contains(modelAt)) { + properSelection = false; + break completeSelection; + } + } + } + return properSelection; + } + + /** + * Starting from start point atom, finds all other atoms connected to it by + * traversing a graph. Used to determine a proper selection. + * + * @param atom + * @param atc + * @param result + */ + private void findConnectedAtoms(IAtom atom, IAtomContainer atc, + List<IAtom> result) { + result.add(atom); + for (IBond bond : atc.bonds()) { + if (bond.contains(atom)) { + if (!result.contains(bond.getConnectedAtom(atom))) { + findConnectedAtoms(bond.getConnectedAtom(atom), atc, result); + } + } + } + } + + /** + * Creates a new molecule based on a user selection, and removes the + * selected atoms/bonds from the atom container where they are currently in. + */ + private Molecule createMolecule(IAtomContainer atc, + Map<IAtom, IAtomContainer> existingAtomDistr, + Map<IBond, IAtomContainer> existingBondDistr) { + for (IAtom atom : atc.atoms()) { + IAtomContainer original = ChemModelManipulator + .getRelevantAtomContainer(jcpPanel.getChemModel(), atom); + existingAtomDistr.put(atom, original); + original.removeAtom(atom); + } + for (IBond bond : atc.bonds()) { + IAtomContainer original = ChemModelManipulator + .getRelevantAtomContainer(jcpPanel.getChemModel(), bond); + existingBondDistr.put(bond, original); + original.removeBond(bond); + } + Molecule molecule = new Molecule(); + molecule.add(atc); + return molecule; + } + + /** + * Clones an RGroupList + * + * @param original + * @return + */ + private static RGroupList makeClone(RGroupList original) { + RGroupList clone = new RGroupList(original.getRGroupNumber()); + try { + clone.setOccurrence(original.getOccurrence()); + clone.setRequiredRGroupNumber(original.getRequiredRGroupNumber()); + clone.setRestH(original.isRestH()); + List<RGroup> rgpList = new ArrayList<RGroup>(); + for (RGroup r : original.getRGroups()) { + rgpList.add(r); + } + clone.setRGroups(rgpList); + } catch (CDKException e) { + e.printStackTrace(); + } + return clone; + } +} Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/SaveAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/SaveAction.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/SaveAction.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -33,6 +33,8 @@ import javax.swing.JOptionPane; +import org.openscience.cdk.isomorphism.matchers.IRGroupQuery; +import org.openscience.cdk.isomorphism.matchers.RGroupQuery; import org.openscience.jchempaint.AbstractJChemPaintPanel; import org.openscience.jchempaint.io.JCPFileFilter; import org.openscience.jchempaint.io.JCPSaveFileFilter; @@ -52,7 +54,7 @@ } /** - * Constructor for the SaveAsAction object + * Constructor for the SaveAction object * *@param jcpPanel Description of the Parameter *@param isPopupAction Description of the Parameter Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/SaveAsAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/SaveAsAction.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/SaveAsAction.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -42,25 +42,23 @@ import org.openscience.cdk.exception.CDKException; import org.openscience.cdk.interfaces.IAtomContainer; -import org.openscience.cdk.interfaces.IAtomContainerSet; -import org.openscience.cdk.interfaces.IChemFile; import org.openscience.cdk.interfaces.IChemModel; import org.openscience.cdk.interfaces.IChemObject; -import org.openscience.cdk.interfaces.IChemSequence; import org.openscience.cdk.interfaces.IMoleculeSet; import org.openscience.cdk.io.CDKSourceCodeWriter; import org.openscience.cdk.io.CMLWriter; import org.openscience.cdk.io.IChemObjectWriter; import org.openscience.cdk.io.MDLRXNWriter; import org.openscience.cdk.io.MDLWriter; +import org.openscience.cdk.io.RGroupQueryWriter; import org.openscience.cdk.io.SMILESWriter; import org.openscience.cdk.io.listener.SwingGUIListener; +import org.openscience.cdk.isomorphism.matchers.IRGroupQuery; import org.openscience.cdk.tools.manipulator.ChemModelManipulator; import org.openscience.jchempaint.AbstractJChemPaintPanel; import org.openscience.jchempaint.GT; import org.openscience.jchempaint.JCPPropertyHandler; import org.openscience.jchempaint.JChemPaintPanel; -import org.openscience.jchempaint.application.JChemPaint; import org.openscience.jchempaint.inchi.StdInChIGenerator; import org.openscience.jchempaint.io.IJCPFileFilter; import org.openscience.jchempaint.io.JCPFileView; @@ -264,6 +262,7 @@ protected File saveAsMol(IChemModel model, File outFile) throws Exception { logger.info("Saving the contents in a MDL molfile file..."); + if(model.getMoleculeSet()==null || model.getMoleculeSet().getAtomContainerCount()==0){ String error = GT._("Problems handling data"); String message = GT._("MDL mol files can only save molecules. You have no molecules painted!"); @@ -277,14 +276,54 @@ if(answer == JOptionPane.NO_OPTION) return null; } + boolean saveAsRgrpQuery=false; + IRGroupQuery rGroupQuery = null; + if(jcpPanel.get2DHub().getRGroupHandler()!=null) + rGroupQuery= jcpPanel.get2DHub().getRGroupHandler().getrGroupQuery(); + + if(rGroupQuery!=null){ + String error = GT._("Please choose a file type!"); + String message = GT._("Would you like to save the drawing as an R-group Query File? (RGFile = extended MOLfile)"); + int answer = JOptionPane.showConfirmDialog(jcpPanel, message, error, JOptionPane.YES_NO_OPTION); + if(answer == JOptionPane.YES_OPTION) + saveAsRgrpQuery=true; + } + String fileName = outFile.toString(); if (!fileName.endsWith(".mol")) { fileName += ".mol"; outFile = new File(fileName); } outFile=new File(fileName); - cow = new MDLWriter(new FileWriter(outFile)); - cow.write(model); + + if(saveAsRgrpQuery) { + cow = new RGroupQueryWriter(new FileWriter(outFile)); + + boolean problem=false; + String message=""; + jcpPanel.get2DHub().getRGroupHandler().cleanUpRGroup(jcpPanel.get2DHub().getChemModel().getMoleculeSet()); + + if(!rGroupQuery.areRootAtomsDefined()) { + message = GT._("The R-group Query is not valid: there are substitutes that have no corresponding atom in the root structure."); + problem=true; + } + if(!rGroupQuery.areSubstituentsDefined()) { + message = GT._("The R-group Query is not valid: the root structure has R# definitions for which no substitutes are defined."); + problem=true; + } + if (problem) { + String error = GT._("Could not save file"); + JOptionPane.showMessageDialog(jcpPanel, message, GT._(error), JOptionPane.INFORMATION_MESSAGE); + return null; + } + + cow.write(rGroupQuery); + } + else { + cow = new MDLWriter(new FileWriter(outFile)); + cow.write(model); + } + cow.close(); if(jcpPanel instanceof JChemPaintPanel) Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/UndoAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/UndoAction.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/UndoAction.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -30,6 +30,7 @@ import java.awt.event.ActionEvent; +import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.jchempaint.renderer.selection.IChemObjectSelection; import org.openscience.jchempaint.renderer.selection.LogicalSelection; import org.openscience.jchempaint.renderer.selection.RectangleSelection; Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2010-03-25 14:51:21 UTC (rev 15496) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2010-03-31 11:02:19 UTC (rev 15497) @@ -168,7 +168,7 @@ theJcpp.announceError(exception); } if (fileURL != null) - loadModelFromUrl(fileURL); + loadModelFromUrl(fileURL, theJcpp); if (smiles != null) loadModelFromSmiles(smiles); } @@ -217,10 +217,10 @@ * * @param fileURL */ - public void loadModelFromUrl(URL fileURL) { + public void loadModelFromUrl(URL fileURL, AbstractJChemPaintPanel panel) { try { IChemModel chemModel = JChemPaint.readFromFileReader(fileURL, - fileURL.toString(), null); + ... [truncated message content] |
From: <sh...@us...> - 2010-04-08 15:46:22
|
Revision: 15505 http://cdk.svn.sourceforge.net/cdk/?rev=15505&view=rev Author: shk3 Date: 2010-04-08 15:46:16 +0000 (Thu, 08 Apr 2010) Log Message: ----------- Added the posibility to make a reaction by drawing an arrow (it is still chemically aware and no arrow is saved or so) Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties Added Paths: ----------- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/PhantomArrowGenerator.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2010-04-07 15:03:30 UTC (rev 15504) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2010-04-08 15:46:16 UTC (rev 15505) @@ -240,6 +240,7 @@ entries.put("pseudoR3", GT._("R3")); entries.put("pseudoR4", GT._("R4")); entries.put("bondToolTooltip", GT._("Draw Bonds and Atoms")); + entries.put("reactionArrowTooltip", GT._("Makes a Reaction by Drawing a Reaction Arrow")); entries.put("double_bondToolTooltip", GT._("Draw Double Bonds")); entries.put("triple_bondToolTooltip", GT._("Draw Triple Bonds")); entries.put("cyclesymbolTooltip", GT._("Change the Atom's Symbol")); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java 2010-04-07 15:03:30 UTC (rev 15504) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java 2010-04-08 15:46:16 UTC (rev 15505) @@ -34,9 +34,9 @@ import org.openscience.jchempaint.controller.AtomAtomMappingModule; import org.openscience.jchempaint.controller.ControllerHub; import org.openscience.jchempaint.controller.IControllerModule; -import org.openscience.jchempaint.controller.MoveModule; +import org.openscience.jchempaint.controller.ReactionArrowModule; +import org.openscience.jchempaint.controller.Rotate3DModule; import org.openscience.jchempaint.controller.RotateModule; -import org.openscience.jchempaint.controller.Rotate3DModule; import org.openscience.jchempaint.controller.SelectLassoModule; import org.openscience.jchempaint.controller.SelectSquareModule; @@ -85,6 +85,8 @@ newActiveModule=new RotateModule(hub); } else if (type.equals("rotate3d")) { newActiveModule=new Rotate3DModule(hub); + } else if (type.equals("reactionArrow")) { + newActiveModule=new ReactionArrowModule(hub); } if(newActiveModule!=null){ newActiveModule.setID(type); Added: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/PhantomArrowGenerator.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/PhantomArrowGenerator.java (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/PhantomArrowGenerator.java 2010-04-08 15:46:16 UTC (rev 15505) @@ -0,0 +1,72 @@ +/* $Revision: $ $Author: $ $Date$ + * + * Copyright (C) 2009 Stefan Kuhn <ste...@eb...> + * + * Contact: cdk...@li... + * + * 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 I ask is that proper credit is given for my 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.jchempaint.controller; + +import java.awt.Color; +import java.util.List; + +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IReaction; +import org.openscience.jchempaint.renderer.RendererModel; +import org.openscience.jchempaint.renderer.elements.ArrowElement; +import org.openscience.jchempaint.renderer.elements.ElementGroup; +import org.openscience.jchempaint.renderer.elements.IRenderingElement; +import org.openscience.jchempaint.renderer.generators.IGenerator; +import org.openscience.jchempaint.renderer.generators.IGeneratorParameter; +import org.openscience.jchempaint.renderer.generators.ReactionArrowGenerator; + +/** + * Draws a phantom arrow in ControllerHub + */ +public class PhantomArrowGenerator implements IGenerator{ + + ControllerHub hub; + + + public PhantomArrowGenerator(){ + + } + + public void setControllerHub(ControllerHub hub) { + this.hub = hub; + } + + public IRenderingElement generate(IAtomContainer ac, RendererModel model) { + if(hub.getPhantomArrow()[0]==null || hub.getPhantomArrow()[1]==null) + return new ElementGroup(); + else + return new ArrowElement(hub.getPhantomArrow()[0].x, + hub.getPhantomArrow()[0].y, + hub.getPhantomArrow()[1].x, + hub.getPhantomArrow()[1].y, + 1 / model.getScale(),true, + Color.GRAY); + } + + public List<IGeneratorParameter> getParameters() { + // TODO Auto-generated method stub + return null; + } +} Added: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java 2010-04-08 15:46:16 UTC (rev 15505) @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2009 Stefan Kuhn <sh...@us...> + * + * Contact: cdk...@li... + * + * 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 I ask is that proper credit is given for my 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.jchempaint.controller; + +import javax.vecmath.Point2d; + +import org.openscience.cdk.geometry.BondTools; +import org.openscience.cdk.interfaces.IMoleculeSet; +import org.openscience.cdk.interfaces.IReaction; +import org.openscience.cdk.interfaces.IReactionSet; +import org.openscience.cdk.tools.ILoggingTool; +import org.openscience.cdk.tools.LoggingToolFactory; + + +public class ReactionArrowModule extends ControllerModuleAdapter { + + protected static ILoggingTool logger = + LoggingToolFactory.createLoggingTool(ReactionArrowModule.class); + Point2d startPoint=null; + protected String ID; + + /** + * Constructor + * @param chemModelRelay + */ + public ReactionArrowModule(IChemModelRelay chemModelRelay) { + super(chemModelRelay); + logger.debug("constructor"); + } + + @Override + public void mouseClickedDown(Point2d worldCoordFrom) { + startPoint=worldCoordFrom; + } + + @Override + public void mouseClickedUp(Point2d worldCoord) { + //for each molecule, we need to look if the majority of + // its atoms are to the left or right or on the arrow + IMoleculeSet moleculeSet = super.chemModelRelay.getChemModel().getMoleculeSet(); + if(moleculeSet.getAtomContainerCount()==0) + return; + //calculate a second point on the perpendicular through start point + double angle = Math.PI/2; + double costheta = Math.cos(angle); + double sintheta = Math.sin(angle); + Point2d point = new Point2d(worldCoord); + Point2d center = new Point2d(startPoint); + double relativex = point.x - center.x; + double relativey = point.y - center.y; + Point2d secondOnStartPerpendicular = new Point2d(); + secondOnStartPerpendicular.x = relativex * costheta - relativey * sintheta + center.x; + secondOnStartPerpendicular.y = relativex * sintheta + relativey * costheta + center.y; + //and on the perpendicular through the end + point = new Point2d(startPoint); + center = new Point2d(worldCoord); + relativex = point.x - center.x; + relativey = point.y - center.y; + Point2d secondOnEndPerpendicular = new Point2d(); + secondOnEndPerpendicular.x = relativex * costheta - relativey * sintheta + center.x; + secondOnEndPerpendicular.y = relativex * sintheta + relativey * costheta + center.y; + IReactionSet reactionSet = super.chemModelRelay.getChemModel().getReactionSet(); + if (reactionSet == null) + { + reactionSet = super.chemModelRelay.getChemModel().getBuilder().newReactionSet(); + super.chemModelRelay.getChemModel().setReactionSet(reactionSet); + } + IReaction reaction = moleculeSet.getBuilder().newReaction(); + reactionSet.addReaction(reaction); + reaction.setID("reaction-" + System.currentTimeMillis()); + for(int i=moleculeSet.getAtomContainerCount()-1;i>=0;i--){ + int left=0; + int right=0; + for(int k=0;k<moleculeSet.getAtomContainer(i).getAtomCount();k++){ + if(BondTools.giveAngleBothMethods(startPoint, secondOnStartPerpendicular, moleculeSet.getAtomContainer(i).getAtom(k).getPoint2d(), false)<0) + right++; + else + left++; + } + int leftend=0; + int rightend=0; + for(int k=0;k<moleculeSet.getAtomContainer(i).getAtomCount();k++){ + if(BondTools.giveAngleBothMethods(secondOnEndPerpendicular, worldCoord, moleculeSet.getAtomContainer(i).getAtom(k).getPoint2d(), false)<0) + rightend++; + else + leftend++; + } + if(left>right){ + //is a reactant + ReactionHub.makeReactantInExistingReaction((ControllerHub)super.chemModelRelay, reaction.getID(), moleculeSet.getAtomContainer(i), moleculeSet.getAtomContainer(i)); + } if(rightend>leftend){ + //is a product + ReactionHub.makeProductInExistingReaction((ControllerHub)super.chemModelRelay, reaction.getID(), moleculeSet.getAtomContainer(i), moleculeSet.getAtomContainer(i)); + } else { + //is a catalyst + //TODO catalysts in general + } + } + chemModelRelay.setPhantomArrow(null, null); + } + + /** + * On mouse drag, quasi-3D rotation around the center is done + * (It isn't real 3D rotation because of truncation of transformation + * matrix to 2x2) + */ + @Override + public void mouseDrag(Point2d worldCoordFrom, Point2d worldCoordTo) { + chemModelRelay.setPhantomArrow(startPoint, worldCoordTo); + chemModelRelay.updateView(); + } + public String getDrawModeString() { + return "Draw a reaction Arrow"; + } + + + public String getID() { + return ID; + } + + public void setID(String ID) { + this.ID=ID; + } +} Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties 2010-04-07 15:03:30 UTC (rev 15504) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties 2010-04-08 15:46:16 UTC (rev 15505) @@ -108,4 +108,4 @@ cut copy paste flipHorizontal flipVertical rotate rotate3d lowertoolbar=C H O N P S F Cl Br I enterelement periodictable plus minus righttoolbar=triangle square pentagon hexagon benzene octagon pasteTemplate -lefttoolbar=bondTool up_bond down_bond undefined_bond undefined_stereo_bond +lefttoolbar=bondTool up_bond down_bond undefined_bond undefined_stereo_bond reactionArrow Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties 2010-04-07 15:03:30 UTC (rev 15504) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties 2010-04-08 15:46:16 UTC (rev 15505) @@ -121,4 +121,4 @@ rotate rotate3d flipHorizontal flipVertical cleanup zoomin zoomout lowertoolbar=C H O N P S F Cl Br I enterR plus minus enterelement periodictable righttoolbar=triangle square pentagon hexagon benzene octagon pasteTemplate -lefttoolbar=bondTool double_bondTool triple_bondTool up_bond down_bond undefined_bond undefined_stereo_bond +lefttoolbar=bondTool double_bondTool triple_bondTool up_bond down_bond undefined_bond undefined_stereo_bond reactionArrow Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2010-04-07 15:03:30 UTC (rev 15504) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2010-04-08 15:46:16 UTC (rev 15505) @@ -46,6 +46,7 @@ double_bondToolImage=resources/small-bin/doubleBond.gif triple_bondToolImage=resources/small-bin/tripleBond.gif quad_bondToolImage=resources/small-bin/quadBond.gif +reactionArrowImage=resources/small-bin/reactionArrow.gif lassoImage=resources/small-bin/lasso.png selectImage=resources/small-bin/selectsquare.png eraserImage=resources/small-bin/eraser.gif @@ -341,6 +342,7 @@ atomatommappingAction=org.openscience.jchempaint.action.ChangeModeAction@atomatommapping rotateAction=org.openscience.jchempaint.action.ChangeModeAction@rotate rotate3dAction=org.openscience.jchempaint.action.ChangeModeAction@rotate3d +reactionArrowAction=org.openscience.jchempaint.action.ChangeModeAction@reactionArrow ####################################################### # Default settings for JChemPaint # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-04-09 09:22:57
|
Revision: 15507 http://cdk.svn.sourceforge.net/cdk/?rev=15507&view=rev Author: shk3 Date: 2010-04-09 09:22:50 +0000 (Fri, 09 Apr 2010) Log Message: ----------- Added the posibility to make a reaction by drawing an arrow (it is still chemically aware and no arrow is saved or so) Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java 2010-04-08 16:07:03 UTC (rev 15506) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java 2010-04-09 09:22:50 UTC (rev 15507) @@ -59,6 +59,7 @@ import org.openscience.jchempaint.controller.ControllerModel; import org.openscience.jchempaint.controller.IControllerModule; import org.openscience.jchempaint.controller.IViewEventRelay; +import org.openscience.jchempaint.controller.PhantomArrowGenerator; import org.openscience.jchempaint.controller.PhantomBondGenerator; import org.openscience.jchempaint.controller.SwingMouseEventRelay; import org.openscience.jchempaint.controller.undoredo.IUndoListener; @@ -118,6 +119,8 @@ private boolean debug = false; private PhantomBondGenerator pbg = new PhantomBondGenerator(); + + private PhantomArrowGenerator pag = new PhantomArrowGenerator(); boolean isFirstDrawing = true; @@ -174,6 +177,7 @@ this.hub = new ControllerHub(controllerModel, renderer, chemModel, this, undoredohandler, new SwingUndoRedoFactory(), isViewer, applet); pbg.setControllerHub(hub); + pag.setControllerHub(hub); // connect mouse events from Panel to the Hub this.mouseEventRelay = new SwingMouseEventRelay(this.hub); @@ -218,6 +222,7 @@ generators.add(new AtomContainerTitleGenerator()); generators.add(new TooltipGenerator()); generators.add(pbg); + generators.add(pag); return generators; } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-04-08 16:07:03 UTC (rev 15506) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-04-09 09:22:50 UTC (rev 15507) @@ -136,6 +136,10 @@ private static RGroupHandler rGroupHandler; int oldMouseCursor = Cursor.DEFAULT_CURSOR; + + private Point2d phantomArrowStart = null; + + private Point2d phantomArrowEnd = null; public ControllerHub(IControllerModel controllerModel, IRenderer renderer, IChemModel chemModel, IViewEventRelay eventRelay, @@ -2700,5 +2704,14 @@ } } } + + public void setPhantomArrow(Point2d start, Point2d end) { + this.phantomArrowStart=start; + this.phantomArrowEnd=end; + } + + public Point2d[] getPhantomArrow() { + return new Point2d[]{phantomArrowStart, phantomArrowEnd}; + } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java 2010-04-08 16:07:03 UTC (rev 15506) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java 2010-04-09 09:22:50 UTC (rev 15507) @@ -115,7 +115,22 @@ * @param atom atom to add as phantom */ public void addPhantomAtom(IAtom atom); + /** + * Sets a phantom = temporary arrow, e. g. for reaction drawing. + * + * @param start The start point. + * @param end The end point (if startt and end are null, no arrow is drawn). + */ + public void setPhantomArrow(Point2d start, Point2d end); + + /** + * Gets start and end for a phantom arrow. + * + * @return [0]=start, [1]=end. Can be null, nothing to be done then. + */ + public Point2d[] getPhantomArrow(); + /** * Adds an temporary bond which might be cleared later, when the final * bond is added. Controllers can use this to draw temporary bonds, for * example while drawing new bonds. Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-04-08 16:07:03 UTC (rev 15506) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-04-09 09:22:50 UTC (rev 15507) @@ -579,8 +579,17 @@ if (reactants == null || products == null) return null; // determine the bounds of everything in the reaction - Rectangle2D reactantsBounds = Renderer.calculateBounds(reactants); - return reactantsBounds.createUnion(Renderer.calculateBounds(products)); + if(reaction.getProducts().getAtomContainerCount()>0){ + Rectangle2D reactantsBounds = Renderer.calculateBounds(reactants); + if(reaction.getReactantCount()>0) + return reactantsBounds.createUnion(Renderer.calculateBounds(products)); + else + return reactantsBounds; + } else if (reaction.getReactantCount()>0){ + return Renderer.calculateBounds(reactants); + } else { + return null; + } } public static Rectangle2D calculateBounds(IMoleculeSet moleculeSet) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-04-09 16:51:57
|
Revision: 15509 http://cdk.svn.sourceforge.net/cdk/?rev=15509&view=rev Author: shk3 Date: 2010-04-09 16:51:47 +0000 (Fri, 09 Apr 2010) Log Message: ----------- The head of reaction arrows now is properly displayed no matter what the orientation is; making reactions via reaction arrow is undoable Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/undoredo/MakeReactantOrProductInExistingReactionEdit.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RenderingParameters.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/visitor/AWTDrawVisitor.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java 2010-04-09 12:22:29 UTC (rev 15508) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java 2010-04-09 16:51:47 UTC (rev 15509) @@ -27,6 +27,7 @@ import javax.vecmath.Point2d; import org.openscience.cdk.geometry.BondTools; +import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IMoleculeSet; import org.openscience.cdk.interfaces.IReaction; import org.openscience.cdk.interfaces.IReactionSet; @@ -57,10 +58,13 @@ @Override public void mouseClickedUp(Point2d worldCoord) { + //first, we get rid of the phantom arrow + chemModelRelay.setPhantomArrow(null, null); + chemModelRelay.updateView(); //for each molecule, we need to look if the majority of // its atoms are to the left or right or on the arrow IMoleculeSet moleculeSet = super.chemModelRelay.getChemModel().getMoleculeSet(); - if(moleculeSet.getAtomContainerCount()==0) + if(moleculeSet.getAtomContainerCount()==0 || (moleculeSet.getAtomContainerCount()==1 && moleculeSet.getAtomContainer(0).getAtomCount()==0)) return; //calculate a second point on the perpendicular through start point double angle = Math.PI/2; @@ -107,18 +111,30 @@ else leftend++; } + IAtomContainer newContainer; + try { + newContainer = (IAtomContainer) moleculeSet.getAtomContainer(i).clone(); + if(moleculeSet.getAtomContainer(i).getID()!=null) + newContainer.setID(moleculeSet.getAtomContainer(i).getID()); + else + newContainer.setID("ac"+System.currentTimeMillis()); + } catch (CloneNotSupportedException e) { + logger.error("Could not clone IAtomContainer: ", e.getMessage()); + logger.debug(e); + return; + } + if(left>right){ //is a reactant - ReactionHub.makeReactantInExistingReaction((ControllerHub)super.chemModelRelay, reaction.getID(), moleculeSet.getAtomContainer(i), moleculeSet.getAtomContainer(i)); + ReactionHub.makeReactantInExistingReaction((ControllerHub)super.chemModelRelay, reaction.getID(), newContainer, moleculeSet.getAtomContainer(i)); } if(rightend>leftend){ //is a product - ReactionHub.makeProductInExistingReaction((ControllerHub)super.chemModelRelay, reaction.getID(), moleculeSet.getAtomContainer(i), moleculeSet.getAtomContainer(i)); + ReactionHub.makeProductInExistingReaction((ControllerHub)super.chemModelRelay, reaction.getID(), newContainer, moleculeSet.getAtomContainer(i)); } else { //is a catalyst //TODO catalysts in general } } - chemModelRelay.setPhantomArrow(null, null); } /** Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/undoredo/MakeReactantOrProductInExistingReactionEdit.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/undoredo/MakeReactantOrProductInExistingReactionEdit.java 2010-04-09 12:22:29 UTC (rev 15508) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/undoredo/MakeReactantOrProductInExistingReactionEdit.java 2010-04-09 16:51:47 UTC (rev 15509) @@ -78,14 +78,20 @@ public void redo() { chemModel.getMoleculeSet().removeAtomContainer(movedContainer); + if(chemModel.getReactionSet()==null) + chemModel.setReactionSet(chemModel.getBuilder().newReactionSet()); IReaction reaction = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID); + if(reaction==null){ + reaction = chemModel.getBuilder().newReaction(); + reaction.setID(reactionID); + chemModel.getReactionSet().addReaction(reaction); + } IMolecule mol=chemModel.getBuilder().newMolecule(movedContainer); mol.setID(movedContainer.getID()); if(reactantOrProduct) reaction.addReactant(mol); else reaction.addProduct(mol); - chemModel.getReactionSet().addReaction(reaction); chemModel.getMoleculeSet().removeAtomContainer(oldContainer); } @@ -98,6 +104,7 @@ reactantsorproducts = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID).getReactants(); else reactantsorproducts = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID).getProducts(); + IReaction reaction = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID); int count=0; for(IAtomContainer mol : reactantsorproducts.atomContainers()){ if(mol.getID().equals(movedContainer.getID())){ @@ -106,6 +113,10 @@ } count++; } + if(reaction.getReactantCount()==0 && reaction.getProductCount()==0) + chemModel.getReactionSet().removeReaction(reaction); + if(chemModel.getReactionSet().getReactionCount()==0) + chemModel.setReactionSet(null); } public boolean canRedo() { Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-04-09 12:22:29 UTC (rev 15508) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-04-09 16:51:47 UTC (rev 15509) @@ -580,9 +580,9 @@ // determine the bounds of everything in the reaction if(reaction.getProducts().getAtomContainerCount()>0){ - Rectangle2D reactantsBounds = Renderer.calculateBounds(reactants); + Rectangle2D reactantsBounds = Renderer.calculateBounds(products); if(reaction.getReactantCount()>0) - return reactantsBounds.createUnion(Renderer.calculateBounds(products)); + return reactantsBounds.createUnion(Renderer.calculateBounds(reactants)); else return reactantsBounds; } else if (reaction.getReactantCount()>0){ Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RenderingParameters.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RenderingParameters.java 2010-04-09 12:22:29 UTC (rev 15508) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RenderingParameters.java 2010-04-09 16:51:47 UTC (rev 15509) @@ -86,7 +86,7 @@ /** * The width of an arrow head */ - private int arrowHeadWidth = 10; + private int arrowHeadWidth = 20; /** * The background color of the rendered image Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/visitor/AWTDrawVisitor.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/visitor/AWTDrawVisitor.java 2010-04-09 12:22:29 UTC (rev 15508) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/visitor/AWTDrawVisitor.java 2010-04-09 16:51:47 UTC (rev 15509) @@ -24,7 +24,6 @@ import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; -import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.RenderingHints; @@ -40,7 +39,11 @@ import javax.vecmath.Point2d; import javax.vecmath.Vector2d; +import org.openscience.cdk.DefaultChemObjectBuilder; import org.openscience.cdk.geometry.BondTools; +import org.openscience.cdk.geometry.GeometryTools; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.jchempaint.renderer.RendererModel; import org.openscience.jchempaint.renderer.elements.ArrowElement; import org.openscience.jchempaint.renderer.elements.AtomSymbolElement; @@ -113,37 +116,42 @@ this.g.setStroke(stroke); strokeMap.put(w, stroke); } - this.g.setColor(line.color); int[] a = this.transformPoint(line.x1, line.y1); int[] b = this.transformPoint(line.x2, line.y2); this.g.drawLine(a[0], a[1], b[0], b[1]); - double aW = rendererModel.getArrowHeadWidth() / rendererModel.getScale(); - if(line.y1==line.y2){ - if(line.direction){ - int[] c = this.transformPoint(line.x1-aW, line.y1-aW); - int[] d = this.transformPoint(line.x1-aW, line.y1+aW); - this.g.drawLine(a[0], a[1], c[0], c[1]); - this.g.drawLine(a[0], a[1], d[0], d[1]); - }else{ - int[] c = this.transformPoint(line.x2+aW, line.y2-aW); - int[] d = this.transformPoint(line.x2+aW, line.y2+aW); - this.g.drawLine(b[0], b[1], c[0], c[1]); - this.g.drawLine(b[0], b[1], d[0], d[1]); - } - }else{ - if(line.direction){ - int[] c = this.transformPoint(line.x1-aW, line.y1-aW); - int[] d = this.transformPoint(line.x1+aW, line.y1-aW); - this.g.drawLine(a[0], a[1], c[0], c[1]); - this.g.drawLine(a[0], a[1], d[0], d[1]); - }else{ - int[] c = this.transformPoint(line.x2-aW, line.y2+aW); - int[] d = this.transformPoint(line.x2+aW, line.y2+aW); - this.g.drawLine(b[0], b[1], c[0], c[1]); - this.g.drawLine(b[0], b[1], d[0], d[1]); - } - } + double arrowWidth = rendererModel.getArrowHeadWidth() / rendererModel.getScale(); + double lenghtOfArrow = Math.sqrt(Math.pow(Math.abs(line.x1 - line.x2),2) + Math.pow(Math.abs(line.y1 - line.y2),2)); + double fractionOfHead = arrowWidth/lenghtOfArrow; + //headpoint is a line on the arrow arrowWidth away from end + Point2d headPoint = new Point2d(); + if(line.x1<line.x2) + headPoint.x = line.x1 + (line.x2-line.x1)*(fractionOfHead); + else + headPoint.x = line.x2 + (line.x1-line.x2)*(1-fractionOfHead); + if(line.y1<line.y2) + headPoint.y = line.y1 + (line.y2-line.y1)*(fractionOfHead); + else + headPoint.y = line.y2 + (line.y1-line.y2)*(1-fractionOfHead); + //rotate headpoint in both directions to get end points of arrow + double relativex = headPoint.x - line.x1; + double relativey = headPoint.y - line.y1; + double angle = Math.PI/6; + double costheta = Math.cos(angle); + double sintheta = Math.sin(angle); + Point2d firstArrowPoint = new Point2d(); + firstArrowPoint.x = relativex * costheta - relativey * sintheta + line.x1; + firstArrowPoint.y = relativex * sintheta + relativey * costheta + line.y1; + int[] firstArrowPointCoords = this.transformPoint(firstArrowPoint.x, firstArrowPoint.y); + this.g.drawLine(a[0], a[1], firstArrowPointCoords[0], firstArrowPointCoords[1]); + angle = -Math.PI/6; + costheta = Math.cos(angle); + sintheta = Math.sin(angle); + Point2d secondArrowPoint = new Point2d(); + secondArrowPoint.x = relativex * costheta - relativey * sintheta + line.x1; + secondArrowPoint.y = relativex * sintheta + relativey * costheta + line.y1; + int[] secondArrowPointCoords = this.transformPoint(secondArrowPoint.x, secondArrowPoint.y); + this.g.drawLine(a[0], a[1], secondArrowPointCoords[0], secondArrowPointCoords[1]); this.g.setStroke(savedStroke); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-04-16 11:18:12
|
Revision: 15519 http://cdk.svn.sourceforge.net/cdk/?rev=15519&view=rev Author: shk3 Date: 2010-04-16 11:18:06 +0000 (Fri, 16 Apr 2010) Log Message: ----------- Some changes which fixes stuff which got broken while adopting to new cdk (mainly usage of IAtomContainer instead of IMolecule) Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionHub.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2010-04-14 16:44:18 UTC (rev 15518) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2010-04-16 11:18:06 UTC (rev 15519) @@ -215,7 +215,7 @@ IChemModel chemModel = DefaultChemObjectBuilder.getInstance().newInstance(IChemModel.class); chemModel.setMoleculeSet(chemModel.getBuilder().newInstance(IMoleculeSet.class)); chemModel.getMoleculeSet().addAtomContainer( - chemModel.getBuilder().newInstance(IAtomContainer.class)); + chemModel.getBuilder().newInstance(IMolecule.class)); return chemModel; } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionHub.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionHub.java 2010-04-14 16:44:18 UTC (rev 15518) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionHub.java 2010-04-16 11:18:06 UTC (rev 15519) @@ -47,7 +47,7 @@ reaction.addReactant(mol); chemModel.getMoleculeSet().removeAtomContainer(oldcontainer); if(chemModel.getMoleculeSet().getAtomContainerCount()==0) - chemModel.getMoleculeSet().addAtomContainer(chemModel.getBuilder().newInstance(IAtomContainer.class)); + chemModel.getMoleculeSet().addAtomContainer(chemModel.getBuilder().newInstance(IMolecule.class)); if(controllerhub.getUndoRedoFactory()!=null && controllerhub.getUndoRedoHandler()!=null){ IUndoRedoable undoredo = controllerhub.getUndoRedoFactory().getMakeReactantOrProductInExistingReactionEdit(chemModel, newContainer, oldcontainer, reactionId, true, "Make Reactant in "+reactionId); controllerhub.getUndoRedoHandler().postEdit(undoredo); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-04-14 16:44:18 UTC (rev 15518) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-04-16 11:18:06 UTC (rev 15519) @@ -271,7 +271,7 @@ return paintMoleculeSet(moleculeSet, drawVisitor); } - if (moleculeSet != null && reactionSet != null) { + if (moleculeSet != null && moleculeSet.getAtomContainerCount()>0 && reactionSet != null) { Rectangle2D totalBounds = Renderer.calculateBounds(reactionSet); totalBounds = totalBounds.createUnion( Renderer.calculateBounds(moleculeSet)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2010-04-30 06:32:49
|
Revision: 15542 http://cdk.svn.sourceforge.net/cdk/?rev=15542&view=rev Author: annulen Date: 2010-04-30 06:32:42 +0000 (Fri, 30 Apr 2010) Log Message: ----------- Added contents frame to help Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/action/HelpAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/jcp.html Added Paths: ----------- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/feedback_frame.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/rgroup_tutorial_frame.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/tutorial_frame.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contents.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/index.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/jcp_frame.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/feedback_frame.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/rgroup_tutorial.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/rgroup_tutorial_frame.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/tutorial_frame.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contents.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/index.html jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/jcp_frame.html Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/HelpAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/HelpAction.java 2010-04-30 06:28:56 UTC (rev 15541) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/HelpAction.java 2010-04-30 06:32:42 UTC (rev 15542) @@ -57,15 +57,15 @@ if (type.equals("tutorial")) { - new HelpDialog(null, helpRoot+language+"/contain/tutorial.html", GT._("JChemPaint Help")).setVisible(true); + new HelpDialog(null, helpRoot+language+"/contain/tutorial_frame.html", GT._("JChemPaint Help")).setVisible(true); } else if (type.equals("rgpTutorial")) { - new HelpDialog(null, helpRoot+language+"/contain/rgroup_tutorial.html", GT._("JChemPaint Help")).setVisible(true); + new HelpDialog(null, helpRoot+language+"/contain/rgroup_tutorial_frame.html", GT._("JChemPaint Help")).setVisible(true); } else if (type.equals("feedback")) { - new HelpDialog(null, helpRoot+language+"/contain/feedback.html", GT._("JChemPaint Help")).setVisible(true); + new HelpDialog(null, helpRoot+language+"/contain/feedback_frame.html", GT._("JChemPaint Help")).setVisible(true); } else if (type.equals("license")) { @@ -73,7 +73,7 @@ } else { - new HelpDialog(null, helpRoot+language+"/jcp.html", GT._("JChemPaint Help")).setVisible(true); + new HelpDialog(null, helpRoot+language+"/jcp_frame.html", GT._("JChemPaint Help")).setVisible(true); } } } Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/feedback_frame.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/feedback_frame.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/feedback_frame.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> + <frameset cols="175,*" rows="*"> + <frame src="../contents.html" name="leftFrame" scrolling="no" noresize> + <frame src="feedback.html" name="mainFrame"> + </frameset> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/rgroup_tutorial_frame.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/rgroup_tutorial_frame.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/rgroup_tutorial_frame.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> + <frameset cols="175,*" rows="*"> + <frame src="../contents.html" name="leftFrame" scrolling="no" noresize> + <frame src="rgroup_tutorial.html" name="mainFrame"> + </frameset> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/tutorial_frame.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/tutorial_frame.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/tutorial_frame.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> + <frameset cols="175,*" rows="*"> + <frame src="../contents.html" name="leftFrame" scrolling="no" noresize> + <frame src="tutorial.html" name="mainFrame"> + </frameset> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contents.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contents.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contents.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,24 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> +<head> +<link rel="stylesheet" type="text/css" href="jcp.css" title="Style"> +</head> +<body> +<table width="100%"> + <tr> + <td><h3>Contents</h3></td> + <td><a href="index.html" target="leftFrame"><h3>Index</h3></a></td> + </tr> +</table> +<p><a href="jcp.html" target="mainFrame"><b>User's Guide</b></a> +<ul> +<li><a href="contain/aboutJCP.html" target="mainFrame"><b>About JChemPaint</b></a> </li> +<li><a href="contain/tutorial.html" target="mainFrame"><b>Basic Tutorial</b></a> </li> +<li><a href="contain/rgroup_tutorial.html" target="mainFrame"><b>Rgroup Query Tutorial</b></a> </li> +<li><a href="contain/referenceGuide.html" target="mainFrame"><b>Reference Guide</b></a> </li> +<li><a href="contain/misc.html" target="mainFrame"><b>Miscellaneous topics</b></a> </li> +<li><a href="contain/feedback.html" target="mainFrame"><b>Feedback</b></a> </li> +</ul> +</p> +</body> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/index.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/index.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/index.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,14 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> +<head> +<link rel="stylesheet" type="text/css" href="jcp.css" title="Style"> +</head> +<body> +<table width="100%"> + <tr> + <td><a href="contents.html" target="leftFrame"><h3>Contents</h3></td> + <td><h3>Index</h3></td> + </tr> +</table> +</body> +</html> Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/jcp.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/jcp.html 2010-04-30 06:28:56 UTC (rev 15541) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/jcp.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -15,7 +15,7 @@ <p>General information about the JChemPaint program and the JChemPaint project.</p> <p><a href="contain/tutorial.html"><b>Basic Tutorial</b></a> </p> <p>This section explains on a few basic examples the use of JChemPaint and more in detail how new compounds and reactions can be drawn. -<p><a href="contain/tutorial.html"><b>Rgroup Query Tutorial</b></a> </p> +<p><a href="contain/rgroup_tutorial.html"><b>Rgroup Query Tutorial</b></a> </p> <p>An introduction to R-groups and how to draw them with JChemPaint.</p> <p><a href="contain/referenceGuide.html"><b>Reference Guide</b></a> </p> <p>A general overview on JChemPaint. Describes the use of Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/jcp_frame.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/jcp_frame.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/jcp_frame.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> + <frameset cols="175,*" rows="*"> + <frame src="contents.html" name="leftFrame" scrolling="no" noresize> + <frame src="jcp.html" name="mainFrame"> + </frameset> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/feedback_frame.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/feedback_frame.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/feedback_frame.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> + <frameset cols="175,*" rows="*"> + <frame src="../contents.html" name="leftFrame" scrolling="no" noresize> + <frame src="feedback.html" name="mainFrame"> + </frameset> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/rgroup_tutorial.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/rgroup_tutorial.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/rgroup_tutorial.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,146 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> + +<html> +<head> +<title> Rgroup Query Tutorial</title> +<link rel="stylesheet" type="text/css" href="../jcp.css" title="Style"> +</head> +<body bgcolor="#ffffff"> + +<div class="navheader"> + <table width="100%"> + <tr> + <th align="center" colspan="3">Rgroup Query Tutorial</th> + </tr> + <tr> + <td align="left" width="20%"><a href="tutorial.html">Prev</a> </td> + <th align="center" width="60%"> </th> + <td align="right" width="20%"> <a href="referenceGuide.html">Next</a></td> + </tr> + </table> + <hr> +</div> + +<h1>Rgroup Query Tutorial</h1> +<h3>Introduction</h3> +<p> + JChemPaint allows you to draw, save and retrieve "Rgroup queries". + Rgroup queries are defined by the Symyx RGfile format, more details for which can be found + in the "CTfile Formats" manual downloadable from www.symyx.com. + <br><br> + In essence, an Rgroup query allows you to define multiple molecules in one data structure + by combining different substituent attachments with one root structure (or scaffold). + A JChemPaint screenshot may help to clarify this: + <br><br> + <img src="../../../large-bin/rgroup.png"> + <br><br> + This (simple) example contains a root structure with one Rgroup labeled "R1" in pink. + For R1, three substituents are defined and drawn under the root structure. Three possible molecules + can thus be derived by substituting R1 with one of these.<br> + The substituents are to be attached to the root by replacing R1 with the substituent atom marked with an asterisk. + It will connect to the root using the bond that is also marked with an asterisk. + <br><br> + Using the "R-groups" menu, you can let JChemPaint generate the possible configurations for any Rgroup query + and save these to an SDF file. + For the example above, this would result in the following configurations (BioClipse screenshot): + <br><br> + <img src="../../../large-bin/rgroup-config.png"> + <br><br><br> + <br><br> + +<h3> Drawing R-groups</h3> + To draw R-groups, the following JChemPaint menus are relevant + <ul> + <li>"R-groups" (from the main menu bar or by right clicking the canvas)</li> + <li>"R-group attachment" in the <span style="font-style:italic">bond</span> popup menu (by right clicking a bond)</li> + <li>"R-group attachment" in the <span style="font-style:italic">atom</span> popup menu (by right clicking a bond)</li> + </ul> + This section will explain how to create Rgroups using the aforementioned menus. + <br><br> + +<h4> Define the root</h4> + The suggested way to construct Rgroup queries is to first draw all the structures you need, and then assign Rgroup aspects + to these. Going back the earlier example, you would first draw the four structures that make up the query. The R1 atom is a so + called "pseudo atom". To draw it, you can draw it as a normal (say Carbon) atom first, and then right click it and from the + atom menu pick Pseudo Atoms->R1. + <br> + Next, use a selection tool to select the entire structure that is intended to become the root structure. With the selection made, + right click the canvas and pick R-groups->Define as Root Structure. See the picture below for an illustration. + <br><br> + <img src="../../../large-bin/rdemo1.png"> + <br><br><br> + +<h4> Define the substituents</h4> + Once a root structure has been chosen, the remaining structures in the drawing are subsequently flagged as "Not in R-Group". + To continue, select each structure that is to become a substituent, and choose R-groups->Define as Substituent. JChemPaint + will then prompt you to "Enter an R-group number". In our example, we'll enter 1. In general, you can pick any number + that corresponds to an R1...R32 atom in your root structure. In this way, you link the substituent to the specific Rgroup + of your choice. + <br><br> + JChemPaint will randomly pick a "connection point" atom on a newly declared substituent and flag this atom with an + asterisk. Potentially, if your Rgroup atom has multiple bonds connecting it to the root, it will pick a second + attachment point and flag this with a double quote. The asterisk and quote on the substituent correspond to the + similarly flagged bonds on the root. The RGfile format allows for two attachment point/bonds to be identified per Rgroup, not more. + <br><br> + You are allowed to change the attachment atom(s) in the substituents and the attachment bond(s) in the root. For example, + to make another atom in a substituent the attachment point, select it and right click it. From the atom popup menu, select + R-Group attachment->Set as first attachment point (or Set as second attachment point). + Similarly, you can pick a bond in the root structure that connects to an R-atom and right click it to define its attachment + using the bond popup menu. + +<h4>Advanced Rgroup logic </h4> + With the Rgroup query in place, the RGfile format allows you to define some more advanced logic on top of it. + With JChemPaint this can be done using menu option R-groups->Advanced R-group logic. + For each group you can indicate: + <ul> + <li>Occurrence: the occurrence value determines the number of times that a member of that an Rgroup must appear in the retrieved + structures. It can be relevant for more elaborate queries, for instance when you have multiple pseudo atoms + labeled R1 in your root structure and want to specify the substitution occurrence.<br> + Allowed values are: + <ul> + <li>n: exactly n</li> + <li>n - m: n through m</li> + <li>< n: fewer than n</li> + + </ul> + The default is ">0". Any non-contradictory combination of the preceding values is also allowed; for example: "1,3-7,9,>11". + </li> + <li>RestH: with RestH set to true, only hydrogen atoms are permitted at the unsatisfied Rgroup sites of retrieved structures. If RestH is set to false (the default), + unsatisfied Rgroup sites can be filled by hydrogen atoms or other molecule fragments. + This becomes relevant when you allow the occurrence for a certain group to be lower than the total amount of R-atoms you have drawn for that group. + </li> + <li>If..Then: you can define dependencies between Rgroups. If a root structure contains for example R2 and R10, you can make the condition + IF R2 THEN R10 (or the other way around). So if a substituent for R2 occurs in a retrieved structure, then it must + also have a substituent for R11.</li> + </ul> +<h4>Saving Rgroups</h4> +When you save the drawing, choose the "MDL MOL file" format as the file type. There is no exclusive file extension reserved for RGfiles. +<br> +JChemPaint will prompt you if you want to retain the RGroup information. Choose Yes; if you do not, the drawing will be saved as a regular +MOL file instead of an RGroup query (extended) MOL file. +<h4>Generating configurations</h4> +To confirm the correctness of you RGroup query specification, you can let JChemPaint/CDK generate all its possible configurations into an SDfile. +This can be done with menu option R-groups->Generate possible configurations. You can use a tool like BioClipse to browse the content of the +SDfile. + +</p> +<br><br><br><br><br><br><br><br> + +<div class="navfooter"><hr> + <table width="100%"> + <tr> + <td align="left" width="40%"><a href="aboutJCP.html">Prev</a> </td> + <td align="center" width="20%"><a href="../jcp.html">Home</a></td> + <td align="right" width="40%"><a href="referenceGuide.html">Next</a></td> + </tr> + <tr> + <td align="left" width="40%"> </td> + <td align="center" width="20%"><a href="../jcp.html">Up</a></td> + <td align="right" width="40%"> </td> + </tr> + </table> +</div> + + +</body> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/rgroup_tutorial_frame.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/rgroup_tutorial_frame.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/rgroup_tutorial_frame.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> + <frameset cols="175,*" rows="*"> + <frame src="../contents.html" name="leftFrame" scrolling="no" noresize> + <frame src="rgroup_tutorial.html" name="mainFrame"> + </frameset> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/tutorial_frame.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/tutorial_frame.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contain/tutorial_frame.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> + <frameset cols="175,*" rows="*"> + <frame src="../contents.html" name="leftFrame" scrolling="no" noresize> + <frame src="tutorial.html" name="mainFrame"> + </frameset> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contents.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contents.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/contents.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,24 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> +<head> +<link rel="stylesheet" type="text/css" href="jcp.css" title="Style"> +</head> +<body> +<table width="100%"> + <tr> + <td><h3>Contents</h3></td> + <td><a href="index.html" target="leftFrame"><h3>Index</h3></a></td> + </tr> +</table> +<p><a href="jcp.html" target="mainFrame"><b>User's Guide</b></a> +<ul> +<li><a href="contain/aboutJCP.html" target="mainFrame"><b>About JChemPaint</b></a> </li> +<li><a href="contain/tutorial.html" target="mainFrame"><b>Basic Tutorial</b></a> </li> +<li><a href="contain/rgroup_tutorial.html" target="mainFrame"><b>Rgroup Query Tutorial</b></a> </li> +<li><a href="contain/referenceGuide.html" target="mainFrame"><b>Reference Guide</b></a> </li> +<li><a href="contain/misc.html" target="mainFrame"><b>Miscellaneous topics</b></a> </li> +<li><a href="contain/feedback.html" target="mainFrame"><b>Feedback</b></a> </li> +</ul> +</p> +</body> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/index.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/index.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/index.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,14 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> +<head> +<link rel="stylesheet" type="text/css" href="jcp.css" title="Style"> +</head> +<body> +<table width="100%"> + <tr> + <td><a href="contents.html" target="leftFrame"><h3>Contents</h3></td> + <td><h3>Index</h3></td> + </tr> +</table> +</body> +</html> Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/jcp_frame.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/jcp_frame.html (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/ru/jcp_frame.html 2010-04-30 06:32:42 UTC (rev 15542) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<html> + <frameset cols="175,*" rows="*"> + <frame src="contents.html" name="leftFrame" scrolling="no" noresize> + <frame src="jcp.html" name="mainFrame"> + </frameset> +</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2010-06-02 08:18:36
|
Revision: 15548 http://cdk.svn.sourceforge.net/cdk/?rev=15548&view=rev Author: mark_rynbeek Date: 2010-06-02 08:18:26 +0000 (Wed, 02 Jun 2010) Log Message: ----------- Limit expensive SSSR recalculation Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeBondAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/OpenAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/RedoAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/UndoAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RendererModel.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/BasicBondGenerator.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/HighlightBondGenerator.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeBondAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeBondAction.java 2010-05-24 10:18:23 UTC (rev 15547) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeBondAction.java 2010-06-02 08:18:26 UTC (rev 15548) @@ -39,6 +39,7 @@ import org.openscience.cdk.interfaces.IChemObject; import org.openscience.cdk.interfaces.IBond.Stereo; import org.openscience.jchempaint.controller.AddBondDragModule; +import org.openscience.jchempaint.renderer.RendererModel; /** @@ -143,7 +144,11 @@ } + RendererModel renderModel = jcpPanel.get2DHub().getRenderer().getRenderer2DModel(); + renderModel.setRecalculationRequiredForSSSR(true); + jcpPanel.get2DHub().updateView(); + } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java 2010-05-24 10:18:23 UTC (rev 15547) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java 2010-06-02 08:18:26 UTC (rev 15548) @@ -130,8 +130,7 @@ logger.info(" type ", type); logger.debug(" source ", e.getSource()); - RendererModel renderModel = - jcpPanel.get2DHub().getRenderer().getRenderer2DModel(); + RendererModel renderModel = jcpPanel.get2DHub().getRenderer().getRenderer2DModel(); IChemModel chemModel = jcpPanel.getChemModel(); Clipboard sysClip = jcpPanel.getToolkit().getSystemClipboard(); @@ -485,6 +484,7 @@ } } jcpPanel.get2DHub().updateView(); + renderModel.setRecalculationRequiredForSSSR(true); jcpPanel.updateStatusBar(); } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/OpenAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/OpenAction.java 2010-05-24 10:18:23 UTC (rev 15547) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/OpenAction.java 2010-06-02 08:18:26 UTC (rev 15548) @@ -44,6 +44,7 @@ import org.openscience.jchempaint.controller.undoredo.IUndoRedoable; import org.openscience.jchempaint.io.JCPFileFilter; import org.openscience.jchempaint.io.JCPFileView; +import org.openscience.jchempaint.renderer.RendererModel; import org.openscience.jchempaint.renderer.selection.LogicalSelection; /** @@ -135,6 +136,9 @@ jcpPanel.getRenderPanel().setFitToScreen(false); jcpPanel.setIsAlreadyAFile(chooser.getSelectedFile()); + RendererModel renderModel = jcpPanel.get2DHub().getRenderer().getRenderer2DModel(); + renderModel.setRecalculationRequiredForSSSR(true); + //in case this is an application, we set the file name as title if (jcpPanel.getGuistring().equals( Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/RedoAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/RedoAction.java 2010-05-24 10:18:23 UTC (rev 15547) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/RedoAction.java 2010-06-02 08:18:26 UTC (rev 15548) @@ -30,6 +30,7 @@ import java.awt.event.ActionEvent; +import org.openscience.jchempaint.renderer.RendererModel; import org.openscience.jchempaint.renderer.selection.LogicalSelection; @@ -57,7 +58,10 @@ .setSelection(new LogicalSelection(LogicalSelection.Type.NONE)); jcpPanel.updateUndoRedoControls(); jcpPanel.updateStatusBar(); - jcpPanel.get2DHub().updateView(); + RendererModel renderModel = jcpPanel.get2DHub().getRenderer().getRenderer2DModel(); + renderModel.setRecalculationRequiredForSSSR(true); + + jcpPanel.get2DHub().updateView(); } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/UndoAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/UndoAction.java 2010-05-24 10:18:23 UTC (rev 15547) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/UndoAction.java 2010-06-02 08:18:26 UTC (rev 15548) @@ -31,6 +31,7 @@ import java.awt.event.ActionEvent; import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.jchempaint.renderer.RendererModel; import org.openscience.jchempaint.renderer.selection.IChemObjectSelection; import org.openscience.jchempaint.renderer.selection.LogicalSelection; import org.openscience.jchempaint.renderer.selection.RectangleSelection; @@ -62,6 +63,9 @@ .setSelection(new LogicalSelection(LogicalSelection.Type.NONE)); jcpPanel.updateUndoRedoControls(); jcpPanel.updateStatusBar(); + RendererModel renderModel = jcpPanel.get2DHub().getRenderer().getRenderer2DModel(); + renderModel.setRecalculationRequiredForSSSR(true); + jcpPanel.get2DHub().updateView(); } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-05-24 10:18:23 UTC (rev 15547) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-06-02 08:18:26 UTC (rev 15548) @@ -2031,6 +2031,10 @@ .getSelection()); if (changeHandler != null) changeHandler.structureChanged(); + + RendererModel renderModel = renderer.getRenderer2DModel(); + renderModel.setRecalculationRequiredForSSSR(true); + } public void fireZoomEvent() { Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RendererModel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RendererModel.java 2010-05-24 10:18:23 UTC (rev 15547) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/RendererModel.java 2010-06-02 08:18:26 UTC (rev 15548) @@ -93,8 +93,19 @@ private IChemObjectSelection selection; private Map<IAtom, IAtom> merge=new HashMap<IAtom, IAtom>(); + + private boolean recalculationRequiredForSSSR=true; - /** + + public boolean isRecalculationRequiredForSSSR() { + return recalculationRequiredForSSSR; + } + + public void setRecalculationRequiredForSSSR(boolean recalculationRequiredForSSSR) { + this.recalculationRequiredForSSSR = recalculationRequiredForSSSR; + } + + /** * Constructor for the RendererModel. * * @param useUserSettings Should user setting (in $HOME/.jchempaint/properties) be used or not? Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/BasicBondGenerator.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/BasicBondGenerator.java 2010-05-24 10:18:23 UTC (rev 15547) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/BasicBondGenerator.java 2010-06-02 08:18:26 UTC (rev 15548) @@ -51,7 +51,7 @@ * @cdk.module renderbasic */ public class BasicBondGenerator implements IGenerator { - + private static ILoggingTool logger = LoggingToolFactory .createLoggingTool(BasicBondGenerator.class); @@ -79,25 +79,32 @@ this.overrideBondWidth = bondWidth; } - protected IRingSet getRingSet(final IAtomContainer atomContainer) { - - IRingSet ringSet = atomContainer.getBuilder().newInstance( - IRingSet.class); - try { - IMoleculeSet molecules = ConnectivityChecker - .partitionIntoMolecules(atomContainer); - for (IAtomContainer mol : molecules.molecules()) { - SSSRFinder sssrf = new SSSRFinder(mol); - ringSet.add(sssrf.findSSSR()); + protected IRingSet getRingSet(final IAtomContainer atomContainer,RendererModel renderModel) { + if(renderModel.isRecalculationRequiredForSSSR() || this.ringSet==null) { + System.out.println("recalc SSSR"); + renderModel.setRecalculationRequiredForSSSR(false); + IRingSet ringSet = atomContainer.getBuilder().newInstance( + IRingSet.class); + try { + IMoleculeSet molecules = ConnectivityChecker + .partitionIntoMolecules(atomContainer); + for (IAtomContainer mol : molecules.molecules()) { + SSSRFinder sssrf = new SSSRFinder(mol); + ringSet.add(sssrf.findSSSR()); + } + + return ringSet; + } catch (Exception exception) { + logger.warn("Could not partition molecule: " + + exception.getMessage()); + logger.debug(exception); + return ringSet; } - - return ringSet; - } catch (Exception exception) { - logger.warn("Could not partition molecule: " - + exception.getMessage()); - logger.debug(exception); - return ringSet; } + else { + return this.ringSet; + } + } /** @@ -150,7 +157,7 @@ public IRenderingElement generate(IAtomContainer ac, RendererModel model) { ElementGroup group = new ElementGroup(); - this.ringSet = this.getRingSet(ac); + this.ringSet = this.getRingSet(ac,model); // Sort the ringSet consistently to ensure consistent rendering. // If this is omitted, the bonds may 'tremble'. Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/HighlightBondGenerator.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/HighlightBondGenerator.java 2010-05-24 10:18:23 UTC (rev 15547) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/HighlightBondGenerator.java 2010-06-02 08:18:26 UTC (rev 15548) @@ -44,7 +44,7 @@ public IRenderingElement generate(IAtomContainer ac, RendererModel model) { IBond bond = model.getHighlightedBond(); if (bond != null && shouldHighlight(bond, model)) { - super.ringSet = super.getRingSet(ac); + super.ringSet = super.getRingSet(ac,model); double r = model.getHighlightDistance() / model.getScale(); r /= 2.0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2010-06-02 08:25:21
|
Revision: 15549 http://cdk.svn.sourceforge.net/cdk/?rev=15549&view=rev Author: mark_rynbeek Date: 2010-06-02 08:25:15 +0000 (Wed, 02 Jun 2010) Log Message: ----------- Commit for Syed Asad Rahman, changes for Reaction handling/display Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java Added Paths: ----------- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/IReactionSetGenerator.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java 2010-06-02 08:18:26 UTC (rev 15548) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ReactionArrowModule.java 2010-06-02 08:25:15 UTC (rev 15549) @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2009 Stefan Kuhn <sh...@us...> * * Contact: cdk...@li... @@ -21,7 +21,6 @@ * 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.jchempaint.controller; import javax.vecmath.Point2d; @@ -31,43 +30,44 @@ import org.openscience.cdk.interfaces.IMoleculeSet; import org.openscience.cdk.interfaces.IReaction; import org.openscience.cdk.interfaces.IReactionSet; +import org.openscience.cdk.reaction.ReactionChain; import org.openscience.cdk.tools.ILoggingTool; import org.openscience.cdk.tools.LoggingToolFactory; - public class ReactionArrowModule extends ControllerModuleAdapter { protected static ILoggingTool logger = - LoggingToolFactory.createLoggingTool(ReactionArrowModule.class); - Point2d startPoint=null; + LoggingToolFactory.createLoggingTool(ReactionArrowModule.class); + Point2d startPoint = null; protected String ID; /** - * Constructor + * Constructor * @param chemModelRelay */ public ReactionArrowModule(IChemModelRelay chemModelRelay) { super(chemModelRelay); logger.debug("constructor"); } - + @Override public void mouseClickedDown(Point2d worldCoordFrom) { - startPoint=worldCoordFrom; + startPoint = worldCoordFrom; } - + @Override public void mouseClickedUp(Point2d worldCoord) { //first, we get rid of the phantom arrow chemModelRelay.setPhantomArrow(null, null); chemModelRelay.updateView(); - //for each molecule, we need to look if the majority of + //for each molecule, we need to look if the majority of // its atoms are to the left or right or on the arrow IMoleculeSet moleculeSet = super.chemModelRelay.getChemModel().getMoleculeSet(); - if(moleculeSet.getAtomContainerCount()==0 || (moleculeSet.getAtomContainerCount()==1 && moleculeSet.getAtomContainer(0).getAtomCount()==0)) + if (moleculeSet.getAtomContainerCount() == 0 || (moleculeSet.getAtomContainerCount() == 1 && moleculeSet.getAtomContainer(0).getAtomCount() == 0)) { return; + } //calculate a second point on the perpendicular through start point - double angle = Math.PI/2; + double angle = Math.PI / 2; double costheta = Math.cos(angle); double sintheta = Math.sin(angle); Point2d point = new Point2d(worldCoord); @@ -86,57 +86,60 @@ secondOnEndPerpendicular.x = relativex * costheta - relativey * sintheta + center.x; secondOnEndPerpendicular.y = relativex * sintheta + relativey * costheta + center.y; IReactionSet reactionSet = super.chemModelRelay.getChemModel().getReactionSet(); - if (reactionSet == null) - { - reactionSet = super.chemModelRelay.getChemModel().getBuilder().newInstance(IReactionSet.class); + if (reactionSet == null) { + reactionSet = new ReactionChain(); //reactionSet = super.chemModelRelay.getChemModel().getBuilder().newInstance(IReactionSet.class); super.chemModelRelay.getChemModel().setReactionSet(reactionSet); } IReaction reaction = moleculeSet.getBuilder().newInstance(IReaction.class); - reactionSet.addReaction(reaction); + ((ReactionChain) reactionSet).addReaction(reaction, reactionSet.getReactionCount()); //reactionSet.addReaction(reaction); reaction.setID("reaction-" + System.currentTimeMillis()); - for(int i=moleculeSet.getAtomContainerCount()-1;i>=0;i--){ - int left=0; - int right=0; - for(int k=0;k<moleculeSet.getAtomContainer(i).getAtomCount();k++){ - if(BondTools.giveAngleBothMethods(startPoint, secondOnStartPerpendicular, moleculeSet.getAtomContainer(i).getAtom(k).getPoint2d(), false)<0) + for (int i = moleculeSet.getAtomContainerCount() - 1; i >= 0; i--) { + int left = 0; + int right = 0; + for (int k = 0; k < moleculeSet.getAtomContainer(i).getAtomCount(); k++) { + if (BondTools.giveAngleBothMethods(startPoint, secondOnStartPerpendicular, moleculeSet.getAtomContainer(i).getAtom(k).getPoint2d(), false) < 0) { right++; - else + } else { left++; + } } - int leftend=0; - int rightend=0; - for(int k=0;k<moleculeSet.getAtomContainer(i).getAtomCount();k++){ - if(BondTools.giveAngleBothMethods(secondOnEndPerpendicular, worldCoord, moleculeSet.getAtomContainer(i).getAtom(k).getPoint2d(), false)<0) + int leftend = 0; + int rightend = 0; + for (int k = 0; k < moleculeSet.getAtomContainer(i).getAtomCount(); k++) { + if (BondTools.giveAngleBothMethods(secondOnEndPerpendicular, worldCoord, moleculeSet.getAtomContainer(i).getAtom(k).getPoint2d(), false) < 0) { rightend++; - else + } else { leftend++; + } } IAtomContainer newContainer; try { newContainer = (IAtomContainer) moleculeSet.getAtomContainer(i).clone(); - if(moleculeSet.getAtomContainer(i).getID()!=null) + if (moleculeSet.getAtomContainer(i).getID() != null) { newContainer.setID(moleculeSet.getAtomContainer(i).getID()); - else - newContainer.setID("ac"+System.currentTimeMillis()); + } else { + newContainer.setID("ac" + System.currentTimeMillis()); + } } catch (CloneNotSupportedException e) { logger.error("Could not clone IAtomContainer: ", e.getMessage()); logger.debug(e); return; } - if(left>right){ + if (left > right) { //is a reactant - ReactionHub.makeReactantInExistingReaction((ControllerHub)super.chemModelRelay, reaction.getID(), newContainer, moleculeSet.getAtomContainer(i)); - } if(rightend>leftend){ + ReactionHub.makeReactantInExistingReaction((ControllerHub) super.chemModelRelay, reaction.getID(), newContainer, moleculeSet.getAtomContainer(i)); + } + if (rightend > leftend) { //is a product - ReactionHub.makeProductInExistingReaction((ControllerHub)super.chemModelRelay, reaction.getID(), newContainer, moleculeSet.getAtomContainer(i)); + ReactionHub.makeProductInExistingReaction((ControllerHub) super.chemModelRelay, reaction.getID(), newContainer, moleculeSet.getAtomContainer(i)); } else { //is a catalyst //TODO catalysts in general } } } - + /** * On mouse drag, quasi-3D rotation around the center is done * (It isn't real 3D rotation because of truncation of transformation @@ -147,16 +150,16 @@ chemModelRelay.setPhantomArrow(startPoint, worldCoordTo); chemModelRelay.updateView(); } + public String getDrawModeString() { return "Draw a reaction Arrow"; } - public String getID() { return ID; } public void setID(String ID) { - this.ID=ID; + this.ID = ID; } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-06-02 08:18:26 UTC (rev 15548) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/Renderer.java 2010-06-02 08:25:15 UTC (rev 15549) @@ -2,27 +2,25 @@ * 2008-2009 Arvid Berg <gog...@us...> * 2009 Stefan Kuhn <sh...@us...> * 2009 Egon Willighagen <eg...@us...> -* -* Contact: cdk...@li... -* -* 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. -* -* 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. -*/ + * + * Contact: cdk...@li... + * + * 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. + * + * 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.jchempaint.renderer; -import java.awt.Color; -import java.awt.Cursor; import java.awt.Rectangle; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; @@ -31,7 +29,6 @@ import javax.vecmath.Point2d; -import org.openscience.cdk.CDKConstants; import org.openscience.cdk.geometry.GeometryTools; import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IChemModel; @@ -40,12 +37,12 @@ import org.openscience.cdk.interfaces.IReaction; import org.openscience.cdk.interfaces.IReactionSet; import org.openscience.jchempaint.RenderPanel; -import org.openscience.jchempaint.renderer.elements.ArrowElement; import org.openscience.jchempaint.renderer.elements.ElementGroup; import org.openscience.jchempaint.renderer.elements.IRenderingElement; import org.openscience.jchempaint.renderer.font.IFontManager; import org.openscience.jchempaint.renderer.generators.IGenerator; import org.openscience.jchempaint.renderer.generators.IReactionGenerator; +import org.openscience.jchempaint.renderer.generators.IReactionSetGenerator; import org.openscience.jchempaint.renderer.visitor.IDrawVisitor; /** @@ -111,12 +108,13 @@ */ public class Renderer extends AtomContainerRenderer implements IRenderer { - /** - * Generators specific to reactions - */ - private List<IReactionGenerator> reactionGenerators; - /** + * Generators specific to reactions + */ + private List<IReactionGenerator> reactionGenerators; + private List<IReactionSetGenerator> reactionSetGenerators; + + /** * A renderer that generates diagrams using the specified * generators and manages fonts with the supplied font manager. * @@ -124,57 +122,58 @@ * a list of classes that implement the IGenerator interface * @param fontManager * a class that manages mappings between zoom and font sizes - * @param useUserSettings Should user setting (in $HOME/.jchempaint/properties) be used or not? + * @param useUserSettings Should user setting (in $HOME/.jchempaint/properties) be used or not? */ - public Renderer(List<IGenerator> generators, IFontManager fontManager, - boolean useUserSettings) { + public Renderer(List<IGenerator> generators, IFontManager fontManager, + boolean useUserSettings) { super(generators, fontManager, useUserSettings); } - - public Renderer(List<IGenerator> generators, - List<IReactionGenerator> reactionGenerators, - IFontManager fontManager, RenderPanel renderPanel, boolean useUserSettings) { - this(generators, fontManager, useUserSettings); + + public Renderer(List<IGenerator> generators, + List<IReactionGenerator> reactionGenerators, + IFontManager fontManager, RenderPanel renderPanel, boolean useUserSettings) { + this(generators, fontManager, useUserSettings); this.reactionGenerators = reactionGenerators; + this.reactionSetGenerators = new ArrayList<IReactionSetGenerator>(); this.setup(); super.renderPanel = renderPanel; - } - - /** - * Setup the transformations necessary to draw this Chem Model. - * - * @param chemModel - * @param screen - */ - public void setup(IChemModel chemModel, Rectangle screen) { - this.setScale(chemModel); - Rectangle2D bounds = Renderer.calculateBounds(chemModel); - this.modelCenter = new Point2d(bounds.getCenterX(), bounds.getCenterY()); - this.drawCenter = new Point2d(screen.getCenterX(), screen.getCenterY()); - this.setup(); - } + } - /** - * Setup the transformations necessary to draw this Reaction Set. - * - * @param reactionSet - * @param screen - */ - public void setup(IReactionSet reactionSet, Rectangle screen) { - this.setScale(reactionSet); - Rectangle2D bounds = Renderer.calculateBounds(reactionSet); + /** + * Setup the transformations necessary to draw this Chem Model. + * + * @param chemModel + * @param screen + */ + public void setup(IChemModel chemModel, Rectangle screen) { + this.setScale(chemModel); + Rectangle2D bounds = Renderer.calculateBounds(chemModel); this.modelCenter = new Point2d(bounds.getCenterX(), bounds.getCenterY()); this.drawCenter = new Point2d(screen.getCenterX(), screen.getCenterY()); this.setup(); - } + } - /** - * Setup the transformations necessary to draw this Reaction. - * - * @param reaction - * @param screen - */ - public void setup(IReaction reaction, Rectangle screen) { + /** + * Setup the transformations necessary to draw this Reaction Set. + * + * @param reactionSet + * @param screen + */ + public void setup(IReactionSet reactionSet, Rectangle screen) { + this.setScale(reactionSet); + Rectangle2D bounds = Renderer.calculateBounds(reactionSet); + this.modelCenter = new Point2d(bounds.getCenterX(), bounds.getCenterY()); + this.drawCenter = new Point2d(screen.getCenterX(), screen.getCenterY()); + this.setup(); + } + + /** + * Setup the transformations necessary to draw this Reaction. + * + * @param reaction + * @param screen + */ + public void setup(IReaction reaction, Rectangle screen) { this.setScale(reaction); Rectangle2D bounds = Renderer.calculateBounds(reaction); this.modelCenter = new Point2d(bounds.getCenterX(), bounds.getCenterY()); @@ -189,29 +188,29 @@ setup(); } - /** - * Set the scale for an IChemModel. It calculates the average bond length of - * the model and calculates the multiplication factor to transform this - * to the bond length that is set in the RendererModel. - * - * @param chemModel - */ - public void setScale(IChemModel chemModel) { - double bondLength = Renderer.calculateAverageBondLength(chemModel); - this.scale = this.calculateScaleForBondLength(bondLength); + /** + * Set the scale for an IChemModel. It calculates the average bond length of + * the model and calculates the multiplication factor to transform this + * to the bond length that is set in the RendererModel. + * + * @param chemModel + */ + public void setScale(IChemModel chemModel) { + double bondLength = Renderer.calculateAverageBondLength(chemModel); + this.scale = this.calculateScaleForBondLength(bondLength); - // store the scale so that other components can access it - this.rendererModel.setScale(scale); - } + // store the scale so that other components can access it + this.rendererModel.setScale(scale); + } - /** - * Set the scale for an IReactionSet. It calculates the average bond length - * of the model and calculates the multiplication factor to transform this + /** + * Set the scale for an IReactionSet. It calculates the average bond length + * of the model and calculates the multiplication factor to transform this * to the bond length that is set in the RendererModel. * - * @param reactionSet - */ - public void setScale(IReactionSet reactionSet) { + * @param reactionSet + */ + public void setScale(IReactionSet reactionSet) { double bondLength = Renderer.calculateAverageBondLength(reactionSet); this.scale = this.calculateScaleForBondLength(bondLength); @@ -271,7 +270,7 @@ return paintMoleculeSet(moleculeSet, drawVisitor); } - if (moleculeSet != null && moleculeSet.getAtomContainerCount()>0 && reactionSet != null) { + if (moleculeSet != null && moleculeSet.getAtomContainerCount() > 0 && reactionSet != null) { Rectangle2D totalBounds = Renderer.calculateBounds(reactionSet); totalBounds = totalBounds.createUnion( Renderer.calculateBounds(moleculeSet)); @@ -281,6 +280,7 @@ diagram.add(this.generateDiagram(reaction)); } diagram.add(this.generateDiagram(moleculeSet)); + diagram.add(this.generateDiagram(reactionSet)); this.paint(drawVisitor, diagram); // the size of the painted diagram is returned @@ -289,7 +289,7 @@ return new Rectangle(0, 0, 0, 0); } - public Rectangle paintReactionSet( + public Rectangle paintReactionSet( IReactionSet reactionSet, IDrawVisitor drawVisitor) { // total up the bounding boxes Rectangle2D totalBounds = new Rectangle2D.Double(); @@ -308,14 +308,15 @@ for (IReaction reaction : reactionSet.reactions()) { diagram.add(this.generateDiagram(reaction)); } + diagram.add(this.generateDiagram(reactionSet)); this.paint(drawVisitor, diagram); // the size of the painted diagram is returned return this.convertToDiagramBounds(totalBounds); } - public Rectangle paintReaction( - IReaction reaction, IDrawVisitor drawVisitor) { + public Rectangle paintReaction( + IReaction reaction, IDrawVisitor drawVisitor) { // calculate the bounds Rectangle2D modelBounds = Renderer.calculateBounds(reaction); @@ -328,7 +329,7 @@ return this.convertToDiagramBounds(modelBounds); } - public Rectangle paintMoleculeSet( + public Rectangle paintMoleculeSet( IMoleculeSet moleculeSet, IDrawVisitor drawVisitor) { // total up the bounding boxes Rectangle2D totalBounds = new Rectangle2D.Double(); @@ -348,11 +349,11 @@ diagram.add(this.generateDiagram(molecule)); } this.paint(drawVisitor, diagram); - + return this.convertToDiagramBounds(totalBounds); } - /** + /** * Paint a ChemModel. * * @param chemModel @@ -419,24 +420,25 @@ for (IReaction reaction : reactionSet.reactions()) { diagram.add(this.generateDiagram(reaction)); } + diagram.add(this.generateDiagram(reactionSet)); // paint them all this.paint(drawVisitor, diagram); } /** - * Paint a reaction. - * - * @param reaction the reaction to paint - * @param drawVisitor the visitor that does the drawing - * @param bounds the bounds on the screen - * @param resetCenter - * if true, set the draw center to be the center of bounds - */ - public void paintReaction(IReaction reaction, IDrawVisitor drawVisitor, + * Paint a reaction. + * + * @param reaction the reaction to paint + * @param drawVisitor the visitor that does the drawing + * @param bounds the bounds on the screen + * @param resetCenter + * if true, set the draw center to be the center of bounds + */ + public void paintReaction(IReaction reaction, IDrawVisitor drawVisitor, Rectangle2D bounds, boolean resetCenter) { - // calculate the bounds + // calculate the bounds Rectangle2D modelBounds = Renderer.calculateBounds(reaction); this.setupTransformToFit(bounds, modelBounds, @@ -449,7 +451,7 @@ this.paint(drawVisitor, diagram); } - /** + /** * Paint a set of molecules. * * @param reaction the reaction to paint @@ -493,12 +495,12 @@ } /** - * Given a chem model, calculates the bounding rectangle in screen space. - * - * @param model the model to draw. - * @return a rectangle in screen space. - */ - public Rectangle calculateDiagramBounds(IChemModel model) { + * Given a chem model, calculates the bounding rectangle in screen space. + * + * @param model the model to draw. + * @return a rectangle in screen space. + */ + public Rectangle calculateDiagramBounds(IChemModel model) { IMoleculeSet moleculeSet = model.getMoleculeSet(); IReactionSet reactionSet = model.getReactionSet(); if ((moleculeSet == null && reactionSet == null)) { @@ -525,22 +527,22 @@ } } - public Rectangle calculateDiagramBounds(IReactionSet reactionSet) { + public Rectangle calculateDiagramBounds(IReactionSet reactionSet) { return this.calculateScreenBounds( Renderer.calculateBounds(reactionSet)); - } + } - public Rectangle calculateDiagramBounds(IReaction reaction) { + public Rectangle calculateDiagramBounds(IReaction reaction) { return this.calculateScreenBounds( Renderer.calculateBounds(reaction)); - } + } - public Rectangle calculateDiagramBounds(IMoleculeSet moleculeSet) { - return this.calculateScreenBounds( - Renderer.calculateBounds(moleculeSet)); - } + public Rectangle calculateDiagramBounds(IMoleculeSet moleculeSet) { + return this.calculateScreenBounds( + Renderer.calculateBounds(moleculeSet)); + } - public static Rectangle2D calculateBounds(IChemModel chemModel) { + public static Rectangle2D calculateBounds(IChemModel chemModel) { IMoleculeSet moleculeSet = chemModel.getMoleculeSet(); IReactionSet reactionSet = chemModel.getReactionSet(); Rectangle2D totalBounds = null; @@ -576,16 +578,19 @@ // get the participants in the reaction IMoleculeSet reactants = reaction.getReactants(); IMoleculeSet products = reaction.getProducts(); - if (reactants == null || products == null) return null; + if (reactants == null || products == null) { + return null; + } // determine the bounds of everything in the reaction - if(reaction.getProducts().getAtomContainerCount()>0){ + if (reaction.getProducts().getAtomContainerCount() > 0) { Rectangle2D reactantsBounds = Renderer.calculateBounds(products); - if(reaction.getReactantCount()>0) + if (reaction.getReactantCount() > 0) { return reactantsBounds.createUnion(Renderer.calculateBounds(reactants)); - else + } else { return reactantsBounds; - } else if (reaction.getReactantCount()>0){ + } + } else if (reaction.getReactantCount() > 0) { return Renderer.calculateBounds(reactants); } else { return null; @@ -597,7 +602,7 @@ for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) { IAtomContainer ac = moleculeSet.getAtomContainer(i); Rectangle2D acBounds = Renderer.calculateBounds(ac); - if (totalBounds==null) { + if (totalBounds == null) { totalBounds = acBounds; } else { Rectangle2D.union(totalBounds, acBounds, totalBounds); @@ -630,7 +635,7 @@ double averageBondModelLength = 0.0; for (IReaction reaction : reactionSet.reactions()) { averageBondModelLength += - Renderer.calculateAverageBondLength(reaction); + Renderer.calculateAverageBondLength(reaction); } return averageBondModelLength / reactionSet.getReactionCount(); } @@ -641,16 +646,16 @@ double reactantAverage = 0.0; if (reactants != null) { reactantAverage = - Renderer.calculateAverageBondLength(reactants) / - reactants.getAtomContainerCount(); + Renderer.calculateAverageBondLength(reactants) + / reactants.getAtomContainerCount(); } IMoleculeSet products = reaction.getProducts(); double productAverage = 0.0; if (products != null) { productAverage = - Renderer.calculateAverageBondLength(products) / - products.getAtomContainerCount(); + Renderer.calculateAverageBondLength(products) + / products.getAtomContainerCount(); } if (productAverage == 0.0 && reactantAverage == 0.0) { @@ -664,30 +669,30 @@ double averageBondModelLength = 0.0; for (IAtomContainer atomContainer : moleculeSet.molecules()) { averageBondModelLength += - GeometryTools.getBondLengthAverage(atomContainer); + GeometryTools.getBondLengthAverage(atomContainer); } return averageBondModelLength / moleculeSet.getAtomContainerCount(); } public RendererModel getRenderer2DModel() { - return this.rendererModel; - } + return this.rendererModel; + } - public void setModelCenter(double x, double y) { - this.modelCenter = new Point2d(x, y); - setup(); - } + public void setModelCenter(double x, double y) { + this.modelCenter = new Point2d(x, y); + setup(); + } - public void setDrawCenter(double x, double y) { + public void setDrawCenter(double x, double y) { this.drawCenter = new Point2d(x, y); setup(); } - public void setZoom(double z) { - getRenderer2DModel().setZoomFactor( z ); - zoom = z; - setup(); - } + public void setZoom(double z) { + getRenderer2DModel().setZoomFactor(z); + zoom = z; + setup(); + } /** * Move the draw center by dx and dy. @@ -697,12 +702,12 @@ * @param dy * the y shift */ - public void shiftDrawCenter(double dx, double dy) { - this.drawCenter.set(this.drawCenter.x + dx, this.drawCenter.y + dy); - setup(); - } + public void shiftDrawCenter(double dx, double dy) { + this.drawCenter.set(this.drawCenter.x + dx, this.drawCenter.y + dy); + setup(); + } - public Point2d getDrawCenter() { + public Point2d getDrawCenter() { return drawCenter; } @@ -718,14 +723,14 @@ * @param drawBounds */ public void setZoomToFit(double drawWidth, - double drawHeight, - double diagramWidth, - double diagramHeight) { + double drawHeight, + double diagramWidth, + double diagramHeight) { double m = this.rendererModel.getMargin(); // determine the zoom needed to fit the diagram to the screen - double widthRatio = drawWidth / (diagramWidth + (2 * m)); + double widthRatio = drawWidth / (diagramWidth + (2 * m)); double heightRatio = drawHeight / (diagramHeight + (2 * m)); this.zoom = Math.min(widthRatio, heightRatio); @@ -745,33 +750,35 @@ * @param diagram * the IRenderingElement tree to render */ - private void paint(IDrawVisitor drawVisitor, - IRenderingElement diagram) { - if (diagram == null) return; + private void paint(IDrawVisitor drawVisitor, + IRenderingElement diagram) { + if (diagram == null) { + return; + } - // cache the diagram for quick-redraw - this.cachedDiagram = diagram; + // cache the diagram for quick-redraw + this.cachedDiagram = diagram; - this.fontManager.setFontName(this.rendererModel.getFontName()); - this.fontManager.setFontStyle(this.rendererModel.getFontStyle()); + this.fontManager.setFontName(this.rendererModel.getFontName()); + this.fontManager.setFontStyle(this.rendererModel.getFontStyle()); - drawVisitor.setFontManager(this.fontManager); - drawVisitor.setTransform(this.transform); - drawVisitor.setRendererModel(this.rendererModel); - diagram.accept(drawVisitor); - } + drawVisitor.setFontManager(this.fontManager); + drawVisitor.setTransform(this.transform); + drawVisitor.setRendererModel(this.rendererModel); + diagram.accept(drawVisitor); + } - /** - * Set the transform for a non-fit to screen paint. - * - * @param modelBounds + /** + * Set the transform for a non-fit to screen paint. + * + * @param modelBounds * the bounding box of the model - */ - private void setupTransformNatural(Rectangle2D modelBounds) { - this.zoom = this.rendererModel.getZoomFactor(); + */ + private void setupTransformNatural(Rectangle2D modelBounds) { + this.zoom = this.rendererModel.getZoomFactor(); this.fontManager.setFontForZoom(zoom); this.setup(); - } + } /** * Sets the transformation needed to draw the model on the canvas when @@ -787,12 +794,14 @@ * if true, model center will be set to the modelBounds center * and the scale will be re-calculated */ - private void setupTransformToFit(Rectangle2D screenBounds, - Rectangle2D modelBounds, - double bondLength, - boolean reset) { + private void setupTransformToFit(Rectangle2D screenBounds, + Rectangle2D modelBounds, + double bondLength, + boolean reset) { - if (screenBounds == null) return; + if (screenBounds == null) { + return; + } this.setDrawCenter( screenBounds.getCenterX(), screenBounds.getCenterY()); @@ -807,36 +816,36 @@ this.setZoomToFit(drawWidth, drawHeight, diagramWidth, diagramHeight); - // this controls whether editing a molecule causes it to re-center - // with each change or not - if (reset || rendererModel.isFitToScreen()) { + // this controls whether editing a molecule causes it to re-center + // with each change or not + if (reset || rendererModel.isFitToScreen()) { this.setModelCenter( modelBounds.getCenterX(), modelBounds.getCenterY()); } - // set the scale in the renderer model for the generators - if (reset) { - this.rendererModel.setScale(scale); - } + // set the scale in the renderer model for the generators + if (reset) { + this.rendererModel.setScale(scale); + } - this.setup(); - } + this.setup(); + } - /** - * Given a bond length for a model, calculate the scale that will transform - * this length to the on screen bond length in RendererModel. - * - * @param modelBondLength - * @param reset - * @return - */ - private double calculateScaleForBondLength(double modelBondLength) { - if (Double.isNaN(modelBondLength) || modelBondLength == 0) { + /** + * Given a bond length for a model, calculate the scale that will transform + * this length to the on screen bond length in RendererModel. + * + * @param modelBondLength + * @param reset + * @return + */ + private double calculateScaleForBondLength(double modelBondLength) { + if (Double.isNaN(modelBondLength) || modelBondLength == 0) { return Renderer.DEFAULT_SCALE; } else { return this.rendererModel.getBondLength() / modelBondLength; } - } + } /** * Calculate the bounds of the diagram on screen, given the current scale, @@ -846,8 +855,8 @@ * the bounds in model space of the chem object * @return the bounds in screen space of the drawn diagram */ - private Rectangle convertToDiagramBounds(Rectangle2D modelBounds) { - double cx = modelBounds.getCenterX(); + private Rectangle convertToDiagramBounds(Rectangle2D modelBounds) { + double cx = modelBounds.getCenterX(); double cy = modelBounds.getCenterY(); double mw = modelBounds.getWidth(); double mh = modelBounds.getHeight(); @@ -856,7 +865,7 @@ // special case for 0 or 1 atoms if (mw == 0 && mh == 0) { - return new Rectangle((int)mc.x, (int)mc.y, 0, 0); + return new Rectangle((int) mc.x, (int) mc.y, 0, 0); } double margin = this.rendererModel.getMargin(); @@ -866,45 +875,54 @@ int y = (int) (mc.y - h / 2); return new Rectangle(x, y, w, h); - } + } - private void setup() { + private void setup() { // set the transform try { this.transform = new AffineTransform(); this.transform.translate(this.drawCenter.x, this.drawCenter.y); - this.transform.scale(1,-1); // Converts between CDK Y-up & Java2D Y-down coordinate-systems + this.transform.scale(1, -1); // Converts between CDK Y-up & Java2D Y-down coordinate-systems this.transform.scale(this.scale, this.scale); this.transform.scale(this.zoom, this.zoom); this.transform.translate(-this.modelCenter.x, -this.modelCenter.y); } catch (NullPointerException npe) { // one of the drawCenter or modelCenter points have not been set! System.err.println(String.format( - "null pointer when setting transform: " + - "drawCenter=%s scale=%s zoom=%s modelCenter=%s", + "null pointer when setting transform: " + + "drawCenter=%s scale=%s zoom=%s modelCenter=%s", this.drawCenter, this.scale, this.zoom, this.modelCenter)); } - } + } + private IRenderingElement generateDiagram(IReactionSet reactionSet) { + ElementGroup diagram = new ElementGroup(); + + for (IReactionSetGenerator generator : this.reactionSetGenerators) { + diagram.add(generator.generate(reactionSet, rendererModel)); + } + return diagram; + } + private IRenderingElement generateDiagram(IReaction reaction) { - ElementGroup diagram = new ElementGroup(); - - for (IReactionGenerator generator : this.reactionGenerators) { - diagram.add(generator.generate(reaction, rendererModel)); - } + ElementGroup diagram = new ElementGroup(); - diagram.add(generateDiagram(reaction.getReactants())); - diagram.add(generateDiagram(reaction.getProducts())); + for (IReactionGenerator generator : this.reactionGenerators) { + diagram.add(generator.generate(reaction, rendererModel)); + } - return diagram; - } + diagram.add(generateDiagram(reaction.getReactants())); + diagram.add(generateDiagram(reaction.getProducts())); - private IRenderingElement generateDiagram(IMoleculeSet moleculeSet) { - ElementGroup diagram = new ElementGroup(); + return diagram; + } + + private IRenderingElement generateDiagram(IMoleculeSet moleculeSet) { + ElementGroup diagram = new ElementGroup(); for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) { IAtomContainer ac = moleculeSet.getAtomContainer(i); for (IGenerator generator : this.generators) { @@ -912,12 +930,12 @@ } } return diagram; - } + } - public List<IGenerator> getGenerators(){ - return new ArrayList<IGenerator>(generators); - } - + public List<IGenerator> getGenerators() { + return new ArrayList<IGenerator>(generators); + } + /** * * @param reactionGenerator @@ -933,4 +951,12 @@ public void addGenerator(IGenerator generator) { generators.add(generator); } + + /** + * + * @param reactionSetGenerator + */ + public void addReactionSetGenerator(IReactionSetGenerator reactionSetGenerator) { + reactionSetGenerators.add(reactionSetGenerator); + } } Added: jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/IReactionSetGenerator.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/IReactionSetGenerator.java (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/renderer/generators/IReactionSetGenerator.java 2010-06-02 08:25:15 UTC (rev 15549) @@ -0,0 +1,12 @@ +package org.openscience.jchempaint.renderer.generators; + +import org.openscience.cdk.interfaces.IReactionSet; +import org.openscience.jchempaint.renderer.RendererModel; +import org.openscience.jchempaint.renderer.elements.IRenderingElement; + +public interface IReactionSetGenerator { + + public IRenderingElement generate(IReactionSet reactionSet, RendererModel model); + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2010-08-25 09:48:14
|
Revision: 15567 http://cdk.svn.sourceforge.net/cdk/?rev=15567&view=rev Author: mark_rynbeek Date: 2010-08-25 09:48:07 +0000 (Wed, 25 Aug 2010) Log Message: ----------- Added on/off for R-groups Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/features.properties Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java 2010-08-25 09:46:19 UTC (rev 15566) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintMenuHelper.java 2010-08-25 09:48:07 UTC (rev 15567) @@ -108,7 +108,13 @@ * @return The created JMenu */ protected JComponent createMenu(final AbstractJChemPaintPanel jcpPanel, String key, boolean isPopup, String guiString, final JComponent menu, List<String> blacklist) { - String[] itemKeys = StringHelper.tokenize(getMenuResourceString(key, guiString)); + // Blacklist entire menu + if (blacklist.contains(key)){ + return null; + } + + String[] itemKeys = StringHelper.tokenize(getMenuResourceString(key, guiString)); + System.out.println(key); for (int i = 0; i < itemKeys.length; i++) { if (!blacklist.contains(itemKeys[i]) && !blacklist.contains(itemKeys[i].substring(1))){ if (itemKeys[i].equals("-")) { Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/features.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/features.properties 2010-08-25 09:46:19 UTC (rev 15566) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/features.properties 2010-08-25 09:48:07 UTC (rev 15567) @@ -3,5 +3,5 @@ #used as an applet param with on/off features, the term to the right is a space-delimited #list of terms from the JCPGUI_applet.properties file reactions=reaction reactionArrow -rgroups= +rgroups=rgroupMenu rgroup rgroupAtomMenu rgroupBondMenu stereochemistry=up_bond down_bond undefined_bond undefined_stereo_bond \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <co...@us...> - 2010-08-26 14:11:03
|
Revision: 15573 http://cdk.svn.sourceforge.net/cdk/?rev=15573&view=rev Author: conni75 Date: 2010-08-26 14:10:51 +0000 (Thu, 26 Aug 2010) Log Message: ----------- Fixes #109 (paste c1ccccc1) Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java 2010-08-26 14:05:09 UTC (rev 15572) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java 2010-08-26 14:10:51 UTC (rev 15573) @@ -71,6 +71,7 @@ import org.openscience.cdk.isomorphism.matchers.RGroupQuery; import org.openscience.cdk.layout.StructureDiagramGenerator; import org.openscience.cdk.layout.TemplateHandler; +import org.openscience.cdk.smiles.DeduceBondSystemTool; import org.openscience.cdk.smiles.SmilesGenerator; import org.openscience.cdk.smiles.SmilesParser; import org.openscience.cdk.tools.CDKHydrogenAdder; @@ -318,7 +319,8 @@ toPaste = sp.parseSmiles( ((String) transfer.getTransferData( DataFlavor.stringFlavor)).trim()); - + toPaste = new DeduceBondSystemTool().fixAromaticBondOrders(toPaste); + IMoleculeSet mols = ConnectivityChecker.partitionIntoMolecules(toPaste); for(int i=0;i<mols.getAtomContainerCount();i++) { Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2010-08-26 14:05:09 UTC (rev 15572) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2010-08-26 14:10:51 UTC (rev 15573) @@ -67,6 +67,7 @@ import org.openscience.cdk.io.RGroupQueryWriter; import org.openscience.cdk.io.IChemObjectReader.Mode; import org.openscience.cdk.layout.StructureDiagramGenerator; +import org.openscience.cdk.smiles.DeduceBondSystemTool; import org.openscience.cdk.smiles.SmilesParser; import org.openscience.cdk.tools.CDKHydrogenAdder; import org.openscience.cdk.tools.manipulator.ChemModelManipulator; @@ -213,6 +214,7 @@ sdg.setMolecule(mol); sdg.generateCoordinates(new Vector2d(0, 1)); mol = sdg.getMolecule(); + mol = new DeduceBondSystemTool().fixAromaticBondOrders(mol); //for some reason, smilesparser sets valencies, which we don't want in jcp for(int i=0;i<mol.getAtomCount();i++){ mol.getAtom(i).setValency(null); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <co...@us...> - 2010-08-30 17:16:54
|
Revision: 15574 http://cdk.svn.sourceforge.net/cdk/?rev=15574&view=rev Author: conni75 Date: 2010-08-30 17:16:47 +0000 (Mon, 30 Aug 2010) Log Message: ----------- Added a chain drawing tool (#40) Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties Added Paths: ----------- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ChainModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/controller/PhantomTextGenerator.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/small-bin/chain.gif Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2010-08-26 14:10:51 UTC (rev 15573) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPMenuTextMaker.java 2010-08-30 17:16:47 UTC (rev 15574) @@ -247,6 +247,7 @@ entries.put("periodictableTooltip", GT._("Select new drawing symbol from periodic table")); entries.put("enterelementTooltip", GT._("Enter an element symbol via keyboard")); entries.put("up_bondTooltip", GT._("Make the Bonds Stereo Up")); + entries.put("chainTooltip", GT._("Draw a chain")); entries.put("down_bondTooltip", GT._("Make the Bonds Stereo Down")); entries.put("plusTooltip", GT._("Increase the charge on an Atom")); entries.put("minusTooltip", GT._("Decrease the charge on an Atom")); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java 2010-08-26 14:10:51 UTC (rev 15573) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java 2010-08-30 17:16:47 UTC (rev 15574) @@ -61,6 +61,7 @@ import org.openscience.jchempaint.controller.IViewEventRelay; import org.openscience.jchempaint.controller.PhantomArrowGenerator; import org.openscience.jchempaint.controller.PhantomBondGenerator; +import org.openscience.jchempaint.controller.PhantomTextGenerator; import org.openscience.jchempaint.controller.SwingMouseEventRelay; import org.openscience.jchempaint.controller.undoredo.IUndoListener; import org.openscience.jchempaint.controller.undoredo.IUndoRedoable; @@ -122,6 +123,8 @@ private PhantomBondGenerator pbg = new PhantomBondGenerator(); private PhantomArrowGenerator pag = new PhantomArrowGenerator(); + + private PhantomTextGenerator ptg = new PhantomTextGenerator(); boolean isFirstDrawing = true; @@ -179,6 +182,7 @@ this, undoredohandler, new SwingUndoRedoFactory(), isViewer, applet); pbg.setControllerHub(hub); pag.setControllerHub(hub); + ptg.setControllerHub(hub); // connect mouse events from Panel to the Hub this.mouseEventRelay = new SwingMouseEventRelay(this.hub); @@ -225,6 +229,7 @@ generators.add(new TooltipGenerator()); generators.add(pbg); generators.add(pag); + generators.add(ptg); return generators; } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java 2010-08-26 14:10:51 UTC (rev 15573) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java 2010-08-30 17:16:47 UTC (rev 15574) @@ -32,6 +32,7 @@ import org.openscience.jchempaint.controller.AddRingModule; import org.openscience.jchempaint.controller.AtomAtomMappingModule; +import org.openscience.jchempaint.controller.ChainModule; import org.openscience.jchempaint.controller.ControllerHub; import org.openscience.jchempaint.controller.IControllerModule; import org.openscience.jchempaint.controller.ReactionArrowModule; @@ -87,6 +88,8 @@ newActiveModule=new Rotate3DModule(hub); } else if (type.equals("reactionArrow")) { newActiveModule=new ReactionArrowModule(hub); + } else if (type.equals("chain")) { + newActiveModule=new ChainModule(hub); } if(newActiveModule!=null){ newActiveModule.setID(type); Added: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ChainModule.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ChainModule.java (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ChainModule.java 2010-08-30 17:16:47 UTC (rev 15574) @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2010 Conni Wagner <co...@us...> + * + * Contact: cdk...@li... + * + * 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 I ask is that proper credit is given for my 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.jchempaint.controller; + +import javax.vecmath.Point2d; +import javax.vecmath.Vector2d; + +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemObject; +import org.openscience.cdk.interfaces.IChemObjectBuilder; +import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.jchempaint.renderer.Renderer; + +/** + * Adds a bond at direction that is dragged. + * + */ +public class ChainModule extends ControllerModuleAdapter { + + Point2d start; + Point2d dest; + IAtom source = null;// either atom at mouse down or new atom + IAtom merge = null; + private double bondLength; + private String ID; + + + /** + * Constructor for the ChainModule. + * + * @param chemModelRelay The current chemModelRelay. + */ + public ChainModule(IChemModelRelay chemModelRelay) { + super( chemModelRelay ); + } + + private IChemObjectBuilder getBuilder() { + return chemModelRelay.getIChemModel().getBuilder(); + } + + @Override + public void mouseClickedDown( Point2d worldCoord ) { + + start = null; + dest = null; + source = null; + bondLength = Renderer.calculateAverageBondLength( chemModelRelay.getIChemModel() ); + + // in case we are starting on an empty canvas + if(bondLength==0|| Double.isNaN(bondLength)) + bondLength=1.5; + + start = new Point2d(worldCoord); + IAtom closestAtom = chemModelRelay.getClosestAtom(worldCoord); + IBond closestBond = chemModelRelay.getClosestBond( worldCoord ); + + IChemObject singleSelection = getHighlighted( worldCoord, + closestAtom, + closestBond ); + + if(singleSelection instanceof IAtom ) { + source = (IAtom) getHighlighted(worldCoord, closestAtom); + + if(source == null) { + source = getBuilder().newInstance(IAtom.class, chemModelRelay.getController2DModel().getDrawElement(), start ); + } + else { + // Take the true (x,y) of the atom, not the click point + // otherwise it's very hard to draw a regular ring + start = closestAtom.getPoint2d(); + } + + } + } + + @Override + public void mouseDrag( Point2d worldCoordFrom, Point2d worldCoordTo ) { + IAtom closestAtom = chemModelRelay.getClosestAtom(worldCoordTo); + chemModelRelay.getRenderer().getRenderer2DModel().getMerge().remove(merge); + merge = (IAtom) getHighlighted(worldCoordTo, closestAtom); + chemModelRelay.clearPhantoms(); + //how many bonds do we want? + double distance = start.distance(worldCoordTo); + int numberofbonds = (int)(distance / (bondLength*.9)); + if(numberofbonds>0){ + //add start atom + IAtomContainer phantoms = getBuilder().newInstance(IAtomContainer.class); + IAtom startAtom; + if(source==null){ + startAtom = getBuilder().newInstance(IAtom.class, chemModelRelay.getController2DModel().getDrawElement(), start ); + }else{ + startAtom=source; + } + phantoms.addAtom(startAtom); + //make atoms and bonds as needed + for(int i=0;i<numberofbonds;i++){ + IAtom nextAtom = getBuilder().newInstance(IAtom.class, chemModelRelay.getController2DModel().getDrawElement(), new Point2d(startAtom.getPoint2d().x+bondLength, startAtom.getPoint2d().y)); + phantoms.addAtom(nextAtom); + phantoms.addBond(getBuilder().newInstance(IBond.class, startAtom, nextAtom, IBond.Order.SINGLE)); + startAtom = nextAtom; + } + Vector2d normal = + new Vector2d(start.y - worldCoordTo.y, start.x - worldCoordTo.x); + normal.normalize(); + normal.scale(bondLength); + Point2d start2 = new Point2d(start); + start2.add(normal); + Point2d worldCoordTo2 = new Point2d(worldCoordTo); + worldCoordTo2.sub(new Vector2d(normal.x*-1, normal.y*-1)); + //System.err.println("normal "+normal); + //System.err.println("start "+start); + //System.err.println("start2 "+start2); + //System.err.println("worldCoordTo "+worldCoordTo); + //System.err.println("worldCoordTo2 "+worldCoordTo2); + //System.err.println(phantoms.getAtomCount()+"___"); + for(int i=1;i<phantoms.getAtomCount();i++){ + //System.err.println("dost "+1.0/phantoms.getAtomCount()*i); + Point2d p1 = new Point2d(); + if(i % 2 == 1){ + //atoms on line2 + p1.interpolate(start2, worldCoordTo2, 1.0/phantoms.getAtomCount()*i); + }else{ + //atoms on line + p1.interpolate(start, worldCoordTo, 1.0/phantoms.getAtomCount()*i); + } + phantoms.getAtom(i).setPoint2d(p1); + //System.err.println("Atom "+i+" "+phantoms.getAtom(i).getPoint2d()); + } + chemModelRelay.setPhantoms(phantoms); + chemModelRelay.setPhantomText(""+phantoms.getAtomCount(), worldCoordTo); + } + chemModelRelay.updateView(); + } + + @Override + public void mouseClickedUp( Point2d worldCoord ) { + if(source!=null) + chemModelRelay.getPhantoms().removeAtom(0); + chemModelRelay.addFragment(getBuilder().newInstance(IMolecule.class,chemModelRelay.getPhantoms())); + chemModelRelay.clearPhantoms(); + chemModelRelay.setPhantomText(null, null); + } + + public String getDrawModeString() { + return "Draw Bond Chain"; + } + + public String getID() { + return ID; + } + + public void setID(String ID) { + this.ID=ID; + } +} Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-08-26 14:10:51 UTC (rev 15573) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ControllerHub.java 2010-08-30 17:16:47 UTC (rev 15574) @@ -73,7 +73,6 @@ import org.openscience.cdk.tools.manipulator.MolecularFormulaManipulator; import org.openscience.cdk.tools.manipulator.ReactionManipulator; import org.openscience.cdk.validate.ProblemMarker; -import org.openscience.jchempaint.GT; import org.openscience.jchempaint.applet.JChemPaintAbstractApplet; import org.openscience.jchempaint.controller.undoredo.IUndoRedoFactory; import org.openscience.jchempaint.controller.undoredo.IUndoRedoable; @@ -141,6 +140,10 @@ private Point2d phantomArrowStart = null; private Point2d phantomArrowEnd = null; + + private Point2d phantomTextPosition = null; + + private String phantomText = null; public ControllerHub(IControllerModel controllerModel, IRenderer renderer, IChemModel chemModel, IViewEventRelay eventRelay, @@ -1811,6 +1814,12 @@ public void clearPhantoms() { this.phantoms.removeAllElements(); } + + @Override + public void setPhantoms(IAtomContainer phantoms) { + this.phantoms = phantoms; + + } public IAtomContainer getPhantoms() { return this.phantoms; @@ -2720,5 +2729,19 @@ public Point2d[] getPhantomArrow() { return new Point2d[]{phantomArrowStart, phantomArrowEnd}; } + + @Override + public void setPhantomText(String text, Point2d position) { + this.phantomText = text; + this.phantomTextPosition = position; + } + + public Point2d getPhantomTextPosition() { + return phantomTextPosition; + } + + public String getPhantomText() { + return phantomText; + } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java 2010-08-26 14:10:51 UTC (rev 15573) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/IChemModelRelay.java 2010-08-30 17:16:47 UTC (rev 15574) @@ -138,7 +138,20 @@ * @param bond bond to add as phantom */ public void addPhantomBond(IBond bond); - /** + /** + * Replaces the phantom bonds/atoms with this atomcontainer. + * + * @param phantoms The new phantoms + */ + public void setPhantoms(IAtomContainer phantoms); + /** + * Sets a text to be rendered as a phantom at a certain position. + * + * @param text The text. + * @param position The position. + */ + public void setPhantomText(String text, Point2d position); + /** * Returns an IAtomContainer containing all phantom atoms and bonds. */ public IAtomContainer getPhantoms(); Added: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/PhantomTextGenerator.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/PhantomTextGenerator.java (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/PhantomTextGenerator.java 2010-08-30 17:16:47 UTC (rev 15574) @@ -0,0 +1,62 @@ +/* $Revision: $ $Author: $ $Date$ + * + * Copyright (C) 2010 Conni Wagner <co...@eb...> + * + * Contact: cdk...@li... + * + * 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 I ask is that proper credit is given for my 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.jchempaint.controller; + +import java.awt.Color; +import java.util.List; + +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.jchempaint.renderer.RendererModel; +import org.openscience.jchempaint.renderer.elements.ElementGroup; +import org.openscience.jchempaint.renderer.elements.IRenderingElement; +import org.openscience.jchempaint.renderer.elements.TextElement; +import org.openscience.jchempaint.renderer.generators.IGenerator; +import org.openscience.jchempaint.renderer.generators.IGeneratorParameter; + +public class PhantomTextGenerator implements IGenerator{ + + ControllerHub hub; + + + public PhantomTextGenerator(){ + + } + + public void setControllerHub(ControllerHub hub) { + this.hub = hub; + } + + public IRenderingElement generate(IAtomContainer ac, RendererModel model) { + if(hub.getPhantomText()==null) + return new ElementGroup(); + else + return new TextElement(hub.getPhantomTextPosition().x, hub.getPhantomTextPosition().y, hub.getPhantomText(), Color.GRAY); + } + + public List<IGeneratorParameter> getParameters() { + // TODO Auto-generated method stub + return null; + } +} Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties 2010-08-26 14:10:51 UTC (rev 15573) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_applet.properties 2010-08-30 17:16:47 UTC (rev 15574) @@ -108,4 +108,4 @@ cut copy paste flipHorizontal flipVertical rotate rotate3d lowertoolbar=C H O N P S F Cl Br I enterelement periodictable plus minus righttoolbar=triangle square pentagon hexagon benzene octagon pasteTemplate -lefttoolbar=bondTool up_bond down_bond undefined_bond undefined_stereo_bond reactionArrow +lefttoolbar=bondTool up_bond down_bond chain undefined_bond undefined_stereo_bond reactionArrow Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties 2010-08-26 14:10:51 UTC (rev 15573) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JCPGUI_application.properties 2010-08-30 17:16:47 UTC (rev 15574) @@ -121,4 +121,4 @@ rotate rotate3d flipHorizontal flipVertical cleanup zoomin zoomout lowertoolbar=C H O N P S F Cl Br I enterR plus minus enterelement periodictable righttoolbar=triangle square pentagon hexagon benzene octagon pasteTemplate -lefttoolbar=bondTool double_bondTool triple_bondTool up_bond down_bond undefined_bond undefined_stereo_bond reactionArrow +lefttoolbar=bondTool double_bondTool triple_bondTool chain up_bond down_bond undefined_bond undefined_stereo_bond reactionArrow Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2010-08-26 14:10:51 UTC (rev 15573) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2010-08-30 17:16:47 UTC (rev 15574) @@ -43,6 +43,7 @@ triple_bondImage=resources/small-bin/tripleBond.gif quad_bondImage=resources/small-bin/quadBond.gif bondToolImage=resources/small-bin/bond.gif +chainImage=resources/small-bin/chain.gif double_bondToolImage=resources/small-bin/doubleBond.gif triple_bondToolImage=resources/small-bin/tripleBond.gif quad_bondToolImage=resources/small-bin/quadBond.gif @@ -320,6 +321,7 @@ double_bondToolAction=org.openscience.jchempaint.action.ChangeBondAction@double_bondTool triple_bondToolAction=org.openscience.jchempaint.action.ChangeBondAction@triple_bondTool quad_bondToolAction=org.openscience.jchempaint.action.ChangeBondAction@quad_bondTool +chainAction=org.openscience.jchempaint.action.ChangeModeAction@chain lassoAction=org.openscience.jchempaint.action.ChangeModeAction@lasso selectAction=org.openscience.jchempaint.action.ChangeModeAction@select eraserAction=org.openscience.jchempaint.action.CopyPasteAction@eraser Added: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/small-bin/chain.gif =================================================================== (Binary files differ) Property changes on: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/small-bin/chain.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <co...@us...> - 2010-08-31 09:44:20
|
Revision: 15575 http://cdk.svn.sourceforge.net/cdk/?rev=15575&view=rev Author: conni75 Date: 2010-08-31 09:44:13 +0000 (Tue, 31 Aug 2010) Log Message: ----------- Finished the chain tool Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ChainModule.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/drawingButtons.html Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ChainModule.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ChainModule.java 2010-08-30 17:16:47 UTC (rev 15574) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/controller/ChainModule.java 2010-08-31 09:44:13 UTC (rev 15575) @@ -98,9 +98,6 @@ @Override public void mouseDrag( Point2d worldCoordFrom, Point2d worldCoordTo ) { - IAtom closestAtom = chemModelRelay.getClosestAtom(worldCoordTo); - chemModelRelay.getRenderer().getRenderer2DModel().getMerge().remove(merge); - merge = (IAtom) getHighlighted(worldCoordTo, closestAtom); chemModelRelay.clearPhantoms(); //how many bonds do we want? double distance = start.distance(worldCoordTo); @@ -122,22 +119,27 @@ phantoms.addBond(getBuilder().newInstance(IBond.class, startAtom, nextAtom, IBond.Order.SINGLE)); startAtom = nextAtom; } - Vector2d normal = - new Vector2d(start.y - worldCoordTo.y, start.x - worldCoordTo.x); - normal.normalize(); - normal.scale(bondLength); - Point2d start2 = new Point2d(start); - start2.add(normal); - Point2d worldCoordTo2 = new Point2d(worldCoordTo); - worldCoordTo2.sub(new Vector2d(normal.x*-1, normal.y*-1)); - //System.err.println("normal "+normal); - //System.err.println("start "+start); - //System.err.println("start2 "+start2); - //System.err.println("worldCoordTo "+worldCoordTo); - //System.err.println("worldCoordTo2 "+worldCoordTo2); - //System.err.println(phantoms.getAtomCount()+"___"); + //calculate a second point on the perpendicular through start point + double angle = Math.PI / 2; + double costheta = Math.cos(angle); + double sintheta = Math.sin(angle); + Point2d point = new Point2d(worldCoordTo); + Point2d center = new Point2d(start); + double relativex = point.x - center.x; + double relativey = point.y - center.y; + Point2d start2 = new Point2d(); + start2.x = relativex * costheta - relativey * sintheta + center.x; + start2.y = relativex * sintheta + relativey * costheta + center.y; + //scale that + start2.x = start.x + (start2.x-start.x)/numberofbonds; + start2.y = start.y + (start2.y-start.y)/numberofbonds; + Point2d worldCoordTo2 = new Point2d(); + worldCoordTo2.x = relativex * costheta - relativey * sintheta + point.x; + worldCoordTo2.y = relativex * sintheta + relativey * costheta + point.y; + //scale that + worldCoordTo2.x = worldCoordTo.x + (worldCoordTo2.x-worldCoordTo.x)/numberofbonds; + worldCoordTo2.y = worldCoordTo.y + (worldCoordTo2.y-worldCoordTo.y)/numberofbonds; for(int i=1;i<phantoms.getAtomCount();i++){ - //System.err.println("dost "+1.0/phantoms.getAtomCount()*i); Point2d p1 = new Point2d(); if(i % 2 == 1){ //atoms on line2 @@ -147,10 +149,15 @@ p1.interpolate(start, worldCoordTo, 1.0/phantoms.getAtomCount()*i); } phantoms.getAtom(i).setPoint2d(p1); - //System.err.println("Atom "+i+" "+phantoms.getAtom(i).getPoint2d()); } chemModelRelay.setPhantoms(phantoms); chemModelRelay.setPhantomText(""+phantoms.getAtomCount(), worldCoordTo); + IAtom closestAtom = chemModelRelay.getClosestAtom(phantoms.getAtom(phantoms.getAtomCount()-1)); + chemModelRelay.getRenderer().getRenderer2DModel().getMerge().remove(merge); + merge = (IAtom) getHighlighted(worldCoordTo, closestAtom); + if(merge!=null) + chemModelRelay.getRenderer().getRenderer2DModel().getMerge().put(merge,closestAtom); + } chemModelRelay.updateView(); } @@ -159,6 +166,10 @@ public void mouseClickedUp( Point2d worldCoord ) { if(source!=null) chemModelRelay.getPhantoms().removeAtom(0); + if(merge!=null){ + chemModelRelay.getPhantoms().getConnectedBondsList(merge).get(0).setAtom(chemModelRelay.getRenderer().getRenderer2DModel().getMerge().get(merge),1); + chemModelRelay.getPhantoms().removeAtom(merge); + } chemModelRelay.addFragment(getBuilder().newInstance(IMolecule.class,chemModelRelay.getPhantoms())); chemModelRelay.clearPhantoms(); chemModelRelay.setPhantomText(null, null); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/drawingButtons.html =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/drawingButtons.html 2010-08-30 17:16:47 UTC (rev 15574) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/userhelp_jcp/en_US/contain/drawingButtons.html 2010-08-31 09:44:13 UTC (rev 15575) @@ -38,6 +38,27 @@ Multiple clicking on an existing bond will cycle its bond order between the values 1, 2, 3 and 4.</p><br> <ul type="circle"> + <li>The Double Bond button <img src="../../../small-bin/doubleBond.gif"></li> + </ul> + <p>Puts JChemPaint in the double bond mode. It behaves like the single bond + mode, just that bonds created are double bonds. Clicking on an + existing bond will set its order to double.</p><br> + <ul type="circle"> + <li>The Triple Bond button <img src="../../../small-bin/tripleBond.gif"></li> + </ul> + <p>Puts JChemPaint in the double bond mode. It behaves like the single bond + mode, just that bonds created are double bonds. Clicking on an + existing bond will set its order to double.</p><br> + <ul type="circle"> + <li>The Chain button <img src="../../../small-bin/chain.gif"></li> + </ul> + <p>Puts JChemPaint in the chain draw mode. When you drag the mouse in this + mode, a chain of single bonds is drawn. Its length depends on the distance + you cover. The number of atoms is counted next to the mouse pointer. If you + start on an atom, this atom will be the first atom of the chain. When the last + atom in the chain is on an atom when letting the button go, this atom becomes + the last atom of the chain.</p><br> + <ul type="circle"> <li>The up-bond button <img src="../../../small-bin/up_bond.gif"></li> </ul> <p>This mode enables you to either draw filled wedge bonds the same way as single This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |