KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > valueeditors > address > AddressDialog


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