Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Add border to sourceviewer
Add border to sourceviewer [message #521862] Thu, 18 March 2010 23:27 Go to next message
Lidder is currently offline LidderFriend
Messages: 46
Registered: July 2009
Member
Hello,

I am trying to create a custom sourceViewer widget that I can reuse in my code. I need to add spell checking facility to it. To show the spell errors, I want to use the sourceViewer. Everything works great. The problem I am having is with the UI. I am unable to add SWT.BORDER to the sourceViewer. I read in another thread that "if a vertical ruler is required then the SourceViewer should be added to a Composite whose style bit is set to SWT.BORDER". This works, but the widget does not look elegant. The border is seems out of place ...

http://i39.tinypic.com/ev6khs.jpg

http://i39.tinypic.com/ev6khs.jpg

Is there a way to remove that extra space between the border and the sourceViewer? I am using the following layout for the composite that contains the sourceViewer.

Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));

SourceViewerWithSpellCheck sourceViewer = new SourceViewerWithSpellCheck(composite, style);


I also tried

sourceViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
sourceViewer.getTextWidget().setLayoutData(new GridData(GridData.FILL_BOTH));

But, nothing changed.
Thanks.
Upkar.

Re: Add border to sourceviewer [message #522440 is a reply to message #521862] Mon, 22 March 2010 16:14 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Upkar,

According to SourceViewer's doc, the space to the left of the text viewer is
its annotation presentation area, and the space to its right is its overview
ruler. Are you providing implementations of either of these? If so then
this expains why these spaces are there, the viewer is composed of the
combination of the text editor along with these strips on each side.

In SourceViewer.createControl() I see the following:

protected void createControl(Composite parent, int styles) {
if (fVerticalRuler != null || fOverviewRuler != null) {
styles= (styles & ~SWT.BORDER);
fComposite= new Canvas(parent, SWT.NONE);
fComposite.setLayout(createLayout());
parent= fComposite;
}
super.createControl(parent, styles);
... <snip> ...

The super.createControl() invocation is what ultimately creates the viewer's
text editor, so if you provide an implementation for either the annotation
area or the overview ruler then SWT.BORDER is removed from the styles used
to create it. And since the only time to provide a style bit like
SWT.BORDER is when a control is initially created, I don't think there's a
way to do what you want, unless I'm making a wrong assumption somewhere here
(eg.- you aren't actually providing an implementation for the annotation
area or overview ruler)?

Grant


"Upkar Lidder" <ulidder@gmail.com> wrote in message
news:hnucse$rvl$1@build.eclipse.org...
> Hello,
>
> I am trying to create a custom sourceViewer widget that I can reuse in my
code. I need to add spell checking facility to it. To show the spell errors,
I want to use the sourceViewer. Everything works great. The problem I am
having is with the UI. I am unable to add SWT.BORDER to the sourceViewer. I
read in another thread that "if a vertical ruler is required then the
SourceViewer should be added to a Composite whose style bit is set to
SWT.BORDER". This works, but the widget does not look elegant. The border is
seems out of place ...
>
> http://i39.tinypic.com/ev6khs.jpg
>
>
>
> Is there a way to remove that extra space between the border and the
sourceViewer? I am using the following layout for the composite that
contains the sourceViewer.
>
> Composite composite = new Composite(parent, SWT.BORDER);
> composite.setLayout(new GridLayout());
> composite.setLayoutData(new GridData(GridData.FILL_BOTH));
>
> SourceViewerWithSpellCheck sourceViewer = new
SourceViewerWithSpellCheck(composite, style);
>
>
> I also tried
>
> sourceViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
> sourceViewer.getTextWidget().setLayoutData(new
GridData(GridData.FILL_BOTH));
>
> But, nothing changed.
> Thanks.
> Upkar.
>
>
Re: Add border to sourceviewer [message #522465 is a reply to message #522440] Mon, 22 March 2010 17:38 Go to previous message
Lidder is currently offline LidderFriend
Messages: 46
Registered: July 2009
Member
Hello Grant,

Thanks for your response. I see your logic and will try and look through the swt code in future myself Smile.
I am using the overview ruler to display the spelling mistakes in the text. I however don't need the annotation ruler on the left. I found a method to turn off the annotation ruler.
sourceViewer.showAnnotations(false);

The widget now looks like ...

http://i43.tinypic.com/noiy6b.jpg

It now looks more like the other widgets on the dialog. That is exactly what I want.

Thanks again for your help.
Upkar.
Previous Topic:Composite invisible?
Next Topic:Excel ActiveX DisplayAlerts property
Goto Forum:
  


Current Time: Sun Dec 08 00:13:45 GMT 2024

Powered by FUDForum. Page generated in 0.03280 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top