KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > search > LimitWidget


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.common.widgets.search;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
25 import org.apache.directory.ldapstudio.browser.common.widgets.BrowserWidget;
26 import org.eclipse.swt.events.ModifyEvent;
27 import org.eclipse.swt.events.ModifyListener;
28 import org.eclipse.swt.events.VerifyEvent;
29 import org.eclipse.swt.events.VerifyListener;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Group;
33 import org.eclipse.swt.widgets.Label;
34 import org.eclipse.swt.widgets.Text;
35
36
37 /**
38  * The LimitWidget could be used to select the limits of a connection
39  * or search. It is composed of a group with text input fields.
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class LimitWidget extends BrowserWidget
45 {
46
47     /** The initial count limit. */
48     private int initialCountLimit;
49
50     /** The initial time limit. */
51     private int initialTimeLimit;
52
53     /** The limit group. */
54     private Group limitGroup;
55
56     /** The count limit label. */
57     private Label countLimitLabel;
58
59     /** The count limit text. */
60     private Text countLimitText;
61
62     /** The time limit label. */
63     private Label timeLimitLabel;
64
65     /** The time limit text. */
66     private Text timeLimitText;
67
68
69     /**
70      * Creates a new instance of LimitWidget.
71      *
72      * @param initialTimeLimit the initial time limit
73      * @param initialCountLimit the initial count limit
74      */

75     public LimitWidget( int initialCountLimit, int initialTimeLimit )
76     {
77         this.initialCountLimit = initialCountLimit;
78         this.initialTimeLimit = initialTimeLimit;
79     }
80
81
82     /**
83      * Creates a new instance of LimitWidget with no limits.
84      */

85     public LimitWidget()
86     {
87         this.initialCountLimit = 0;
88         this.initialTimeLimit = 0;
89     }
90
91
92     /**
93      * Creates the widget.
94      *
95      * @param parent the parent
96      */

97     public void createWidget( Composite parent )
98     {
99
100         limitGroup = BaseWidgetUtils.createGroup( parent, "Limits", 1 );
101         GridLayout gl = new GridLayout( 2, false );
102         limitGroup.setLayout( gl );
103
104         // Count limit
105
countLimitLabel = BaseWidgetUtils.createLabel( limitGroup, "&Count Limit:", 1 );
106         countLimitText = BaseWidgetUtils.createText( limitGroup, "", 1 );
107         countLimitText.addVerifyListener( new VerifyListener()
108         {
109             public void verifyText( VerifyEvent e )
110             {
111                 if ( !e.text.matches( "[0-9]*" ) )
112                 {
113                     e.doit = false;
114                 }
115             }
116         } );
117         countLimitText.addModifyListener( new ModifyListener()
118         {
119             public void modifyText( ModifyEvent e )
120             {
121                 notifyListeners();
122             }
123         } );
124
125         // Time limit
126
timeLimitLabel = BaseWidgetUtils.createLabel( limitGroup, "&Time Limit:", 1 );
127         timeLimitText = BaseWidgetUtils.createText( limitGroup, "", 1 );
128         timeLimitText.addVerifyListener( new VerifyListener()
129         {
130             public void verifyText( VerifyEvent e )
131             {
132                 if ( !e.text.matches( "[0-9]*" ) )
133                 {
134                     e.doit = false;
135                 }
136             }
137         } );
138         timeLimitText.addModifyListener( new ModifyListener()
139         {
140             public void modifyText( ModifyEvent e )
141             {
142                 notifyListeners();
143             }
144         } );
145
146         setCountLimit( initialCountLimit );
147         setTimeLimit( initialTimeLimit );
148     }
149
150
151     /**
152      * Sets the count limit.
153      *
154      * @param countLimit the count limit
155      */

156     public void setCountLimit( int countLimit )
157     {
158         initialCountLimit = countLimit;
159         countLimitText.setText( Integer.toString( initialCountLimit ) );
160     }
161
162
163     /**
164      * Sets the time limit.
165      *
166      * @param timeLimit the time limit
167      */

168     public void setTimeLimit( int timeLimit )
169     {
170         initialTimeLimit = timeLimit;
171         timeLimitText.setText( Integer.toString( initialTimeLimit ) );
172     }
173
174
175     /**
176      * Gets the count limit.
177      *
178      * @return the count limit
179      */

180     public int getCountLimit()
181     {
182         int countLimit;
183         try
184         {
185             countLimit = new Integer JavaDoc( countLimitText.getText() ).intValue();
186         }
187         catch ( NumberFormatException JavaDoc e )
188         {
189             countLimit = 0;
190         }
191         return countLimit;
192     }
193
194
195     /**
196      * Gets the time limit.
197      *
198      * @return the time limit
199      */

200     public int getTimeLimit()
201     {
202         int timeLimit;
203         try
204         {
205             timeLimit = new Integer JavaDoc( timeLimitText.getText() ).intValue();
206         }
207         catch ( NumberFormatException JavaDoc e )
208         {
209             timeLimit = 0;
210         }
211         return timeLimit;
212     }
213
214
215     /**
216      * Sets the enabled state of the widget.
217      *
218      * @param b true to enable the widget, false to disable the widget
219      */

220     public void setEnabled( boolean b )
221     {
222         limitGroup.setEnabled( b );
223         countLimitLabel.setEnabled( b );
224         countLimitText.setEnabled( b );
225         timeLimitLabel.setEnabled( b );
226         timeLimitText.setEnabled( b );
227     }
228
229 }
230
Popular Tags