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.ui.components.gpropertyeditor.GPropertyEditor;
007    import graphlab.ui.components.utils.GFrameLocationProvider;
008    
009    import javax.swing.*;
010    import java.awt.*;
011    import java.awt.event.ActionEvent;
012    import java.awt.event.ActionListener;
013    import java.awt.event.KeyAdapter;
014    import java.awt.event.KeyEvent;
015    
016    /**
017     * @author Rouzbeh Ebrahimi
018     */
019    public class GTabbedAttributeFrame extends JDialog {
020        /**
021         *
022         */
023        private static final long serialVersionUID = 2001771646679881523L;
024        //    private NotifiableAttributeSet atr;
025        public GTabbedAttributePane tabbedPane;
026    
027        /**
028         * Creates new form GAttrFrame
029         */
030        public GTabbedAttributeFrame(java.awt.Frame parent, GTabbedAttributePane tabbedPane, boolean modal) {
031            super(parent, modal);
032    
033            this.tabbedPane = tabbedPane;
034    
035            tabbedPane.setVisible(true);
036            initComponents();
037        }
038    
039        /**
040         * @return the return status of this dialog - true-> the ok presses, false-> cancelled by user
041         */
042        public boolean getReturnStatus() {
043            return status;
044        }
045    
046        GPropertyEditor table;
047    
048        private void initComponents() {
049            setAlwaysOnTop(true);
050            add(tabbedPane);
051            JPanel buttonPanel = new JPanel();
052            JButton cancelButton = new JButton("cancel");
053    //        table = new gpropertyeditor();
054    //        table.connect(tabbedPane);
055    
056            JButton okButton = new JButton("Ok");
057            setDefaultCloseOperation(HIDE_ON_CLOSE);
058    
059            addWindowListener(new java.awt.event.WindowAdapter() {
060                public void windowClosing(java.awt.event.WindowEvent evt) {
061                    closeDialog();
062                }
063            });
064            okButton.addActionListener(new ActionListener() {
065                public void actionPerformed(ActionEvent evt) {
066                    finished(true);
067                }
068            });
069            cancelButton.addActionListener(new ActionListener() {
070                public void actionPerformed(ActionEvent evt) {
071                    finished(false);
072                }
073            });
074    
075            okButton.addKeyListener(new KeyAdapter() {
076                public void keyTyped(KeyEvent e) {
077                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
078                        finished(true);
079                    }
080                }
081            });
082            buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
083            buttonPanel.add(okButton);
084            buttonPanel.add(cancelButton);
085    //        buttonPanel.add(applyButton);
086            add(buttonPanel, java.awt.BorderLayout.SOUTH);
087    //        add(table,java.awt.BorderLayout.CENTER);
088    //        applyButton.setSelected(true);
089            setSize(GFrameLocationProvider.getPopUpSize());
090            setLocation(GFrameLocationProvider.getPopUpLocation());
091            validate();
092            okButton.setSelected(true);
093            pack();
094    //        applyButton.grabFocus();
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    
110        public static GTabbedAttributeFrame showEditDialog(GTabbedAttributePane tabs) {
111            return showEditDialog(tabs, true);
112        }
113    
114        /**
115         * Shows a Property editor to edit the attributes in the input.
116         * the modal is like the modal in JDialog
117         */
118        public static GTabbedAttributeFrame showEditDialog(GTabbedAttributePane tabs, boolean modal) {
119            GTabbedAttributeFrame gAttrFrame = new GTabbedAttributeFrame(new JFrame(), tabs, modal);
120            gAttrFrame.setVisible(true);
121            return gAttrFrame;
122        }
123    
124        /**
125         * return the GProertyEditor which is the main editor of notifiableAttributeSet
126         */
127        public GPropertyEditor getPropertyEditor() {
128            return table;
129        }
130    }