001: /*
002: * @(#)AutoCompletionComboBox.java 7/24/2005
003: *
004: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.swing;
007:
008: import javax.swing.*;
009: import java.util.Vector;
010:
011: /**
012: * An auto completion combobox. It used {@link AutoCompletion} to make the combobox auto-completing.
013: * You can use {@link AutoCompletion} directly to make any combobox auto-completing. This class
014: * is just a convenient class if all you need is an auto complete combobox.
015: * <p/>
016: * Since auto-complete has to listen to the key user types, it has to be editable. If you want to limit user
017: * to the list available in the combobox model, you can call {@link #setStrict(boolean)} and set it to true.
018: */
019: public class AutoCompletionComboBox extends JComboBox {
020: protected AutoCompletion _autoCompletion;
021:
022: public AutoCompletionComboBox() {
023: initComponents();
024: }
025:
026: public AutoCompletionComboBox(Vector<?> items) {
027: super (items);
028: initComponents();
029: }
030:
031: public AutoCompletionComboBox(final Object items[]) {
032: super (items);
033: initComponents();
034: }
035:
036: public AutoCompletionComboBox(ComboBoxModel aModel) {
037: super (aModel);
038: initComponents();
039: }
040:
041: protected void initComponents() {
042: setEditable(true);
043: _autoCompletion = createAutoCompletion();
044: }
045:
046: /**
047: * Creates the <code>AutoCompletion</code>.
048: *
049: * @return the <code>AutoCompletion</code>.
050: */
051: protected AutoCompletion createAutoCompletion() {
052: return new AutoCompletion(this );
053: }
054:
055: /**
056: * Gets the strict property.
057: *
058: * @return the value of strict property.
059: */
060: public boolean isStrict() {
061: return getAutoCompletion().isStrict();
062: }
063:
064: /**
065: * Sets the strict property. If true, it will not allow user to type in anything
066: * that is not in the known item list. If false, user can type in whatever he/she wants. If the text
067: * can match with a item in the known item list, it will still auto-complete.
068: *
069: * @param strict true or false.
070: */
071: public void setStrict(boolean strict) {
072: getAutoCompletion().setStrict(strict);
073: }
074:
075: /**
076: * Gets the strict completion property.
077: *
078: * @return the value of strict completion property.
079: * @see #setStrictCompletion(boolean)
080: */
081: public boolean isStrictCompletion() {
082: return getAutoCompletion().isStrictCompletion();
083: }
084:
085: /**
086: * Sets the strict completion property. If true, in case insensitive searching,
087: * it will always use the exact item in the Searchable to replace whatever user types. For example,
088: * when Searchable has an item "Arial" and user types in "AR", if this flag is true, it will autocompleted
089: * as "Arial". If false, it will be autocompleted as "ARial". Of course, this flag will only
090: * make a difference if Searchable is case insensitive.
091: *
092: * @param strictCompletion
093: */
094: public void setStrictCompletion(boolean strictCompletion) {
095: getAutoCompletion().setStrictCompletion(strictCompletion);
096: }
097:
098: /**
099: * Gets the underlying AutoCompletion class.
100: *
101: * @return the underlying AutoCompletion.
102: */
103: public AutoCompletion getAutoCompletion() {
104: return _autoCompletion;
105: }
106:
107: }
|