public static IChemModel readFromFileReader(final URL fileURL, final String url, final String type, final AbstractJChemPaintPanel panel) throws CDKException { IChemModel chemModel = null; WaitDialog.showDialog(); // InChI workaround - guessing for InChI results into an INChIReader // (this does not work, we'd need an INChIPlainTextReader..) // Instead here we use STDInChIReader, to be consistent throughout JCP // using the nestedVm based classes. try { ISimpleChemObjectReader cor = null; if (url.endsWith("txt")) { // chemModel = StdInChIReader.readInChI(fileURL); } else { cor = FileHandler.createReader(fileURL, url, type); chemModel = JChemPaint.getChemModelFromReader(cor, panel); } boolean avoidOverlap = true; if (cor instanceof RGroupQueryReader) { avoidOverlap = false; } JChemPaint.cleanUpChemModel(chemModel, avoidOverlap, panel); } finally { WaitDialog.hideDialog(); } return chemModel; }
/** * Read an IChemModel from a given file. * * @param file * @param type * @param panel * @return * @throws CDKException * @throws FileNotFoundException */ public static IChemModel readFromFile(final File file, final String type, final AbstractJChemPaintPanel panel) throws CDKException, FileNotFoundException { final String url = file.toURI().toString(); ISimpleChemObjectReader cor = null; try { cor = FileHandler.createReader(file.toURI().toURL(), url, type); } catch (final MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (cor instanceof CMLReader) { cor.setReader(new FileInputStream(file)); // hack } else { cor.setReader(new FileReader(file)); // hack } final IChemModel chemModel = JChemPaint.getChemModelFromReader(cor, panel); boolean avoidOverlap = true; if (cor instanceof RGroupQueryReader) { avoidOverlap = false; } JChemPaint.cleanUpChemModel(chemModel, avoidOverlap, panel); return chemModel; }