View Javadoc

1   /***
2    * CompletionModel.java
3    *
4    * This file is part of the creme library.
5    * The creme library intends to ease the development effort of large
6    * applications by providing easy to use support classes.
7    *
8    * Copyright (C) 2002 Denis Bregeon
9    *
10   * This library is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU Lesser General Public
12   * License as published by the Free Software Foundation; either
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   * Lesser General Public License for more details.
19   *
20   * You should have received a copy of the GNU Lesser General Public
21   * License along with this library; if not, write to the Free Software
22   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23   *
24   * contact information: dbregeon@sourceforge.net
25   */
26  package org.jcreme.swing;
27  
28  import java.beans.PropertyChangeListener;
29  import java.text.Format;
30  import java.util.Collection;
31  
32  /***
33   * This interface describes the method available to handle a completion task.
34   * The completion is based on a completion pattern (a suffix and a prefix) that
35   * will be matched to the possible completions. The completion works on any
36   * object provided they can be transformed into Strings using a Format class
37   * (Files for instance).
38   * 
39   * @author $Author: dbregeon $
40   * @version $Revision: 1.2 $
41   */
42  public interface CompletionModel {
43      /***
44       * The property name for the completionListElementFormat.
45       */
46      static final String COMPLETION_LIST_ELEMENT_FORMAT_PROPERTY = "completionListElementFormat";
47  
48      /***
49       * Enables to change the pattern that will be matched in front of the text
50       * to complete.
51       * 
52       * @param prefix
53       *            a pattern using % and ? as wildcards in the usual SQL manner.
54       */
55      void setCompletionPrefix(String prefix);
56  
57      /***
58       * Gives access to the current prefix of the completion pattern.
59       * 
60       * @return the current prefix used.
61       */
62      String getCompletionPrefix();
63  
64      /***
65       * Enables to change the pattern that will be matched in after the text to
66       * complete.
67       * 
68       * @param suffix
69       *            a pattern using % and ? as wildcards in the usual SQL manner.
70       */
71      void setCompletionSuffix(String suffix);
72  
73      /***
74       * Gives access to the current suffix of the completion pattern.
75       * 
76       * @return the current suffix used.
77       */
78      String getCompletionSuffix();
79  
80      /***
81       * This method enables to set the collection of values from which to look
82       * for a completion. The collection can contain Objects of different types
83       * (not necessarily Strings) as long as the completionListElementFormat can
84       * handle them.
85       * 
86       * @param c
87       *            the collection from which a completion has to be found.
88       */
89      void setCompletionList(Collection c);
90  
91      /***
92       * This method enables to change the Format implementation that will be used
93       * to transform non String objects into Strings to perform the completion.
94       * 
95       * @param f
96       *            a Format implementation.
97       */
98      void setCompletionListElementFormat(Format f);
99  
100     /***
101      * This method gives access to the Format implementation that enables to
102      * perform the completion on objects.
103      * 
104      * @return the Format implementation currently in use.
105      */
106     Format getCompletionListElementFormat();
107 
108     /***
109      * Enables to access a list of possible completions for a given String.
110      * 
111      * @param seed
112      *            the String to complete in the completionList.
113      * @return a Collection of possible completions.
114      */
115     Collection getCompletions(String seed);
116 
117     /***
118      * This method ensures that the implementations of this interface provide
119      * bean services.
120      * 
121      * @param l
122      *            a listener.
123      */
124     void addPropertyChangeListener(PropertyChangeListener l);
125 
126     /***
127      * This method ensures that the implementations of this interface provide
128      * bean services.
129      * 
130      * @param l
131      *            a listener.
132      */
133     void removePropertyChangeListener(PropertyChangeListener l);
134 }