📄 filemenu.java
字号:
String pName = IOTool.getPrinterName(); PrintService printerToUse = null; for(PrintService printer : printers) { if (pName.equals(printer.getName())) { printerToUse = printer; break; } } if (printerToUse != null) { try { pj.setPrintService(printerToUse); } catch (PrinterException e) { System.out.println("Printing error " + e); } } PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); if (pj.printDialog(aset)) { // disable double-buffering so prints look better JPanel overall = wf.getContent().getPanel(); RepaintManager currentManager = RepaintManager.currentManager(overall); currentManager.setDoubleBufferingEnabled(false); ElectricPrinter ep = getOutputPreferences(wf.getContent(), pj); Dimension oldSize = overall.getSize(); ep.setOldSize(oldSize); // determine area to print EditWindow_ wnd = null; if (wf.getContent() instanceof EditWindow) wnd = (EditWindow_)wf.getContent(); Rectangle2D printBounds = Output.getAreaToPrint(cell, false, wnd); ep.setRenderArea(printBounds); // initialize for content-specific printing if (!wf.getContent().initializePrinting(ep, pageFormat)) { String message = "Problems initializing printers. Check printer setup."; System.out.println(message); JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), message, "Printing Cell", JOptionPane.ERROR_MESSAGE); return; } printerToUse = pj.getPrintService(); if (printerToUse != null) IOTool.setPrinterName(printerToUse.getName()); SwingUtilities.invokeLater(new PrintJobAWT(wf, pj, oldSize, aset)); } } private static class PrintJobAWT implements Runnable { private WindowFrame wf; private PrinterJob pj; private Dimension oldSize; private PrintRequestAttributeSet aset; PrintJobAWT(WindowFrame wf, PrinterJob pj, Dimension oldSize, PrintRequestAttributeSet aset) { this.wf = wf; this.pj = pj; this.oldSize = oldSize; this.aset = aset; } public void run() { try { pj.print(aset); } catch (PrinterException pe) { System.out.println("Print aborted."); } JPanel overall = wf.getContent().getPanel(); RepaintManager currentManager = RepaintManager.currentManager(overall); currentManager.setDoubleBufferingEnabled(true); if (oldSize != null) { overall.setSize(oldSize); overall.validate(); } } } /** * This method implements the command to quit Electric. */ public static boolean quitCommand() { Collection<RenameAndSaveLibraryTask> saveTasks = preventLoss(null, 0); if (saveTasks == null) return true; try { new QuitJob(saveTasks); } catch (java.lang.NoClassDefFoundError e) { // Ignoring this one return true; } catch (Exception e) { // Don't quit in this case. return false; } return true; } /** * Class to clear the date information on a Cell. * Used by regressions to reset date information so that files match. */ public static class ClearCellDate extends Job { private String cellName; private Cell cell; public ClearCellDate(String cellName) { super("Clear Cell Dates", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cellName = cellName; startJob(); } public ClearCellDate(Cell cell) { super("Clear Cell Dates", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; startJob(); } public boolean doIt() throws JobException { if (cell == null && cellName != null) cell = (Cell)Cell.findNodeProto(cellName); if (cell != null) { cell.lowLevelSetRevisionDate(new Date(0)); cell.lowLevelSetCreationDate(new Date(0)); } return true; } } /** * Class to quit Electric in a Job. * The quit function is done in a Job so that it can force all other jobs to finish. */ public static class QuitJob extends Job { private Collection<RenameAndSaveLibraryTask> saveTasks; public QuitJob(Collection<RenameAndSaveLibraryTask> saveTasks) { super("Quitting", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.saveTasks = saveTasks; startJob(); } public boolean doIt() throws JobException { for (RenameAndSaveLibraryTask saveTask: saveTasks) saveTask.renameAndSave(); return true; } public void terminateOK() { try { Library.saveExpandStatus(); } catch (BackingStoreException e) { int response = JOptionPane.showConfirmDialog(TopLevel.getCurrentJFrame(), "Cannot save cell expand status. Do you still want to quit?", "Cell Status Error", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (response != JOptionPane.YES_OPTION) { return; } } // save changes to layer visibility Layer.preserveVisibility(); // save changes to waveform window signals WaveformWindow.preserveSignalOrder(); ActivityLogger.finished(); System.exit(0); } } /** * Method to check if one or more libraries are saved. * If the quit/close/replace operation may be continued, * returns libraries to be saved before. * This Collection can be empty. * If the operation should be aborted, returns null * @param desiredLib the library to check for being saved. * If desiredLib is null, all libraries are checked. * @param action the type of action that will occur: * 0: quit; * 1: close a library; * 2: replace a library. * @return libraries to be saved or null */ public static Collection<RenameAndSaveLibraryTask> preventLoss(Library desiredLib, int action) { ArrayList<RenameAndSaveLibraryTask> librariesToSave = new ArrayList<RenameAndSaveLibraryTask>(); boolean checkedInvariants = false; for(Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) { Library lib = it.next(); if (desiredLib != null && desiredLib != lib) continue; if (lib.isHidden()) continue; if (!lib.isChanged()) continue; // Abort if database invariants are not valid if (!checkedInvariants) { if (!checkInvariants()) return null; checkedInvariants = true; } // warn about this library String theAction = "Save before quitting?"; if (action == 1) theAction = "Save before closing?"; else if (action == 2) theAction = "Save before replacing?"; String [] options = {"Yes", "No", "Cancel", "No to All"}; int ret = showFileMenuOptionDialog(TopLevel.getCurrentJFrame(), "Library '" + lib.getName() + "' has changed. " + theAction, "Save Library?", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0], null); if (ret == 0) { // save the library RenameAndSaveLibraryTask saveTask = saveLibraryRequest(lib, FileType.DEFAULTLIB, false, true, false); if (saveTask != null) librariesToSave.add(saveTask); continue; } if (ret == 1) continue; if (ret == 2 || ret == -1) return null; if (ret == 3) break; } return librariesToSave; } /** * Based on JOptionPane but allows ToolTip text * @param parentComponent * @param message * @param title * @param optionType * @param messageType * @param icon * @param options * @param initialValue * @return the return value of the JOptionPane choice. Returns -1 if aborted * @throws HeadlessException */ public static int showFileMenuOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue, String toolTipMessage) throws HeadlessException { JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, options, initialValue); pane.setInitialValue(initialValue); pane.setComponentOrientation(((parentComponent == null) ? JOptionPane.getRootFrame() : parentComponent).getComponentOrientation()); pane.setMessageType(messageType); JDialog dialog = pane.createDialog(parentComponent, title); pane.selectInitialValue(); pane.setToolTipText(toolTipMessage); dialog.setVisible(true); dialog.dispose(); Object selectedValue = pane.getValue(); if(selectedValue == null) return JOptionPane.CLOSED_OPTION; if(options == null) { if(selectedValue instanceof Integer) return (((Integer)selectedValue).intValue()); // using autoboxing return JOptionPane.CLOSED_OPTION; } for(int counter = 0, maxCounter = options.length; counter < maxCounter; counter++) { if(options[counter].equals(selectedValue)) return counter; } return JOptionPane.CLOSED_OPTION; } static class CellMouseMotionAdapter extends MouseMotionAdapter { JOptionPane pane; CellMouseMotionAdapter(JOptionPane p) { pane = p;} public void mouseMoved(MouseEvent e) { System.out.println(" Point " + pane.getToolTipLocation(e));} } /** * Unsafe way to force Electric to quit. If this method returns, * it obviously did not kill electric (because of user input or some other reason). */ public static void forceQuit() { // check if libraries need to be saved boolean dirty = false; for(Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) { Library lib = it.next(); if (lib.isHidden()) continue; if (!lib.isChanged()) continue; dirty = true; break; } if (dirty) { String [] options = { "Force Save and Quit", "Cancel", "Quit without Saving"}; int i = JOptionPane.showOptionDialog(TopLevel.getCurrentJFrame(), new String [] {"Warning! Libraries Changed! Saving changes now may create bad libraries!"}, "Force Quit", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); if (i == 0) { // force save if (!forceSave(false)) { JOptionPane.showMessageDialog(TopLevel.getC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -