📄 filemenu.java
字号:
super("Write "+task.lib, User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); // CHANGE because of possible renaming this.task = task; startJob(); } @Override public boolean doIt() throws JobException { // rename the library if requested idMapper = task.renameAndSave(); fieldVariableChanged("idMapper"); return true; } @Override public void terminateOK() { User.fixStaleCellReferences(idMapper); } } private static class RenameAndSaveLibraryTask implements Serializable { private Library lib; private String newName; private FileType type; private boolean compatibleWith6; private RenameAndSaveLibraryTask(Library lib, String newName, FileType type, boolean compatibleWith6) { this.lib = lib; this.newName = newName; this.type = type; this.compatibleWith6 = compatibleWith6; } private IdMapper renameAndSave() throws JobException { IdMapper idMapper = null; boolean success = false; try { if (newName != null) { URL libURL = TextUtils.makeURLToFile(newName); lib.setLibFile(libURL); idMapper = lib.setName(TextUtils.getFileNameWithoutExtension(libURL)); if (idMapper != null) lib = EDatabase.serverDatabase().getLib(idMapper.get(lib.getId())); } success = !Output.writeLibrary(lib, type, compatibleWith6, false, false); } catch (Exception e) { e.printStackTrace(System.out); throw new JobException("Exception caught when saving files: " + e.getMessage() + "Please check your disk libraries"); } if (!success) throw new JobException("Error saving files. Please check your disk libraries"); return idMapper; } } /** * This method implements the command to save a library to a different file. * It is interactive, and pops up a dialog box. */ public static void saveAsLibraryCommand(Library lib) { saveLibraryCommand(lib, FileType.DEFAULTLIB, false, true, true); WindowFrame.wantToRedoTitleNames(); } /** * This method implements the command to save all libraries. */ public static void saveAllLibrariesCommand() { saveAllLibrariesCommand(FileType.DEFAULTLIB, false, true); } public static void saveAllLibrariesCommand(FileType type, boolean compatibleWith6, boolean forceToType) { HashMap<Library,FileType> libsToSave = new HashMap<Library,FileType>(); for(Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) { Library lib = it.next(); if (lib.isHidden()) continue; if (!lib.isChanged()) continue; if (lib.getLibFile() != null) type = getLibraryFormat(lib.getLibFile().getFile(), type); libsToSave.put(lib, type); } boolean justSkip = false; for(Iterator<Library> it = libsToSave.keySet().iterator(); it.hasNext(); ) { Library lib = it.next(); type = libsToSave.get(lib); if (!saveLibraryCommand(lib, type, compatibleWith6, forceToType, false)) { if (justSkip) continue; if (it.hasNext()) { String [] options = {"Cancel", "Skip this Library"}; int ret = JOptionPane.showOptionDialog(TopLevel.getCurrentJFrame(), "Cancel all library saving, or just skip saving this library?", "Save Cancelled", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, "Cancel"); if (ret == 1) { justSkip = true; continue; } } break; } } } public static void saveAllLibrariesInFormatCommand() { Object[] formats = {FileType.JELIB, FileType.ELIB, FileType.READABLEDUMP, FileType.DELIB}; Object format = JOptionPane.showInputDialog(TopLevel.getCurrentJFrame(), "Output file format for all libraries:", "Save All Libraries In Format...", JOptionPane.PLAIN_MESSAGE, null, formats, FileType.DEFAULTLIB); if (format == null) return; // cancel operation FileType outType = (FileType)format; new SaveAllLibrariesInFormatJob(outType); } public static class SaveAllLibrariesInFormatJob extends Job { private FileType outType; public SaveAllLibrariesInFormatJob(FileType outType) { super("Save All Libraries", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.outType = outType; startJob(); } public boolean doIt() { for (Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) { Library lib = it.next(); if (lib.isHidden()) continue; if (!lib.isFromDisk()) continue; if (lib.getLibFile() != null) { // set library file to new format String fullName = lib.getLibFile().getFile(); //if (fullName.endsWith("spiceparts.txt")) continue; // ignore spiceparts library // match ".<word><endline>" fullName = fullName.replaceAll("\\.\\w*?$", "."+outType.getExtensions()[0]); lib.setLibFile(TextUtils.makeURLToFile(fullName)); } lib.setChanged(); } saveAllLibrariesCommand(outType, false, false); return true; } } /** * This method checks database invariants. * @return true if database is valid or user forced saving. */ private static boolean checkInvariants() {// // check database invariants// if (!EDatabase.clientDatabase().checkInvariants())// {// String [] messages = {// "Database invariants are not valid",// "You may use \"Force Quit (and Save)\" to save in a panic directory",// "Do you really want to write libraries into the working directory?"};// Object [] options = {"Continue Writing", "Cancel", "ForceQuit" };// int val = JOptionPane.showOptionDialog(TopLevel.getCurrentJFrame(), messages,// "Invalid database invariants", JOptionPane.DEFAULT_OPTION,// JOptionPane.WARNING_MESSAGE, null, options, options[1]);// if (val == 1) return false;// if (val == 2)// {// forceQuit();// return false;// }// } return true; } /** * This method implements the export cell command for different export types. * It is interactive, and pops up a dialog box. */ public static void exportCommand(FileType type, boolean isNetlist) { // synchronization of PostScript is done first because no window is needed if (type == FileType.POSTSCRIPT) { if (PostScript.syncAll()) return; } WindowFrame wf = WindowFrame.getCurrentWindowFrame(false); WindowContent wnd = (wf != null) ? wf.getContent() : null; if (wnd == null) { System.out.println("No current window"); return; } Cell cell = wnd.getCell(); if (cell == null) { System.out.println("No cell in this window"); return; } VarContext context = (wnd instanceof EditWindow) ? ((EditWindow)wnd).getVarContext() : null; List<PolyBase> override = null; if (type == FileType.POSTSCRIPT) { if (cell.getView() == View.DOC) { System.out.println("Document cells can't be exported as postscript."); JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), "Document cells can't be exported as postscript.\n" + "Try \"Export -> Text Cell Contents\"", "Exporting PS", JOptionPane.ERROR_MESSAGE); return; } if (IOTool.isPrintEncapsulated()) type = FileType.EPS; if (wnd instanceof WaveformWindow) { // waveform windows provide a list of polygons to print WaveformWindow ww = (WaveformWindow)wnd; override = ww.getPolysForPrinting(); } } String [] extensions = type.getExtensions(); String filePath = cell.getName() + "." + extensions[0]; // special case for spice if (type == FileType.SPICE && !Simulation.getSpiceRunChoice().equals(Simulation.spiceRunChoiceDontRun)) { // check if user specified working dir if (Simulation.getSpiceUseRunDir()) filePath = Simulation.getSpiceRunDir() + File.separator + filePath; else filePath = User.getWorkingDirectory() + File.separator + filePath; // check for automatic overwrite if (User.isShowFileSelectionForNetlists() && !Simulation.getSpiceOutputOverwrite()) { String saveDir = User.getWorkingDirectory(); filePath = OpenFile.chooseOutputFile(type, null, filePath); User.setWorkingDirectory(saveDir); if (filePath == null) return; } Output.exportCellCommand(cell, context, filePath, type, override); return; } if (User.isShowFileSelectionForNetlists() || !isNetlist) { filePath = OpenFile.chooseOutputFile(type, null, filePath); if (filePath == null) return; } else { filePath = User.getWorkingDirectory() + File.separator + filePath; } // Special case for PNG format if (type == FileType.PNG) { new ExportImage(cell.toString(), wnd, filePath); return; } Output.exportCellCommand(cell, context, filePath, type, override); } private static class ExportImage extends Job { private String filePath; private WindowContent wnd; public ExportImage(String description, WindowContent wnd, String filePath) { super("Export "+description+" ("+FileType.PNG+")", User.getUserTool(), Job.Type.EXAMINE, null, null, Job.Priority.USER); this.wnd = wnd; this.filePath = filePath; startJob(); } public boolean doIt() throws JobException { PrinterJob pj = PrinterJob.getPrinterJob(); ElectricPrinter ep = getOutputPreferences(wnd, pj); // Export has to be done in same thread as offscreen raster (valid for 3D at least) wnd.writeImage(ep, filePath);// BufferedImage img = wnd.getOffScreenImage(ep);// PNG.writeImage(img, filePath); return true; } } private static PageFormat pageFormat = null; public static void pageSetupCommand() { PrinterJob pj = PrinterJob.getPrinterJob(); if (pageFormat == null) pageFormat = pj.pageDialog(pj.defaultPage()); else pageFormat = pj.pageDialog(pageFormat); } private static ElectricPrinter getOutputPreferences(WindowContent context, PrinterJob pj) { if (pageFormat == null) { pageFormat = pj.defaultPage(); pageFormat.setOrientation(PageFormat.LANDSCAPE); pageFormat = pj.validatePage(pageFormat); } ElectricPrinter ep = new ElectricPrinter(context, pageFormat, pj); pj.setPrintable(ep, pageFormat); return (ep); } /** * This method implements the command to print the current window. */ public static void printCommand() { WindowFrame wf = WindowFrame.getCurrentWindowFrame(); if (wf == null) { System.out.println("No current window to print"); return; } Cell cell = WindowFrame.needCurCell(); if (cell == null) return; PrinterJob pj = PrinterJob.getPrinterJob(); pj.setJobName(wf.getTitle()); PrintService [] printers = new PrintService[0]; try { SecurityManager secman = System.getSecurityManager(); secman.checkPrintJobAccess();// printers = PrinterJob.lookupPrintServices(); printers = PrintServiceLookup.lookupPrintServices(null, null); } catch(Exception e) {} // see if a default printer should be mentioned
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -