001 /* 002 * Copyright (C) 2008-2010 by Holger Arndt 003 * 004 * This file is part of the Universal Java Matrix Package (UJMP). 005 * See the NOTICE file distributed with this work for additional 006 * information regarding copyright ownership and licensing. 007 * 008 * UJMP is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation; either version 2 011 * of the License, or (at your option) any later version. 012 * 013 * UJMP is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with UJMP; if not, write to the 020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 021 * Boston, MA 02110-1301 USA 022 */ 023 024 package org.ujmp.jung; 025 026 import java.awt.event.ActionEvent; 027 028 import javax.swing.AbstractAction; 029 import javax.swing.Action; 030 import javax.swing.JComponent; 031 import javax.swing.JMenu; 032 import javax.swing.JPopupMenu; 033 import javax.swing.JSeparator; 034 import javax.swing.UIManager; 035 036 import org.ujmp.gui.actions.PanelActions; 037 import org.ujmp.gui.io.ExportJPEG; 038 import org.ujmp.gui.io.ExportPDF; 039 import org.ujmp.gui.util.GraphicsExecutor; 040 041 public class JungGraphActions extends JPopupMenu { 042 043 private static final long serialVersionUID = -2307893165969916295L; 044 045 JungGraphPanel jungGraphPanel = null; 046 047 public JungGraphActions(JungGraphPanel m) { 048 this.jungGraphPanel = m; 049 050 JMenu panelMenu = new JMenu("This Panel"); 051 for (JComponent c : new PanelActions(m, null)) { 052 panelMenu.add(c); 053 } 054 this.add(panelMenu); 055 056 JMenu layoutMenu = new JMenu("Layout"); 057 layoutMenu.add(frLayoutAction); 058 layoutMenu.add(kkLayoutAction); 059 layoutMenu.add(iSomLayoutAction); 060 layoutMenu.add(springLayoutAction); 061 layoutMenu.add(circleLayoutAction); 062 this.add(layoutMenu); 063 this.add(toggleEdgesAction); 064 this.add(toggleEdgeLabelsAction); 065 this.add(toggleVertexLabelsAction); 066 this.add(new JSeparator()); 067 this.add(exportToJpgAction); 068 this.add(exportToPdfAction); 069 this.add(new JSeparator()); 070 this.add(refreshAction); 071 } 072 073 public final Action frLayoutAction = new AbstractAction("FR Layout") { 074 private static final long serialVersionUID = 3149916178777567323L; 075 076 public void actionPerformed(ActionEvent e) { 077 jungGraphPanel.switchLayout(JungGraphPanel.GraphLayout.FRLayout); 078 } 079 }; 080 081 public final Action iSomLayoutAction = new AbstractAction("ISOM Layout") { 082 private static final long serialVersionUID = 1862486279803190687L; 083 084 public void actionPerformed(ActionEvent e) { 085 jungGraphPanel.switchLayout(JungGraphPanel.GraphLayout.ISOMLayout); 086 } 087 }; 088 089 public final Action kkLayoutAction = new AbstractAction("KK Layout") { 090 private static final long serialVersionUID = 8756219332341323478L; 091 092 public void actionPerformed(ActionEvent e) { 093 jungGraphPanel.switchLayout(JungGraphPanel.GraphLayout.KKLayout); 094 } 095 }; 096 097 public final Action springLayoutAction = new AbstractAction("Spring Layout") { 098 private static final long serialVersionUID = -9129746911116351142L; 099 100 public void actionPerformed(ActionEvent e) { 101 jungGraphPanel 102 .switchLayout(JungGraphPanel.GraphLayout.SpringLayout); 103 } 104 }; 105 106 public final Action circleLayoutAction = new AbstractAction("Circle Layout") { 107 private static final long serialVersionUID = -3030980988050670381L; 108 109 public void actionPerformed(ActionEvent e) { 110 jungGraphPanel 111 .switchLayout(JungGraphPanel.GraphLayout.CircleLayout); 112 } 113 }; 114 115 public final Action refreshAction = new AbstractAction("Refresh") { 116 private static final long serialVersionUID = -8057389215808050942L; 117 118 public void actionPerformed(ActionEvent e) { 119 GraphicsExecutor.scheduleUpdate(jungGraphPanel); 120 } 121 }; 122 123 public final Action exportToPdfAction = new AbstractAction( 124 "Export to PDF...", UIManager.getIcon("JDMP.icon.pdf")) { 125 private static final long serialVersionUID = -7413294854080175036L; 126 127 public void actionPerformed(ActionEvent e) { 128 jungGraphPanel.exportToPDF(ExportPDF.selectFile()); 129 } 130 }; 131 132 public final Action exportToJpgAction = new AbstractAction( 133 "Export to JPG...", UIManager.getIcon("JDMP.icon.image")) { 134 private static final long serialVersionUID = 2903870037000412488L; 135 136 public void actionPerformed(ActionEvent e) { 137 jungGraphPanel.exportToJPEG(ExportJPEG.selectFile()); 138 } 139 }; 140 141 public final Action toggleEdgesAction = new AbstractAction("Toggle Edges") { 142 private static final long serialVersionUID = -7632767332831157590L; 143 144 public void actionPerformed(ActionEvent e) { 145 jungGraphPanel.setShowEdges(!jungGraphPanel.isShowEdges()); 146 } 147 }; 148 149 public final Action toggleEdgeLabelsAction = new AbstractAction( 150 "Toggle Edge Labels") { 151 private static final long serialVersionUID = 5043606502712307760L; 152 153 public void actionPerformed(ActionEvent e) { 154 jungGraphPanel 155 .setShowEdgeLabels(!jungGraphPanel.isShowEdgeLabels()); 156 } 157 }; 158 159 public final Action toggleVertexLabelsAction = new AbstractAction( 160 "Toggle Vertex Labels") { 161 private static final long serialVersionUID = -8736147166116311565L; 162 163 public void actionPerformed(ActionEvent e) { 164 jungGraphPanel.setShowVertexLabels(!jungGraphPanel 165 .isShowVertexLabels()); 166 } 167 }; 168 169 }