1 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 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 initialValue; 46 47 private String returnValue; 48 49 private Text text; 50 51 52 public TextDialog( Shell parentShell, String 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 Composite composite = ( Composite ) super.createDialogArea( parent ); 93 GridData gd = new GridData( GridData.FILL_BOTH ); 94 composite.setLayoutData( gd ); 95 96 text = new Text( composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL ); 98 text.setText( this.initialValue ); 99 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 getText() 112 { 113 return this.returnValue; 114 } 115 } 116 | Popular Tags |