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.ui.components.prefeditor;
005    
006    import graphlab.platform.attribute.NotifiableAttributeSetImpl;
007    import graphlab.platform.preferences.AbstractPreference;
008    import graphlab.ui.components.gpropertyeditor.GPropertyEditor;
009    import graphlab.ui.components.utils.GFrameLocationProvider;
010    
011    import javax.swing.*;
012    import java.util.HashMap;
013    import java.util.HashSet;
014    import java.util.Iterator;
015    import java.util.Map;
016    
017    /**
018     * @author Rouzbeh Ebrahimi
019     */
020    public class GTabbedAttributePane extends JTabbedPane {
021        /**
022         *
023         */
024        private static final long serialVersionUID = -1122049309619308113L;
025        public HashMap<String, AbstractPreference> tabs;
026        public HashMap<String, HashSet<AbstractPreference>> complicatedTabs;
027        public boolean isComplicatedForm;
028    
029        /**
030         * Creates new form GAttrFrame
031         */
032        public GTabbedAttributePane(HashMap<String, AbstractPreference> tabs) {
033            super();
034            this.tabs = tabs;
035            initComponents();
036        }
037    
038        public GTabbedAttributePane(HashMap<String, HashSet<AbstractPreference>> tabs, boolean complicatedForm) {
039            super();
040            this.complicatedTabs = tabs;
041            this.isComplicatedForm = complicatedForm;
042            initComponents();
043        }
044    
045        /**
046         * @return the return status of this dialog - true-> the ok presses, false-> cancelled by user
047         */
048        public boolean getReturnStatus() {
049            return status;
050        }
051    
052        GPropertyEditor table;
053    
054        public void initComponents() {
055            setPreferredSize(GFrameLocationProvider.getPrefSize());
056            setLocation(GFrameLocationProvider.getPrefLocation());
057            setName("Preferences");
058            Iterator<String> iter;
059            if (!isComplicatedForm) {
060                iter = tabs.keySet().iterator();
061            } else {
062                iter = complicatedTabs.keySet().iterator();
063            }
064            for (; iter.hasNext();) {
065                if (!isComplicatedForm) {
066                    String title = iter.next();
067                    GPropertyEditor gp = new GPropertyEditor();
068                    gp.connect(tabs.get(title).attributeSet);
069                    gp.setVisible(true);
070                    addTab(title, gp);
071                } else {
072                    String title = iter.next();
073                    GPropertyEditor gp = new GPropertyEditor();
074                    Iterator<AbstractPreference> i = complicatedTabs.get(title).iterator();
075                    NotifiableAttributeSetImpl attributeSet = new NotifiableAttributeSetImpl();
076                    for (; i.hasNext();) {
077                        AbstractPreference ap = i.next();
078    
079                        Map<String, Object> attributeMap = ap.attributeSet.getAttrs();
080                        Iterator<String> j = attributeMap.keySet().iterator();
081                        for (; j.hasNext();) {
082                            String name = j.next();
083                            Object o = attributeMap.get(name);
084                            attributeSet.put(ap.preferenceName + ":   " + name, o);
085                        }
086                    }
087    //                GraphPreferences prefInstance=new GraphPreferences();
088                    gp.connect(attributeSet);
089    
090                    gp.setVisible(true);
091                    addTab(title, gp);
092                }
093            }
094    
095        }
096    
097        private boolean status = false;
098        private boolean finished = false;
099    
100        private void closeDialog() {
101            finished = true;
102        }
103    
104        private void finished(boolean status) {
105            this.status = status;
106            closeDialog();
107            //dispose();
108        }
109    //    public static GTabbedAttributePane showEditDialog(NotifiableAttributeSet input){
110    //        return showEditDialog(input, true);
111    //    }
112    //    /** Shows a Property editor to edit the attributes in the input.
113    //     * the modal is like the modal in JDialog */
114    //    public static GTabbedAttributePane showEditDialog(NotifiableAttributeSet input, boolean modal){
115    //        GTabbedAttributePane gAttrpane = new GTabbedAttributePane();
116    //        gAttrpane.setVisible(true);
117    //        return gAttrPane;
118    //    }
119    
120        /**
121         * return the GProertyEditor which is the main editor of notifiableAttributeSet
122         */
123        public GPropertyEditor getPropertyEditor() {
124            return table;
125        }
126    }