📄 userinterfacemain.java
字号:
Geometric geom1 = null, geom2 = null; for(Iterator<ErrorHighlight> it = log.getHighlights(); it.hasNext(); ) { ErrorHighlight eh = it.next(); if (geom1 == null) geom1 = (Geometric)eh.getObject(database); else if (geom2 == null) geom2 = (Geometric)eh.getObject(database); } // return geometry if requested if (geom1 != null) gPair[0] = geom1; if (geom2 != null) gPair[1] = geom2; } // show the error if (showhigh) { Highlighter highlighter = null; EditWindow wnd = null; // first show the geometry associated with this error for(Iterator<ErrorHighlight> it = log.getHighlights(); it.hasNext(); ) { ErrorHighlight eh = it.next(); Cell cell = eh.getCell(database); // validate the cell (it may have been deleted) if (cell != null) { if (!cell.isLinked()) { return "(cell deleted): " + log.getMessageString(); } // make sure it is shown wnd = EditWindow.showEditWindowForCell(cell, eh.getVarContext()); if (highlighter == null) { highlighter = wnd.getHighlighter(); highlighter.clear(); } } if (highlighter == null) continue; eh.addToHighlighter(highlighter, database); } // Something found to highlight if (highlighter != null) { highlighter.ensureHighlightingSeen(); highlighter.finished(); // make sure the selection is visible Rectangle2D hBounds = highlighter.getHighlightedArea(wnd); Rectangle2D shown = wnd.getDisplayedBounds(); if (!shown.intersects(hBounds)) { wnd.focusOnHighlighted(); } } else { Cell logCell = log.getCell(); // Checking also that the cell hasn't been removed yet if (logCell != null && logCell.isLinked()) { // in case of errors or warnings with only cell information // This would bring the EditWindow to the front. EditWindow.showEditWindowForCell(logCell, null); } } } // return the error message return log.getMessageString(); } /** * Method to show an error message. * @param message the error message to show. * @param title the title of a dialog with the error message. */ public void showErrorMessage(final Object message, final String title) { if (SwingUtilities.isEventDispatchThread()) JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), message, title, JOptionPane.ERROR_MESSAGE); else { SwingUtilities.invokeLater( new Runnable() { public void run() { showErrorMessage(message, title); } }); } } /** * Method to show an informational message. * @param message the message to show. * @param title the title of a dialog with the message. */ public void showInformationMessage(final Object message, final String title) { if (SwingUtilities.isEventDispatchThread()) JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), message, title, JOptionPane.INFORMATION_MESSAGE); else { SwingUtilities.invokeLater( new Runnable() { public void run() { showInformationMessage(message, title); } }); } } /** * Method to show a message and ask for confirmation. * @param message the message to show. * @return true if "yes" was selected, false if "no" was selected. */ public boolean confirmMessage(Object message) { int response = JOptionPane.showConfirmDialog(TopLevel.getCurrentJFrame(), message); return response == JOptionPane.YES_OPTION; } /** * Method to ask for a choice among possibilities. * @param message the message to show. * @param title the title of the dialog with the query. * @param choices an array of choices to present, each in a button. * @param defaultChoice the default choice. * @return the index into the choices array that was selected. */ public int askForChoice(String message, String title, String [] choices, String defaultChoice) { // make sure the message is not too long and add \n if necessary String msg = message; int size = msg.length(); int pos = 0; int lineNumber = 0; String newMsg = ""; while (pos < size && lineNumber < 10) { int endIndex = pos+256; if (endIndex > size) endIndex = size; newMsg += msg.substring(pos, endIndex); newMsg += "\n"; pos +=256; lineNumber++; } if (pos < size) // too many lines { newMsg += "........\n"; // adding the end of the message. If end of message is close then add the remainder otherwise // print the last 256 characters. int index = (size - pos > 256) ? (size - 256) : (pos); newMsg += msg.substring(index, size); } msg= newMsg; message = msg; int val = JOptionPane.showOptionDialog(TopLevel.getCurrentJFrame(), message, title, JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, choices, defaultChoice); return val; } /** * Method to ask for a line of text. * @param message the prompt message. * @param title the title of a dialog with the message. * @param def the default response. * @return the string (null if cancelled). */ public String askForInput(Object message, String title, String def) { Object ret = JOptionPane.showInputDialog(TopLevel.getCurrentJFrame(), message, title, JOptionPane.QUESTION_MESSAGE, null, null, def); if (ret == null) return null; return ret.toString(); } /** For Pref */ /** * Method to import the preferences from an XML file. * Prompts the user and reads the file. */ public void importPrefs() { // prompt for the XML file String fileName = OpenFile.chooseInputFile(FileType.PREFS, "Saved Preferences"); if (fileName == null) return; Pref.importPrefs(fileName, EDatabase.clientDatabase().getTechPool()); } /** * Method to export the preferences to an XML file. * Prompts the user and writes the file. */ public void exportPrefs() { // prompt for the XML file String fileName = OpenFile.chooseOutputFile(FileType.PREFS, "Saved Preferences", "electricPrefs.xml"); if (fileName == null) return; Pref.exportPrefs(fileName); } // ExtendedUserInterface public void restoreSavedBindings(boolean initialCall) { TopLevel top = TopLevel.getCurrentJFrame(); top.getEMenuBar().restoreSavedBindings(false); //trying to cache again } /** * Save current state of highlights and return its ID. */ public int saveHighlights() { EditWindow_ wnd = getCurrentEditWindow_(); if (wnd == null) return -1; SavedHighlights sh = new SavedHighlights(lastId++, wnd); while (savedHighlights.size() >= User.getMaxUndoHistory() && !savedHighlights.isEmpty()) savedHighlights.remove(0); savedHighlights.add(sh); return sh.id; } /** * Restore state of highlights by its ID. */ public void restoreHighlights(int highlightsId) { for (SavedHighlights sh: savedHighlights) { if (sh.id == highlightsId) { sh.restore(); break; } } } /** * Show status of undo/redo buttons * @param newUndoEnabled new status of undo button. * @param newRedoEnabled new status of redo button. */ public void showUndoRedoStatus(boolean newUndoEnabled, boolean newRedoEnabled) { PropertyChangeEvent e = null; if (undoEnabled != newUndoEnabled) { // PropertyChangeEvent e = new PropertyChangeEvent(this, propUndoEnabled, undoEnabled, newUndoEnabled); undoEnabled = newUndoEnabled; SwingUtilities.invokeLater(new PropertyChangeRun(e)); } if (redoEnabled != newRedoEnabled) { // PropertyChangeEvent e = new PropertyChangeEvent(this, propRedoEnabled, redoEnabled, newRedoEnabled); redoEnabled = newRedoEnabled; SwingUtilities.invokeLater(new PropertyChangeRun(e)); } } /** * Show new database snapshot. * @param newSnapshot new snapshot. */ public void showSnapshot(Snapshot newSnapshot, boolean undoRedo) { SwingUtilities.invokeLater(new DatabaseChangeRun(newSnapshot, undoRedo)); } public void beep() { Toolkit.getDefaultToolkit().beep(); } /** * Method to tell whether undo can be done. * This is used by the tool bar to determine whether the undo button should be available. * @return true if undo can be done. */ public static boolean getUndoEnabled() { return undoEnabled; } /** * Method to tell whether redo can be done. * This is used by the tool bar to determine whether the undo button should be available. * @return true if redo can be done. */ public static boolean getRedoEnabled() { return redoEnabled; }// /** Add a property change listener. This generates Undo and Redo enabled property changes */// public static synchronized void addUndoRedoListener(PropertyChangeListener l)// {// assert SwingUtilities.isEventDispatchThread();// undoRedoListenerList.add(PropertyChangeListener.class, l);// }//// /** Remove a property change listener. */// public static synchronized void removeUndoRedoListener(PropertyChangeListener l)// {// assert SwingUtilities.isEventDispatchThread();// undoRedoListenerList.remove(PropertyChangeListener.class, l);// } private static void firePropertyChange(PropertyChangeEvent e) { assert SwingUtilities.isEventDispatchThread(); ToolBar.updateUndoRedoButtons(getUndoEnabled(), getRedoEnabled()); // Check all current WindowFrames and determine if displayed cells are still valid // close windows that reference this cell for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); WindowContent content = wf.getContent(); if (content == null) continue; Cell c = content.getCell(); if (c != null && !c.isLinked()) // got removed in undo { wf.setCellWindow(null, null);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -