]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/common/ui/IComboBox.java
3 The file is used to override JComboBox to provides customized interfaces
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 package org
.tianocore
.packaging
.common
.ui
;
17 import java
.awt
.event
.FocusEvent
;
18 import java
.awt
.event
.FocusListener
;
19 import java
.awt
.event
.KeyEvent
;
20 import java
.awt
.event
.KeyListener
;
21 import java
.awt
.event
.MouseEvent
;
22 import java
.awt
.event
.MouseListener
;
24 import javax
.swing
.JComboBox
;
25 import javax
.swing
.JFrame
;
26 import javax
.swing
.JPanel
;
29 The class is used to override JComboBox to provides customized interfaces
30 It extends JComboBox implements KeyListener, MouseListener and FocusListener
32 @since ModuleEditor 1.0
35 public class IComboBox
extends JComboBox
implements KeyListener
, MouseListener
, FocusListener
{
38 /// Define class Serial Version UID
40 private static final long serialVersionUID
= -1940262568168458911L;
42 public void focusGained(FocusEvent arg0
) {
43 // TODO Auto-generated method stub
48 * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
50 * Override focusLost to exit edit mode
53 public void focusLost(FocusEvent arg0
) {
58 Main class, used for test
63 public static void main(String
[] args
) {
64 JFrame jf
= new JFrame();
66 JPanel jp
= new JPanel();
68 IComboBox icb
= new IComboBox();
70 jf
.setContentPane(jp
);
75 This is the default constructor
84 This method initializes this
88 this.setSize(320, 20);
89 this.setEditable(false);
90 this.editor
.addActionListener(this);
91 this.addMouseListener(this);
92 this.addKeyListener(this);
93 this.getEditor().getEditorComponent().addKeyListener(this);
94 this.getEditor().getEditorComponent().addFocusListener(this);
97 public void keyPressed(KeyEvent arg0
) {
98 // TODO Auto-generated method stub
102 * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
104 * Override keyReleased to listen key action
107 public void keyReleased(KeyEvent arg0
) {
109 //Add new item to list when press ENTER
111 if (arg0
.getSource() == this.getEditor().getEditorComponent()) {
112 if (arg0
.getKeyCode() == KeyEvent
.VK_ENTER
) {
113 String strCurrentText
= this.getEditor().getItem().toString().trim();
114 if (strCurrentText
.length() == 0) {
115 if (this.getItemCount() > 0) {
116 this.setSelectedIndex(0);
119 this.addItem(strCurrentText
);
120 this.setSelectedItem(strCurrentText
);
122 this.setEditable(false);
124 if (arg0
.getKeyCode() == KeyEvent
.VK_ESCAPE
) {
129 if (arg0
.getSource() == this) {
131 //Remove item from the list when press DEL
133 if (arg0
.getKeyCode() == KeyEvent
.VK_DELETE
) {
134 int intSelected
= this.getSelectedIndex();
135 if (intSelected
> -1) {
136 this.removeItemAt(this.getSelectedIndex());
137 if (this.getItemCount() > 0) {
138 this.setSelectedIndex(0);
140 this.removeAllItems();
147 public void keyTyped(KeyEvent arg0
) {
148 // TODO Auto-generated method stub
152 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
154 * Override mouseClicked to enter edit mode when double click mouse
157 public void mouseClicked(MouseEvent arg0
) {
158 if (arg0
.getClickCount() == 2) {
159 this.setEditable(true);
160 this.getEditor().setItem("");
165 public void mouseEntered(MouseEvent arg0
) {
166 // TODO Auto-generated method stub
170 public void mouseExited(MouseEvent arg0
) {
171 // TODO Auto-generated method stub
175 public void mousePressed(MouseEvent arg0
) {
176 // TODO Auto-generated method stub
180 public void mouseReleased(MouseEvent arg0
) {
181 // TODO Auto-generated method stub
189 private void closeEdit() {
190 this.setEditable(false);
191 this.getEditor().setItem("");
192 if (this.getItemCount() > 0) {
193 this.setSelectedIndex(0);