1 package com.mxgraph.examples.swing.editor; 2 3 import javax.swing.JMenu; 4 import javax.swing.JPopupMenu; 5 import javax.swing.TransferHandler; 6 7 import com.mxgraph.examples.swing.editor.EditorActions.HistoryAction; 8 import com.mxgraph.swing.util.mxGraphActions; 9 import com.mxgraph.util.mxResources; 10 11 public class EditorPopupMenu extends JPopupMenu 12 { 13 14 /** 15 * 16 */ 17 private static final long serialVersionUID = -3132749140550242191L; 18 EditorPopupMenu(BasicGraphEditor editor)19 public EditorPopupMenu(BasicGraphEditor editor) 20 { 21 boolean selected = !editor.getGraphComponent().getGraph() 22 .isSelectionEmpty(); 23 24 add(editor.bind(mxResources.get("undo"), new HistoryAction(true), 25 "/com/mxgraph/examples/swing/images/undo.gif")); 26 27 addSeparator(); 28 29 add( 30 editor.bind(mxResources.get("cut"), TransferHandler 31 .getCutAction(), 32 "/com/mxgraph/examples/swing/images/cut.gif")) 33 .setEnabled(selected); 34 add( 35 editor.bind(mxResources.get("copy"), TransferHandler 36 .getCopyAction(), 37 "/com/mxgraph/examples/swing/images/copy.gif")) 38 .setEnabled(selected); 39 add(editor.bind(mxResources.get("paste"), TransferHandler 40 .getPasteAction(), 41 "/com/mxgraph/examples/swing/images/paste.gif")); 42 43 addSeparator(); 44 45 add( 46 editor.bind(mxResources.get("delete"), mxGraphActions 47 .getDeleteAction(), 48 "/com/mxgraph/examples/swing/images/delete.gif")) 49 .setEnabled(selected); 50 51 addSeparator(); 52 53 // Creates the format menu 54 JMenu menu = (JMenu) add(new JMenu(mxResources.get("format"))); 55 56 EditorMenuBar.populateFormatMenu(menu, editor); 57 58 // Creates the shape menu 59 menu = (JMenu) add(new JMenu(mxResources.get("shape"))); 60 61 EditorMenuBar.populateShapeMenu(menu, editor); 62 63 addSeparator(); 64 65 add( 66 editor.bind(mxResources.get("edit"), mxGraphActions 67 .getEditAction())).setEnabled(selected); 68 69 addSeparator(); 70 71 add(editor.bind(mxResources.get("selectVertices"), mxGraphActions 72 .getSelectVerticesAction())); 73 add(editor.bind(mxResources.get("selectEdges"), mxGraphActions 74 .getSelectEdgesAction())); 75 76 addSeparator(); 77 78 add(editor.bind(mxResources.get("selectAll"), mxGraphActions 79 .getSelectAllAction())); 80 } 81 82 } 83