📄 windowframe.java
字号:
// make a tabbed list of panes on the left sideBar = new JTabbedPane(); // Only Mac version will align tabs on the left. The text orientation is vertical by default on Mac if (Client.isOSMac()) sideBar.setTabPlacement(JTabbedPane.LEFT); paletteTab = PaletteFrame.newInstance(this); layersTab = new LayerTab(this); loadComponentMenuForTechnology(); sideBar.add("Components", paletteTab.getTechPalette()); sideBar.add("Explorer", scrolledTree); sideBar.add("Layers", layersTab); sideBar.setSelectedIndex(User.getDefaultWindowTab()); sideBar.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { JTabbedPane tp = (JTabbedPane)evt.getSource(); User.setDefaultWindowTab(tp.getSelectedIndex()); } }); // initialize the frame String cellDescription = (cell == null) ? "no cell" : cell.describe(false); Dimension sz = createJFrame(cellDescription, gc); windowOffset += 70; if (windowOffset > 300) windowOffset = 0; // put them together into the split pane js = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); sideBarOnLeft = !User.isSideBarOnRight(); if (sideBarOnLeft) { js.setLeftComponent(sideBar); js.setRightComponent(content.getPanel()); js.setDividerLocation(200); } else { js.setLeftComponent(content.getPanel()); js.setRightComponent(sideBar); js.setDividerLocation(sz.width - 200); } // accumulate a list of current windows synchronized(windowList) { windowList.add(this); } return sz; } /** * Method to create a JFrame that will hold all the Components in this WindowFrame. * @param title the window title. * @param gc the GraphicsConfiguration (which screen the window is on). * @return the size of the frame. */ private Dimension createJFrame(String title, GraphicsConfiguration gc) { Dimension scrnSize = TopLevel.getScreenSize(); Dimension frameSize = new Dimension(scrnSize.width * 4 / 5, scrnSize.height * 6 / 8); if (TopLevel.isMDIMode()) { jif = new JInternalFrame(title, true, true, true, true); jif.setSize(frameSize); jif.setLocation(windowOffset+WINDOW_OFFSET, windowOffset); jif.setAutoscrolls(true); jif.setFrameIcon(TopLevel.getFrameIcon()); } else { jf = new TopLevel("Electric - " + title, new Rectangle(frameSize), this, gc); Dimension preferredSize = User.getDefaultWindowSize(); if (preferredSize != null) frameSize = preferredSize; jf.setSize(frameSize); Point preferredLoc = User.getDefaultWindowPos(); jf.setLocation(windowOffset+WINDOW_OFFSET+preferredLoc.x, windowOffset+preferredLoc.y); } return frameSize; } /** * Set the Technology popup in the component tab and the layers tab to the current technology. */ public void loadComponentMenuForTechnology() { Technology tech = Technology.getCurrent(); if (content.getCell() != null) { tech = content.getCell().getTechnology(); } //Technology tech = Technology.findTechnology(User.getDefaultTechnology()); paletteTab.loadForTechnology(tech, this); layersTab.updateLayersTab(); } /** * Populate the JFrame with the Components */ private void populateJFrame() { if (TopLevel.isMDIMode()) { jif.getContentPane().add(js); internalWindowsEvents = new InternalWindowsEvents(this); jif.addInternalFrameListener(internalWindowsEvents); // add tool bar as listener so it can find out state of cell history in EditWindow// jif.addInternalFrameListener(TopLevel.getCurrentJFrame().getToolBar()); //content.getPanel().addPropertyChangeListener(TopLevel.getTopLevel().getToolBar());// content.getPanel().addPropertyChangeListener(EditWindow.propGoBackEnabled, TopLevel.getCurrentJFrame().getToolBar());// content.getPanel().addPropertyChangeListener(EditWindow.propGoForwardEnabled, TopLevel.getCurrentJFrame().getToolBar());// frame.jif.moveToFront(); TopLevel.addToDesktop(jif); } else { jf.getContentPane().add(js); windowsEvents = new WindowsEvents(this); jf.addWindowListener(windowsEvents); jf.addWindowFocusListener(windowsEvents); // add tool bar as listener so it can find out state of cell history in EditWindow// content.getPanel().addPropertyChangeListener(EditWindow.propGoBackEnabled, ((TopLevel)jf).getToolBar());// content.getPanel().addPropertyChangeListener(EditWindow.propGoForwardEnabled, ((TopLevel)jf).getToolBar()); /*if (!Job.BATCHMODE)*/ jf.setVisible(true); } } public Component getComponent() { if (TopLevel.isMDIMode()) return jif; return jf; } /** * Method to return the usage clock of this WindowFrame. * Each activation of the WindowFrame increments the value, so the WindowFrame * with the highest value is the one most recently activated. * @return the usage clock of this WindowFrame. */ public int getUsageClock() { return usageClock; } /** * Depopulate the JFrame. Currently this is only used in SDI mode when * moving a WindowFrame from one display to another. A new JFrame on the * new display must be created and populated with the WindowFrame Components. * To do so, those components must first be removed from the old frame. */ private void depopulateJFrame() { assert SwingUtilities.isEventDispatchThread(); if (TopLevel.isMDIMode()) { jif.getContentPane().remove(js); jif.removeInternalFrameListener(internalWindowsEvents);// jif.removeInternalFrameListener(TopLevel.getCurrentJFrame().getToolBar()); // TopLevel.removeFromDesktop(jif);// content.getPanel().removePropertyChangeListener(TopLevel.getCurrentJFrame().getToolBar());// content.getPanel().removePropertyChangeListener(TopLevel.getCurrentJFrame().getToolBar()); TopLevel.removeFromDesktop(jif); } else { jf.getContentPane().remove(js); jf.removeWindowListener(windowsEvents); jf.removeWindowFocusListener(windowsEvents);// content.getPanel().removePropertyChangeListener(EditWindow.propGoBackEnabled, ((TopLevel)jf).getToolBar());// content.getPanel().removePropertyChangeListener(EditWindow.propGoForwardEnabled, ((TopLevel)jf).getToolBar()); } } //******************************** WINDOW CONTROL ******************************** /** * Method to show a cell in the right-part of this WindowFrame. * Handles both circuit cells and text cells. * @param cell the Cell to display. */ public void setCellWindow(Cell cell, CellHistory history) { if (cell != null && cell.getView().isTextView()) { // want a TextWindow here if (!(getContent() instanceof TextWindow)) { getContent().finished(); content = new TextWindow(cell, this); int i = js.getDividerLocation(); if (sideBarOnLeft) js.setRightComponent(content.getPanel()); else js.setLeftComponent(content.getPanel()); js.setDividerLocation(i); content.fillScreen(); if (history == null) addToHistory(cell, VarContext.globalContext, null); return; } } else { // want an EditWindow here if (!(getContent() instanceof EditWindow)) { getContent().finished(); Component c = js.getLeftComponent(); if (sideBarOnLeft) c = js.getRightComponent(); Dimension sz = c.getSize(); content = EditWindow.CreateElectricDoc(cell, this, sz); int i = js.getDividerLocation(); if (sideBarOnLeft) js.setRightComponent(content.getPanel()); else js.setLeftComponent(content.getPanel()); js.setDividerLocation(i); content.fillScreen(); if (history == null) addToHistory(cell, VarContext.globalContext, null); return; } } // proper window type already there: switch cells DisplayAttributes da = null; VarContext upperContext = VarContext.globalContext; if (history != null) { da = history.da; upperContext = history.context; } content.setCell(cell, upperContext, da); currentCellChanged(); // Adding into WindowMenu WindowMenu.setDynamicMenus(); if (history == null) addToHistory(cell, VarContext.globalContext, null); } public void moveEditWindow(GraphicsConfiguration gc) { if (TopLevel.isMDIMode()) return; // only valid in SDI mode jf.setVisible(false); // hide old Frame //jf.getFocusOwner().setFocusable(false); //System.out.println("Set unfocasable: "+jf.getFocusOwner()); depopulateJFrame(); // remove all components from old Frame TopLevel oldFrame = jf; oldFrame.finished(); // clear and garbage collect old Frame Cell cell = content.getCell(); // get current cell String cellDescription = (cell == null) ? "no cell" : cell.describe(false); // new title createJFrame(cellDescription, gc); // create new Frame populateJFrame(); // populate new Frame fireCellHistoryStatus(); // update tool bar history buttons } //******************************** EXPLORER PART ******************************** /** * Method to force the explorer tree to show the current library or signals list. * @param openLib true to open the current library, false to open the signals list. * @param cell cell to select in ExplorerTree */ public static void wantToOpenCurrentLibrary(boolean openLib, Cell cell) { for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); wf.explorerTab.openLibraryInExplorerTree(Library.getCurrent(), cell, openLib); } } /** * Method to request that the library tree be reloaded. */ public static void wantToRedoLibraryTree() { for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); wf.explorerTab.redoContentTrees(wf.content.loadExplorerTrees()); } } public void wantToRedoSignalTree() { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(new Runnable() { public void run() { wantToRedoSignalTree(); } }); return; } explorerTab.redoContentTrees(content.loadExplorerTrees()); } public static void setSideBarLocation(boolean onLeft) { WindowFrame wf = getCurrentWindowFrame(); if (wf.sideBarOnLeft == onLeft) return; wf.sideBarOnLeft = onLeft; wf.js.setLeftComponent(null); wf.js.setRightComponent(null); Dimension sz = wf.js.getSize(); int loc = sz.width - wf.js.getDividerLocation(); wf.js.setDividerLocation(loc); if (onLeft) { wf.js.setLeftComponent(wf.sideBar); wf.js.setRightComponent(wf.content.getPanel()); } else { wf.js.setLeftComponent(wf.content.getPanel()); wf.js.setRightComponent(wf.sideBar); } } //******************************** INTERFACE ******************************** /** * Method to get the content of this window. * The content is the object in the right side (EditWindow, WaveformWindow, etc.) * @return the content of this window. */ public WindowContent getContent() { return content; } /** * Method to get the current WindowFrame. If there is no current * WindowFrame, then it will create a new EditWindow window frame. * @return the current WindowFrame. */ public static WindowFrame getCurrentWindowFrame() { return getCurrentWindowFrame(true); } /** * Method to get the current WindowFrame. If 'makeNewFrame' is true, * then this will make a new EditWindow window frame if there is no * current frame. If 'makeNewFrame' is false, this will return null * if there is no current WindowFrame. * @param makeNewFrame whether or not to make a new WindowFrame if no current frame * @return the current WindowFrame. May return null if 'makeNewFrame' is false. */ public static WindowFrame getCurrentWindowFrame(boolean makeNewFrame) { synchronized(windowList) { if ((curWindowFrame == null) && makeNewFrame) { for (WindowFrame wf: windowList) { // get last in list curWindowFrame = wf; } if (curWindowFrame == null) curWindowFrame = createEditWindow(null); } return curWindowFrame; } } /** * Method to set the current listener that responds to clicks in any window. * There is a single listener in effect everywhere, usually controlled by the toolbar. * @param listener the new lister to be in effect. */ public static void setListener(EventListener listener) { curMouseListener = (MouseListener)listener; curMouseMotionListener = (MouseMotionListener)listener; curMouseWheelListener = (MouseWheelListener)listener; curKeyListener = (KeyListener)listener; } /** * Method to get the current listener that responds to clicks in any window. * There is a single listener in effect everywhere, usually controlled by the toolbar.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -