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.ui; 006 007 import graphlab.graph.ui.GHTMLPageComponent; 008 import graphlab.graph.ui.HyperlinkHandler; 009 import graphlab.platform.attribute.NotifiableAttributeSet; 010 import graphlab.platform.core.BlackBoard; 011 import graphlab.platform.preferences.lastsettings.StorableOnExit; 012 import graphlab.ui.actions.UIEventData; 013 import graphlab.ui.components.GFrame; 014 import graphlab.ui.components.gpropertyeditor.GBasicCellEditor; 015 import graphlab.ui.components.gpropertyeditor.GBasicCellRenderer; 016 import graphlab.ui.components.gpropertyeditor.GCellEditor; 017 import graphlab.ui.components.gpropertyeditor.GCellRenderer; 018 import graphlab.ui.components.gpropertyeditor.utils.ObjectViewer; 019 import graphlab.ui.components.utils.GAttrFrame; 020 021 import javax.swing.*; 022 import java.awt.*; 023 024 /** 025 * @author Azin Azadi 026 */ 027 public class UIUtils { 028 public static Component getComponent(BlackBoard b, String id) { 029 return b.getData(getComponentVariableKeyNameInBlackBoard(id)); 030 } 031 032 public static void setComponent(BlackBoard b, String id, Component c) { 033 b.setData(getComponentVariableKeyNameInBlackBoard(id), c); 034 } 035 036 /** 037 * This method gives a standard way to name the awt.components that are in the black board. 038 * when in XML we give an id to a component, when we want to fetch it from blackboard we should use this 039 * method to have its exact name in black board which is stored in a Variable 040 * 041 * @param componentId the id of component which is given via XML 042 * @return the name of Variable in the blackboard which the component can be accessed 043 */ 044 045 public static String getComponentVariableKeyNameInBlackBoard(String componentId) { 046 return "UI Component" + componentId; 047 } 048 049 /** 050 * returns the GFrame object that mapped to the blackboard. 051 * the returned GFrame contains all menus, sidebars, toolbars and ... of the User Interface. 052 */ 053 public static GFrame getGFrame(BlackBoard b) { 054 UI ui = b.getData(UI.name); 055 return ui.frame; 056 } 057 058 /** 059 * @return the UI instance which is currently running in the given blackboard environment 060 */ 061 public static UI getUI(BlackBoard blackboard) { 062 return blackboard.getData(UI.name); 063 } 064 065 public static String getUIEventKey(String id) { 066 return UIEventData.name(id); 067 } 068 069 public static void exit() { 070 if (JOptionPane.showConfirmDialog(null, "Are you sure to exit?", 071 "Exiting From the Application...", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { 072 try { 073 StorableOnExit.SETTINGS.saveSettings(); 074 } catch (Exception e) { 075 e.printStackTrace(); 076 } 077 System.exit(0); 078 } 079 } 080 081 //______________________________ gpropertyeditor ____________________________________ 082 /** 083 * @see graphlab.ui.components.utils.GAttrFrame#showEditDialog(graphlab.platform.attribute.NotifiableAttributeSet,boolean) 084 */ 085 public static GAttrFrame showEditDialog(NotifiableAttributeSet input, boolean modal) { 086 return GAttrFrame.showEditDialog(input, modal); 087 } 088 089 /** 090 * @see graphlab.ui.components.gpropertyeditor.utils.ObjectViewer 091 */ 092 public static ObjectViewer showObject(Object o) { 093 return ObjectViewer.showObject(o); 094 } 095 096 /** 097 * @see graphlab.ui.components.gpropertyeditor.GCellRenderer#registerRenderer(Class,graphlab.ui.components.gpropertyeditor.GBasicCellRenderer) 098 */ 099 public static void registerRenderer(Class clazz, GBasicCellRenderer viewer) { 100 GCellRenderer.registerRenderer(clazz, viewer); 101 } 102 103 /** 104 * @see graphlab.ui.components.gpropertyeditor.GCellEditor#registerEditor(Class,graphlab.ui.components.gpropertyeditor.GBasicCellEditor) 105 */ 106 public static void registerEditor(Class clazz, GBasicCellEditor editor) { 107 GCellEditor.registerEditor(clazz, editor); 108 } 109 110 /** 111 * @see graphlab.ui.components.gpropertyeditor.GCellEditor#getEditorFor(Object) 112 */ 113 public static GBasicCellEditor getEditorFor(Object value) { 114 return GCellEditor.getEditorFor(value); 115 } 116 117 /** 118 * @see graphlab.ui.components.gpropertyeditor.GCellRenderer#getRendererFor(Object) 119 */ 120 public static Component getRendererFor(Object value) { 121 return GCellRenderer.getRendererFor(value); 122 } 123 124 125 126 //_____________ GHTMLPageComponent _________________ 127 /** 128 * @see graphlab.graph.ui.GHTMLPageComponent#registerHyperLinkHandler(java.lang.String,graphlab.graph.ui.HyperlinkHandler) 129 */ 130 public static void registerHyperLinkHandler(String protocol, HyperlinkHandler h) { 131 GHTMLPageComponent.registerHyperLinkHandler(protocol, h); 132 } 133 }