KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > dialogs > TextDialog


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.dialogs;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
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.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Shell;
33 import org.eclipse.swt.widgets.Text;
34
35
36 public class TextDialog extends Dialog
37 {
38
39     public static final String JavaDoc DIALOG_TITLE = "Text Editor";
40
41     public static final double MAX_WIDTH = 250.0;
42
43     public static final double MAX_HEIGHT = 250.0;
44
45     private String JavaDoc initialValue;
46
47     private String JavaDoc returnValue;
48
49     private Text text;
50
51
52     public TextDialog( Shell parentShell, String JavaDoc initialValue )
53     {
54         super( parentShell );
55         super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
56         this.initialValue = initialValue;
57         this.returnValue = null;
58     }
59
60
61     public boolean close()
62     {
63         return super.close();
64     }
65
66
67     protected void configureShell( Shell shell )
68     {
69         super.configureShell( shell );
70         shell.setText( DIALOG_TITLE );
71         shell.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_TEXTEDITOR ) );
72     }
73
74
75     protected void createButtonsForButtonBar( Composite parent )
76     {
77         createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
78         createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
79     }
80
81
82     protected void okPressed()
83     {
84         this.returnValue = this.text.getText();
85         super.okPressed();
86     }
87
88
89     protected Control createDialogArea( Composite parent )
90     {
91         // create composite
92
Composite composite = ( Composite ) super.createDialogArea( parent );
93         GridData gd = new GridData( GridData.FILL_BOTH );
94         composite.setLayoutData( gd );
95
96         // text widget
97
text = new Text( composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL );
98         text.setText( this.initialValue );
99         // GridData gd = new GridData(GridData.GRAB_HORIZONTAL |
100
// GridData.HORIZONTAL_ALIGN_FILL);
101
gd = new GridData( GridData.FILL_BOTH );
102         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
103         gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 );
104         text.setLayoutData( gd );
105
106         applyDialogFont( composite );
107         return composite;
108     }
109
110
111     public String JavaDoc getText()
112     {
113         return this.returnValue;
114     }
115 }
116
Popular Tags