KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > valueeditors > integer > IntegerDialog


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.valueeditors.integer;
22
23
24 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsActivator;
25 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsConstants;
26 import org.eclipse.jface.dialogs.Dialog;
27 import org.eclipse.jface.dialogs.IDialogConstants;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.Shell;
34 import org.eclipse.swt.widgets.Spinner;
35
36
37 /**
38  * This class provides a dialog to enter or choose an integer.
39  *
40  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
41  * @version $Rev$, $Date$
42  */

43 public class IntegerDialog extends Dialog
44 {
45
46     /** The dialog title */
47     public static final String JavaDoc DIALOG_TITLE = "Integer Editor";
48
49     /** The initial value. */
50     private int initialValue;
51
52     /** The return value. */
53     private int returnValue;
54
55     /** The spinner to select an integer */
56     private Spinner spinner = null;
57
58
59     /**
60      * Creates a new instance of IntegerDialog.
61      *
62      * @param parentShell the parent shell
63      * @param initialValue the initial value
64      */

65     public IntegerDialog( Shell parentShell, int initialValue )
66     {
67         super( parentShell );
68         super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
69         this.initialValue = initialValue;
70         this.returnValue = -1;
71     }
72
73
74     /**
75      * {@inheritDoc}
76      */

77     protected void configureShell( Shell shell )
78     {
79         super.configureShell( shell );
80         shell.setText( DIALOG_TITLE );
81         shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_INTEGEREDITOR ) );
82     }
83
84
85     /**
86      * {@inheritDoc}
87      */

88     protected void createButtonsForButtonBar( Composite parent )
89     {
90         createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
91         createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
92     }
93
94
95     /**
96      * {@inheritDoc}
97      */

98     protected void okPressed()
99     {
100         returnValue = spinner.getSelection();
101         super.okPressed();
102     }
103
104
105     /**
106      * {@inheritDoc}
107      */

108     protected Control createDialogArea( Composite parent )
109     {
110         // create composite
111
Composite composite = ( Composite ) super.createDialogArea( parent );
112         composite.setLayout( new GridLayout() );
113         GridData gd = new GridData( GridData.FILL_BOTH );
114         composite.setLayoutData( gd );
115
116         spinner = new Spinner( composite, SWT.BORDER );
117         spinner.setMinimum( 0 );
118         spinner.setMaximum( Integer.MAX_VALUE );
119         spinner.setDigits( 0 );
120         spinner.setIncrement( 1 );
121         spinner.setPageIncrement( 100 );
122         spinner.setSelection( initialValue );
123         spinner.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
124
125         applyDialogFont( composite );
126         return composite;
127     }
128
129
130     /**
131      * Gets the integer.
132      *
133      * @return the integer
134      */

135     public int getInteger()
136     {
137         return returnValue;
138     }
139 }
140
Popular Tags