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.net.URL; 28 29 import javax.swing.ImageIcon; 30 import javax.swing.JPopupMenu; 31 import javax.swing.JRadioButtonMenuItem; 32 import javax.swing.event.MenuEvent; 33 import javax.swing.event.MenuListener; 34 35 import org.jmol.api.SC; 36 import org.jmol.modelkit.ModelKitPopup; 37 import org.jmol.popup.PopupResource; 38 39 public class AwtModelKitPopup extends ModelKitPopup { 40 AwtModelKitPopup()41 public AwtModelKitPopup() { 42 helper = new AwtPopupHelper(this); 43 } 44 45 @Override addMenu(final String id, final String item, final SC subMenu, String label, final PopupResource popupResourceBundle)46 protected void addMenu(final String id, final String item, final SC subMenu, String label, 47 final PopupResource popupResourceBundle) { 48 49 final AwtSwingComponent c = (AwtSwingComponent) subMenu; 50 c.deferred = true; 51 c.jm.addMenuListener(new MenuListener() { 52 53 @Override 54 public void menuSelected(MenuEvent e) { 55 if (c.deferred) { 56 c.deferred = false; 57 if (item.indexOf("Computed") < 0) 58 addMenuItems(id, item, subMenu, popupResourceBundle); 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 updateAwtMenus(String item)74 protected void updateAwtMenus(String item) { 75 if (item.equals("xtalOp!PersistMenu")) { 76 lastModelSet = null; 77 jpiUpdateComputedMenus(); 78 } else { 79 updateOperatorMenu(); 80 } 81 } 82 83 84 85 @Override menuShowPopup(SC popup, int x, int y)86 protected void menuShowPopup(SC popup, int x, int y) { 87 try { 88 ((JPopupMenu)((AwtSwingComponent)popup).jc).show((Component) vwr.display, x, y); 89 } catch (Exception e) { 90 // ignore 91 } 92 } 93 94 @Override menuHidePopup(SC popup)95 protected void menuHidePopup(SC popup) { 96 try { 97 ((JPopupMenu)((AwtSwingComponent)popup).jc).setVisible(false); 98 } catch (Exception e) { 99 // ignore 100 } 101 } 102 103 @Override exitBondRotation()104 protected void exitBondRotation() { 105 try { 106 if (bondRotationCheckBox != null) 107 ((JRadioButtonMenuItem) bondRotationCheckBox).setSelected(false); 108 if (prevBondCheckBox != null) 109 ((JRadioButtonMenuItem) prevBondCheckBox).setSelected(true); 110 } catch (Exception e) { 111 // ignore 112 } 113 super.exitBondRotation(); 114 } 115 116 117 @Override getImageIcon(String fileName)118 protected Object getImageIcon(String fileName) { 119 String imageName = "org/jmol/modelkit/images/" + fileName; 120 URL imageUrl = this.getClass().getClassLoader().getResource(imageName); 121 return (imageUrl == null ? null : new ImageIcon(imageUrl)); 122 } 123 124 } 125