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

📄 toolbartab.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: ToolbarTab.java * * Copyright (c) 2008 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING.  If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.user.dialogs.options;import com.sun.electric.database.text.TextUtils;import com.sun.electric.tool.Job;import com.sun.electric.tool.io.FileType;import com.sun.electric.tool.user.Resources;import com.sun.electric.tool.user.dialogs.OpenFile;import com.sun.electric.tool.user.dialogs.PreferencesFrame;import com.sun.electric.tool.user.menus.EMenu;import com.sun.electric.tool.user.menus.EMenuItem;import com.sun.electric.tool.user.ui.ToolBar;import com.sun.electric.tool.user.ui.TopLevel;import com.sun.electric.tool.user.ui.ToolBar.EToolBarButton;import java.awt.Color;import java.awt.Component;import java.awt.Frame;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Point;import java.awt.Rectangle;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.Transferable;import java.awt.dnd.DnDConstants;import java.awt.dnd.DragGestureEvent;import java.awt.dnd.DragGestureListener;import java.awt.dnd.DragSource;import java.awt.dnd.DragSourceDragEvent;import java.awt.dnd.DragSourceDropEvent;import java.awt.dnd.DragSourceEvent;import java.awt.dnd.DragSourceListener;import java.awt.dnd.DropTarget;import java.awt.dnd.DropTargetDragEvent;import java.awt.dnd.DropTargetDropEvent;import java.awt.dnd.DropTargetEvent;import java.awt.dnd.DropTargetListener;import java.awt.event.InputEvent;import java.awt.image.BufferedImage;import java.awt.image.Raster;import java.awt.image.WritableRaster;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTree;import javax.swing.TransferHandler;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.DefaultTreeModel;import javax.swing.tree.TreePath;import javax.swing.tree.TreeSelectionModel;/** * Class to handle the "Toolbar" tab of the Preferences dialog. */public class ToolbarTab extends PreferencePanel implements TreeSelectionListener{	private CommandTree commandsTree;	private List<DraggableToolbarEntry> sampleToolbarComponents;	private Map<String,EToolBarButton> knownButtons;	private Map<String,EMenuItem> menuEntries;	private Map<String,String> commandToIconMap;	private MenuTreeNode currentTreeNode;	private PreferencesFrame trueParent;	private static ImageIcon menuIcon = Resources.getResource(ToolBar.class, "ButtonMenu.gif");	private static ImageIcon trashIcon = Resources.getResource(ToolBar.class, "IconTrash.gif");	private static ImageIcon separatorIcon = Resources.getResource(ToolBar.class, "IconSeparator.gif");	private static ImageIcon separatorButton = Resources.getResource(ToolBar.class, "ButtonSeparator.gif");	/** Creates new form ToolbarTab */	public ToolbarTab(Frame parent, boolean modal, PreferencesFrame trueParent)	{		super(parent, modal);		this.trueParent = trueParent;		initComponents();		// initialize the separator icon (and make it draggable)		separatorLabel.setIcon(separatorIcon);		DragSource dragSource = DragSource.getDefaultDragSource();		dragSource.createDefaultDragGestureRecognizer(separatorLabel, DnDConstants.ACTION_LINK, new SeparatorDrag());		// initialize the trash icon (and make it droppable)		trashLabel.setIcon(trashIcon);		TrashDropTarget dropTarget = new TrashDropTarget();		new DropTarget(trashLabel, DnDConstants.ACTION_MOVE, dropTarget, true);	}	/** return the panel to use for this preferences tab. */	public JPanel getPanel() { return toolbar; }	/** return the name of this preferences tab. */	public String getName() { return "Toolbar"; }	/**	 * Method called at the start of the dialog.	 * Caches current values and displays them in the Toolbar tab.	 */	public void init()	{		// initialize the known buttons that are in the toolbar		knownButtons = new HashMap<String,EToolBarButton>();		List<ToolBar.EToolBarButton> allButtons = ToolBar.getAllButtons();		for (ToolBar.EToolBarButton b : allButtons)			knownButtons.put(b.getMenuName() + ":" + b.getText().replace("_", ""), b);		// build the command tree		commandsTree = new CommandTree();		buildCommandsTree();		// add in new buttons that have custom icons		commandToIconMap = ToolBar.getCommandToIconMap();		for(String command : commandToIconMap.keySet())		{			String fileName = commandToIconMap.get(command);			ToolBar.EToolBarButton but = knownButtons.get(command);			if (but == null)			{				int lastColon = command.lastIndexOf(':');				String menuName = (lastColon < 0) ? "" : command.substring(0, lastColon);				String commandName = command.substring(lastColon+1);				EMenuItem mi = menuEntries.get(command);				if (mi == null) continue;				but = new ToolBar.EToolBarGeneralMenuButton(commandName, "ButtonUnknown", menuName, mi);				knownButtons.put(command, but);			}			ImageIcon icon = ToolBar.getProperSizeIcon(fileName);			but.setIcon(icon, fileName);		}		// finish initializing the command tree		commandsTree.setCellRenderer(new MyRenderer());		commandsPane.setViewportView(commandsTree);		// make sure all button icons exist in the menus		for(String iconCommand : knownButtons.keySet())		{			if (menuEntries.get(iconCommand) == null)				System.out.println("WARNING: Icon mapped to command '" + iconCommand + "' which does not exist");		}		// construct the toolbar		currentToolbar.setLayout(new GridBagLayout());		EToolBarButton [] currentButtons = ToolBar.getToolbarButtons();		sampleToolbarComponents = new ArrayList<DraggableToolbarEntry>();		for (int i=0; i<currentButtons.length; i++)		{			EToolBarButton b = currentButtons[i];			DraggableToolbarEntry j = new DraggableToolbarEntry(i, b);			sampleToolbarComponents.add(j);		}		buildSampleToolbar();	}	/**	 * Method called when the "OK" button is hit.	 * Updates any changed fields in the Toolbar tab.	 */	public void term()	{		ToolBar.setCommandToIconMap(commandToIconMap);		EToolBarButton [] newButtons = new EToolBarButton[sampleToolbarComponents.size()];		for(int i=0; i<sampleToolbarComponents.size(); i++)			newButtons[i] = sampleToolbarComponents.get(i).getToolbarButton();		ToolBar.setToolbarButtons(newButtons);	}	/**	 * Method called when the factory reset is requested for just this panel.	 * @return true if the panel can be reset "in place" without redisplay.	 */	public boolean resetThis()	{		sampleToolbarComponents.clear();		EToolBarButton [] factorySet = ToolBar.getFactoryButtons();		for(int i=0; i<factorySet.length; i++)			sampleToolbarComponents.add(new DraggableToolbarEntry(i, factorySet[i]));		buildSampleToolbar();		trueParent.pack();		return true;	}	/**	 * Method called when the factory reset is requested.	 */	public void reset()	{		EToolBarButton [] fButs = ToolBar.getFactoryButtons();		EToolBarButton [] buts = ToolBar.getToolbarButtons();		boolean same = fButs.equals(buts);		if (!same)			ToolBar.setToolbarButtons(ToolBar.getFactoryButtons());	}	private void buildSampleToolbar()	{		currentToolbar.removeAll();		for (int i=0; i<sampleToolbarComponents.size(); i++)		{			DraggableToolbarEntry j = sampleToolbarComponents.get(i);			j.setIndex(i);			GridBagConstraints gbc = new GridBagConstraints();			gbc.gridx = i;   gbc.gridy = 0;			currentToolbar.add(j, gbc);		}	}	private void dropButton(String droppedButton)	{		if (droppedButton.startsWith("#"))		{			int index = TextUtils.atoi(droppedButton.substring(1));			sampleToolbarComponents.remove(index);			buildSampleToolbar();			trueParent.pack();		}	}	private void droppedAt(int index, String what, boolean before)	{		if (!before) index++;		if (what.startsWith("#"))		{			// a rearrangement of buttons			int startLoc = TextUtils.atoi(what.substring(1));			DraggableToolbarEntry j = sampleToolbarComponents.get(startLoc);			sampleToolbarComponents.remove(startLoc);			if (startLoc < index) index--;			sampleToolbarComponents.add(index, j);		} else		{			if (what.equals("SEPARATOR"))			{				// inserting separator				DraggableToolbarEntry j = new DraggableToolbarEntry(0, null);				sampleToolbarComponents.add(index, j);			} else			{				// inserting new command				EToolBarButton but = knownButtons.get(what);				if (but == null)				{					int lastColon = what.lastIndexOf(':');					String menuName = (lastColon < 0) ? "" : what.substring(0, lastColon);					String commandName = what.substring(lastColon+1);					EMenuItem mi = menuEntries.get(what);					but = new ToolBar.EToolBarGeneralMenuButton(commandName, "ButtonUnknown", menuName, mi);					knownButtons.put(what, but);				}				DraggableToolbarEntry j = new DraggableToolbarEntry(0, but);				sampleToolbarComponents.add(index, j);			}		}		buildSampleToolbar();		trueParent.pack();	}	/**	 * Called when selection of Node in tree changes.	 * It updates the list box to reflect the current tree selection.	 */	public void valueChanged(TreeSelectionEvent e)	{		currentTreeNode = null;		TreePath path = e.getPath();		if (path == null) return;		Object obj = path.getLastPathComponent();		DefaultMutableTreeNode node = (DefaultMutableTreeNode)obj;		Object n = node.getUserObject();		if (!(n instanceof MenuTreeNode)) return;		MenuTreeNode mtn = (MenuTreeNode)n;		if (mtn.menuName.endsWith("--")) return;		currentTreeNode = mtn;	}	private void attachImageToCommand()	{		if (currentTreeNode == null)		{			Job.getUserInterface().showErrorMessage("Must select a command from the 'Commands' tree first", "Cannot Set Image");			return;		}		String fileName = OpenFile.chooseInputFile(FileType.ANY, "Image to attach to command");		if (fileName == null) return;		ImageIcon icon = ToolBar.getProperSizeIcon(fileName);		if (icon != null)		{			// find the button associated with this command and set the icon			String what = currentTreeNode.menuName;			EToolBarButton but = knownButtons.get(what);			if (but == null)			{

⌨️ 快捷键说明

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