]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/ui/IComboBox.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / 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("<html>Double Click to add an entry, then finish by press ENTER.<br>"
96 + "Selecting DELETE will remove selected entry.</html>");
97 }
98
99 public void keyPressed(KeyEvent arg0) {
100 // TODO Auto-generated method stub
101 }
102
103 /* (non-Javadoc)
104 * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
105 *
106 * Override keyReleased to listen key action
107 *
108 */
109 public void keyReleased(KeyEvent arg0) {
110 //
111 //Add new item to list when press ENTER
112 //
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);
119 }
120 } else {
121 this.addItem(strCurrentText);
122 this.setSelectedItem(strCurrentText);
123 }
124 this.setEditable(false);
125 }
126
127 if (arg0.getKeyCode() == KeyEvent.VK_ESCAPE) {
128 closeEdit();
129 }
130 }
131
132 if (arg0.getSource() == this) {
133 //
134 //Remove item from the list when press DEL
135 //
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);
142 } else {
143 this.removeAllItems();
144 }
145 }
146 }
147 }
148 }
149
150 public void keyTyped(KeyEvent arg0) {
151 // TODO Auto-generated method stub
152 }
153
154 /* (non-Javadoc)
155 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
156 *
157 * Override mouseClicked to enter edit mode when double click mouse
158 *
159 */
160 public void mouseClicked(MouseEvent arg0) {
161 if (arg0.getClickCount() == 2) {
162 this.setEditable(true);
163 this.getEditor().setItem("");
164 }
165 }
166
167 public void mouseEntered(MouseEvent arg0) {
168 // TODO Auto-generated method stub
169
170 }
171
172 public void mouseExited(MouseEvent arg0) {
173 // TODO Auto-generated method stub
174
175 }
176
177 public void mousePressed(MouseEvent arg0) {
178 // TODO Auto-generated method stub
179
180 }
181
182 public void mouseReleased(MouseEvent arg0) {
183 // TODO Auto-generated method stub
184
185 }
186
187 /**
188 Exit edit mode
189
190 **/
191 private void closeEdit() {
192 this.setEditable(false);
193 this.getEditor().setItem("");
194 }
195 }