⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codingmanager.java

📁 无线传感器网络节点Sun SPOT管理工具
💻 JAVA
字号:
/* * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.  *  * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is * described in this document. In particular, and without limitation, these intellectual property rights may * include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents * or pending patent applications in the U.S. and in other countries. *  * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. * standard license agreement and applicable provisions of the FAR and its supplements. *  * Use is subject to license terms.  *  * This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo and * Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.  *  * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits r?serv?s. *  * Sun Microsystems, Inc. d?tient les droits de propri?t? intellectuels relatifs ? la technologie incorpor?e dans * le produit qui est d?crit dans ce document. En particulier, et ce sans limitation, ces droits de propri?t? * intellectuelle peuvent inclure un ou plus des brevets am?ricains list?s ? l'adresse http://www.sun.com/patents * et un ou les brevets suppl?mentaires ou les applications de brevet en attente aux Etats - Unis et dans les * autres pays. *  * L'utilisation est soumise aux termes du contrat de licence. *  * Cette distribution peut comprendre des composants d?velopp?s par des tierces parties. * Sun, Sun Microsystems, le logo Sun et Java sont des marques de fabrique ou des marques d?pos?es de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.spot.spotworld;import com.sun.spot.spotworld.gui.AppProjectFileChooser;import com.sun.spot.spotworld.gui.SpotWorldPortal;import java.io.File;import java.io.IOException;import javax.swing.JComponent;import javax.swing.JFileChooser;import javax.swing.filechooser.FileFilter;/** * Information about java source files, suite files, and all that, and methods for managing * and deploying suites. * * @author randy */public class CodingManager {        private static CodingManager soleInstance;        public static CodingManager getInstance(){        if(soleInstance == null){            soleInstance = new CodingManager();        }         return soleInstance;    }        public CodingManager() {        init();    }        public void init(){        //Try hard to start with some default directory        File currentProjDir = getCurrentProjDir();        if(currentProjDir.isFile()){            //Maybe can happen if running from a jar file. Find a directory instead.            currentProjDir = currentProjDir.getParentFile();                        if(currentProjDir == null) {                currentProjDir = File.listRoots()[0];            }            setCurrentProjDir(currentProjDir);        }    }        /*     * A cleaned project directory has a build.xml file and a src/ directory.     */    public String checkIfProperProjDirectory(String dirName){        String reply = "OK";        File dir = new File(dirName);        if(! dir.exists()) {            reply = "" + dirName + ": does not exist.";             return reply;        }        if(! dir.isDirectory()){            reply = "" + dirName + " is a file, please choose a directory with build.xml and a src subdirectory.";            return reply;        }        File buildFile = new File(dirName + File.separator + "build.xml");        if(! buildFile.exists()) reply = "No build.xml file in " + dirName;        File srcDir    = new File(dirName + File.separator + "src");        if(! buildFile.exists()){            if(reply.equals("OK")) {                reply = "No src directory in " + dirName;            } else {                reply = reply + "\nNo src directory in " + dirName;            }        }         return reply;    }        public File getBuildFileFromUser(JComponent comp){        AppProjectFileChooser fc;        try {            fc = new AppProjectFileChooser(getCurrentProjDir().getCanonicalPath());              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);            fc.setApproveButtonText("Use this directory");            fc.setDialogTitle("Select application project directory (must contain a build.xml)");            String dirName = getCurrentProjDir().getCanonicalPath();            if(!dirName.endsWith(File.separator)) dirName = dirName + File.separator;            File f = new File(dirName +  "build.xml");            // On the Mac the next line does not work .. it is a known and filed bug.            if(f.exists()) fc.setSelectedFile(f);            int returnVal = fc.showOpenDialog(comp);            if (returnVal == JFileChooser.APPROVE_OPTION) {                 File sel = fc.getSelectedFile();                setCurrentProjDir(sel.getParentFile());                return sel;            }        } catch (IOException ex) {            ex.printStackTrace();        }        return null;    }        public FileFilter newProjFileFilter(){        return new FileFilter(){            public boolean accept(File f){                return f.isDirectory() || f.getName().equals("build.xml");            }            public String getDescription(){ return "build.xml"; }        };    }     public File getCurrentProjDir() {        String dirName = SpotWorldPortal.getSPOTWorldProperty("DeploymentDir");         if(dirName == null){            dirName = System.getProperty("sunspot.home") + "/src/kami/";            System.out.println("USING = " + dirName);        }        File newDir = new File(dirName);        if(! newDir.exists()) newDir = new File("."); //Gues that has to exist.        setCurrentProjDir(newDir);        return newDir;    }    public void setCurrentProjDir(File dir) {        SpotWorldPortal.setSPOTWorldProperty("DeploymentDir", dir.getAbsolutePath());    }        /*     * Utility: most recent modification time (in milliseconds since 1969) of the      * files in this directory, through subdirectories transitivly.     */        public long getMostRecentModTime(File dir){        if(! dir.isDirectory()){            throw new RuntimeException("method applies only to directories.");        }        long reply = 0;        long t = 0;        File[] files = dir.listFiles();        for(File f : files){            if(f.isDirectory()) t = getMostRecentModTime(f);            else t = f.lastModified();            if(t > reply) reply = t;        }        return reply;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -