1package com.mxgraph.examples.swing.editor; 2 3import java.awt.event.ActionEvent; 4import java.awt.event.ActionListener; 5 6import javax.swing.AbstractAction; 7import javax.swing.JMenu; 8import javax.swing.JMenuBar; 9import javax.swing.JMenuItem; 10import javax.swing.SwingUtilities; 11import javax.swing.TransferHandler; 12import javax.swing.UIManager; 13 14import com.mxgraph.examples.swing.editor.EditorActions.AlignCellsAction; 15import com.mxgraph.examples.swing.editor.EditorActions.AutosizeAction; 16import com.mxgraph.examples.swing.editor.EditorActions.BackgroundAction; 17import com.mxgraph.examples.swing.editor.EditorActions.BackgroundImageAction; 18import com.mxgraph.examples.swing.editor.EditorActions.ColorAction; 19import com.mxgraph.examples.swing.editor.EditorActions.ExitAction; 20import com.mxgraph.examples.swing.editor.EditorActions.GridColorAction; 21import com.mxgraph.examples.swing.editor.EditorActions.GridStyleAction; 22import com.mxgraph.examples.swing.editor.EditorActions.HistoryAction; 23import com.mxgraph.examples.swing.editor.EditorActions.KeyValueAction; 24import com.mxgraph.examples.swing.editor.EditorActions.NewAction; 25import com.mxgraph.examples.swing.editor.EditorActions.OpenAction; 26import com.mxgraph.examples.swing.editor.EditorActions.PageBackgroundAction; 27import com.mxgraph.examples.swing.editor.EditorActions.PageSetupAction; 28import com.mxgraph.examples.swing.editor.EditorActions.PrintAction; 29import com.mxgraph.examples.swing.editor.EditorActions.PromptPropertyAction; 30import com.mxgraph.examples.swing.editor.EditorActions.PromptValueAction; 31import com.mxgraph.examples.swing.editor.EditorActions.SaveAction; 32import com.mxgraph.examples.swing.editor.EditorActions.ScaleAction; 33import com.mxgraph.examples.swing.editor.EditorActions.SelectShortestPathAction; 34import com.mxgraph.examples.swing.editor.EditorActions.SelectSpanningTreeAction; 35import com.mxgraph.examples.swing.editor.EditorActions.SetLabelPositionAction; 36import com.mxgraph.examples.swing.editor.EditorActions.SetStyleAction; 37import com.mxgraph.examples.swing.editor.EditorActions.StyleAction; 38import com.mxgraph.examples.swing.editor.EditorActions.StylesheetAction; 39import com.mxgraph.examples.swing.editor.EditorActions.ToggleAction; 40import com.mxgraph.examples.swing.editor.EditorActions.ToggleConnectModeAction; 41import com.mxgraph.examples.swing.editor.EditorActions.ToggleCreateTargetItem; 42import com.mxgraph.examples.swing.editor.EditorActions.ToggleDirtyAction; 43import com.mxgraph.examples.swing.editor.EditorActions.ToggleGridItem; 44import com.mxgraph.examples.swing.editor.EditorActions.ToggleOutlineItem; 45import com.mxgraph.examples.swing.editor.EditorActions.TogglePropertyItem; 46import com.mxgraph.examples.swing.editor.EditorActions.ToggleRulersItem; 47import com.mxgraph.examples.swing.editor.EditorActions.WarningAction; 48import com.mxgraph.examples.swing.editor.EditorActions.ZoomPolicyAction; 49import com.mxgraph.swing.mxGraphComponent; 50import com.mxgraph.swing.util.mxGraphActions; 51import com.mxgraph.util.mxConstants; 52import com.mxgraph.util.mxPoint; 53import com.mxgraph.util.mxResources; 54import com.mxgraph.view.mxGraph; 55 56public class EditorMenuBar extends JMenuBar 57{ 58 59 /** 60 * 61 */ 62 private static final long serialVersionUID = 4060203894740766714L; 63 64 @SuppressWarnings("serial") 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")); 303 submenu.add(editor.graphLayout("horizontalHierarchical")); 304 305 submenu.addSeparator(); 306 307 submenu.add(editor.graphLayout("verticalPartition")); 308 submenu.add(editor.graphLayout("horizontalPartition")); 309 310 submenu.addSeparator(); 311 312 submenu.add(editor.graphLayout("verticalStack")); 313 submenu.add(editor.graphLayout("horizontalStack")); 314 315 submenu.addSeparator(); 316 317 submenu.add(editor.graphLayout("verticalTree")); 318 submenu.add(editor.graphLayout("horizontalTree")); 319 320 submenu.addSeparator(); 321 322 submenu.add(editor.graphLayout("placeEdgeLabels")); 323 submenu.add(editor.graphLayout("parallelEdges")); 324 325 submenu.addSeparator(); 326 327 submenu.add(editor.graphLayout("organicLayout")); 328 submenu.add(editor.graphLayout("circleLayout")); 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 */ 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 */ 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("hide"), new ToggleAction( 691 mxConstants.STYLE_NOLABEL))); 692 693 menu.addSeparator(); 694 695 submenu = (JMenu) menu.add(new JMenu(mxResources.get("line"))); 696 697 submenu.add(editor.bind(mxResources.get("linecolor"), new ColorAction( 698 "Linecolor", mxConstants.STYLE_STROKECOLOR), 699 "/com/mxgraph/examples/swing/images/linecolor.gif")); 700 701 submenu.addSeparator(); 702 703 submenu.add(editor.bind(mxResources.get("dashed"), new ToggleAction( 704 mxConstants.STYLE_DASHED))); 705 submenu.add(editor.bind(mxResources.get("linewidth"), 706 new PromptValueAction(mxConstants.STYLE_STROKEWIDTH, 707 "Linewidth"))); 708 709 submenu = (JMenu) menu.add(new JMenu(mxResources.get("connector"))); 710 711 submenu.add(editor.bind(mxResources.get("straight"), 712 new SetStyleAction("straight"), 713 "/com/mxgraph/examples/swing/images/straight.gif")); 714 715 submenu.add(editor.bind(mxResources.get("horizontal"), 716 new SetStyleAction(""), 717 "/com/mxgraph/examples/swing/images/connect.gif")); 718 submenu.add(editor.bind(mxResources.get("vertical"), 719 new SetStyleAction("vertical"), 720 "/com/mxgraph/examples/swing/images/vertical.gif")); 721 722 submenu.addSeparator(); 723 724 submenu.add(editor.bind(mxResources.get("entityRelation"), 725 new SetStyleAction("edgeStyle=mxEdgeStyle.EntityRelation"), 726 "/com/mxgraph/examples/swing/images/entity.gif")); 727 submenu.add(editor.bind(mxResources.get("arrow"), new SetStyleAction( 728 "arrow"), "/com/mxgraph/examples/swing/images/arrow.gif")); 729 730 submenu.addSeparator(); 731 732 submenu.add(editor.bind(mxResources.get("plain"), new ToggleAction( 733 mxConstants.STYLE_NOEDGESTYLE))); 734 735 menu.addSeparator(); 736 737 submenu = (JMenu) menu.add(new JMenu(mxResources.get("linestart"))); 738 739 submenu.add(editor.bind(mxResources.get("open"), new KeyValueAction( 740 mxConstants.STYLE_STARTARROW, mxConstants.ARROW_OPEN), 741 "/com/mxgraph/examples/swing/images/open_start.gif")); 742 submenu.add(editor.bind(mxResources.get("classic"), new KeyValueAction( 743 mxConstants.STYLE_STARTARROW, mxConstants.ARROW_CLASSIC), 744 "/com/mxgraph/examples/swing/images/classic_start.gif")); 745 submenu.add(editor.bind(mxResources.get("block"), new KeyValueAction( 746 mxConstants.STYLE_STARTARROW, mxConstants.ARROW_BLOCK), 747 "/com/mxgraph/examples/swing/images/block_start.gif")); 748 749 submenu.addSeparator(); 750 751 submenu.add(editor.bind(mxResources.get("diamond"), new KeyValueAction( 752 mxConstants.STYLE_STARTARROW, mxConstants.ARROW_DIAMOND), 753 "/com/mxgraph/examples/swing/images/diamond_start.gif")); 754 submenu.add(editor.bind(mxResources.get("oval"), new KeyValueAction( 755 mxConstants.STYLE_STARTARROW, mxConstants.ARROW_OVAL), 756 "/com/mxgraph/examples/swing/images/oval_start.gif")); 757 758 submenu.addSeparator(); 759 760 submenu.add(editor.bind(mxResources.get("none"), new KeyValueAction( 761 mxConstants.STYLE_STARTARROW, mxConstants.NONE))); 762 submenu.add(editor.bind(mxResources.get("size"), new PromptValueAction( 763 mxConstants.STYLE_STARTSIZE, "Linestart Size"))); 764 765 submenu = (JMenu) menu.add(new JMenu(mxResources.get("lineend"))); 766 767 submenu.add(editor.bind(mxResources.get("open"), new KeyValueAction( 768 mxConstants.STYLE_ENDARROW, mxConstants.ARROW_OPEN), 769 "/com/mxgraph/examples/swing/images/open_end.gif")); 770 submenu.add(editor.bind(mxResources.get("classic"), new KeyValueAction( 771 mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC), 772 "/com/mxgraph/examples/swing/images/classic_end.gif")); 773 submenu.add(editor.bind(mxResources.get("block"), new KeyValueAction( 774 mxConstants.STYLE_ENDARROW, mxConstants.ARROW_BLOCK), 775 "/com/mxgraph/examples/swing/images/block_end.gif")); 776 777 submenu.addSeparator(); 778 779 submenu.add(editor.bind(mxResources.get("diamond"), new KeyValueAction( 780 mxConstants.STYLE_ENDARROW, mxConstants.ARROW_DIAMOND), 781 "/com/mxgraph/examples/swing/images/diamond_end.gif")); 782 submenu.add(editor.bind(mxResources.get("oval"), new KeyValueAction( 783 mxConstants.STYLE_ENDARROW, mxConstants.ARROW_OVAL), 784 "/com/mxgraph/examples/swing/images/oval_end.gif")); 785 786 submenu.addSeparator(); 787 788 submenu.add(editor.bind(mxResources.get("none"), new KeyValueAction( 789 mxConstants.STYLE_ENDARROW, mxConstants.NONE))); 790 submenu.add(editor.bind(mxResources.get("size"), new PromptValueAction( 791 mxConstants.STYLE_ENDSIZE, "Linestart Size"))); 792 793 menu.addSeparator(); 794 795 submenu = (JMenu) menu.add(new JMenu(mxResources.get("alignment"))); 796 797 submenu.add(editor.bind(mxResources.get("left"), new KeyValueAction( 798 mxConstants.STYLE_ALIGN, mxConstants.ALIGN_LEFT), 799 "/com/mxgraph/examples/swing/images/left.gif")); 800 submenu.add(editor.bind(mxResources.get("center"), new KeyValueAction( 801 mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER), 802 "/com/mxgraph/examples/swing/images/center.gif")); 803 submenu.add(editor.bind(mxResources.get("right"), new KeyValueAction( 804 mxConstants.STYLE_ALIGN, mxConstants.ALIGN_RIGHT), 805 "/com/mxgraph/examples/swing/images/right.gif")); 806 807 submenu.addSeparator(); 808 809 submenu.add(editor.bind(mxResources.get("top"), new KeyValueAction( 810 mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP), 811 "/com/mxgraph/examples/swing/images/top.gif")); 812 submenu.add(editor.bind(mxResources.get("middle"), new KeyValueAction( 813 mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE), 814 "/com/mxgraph/examples/swing/images/middle.gif")); 815 submenu.add(editor.bind(mxResources.get("bottom"), new KeyValueAction( 816 mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_BOTTOM), 817 "/com/mxgraph/examples/swing/images/bottom.gif")); 818 819 submenu = (JMenu) menu.add(new JMenu(mxResources.get("spacing"))); 820 821 submenu.add(editor.bind(mxResources.get("top"), new PromptValueAction( 822 mxConstants.STYLE_SPACING_TOP, "Top Spacing"))); 823 submenu.add(editor.bind(mxResources.get("right"), 824 new PromptValueAction(mxConstants.STYLE_SPACING_RIGHT, 825 "Right Spacing"))); 826 submenu.add(editor.bind(mxResources.get("bottom"), 827 new PromptValueAction(mxConstants.STYLE_SPACING_BOTTOM, 828 "Bottom Spacing"))); 829 submenu.add(editor.bind(mxResources.get("left"), new PromptValueAction( 830 mxConstants.STYLE_SPACING_LEFT, "Left Spacing"))); 831 832 submenu.addSeparator(); 833 834 submenu.add(editor.bind(mxResources.get("global"), 835 new PromptValueAction(mxConstants.STYLE_SPACING, "Spacing"))); 836 837 submenu.addSeparator(); 838 839 submenu.add(editor.bind(mxResources.get("sourceSpacing"), 840 new PromptValueAction( 841 mxConstants.STYLE_SOURCE_PERIMETER_SPACING, mxResources 842 .get("sourceSpacing")))); 843 submenu.add(editor.bind(mxResources.get("targetSpacing"), 844 new PromptValueAction( 845 mxConstants.STYLE_TARGET_PERIMETER_SPACING, mxResources 846 .get("targetSpacing")))); 847 848 submenu.addSeparator(); 849 850 submenu.add(editor.bind(mxResources.get("perimeter"), 851 new PromptValueAction(mxConstants.STYLE_PERIMETER_SPACING, 852 "Perimeter Spacing"))); 853 854 submenu = (JMenu) menu.add(new JMenu(mxResources.get("direction"))); 855 856 submenu.add(editor.bind(mxResources.get("north"), new KeyValueAction( 857 mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_NORTH))); 858 submenu.add(editor.bind(mxResources.get("east"), new KeyValueAction( 859 mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST))); 860 submenu.add(editor.bind(mxResources.get("south"), new KeyValueAction( 861 mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_SOUTH))); 862 submenu.add(editor.bind(mxResources.get("west"), new KeyValueAction( 863 mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_WEST))); 864 865 submenu.addSeparator(); 866 867 submenu.add(editor.bind(mxResources.get("rotation"), 868 new PromptValueAction(mxConstants.STYLE_ROTATION, 869 "Rotation (0-360)"))); 870 871 menu.addSeparator(); 872 873 menu.add(editor.bind(mxResources.get("rounded"), new ToggleAction( 874 mxConstants.STYLE_ROUNDED))); 875 876 menu.add(editor.bind(mxResources.get("style"), new StyleAction())); 877 } 878 879} 880