KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > plaf > CompiereComboBoxUI


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.plaf;
15
16 import java.awt.event.MouseListener JavaDoc;
17
18 import javax.swing.Icon JavaDoc;
19 import javax.swing.JButton JavaDoc;
20 import javax.swing.JComponent JavaDoc;
21 import javax.swing.plaf.ComponentUI JavaDoc;
22 import javax.swing.plaf.basic.ComboPopup JavaDoc;
23 import javax.swing.plaf.metal.MetalComboBoxButton JavaDoc;
24 import javax.swing.plaf.metal.MetalComboBoxUI JavaDoc;
25
26
27 /**
28  * Compiere ComboBox UI.
29  * The ComboBox is opaque - with opaque arrow button and textfield background
30  *
31  * @author Jorg Janke
32  * @version $Id: CompiereComboBoxUI.java,v 1.6 2003/09/27 11:08:52 jjanke Exp $
33  */

34 public class CompiereComboBoxUI extends MetalComboBoxUI JavaDoc
35 {
36     /**
37      * Create UI
38      * @param c
39      * @return new instance of CompiereComboBoxUI
40      */

41     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c)
42     {
43         return new CompiereComboBoxUI();
44     } // CreateUI
45

46     /*************************************************************************/
47
48     static int s_no = 0;
49     /**
50      * Install UI - Set ComboBox opaque.
51      * Bug in Metal: arrowButton gets Mouse Events, so add the JComboBox
52      * MouseListeners to the arrowButton
53      * @see CComboBox#addMouseListener(MouseListener)
54      * @param c componrnt
55      */

56     public void installUI (JComponent JavaDoc c)
57     {
58         MouseListener JavaDoc[] ml = c.getMouseListeners();
59         super.installUI(c);
60         c.setOpaque(false);
61         //
62
for (int i = 0; i < ml.length; i++)
63         {
64         // System.out.println("adding " + c.getClass().getName());
65
arrowButton.addMouseListener(ml[i]);
66         }
67
68     } // installUI
69

70     /*************************************************************************/
71
72     /**
73      * Create opaque button
74      * @return opaque button
75      */

76     protected JButton JavaDoc createArrowButton()
77     {
78         JButton JavaDoc button = super.createArrowButton();
79         button.setContentAreaFilled(false);
80         button.setOpaque(false);
81         return button;
82     } // createArrowButton
83

84     public JButton JavaDoc getArrowButton()
85     {
86         return arrowButton;
87     }
88
89     /**
90      * Set Icon of arrow button
91      * @param defaultIcon
92      */

93     public void setIcon(Icon JavaDoc defaultIcon)
94     {
95         ((MetalComboBoxButton JavaDoc)arrowButton).setComboIcon(defaultIcon);
96     } // setIcon
97

98     /*************************************************************************/
99
100     /**
101      * Create Popup
102      * @return CompiereComboPopup
103      */

104     protected ComboPopup JavaDoc createPopup()
105     {
106         CompiereComboPopup newPopup = new CompiereComboPopup( comboBox );
107         newPopup.getAccessibleContext().setAccessibleParent(comboBox);
108         return newPopup;
109     } // createPopup
110

111 } // CompiereComboBoxUI
112
Popular Tags