Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to set font color for generated diagram?
icon3.gif  How to set font color for generated diagram? [message #687582] Wed, 22 June 2011 19:21 Go to next message
Vitaly Savickas is currently offline Vitaly Savickas
Messages: 61
Registered: March 2010
Member
Such a simple thing as setting font color for node labels and I don't know how to do it. There are few unanswered posts in the forum, but I can't believe such a basic thing is not supported?! Anyone knows how to do it in gmfgraph or gmfgen, or at least using template modifications? My font color must be the same for all diagram labels.

Regards,
Vitaly
(no subject) [message #687828 is a reply to message #687582] Thu, 23 June 2011 10:19 Go to previous messageGo to next message
Ivar Refsdal is currently offline Ivar Refsdal
Messages: 24
Registered: May 2011
Junior Member
Hi Vitaly,

I am quite new to GMF, so take my answer with some caution,
but anyway:

You can change the default font color in XXXViewProvider.java in the
createXXXX_XXX methods.

If you want the template, it is located in
/org.eclipse.gmf.codegen/templates/xpt/providers/ViewProvider.xpt

Particularly you could look at:

> «DEFINE initFontFromPrefs(String viewVar, String prefStoreVar) FOR gmfgen::GenCommonBase-»
> org.eclipse.gmf.runtime.notation.FontStyle «viewVar»FontStyle = (org.eclipse.gmf.runtime.notation.FontStyle) «viewVar».getStyle(org.eclipse.gmf.runtime.notation.NotationPackage.Literals.FONT_STYLE);
> if («viewVar»FontStyle != null) {«REM»Given this template is invoked only when FontStyle is present, no need to check fontStyle for null, but at least this gives a scope for fontData var«ENDREM»
> org.eclipse.swt.graphics.FontData fontData = org.eclipse.jface.preference.PreferenceConverter.getFontData(«prefStoreVar», org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_DEFAULT_FONT);
> «viewVar»FontStyle.setFontName(fontData.getName());
> «viewVar»FontStyle.setFontHeight(fontData.getHeight());
> «viewVar»FontStyle.setBold((fontData.getStyle() & org.eclipse.swt.SWT.BOLD) != 0);
> «viewVar»FontStyle.setItalic((fontData.getStyle() & org.eclipse.swt.SWT.ITALIC) != 0);
> org.eclipse.swt.graphics.RGB fontRGB = org.eclipse.jface.preference.PreferenceConverter.getColor(«prefStoreVar», org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_FONT_COLOR);
> «viewVar»FontStyle.setFontColor(org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities.RGBToInteger(fontRGB).intValue());
> }
> «ENDDEFINE»

I agree it would be good to have a possibility to specify it in gmfgraph
or gmfgen. I could not find it either..

Best regards,
Ivar


Vitaly Savickas wrote, on 06/22/2011 09:21 PM:
> Such a simple thing as setting font color for node labels and I don't
> know how to do it. There are few unanswered posts in the forum, but I
> can't believe such a basic thing is not supported?! Anyone knows how to
> do it in gmfgraph or gmfgen, or at least using template modifications?
> My font color must be the same for all diagram labels.
>
> Regards,
> Vitaly
Re: (no subject) [message #687874 is a reply to message #687828] Thu, 23 June 2011 12:36 Go to previous messageGo to next message
Vitaly Savickas is currently offline Vitaly Savickas
Messages: 61
Registered: March 2010
Member
Thanks Ivar,

The bit you have shown is only used if some global color preferences are present thus not useful for default diagram. But I have modified the TextAware template i.e. changed provided color to figure's foreground color in setFontColor method definition. Not a clean solution at all, but at least it is persisted on regeneration and the color can be modified now from gmfgraph by setting corresponding foreground color. A better solution would be to extend the gen metamodel and use it in templates, but I don't have the required knowledge. Anyway, I still can't believe there is no facility for such a basic requirement in GMF.

Regards,
Vitaly
Re: (no subject) [message #687896 is a reply to message #687874] Thu, 23 June 2011 13:13 Go to previous message
Ivar Refsdal is currently offline Ivar Refsdal
Messages: 24
Registered: May 2011
Junior Member
Thanks also to you Vitaly,

your solution is far better.
I agree about the lack of such a requirement is not very good.

The GenCommonBase for which the setFontColor method is generated
actually has a styles attribute, so perhaps it's possible to fit it
inside there. I also do not have the knowledge to fix this..
Stadnik and Shatalin were the initial contributors of TextAware.xpt, but
both seems to have left the forums some years ago.

Best
Ivar

Vitaly Savickas wrote, on 06/23/2011 02:36 PM:
> Thanks Ivar,
>
> The bit you have shown is only used if some global color preferences are
> present thus not useful for default diagram. But I have modified the
> TextAware template i.e. changed provided color to figure's foreground
> color in setFontColor method definition. Not a clean solution at all,
> but at least it is persisted on regeneration and the color can be
> modified now from gmfgraph by setting corresponding foreground color. A
> better solution would be to extend the gen metamodel and use it in
> templates, but I don't have the required knowledge. Anyway, I still
> can't believe there is no facility for such a basic requirement in GMF.
>
> Regards,
> Vitaly
Previous Topic:Changing background color and location's node
Next Topic:No GMF Project or artifact wizards in Indigo Modeling
Goto Forum:
  


Current Time: Thu Oct 30 15:25:28 GMT 2014

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

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