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; 005 006 import graphlab.graph.graph.GraphColoring; 007 import graphlab.graph.graph.SubGraph; 008 import graphlab.graph.old.ArrowHandler; 009 import graphlab.graph.old.GShape; 010 import graphlab.graph.old.GStroke; 011 import graphlab.graph.old.PolygonArrow; 012 import graphlab.platform.Application; 013 import graphlab.platform.StaticUtils; 014 import graphlab.platform.core.BlackBoard; 015 import graphlab.platform.core.Listener; 016 import graphlab.platform.preferences.lastsettings.StorableOnExit; 017 import graphlab.plugins.main.ui.*; 018 import graphlab.ui.UI; 019 import graphlab.ui.UIUtils; 020 import graphlab.ui.components.GFrame; 021 import graphlab.ui.components.gpropertyeditor.editors.inplace.GSimpleComboEditor; 022 023 import javax.swing.*; 024 import java.awt.event.WindowAdapter; 025 import java.awt.event.WindowEvent; 026 import java.net.URL; 027 028 /** 029 * @author Reza Mohammadi, azin 030 */ 031 public class Init implements graphlab.platform.plugin.PluginInterface, StorableOnExit { 032 033 public static Class uiClass = null; 034 035 public void init(final BlackBoard blackboard) { 036 try { 037 try { 038 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 039 } catch (Exception e) { 040 e.printStackTrace(); 041 } 042 UI ui = new UI(blackboard, false); 043 blackboard.addListener(Application.POST_INIT_EVENT, new Listener() { 044 public void keyChanged(String key, Object value) { 045 GFrame frame = UIUtils.getGFrame(blackboard); 046 URL resource = getClass().getResource("/images/Icon.ICO"); 047 if (resource != null) { 048 ImageIcon icon = new ImageIcon(resource); 049 frame.setIconImage(icon.getImage()); 050 } 051 frame.validate(); 052 UIUtils.getGFrame(blackboard).setVisible(true); 053 } 054 }); 055 ui.loadXML("/graphlab/plugins/main/core/SampleUI.xml", getClass()); 056 UIUtils.registerRenderer(PolygonArrow.class, new ArrowRenderer()); 057 UIUtils.registerEditor(PolygonArrow.class, new ArrowEditor()); 058 UIUtils.registerRenderer(GShape.class, new GShapeRenderer()); 059 UIUtils.registerRenderer(GStroke.class, new GStrokeRenderer()); 060 UIUtils.registerEditor(GStroke.class, new GStrokeEditor()); 061 UIUtils.registerEditor(GShape.class, new GSimpleComboEditor(new GShapeRenderer())); 062 UIUtils.registerRenderer(SubGraph.class, new SubGraphRenderer()); 063 UIUtils.registerRenderer(GraphColoring.class, new GraphColoringRenderer()); 064 065 StaticUtils.setFromStringProvider(PolygonArrow.class.getName(), new ArrowHandler()); 066 graphlab.ui.components.GFrame gFrame = UIUtils.getGFrame(blackboard); 067 gFrame.setTitle("GraphLab V1.0"); 068 gFrame.addWindowListener(new WindowAdapter() { 069 public void windowClosing(WindowEvent e) { 070 if (JOptionPane.showConfirmDialog(null, "Do you want to exit?", 071 "Application Exiting...", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { 072 try { 073 SETTINGS.saveSettings(); 074 } catch (Exception e1) { 075 e1.printStackTrace(); 076 } 077 System.exit(0); 078 } 079 } 080 }); 081 082 083 } catch (Exception e) { 084 e.printStackTrace(); 085 } 086 } 087 }