Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » HyperLink, setEnabled and it's visual response
HyperLink, setEnabled and it's visual response [message #333846] Thu, 08 January 2009 19:31 Go to next message
Philipp Simon is currently offline Philipp SimonFriend
Messages: 26
Registered: July 2009
Junior Member
Hi,

when disabling an eclipse forms HyperLink the only visible response i get
is that the hoover icon for the mousepointer stops to appear ( so
basically the funcionality is gone). Though there does not seem to happen
some other way of coloring to make clear that this link is disabled and
not just "broken". Since all other widgets have some sort of feedback when
disabling them (e.g. buttons and combos becoming grayish) i wonder if
there has to be something additional done which i overlook. Adding it to a
Hyperlinkgroup does not help :).

Of course there is the possibility to set a foreground color by hand when
disabling, but i wonder which one should be used to make sure one does not
get strange look and feels on other platforms/themes. The SWT and JFace
constants don't seem to offer a suitable Color here.

Any help very much appreciated!

Thanks,
Philipp
Re: HyperLink, setEnabled and it's visual response [message #333853 is a reply to message #333846] Fri, 09 January 2009 14:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 1/8/2009 2:31 PM, Philipp Simon wrote:
> Hi,
>
> when disabling an eclipse forms HyperLink the only visible response i
> get is that the hoover icon for the mousepointer stops to appear ( so
> basically the funcionality is gone). Though there does not seem to
> happen some other way of coloring to make clear that this link is
> disabled and not just "broken". Since all other widgets have some sort
> of feedback when disabling them (e.g. buttons and combos becoming
> grayish) i wonder if there has to be something additional done which i
> overlook. Adding it to a Hyperlinkgroup does not help :).
>
> Of course there is the possibility to set a foreground color by hand
> when disabling, but i wonder which one should be used to make sure one
> does not get strange look and feels on other platforms/themes. The SWT
> and JFace constants don't seem to offer a suitable Color here.
>
> Any help very much appreciated!

I often use a org.eclipse.swt.widgets.Link instead of a Hyperlink, for
that and other reasons.

Hope this helps,
Eric
Re: HyperLink, setEnabled and it's visual response [message #333856 is a reply to message #333853] Fri, 09 January 2009 19:04 Go to previous messageGo to next message
Philipp Simon is currently offline Philipp SimonFriend
Messages: 26
Registered: July 2009
Junior Member
the problem with the swt link widget in this case is that it is missing
the ability to influence underline/hover behaviour (correct me if i'm
wrong). Many thanks for the pointer though!

Any other ideas?

Thanks,
Philipp
Re: HyperLink, setEnabled and it's visual response [message #333858 is a reply to message #333856] Fri, 09 January 2009 20:13 Go to previous messageGo to next message
Philipp Simon is currently offline Philipp SimonFriend
Messages: 26
Registered: July 2009
Junior Member
Hi,

i did some checks on how text disabled rendering is usually done on other
widgets ( on gtk winxp and win2k and normal + high contrast) and all these
cases it's paint text in white one pixel right and down and paint text in
dark gray on normal location. Therefore my current solution is something
like this:

link = new ImageHyperlink(parent, SWT.WRAP){
@Override
protected void paintText(GC gc, Rectangle bounds) {
if(!getEnabled()){
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COL OR_WHITE));
gc.drawText(getText(), bounds.x+1, bounds.y +1);
link.setForeground(Display.getCurrent().getSystemColor(SWT.C OLOR_DARK_GRAY));
}
super.paintText(gc, bounds);
}
};

Seems to work reasonably though on white background the result is of
course only gray. I wonder if a feature enhancement request for the
Hyperlink class would make sense, or if the missing disabled behaviour is
in there by design.

Thanks,
Philipp
Re: HyperLink, setEnabled and it's visual response [message #333879 is a reply to message #333858] Mon, 12 January 2009 13:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 1/9/2009 3:13 PM, Philipp Simon wrote:
> Hi,
>
> i did some checks on how text disabled rendering is usually done on
> other widgets ( on gtk winxp and win2k and normal + high contrast) and
> all these cases it's paint text in white one pixel right and down and
> paint text in dark gray on normal location. Therefore my current
> solution is something like this:
>
> link = new ImageHyperlink(parent, SWT.WRAP){
> @Override
> protected void paintText(GC gc, Rectangle bounds) {
> if(!getEnabled()){
> gc.setForeground(Display.getCurrent().getSystemColor(SWT.COL OR_WHITE));
> gc.drawText(getText(), bounds.x+1, bounds.y +1);
> link.setForeground(Display.getCurrent().getSystemColor(SWT.C OLOR_DARK_GRAY));
>
> }
> super.paintText(gc, bounds);
> }
> };
>
> Seems to work reasonably though on white background the result is of
> course only gray. I wonder if a feature enhancement request for the
> Hyperlink class would make sense, or if the missing disabled behaviour
> is in there by design.

I'd suggest you enter a bug report against Eclipse > Platform > User
Assistance component and attach your code. Best would be to get the
latest code from CVS and create a patch to Hyperlink with your change
added to it.

Hope this helps,
Eric
Re: HyperLink, setEnabled and it's visual response [message #489949 is a reply to message #333858] Tue, 06 October 2009 15:08 Go to previous messageGo to next message
Woody Zenfell III is currently offline Woody Zenfell IIIFriend
Messages: 1
Registered: October 2009
Junior Member
I expanded on the code above (thanks!) to better update dynamically when setEnabled() is called. It also now uses the Hyperlink's Display instead of the "current" Display . . . I don't really know whether this makes any difference in practice, but it feels better ("buy local").

I also make decisions based on isEnabled(), which according to the docs takes into consideration the enablement of the whole hierarchy, rather than getEnabled(), which according to the docs is a setting just for this control. Again, I don't know whether this is important. Also, the code seems slightly inaccurate in that we only call redraw() when this control's setEnabled() is called (and not, presumably, when a parent control's enablement changes). But I didn't see a suitable "enablement listener" that I could add.

	Hyperlink hyperlink = new Hyperlink(composite, SWT.NONE) {
		@Override
		public Color getForeground() {
			return isEnabled() ? super.getForeground() : getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
		}

		@Override
		protected void paintText(GC gc, Rectangle bounds) {
			if (!isEnabled()) {
				gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
				gc.drawText(getText(), bounds.x + 1, bounds.y + 1);
			}
			super.paintText(gc, bounds);
		}

		@Override
		public void setEnabled(boolean enabled) {
			super.setEnabled(enabled);
			redraw();
		}
	};


I should indicate I'm using Eclipse RCP version 3.2.2 on Windows XP Professional Version 2002 SP 3, in case that matters. This rendering technique looks fine for my hyperlinks, which are in a view (grey background) and are added to a HyperlinkGroup.

Woody

[Updated on: Tue, 06 October 2009 15:10]

Report message to a moderator

Re: HyperLink, setEnabled and it's visual response [message #538362 is a reply to message #333846] Mon, 07 June 2010 13:15 Go to previous messageGo to next message
Bogdan B. is currently offline Bogdan B.Friend
Messages: 50
Registered: July 2009
Member
Hi,

when starting my application with an Eclipse 3.5 target, then the texts and icons of my disabled ImageHyperlinks are automatically "greyed".
But when starting it with a 3.4 target (I have to make it backwards compatible), than just as you said, only the hover mouse pointer is removed, the icons and text foregrounds stay the same as in the "enabled" state.
Your solution treats only the text foreground. Have you also found one for the icons, (without having to provide and manually set a "disabled" version for each one of them)?
Re: HyperLink, setEnabled and it's visual response [message #538471 is a reply to message #333846] Mon, 07 June 2010 16:56 Go to previous message
Bogdan B. is currently offline Bogdan B.Friend
Messages: 50
Registered: July 2009
Member
Got one solution that works for images (could be of course merged with the previously listed solution for the text foreground), didn't test it too much though.
Do you see any problems?

new ImageHyperlink(hyperlinkParent, style) {

                    private Image enabledImage;
                    private DisposeListener disposeListener;

                    @Override
                    public void setEnabled(boolean enabled) {
                        if (enabled != getEnabled()) {
                            setEnabledImage(enabled);
                        }
                        super.setEnabled(enabled);
                        redraw();
                    }

                    @Override
                    public void setImage(Image image) {
                        enabledImage = image;
                        setEnabledImage(isEnabled());
                    }

                    private void setEnabledImage(boolean enabled) {
                        if (enabledImage != null) {
                            if (enabled) {
                                // image previously disabled --> enable it
                                if (disposeListener != null) {
                                    removeDisposeListener(disposeListener);
                                }
                                if (getImage() != null && !getImage().isDisposed()) {
                                    getImage().dispose();
                                }
                                super.setImage(enabledImage);
                            } else {
                                // image previously enabled --> disable it
                                final Image[] disabledImage = new Image[1];
                                disabledImage[0] = new Image(enabledImage.getDevice(), enabledImage, SWT.IMAGE_DISABLE);
                                disposeListener = new DisposeListener() {

                                    public void widgetDisposed(DisposeEvent e) {
                                        if (disabledImage[0] != null && !disabledImage[0].isDisposed()) {
                                            disabledImage[0].dispose();
                                        }
                                    }
                                };
                                addDisposeListener(disposeListener);
                                super.setImage(disabledImage[0]);
                            }
                        }
                    }
                };
                return hyperlink;
            }
        }

[Updated on: Mon, 07 June 2010 16:59]

Report message to a moderator

Previous Topic:finding classes (in eclipse) compiled into memory - which classloader?
Next Topic:Starting Equinox OSGI environment
Goto Forum:
  


Current Time: Thu Mar 28 09:50:28 GMT 2024

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

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

Back to the top