1 19 20 package org.apache.excalibur.instrument.client; 21 22 import java.awt.Container ; 23 import java.awt.Dimension ; 24 import java.awt.Point ; 25 import java.awt.Toolkit ; 26 27 import javax.swing.Action ; 28 import javax.swing.JMenu ; 29 import javax.swing.JPopupMenu ; 30 31 39 public class LargeMenu 40 extends JMenu 41 { 42 45 48 public LargeMenu() 49 { 50 super(); 51 } 52 53 59 public LargeMenu( String s ) 60 { 61 super( s ); 62 } 63 64 69 public LargeMenu( Action a ) 70 { 71 super( a ); 72 } 73 74 81 public LargeMenu( String s, boolean b ) 82 { 83 super( s, b ); 84 } 85 86 89 98 protected Point getPopupMenuOrigin() 99 { 100 int x = 0; 101 int y = 0; 102 JPopupMenu pm = getPopupMenu(); 103 Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize(); 105 Dimension s = getSize(); 106 Dimension pmSize = pm.getSize(); 107 if (pmSize.width==0) 110 { 111 pmSize = pm.getPreferredSize(); 112 } 113 Point position = getLocationOnScreen(); 114 115 Container parent = getParent(); 116 if (parent instanceof JPopupMenu ) 117 { 118 120 if (position.x+s.width + pmSize.width < screenSize.width) 123 { 124 x = s.width; } 126 else 127 { 128 x = 0-pmSize.width; } 130 131 if (position.y+pmSize.height < screenSize.height) 133 { 134 y = 0; } 136 else 137 { 138 144 if ( position.y + s.height - pmSize.height >= 0 ) 146 { 147 y = s.height - pmSize.height; 149 } 150 else 151 { 152 y = 0 - position.y; 155 } 156 } 157 } else { 158 160 if (position.x+pmSize.width < screenSize.width) { 163 x = 0; } else { 165 x = s.width-pmSize.width; } 167 168 if (position.y+s.height+pmSize.height < screenSize.height) { 170 y = s.height; } else { 172 178 if ( position.y - pmSize.height >= 0 ) 180 { 181 y = 0 - pmSize.height; 183 } 184 else 185 { 186 y = 0 - position.y; 189 } 190 } 191 } 192 return new Point (x,y); 193 } 194 } 195 | Popular Tags |