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

📄 toolbar.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
						high.setPoint(-1);						wnd.repaint();					}				}			}		}	}	private static final CursorModeButton clickZoomWireCommand = new CursorModeButton("Click/Zoom/Wire", 'S', "ButtonClickZoomWire",		"Edit:Modes:Edit", CursorMode.CLICKZOOMWIRE);	private static final CursorModeButton panCommand = new CursorModeButton("Toggle Pan", 'P', "ButtonPan",		"Edit:Modes:Edit", CursorMode.PAN);	private static final CursorModeButton zoomCommand = new CursorModeButton("Toggle Zoom", 'Z', "ButtonZoom",		"Edit:Modes:Edit", CursorMode.ZOOM);	private static final CursorModeButton outlineCommand = new CursorModeButton("Toggle Outline Edit", 'Y', "ButtonOutline",		"Edit:Modes:Edit", CursorMode.OUTLINE);	private static final CursorModeButton measureCommand = new CursorModeButton("Toggle Measure Distance", 'M', "ButtonMeasure",		"Edit:Modes:Edit", CursorMode.MEASURE);	private static class CursorModeButton extends EToolBarRadioButton	{		private final CursorMode cm;		CursorModeButton(String text, char acceleratorChar, String iconName, String menuName, CursorMode cm)		{			super(text, KeyStroke.getKeyStroke(acceleratorChar, 0), iconName, menuName);			this.cm = cm;		}		@Override public boolean isSelected() { return getCursorMode() == cm; }		@Override public void run() { setCursorMode(cm); }	}	// --------------------------- ArrowDistance staff ---------------------------------------------------------	/**	 * Method to signal ToolBar that gridAlignment changed	 */	public static void setGridAligment() { updateToolBarButtons(); }	private static EMenuItem gridDistance1Command = new EMenuItem("Grid Alignment 1 (largest)") { public void run() {		changeGridSize(0); }};	private static EMenuItem gridDistance2Command = new EMenuItem("Grid Alignment 2") { public void run() {		changeGridSize(1); }};	private static EMenuItem gridDistance3Command = new EMenuItem("Grid Alignment 3") { public void run() {		changeGridSize(2); }};	private static EMenuItem gridDistance4Command = new EMenuItem("Grid Alignment 4") { public void run() {		changeGridSize(3); }};	private static EMenuItem gridDistance5Command = new EMenuItem("Grid Alignment 5 (smallest)") { public void run() {		changeGridSize(4); }};	private JButton currentGridAmount = new JButton();	private boolean currentGridAmountInited = false;	private static final EToolBarButton gridLarger = new EToolBarButton("Make Grid Larger",		KeyStroke.getKeyStroke('F', 0), "ButtonGridCoarser", "Edit:Modes:Movement")    {        public void run() { changeGridSize(true); }        public boolean isEnabled()        {            int index = User.getAlignmentToGridIndex();            return (index != 0); // most right        }    };	private static final EToolBarButton gridSmaller = new EToolBarButton("Make Grid Smaller",		KeyStroke.getKeyStroke('H', 0), "ButtonGridFiner", "Edit:Modes:Movement")    {        public void run() { changeGridSize(false); }        public boolean isEnabled()        {        	Dimension2D[] vals = User.getAlignmentToGridVector();            int index = User.getAlignmentToGridIndex();            return (index != vals.length - 1); // most right        }    };	private static void changeGridSize(int size)	{		Dimension2D[] vals = User.getAlignmentToGridVector();		User.setAlignmentToGridVector(vals, size);		rewriteGridDistance();		updateToolBarButtons();	}    private static void changeGridSize(boolean larger)	{    	Dimension2D[] vals = User.getAlignmentToGridVector();        int i = User.getAlignmentToGridIndex();        if (larger)        {            if (i > 0)            {                User.setAlignmentToGridVector(vals, i-1);                rewriteGridDistance();            }        } else        {            if (i < vals.length-1)            {                User.setAlignmentToGridVector(vals, i+1);                rewriteGridDistance();            }        }	}	// --------------------------- SelectMode staff ---------------------------------------------------------	private static SelectMode curSelectMode = SelectMode.OBJECTS;	/**	 * SelectMode is a typesafe enum class that describes the current selection modes (objects or area).	 */	public static enum SelectMode	{		/** Describes Selection mode (click and drag). */		OBJECTS,		/** Describes Selection mode (click and drag). */		AREA;	}	/**	 * Method to tell what selection mode is in effect.	 * @return the current selection mode (objects or area).	 */	public static SelectMode getSelectMode() { return curSelectMode; }	private static void setSelectMode(SelectMode selectMode) { curSelectMode = selectMode; }	private static final SelectModeButton selectObjectsCommand = new SelectModeButton("Select Objects", "ButtonObjects",		"Edit:Modes:Select", SelectMode.OBJECTS);	private static final SelectModeButton selectAreaCommand = new SelectModeButton("Select Area", "ButtonArea",		"Edit:Modes:Select", SelectMode.AREA);	public static class SelectModeButton extends EToolBarRadioButton	{		private final SelectMode sm;		SelectModeButton(String text, String iconName, String menuName, SelectMode sm)		{			super(text, null, iconName, menuName);			this.sm = sm;		}		@Override public boolean isSelected() { return getSelectMode() == sm; }		@Override public void run() { setSelectMode(sm); }	}	// --------------------------- SelectSpecial staff ---------------------------------------------------------	private static boolean selectSpecial = false;	/**	 * Returns state of "select special" button	 * @return true if select special button selected, false otherwise	 */	public static boolean isSelectSpecial() { return selectSpecial; }	/**	 * Method called to toggle the state of the "select special"	 * button.	 */	private static void setSelectSpecial(boolean b) { selectSpecial = b; }	private static final ImageIcon selectSpecialIconOn = Resources.getResource(ToolBar.class, "ButtonSelectSpecialOn.gif");	private static final ImageIcon selectSpecialIconOff = Resources.getResource(ToolBar.class, "ButtonSelectSpecialOff.gif");	private static EToolBarButton toggleSelectSpecialCommand = new EToolBarButton("Toggle Special Select", null, "ButtonSelectSpecialOff",		"Edit:Modes:Select")	{		public boolean isSelected() { return isSelectSpecial(); }		@Override protected JMenuItem createMenuItem() { return new JCheckBoxMenuItem(); }		@Override AbstractButton createToolBarButton() { return new JToggleButton(); }		@Override public void run() { setSelectSpecial(!isSelectSpecial()); }		@Override void updateToolBarButton(AbstractButton item)		{			super.updateToolBarButton(item);			item.setSelected(isSelected());			item.setIcon(isSelected() ? selectSpecialIconOn : selectSpecialIconOff);		}	};	// --------------------------- Modes submenu of Edit menu ---------------------------------------------------------	// mnemonic keys available: ABCD FGHIJKL NOPQR TUVWXYZ	public static final EMenu modesSubMenu = new EMenu("M_odes",		new EMenu("_Edit",			clickZoomWireCommand,			panCommand,			zoomCommand,			outlineCommand,			measureCommand),		new EMenu("_Movement",			gridLarger,			gridDistance1Command,			gridDistance2Command,			gridDistance3Command,			gridDistance4Command,			gridDistance5Command,			gridSmaller),		new EMenu("_Select",			selectObjectsCommand,			selectAreaCommand,			toggleSelectSpecialCommand)	);	// --------------------------- Misc commands ---------------------------------------------------------	public static final EToolBarButton preferencesCommand = new EToolBarButton("P_references...", null, "ButtonPreferences", "File")	{		public void run() { PreferencesFrame.preferencesCommand(); }	};	public static final EToolBarButton expandOneLevelCommand = new EToolBarButton("_One Level Down", null, "ButtonExpand",		"Cell:Expand Cell Instances")	{		public void run() { CircuitChanges.DoExpandCommands(false, 1); }	};	public static final EToolBarButton unexpandOneLevelCommand = new EToolBarButton("_One Level Up", null, "ButtonUnexpand",		"Cell:Unexpand Cell Instances")	{		public void run() { CircuitChanges.DoExpandCommands(true, 1); }	};	// --------------------------- Undo/Redo staff ---------------------------------------------------------	public static final EToolBarButton undoCommand = new EToolBarButton("_Undo", 'Z', "ButtonUndo", "Edit")	{		public void run()		{			WindowFrame wf = WindowFrame.getCurrentWindowFrame();			if (wf != null && wf.getContent() instanceof TextWindow)			{				// handle undo in text windows specially				TextWindow tw = (TextWindow)wf.getContent();				tw.undo();			} else			{				// if there is edit-in-place going on, undo that				EditWindow wnd = EditWindow.getCurrent();				if (wnd != null)				{					GetInfoText.EditInPlaceListener eip = wnd.getInPlaceTextObject();					if (eip != null)					{						eip.undo();						return;					}				}				// do database undo				Undo.undo();			}		}		public boolean isEnabled() { return UserInterfaceMain.getUndoEnabled(); }	};	public static final EToolBarButton redoCommand = new EToolBarButton("Re_do", 'Y', "ButtonRedo", "Edit")	{		public void run()		{			WindowFrame wf = WindowFrame.getCurrentWindowFrame();			if (wf != null && wf.getContent() instanceof TextWindow)			{				// handle redo in text windows specially				TextWindow tw = (TextWindow)wf.getContent();				tw.redo();			} else			{				// if there is edit-in-place going on, redo that				EditWindow wnd = EditWindow.getCurrent();				if (wnd != null)				{					GetInfoText.EditInPlaceListener eip = wnd.getInPlaceTextObject();					if (eip != null)					{						eip.redo();						return;					}				}				// do database redo				Undo.redo();			}		}		public boolean isEnabled() { return UserInterfaceMain.getRedoEnabled(); }	};	public static void updateUndoRedoButtons(boolean undo, boolean redo)	{		updateToolBarButtons();	}	// --------------------------- CellHistory stuff ---------------------------------------------------------	private static final EToolBarButton goBackButtonStatic = new EToolBarButton("Go Back a Cell", null, "ButtonGoBack",		"Cell:Cell Viewing History") { public void run() {} };	private static final EToolBarButton goForwardButtonStatic = new EToolBarButton("Go Forward a Cell", null, "ButtonGoForward",		"Cell:Cell Viewing History") { public void run() {} };	/** Go back button */	private CellHistoryButton goBackButton = new CellHistoryButton("Go Back a Cell", "ButtonGoBack",		"Cell:Cell Viewing History")	{		public void run()		{			WindowFrame wf = WindowFrame.getCurrentWindowFrame();			if (wf != null) wf.cellHistoryGoBack();		}	};	/** Go forward button */	private CellHistoryButton goForwardButton = new CellHistoryButton("Go Forward a Cell", "ButtonGoForward",		"Cell:Cell Viewing History")	{		public void run()		{			WindowFrame wf = WindowFrame.getCurrentWindowFrame();			if (wf != null) wf.cellHistoryGoForward();		}	};	private static abstract class CellHistoryButton extends EToolBarButton implements MouseListener	{		private boolean enabled;		CellHistoryButton(String text, String iconName, String menuName) { super(text, null, iconName, menuName); }		@Override public AbstractButton genToolBarButton()		{			AbstractButton b = super.genToolBarButton();			b.addMouseListener(this);			return b;		}		public boolean isEnabled() { return enabled; }		void setEnabled(boolean b) { enabled = b; }		public void mouseClicked(MouseEvent e) {}		public void mouseEntered(MouseEvent e) {}		public void mouseExited(MouseEvent e) {}		public void mousePressed(MouseEvent e) {}		public void mouseReleased(MouseEvent e)		{			AbstractButton b = (AbstractButton) e.getSource();			if(ClickZoomWireListener.isRightMouse(e) && b.contains(e.getX(), e.getY()))				showHistoryPopup(e);		}	}	/**	 * Update CellHistory buttons on this ToolBar	 * @param backEnabled true to enable goBackButton.	 * @param forwardEnabled true toenable goForwardButton.	 */	public void updateCellHistoryStatus(boolean backEnabled, boolean forwardEnabled)	{		goBackButton.setEnabled(backEnabled);		goForwardButton.setEnabled(forwardEnabled);		updateToolBarButtons();	}	private static void showHistoryPopup(MouseEvent e)	{		WindowFrame wf = WindowFrame.getCurrentWindowFrame();		if (wf == null) return;		List<WindowFrame.CellHistory> historyList = wf.getCellHistoryList();		int location = wf.getCellHistoryLocation();		JPopupMenu popup = new JPopupMenu();		Map<Cell,Cell> listed = new HashMap<Cell,Cell>();		for (int i=historyList.size()-1; i > -1; i--)		{			WindowFrame.CellHistory entry = historyList.get(i);			Cell cell = entry.getCell();			// skip if already shown such a cell			if (cell == null) continue;			if (listed.get(cell) != null) continue;			listed.put(cell, cell);			boolean shown = (i == location);			JMenuItem m = new JMenuItem(cell.noLibDescribe() + (shown? "  (shown)" : ""));			m.addActionListener(new HistoryPopupAction(wf, i));			popup.add(m);		}		Component invoker = e.getComponent();		if (invoker != null)		{			popup.setInvoker(invoker);			Point2D loc = invoker.getLocationOnScreen();			popup.setLocation((int)loc.getX() + invoker.getWidth()/2, (int)loc.getY() + invoker.getHeight()/2);		}		popup.setVisible(true);	}	private static class HistoryPopupAction implements ActionListener	{		private final WindowFrame wf;		private final int historyLocation;		private HistoryPopupAction(WindowFrame wf, int loc)		{			this.wf = wf;			this.historyLocation = loc;		}		public void actionPerformed(ActionEvent e) { wf.setCellByHistory(historyLocation); }	}	// ----------------------------------------------------------------------------	/**	 * Update associated ToolBarButtons on all toolbars and updatable menu items on all menubars	 */	public static void updateToolBarButtons()	{		for (ToolBar toolBar: TopLevel.getToolBars())		{			for (Component c: toolBar.getComponents())			{				if (c == toolBar.currentGridAmount)				{					rewriteGridDistance();					continue;				}				if (!(c instanceof AbstractButton)) continue;				AbstractButton b = (AbstractButton)c;				for (ActionListener a: b.getActionListeners())				{					if (a instanceof EToolBarButton)					{						EToolBarButton tbb = (EToolBarButton)a;						// special case for buttons that are different in each toolbar						if (tbb == goBackButtonStatic) tbb = toolBar.goBackButton;						if (tbb == goForwardButtonStatic) tbb = toolBar.goForwardButton;						tbb.updateToolBarButton(b);					}				}			}		}		MenuCommands.menuBar().updateAllButtons();	}	/**	 * Call when done with this toolBar to release its resources	 */	public void finished() {}}

⌨️ 快捷键说明

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