Mercurial > projects > dwt-samples
view jface/user/Decoration.d @ 147:5f508f322464
more JFace examples
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 16 Aug 2008 13:21:55 +0200 |
parents | |
children |
line wrap: on
line source
module user.Decoration; import tango.util.log.Trace; import dwt.dwthelper.utils; import dwt.DWT; import dwt.layout.GridLayout; import dwt.layout.GridData; import dwt.graphics.Image; import dwt.widgets.Text; import dwt.widgets.Control; import dwt.widgets.Composite; import dwt.widgets.Group; import dwt.widgets.Display; import dwt.widgets.Shell; import dwt.widgets.Listener; import dwt.widgets.Event; import dwtx.jface.bindings.keys.KeyStroke; import dwtx.jface.dialogs.TitleAreaDialog; import dwtx.jface.dialogs.IDialogConstants; import dwtx.jface.dialogs.IMessageProvider; import dwtx.jface.dialogs.Dialog; import dwtx.jface.resource.JFaceResources; import dwtx.jface.fieldassist.FieldDecorationRegistry; import dwtx.jface.fieldassist.FieldDecoration; import dwtx.jface.fieldassist.DecoratedField; import dwtx.jface.fieldassist.TextControlCreator; import dwtx.jface.fieldassist.ContentProposalAdapter; import dwtx.jface.fieldassist.TextContentAdapter; import dwtx.jface.fieldassist.SimpleContentProposalProvider; import dwtx.jface.fieldassist.IContentProposal; import dwtx.jface.viewers.ILabelProvider; import dwtx.jface.viewers.ILabelProviderListener; version(JIVE) import jive.stacktrace; class MyDialog : TitleAreaDialog { private DecoratedField textField; private uint step; private FieldDecoration[] decos; this( Shell parent ){ super(parent); } protected Control createContents(Composite parent) { Control contents = super.createContents(parent); setTitle("Show Decoration"); setMessage("Type into the text field to change the decoration", IMessageProvider.INFORMATION); return contents; } protected Control createDialogArea(Composite parent) { Composite comp = new Composite(parent, DWT.NONE); comp.setLayoutData(new GridData(GridData.FILL_BOTH)); comp.setLayout(new GridLayout(1, false)); auto registry = FieldDecorationRegistry.getDefault(); decos ~= registry.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL ); decos ~= registry.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR ); decos ~= registry.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR_QUICKFIX ); decos ~= registry.getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION ); decos ~= registry.getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED ); decos ~= registry.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING ); decos ~= null; with( textField = new DecoratedField(comp, DWT.BORDER, new TextControlCreator())){ addFieldDecoration( decos[0], DWT.TOP | DWT.LEFT, false); getLayoutControl().setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); auto text = cast(Text)getControl(); assert(text); text.addListener(DWT.Verify, dgListener(&handleVerify)); } Text text; with( text = new Text( comp, DWT.BORDER )){ auto gd = new GridData( GridData.FILL, GridData.VERTICAL_ALIGN_CENTER, true, false ); gd.horizontalIndent = registry.getMaximumDecorationWidth(); setLayoutData( gd ); setText( "without Decoration" ); } ContentProposalAdapter adapter = new ContentProposalAdapter( text, new TextContentAdapter(), new SimpleContentProposalProvider([ "The very first proposal"[], "second proposal", "and a last one"]), KeyStroke.getInstance(DWT.CTRL, ' '), null); adapter.setLabelProvider( new class ILabelProvider { uint idx; Image getImage(Object element){ idx++; switch(idx % 4){ case 0: return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO); case 1: return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING); case 2: return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR); case 3: return JFaceResources.getImage(Dialog.DLG_IMG_HELP); default: return null; } } String getText(Object element){ return (cast(IContentProposal)element).getContent(); } void addListener(ILabelProviderListener listener){} void dispose(){} bool isLabelProperty(Object element, String property){ return true; } void removeListener(ILabelProviderListener listener){} }); return comp; } private void handleVerify(Event e){ FieldDecoration deco; deco = decos[ step % decos.length ]; if( deco ){ textField.hideDecoration(deco); } step++; deco = decos[ step % decos.length ]; if( deco ){ textField.addFieldDecoration( deco, DWT.TOP | DWT.LEFT, false); } } protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); } } void main(){ auto d = new Display(); (new MyDialog(null)).open(); }