KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > motif > MotifPopupMenuUI


1 /*
2  * @(#)MotifPopupMenuUI.java 1.25 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

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 JavaDoc;
15 import java.awt.Component JavaDoc;
16 import java.awt.Container JavaDoc;
17 import java.awt.Dimension JavaDoc;
18 import java.awt.Font JavaDoc;
19 import java.awt.FontMetrics JavaDoc;
20 import java.awt.Frame JavaDoc;
21 import java.awt.Graphics JavaDoc;
22 import java.awt.Insets JavaDoc;
23 import java.awt.LayoutManager JavaDoc;
24 import java.awt.Point JavaDoc;
25 import java.awt.Rectangle JavaDoc;
26 import java.awt.event.*;
27 import javax.swing.plaf.*;
28 import javax.swing.plaf.basic.BasicPopupMenuUI JavaDoc;
29
30
31 /**
32  * A Motif L&F implementation of PopupMenuUI.
33  * <p>
34  * <strong>Warning:</strong>
35  * Serialized objects of this class will not be compatible with
36  * future Swing releases. The current serialization support is appropriate
37  * for short term storage or RMI between applications running the same
38  * version of Swing. A future release of Swing will provide support for
39  * long term persistence.
40  *
41  * @version 1.25 12/19/03
42  * @author Georges Saab
43  * @author Rich Schiavi
44  */

45 public class MotifPopupMenuUI extends BasicPopupMenuUI JavaDoc {
46     private static Border border = null;
47     private Font JavaDoc titleFont = null;
48
49     public static ComponentUI createUI(JComponent x) {
50     return new MotifPopupMenuUI();
51     }
52
53     /* This has to deal with the fact that the title may be wider than
54        the widest child component.
55        */

56     public Dimension JavaDoc getPreferredSize(JComponent c) {
57     LayoutManager JavaDoc layout = c.getLayout();
58     Dimension JavaDoc d = layout.preferredLayoutSize(c);
59     String JavaDoc title = ((JPopupMenu)c).getLabel();
60     if (titleFont == null) {
61         UIDefaults table = UIManager.getLookAndFeelDefaults();
62         titleFont = table.getFont("PopupMenu.font");
63     }
64     FontMetrics JavaDoc 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 JavaDoc 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