]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/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("<html>Double Click to add an entry, then finish by press ENTER.<br>"
96 + "Selecting DELETE will remove selected entry.</html>");
99 public void keyPressed(KeyEvent arg0
) {
100 // TODO Auto-generated method stub
104 * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
106 * Override keyReleased to listen key action
109 public void keyReleased(KeyEvent arg0
) {
111 //Add new item to list when press ENTER
113 if (arg0
.getSource() == this.getEditor().getEditorComponent()) {
114 if (arg0
.getKeyCode() == KeyEvent
.VK_ENTER
) {
115 String strCurrentText
= this.getEditor().getItem().toString().trim();
116 if (strCurrentText
.length() == 0) {
117 if (this.getItemCount() > 0) {
118 this.setSelectedIndex(0);
121 this.addItem(strCurrentText
);
122 this.setSelectedItem(strCurrentText
);
124 this.setEditable(false);
127 if (arg0
.getKeyCode() == KeyEvent
.VK_ESCAPE
) {
132 if (arg0
.getSource() == this) {
134 //Remove item from the list when press DEL
136 if (arg0
.getKeyCode() == KeyEvent
.VK_DELETE
) {
137 int intSelected
= this.getSelectedIndex();
138 if (intSelected
> -1) {
139 this.removeItemAt(this.getSelectedIndex());
140 if (this.getItemCount() > 0) {
141 this.setSelectedIndex(0);
143 this.removeAllItems();
150 public void keyTyped(KeyEvent arg0
) {
151 // TODO Auto-generated method stub
155 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
157 * Override mouseClicked to enter edit mode when double click mouse
160 public void mouseClicked(MouseEvent arg0
) {
161 if (arg0
.getClickCount() == 2) {
162 this.setEditable(true);
163 this.getEditor().setItem("");
167 public void mouseEntered(MouseEvent arg0
) {
168 // TODO Auto-generated method stub
172 public void mouseExited(MouseEvent arg0
) {
173 // TODO Auto-generated method stub
177 public void mousePressed(MouseEvent arg0
) {
178 // TODO Auto-generated method stub
182 public void mouseReleased(MouseEvent arg0
) {
183 // TODO Auto-generated method stub
191 private void closeEdit() {
192 this.setEditable(false);
193 this.getEditor().setItem("");