1 7 8 package com.sun.java.swing.plaf.motif; 9 10 import com.sun.java.swing.SwingUtilities2; 11 import javax.swing.*; 12 import javax.swing.event.*; 13 import javax.swing.border.*; 14 import java.awt.Color ; 15 import java.awt.Component ; 16 import java.awt.Container ; 17 import java.awt.Dimension ; 18 import java.awt.Font ; 19 import java.awt.FontMetrics ; 20 import java.awt.Frame ; 21 import java.awt.Graphics ; 22 import java.awt.Insets ; 23 import java.awt.LayoutManager ; 24 import java.awt.Point ; 25 import java.awt.Rectangle ; 26 import java.awt.event.*; 27 import javax.swing.plaf.*; 28 import javax.swing.plaf.basic.BasicPopupMenuUI ; 29 30 31 45 public class MotifPopupMenuUI extends BasicPopupMenuUI { 46 private static Border border = null; 47 private Font titleFont = null; 48 49 public static ComponentUI createUI(JComponent x) { 50 return new MotifPopupMenuUI(); 51 } 52 53 56 public Dimension getPreferredSize(JComponent c) { 57 LayoutManager layout = c.getLayout(); 58 Dimension d = layout.preferredLayoutSize(c); 59 String title = ((JPopupMenu)c).getLabel(); 60 if (titleFont == null) { 61 UIDefaults table = UIManager.getLookAndFeelDefaults(); 62 titleFont = table.getFont("PopupMenu.font"); 63 } 64 FontMetrics fm = c.getFontMetrics(titleFont); 65 int stringWidth = 0; 66 67 if (title!=null) { 68 stringWidth += SwingUtilities2.stringWidth(c, fm, title); 69 } 70 71 if (d.width < stringWidth) { 72 d.width = stringWidth + 8; 73 Insets i = c.getInsets(); 74 if (i!=null) { 75 d.width += i.left + i.right; 76 } 77 if (border != null) { 78 i = border.getBorderInsets(c); 79 d.width += i.left + i.right; 80 } 81 82 return d; 83 } 84 return null; 85 } 86 87 protected ChangeListener createChangeListener(JPopupMenu m) { 88 return new ChangeListener() { 89 public void stateChanged(ChangeEvent e) {} 90 }; 91 } 92 93 public boolean isPopupTrigger(MouseEvent e) { 94 return ((e.getID()==MouseEvent.MOUSE_PRESSED) 95 && ((e.getModifiers() & MouseEvent.BUTTON3_MASK)!=0)); 96 } 97 } 98 99 100 101 102 | Popular Tags |