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

📄 editormenubar.java

📁 经典的java图像处理程序源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.mxgraph.swing.examples.editor;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.AbstractAction;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.SwingUtilities;import javax.swing.TransferHandler;import javax.swing.UIManager;import com.mxgraph.swing.mxGraphComponent;import com.mxgraph.swing.examples.editor.EditorActions.AlignCellsAction;import com.mxgraph.swing.examples.editor.EditorActions.AutosizeAction;import com.mxgraph.swing.examples.editor.EditorActions.BackgroundAction;import com.mxgraph.swing.examples.editor.EditorActions.BackgroundImageAction;import com.mxgraph.swing.examples.editor.EditorActions.ColorAction;import com.mxgraph.swing.examples.editor.EditorActions.ExitAction;import com.mxgraph.swing.examples.editor.EditorActions.GridColorAction;import com.mxgraph.swing.examples.editor.EditorActions.GridStyleAction;import com.mxgraph.swing.examples.editor.EditorActions.HistoryAction;import com.mxgraph.swing.examples.editor.EditorActions.KeyValueAction;import com.mxgraph.swing.examples.editor.EditorActions.NewAction;import com.mxgraph.swing.examples.editor.EditorActions.OpenAction;import com.mxgraph.swing.examples.editor.EditorActions.PageBackgroundAction;import com.mxgraph.swing.examples.editor.EditorActions.PageSetupAction;import com.mxgraph.swing.examples.editor.EditorActions.PrintAction;import com.mxgraph.swing.examples.editor.EditorActions.PromptPropertyAction;import com.mxgraph.swing.examples.editor.EditorActions.PromptValueAction;import com.mxgraph.swing.examples.editor.EditorActions.SaveAction;import com.mxgraph.swing.examples.editor.EditorActions.ScaleAction;import com.mxgraph.swing.examples.editor.EditorActions.SelectShortestPathAction;import com.mxgraph.swing.examples.editor.EditorActions.SelectSpanningTreeAction;import com.mxgraph.swing.examples.editor.EditorActions.SetLabelPositionAction;import com.mxgraph.swing.examples.editor.EditorActions.SetStyleAction;import com.mxgraph.swing.examples.editor.EditorActions.StyleAction;import com.mxgraph.swing.examples.editor.EditorActions.StylesheetAction;import com.mxgraph.swing.examples.editor.EditorActions.ToggleAction;import com.mxgraph.swing.examples.editor.EditorActions.ToggleConnectModeAction;import com.mxgraph.swing.examples.editor.EditorActions.ToggleCreateTargetItem;import com.mxgraph.swing.examples.editor.EditorActions.ToggleDirtyAction;import com.mxgraph.swing.examples.editor.EditorActions.ToggleGridItem;import com.mxgraph.swing.examples.editor.EditorActions.ToggleOutlineItem;import com.mxgraph.swing.examples.editor.EditorActions.TogglePropertyItem;import com.mxgraph.swing.examples.editor.EditorActions.ToggleRulersItem;import com.mxgraph.swing.examples.editor.EditorActions.WarningAction;import com.mxgraph.swing.examples.editor.EditorActions.ZoomPolicyAction;import com.mxgraph.swing.util.mxGraphActions;import com.mxgraph.util.mxConstants;import com.mxgraph.util.mxPoint;import com.mxgraph.util.mxResources;import com.mxgraph.view.mxGraph;public class EditorMenuBar extends JMenuBar{	public EditorMenuBar(final BasicGraphEditor editor)	{		final mxGraphComponent graphComponent = editor.getGraphComponent();		final mxGraph graph = graphComponent.getGraph();		JMenu menu = null;		JMenu submenu = null;		// Creates the file menu		menu = add(new JMenu(mxResources.get("file")));		menu.add(editor.bind(mxResources.get("new"), new NewAction(),				"/com/mxgraph/swing/examples/images/new.gif"));		menu.add(editor.bind(mxResources.get("openFile"), new OpenAction(),				"/com/mxgraph/swing/examples/images/open.gif"));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("save"), new SaveAction(false),				"/com/mxgraph/swing/examples/images/save.gif"));		menu.add(editor.bind(mxResources.get("saveAs"), new SaveAction(true),				"/com/mxgraph/swing/examples/images/saveas.gif"));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("pageSetup"),				new PageSetupAction(),				"/com/mxgraph/swing/examples/images/pagesetup.gif"));		menu.add(editor.bind(mxResources.get("print"), new PrintAction(),				"/com/mxgraph/swing/examples/images/print.gif"));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("exit"), new ExitAction()));		// Creates the edit menu		menu = add(new JMenu(mxResources.get("edit")));		menu.add(editor.bind(mxResources.get("undo"), new HistoryAction(true),				"/com/mxgraph/swing/examples/images/undo.gif"));		menu.add(editor.bind(mxResources.get("redo"), new HistoryAction(false),				"/com/mxgraph/swing/examples/images/redo.gif"));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("cut"), TransferHandler				.getCutAction(), "/com/mxgraph/swing/examples/images/cut.gif"));		menu.add(editor				.bind(mxResources.get("copy"), TransferHandler.getCopyAction(),						"/com/mxgraph/swing/examples/images/copy.gif"));		menu.add(editor.bind(mxResources.get("paste"), TransferHandler				.getPasteAction(),				"/com/mxgraph/swing/examples/images/paste.gif"));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("delete"), mxGraphActions				.getDeleteAction(),				"/com/mxgraph/swing/examples/images/delete.gif"));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("selectAll"), mxGraphActions				.getSelectAllAction()));		menu.add(editor.bind(mxResources.get("selectNone"), mxGraphActions				.getSelectNoneAction()));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("warning"), new WarningAction()));		menu.add(editor.bind(mxResources.get("edit"), mxGraphActions				.getEditAction()));		// Creates the view menu		menu = add(new JMenu(mxResources.get("view")));		JMenuItem item = menu.add(new TogglePropertyItem(graphComponent,				mxResources.get("pageLayout"), "PageVisible", true,				new ActionListener()				{					/**					 * 					 */					public void actionPerformed(ActionEvent e)					{						if (graphComponent.isPageVisible()								&& graphComponent.isCenterPage())						{							graphComponent.zoomAndCenter();						}						else						{							graphComponent.getGraphControl()									.updatePreferredSize();						}					}				}));		item.addActionListener(new ActionListener()		{			/*			 * (non-Javadoc)			 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)			 */			public void actionPerformed(ActionEvent e)			{				if (e.getSource() instanceof TogglePropertyItem)				{					final mxGraphComponent graphComponent = editor							.getGraphComponent();					TogglePropertyItem toggleItem = (TogglePropertyItem) e							.getSource();					if (toggleItem.isSelected())					{						// Scrolls the view to the center						SwingUtilities.invokeLater(new Runnable()						{							/*							 * (non-Javadoc)							 * @see java.lang.Runnable#run()							 */							public void run()							{								graphComponent.scrollToCenter(true);								graphComponent.scrollToCenter(false);							}						});					}					else					{						// Resets the translation of the view						mxPoint tr = graphComponent.getGraph().getView()								.getTranslate();						if (tr.getX() != 0 || tr.getY() != 0)						{							graphComponent.getGraph().getView().setTranslate(									new mxPoint());						}					}				}			}		});		menu.add(new TogglePropertyItem(graphComponent, mxResources				.get("antialias"), "AntiAlias", true));		menu.addSeparator();		menu.add(new ToggleGridItem(editor, mxResources.get("grid")));		menu.add(new ToggleRulersItem(editor, mxResources.get("rulers")));		menu.addSeparator();		submenu = (JMenu) menu.add(new JMenu(mxResources.get("zoom")));		submenu.add(editor.bind("400%", new ScaleAction(4)));		submenu.add(editor.bind("200%", new ScaleAction(2)));		submenu.add(editor.bind("150%", new ScaleAction(1.5)));		submenu.add(editor.bind("100%", new ScaleAction(1)));		submenu.add(editor.bind("75%", new ScaleAction(0.75)));		submenu.add(editor.bind("50%", new ScaleAction(0.5)));		submenu.addSeparator();		submenu.add(editor.bind(mxResources.get("custom"), new ScaleAction(0)));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("zoomIn"), mxGraphActions				.getZoomInAction()));		menu.add(editor.bind(mxResources.get("zoomOut"), mxGraphActions				.getZoomOutAction()));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("page"), new ZoomPolicyAction(				mxGraphComponent.ZOOM_POLICY_PAGE)));		menu.add(editor.bind(mxResources.get("width"), new ZoomPolicyAction(				mxGraphComponent.ZOOM_POLICY_WIDTH)));		menu.addSeparator();		menu.add(editor.bind(mxResources.get("actualSize"), mxGraphActions				.getZoomActualAction()));		// Creates the format menu		menu = add(new JMenu(mxResources.get("format")));		populateFormatMenu(menu, editor);		// Creates the shape menu		menu = add(new JMenu(mxResources.get("shape")));		populateShapeMenu(menu, editor);		// Creates the diagram menu		menu = add(new JMenu(mxResources.get("diagram")));		menu.add(new ToggleOutlineItem(editor, mxResources.get("outline")));		menu.addSeparator();		submenu = (JMenu) menu.add(new JMenu(mxResources.get("background")));		submenu.add(editor.bind(mxResources.get("backgroundColor"),				new BackgroundAction()));		submenu.add(editor.bind(mxResources.get("backgroundImage"),				new BackgroundImageAction()));		submenu.addSeparator();		submenu.add(editor.bind(mxResources.get("pageBackground"),				new PageBackgroundAction()));		submenu = (JMenu) menu.add(new JMenu(mxResources.get("grid")));		submenu.add(editor.bind(mxResources.get("gridSize"),				new PromptPropertyAction(graph, "Grid Size", "GridSize")));		submenu.add(editor.bind(mxResources.get("gridColor"),				new GridColorAction()));		submenu.addSeparator();		submenu.add(editor.bind(mxResources.get("dashed"), new GridStyleAction(				mxGraphComponent.GRID_STYLE_DASHED)));		submenu.add(editor.bind(mxResources.get("dot"), new GridStyleAction(				mxGraphComponent.GRID_STYLE_DOT)));		submenu.add(editor.bind(mxResources.get("line"), new GridStyleAction(				mxGraphComponent.GRID_STYLE_LINE)));		submenu.add(editor.bind(mxResources.get("cross"), new GridStyleAction(				mxGraphComponent.GRID_STYLE_CROSS)));

⌨️ 快捷键说明

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