]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/ui/IComboBox.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / ui / IComboBox.java
1 /** @file
2
3 The file is used to override JComboBox to provides customized interfaces
4
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
10
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.
13
14 **/
15 package org.tianocore.frameworkwizard.common.ui;
16
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;
23
24 import javax.swing.JComboBox;
25 import javax.swing.JFrame;
26 import javax.swing.JPanel;
27
28 /**
29 The class is used to override JComboBox to provides customized interfaces
30 It extends JComboBox implements KeyListener, MouseListener and FocusListener
31
32
33
34 **/
35 public class IComboBox extends JComboBox implements KeyListener, MouseListener, FocusListener {
36
37 ///
38 /// Define class Serial Version UID
39 ///
40 private static final long serialVersionUID = -1940262568168458911L;
41
42 public void focusGained(FocusEvent arg0) {
43 // TODO Auto-generated method stub
44
45 }
46
47 /* (non-Javadoc)
48 * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
49 *
50 * Override focusLost to exit edit mode
51 *
52 */
53 public void focusLost(FocusEvent arg0) {
54 this.closeEdit();
55 }
56
57 /**
58 Main class, used for test
59
60 @param args
61
62 **/
63 public static void main(String[] args) {
64 JFrame jf = new JFrame();
65 jf.setSize(500, 200);
66 JPanel jp = new JPanel();
67 jp.setLayout(null);
68 IComboBox icb = new IComboBox();
69 jp.add(icb, null);
70 jf.setContentPane(jp);
71 jf.setVisible(true);
72 }
73
74 /**
75 This is the default constructor
76
77 **/
78 public IComboBox() {
79 super();
80 init();
81 }
82
83 /**
84 This method initializes this
85
86 **/
87 private void init() {
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.");
96 }
97
98 public void keyPressed(KeyEvent arg0) {
99 // TODO Auto-generated method stub
100 }
101
102 /* (non-Javadoc)
103 * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
104 *
105 * Override keyReleased to listen key action
106 *
107 */
108 public void keyReleased(KeyEvent arg0) {
109 //
110 //Add new item to list when press ENTER
111 //
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);
118 }
119 } else {
120 this.addItem(strCurrentText);
121 this.setSelectedItem(strCurrentText);
122 }
123 this.setEditable(false);
124 }
125 if (arg0.getKeyCode() == KeyEvent.VK_ESCAPE) {
126 closeEdit();
127 }
128 }
129
130 if (arg0.getSource() == this) {
131 //
132 //Remove item from the list when press DEL
133 //
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);
140 } else {
141 this.removeAllItems();
142 }
143 }
144 }
145 }
146 }
147
148 public void keyTyped(KeyEvent arg0) {
149 // TODO Auto-generated method stub
150 }
151
152 /* (non-Javadoc)
153 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
154 *
155 * Override mouseClicked to enter edit mode when double click mouse
156 *
157 */
158 public void mouseClicked(MouseEvent arg0) {
159 if (arg0.getClickCount() == 2) {
160 this.setEditable(true);
161 this.getEditor().setItem("");
162 }
163
164 }
165
166 public void mouseEntered(MouseEvent arg0) {
167 // TODO Auto-generated method stub
168
169 }
170
171 public void mouseExited(MouseEvent arg0) {
172 // TODO Auto-generated method stub
173
174 }
175
176 public void mousePressed(MouseEvent arg0) {
177 // TODO Auto-generated method stub
178
179 }
180
181 public void mouseReleased(MouseEvent arg0) {
182 // TODO Auto-generated method stub
183
184 }
185
186 /**
187 Exit edit mode
188
189 **/
190 private void closeEdit() {
191 this.setEditable(false);
192 this.getEditor().setItem("");
193 if (this.getItemCount() > 0) {
194 this.setSelectedIndex(0);
195 }
196 }
197 }