001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.plugins.main.core.actions; 005 006 import graphlab.graph.graph.GraphModel; 007 import graphlab.graph.ui.GTabbedGraphPane; 008 import graphlab.platform.core.AbstractAction; 009 import graphlab.platform.core.BlackBoard; 010 import graphlab.ui.UIUtils; 011 012 import javax.swing.*; 013 import java.awt.*; 014 015 /** 016 * @author azin azadi 017 */ 018 public class AddTab extends AbstractAction { 019 020 021 /** 022 * constructor 023 * 024 * @param bb the blackboard of the action 025 */ 026 public AddTab(BlackBoard bb) { 027 super(bb); 028 listen4Event(UIUtils.getUIEventKey("add tab")); 029 } 030 031 public void performAction(String eventName, Object value) { 032 addTab(blackboard); 033 } 034 035 /** 036 * creates a graph ans add it as a tab to the current editing graph window 037 */ 038 public static void addTab(BlackBoard blackboard) { 039 GTabbedGraphPane gtgp = blackboard.getData(GTabbedGraphPane.NAME); 040 int a = JOptionPane.showOptionDialog(null, "Graph Direction :", "New Graph", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[]{"Directed", "Undirected"}, "Undirected"); 041 // System.out.println("a = " + a); 042 GraphModel g = new GraphModel(a == 0); 043 gtgp.addGraph(g); 044 } 045 046 /** 047 * creates a graph ans add it as a tab to the current editing graph window 048 */ 049 public static void addTabNoGUI(boolean isdirected , BlackBoard blackboard) { 050 GTabbedGraphPane gtgp = blackboard.getData(GTabbedGraphPane.NAME); 051 GraphModel g = new GraphModel(isdirected); 052 gtgp.addGraph(g); 053 } 054 055 056 /** 057 * displays the givven graph in GraphLab 058 */ 059 public static void displayGraph(GraphModel g, BlackBoard blackBoard) { 060 GTabbedGraphPane gtgp = blackBoard.getData(GTabbedGraphPane.NAME); 061 gtgp.addGraph(g); 062 } 063 064 }