Ignore:
Timestamp:
2006-09-05T11:41:24+12:00 (18 years ago)
Author:
kjdon
Message:

right hand side now in a split pane. attribute tables now both use AttributeTable class. some components renamed. some coding style changes, incl indenting. tree and table right click popup menus no longer handled here. table ones have gone for now, tree one handled by MetadataSetTree. added file->close which does nothing yet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java

    r12572 r12665  
    7676 
    7777    static final private Dimension SIZE = new Dimension(800,550);
    78     static final private Dimension TREE_SIZE = new Dimension(250,550);
    79     static final private Dimension TABLE_SIZE = new Dimension(550,200);
    8078
    8179    private GEMS self = null;
     
    8482    private DeleteMetadataSetPrompt delete_prompt;
    8583    private NewMetadataSetPrompt new_prompt;   
    86 
     84   
     85    private JSplitPane splitPane = null;
     86    private JSplitPane rightPane = null;
    8787     
    8888    /** Um, the size of the screen I'd guess. */
     
    9191    private MetadataSetManager msm;
    9292
    93     private MetadataElementTable meta_element_table;
    94     private LangDependElementTable lang_element_table;
    95 
    96     private MetadataSetTree  meta_set_tree;     
    97 
    98     private  MetadataSetModel metadata_set_model;
     93    private AttributeTable attribute_table;  // meta_element_table
     94    private AttributeTable language_dependent_attribute_table; //lang_element_table;
     95
     96    private MetadataSetTree meta_set_tree;     
     97
     98    private MetadataSetModel metadata_set_model;
    9999
    100100    private boolean stand_alone = true;
     
    125125
    126126    /** Constructor.
    127      * @param set a MetadataSet that should be initially selected
    128      * @param action a systematic action that should be performed
    129127     */
    130128    public GEMS(String gsdl_path, String metadata_path, boolean standalone, boolean new_set)
     
    143141            System.exit(0);
    144142            }
    145             else{
     143            else {
    146144            notifyListeners();
    147145            setVisible(false);
     
    161159        metadata_set_model.addObserver(meta_set_tree);
    162160
    163     meta_element_table = new MetadataElementTable();
    164     MetadataElementModel  mem= new MetadataElementModel();
    165         mem.addMetadataElementListener((MetadataElementListener)meta_element_table);
    166     meta_element_table.addAttributeListener(metadata_set_model);
    167 
    168     lang_element_table = new LangDependElementTable();
    169         mem.addMetadataElementListener((MetadataElementListener)lang_element_table);
    170     lang_element_table.addAttributeListener(metadata_set_model);
     161    attribute_table = new AttributeTable(false);
     162    MetadataElementModel mem = new MetadataElementModel();
     163        mem.addMetadataElementListener((MetadataElementListener)attribute_table);
     164    attribute_table.addAttributeListener(metadata_set_model);
     165
     166    language_dependent_attribute_table = new AttributeTable(true);
     167        mem.addMetadataElementListener((MetadataElementListener)language_dependent_attribute_table);
     168    language_dependent_attribute_table.addAttributeListener(metadata_set_model);
    171169
    172170        MetadataSetInfo msti= new MetadataSetInfo();
    173         msti.addMetadataSetListener((MetadataSetListener)meta_element_table);
    174         msti.addMetadataSetListener((MetadataSetListener)lang_element_table);
     171        msti.addMetadataSetListener((MetadataSetListener)attribute_table);
     172        msti.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
    175173        msti.setMetadataSetModel(metadata_set_model);
    176174       
    177175        open_prompt = new OpenMetadataSetPrompt(self,msm);
    178176        open_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
    179         open_prompt.addMetadataSetListener((MetadataSetListener)meta_element_table);       
    180     open_prompt.addMetadataSetListener((MetadataSetListener)lang_element_table);   
     177        open_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);       
     178    open_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);   
    181179   
    182180        delete_prompt = new DeleteMetadataSetPrompt(self,msm);
    183181        delete_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
    184         delete_prompt.addMetadataSetListener((MetadataSetListener)meta_element_table);
    185     delete_prompt.addMetadataSetListener((MetadataSetListener)lang_element_table);
     182        delete_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
     183    delete_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
    186184   
    187185        new_prompt = new NewMetadataSetPrompt(self,msm);
    188186        new_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
    189         new_prompt.addMetadataSetListener((MetadataSetListener)meta_element_table);
    190         new_prompt.addMetadataSetListener((MetadataSetListener)lang_element_table);
     187        new_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
     188        new_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
    191189 
    192190
     
    199197    }
    200198
     199    // the set tree
    201200        JScrollPane treePane = new JScrollPane(meta_set_tree);
    202         treePane.setPreferredSize(TREE_SIZE);
    203 
    204     JScrollPane tablePane = new JScrollPane(meta_element_table);
    205         tablePane.setPreferredSize(TABLE_SIZE);
    206 
    207         JScrollPane langTablePane =  new JScrollPane(lang_element_table);
     201    // the language independent attributes
     202    JScrollPane tablePane = new JScrollPane(attribute_table);
     203    // the language dependent attributes
     204    JScrollPane langTablePane =  new JScrollPane(language_dependent_attribute_table);
    208205
    209206
     
    227224        leftPane.add(treePane,BorderLayout.CENTER); 
    228225    leftPane.add(buttonPane,BorderLayout.SOUTH); 
    229 
    230     // Initialise popup menus
    231     createAttributePopupMenu();
    232     createElementPopupMenu();
    233     createLanguageDependAttributePopupMenu();
    234226         
    235     JLabel  selected_language_label = new JLabel(Dictionary.get("GEMS.SelecedLanguage"));
     227    JLabel selected_language_label = new JLabel(Dictionary.get("GEMS.SelectedLanguage"));
    236228    selected_language_label.setOpaque(true);
    237229       
    238         JComboBox language_combo = new JComboBox(new Vector(msm.getLanguageList()));
     230    Vector language_vector = new Vector(msm.getLanguageList());
     231        language_vector.add(0, Dictionary.get("GEMS.Language"));
     232    JComboBox language_combo = new JComboBox(language_vector);
     233   
    239234    language_combo.addActionListener(new ActionListener(){
    240235        public void actionPerformed(ActionEvent e){
    241236            JComboBox language_combo = (JComboBox) e.getSource();
    242237            String langInfo = (String)language_combo.getSelectedItem();
    243                     String lang = langInfo.split("\\s")[0];                 
    244             lang_element_table.languageSelected(lang);
     238            if (!langInfo.equals(Dictionary.get("GEMS.Language"))) {
     239            String lang = langInfo.split("\\s")[0];                 
     240            language_dependent_attribute_table.addNewLanguage(lang);
     241            }
    245242        }
    246243
    247244        });     
    248245
    249         JLabel  language_label = new JLabel(Dictionary.get("GEMS.LanguageDependent"));
     246        JLabel language_label = new JLabel(Dictionary.get("GEMS.LanguageDependent"));
    250247    language_label.setOpaque(true);
    251248     
     
    257254
    258255        JPanel languagePane =  new JPanel(new BorderLayout(5,5));
     256    languagePane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    259257    languagePane.add(language_label,BorderLayout.NORTH); 
    260258        languagePane.add(selectLangPane,BorderLayout.CENTER);       
    261259
    262260
    263         JPanel languageAttributePane =  new JPanel(new BorderLayout(5,5));
     261        JPanel languageAttributePane =  new JPanel(new BorderLayout());
    264262    languageAttributePane.add(languagePane,BorderLayout.NORTH); 
    265263        languageAttributePane.add(langTablePane,BorderLayout.CENTER);       
    266264
    267 
    268         JPanel rightPane =  new JPanel(new BorderLayout(5,5));
    269     rightPane.add(tablePane,BorderLayout.NORTH); 
    270         rightPane.add(languageAttributePane,BorderLayout.CENTER);
    271 
    272     JSplitPane splitPane =  new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPane,rightPane);     
    273                                    
     265    JLabel attribute_label = new JLabel(Dictionary.get("GEMS.Attribute_Table"));
     266    attribute_label.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     267    JPanel mainAttributePane = new JPanel(new BorderLayout());
     268    mainAttributePane.add(attribute_label, BorderLayout.NORTH);
     269    mainAttributePane.add(tablePane, BorderLayout.CENTER);
     270   
     271    rightPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,mainAttributePane,languageAttributePane);
     272   
     273    splitPane =  new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPane,rightPane);   
    274274    getContentPane().add(splitPane,BorderLayout.CENTER);
    275275
     
    279279    }
    280280
     281    public void setVisible(boolean visible) {
     282    super.setVisible(visible);
     283    rightPane.setDividerLocation(0.3);
     284    }
     285   
    281286    public void displayMetadataSet(String metadata_path){
    282287    open_prompt.openMetadataSet(metadata_path);
     
    312317    mem.removeAllMetadataElementListeners();
    313318    }
    314 
    315 
    316    public void createAttributePopupMenu() {
    317         JMenuItem menuItem;
    318 
    319         //Create the popup menu.
    320         JPopupMenu popup = new JPopupMenu();
    321         menuItem = new JMenuItem(Dictionary.get("GEMS.Popup.AddAttribute"));
    322         menuItem.addActionListener(meta_element_table);
    323         menuItem.setActionCommand(GEMSConstants.ADD_ATTRIBUTE);
    324         popup.add(menuItem);
    325         menuItem = new JMenuItem(Dictionary.get("GEMS.Popup.DeleteAttribute"));
    326         menuItem.addActionListener(meta_element_table);
    327     menuItem.setActionCommand(GEMSConstants.DELETE_ATTRIBUTE);
    328         popup.add(menuItem);
    329 
    330         //Add listener to the text area so the popup menu can come up.
    331         MouseListener popupListener = new PopupListener(popup);
    332         meta_element_table.addMouseListener(popupListener);
    333                
    334     }
    335 
    336   public void createLanguageDependAttributePopupMenu() {
    337         JMenuItem menuItem;
    338 
    339         //Create the popup menu.
    340         JPopupMenu popup = new JPopupMenu();
    341         //menuItem = new JMenuItem(Dictionary.get("GEMS.Popup.AddAttribute"));
    342         //menuItem.addActionListener(lang_element_table);
    343         //menuItem.setActionCommand(GEMSConstants.ADD_ATTRIBUTE);
    344         //popup.add(menuItem);
    345         menuItem = new JMenuItem(Dictionary.get("GEMS.Popup.DeleteAttribute"));
    346         menuItem.addActionListener(lang_element_table);
    347     menuItem.setActionCommand(GEMSConstants.DELETE_ATTRIBUTE);
    348         popup.add(menuItem);
    349 
    350         //Add listener to the text area so the popup menu can come up.
    351         MouseListener popupListener = new PopupListener(popup);
    352         lang_element_table.addMouseListener(popupListener);
    353          
    354     }
    355 
    356 
    357 
    358       public void createElementPopupMenu() {
    359         JMenuItem menuItem;
    360     //Create the popup menu.
    361         JPopupMenu popup = new JPopupMenu();
    362         menuItem = new JMenuItem(Dictionary.get("GEMS.Popup.AddElement"));
    363         menuItem.addActionListener(meta_set_tree);
    364         menuItem.setActionCommand(GEMSConstants.ADD_ELEMENT);
    365         popup.add(menuItem);
    366         menuItem = new JMenuItem(Dictionary.get("GEMS.Popup.DeleteElement"));
    367         menuItem.addActionListener(meta_set_tree);
    368     menuItem.setActionCommand(GEMSConstants.DELETE_ELEMENT);
    369         popup.add(menuItem);
    370    
    371         //Add listener to the text area so the popup menu can come up.
    372         MouseListener popupListener = new PopupListener(popup);
    373         meta_set_tree.addMouseListener(popupListener);
    374        
    375       }
    376  
     319   
    377320    public void windowGainedFocus(WindowEvent e) {
    378321    //System.out.println("windowGainedFocus.");
     
    397340    public JMenuItem file_new    = null;
    398341    public JMenuItem file_open   = null;
     342    public JMenuItem file_close   = null;
    399343    public JMenuItem file_save   = null;
    400344    public JMenuItem edit_copy   = null;
     
    409353        file.setText(Dictionary.get("Menu.File"));
    410354       
    411         file_exit = new JMenuItem(Dictionary.get("Menu.File_Close"));
     355        file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit"));
    412356        file_exit.addActionListener(this);
    413357       
     
    418362        file_open.addActionListener(this);
    419363       
     364        file_close = new JMenuItem(Dictionary.get("Menu.File_Close"));
     365        file_close.addActionListener(this);
     366
    420367        file_save = new JMenuItem(Dictionary.get("Menu.File_Save"));
    421368        file_save.addActionListener(this);
     
    430377        file.add(file_new);
    431378        file.add(file_open);
     379        file.add(file_close);
    432380        file.add(file_save);
    433381            file.add(file_delete);
    434382        file.add(new JSeparator());
    435383            //file.add(file_preferences);
    436             file.add(new JSeparator());
     384            //file.add(new JSeparator());
    437385        file.add(file_exit);
    438386           
     
    481429        }
    482430
     431        // File -> Close
     432        if (event_source == file_close) {
     433       
     434        }
    483435              // File -> Delete
    484436        if (event_source == file_delete) {               
     
    561513    }
    562514
    563 
    564    
    565  class PopupListener extends MouseAdapter {
    566         JPopupMenu popup;
    567 
    568         PopupListener(JPopupMenu popupMenu) {
    569             popup = popupMenu;
    570         }
    571 
    572         public void mousePressed(MouseEvent e) {
    573             maybeShowPopup(e);
    574         }
    575 
    576         public void mouseReleased(MouseEvent e) {
    577             maybeShowPopup(e);
    578         }
    579 
    580         private void maybeShowPopup(MouseEvent e) {
    581             Component source = (Component)e.getSource();
    582             boolean show = false;
    583 
    584         if (source instanceof JTable){
    585                 show = true;
    586         JTable table = (JTable)source;
    587         JMenuItem item = null;
    588                 if (table.getSelectedRow() !=-1){
    589            
    590             if(popup.getComponentCount() >1){
    591             item = (JMenuItem)popup.getComponent(1);
    592             }
    593             else{
    594             item = (JMenuItem)popup.getComponent(0);
    595             }
    596          
    597             item.setEnabled(true);
    598         }
    599         else{//disable the delete item if no row is selected
    600             if(popup.getComponentCount() >1){
    601             item = (JMenuItem)popup.getComponent(1);
    602             }
    603             else{
    604             item = (JMenuItem)popup.getComponent(0);
    605             }
    606             item.setEnabled(false);
    607         }
    608         }             
    609 
    610             if (source instanceof JTree){
    611        
    612         JTree tree = (JTree)source;
    613         TreePath tse = tree.getSelectionPath();
    614         if (tse ==null) return;
    615         DefaultMutableTreeNode snode= (DefaultMutableTreeNode)tse.getLastPathComponent();
    616              
    617         Object data = snode.getUserObject();
    618                 // don't allow the root element deletion         
    619         if (data instanceof MetadataElementModel){               
    620             JMenuItem item = (JMenuItem)popup.getComponent(1);
    621                     item.setEnabled(true);
    622         }
    623         else{
    624             JMenuItem item = (JMenuItem)popup.getComponent(1);
    625                     item.setEnabled(false);
    626         }
    627                
    628        
    629         // don't allow to add elements two levels deep       
    630         if (tse.getPath().length > 2){               
    631             JMenuItem item = (JMenuItem)popup.getComponent(0);
    632                     item.setEnabled(false);
    633         }
    634         else{
    635             JMenuItem item = (JMenuItem)popup.getComponent(0);
    636                     item.setEnabled(true);
    637         }
    638 
    639 
    640         show = true;
    641         }             
    642 
    643            
    644 
    645             if (e.isPopupTrigger() && show) {
    646                 popup.show(e.getComponent(),
    647                            e.getX(), e.getY());
    648             }
    649         }
    650    }
    651515}
Note: See TracChangeset for help on using the changeset viewer.