]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/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
.frameworkwizard
.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
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);
95 this.setToolTipText("Double Click to add an entry and finished by press ENTER. Press DELETE can remove selected entry.");
98 public void keyPressed(KeyEvent arg0
) {
99 // TODO Auto-generated method stub
103 * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
105 * Override keyReleased to listen key action
108 public void keyReleased(KeyEvent arg0
) {
110 //Add new item to list when press ENTER
112 if (arg0
.getSource() == this.getEditor().getEditorComponent()) {
113 if (arg0
.getKeyCode() == KeyEvent
.VK_ENTER
) {
114 String strCurrentText
= this.getEditor().getItem().toString().trim();
115 if (strCurrentText
.length() == 0) {
116 if (this.getItemCount() > 0) {
117 this.setSelectedIndex(0);
120 this.addItem(strCurrentText
);
121 this.setSelectedItem(strCurrentText
);
123 this.setEditable(false);
125 if (arg0
.getKeyCode() == KeyEvent
.VK_ESCAPE
) {
130 if (arg0
.getSource() == this) {
132 //Remove item from the list when press DEL
134 if (arg0
.getKeyCode() == KeyEvent
.VK_DELETE
) {
135 int intSelected
= this.getSelectedIndex();
136 if (intSelected
> -1) {
137 this.removeItemAt(this.getSelectedIndex());
138 if (this.getItemCount() > 0) {
139 this.setSelectedIndex(0);
141 this.removeAllItems();
148 public void keyTyped(KeyEvent arg0
) {
149 // TODO Auto-generated method stub
153 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
155 * Override mouseClicked to enter edit mode when double click mouse
158 public void mouseClicked(MouseEvent arg0
) {
159 if (arg0
.getClickCount() == 2) {
160 this.setEditable(true);
161 this.getEditor().setItem("");
166 public void mouseEntered(MouseEvent arg0
) {
167 // TODO Auto-generated method stub
171 public void mouseExited(MouseEvent arg0
) {
172 // TODO Auto-generated method stub
176 public void mousePressed(MouseEvent arg0
) {
177 // TODO Auto-generated method stub
181 public void mouseReleased(MouseEvent arg0
) {
182 // TODO Auto-generated method stub
190 private void closeEdit() {
191 this.setEditable(false);
192 this.getEditor().setItem("");
193 if (this.getItemCount() > 0) {
194 this.setSelectedIndex(0);