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. |