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 005 package graphlab.plugins.main.preview; 006 007 import graphlab.graph.JGraph; 008 import graphlab.graph.graph.GraphModel; 009 import graphlab.platform.core.AbstractAction; 010 import graphlab.platform.core.BlackBoard; 011 import graphlab.plugins.main.saveload.Load; 012 import graphlab.ui.UI; 013 import graphlab.ui.UIUtils; 014 import org.xml.sax.SAXException; 015 016 import javax.swing.*; 017 import javax.xml.parsers.ParserConfigurationException; 018 import java.io.File; 019 import java.io.IOException; 020 021 /** 022 * @author azin azadi 023 024 */ 025 public class ShowPreview extends AbstractAction { 026 /** 027 * constructor 028 * 029 * @param bb the blackboard of the action 030 */ 031 public ShowPreview(BlackBoard bb) { 032 super(bb); 033 listen4Event(UIUtils.getUIEventKey("show preview")); 034 } 035 036 public void performAction(String eventName, Object value) { 037 String fileName = JOptionPane.showInputDialog(null, "Enter the file path to preview"); 038 show(fileName); 039 } 040 041 /** 042 * displayes a preview of the given file (as a GraphML file), the preview window will be a light! window which only a few plugins are loaded to build it 043 */ 044 public static void show(String fileName) { 045 BlackBoard b = new BlackBoard(); 046 loadPlugins(b); 047 GraphModel g = new GraphModel(); 048 try { 049 g = Load.loadGraphFromFile(new File(fileName)); 050 } catch (IOException e) { 051 e.printStackTrace(); 052 } catch (ParserConfigurationException e) { 053 e.printStackTrace(); 054 } catch (SAXException e) { 055 e.printStackTrace(); 056 } 057 JFrame f = new JFrame("preview"); 058 059 f.add(JGraph.getNewComponent(b)); 060 f.pack(); 061 f.setVisible(true); 062 } 063 064 private static void loadPlugins(BlackBoard b) { 065 UI ui = new UI(b, true); 066 try { 067 ui.loadXML("graphlab/plugins/graph/SampleUI.xml", null); 068 ui.addXML("graphlab/plugins/rightclick/config.xml", null); 069 ui.addXML("graphlab/plugins/actiongrouping/GroupActions.xml", null); 070 } catch (IOException e) { 071 e.printStackTrace(); 072 } catch (SAXException e) { 073 e.printStackTrace(); 074 } 075 } 076 077 // public static void main(String[] args) { 078 // show(something); 079 // } 080 081 }