1 /* 2 * $Id: JGraphLayoutExampleMenuBar.java,v 1.1 2009/09/25 15:17:49 david Exp $ 3 * Copyright (c) 2001-2005, Gaudenz Alder 4 * 5 * All rights reserved. 6 * 7 * This file is licensed under the JGraph software license, a copy of which 8 * will have been provided to you in the file LICENSE at the root of your 9 * installation directory. If you are unable to locate this file please 10 * contact JGraph sales for another copy. 11 */ 12 package com.jgraph.layout; 13 14 import java.awt.event.ActionEvent; 15 16 import javax.swing.AbstractAction; 17 import javax.swing.Action; 18 import javax.swing.ButtonGroup; 19 import javax.swing.JCheckBoxMenuItem; 20 import javax.swing.JMenu; 21 22 import com.jgraph.example.GraphEdXMenuBar; 23 import com.jgraph.example.JGraphGraphFactory; 24 25 /** 26 * @author Administrator 27 * 28 * TODO To change the template for this generated type comment go to Window - 29 * Preferences - Java - Code Style - Code Templates 30 */ 31 public class JGraphLayoutExampleMenuBar extends GraphEdXMenuBar { 32 33 /** 34 * JGraph Factory instance for random new graphs 35 */ 36 protected JGraphGraphFactory graphFactory = null; 37 JGraphLayoutExampleMenuBar(final JGraphLayoutExample app, JGraphGraphFactory factory)38 public JGraphLayoutExampleMenuBar(final JGraphLayoutExample app, 39 JGraphGraphFactory factory) { 40 super(app, factory); 41 graphFactory = factory; 42 43 // Layout menu 44 JMenu layoutMenu = new JMenu("Layout"); 45 ButtonGroup layoutGroup = new ButtonGroup(); 46 Action[] layoutActions = app.layoutActions; 47 for (int i = 0; i < layoutActions.length; i++) { 48 layoutMenu.add(createRadioMenuItem(layoutGroup, layoutActions[i])); 49 } 50 layoutMenu.getItem(0).setSelected(true); 51 add(layoutMenu); 52 layoutMenu.setEnabled(true); 53 54 // Move selected cells switch 55 JMenu optionsMenu = new JMenu("Options"); 56 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new AbstractAction( 57 "Allow to move selected cells") { 58 public void actionPerformed(ActionEvent e) { 59 app.layoutCache.layoutMoveSelection = ((JCheckBoxMenuItem) e 60 .getSource()).isSelected(); 61 } 62 }); 63 item.setSelected(app.layoutCache.layoutMoveSelection); 64 optionsMenu.add(item); 65 item = new JCheckBoxMenuItem(new AbstractAction( 66 "Ignore cells inside groups") { 67 public void actionPerformed(ActionEvent e) { 68 app.layoutCache.ignoreChildren = ((JCheckBoxMenuItem) e 69 .getSource()).isSelected(); 70 } 71 }); 72 item.setSelected(app.layoutCache.ignoreChildren); 73 optionsMenu.add(item); 74 item = new JCheckBoxMenuItem(new AbstractAction("Ignore hidden cells") { 75 public void actionPerformed(ActionEvent e) { 76 app.layoutCache.ignoreHidden = ((JCheckBoxMenuItem) e 77 .getSource()).isSelected(); 78 } 79 }); 80 item.setSelected(app.layoutCache.ignoreHidden); 81 optionsMenu.add(item); 82 item = new JCheckBoxMenuItem(new AbstractAction( 83 "Ignore unconnected cells") { 84 public void actionPerformed(ActionEvent e) { 85 app.layoutCache.ignoreUnconnected = ((JCheckBoxMenuItem) e 86 .getSource()).isSelected(); 87 } 88 }); 89 item.setSelected(app.layoutCache.ignoreUnconnected); 90 optionsMenu.add(item); 91 item = new JCheckBoxMenuItem(new AbstractAction("Directed layout") { 92 public void actionPerformed(ActionEvent e) { 93 app.layoutCache.layoutDirectedGraph = ((JCheckBoxMenuItem) e 94 .getSource()).isSelected(); 95 } 96 }); 97 item.setSelected(app.layoutCache.layoutDirectedGraph); 98 optionsMenu.add(item); 99 optionsMenu.addSeparator(); 100 item = new JCheckBoxMenuItem(new AbstractAction("Flush to origin") { 101 public void actionPerformed(ActionEvent e) { 102 app.layoutCache.layoutFlushOrigin = ((JCheckBoxMenuItem) e 103 .getSource()).isSelected(); 104 } 105 }); 106 item.setSelected(app.layoutCache.layoutFlushOrigin); 107 optionsMenu.add(item); 108 item = new JCheckBoxMenuItem(new AbstractAction("Ignore grid") { 109 public void actionPerformed(ActionEvent e) { 110 app.layoutCache.layoutIgnoreGrid = ((JCheckBoxMenuItem) e 111 .getSource()).isSelected(); 112 } 113 }); 114 item.setSelected(app.layoutCache.layoutIgnoreGrid); 115 optionsMenu.add(item); 116 optionsMenu.addSeparator(); 117 item = new JCheckBoxMenuItem(new AbstractAction("Morphing") { 118 public void actionPerformed(ActionEvent e) { 119 app.layoutCache.morphing = ((JCheckBoxMenuItem) e.getSource()) 120 .isSelected(); 121 } 122 }); 123 item.setSelected(app.layoutCache.morphing); 124 optionsMenu.add(item); 125 126 add(optionsMenu); 127 } 128 } 129