Package org.openscience.jchempaint.dialog.templates

Examples of org.openscience.jchempaint.dialog.templates.DummyClass


     * @param withsubdirs     true=all of the above will be filled, false=only names in entriesMol will be filled (values in entriesMol will be empty, other maps as well, these can be passed as null).
     * @throws Exception      Problems reading directories.
     */
    public static void createTemplatesMaps(Map<String, List<IAtomContainer>> entriesMol,
            Map<IAtomContainer, String> entriesMolName, Map<String, Icon> entriesIcon, boolean withsubdirs) throws Exception{
        DummyClass dummy = new DummyClass();
        URL loc = dummy.getClass().getProtectionDomain().getCodeSource().getLocation();
            try{
                // Create a URL that refers to a jar file on the net
                URL url = new URL("jar:"+loc.toURI()+"!/");
                // Get the jar file
                JarURLConnection conn = (JarURLConnection)url.openConnection();
                JarFile jarfile = conn.getJarFile();
                for (Enumeration<JarEntry> e = jarfile.entries() ; e.hasMoreElements() ;) {
                    JarEntry entry = e.nextElement();
                    if(entry.getName().indexOf(TEMPLATES_PACKAGE+"/")==0){
                        String restname = entry.getName().substring(new String(TEMPLATES_PACKAGE+"/").length());
                        if(restname.length()>2){
                            if(restname.indexOf("/")==restname.length()-1){
                                entriesMol.put(restname.substring(0,restname.length()-1), new ArrayList<IAtomContainer>());
                            }else if(restname.indexOf("/")>-1 && withsubdirs){
                                if(entry.getName().indexOf(".mol")>-1){
                                    InputStream ins = dummy.getClass().getClassLoader().getResourceAsStream(entry.getName());
                                    MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.RELAXED);
                                    IAtomContainer cdkmol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
                                    entriesMol.get(restname.substring(0,restname.indexOf("/"))).add(cdkmol);
                                    entriesMolName.put(cdkmol,entry.getName().substring(0,entry.getName().length()-4));
                                }else{
                                    Icon icon = new ImageIcon(new URL(url.toString()+entry.getName()));
                                    entriesIcon.put(entry.getName().substring(0,entry.getName().length()-4),icon);
                                }
                            }
                        }
                    }
                }
            }catch(IOException ex){
                //This is a version we fall back to if no jar available. This should be in Eclipse only.
                File file = new File(new File(dummy.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getAbsolutePath()+File.separator+TEMPLATES_PACKAGE.replace('/', File.separatorChar));
                for (int i=0;i<file.listFiles().length ; i++) {
                    if(file.listFiles()[i].isDirectory()){
                        File dir = file.listFiles()[i];
                        if(!dir.getName().startsWith(".")) {
                            entriesMol.put(dir.getName(), new ArrayList<IAtomContainer>());
View Full Code Here


* they need to be copied to src.
*/
public class TemplateImagesMaker {
   
    public static void main(String[] args) throws CDKException, IOException, TranscoderException{
        File file = new File(new DummyClass().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()+TemplateBrowser.TEMPLATES_PACKAGE);
        for (int i=0;i<file.listFiles().length ; i++) {
            if(file.listFiles()[i].isDirectory()){
                File dir = file.listFiles()[i];
                for(int k=0;k<dir.list().length;k++){
                    if(dir.listFiles()[k].getName().indexOf(".mol")>-1){
View Full Code Here

TOP

Related Classes of org.openscience.jchempaint.dialog.templates.DummyClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.