1 package com.mxgraph.examples.swing.editor;
2 
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 
6 import javax.swing.AbstractAction;
7 import javax.swing.JMenu;
8 import javax.swing.JMenuBar;
9 import javax.swing.JMenuItem;
10 import javax.swing.SwingUtilities;
11 import javax.swing.TransferHandler;
12 import javax.swing.UIManager;
13 
14 import com.mxgraph.examples.swing.editor.EditorActions.AlignCellsAction;
15 import com.mxgraph.examples.swing.editor.EditorActions.AutosizeAction;
16 import com.mxgraph.examples.swing.editor.EditorActions.BackgroundAction;
17 import com.mxgraph.examples.swing.editor.EditorActions.BackgroundImageAction;
18 import com.mxgraph.examples.swing.editor.EditorActions.ColorAction;
19 import com.mxgraph.examples.swing.editor.EditorActions.ExitAction;
20 import com.mxgraph.examples.swing.editor.EditorActions.GridColorAction;
21 import com.mxgraph.examples.swing.editor.EditorActions.GridStyleAction;
22 import com.mxgraph.examples.swing.editor.EditorActions.HistoryAction;
23 import com.mxgraph.examples.swing.editor.EditorActions.KeyValueAction;
24 import com.mxgraph.examples.swing.editor.EditorActions.NewAction;
25 import com.mxgraph.examples.swing.editor.EditorActions.OpenAction;
26 import com.mxgraph.examples.swing.editor.EditorActions.PageBackgroundAction;
27 import com.mxgraph.examples.swing.editor.EditorActions.PageSetupAction;
28 import com.mxgraph.examples.swing.editor.EditorActions.PrintAction;
29 import com.mxgraph.examples.swing.editor.EditorActions.PromptPropertyAction;
30 import com.mxgraph.examples.swing.editor.EditorActions.PromptValueAction;
31 import com.mxgraph.examples.swing.editor.EditorActions.SaveAction;
32 import com.mxgraph.examples.swing.editor.EditorActions.ScaleAction;
33 import com.mxgraph.examples.swing.editor.EditorActions.SelectShortestPathAction;
34 import com.mxgraph.examples.swing.editor.EditorActions.SelectSpanningTreeAction;
35 import com.mxgraph.examples.swing.editor.EditorActions.SetLabelPositionAction;
36 import com.mxgraph.examples.swing.editor.EditorActions.SetStyleAction;
37 import com.mxgraph.examples.swing.editor.EditorActions.StyleAction;
38 import com.mxgraph.examples.swing.editor.EditorActions.StylesheetAction;
39 import com.mxgraph.examples.swing.editor.EditorActions.ToggleAction;
40 import com.mxgraph.examples.swing.editor.EditorActions.ToggleConnectModeAction;
41 import com.mxgraph.examples.swing.editor.EditorActions.ToggleCreateTargetItem;
42 import com.mxgraph.examples.swing.editor.EditorActions.ToggleDirtyAction;
43 import com.mxgraph.examples.swing.editor.EditorActions.ToggleGridItem;
44 import com.mxgraph.examples.swing.editor.EditorActions.ToggleOutlineItem;
45 import com.mxgraph.examples.swing.editor.EditorActions.TogglePropertyItem;
46 import com.mxgraph.examples.swing.editor.EditorActions.ToggleRulersItem;
47 import com.mxgraph.examples.swing.editor.EditorActions.WarningAction;
48 import com.mxgraph.examples.swing.editor.EditorActions.ZoomPolicyAction;
49 import com.mxgraph.swing.mxGraphComponent;
50 import com.mxgraph.swing.util.mxGraphActions;
51 import com.mxgraph.util.mxConstants;
52 import com.mxgraph.util.mxPoint;
53 import com.mxgraph.util.mxResources;
54 import com.mxgraph.view.mxGraph;
55 
56 public class EditorMenuBar extends JMenuBar
57 {
58 
59 	/**
60 	 *
61 	 */
62 	private static final long serialVersionUID = 4060203894740766714L;
63 
64 	@SuppressWarnings("serial")
EditorMenuBar(final BasicGraphEditor editor)65 	public EditorMenuBar(final BasicGraphEditor editor)
66 	{
67 		final mxGraphComponent graphComponent = editor.getGraphComponent();
68 		final mxGraph graph = graphComponent.getGraph();
69 		JMenu menu = null;
70 		JMenu submenu = null;
71 
72 		// Creates the file menu
73 		menu = add(new JMenu(mxResources.get("file")));
74 
75 		menu.add(editor.bind(mxResources.get("clear"), new NewAction(),
76 				"/com/mxgraph/examples/swing/images/new.gif"));
77 		menu.add(editor.bind(mxResources.get("reload"), new OpenAction(),
78 				"/com/mxgraph/examples/swing/images/open.gif"));
79 
80 		menu.addSeparator();
81 
82 		menu.add(editor.bind(mxResources.get("save"), new SaveAction(false),
83 				"/com/mxgraph/examples/swing/images/save.gif"));
84 //		menu.add(editor.bind(mxResources.get("saveAs"), new SaveAction(true),
85 //				"/com/mxgraph/examples/swing/images/saveas.gif"));
86 
87 //		menu.addSeparator();
88 
89 //		menu.add(editor.bind(mxResources.get("pageSetup"),
90 //				new PageSetupAction(),
91 //				"/com/mxgraph/examples/swing/images/pagesetup.gif"));
92 //		menu.add(editor.bind(mxResources.get("print"), new PrintAction(),
93 //				"/com/mxgraph/examples/swing/images/print.gif"));
94 
95 //		menu.addSeparator();
96 //
97 //		menu.add(editor.bind(mxResources.get("exit"), new ExitAction()));
98 
99 		// Creates the edit menu
100 		menu = add(new JMenu(mxResources.get("edit")));
101 
102 		menu.add(editor.bind(mxResources.get("undo"), new HistoryAction(true),
103 				"/com/mxgraph/examples/swing/images/undo.gif"));
104 		menu.add(editor.bind(mxResources.get("redo"), new HistoryAction(false),
105 				"/com/mxgraph/examples/swing/images/redo.gif"));
106 
107 		menu.addSeparator();
108 
109 		menu.add(editor.bind(mxResources.get("cut"), TransferHandler
110 				.getCutAction(), "/com/mxgraph/examples/swing/images/cut.gif"));
111 		menu.add(editor
112 				.bind(mxResources.get("copy"), TransferHandler.getCopyAction(),
113 						"/com/mxgraph/examples/swing/images/copy.gif"));
114 		menu.add(editor.bind(mxResources.get("paste"), TransferHandler
115 				.getPasteAction(),
116 				"/com/mxgraph/examples/swing/images/paste.gif"));
117 
118 		menu.addSeparator();
119 
120 		menu.add(editor.bind(mxResources.get("delete"), mxGraphActions
121 				.getDeleteAction(),
122 				"/com/mxgraph/examples/swing/images/delete.gif"));
123 
124 		menu.addSeparator();
125 
126 		menu.add(editor.bind(mxResources.get("selectAll"), mxGraphActions
127 				.getSelectAllAction()));
128 		menu.add(editor.bind(mxResources.get("selectNone"), mxGraphActions
129 				.getSelectNoneAction()));
130 
131 		menu.addSeparator();
132 
133 		menu.add(editor.bind(mxResources.get("warning"), new WarningAction()));
134 		menu.add(editor.bind(mxResources.get("edit"), mxGraphActions
135 				.getEditAction()));
136 
137 		// Creates the view menu
138 		menu = add(new JMenu(mxResources.get("view")));
139 
140 		JMenuItem item = menu.add(new TogglePropertyItem(graphComponent,
141 				mxResources.get("pageLayout"), "PageVisible", true,
142 				new ActionListener()
143 				{
144 					/**
145 					 *
146 					 */
147 					public void actionPerformed(ActionEvent e)
148 					{
149 						if (graphComponent.isPageVisible()
150 								&& graphComponent.isCenterPage())
151 						{
152 							graphComponent.zoomAndCenter();
153 						}
154 						else
155 						{
156 							graphComponent.getGraphControl()
157 									.updatePreferredSize();
158 						}
159 					}
160 				}));
161 
162 		item.addActionListener(new ActionListener()
163 		{
164 			/*
165 			 * (non-Javadoc)
166 			 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
167 			 */
168 			public void actionPerformed(ActionEvent e)
169 			{
170 				if (e.getSource() instanceof TogglePropertyItem)
171 				{
172 					final mxGraphComponent graphComponent = editor
173 							.getGraphComponent();
174 					TogglePropertyItem toggleItem = (TogglePropertyItem) e
175 							.getSource();
176 
177 					if (toggleItem.isSelected())
178 					{
179 						// Scrolls the view to the center
180 						SwingUtilities.invokeLater(new Runnable()
181 						{
182 							/*
183 							 * (non-Javadoc)
184 							 * @see java.lang.Runnable#run()
185 							 */
186 							public void run()
187 							{
188 								graphComponent.scrollToCenter(true);
189 								graphComponent.scrollToCenter(false);
190 							}
191 						});
192 					}
193 					else
194 					{
195 						// Resets the translation of the view
196 						mxPoint tr = graphComponent.getGraph().getView()
197 								.getTranslate();
198 
199 						if (tr.getX() != 0 || tr.getY() != 0)
200 						{
201 							graphComponent.getGraph().getView().setTranslate(
202 									new mxPoint());
203 						}
204 					}
205 				}
206 			}
207 		});
208 
209 		menu.add(new TogglePropertyItem(graphComponent, mxResources
210 				.get("antialias"), "AntiAlias", true));
211 
212 		menu.addSeparator();
213 
214 		menu.add(new ToggleGridItem(editor, mxResources.get("grid")));
215 		menu.add(new ToggleRulersItem(editor, mxResources.get("rulers")));
216 
217 		menu.addSeparator();
218 
219 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("zoom")));
220 
221 		submenu.add(editor.bind("400%", new ScaleAction(4)));
222 		submenu.add(editor.bind("200%", new ScaleAction(2)));
223 		submenu.add(editor.bind("150%", new ScaleAction(1.5)));
224 		submenu.add(editor.bind("100%", new ScaleAction(1)));
225 		submenu.add(editor.bind("75%", new ScaleAction(0.75)));
226 		submenu.add(editor.bind("50%", new ScaleAction(0.5)));
227 
228 		submenu.addSeparator();
229 
230 		submenu.add(editor.bind(mxResources.get("custom"), new ScaleAction(0)));
231 
232 		menu.addSeparator();
233 
234 		menu.add(editor.bind(mxResources.get("zoomIn"), mxGraphActions
235 				.getZoomInAction()));
236 		menu.add(editor.bind(mxResources.get("zoomOut"), mxGraphActions
237 				.getZoomOutAction()));
238 
239 		menu.addSeparator();
240 
241 		menu.add(editor.bind(mxResources.get("page"), new ZoomPolicyAction(
242 				mxGraphComponent.ZOOM_POLICY_PAGE)));
243 		menu.add(editor.bind(mxResources.get("width"), new ZoomPolicyAction(
244 				mxGraphComponent.ZOOM_POLICY_WIDTH)));
245 
246 		menu.addSeparator();
247 
248 		menu.add(editor.bind(mxResources.get("actualSize"), mxGraphActions
249 				.getZoomActualAction()));
250 
251 		// Creates the format menu
252 		menu = add(new JMenu(mxResources.get("format")));
253 
254 		populateFormatMenu(menu, editor);
255 
256 		// Creates the shape menu
257 		menu = add(new JMenu(mxResources.get("shape")));
258 
259 		populateShapeMenu(menu, editor);
260 
261 		// Creates the diagram menu
262 		menu = add(new JMenu(mxResources.get("diagram")));
263 
264 		menu.add(new ToggleOutlineItem(editor, mxResources.get("outline")));
265 
266 		menu.addSeparator();
267 
268 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("background")));
269 
270 		submenu.add(editor.bind(mxResources.get("backgroundColor"),
271 				new BackgroundAction()));
272 		submenu.add(editor.bind(mxResources.get("backgroundImage"),
273 				new BackgroundImageAction()));
274 
275 		submenu.addSeparator();
276 
277 		submenu.add(editor.bind(mxResources.get("pageBackground"),
278 				new PageBackgroundAction()));
279 
280 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("grid")));
281 
282 		submenu.add(editor.bind(mxResources.get("gridSize"),
283 				new PromptPropertyAction(graph, "Grid Size", "GridSize")));
284 		submenu.add(editor.bind(mxResources.get("gridColor"),
285 				new GridColorAction()));
286 
287 		submenu.addSeparator();
288 
289 		submenu.add(editor.bind(mxResources.get("dashed"), new GridStyleAction(
290 				mxGraphComponent.GRID_STYLE_DASHED)));
291 		submenu.add(editor.bind(mxResources.get("dot"), new GridStyleAction(
292 				mxGraphComponent.GRID_STYLE_DOT)));
293 		submenu.add(editor.bind(mxResources.get("line"), new GridStyleAction(
294 				mxGraphComponent.GRID_STYLE_LINE)));
295 		submenu.add(editor.bind(mxResources.get("cross"), new GridStyleAction(
296 				mxGraphComponent.GRID_STYLE_CROSS)));
297 
298 		menu.addSeparator();
299 
300 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("layout")));
301 
302 		submenu.add(editor.graphLayout("verticalHierarchical", true));
303 		submenu.add(editor.graphLayout("horizontalHierarchical", true));
304 
305 		submenu.addSeparator();
306 
307 		submenu.add(editor.graphLayout("verticalPartition", false));
308 		submenu.add(editor.graphLayout("horizontalPartition", false));
309 
310 		submenu.addSeparator();
311 
312 		submenu.add(editor.graphLayout("verticalStack", false));
313 		submenu.add(editor.graphLayout("horizontalStack", false));
314 
315 		submenu.addSeparator();
316 
317 		submenu.add(editor.graphLayout("verticalTree", true));
318 		submenu.add(editor.graphLayout("horizontalTree", true));
319 
320 		submenu.addSeparator();
321 
322 		submenu.add(editor.graphLayout("placeEdgeLabels", false));
323 		submenu.add(editor.graphLayout("parallelEdges", false));
324 
325 		submenu.addSeparator();
326 
327 		submenu.add(editor.graphLayout("organicLayout", true));
328 		submenu.add(editor.graphLayout("circleLayout", true));
329 
330 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("selection")));
331 
332 		submenu.add(editor.bind(mxResources.get("selectPath"),
333 				new SelectShortestPathAction(false)));
334 		submenu.add(editor.bind(mxResources.get("selectDirectedPath"),
335 				new SelectShortestPathAction(true)));
336 
337 		submenu.addSeparator();
338 
339 		submenu.add(editor.bind(mxResources.get("selectTree"),
340 				new SelectSpanningTreeAction(false)));
341 		submenu.add(editor.bind(mxResources.get("selectDirectedTree"),
342 				new SelectSpanningTreeAction(true)));
343 
344 		menu.addSeparator();
345 
346 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("stylesheet")));
347 
348 		submenu
349 				.add(editor
350 						.bind(
351 								mxResources.get("basicStyle"),
352 								new StylesheetAction(
353 										"/com/mxgraph/examples/swing/resources/basic-style.xml")));
354 		submenu
355 				.add(editor
356 						.bind(
357 								mxResources.get("defaultStyle"),
358 								new StylesheetAction(
359 										"/com/mxgraph/examples/swing/resources/default-style.xml")));
360 
361 		// Creates the options menu
362 		menu = add(new JMenu(mxResources.get("options")));
363 
364 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("display")));
365 		submenu.add(new TogglePropertyItem(graphComponent, mxResources
366 				.get("buffering"), "TripleBuffered", true));
367 
368 		submenu.add(new TogglePropertyItem(graphComponent, mxResources
369 				.get("preferPageSize"), "PreferPageSize", true,
370 				new ActionListener()
371 				{
372 					/**
373 					 *
374 					 */
375 					public void actionPerformed(ActionEvent e)
376 					{
377 						graphComponent.zoomAndCenter();
378 					}
379 				}));
380 
381 		// TODO: This feature is not yet implemented
382 		//submenu.add(new TogglePropertyItem(graphComponent, mxResources
383 		//		.get("pageBreaks"), "PageBreakVisible", true));
384 
385 		submenu.addSeparator();
386 
387 		submenu.add(editor.bind(mxResources.get("tolerance"),
388 				new PromptPropertyAction(graphComponent, "Tolerance")));
389 
390 		submenu.add(editor.bind(mxResources.get("dirty"),
391 				new ToggleDirtyAction()));
392 
393 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("zoom")));
394 
395 		submenu.add(new TogglePropertyItem(graphComponent, mxResources
396 				.get("centerZoom"), "CenterZoom", true));
397 		submenu.add(new TogglePropertyItem(graphComponent, mxResources
398 				.get("zoomToSelection"), "KeepSelectionVisibleOnZoom", true));
399 
400 		submenu.addSeparator();
401 
402 		submenu.add(new TogglePropertyItem(graphComponent, mxResources
403 				.get("centerPage"), "CenterPage", true, new ActionListener()
404 		{
405 			/**
406 			 *
407 			 */
408 			public void actionPerformed(ActionEvent e)
409 			{
410 				if (graphComponent.isPageVisible()
411 						&& graphComponent.isCenterPage())
412 				{
413 					graphComponent.zoomAndCenter();
414 				}
415 			}
416 		}));
417 
418 		menu.addSeparator();
419 
420 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("dragAndDrop")));
421 
422 		submenu.add(new TogglePropertyItem(graphComponent, mxResources
423 				.get("dragEnabled"), "DragEnabled"));
424 		submenu.add(new TogglePropertyItem(graph, mxResources
425 				.get("dropEnabled"), "DropEnabled"));
426 
427 		submenu.addSeparator();
428 
429 		submenu.add(new TogglePropertyItem(graphComponent.getGraphHandler(),
430 				mxResources.get("imagePreview"), "ImagePreview"));
431 
432 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("labels")));
433 
434 		submenu.add(new TogglePropertyItem(graph,
435 				mxResources.get("htmlLabels"), "HtmlLabels", true));
436 		submenu.add(new TogglePropertyItem(graph,
437 				mxResources.get("showLabels"), "LabelsVisible", true));
438 
439 		submenu.addSeparator();
440 
441 		submenu.add(new TogglePropertyItem(graph, mxResources
442 				.get("moveEdgeLabels"), "EdgeLabelsMovable"));
443 		submenu.add(new TogglePropertyItem(graph, mxResources
444 				.get("moveVertexLabels"), "VertexLabelsMovable"));
445 
446 		submenu.addSeparator();
447 
448 		submenu.add(new TogglePropertyItem(graphComponent,
449 				mxResources.get("handleReturn"), "EnterStopsCellEditing"));
450 
451 		menu.addSeparator();
452 
453 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("connections")));
454 
455 		submenu.add(new TogglePropertyItem(graphComponent, mxResources
456 				.get("connectable"), "Connectable"));
457 		submenu.add(new TogglePropertyItem(graph, mxResources
458 				.get("connectableEdges"), "ConnectableEdges"));
459 
460 		submenu.addSeparator();
461 
462 		submenu.add(new ToggleCreateTargetItem(editor, mxResources
463 				.get("createTarget")));
464 		submenu.add(new TogglePropertyItem(graph, mxResources
465 				.get("disconnectOnMove"), "DisconnectOnMove"));
466 
467 		submenu.addSeparator();
468 
469 		submenu.add(editor.bind(mxResources.get("connectMode"),
470 				new ToggleConnectModeAction()));
471 
472 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("validation")));
473 
474 		submenu.add(new TogglePropertyItem(graph, mxResources
475 				.get("allowDanglingEdges"), "AllowDanglingEdges"));
476 		submenu.add(new TogglePropertyItem(graph, mxResources
477 				.get("cloneInvalidEdges"), "CloneInvalidEdges"));
478 
479 		submenu.addSeparator();
480 
481 		submenu.add(new TogglePropertyItem(graph,
482 				mxResources.get("allowLoops"), "AllowLoops"));
483 		submenu.add(new TogglePropertyItem(graph,
484 				mxResources.get("multigraph"), "Multigraph"));
485 
486 //		// Creates the window menu
487 //		menu = add(new JMenu(mxResources.get("window")));
488 //
489 //		UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
490 //
491 //		for (int i = 0; i < lafs.length; i++)
492 //		{
493 //			final String clazz = lafs[i].getClassName();
494 //			menu.add(new AbstractAction(lafs[i].getName())
495 //			{
496 //				public void actionPerformed(ActionEvent e)
497 //				{
498 //					editor.setLookAndFeel(clazz);
499 //				}
500 //			});
501 //		}
502 
503 //		// Creates the help menu
504 //		menu = add(new JMenu(mxResources.get("help")));
505 //
506 //		item = menu.add(new JMenuItem(mxResources.get("aboutGraphEditor")));
507 //		item.addActionListener(new ActionListener()
508 //		{
509 //			/*
510 //			 * (non-Javadoc)
511 //			 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
512 //			 */
513 //			public void actionPerformed(ActionEvent e)
514 //			{
515 //
516 //				// Doesn't work in the applet.
517 ////				editor.about();
518 //			}
519 //		});
520 	}
521 
522 	/**
523 	 * Adds menu items to the given shape menu. This is factored out because
524 	 * the shape menu appears in the menubar and also in the popupmenu.
525 	 */
populateShapeMenu(JMenu menu, BasicGraphEditor editor)526 	public static void populateShapeMenu(JMenu menu, BasicGraphEditor editor)
527 	{
528 		menu.add(editor.bind(mxResources.get("home"), mxGraphActions
529 				.getHomeAction(),
530 				"/com/mxgraph/examples/swing/images/house.gif"));
531 
532 		menu.addSeparator();
533 
534 		menu.add(editor.bind(mxResources.get("exitGroup"), mxGraphActions
535 				.getExitGroupAction(),
536 				"/com/mxgraph/examples/swing/images/up.gif"));
537 		menu.add(editor.bind(mxResources.get("enterGroup"), mxGraphActions
538 				.getEnterGroupAction(),
539 				"/com/mxgraph/examples/swing/images/down.gif"));
540 
541 		menu.addSeparator();
542 
543 		menu.add(editor.bind(mxResources.get("group"), mxGraphActions
544 				.getGroupAction(),
545 				"/com/mxgraph/examples/swing/images/group.gif"));
546 		menu.add(editor.bind(mxResources.get("ungroup"), mxGraphActions
547 				.getUngroupAction(),
548 				"/com/mxgraph/examples/swing/images/ungroup.gif"));
549 
550 		menu.addSeparator();
551 
552 		menu.add(editor.bind(mxResources.get("removeFromGroup"), mxGraphActions
553 				.getRemoveFromParentAction()));
554 
555 		menu.add(editor.bind(mxResources.get("updateGroupBounds"), mxGraphActions
556 				.getUpdateGroupBoundsAction()));
557 
558 		menu.addSeparator();
559 
560 		menu.add(editor.bind(mxResources.get("collapse"), mxGraphActions
561 				.getCollapseAction(),
562 				"/com/mxgraph/examples/swing/images/collapse.gif"));
563 		menu.add(editor.bind(mxResources.get("expand"), mxGraphActions
564 				.getExpandAction(),
565 				"/com/mxgraph/examples/swing/images/expand.gif"));
566 
567 		menu.addSeparator();
568 
569 		menu.add(editor.bind(mxResources.get("toBack"), mxGraphActions
570 				.getToBackAction(),
571 				"/com/mxgraph/examples/swing/images/toback.gif"));
572 		menu.add(editor.bind(mxResources.get("toFront"), mxGraphActions
573 				.getToFrontAction(),
574 				"/com/mxgraph/examples/swing/images/tofront.gif"));
575 
576 		menu.addSeparator();
577 
578 		JMenu submenu = (JMenu) menu.add(new JMenu(mxResources.get("align")));
579 
580 		submenu.add(editor.bind(mxResources.get("left"), new AlignCellsAction(
581 				mxConstants.ALIGN_LEFT),
582 				"/com/mxgraph/examples/swing/images/alignleft.gif"));
583 		submenu.add(editor.bind(mxResources.get("center"),
584 				new AlignCellsAction(mxConstants.ALIGN_CENTER),
585 				"/com/mxgraph/examples/swing/images/aligncenter.gif"));
586 		submenu.add(editor.bind(mxResources.get("right"), new AlignCellsAction(
587 				mxConstants.ALIGN_RIGHT),
588 				"/com/mxgraph/examples/swing/images/alignright.gif"));
589 
590 		submenu.addSeparator();
591 
592 		submenu.add(editor.bind(mxResources.get("top"), new AlignCellsAction(
593 				mxConstants.ALIGN_TOP),
594 				"/com/mxgraph/examples/swing/images/aligntop.gif"));
595 		submenu.add(editor.bind(mxResources.get("middle"),
596 				new AlignCellsAction(mxConstants.ALIGN_MIDDLE),
597 				"/com/mxgraph/examples/swing/images/alignmiddle.gif"));
598 		submenu.add(editor.bind(mxResources.get("bottom"),
599 				new AlignCellsAction(mxConstants.ALIGN_BOTTOM),
600 				"/com/mxgraph/examples/swing/images/alignbottom.gif"));
601 
602 		menu.addSeparator();
603 
604 		menu
605 				.add(editor.bind(mxResources.get("autosize"),
606 						new AutosizeAction()));
607 
608 	}
609 
610 	/**
611 	 * Adds menu items to the given format menu. This is factored out because
612 	 * the format menu appears in the menubar and also in the popupmenu.
613 	 */
populateFormatMenu(JMenu menu, BasicGraphEditor editor)614 	public static void populateFormatMenu(JMenu menu, BasicGraphEditor editor)
615 	{
616 		JMenu submenu = (JMenu) menu.add(new JMenu(mxResources
617 				.get("background")));
618 
619 		submenu.add(editor.bind(mxResources.get("fillcolor"), new ColorAction(
620 				"Fillcolor", mxConstants.STYLE_FILLCOLOR),
621 				"/com/mxgraph/examples/swing/images/fillcolor.gif"));
622 		submenu.add(editor.bind(mxResources.get("gradient"), new ColorAction(
623 				"Gradient", mxConstants.STYLE_GRADIENTCOLOR)));
624 
625 		submenu.addSeparator();
626 
627 		submenu.add(editor.bind(mxResources.get("image"),
628 				new PromptValueAction(mxConstants.STYLE_IMAGE, "Image")));
629 		submenu.add(editor.bind(mxResources.get("shadow"), new ToggleAction(
630 				mxConstants.STYLE_SHADOW)));
631 
632 		submenu.addSeparator();
633 
634 		submenu.add(editor.bind(mxResources.get("opacity"),
635 				new PromptValueAction(mxConstants.STYLE_OPACITY,
636 						"Opacity (0-100)")));
637 
638 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("label")));
639 
640 		submenu.add(editor.bind(mxResources.get("fontcolor"), new ColorAction(
641 				"Fontcolor", mxConstants.STYLE_FONTCOLOR),
642 				"/com/mxgraph/examples/swing/images/fontcolor.gif"));
643 
644 		submenu.addSeparator();
645 
646 		submenu.add(editor.bind(mxResources.get("labelFill"), new ColorAction(
647 				"Label Fill", mxConstants.STYLE_LABEL_BACKGROUNDCOLOR)));
648 		submenu.add(editor.bind(mxResources.get("labelBorder"),
649 				new ColorAction("Label Border",
650 						mxConstants.STYLE_LABEL_BORDERCOLOR)));
651 
652 		submenu.addSeparator();
653 
654 		submenu.add(editor.bind(mxResources.get("rotateLabel"),
655 				new ToggleAction(mxConstants.STYLE_HORIZONTAL, true)));
656 
657 		submenu.add(editor.bind(mxResources.get("textOpacity"),
658 				new PromptValueAction(mxConstants.STYLE_TEXT_OPACITY,
659 						"Opacity (0-100)")));
660 
661 		submenu.addSeparator();
662 
663 		JMenu subsubmenu = (JMenu) submenu.add(new JMenu(mxResources
664 				.get("position")));
665 
666 		subsubmenu.add(editor.bind(mxResources.get("top"),
667 				new SetLabelPositionAction(mxConstants.ALIGN_TOP,
668 						mxConstants.ALIGN_BOTTOM)));
669 		subsubmenu.add(editor.bind(mxResources.get("middle"),
670 				new SetLabelPositionAction(mxConstants.ALIGN_MIDDLE,
671 						mxConstants.ALIGN_MIDDLE)));
672 		subsubmenu.add(editor.bind(mxResources.get("bottom"),
673 				new SetLabelPositionAction(mxConstants.ALIGN_BOTTOM,
674 						mxConstants.ALIGN_TOP)));
675 
676 		subsubmenu.addSeparator();
677 
678 		subsubmenu.add(editor.bind(mxResources.get("left"),
679 				new SetLabelPositionAction(mxConstants.ALIGN_LEFT,
680 						mxConstants.ALIGN_RIGHT)));
681 		subsubmenu.add(editor.bind(mxResources.get("center"),
682 				new SetLabelPositionAction(mxConstants.ALIGN_CENTER,
683 						mxConstants.ALIGN_CENTER)));
684 		subsubmenu.add(editor.bind(mxResources.get("right"),
685 				new SetLabelPositionAction(mxConstants.ALIGN_RIGHT,
686 						mxConstants.ALIGN_LEFT)));
687 
688 		submenu.addSeparator();
689 
690 		submenu.add(editor.bind(mxResources.get("wordWrap"),
691 				new KeyValueAction(mxConstants.STYLE_WHITE_SPACE, "wrap")));
692 		submenu.add(editor.bind(mxResources.get("noWordWrap"),
693 				new KeyValueAction(mxConstants.STYLE_WHITE_SPACE, null)));
694 
695 		submenu.addSeparator();
696 
697 		submenu.add(editor.bind(mxResources.get("hide"), new ToggleAction(
698 				mxConstants.STYLE_NOLABEL)));
699 
700 		menu.addSeparator();
701 
702 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("line")));
703 
704 		submenu.add(editor.bind(mxResources.get("linecolor"), new ColorAction(
705 				"Linecolor", mxConstants.STYLE_STROKECOLOR),
706 				"/com/mxgraph/examples/swing/images/linecolor.gif"));
707 
708 		submenu.addSeparator();
709 
710 		submenu.add(editor.bind(mxResources.get("orthogonal"), new ToggleAction(
711 				mxConstants.STYLE_ORTHOGONAL)));
712 		submenu.add(editor.bind(mxResources.get("dashed"), new ToggleAction(
713 				mxConstants.STYLE_DASHED)));
714 
715 		submenu.addSeparator();
716 
717 		submenu.add(editor.bind(mxResources.get("linewidth"),
718 				new PromptValueAction(mxConstants.STYLE_STROKEWIDTH,
719 						"Linewidth")));
720 
721 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("connector")));
722 
723 		submenu.add(editor.bind(mxResources.get("straight"),
724 				new SetStyleAction("straight"),
725 				"/com/mxgraph/examples/swing/images/straight.gif"));
726 
727 		submenu.add(editor.bind(mxResources.get("horizontal"),
728 				new SetStyleAction(""),
729 				"/com/mxgraph/examples/swing/images/connect.gif"));
730 		submenu.add(editor.bind(mxResources.get("vertical"),
731 				new SetStyleAction("vertical"),
732 				"/com/mxgraph/examples/swing/images/vertical.gif"));
733 
734 		submenu.addSeparator();
735 
736 		submenu.add(editor.bind(mxResources.get("entityRelation"),
737 				new SetStyleAction("edgeStyle=mxEdgeStyle.EntityRelation"),
738 				"/com/mxgraph/examples/swing/images/entity.gif"));
739 		submenu.add(editor.bind(mxResources.get("arrow"), new SetStyleAction(
740 				"arrow"), "/com/mxgraph/examples/swing/images/arrow.gif"));
741 
742 		submenu.addSeparator();
743 
744 		submenu.add(editor.bind(mxResources.get("plain"), new ToggleAction(
745 				mxConstants.STYLE_NOEDGESTYLE)));
746 
747 		menu.addSeparator();
748 
749 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("linestart")));
750 
751 		submenu.add(editor.bind(mxResources.get("open"), new KeyValueAction(
752 				mxConstants.STYLE_STARTARROW, mxConstants.ARROW_OPEN),
753 				"/com/mxgraph/examples/swing/images/open_start.gif"));
754 		submenu.add(editor.bind(mxResources.get("classic"), new KeyValueAction(
755 				mxConstants.STYLE_STARTARROW, mxConstants.ARROW_CLASSIC),
756 				"/com/mxgraph/examples/swing/images/classic_start.gif"));
757 		submenu.add(editor.bind(mxResources.get("block"), new KeyValueAction(
758 				mxConstants.STYLE_STARTARROW, mxConstants.ARROW_BLOCK),
759 				"/com/mxgraph/examples/swing/images/block_start.gif"));
760 
761 		submenu.addSeparator();
762 
763 		submenu.add(editor.bind(mxResources.get("diamond"), new KeyValueAction(
764 				mxConstants.STYLE_STARTARROW, mxConstants.ARROW_DIAMOND),
765 				"/com/mxgraph/examples/swing/images/diamond_start.gif"));
766 		submenu.add(editor.bind(mxResources.get("oval"), new KeyValueAction(
767 				mxConstants.STYLE_STARTARROW, mxConstants.ARROW_OVAL),
768 				"/com/mxgraph/examples/swing/images/oval_start.gif"));
769 
770 		submenu.addSeparator();
771 
772 		submenu.add(editor.bind(mxResources.get("none"), new KeyValueAction(
773 				mxConstants.STYLE_STARTARROW, mxConstants.NONE)));
774 		submenu.add(editor.bind(mxResources.get("size"), new PromptValueAction(
775 				mxConstants.STYLE_STARTSIZE, "Linestart Size")));
776 
777 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("lineend")));
778 
779 		submenu.add(editor.bind(mxResources.get("open"), new KeyValueAction(
780 				mxConstants.STYLE_ENDARROW, mxConstants.ARROW_OPEN),
781 				"/com/mxgraph/examples/swing/images/open_end.gif"));
782 		submenu.add(editor.bind(mxResources.get("classic"), new KeyValueAction(
783 				mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC),
784 				"/com/mxgraph/examples/swing/images/classic_end.gif"));
785 		submenu.add(editor.bind(mxResources.get("block"), new KeyValueAction(
786 				mxConstants.STYLE_ENDARROW, mxConstants.ARROW_BLOCK),
787 				"/com/mxgraph/examples/swing/images/block_end.gif"));
788 
789 		submenu.addSeparator();
790 
791 		submenu.add(editor.bind(mxResources.get("diamond"), new KeyValueAction(
792 				mxConstants.STYLE_ENDARROW, mxConstants.ARROW_DIAMOND),
793 				"/com/mxgraph/examples/swing/images/diamond_end.gif"));
794 		submenu.add(editor.bind(mxResources.get("oval"), new KeyValueAction(
795 				mxConstants.STYLE_ENDARROW, mxConstants.ARROW_OVAL),
796 				"/com/mxgraph/examples/swing/images/oval_end.gif"));
797 
798 		submenu.addSeparator();
799 
800 		submenu.add(editor.bind(mxResources.get("none"), new KeyValueAction(
801 				mxConstants.STYLE_ENDARROW, mxConstants.NONE)));
802 		submenu.add(editor.bind(mxResources.get("size"), new PromptValueAction(
803 				mxConstants.STYLE_ENDSIZE, "Linestart Size")));
804 
805 		menu.addSeparator();
806 
807 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("alignment")));
808 
809 		submenu.add(editor.bind(mxResources.get("left"), new KeyValueAction(
810 				mxConstants.STYLE_ALIGN, mxConstants.ALIGN_LEFT),
811 				"/com/mxgraph/examples/swing/images/left.gif"));
812 		submenu.add(editor.bind(mxResources.get("center"), new KeyValueAction(
813 				mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER),
814 				"/com/mxgraph/examples/swing/images/center.gif"));
815 		submenu.add(editor.bind(mxResources.get("right"), new KeyValueAction(
816 				mxConstants.STYLE_ALIGN, mxConstants.ALIGN_RIGHT),
817 				"/com/mxgraph/examples/swing/images/right.gif"));
818 
819 		submenu.addSeparator();
820 
821 		submenu.add(editor.bind(mxResources.get("top"), new KeyValueAction(
822 				mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP),
823 				"/com/mxgraph/examples/swing/images/top.gif"));
824 		submenu.add(editor.bind(mxResources.get("middle"), new KeyValueAction(
825 				mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE),
826 				"/com/mxgraph/examples/swing/images/middle.gif"));
827 		submenu.add(editor.bind(mxResources.get("bottom"), new KeyValueAction(
828 				mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_BOTTOM),
829 				"/com/mxgraph/examples/swing/images/bottom.gif"));
830 
831 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("spacing")));
832 
833 		submenu.add(editor.bind(mxResources.get("top"), new PromptValueAction(
834 				mxConstants.STYLE_SPACING_TOP, "Top Spacing")));
835 		submenu.add(editor.bind(mxResources.get("right"),
836 				new PromptValueAction(mxConstants.STYLE_SPACING_RIGHT,
837 						"Right Spacing")));
838 		submenu.add(editor.bind(mxResources.get("bottom"),
839 				new PromptValueAction(mxConstants.STYLE_SPACING_BOTTOM,
840 						"Bottom Spacing")));
841 		submenu.add(editor.bind(mxResources.get("left"), new PromptValueAction(
842 				mxConstants.STYLE_SPACING_LEFT, "Left Spacing")));
843 
844 		submenu.addSeparator();
845 
846 		submenu.add(editor.bind(mxResources.get("global"),
847 				new PromptValueAction(mxConstants.STYLE_SPACING, "Spacing")));
848 
849 		submenu.addSeparator();
850 
851 		submenu.add(editor.bind(mxResources.get("sourceSpacing"),
852 				new PromptValueAction(
853 						mxConstants.STYLE_SOURCE_PERIMETER_SPACING, mxResources
854 								.get("sourceSpacing"))));
855 		submenu.add(editor.bind(mxResources.get("targetSpacing"),
856 				new PromptValueAction(
857 						mxConstants.STYLE_TARGET_PERIMETER_SPACING, mxResources
858 								.get("targetSpacing"))));
859 
860 		submenu.addSeparator();
861 
862 		submenu.add(editor.bind(mxResources.get("perimeter"),
863 				new PromptValueAction(mxConstants.STYLE_PERIMETER_SPACING,
864 						"Perimeter Spacing")));
865 
866 		submenu = (JMenu) menu.add(new JMenu(mxResources.get("direction")));
867 
868 		submenu.add(editor.bind(mxResources.get("north"), new KeyValueAction(
869 				mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_NORTH)));
870 		submenu.add(editor.bind(mxResources.get("east"), new KeyValueAction(
871 				mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST)));
872 		submenu.add(editor.bind(mxResources.get("south"), new KeyValueAction(
873 				mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_SOUTH)));
874 		submenu.add(editor.bind(mxResources.get("west"), new KeyValueAction(
875 				mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_WEST)));
876 
877 		submenu.addSeparator();
878 
879 		submenu.add(editor.bind(mxResources.get("rotation"),
880 				new PromptValueAction(mxConstants.STYLE_ROTATION,
881 						"Rotation (0-360)")));
882 
883 		menu.addSeparator();
884 
885 		menu.add(editor.bind(mxResources.get("rounded"), new ToggleAction(
886 				mxConstants.STYLE_ROUNDED)));
887 
888 		menu.add(editor.bind(mxResources.get("style"), new StyleAction()));
889 	}
890 
891 }
892