public static List<String> getAllIDs(IChemModel chemModel) { ArrayList<String> list = new ArrayList<String>(); if (chemModel.getID() != null) list.add(chemModel.getID()); ICrystal crystal = chemModel.getCrystal(); if (crystal != null) { list.addAll(AtomContainerManipulator.getAllIDs(crystal)); } IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); if (moleculeSet != null) { list.addAll(MoleculeSetManipulator.getAllIDs(moleculeSet)); } IReactionSet reactionSet = chemModel.getReactionSet(); if (reactionSet != null) { list.addAll(ReactionSetManipulator.getAllIDs(reactionSet)); } return list; } }
/** * Allows setting of the is modified stage (e. g. after save) * * @param isModified * is modified */ public void setModified(boolean isModified) { this.modified = isModified; Container c = this.getTopLevelContainer(); if (c instanceof JFrame) { String id = renderPanel.getChemModel().getID(); //String title = ((JFrame) c).getTitle(); if (isModified) ((JFrame) c).setTitle('*' + id + AbstractJChemPaintPanel.getAppTitle()); else ((JFrame) c).setTitle(id + AbstractJChemPaintPanel.getAppTitle()); } }
protected File saveAsCML2(IChemObject object, File outFile) throws Exception { if(Float.parseFloat(System.getProperty("java.specification.version"))<1.5){ JOptionPane.showMessageDialog(null,"For saving as CML you need Java 1.5 or higher!"); return outFile; } logger.info("Saving the contents in a CML 2.0 file..."); String fileName = outFile.toString(); if (!fileName.endsWith(".cml")) { fileName += ".cml"; outFile = new File(fileName); } FileWriter sw = new FileWriter(outFile); cow = new CMLWriter(sw); if (cow != null && askIOSettings()) { cow.addChemObjectIOListener(new SwingGUIListener(jcpPanel, IOSetting.Importance.HIGH)); } cow.write(object); cow.close(); sw.close(); if(jcpPanel instanceof JChemPaintPanel) ((JChemPaintPanel)jcpPanel).setTitle(jcpPanel.getChemModel().getID()); return outFile; }
protected File saveAsCDKSourceCode(IChemModel model, File outFile) throws Exception { logger.info("Saving the contents as a CDK source code file..."); String fileName = outFile.toString(); if (!fileName.endsWith(".cdk")) { fileName += ".cdk"; outFile = new File(fileName); } cow = new CDKSourceCodeWriter(new FileWriter(outFile)); if (cow != null && askIOSettings()) { cow.addChemObjectIOListener(new SwingGUIListener(jcpPanel, IOSetting.Importance.HIGH)); } Iterator<IAtomContainer> containers = ChemModelManipulator.getAllAtomContainers(model).iterator(); while (containers.hasNext()) { IAtomContainer ac = (IAtomContainer)containers.next(); if (ac != null) { cow.write(ac); } else { System.err.println("AC == null!"); } } cow.close(); if(jcpPanel instanceof JChemPaintPanel) ((JChemPaintPanel)jcpPanel).setTitle(jcpPanel.getChemModel().getID()); return outFile; }
.getChemModel().getID() + " " + GT.get("has unsaved data. Do you want to save it?"), GT.get("Unsaved data"), JOptionPane.YES_NO_CANCEL_OPTION,
private CMLList cdkChemModelToCMLList(IChemModel model, boolean setIDs) { CMLList cmlList = new CMLList(); cmlList.setConvention("cdk:model"); if (useCMLIDs && setIDs) { IDCreator.createIDs(model); } if (model.getID() != null && !model.getID().equals("")) cmlList.setId(model.getID()); if (model.getCrystal() != null) { cmlList.appendChild(cdkCrystalToCMLMolecule(model.getCrystal(), false)); } if (model.getReactionSet() != null) { cmlList.appendChild(cdkReactionSetToCMLReactionList(model.getReactionSet(), false)); } if (model.getMoleculeSet() != null) { cmlList.appendChild(cdkAtomContainerSetToCMLList(model.getMoleculeSet(), false)); } return cmlList; }
private CMLList cdkChemModelToCMLList(IChemModel model, boolean setIDs) { CMLList cmlList = new CMLList(); cmlList.setConvention("cdk:model"); if (useCMLIDs && setIDs) { IDCreator.createIDs(model); } if (model.getID() != null && !model.getID().equals("")) cmlList.setId(model.getID()); if (model.getCrystal() != null) { cmlList.appendChild(cdkCrystalToCMLMolecule(model.getCrystal(), false)); } if (model.getReactionSet() != null) { cmlList.appendChild(cdkReactionSetToCMLReactionList(model.getReactionSet(), false)); } if (model.getMoleculeSet() != null) { cmlList.appendChild(cdkAtomContainerSetToCMLList(model.getMoleculeSet(), false)); } return cmlList; }
protected File saveAsRXN(IChemModel model, File outFile) throws IOException, CDKException { if(model.getMoleculeSet()!=null && model.getMoleculeSet().getAtomContainerCount()>0){ String error = GT.get("Problems handling data"); String message = GT.get("{0} files cannot contain extra molecules. You painted molecules outside the reaction(s), which will not be in the file. Continue?", "RXN"); int answer = JOptionPane.showConfirmDialog(jcpPanel, message, error, JOptionPane.YES_NO_OPTION); if(answer == JOptionPane.NO_OPTION) return null; } if(model.getReactionSet()==null || model.getReactionSet().getReactionCount()==0){ String error = GT.get("Problems handling data"); String message = GT.get("RXN can only save reactions. You have no reactions painted!"); JOptionPane.showMessageDialog(jcpPanel, message, error, JOptionPane.WARNING_MESSAGE); return null; } logger.info("Saving the contents in an rxn file..."); String fileName = outFile.toString(); if (!fileName.endsWith(".rxn")) { fileName += ".rxn"; outFile = new File(fileName); } outFile=new File(fileName); cow = new MDLRXNWriter(new FileWriter(outFile)); cow.write(model.getReactionSet()); cow.close(); if(jcpPanel instanceof JChemPaintPanel) ((JChemPaintPanel)jcpPanel).setTitle(jcpPanel.getChemModel().getID()); return outFile; }
cow.close(); if(jcpPanel instanceof JChemPaintPanel) ((JChemPaintPanel)jcpPanel).setTitle(jcpPanel.getChemModel().getID()); return outFile;
((JChemPaintPanel)jcpPanel).setTitle(jcpPanel.getChemModel().getID()); return outFile;
private static void createIDsForChemModel(IChemModel model, List<String> tabuList) { if (tabuList == null) tabuList = ChemModelManipulator.getAllIDs(model); if (null == model.getID()) { chemModelCount = setID(CHEMMODEL_PREFIX, chemModelCount, model, tabuList); } ICrystal crystal = model.getCrystal(); if (crystal != null) { if (policy == OBJECT_UNIQUE_POLICY) { atomCount = 0; bondCount = 0; } createIDsForAtomContainer(crystal, tabuList); } IAtomContainerSet moleculeSet = model.getMoleculeSet(); if (moleculeSet != null) { if (policy == OBJECT_UNIQUE_POLICY) { atomContainerSetCount = 0; atomContainerCount = 0; } createIDsForAtomContainerSet(moleculeSet, tabuList); } IReactionSet reactionSet = model.getReactionSet(); if (reactionSet != null) { if (policy == OBJECT_UNIQUE_POLICY) { reactionSetCount = 0; reactionCount = 0; } createIDsForReactionSet(reactionSet, tabuList); } }