1 /* $RCSfile$ 2 * $Author: hansonr $ 3 * $Date: 2010-05-11 15:47:18 -0500 (Tue, 11 May 2010) $ 4 * $Revision: 13064 $ 5 * 6 * Copyright (C) 2000-2005 The Jmol Development Team 7 * 8 * Contact: jmol-developers@lists.sf.net 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; either 13 * version 2.1 of the License, or (at your option) any later version. 14 * 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23 */ 24 package org.jmol.awt; 25 26 import java.awt.Component; 27 import java.util.Map; 28 29 import javax.swing.JPopupMenu; 30 import javax.swing.event.MenuEvent; 31 import javax.swing.event.MenuListener; 32 33 import org.jmol.api.SC; 34 import org.jmol.popup.JmolPopup; 35 import org.jmol.popup.PopupResource; 36 37 38 public class AwtJmolPopup extends JmolPopup { 39 AwtJmolPopup()40 public AwtJmolPopup() { 41 helper = new AwtPopupHelper(this); 42 } 43 44 @Override addMenu(final String id, final String item, final SC subMenu, final String label, final PopupResource popupResourceBundle)45 protected void addMenu(final String id, final String item, final SC subMenu, final String label, 46 final PopupResource popupResourceBundle) { 47 48 final AwtSwingComponent c = (AwtSwingComponent) subMenu; 49 c.deferred = true; 50 c.jm.addMenuListener(new MenuListener() { 51 52 @Override 53 public void menuSelected(MenuEvent e) { 54 if (c.deferred) { 55 c.deferred = false; 56 if (item.indexOf("Computed") < 0) 57 addMenuItems(id, item, subMenu, popupResourceBundle); 58 appCheckSpecialMenu(item, subMenu, label); 59 updateAwtMenus(item); 60 } 61 } 62 63 @Override 64 public void menuDeselected(MenuEvent e) { 65 } 66 67 @Override 68 public void menuCanceled(MenuEvent e) { 69 } 70 71 }); 72 } 73 74 @SuppressWarnings("unchecked") updateAwtMenus(String item)75 protected void updateAwtMenus(String item) { 76 switch (item.charAt(0)) { 77 case 'c': 78 // case "configurationComputedMenu": 79 updateConfigurationComputedMenu(); 80 break; 81 case 'f': 82 // case "fileMenu": 83 updateFileMenu(); 84 break; 85 case 'e': 86 // case "elementsComputedMenu": 87 updateElementsComputedMenu(vwr.getElementsPresentBitSet(modelIndex)); 88 break; 89 case 'F': 90 // case "FRAMESbyModelComputedMenu": 91 updateFRAMESbyModelComputedMenu(); 92 break; 93 case 'l': 94 // case "languageComputedMenu": 95 updateLanguageSubmenu(); 96 break; 97 case 'm': 98 // case "modelSetMenu": 99 updateModelSetComputedMenu(); 100 break; 101 case 'P': 102 if (item.equals("PDBheteroComputedMenu")) 103 updateHeteroComputedMenu(vwr.ms.getHeteroList(modelIndex)); 104 else if (item.equals("PDBnucleicResiduesComputedMenu")) 105 updatePDBResidueComputedMenus(); 106 else if (item.equals("PDBaaResiduesComputedMenu")) 107 updatePDBResidueComputedMenus(); 108 else if (item.equals("PDBaaResiduesComputedMenu")) 109 updatePDBResidueComputedMenus(); 110 break; 111 case 's': 112 switch (item.charAt(1)) { 113 case 'p': 114 // case "spectraMenu": 115 updateSpectraMenu(); 116 break; 117 case 'c': 118 // case "sceneComputedMenu": 119 updateSceneComputedMenu(); 120 break; 121 case 'e': 122 // case "selectMenuText": 123 updatePDBResidueComputedMenus(); 124 break; 125 case 'u': 126 // case "surfMoComputedMenuText": 127 updateSurfMoComputedMenu((Map<String, Object>) modelInfo.get("moData")); 128 break; 129 case 'y': 130 // case "systemMenu": 131 updateAboutSubmenu(); 132 break; 133 } 134 break; 135 case 'S': 136 if (item.indexOf("Select") >= 0) 137 // case "SYMMETRYSelectComputedMenu": 138 updateSYMMETRYSelectComputedMenu(); 139 else 140 // case "SYMMETRYShowComputedMenu": 141 updateSYMMETRYShowComputedMenu(); 142 break; 143 } 144 updateFileTypeDependentMenus(); 145 for (int i = Special.size(); --i >= 0;) 146 updateSpecialMenuItem(Special.get(i)); 147 } 148 149 @Override menuShowPopup(SC popup, int x, int y)150 protected void menuShowPopup(SC popup, int x, int y) { 151 try { 152 ((JPopupMenu)((AwtSwingComponent)popup).jc).show((Component) vwr.display, x, y); 153 } catch (Exception e) { 154 // ignore 155 } 156 } 157 158 @Override getUnknownCheckBoxScriptToRun(SC item, String name, String what, boolean TF)159 public String getUnknownCheckBoxScriptToRun(SC item, String name, String what, boolean TF) { 160 // n/a 161 return null; 162 } 163 164 @Override getImageIcon(String fileName)165 protected Object getImageIcon(String fileName) { 166 // n/a 167 return null; 168 } 169 170 @Override menuFocusCallback(String name, String actionCommand, boolean b)171 public void menuFocusCallback(String name, String actionCommand, boolean b) { 172 // n/a ?? 173 } 174 175 176 } 177