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

📄 filemenu.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        new NewLibrary(newLibName);    }	private static class NewLibrary extends Job {        private String newLibName;        public NewLibrary(String newLibName) {            super("New Library", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);            this.newLibName = newLibName;            startJob();        }        public boolean doIt() throws JobException        {            Library lib = Library.newInstance(newLibName, null);            if (lib == null) return false;            lib.setCurrent();            System.out.println("New "+lib+" created");            return true;        }        public void terminateOK()        {            EditWindow.repaintAll();            ToolBar.setSaveLibraryButton();        }    }    /**     * This method implements the command to read a library.     * It is interactive, and pops up a dialog box.     */    public static void openLibraryCommand()    {        String fileName = OpenFile.chooseInputFile(FileType.LIBRARYFORMATS, null);        if (fileName != null)        {            // start a job to do the input            URL fileURL = TextUtils.makeURLToFile(fileName);			String libName = TextUtils.getFileNameWithoutExtension(fileURL);			Library deleteLib = Library.findLibrary(libName);            RenameAndSaveLibraryTask saveTask = null;			if (deleteLib != null)			{				// library already exists, prompt for save                Collection<RenameAndSaveLibraryTask> librariesToSave = preventLoss(deleteLib, 2);                if (librariesToSave == null) return;                if (!librariesToSave.isEmpty()) {                    assert librariesToSave.size() == 1;                    saveTask = librariesToSave.iterator().next();                    assert saveTask.lib == deleteLib;                }				WindowFrame.removeLibraryReferences(deleteLib);			}			FileType type = getLibraryFormat(fileName, FileType.DEFAULTLIB);			new ReadLibrary(fileURL, type, TextUtils.getFilePath(fileURL), deleteLib, saveTask, null);        }    }    /**     * This method implements the command to read a library.     * It takes library URL from a parameter.     * @param file URL of a library     */    public static void openLibraryCommand(URL file)    {        String fileName = file.getFile();        FileType defType = getLibraryFormat(fileName, null);        if (defType == null) {            // no valid extension, search for file with extension            URL f = TextUtils.makeURLToFile(fileName + "." + FileType.JELIB.getExtensions()[0]);            if (TextUtils.URLExists(f, null)) {                defType = FileType.JELIB;                file = f;            }        }        if (defType == null) {            // no valid extension, search for file with extension            URL f = TextUtils.makeURLToFile(fileName + "." + FileType.ELIB.getExtensions()[0]);            if (TextUtils.URLExists(f, null)) {                defType = FileType.ELIB;                file = f;            }        }        if (defType == null) {            // no valid extension, search for file with extension            URL f = TextUtils.makeURLToFile(fileName + "." + FileType.DELIB.getExtensions()[0]);            if (TextUtils.URLExists(f, null)) {                defType = FileType.DELIB;                file = f;            }        }        if (defType == null) {            // no valid extension, search for file with extension            URL f = TextUtils.makeURLToFile(fileName + "." + FileType.READABLEDUMP.getExtensions()[0]);            if (TextUtils.URLExists(f, null)) {                defType = FileType.READABLEDUMP;                file = f;            }        }        if (defType == null) defType = FileType.DEFAULTLIB;        File f = new File(file.getPath());        if (defType != FileType.DELIB && f.isDirectory())            System.out.println("The filename provided is not a valid Electric's library: '" +            fileName + "'.");        else            new ReadLibrary(file, defType, TextUtils.getFilePath(file), null, null, null);    }    /** Get the type from the fileName, or if no valid Library type found, return defaultType.     */    public static FileType getLibraryFormat(String fileName, FileType defaultType) {        if (fileName != null)        {            if (fileName.endsWith(File.separator)) {                fileName = fileName.substring(0, fileName.length()-File.separator.length());            }            for (FileType type :  FileType.libraryTypes)            {                if (fileName.endsWith("."+type.getExtensions()[0])) return type;            }        }        return defaultType;    }	/**	 * Class to read a library in a new thread.	 * For a non-interactive script, use ReadLibrary job = new ReadLibrary(filename, format).	 */	public static class ReadLibrary extends Job	{		private URL fileURL;		private FileType type;        private File projsettings;		private Library deleteLib;        private RenameAndSaveLibraryTask saveTask;        private String cellName; // cell to view once the library is open        private Library lib;		public ReadLibrary(URL fileURL, FileType type, String cellName) {            this(fileURL, type, null, null, null, cellName);        }		public ReadLibrary(URL fileURL, FileType type, String settingsDirectory,                Library deleteLib, RenameAndSaveLibraryTask saveTask, String cellName)		{			super("Read External Library", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.fileURL = fileURL;			this.type = type;			this.deleteLib = deleteLib;            this.saveTask = saveTask;            this.cellName = cellName;            Map<Setting,Object> projectSettings = null;            if (settingsDirectory != null) {                projsettings = new File(settingsDirectory, "projsettings.xml");                if (!projsettings.exists())                    projsettings = null;            }            if (projsettings == null) {                projectSettings = LibraryFiles.readProjectsSettingsFromLibrary(fileURL, type);                if (projectSettings != null) {                    Map<Setting,Object> settingsToReconcile = Setting.reconcileSettings(projectSettings);                    if (!settingsToReconcile.isEmpty()) {                        String libName = TextUtils.getFileNameWithoutExtension(fileURL);                        OptionReconcile dialog = new OptionReconcile(TopLevel.getCurrentJFrame(), settingsToReconcile, libName, this);                        dialog.setVisible(true);                        return; // startJob will be executed by reconcilation dialog                    }                }            }			startJob();		}		public boolean doIt() throws JobException		{			// see if the former library can be deleted			if (deleteLib != null)			{                // save the library                if (saveTask != null) {                    assert deleteLib == saveTask.lib;                    saveTask.renameAndSave();                    deleteLib = saveTask.lib;                }				if (!deleteLib.kill("replace")) return false;				deleteLib = null;			}            // read project settings            if (projsettings != null)                ProjSettings.readSettings(projsettings, false);            lib = LibraryFiles.readLibrary(fileURL, null, type, false);            if (lib == null)            {                System.out.println("Error importing " + fileURL.getFile() + " as " + type + " format.");                return false;            }            fieldVariableChanged("lib");             // new library open: check for default "noname" library and close if empty            Library noname = Library.findLibrary("noname");            if (noname != null) {                // Only when noname is not exactly the library read that could be empty                if (noname == lib)                {                    // Making sure the URL is propoerly setup since the dummy noname library is                    // retrieved from LibraryFiles.readLibrary()                    if (lib.getLibFile() == null)                        lib.setLibFile(fileURL);                }                else if (!noname.getCells().hasNext()) {                    noname.kill("delete");                }            }            User.setCurrentLibrary(lib);			return true;		}        public void terminateOK()        {           Cell showThisCell = (cellName != null) ?                    lib.findNodeProto(cellName) :                    Job.getUserInterface().getCurrentCell(lib);        	doneOpeningLibrary(showThisCell);            // Repair libraries.            CircuitChanges.checkAndRepairCommand(true);            User.addRecentlyOpenedLibrary(fileURL.getFile());            updateRecentlyOpenedLibrariesList();        }	}    public static void updateRecentlyOpenedLibrariesList() {        String [] recentLibs = User.getRecentlyOpenedLibraries();        List<EMenuItem> list = new ArrayList<EMenuItem>();        for (int i=0; i<recentLibs.length; i++) {            EMenuItem menu = new EMenuItem(recentLibs[i], null, false) {                public void run() {                    openLibraryCommand(TextUtils.makeURLToFile(this.getText()));                    File f = new File(this.getText());                    if (f.exists()) {                        User.setWorkingDirectory(f.getParent());                        FileType.LIBRARYFORMATS.setGroupPath(f.getParent());                    }                }                @Override protected void updateButtons() {}            };            list.add(menu);        }        if (list.size() == 0) {            EMenuItem menu = new EMenuItem("<none>") {                public void run() {}            };            list.add(menu);        }        openRecentLibs.setDynamicItems(list);    }    /**	 * Class to import a library in a new thread.	 */	public static class ImportLibrary extends Job	{		private URL fileURL;		private FileType type;		private Library createLib;		private Library deleteLib;        private RenameAndSaveLibraryTask saveTask;		private boolean useCurrentLib;		private long startMemory, startTime;		public ImportLibrary(URL fileURL, FileType type,                Library deleteLib, RenameAndSaveLibraryTask saveTask)		{			super("Import External Library", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.fileURL = fileURL;			this.type = type;			this.deleteLib = deleteLib;            this.saveTask = saveTask;			this.useCurrentLib = false;			if (type == FileType.DAIS)			{				startTime = System.currentTimeMillis();				startMemory = com.sun.electric.Main.getMemoryUsage();			}			startJob();		}		// this version imports to current library		public ImportLibrary(URL fileURL, FileType type)		{			super("Import to Current Library", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.fileURL = fileURL;			this.type = type;			this.useCurrentLib = true;			startJob();		}		public boolean doIt() throws JobException		{			// see if the former library can be deleted			if (deleteLib != null)			{                // save the library                if (saveTask != null) {                    assert deleteLib == saveTask.lib;                    saveTask.renameAndSave();                    deleteLib = saveTask.lib;                }				if (!deleteLib.kill("replace")) return false;				deleteLib = null;			}			if (useCurrentLib) {				createLib = Input.importToCurrentLibrary(fileURL, type);			} else {				createLib = Input.importLibrary(fileURL, type);			}						if (createLib == null) return false;            // new library open: check for default "noname" library and close if empty            Library noname = Library.findLibrary("noname");            if (noname != null)            {            	if (!noname.getCells().hasNext())            	{                	noname.kill("delete");                }            }			fieldVariableChanged("createLib");			return true;		}		public void terminateOK()        {    		User.setCurrentLibrary(createLib);        	Cell showThisCell = Job.getUserInterface().getCurrentCell(createLib);

⌨️ 快捷键说明

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