Changeset 12665 for trunk/gli/src/org/greenstone/gatherer
- Timestamp:
- 2006-09-05T11:41:24+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java
r12572 r12665 76 76 77 77 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);80 78 81 79 private GEMS self = null; … … 84 82 private DeleteMetadataSetPrompt delete_prompt; 85 83 private NewMetadataSetPrompt new_prompt; 86 84 85 private JSplitPane splitPane = null; 86 private JSplitPane rightPane = null; 87 87 88 88 /** Um, the size of the screen I'd guess. */ … … 91 91 private MetadataSetManager msm; 92 92 93 private MetadataElementTable meta_element_table;94 private LangDependElementTablelang_element_table;95 96 private MetadataSetTree 97 98 private 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; 99 99 100 100 private boolean stand_alone = true; … … 125 125 126 126 /** Constructor. 127 * @param set a MetadataSet that should be initially selected128 * @param action a systematic action that should be performed129 127 */ 130 128 public GEMS(String gsdl_path, String metadata_path, boolean standalone, boolean new_set) … … 143 141 System.exit(0); 144 142 } 145 else {143 else { 146 144 notifyListeners(); 147 145 setVisible(false); … … 161 159 metadata_set_model.addObserver(meta_set_tree); 162 160 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); 171 169 172 170 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); 175 173 msti.setMetadataSetModel(metadata_set_model); 176 174 177 175 open_prompt = new OpenMetadataSetPrompt(self,msm); 178 176 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); 181 179 182 180 delete_prompt = new DeleteMetadataSetPrompt(self,msm); 183 181 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); 186 184 187 185 new_prompt = new NewMetadataSetPrompt(self,msm); 188 186 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); 191 189 192 190 … … 199 197 } 200 198 199 // the set tree 201 200 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); 208 205 209 206 … … 227 224 leftPane.add(treePane,BorderLayout.CENTER); 228 225 leftPane.add(buttonPane,BorderLayout.SOUTH); 229 230 // Initialise popup menus231 createAttributePopupMenu();232 createElementPopupMenu();233 createLanguageDependAttributePopupMenu();234 226 235 JLabel selected_language_label = new JLabel(Dictionary.get("GEMS.SelecedLanguage"));227 JLabel selected_language_label = new JLabel(Dictionary.get("GEMS.SelectedLanguage")); 236 228 selected_language_label.setOpaque(true); 237 229 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 239 234 language_combo.addActionListener(new ActionListener(){ 240 235 public void actionPerformed(ActionEvent e){ 241 236 JComboBox language_combo = (JComboBox) e.getSource(); 242 237 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 } 245 242 } 246 243 247 244 }); 248 245 249 JLabel 246 JLabel language_label = new JLabel(Dictionary.get("GEMS.LanguageDependent")); 250 247 language_label.setOpaque(true); 251 248 … … 257 254 258 255 JPanel languagePane = new JPanel(new BorderLayout(5,5)); 256 languagePane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 259 257 languagePane.add(language_label,BorderLayout.NORTH); 260 258 languagePane.add(selectLangPane,BorderLayout.CENTER); 261 259 262 260 263 JPanel languageAttributePane = new JPanel(new BorderLayout( 5,5));261 JPanel languageAttributePane = new JPanel(new BorderLayout()); 264 262 languageAttributePane.add(languagePane,BorderLayout.NORTH); 265 263 languageAttributePane.add(langTablePane,BorderLayout.CENTER); 266 264 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); 274 274 getContentPane().add(splitPane,BorderLayout.CENTER); 275 275 … … 279 279 } 280 280 281 public void setVisible(boolean visible) { 282 super.setVisible(visible); 283 rightPane.setDividerLocation(0.3); 284 } 285 281 286 public void displayMetadataSet(String metadata_path){ 282 287 open_prompt.openMetadataSet(metadata_path); … … 312 317 mem.removeAllMetadataElementListeners(); 313 318 } 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 377 320 public void windowGainedFocus(WindowEvent e) { 378 321 //System.out.println("windowGainedFocus."); … … 397 340 public JMenuItem file_new = null; 398 341 public JMenuItem file_open = null; 342 public JMenuItem file_close = null; 399 343 public JMenuItem file_save = null; 400 344 public JMenuItem edit_copy = null; … … 409 353 file.setText(Dictionary.get("Menu.File")); 410 354 411 file_exit = new JMenuItem(Dictionary.get("Menu.File_ Close"));355 file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit")); 412 356 file_exit.addActionListener(this); 413 357 … … 418 362 file_open.addActionListener(this); 419 363 364 file_close = new JMenuItem(Dictionary.get("Menu.File_Close")); 365 file_close.addActionListener(this); 366 420 367 file_save = new JMenuItem(Dictionary.get("Menu.File_Save")); 421 368 file_save.addActionListener(this); … … 430 377 file.add(file_new); 431 378 file.add(file_open); 379 file.add(file_close); 432 380 file.add(file_save); 433 381 file.add(file_delete); 434 382 file.add(new JSeparator()); 435 383 //file.add(file_preferences); 436 file.add(new JSeparator());384 //file.add(new JSeparator()); 437 385 file.add(file_exit); 438 386 … … 481 429 } 482 430 431 // File -> Close 432 if (event_source == file_close) { 433 434 } 483 435 // File -> Delete 484 436 if (event_source == file_delete) { … … 561 513 } 562 514 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 selected600 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 deletion619 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 deep630 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 }651 515 }
Note:
See TracChangeset
for help on using the changeset viewer.