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

📄 edit.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: Edit.java * * Copyright (c) 2003 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING.  If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.cvspm;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.Snapshot;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.database.change.Undo;import com.sun.electric.database.id.CellId;import com.sun.electric.tool.Job;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.Exec;import javax.swing.*;import javax.swing.table.*;import java.io.*;import java.util.*;import java.util.List;import java.text.DateFormat;import java.net.InetAddress;import java.awt.*;/** * User: gainsley * Date: Mar 15, 2006 */public class Edit {    // ------------------------ Edit -----------------------------    /**     * Mark the current user as an editor of the cell     * @param cell the Cell to mark.     * @return true if successful.     */    public static boolean edit(Cell cell) {        File file = CVS.getCellFile(cell);        if (!CVS.isDELIB(cell.getLibrary())) return false;        if (!CVS.isFileInCVS(CVS.getCellFile(cell))) return false;        String dir = file.getParent();        String c = file.getName();        boolean success = edit(c, dir);        return success;    }    /**     * Establish a lock the file in dir for your exclusive edit.     * If anyone else is editing the file, this returns false, and     * if 'showDialog' is true, pops up an error dialog, otherwise it     * just prints to System.out.     * @return true if the edit lock is now yours, false otherwise.     */    public static boolean edit(String file, String dir) {        // check if anyone else is editing the file        // no one editing, set edit lock        CVS.runCVSCommand("edit -a none "+file, "Edit",                dir, System.out);        return true;    }    // ---------------------- Get Editors ----------------------------    public static void listEditorsProject() {        List<Library> allLibs = new ArrayList<Library>();        for (Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) {            Library lib = it.next();            if (lib.isHidden()) continue;            if (!lib.isFromDisk()) continue;            allLibs.add(lib);        }        (new ListEditorsJob(allLibs, null, true)).startJob();    }    public static void listEditorsOpenLibraries() {        List<Library> allLibs = new ArrayList<Library>();        for (Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) {            Library lib = it.next();            if (lib.isHidden()) continue;            if (!lib.isFromDisk()) continue;            allLibs.add(lib);        }        listEditors(allLibs, null);    }    public static void listEditors(Library lib) {        List<Library> libs = new ArrayList<Library>();        libs.add(lib);        listEditors(libs, null);    }    public static void listEditors(Cell cell) {        List<Cell> cells = new ArrayList<Cell>();        cells.add(cell);        listEditors(null, cells);    }    public static void listEditors(List<Library> libs, List<Cell> cells) {        (new ListEditorsJob(libs, cells, false)).startJob();            }    public static class ListEditorsJob extends Job {        private List<Library> libs;        private List<Cell> cells;        private boolean forProject;        public ListEditorsJob(List<Library> libs, List<Cell> cells, boolean forProject) {            super("List CVS Editors", User.getUserTool(), Job.Type.EXAMINE, null, null, Job.Priority.USER);            this.libs = libs;            this.cells = cells;            this.forProject = forProject;            if (this.libs == null) this.libs = new ArrayList<Library>();            if (this.cells == null) this.cells = new ArrayList<Cell>();        }        public boolean doIt() {            String useDir = CVS.getUseDir(libs, cells);            StringBuffer libsBuf = CVS.getLibraryFiles(libs, useDir);            StringBuffer cellsBuf = CVS.getCellFiles(cells, useDir);            String args = libsBuf + " " + cellsBuf;            if (args.trim().equals("")) return true;            if (forProject) args = "";            CVS.runCVSCommand("editors "+args, "List CVS Editors", useDir, System.out);            System.out.println("List CVS Editors complete.");            return true;        }    }/*    static List<Editor> getEditors(Library lib) {        File file = new File(lib.getLibFile().getPath());        if (!CVS.isFileInCVS(file)) {            // library not in CVS            System.out.println(lib.getName()+" is not in CVS");            return null;        }        String dir = file.getParent();        String delib = file.getName();        return getEditors(delib, dir);    }    static List<Editor> getEditors(Cell cell) {        File file = CVS.getCellFile(cell);        if (!CVS.isFileInCVS(CVS.getCellFile(cell))) return null;        String dir = file.getParent();        String c = file.getName();        return getEditors(c, dir);    }    static List<Editor> getEditors(String file, String dir) {        ByteArrayOutputStream out = new ByteArrayOutputStream();        CVS.runCVSCommand("editors "+file, "Checking for editors of "+file,                dir, out);        LineNumberReader result = new LineNumberReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray())));        return parseOutput(result);    }*/    // ----------------------- Editing Modified Cells -----------------------    private static Map<CellId,CellId> modifiedCells = new HashMap<CellId,CellId>();    /**      * Handles database changes of a Job.      * @param oldSnapshot database snapshot before Job.      * @param newSnapshot database snapshot after Job and constraint propagation.      * @param undoRedo true if Job was Undo/Redo job.      */    static void endBatch(Snapshot oldSnapshot, Snapshot newSnapshot, boolean undoRedo) {        //if (undoRedo) return;        // keep track of which cells are newly modified        List<Cell> newlyModifiedCells = new ArrayList<Cell>();        List<Cell> newlyUnmodifiedCells = new ArrayList<Cell>();        for (CellId cellId: newSnapshot.getChangedCells(oldSnapshot)) {            Cell cell = Cell.inCurrentThread(cellId);            if (cell == null) {                modifiedCells.remove(cellId);                continue;            }            if (cell.isModified() && !modifiedCells.containsKey(cellId)) {                modifiedCells.put(cellId, cellId);                newlyModifiedCells.add(cell);            }            if (!cell.isModified() && modifiedCells.containsKey(cellId)) {                // undo or save                modifiedCells.remove(cellId);                newlyUnmodifiedCells.add(cell);            }        }        // mark for edit any newly modified cells that are not modified in CVS        // (if they are modified in CVS, they have already been marked for edit        List<Cell> markForEdit = new ArrayList<Cell>();        for (Cell cell : newlyModifiedCells) {            State state = CVSLibrary.getState(cell);            if (state == State.NONE || state == State.CONFLICT || state == State.UPDATE)                markForEdit.add(cell);        }        // unmark for edit any newly unmodified cells that are not modified in CVS        // (this will only happen if you undo to the point of being unmodified,        //  and the cell is then consistent with what is in CVS)        List<Cell> unmarkForEdit = new ArrayList<Cell>();        for (Cell cell : newlyUnmodifiedCells) {            State state = CVSLibrary.getState(cell);            if (state == State.NONE || state == State.CONFLICT || state == State.UPDATE)                unmarkForEdit.add(cell);        }        // condense jelibs cells into jelibs        CVSLibrary.LibsCells modified = CVSLibrary.getInCVSSorted(new ArrayList<Library>(), markForEdit);        if (modified.libs.size() != 0 || modified.cells.size() != 0) {            (new MarkForEditJob(modified.libs, modified.cells, true, false)).startJob();        }        CVSLibrary.LibsCells unmodified = CVSLibrary.getInCVSSorted(new ArrayList<Library>(), unmarkForEdit);        if (unmodified.libs.size() != 0 || unmodified.cells.size() != 0) {            (new MarkForEditJob(unmodified.libs, unmodified.cells, false, true)).startJob();        }    }    public static class MarkForEditJob extends Job {        private List<Library> libs;        private List<Cell> cells;        private boolean unedit;         // true to unmark rather than mark        private boolean checkConflicts;        private List<Editor> editors;        public MarkForEditJob(List<Library> libs, List<Cell> cells, boolean checkConflicts, boolean unedit) {            super("Check CVS Editors", User.getUserTool(), Job.Type.EXAMINE, null, null, Job.Priority.USER);            this.libs = libs;            this.cells = cells;            this.checkConflicts = checkConflicts;            this.unedit = unedit;            this.editors = new ArrayList<Editor>();            if (this.libs == null) this.libs = new ArrayList<Library>();            if (this.cells == null) this.cells = new ArrayList<Cell>();        }        public boolean doIt() {            String useDir = CVS.getUseDir(libs, cells);            StringBuffer libsBuf = CVS.getLibraryFiles(libs, useDir);            StringBuffer cellsBuf = CVS.getCellFiles(cells, useDir);            String args = libsBuf + " " + cellsBuf;            if (args.trim().equals("")) return true;            if (unedit) {                // can only unedit files that are up-to-date                // otherwise, you cvs will ask if you want to rollback local copy                List<Library> libsToUnedit = new ArrayList<Library>();                List<Cell> cellsToUnedit = new ArrayList<Cell>();                for (Library lib : libs) {                    State state = CVSLibrary.getState(lib);                    if (state == State.NONE) libsToUnedit.add(lib);                }                for (Cell cell : cells) {                    State state = CVSLibrary.getState(cell);                    if (state == State.NONE) cellsToUnedit.add(cell);                }                libsBuf = CVS.getLibraryFiles(libsToUnedit, useDir);                cellsBuf = CVS.getCellFiles(cellsToUnedit, useDir);                args = libsBuf + " " + cellsBuf;                if (args.trim().equals("")) return true;                Exec.OutputStreamChecker checker = new Exec.OutputStreamChecker(System.out, "has been modified; revert changes?", false, null);                checker.addOutputStreamCheckerListener(new UneditResponder(libs, cells));                //System.out.println("Unmarking CVS edit: "+args);                CVS.runCVSCommand("unedit -l "+args, "CVS Unedit", useDir, checker);                return true;            }            if (checkConflicts) {                //System.out.println("Checking editors for: "+args);                ByteArrayOutputStream out = new ByteArrayOutputStream();                CVS.runCVSCommand("editors "+args, "Check CVS Editors", useDir, out);                LineNumberReader reader = new LineNumberReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray())));                editors = parseOutput(reader);                // also run status to see if they need an update                Update.StatusResult status = Update.update(args, useDir, Update.UpdateEnum.STATUS);                for (Cell cell : status.getCells(State.CONFLICT)) {                    Editor e = new Editor(cell.describe(false), "CONFLICT", new Date(), "", "");                    editors.add(e);                }                for (Cell cell : status.getCells(State.UPDATE)) {

⌨️ 快捷键说明

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