Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Fill Gradient
Fill Gradient [message #160983] Fri, 16 November 2007 16:04 Go to next message
Eclipse UserFriend
Originally posted by: martinschmidt.83.web.de

Hi,
I want to add background gradient to a rectangle figure. I found some
comments in newsgroup, but i don
Re: Fill Gradient [message #160991 is a reply to message #160983] Fri, 16 November 2007 16:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Please see my thread earlier, it is a relatively simple procedure. You
override the method in the editpart's XYZFigure class. Ex:
XYZ.edit.parts.XYZEditPart -> XYZFigure.

HTH,

Tomas Zijdemans

Martin Schmidt wrote:
> Hi,
> I want to add background gradient to a rectangle figure. I found some
> comments in newsgroup, but i don´t understand it. I don´t know where to
> override the fillShape method :(
> Can somebody give an approach for a beginner?
>
> Regards, Martin
>
>
Re: Fill Gradient [message #161116 is a reply to message #160991] Sun, 18 November 2007 19:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

Hi Tomas,

did you find a solution? I added the following code to the
<whatever>EditPart.java for the <whatever> class inside:


public void paintFigure(Graphics g) {
Rectangle bounds = getPrimaryFigureBounds();

Point topLeft = bounds.getTopLeft();
Point bottomRight = bounds.getBottomRight();
Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x,
topLeft.y, bottomRight.x, bottomRight.y,
ColorConstants.white, ColorConstants.darkBlue);

g.setBackgroundPattern(pattern);
g.fillRectangle(bounds);
}

well, but what should I say ... It didn't work. I am a little bit
surpriced since the following code generates a box (whithout gradient)
as expected:

public void paintFigure(Graphics g) {
// Rectangle bounds = getPrimaryFigureBounds();
//
// Point topLeft = bounds.getTopLeft();
// Point bottomRight = bounds.getBottomRight();
// Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x,
// topLeft.y, bottomRight.x, bottomRight.y,
// ColorConstants.white, ColorConstants.darkBlue);
//
// g.setBackgroundPattern(pattern);

g.fillRectangle(bounds);
}

Maybe someone could shade some light on this, why the pattern does not work.

Regards
Martin


Tomas Zijdemans wrote:
> Please see my thread earlier, it is a relatively simple procedure. You
> override the method in the editpart's XYZFigure class. Ex:
> XYZ.edit.parts.XYZEditPart -> XYZFigure.
>
> HTH,
>
> Tomas Zijdemans
>
> Martin Schmidt wrote:
>> Hi,
>> I want to add background gradient to a rectangle figure. I found some
>> comments in newsgroup, but i don´t understand it. I don´t know where
>> to override the fillShape method :(
>> Can somebody give an approach for a beginner?
>>
>> Regards, Martin
>>
Re: Fill Gradient [message #161140 is a reply to message #161116] Sun, 18 November 2007 21:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Comments below

Martin Tauber wrote:
> Hi Tomas,
>
> did you find a solution?
To filling scalable polygons and ellipses with gradient? No.

I added the following code to the
> <whatever>EditPart.java for the <whatever> class inside:
>
>
> public void paintFigure(Graphics g) {
> Rectangle bounds = getPrimaryFigureBounds();
>
> Point topLeft = bounds.getTopLeft();
> Point bottomRight = bounds.getBottomRight();
> Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x,
> topLeft.y, bottomRight.x, bottomRight.y,
> ColorConstants.white, ColorConstants.darkBlue);
>
> g.setBackgroundPattern(pattern);
> g.fillRectangle(bounds);
> }
>
> well, but what should I say ... It didn't work.
I am confused, are you trying to fill a rectangle? To do this I do:

public xyzFigure() {
....
this.setBackgroundColor(ColorConstants.orange);
this.setForegroundColor(ColorConstants.white);
this.setBorder(new LineBorder(ColorConstants.black, 1));

createContents();
}

/**
* @generated NOT
*/
@Override
protected void fillShape(Graphics graphics) {
graphics.fillGradient(getBounds(), true);
}

I am a little bit
> surpriced since the following code generates a box (whithout gradient)
> as expected:
>
> public void paintFigure(Graphics g) {
> // Rectangle bounds = getPrimaryFigureBounds();
> //
> // Point topLeft = bounds.getTopLeft();
> // Point bottomRight = bounds.getBottomRight();
> // Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x,
> // topLeft.y, bottomRight.x, bottomRight.y,
> // ColorConstants.white, ColorConstants.darkBlue);
> //
> // g.setBackgroundPattern(pattern);
>
> g.fillRectangle(bounds);
> }
You won't get a gradient without setting foreground and background color.

As I mentioned, I am not quite sure I understood what you meant, but I
hope this helps!


Best Regards,

Tomas Zijdemans


>
> Regards
> Martin
>
>
> Tomas Zijdemans wrote:
>> Please see my thread earlier, it is a relatively simple procedure. You
>> override the method in the editpart's XYZFigure class. Ex:
>> XYZ.edit.parts.XYZEditPart -> XYZFigure.
>>
>> HTH,
>>
>> Tomas Zijdemans
>>
>> Martin Schmidt wrote:
>>> Hi,
>>> I want to add background gradient to a rectangle figure. I found some
>>> comments in newsgroup, but i don´t understand it. I don´t know where
>>> to override the fillShape method :(
>>> Can somebody give an approach for a beginner?
>>>
>>> Regards, Martin
>>>
Re: Fill Gradient [message #161275 is a reply to message #161140] Mon, 19 November 2007 13:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

Hi Tomas,

(1)
I think we are not talking about exactly the same thing. My Figures in
GMF are children org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure,
which does not have a method called fillShape. fillShape is a method of
Shape as far as I understand. So the method that I am using is paintFigure.

paintFigure now take org.eclipse.draw2d.Graphics as a parameter which is
the parent of ScaledGraphics. So I am confused why you are saying you
didn't manage to get a solution for scalable polygons and ellipses.

(2)
As I understood the Pattern class it takes two colors to create the
gradient. So why sould I then set the foreground and background class.

Regards
Martin




Tomas Zijdemans wrote:
> Comments below
>
> Martin Tauber wrote:
>> Hi Tomas,
>>
>> did you find a solution?
> To filling scalable polygons and ellipses with gradient? No.
>
> I added the following code to the
>> <whatever>EditPart.java for the <whatever> class inside:
>>
>>
>> public void paintFigure(Graphics g) {
>> Rectangle bounds = getPrimaryFigureBounds();
>>
>> Point topLeft = bounds.getTopLeft();
>> Point bottomRight = bounds.getBottomRight();
>> Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x,
>> topLeft.y, bottomRight.x, bottomRight.y,
>> ColorConstants.white, ColorConstants.darkBlue);
>>
>> g.setBackgroundPattern(pattern);
>> g.fillRectangle(bounds);
>> }
>>
>> well, but what should I say ... It didn't work.
> I am confused, are you trying to fill a rectangle? To do this I do:
>
> public xyzFigure() {
> ...
> this.setBackgroundColor(ColorConstants.orange);
> this.setForegroundColor(ColorConstants.white);
> this.setBorder(new LineBorder(ColorConstants.black, 1));
>
> createContents();
> }
>
> /**
> * @generated NOT
> */
> @Override
> protected void fillShape(Graphics graphics) {
> graphics.fillGradient(getBounds(), true);
> }
>
> I am a little bit
>> surpriced since the following code generates a box (whithout gradient)
>> as expected:
>>
>> public void paintFigure(Graphics g) {
>> // Rectangle bounds = getPrimaryFigureBounds();
>> //
>> // Point topLeft = bounds.getTopLeft();
>> // Point bottomRight = bounds.getBottomRight();
>> // Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x,
>> // topLeft.y, bottomRight.x, bottomRight.y,
>> // ColorConstants.white, ColorConstants.darkBlue);
>> //
>> // g.setBackgroundPattern(pattern);
>>
>> g.fillRectangle(bounds);
>> }
> You won't get a gradient without setting foreground and background color.
>
> As I mentioned, I am not quite sure I understood what you meant, but I
> hope this helps!
>
>
> Best Regards,
>
> Tomas Zijdemans
>
>
>>
>> Regards
>> Martin
>>
>>
>> Tomas Zijdemans wrote:
>>> Please see my thread earlier, it is a relatively simple procedure.
>>> You override the method in the editpart's XYZFigure class. Ex:
>>> XYZ.edit.parts.XYZEditPart -> XYZFigure.
>>>
>>> HTH,
>>>
>>> Tomas Zijdemans
>>>
>>> Martin Schmidt wrote:
>>>> Hi,
>>>> I want to add background gradient to a rectangle figure. I found
>>>> some comments in newsgroup, but i don´t understand it. I don´t know
>>>> where to override the fillShape method :(
>>>> Can somebody give an approach for a beginner?
>>>>
>>>> Regards, Martin
>>>>
Re: Fill Gradient [message #161306 is a reply to message #161275] Mon, 19 November 2007 13:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Martin Tauber wrote:
> Hi Tomas,
>
> (1)
> I think we are not talking about exactly the same thing. My Figures in
> GMF are children org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure,
> which does not have a method called fillShape. fillShape is a method of
> Shape as far as I understand. So the method that I am using is paintFigure.
I think we are using the same class (default gmf) fillShape and
paintFigure are both methods of Shape. So far I have only tried
fillShape (works great for rectangles but nothing else) - You got
gradient working on other figures than rectangles using paintFigure?
That would be great news!
> (2)
> As I understood the Pattern class it takes two colors to create the
> gradient. So why sould I then set the foreground and background class.
I have little experience with the Pattern class. I thought you were
using fillShape.

Regards,

Tomas Zijdemans
Re: Fill Gradient [message #161503 is a reply to message #161306] Mon, 19 November 2007 16:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

Hi Tomas,

Hm, I'm actually traing to learn as much as possible from GMF, thats why
I am following the newsgroup intensivly. So I thought that shapes with
gradient would be a cute idea for my project ;-) Well but the bad news
is, that I havn't done it yet ....

About out discussion on org.eclipse.draw2d.Shape and
org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure both implement the
IFigure interface and I think this is key. I guess you are not using
customizable figures so maybe hen the code generater just generates a
Shape object. Nevertheless NodeFigure doesn't have the fillShape method ...

Regards
Martin

Tomas Zijdemans wrote:
> Martin Tauber wrote:
>> Hi Tomas,
>>
>> (1)
>> I think we are not talking about exactly the same thing. My Figures in
>> GMF are children org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure,
>> which does not have a method called fillShape. fillShape is a method
>> of Shape as far as I understand. So the method that I am using is
>> paintFigure.
> I think we are using the same class (default gmf) fillShape and
> paintFigure are both methods of Shape. So far I have only tried
> fillShape (works great for rectangles but nothing else) - You got
> gradient working on other figures than rectangles using paintFigure?
> That would be great news!
>> (2)
>> As I understood the Pattern class it takes two colors to create the
>> gradient. So why sould I then set the foreground and background class.
> I have little experience with the Pattern class. I thought you were
> using fillShape.
>
> Regards,
>
> Tomas Zijdemans
>

> Martin Tauber wrote:
>> Hi Tomas,
>>
>> (1)
>> I think we are not talking about exactly the same thing. My Figures in
>> GMF are children org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure,
>> which does not have a method called fillShape. fillShape is a method
>> of Shape as far as I understand. So the method that I am using is
>> paintFigure.
> I think we are using the same class (default gmf) fillShape and
> paintFigure are both methods of Shape. So far I have only tried
> fillShape (works great for rectangles but nothing else) - You got
> gradient working on other figures than rectangles using paintFigure?
> That would be great news!
>> (2)
>> As I understood the Pattern class it takes two colors to create the
>> gradient. So why sould I then set the foreground and background class.
> I have little experience with the Pattern class. I thought you were
> using fillShape.
>
> Regards,
>
> Tomas Zijdemans
>
Re: Fill Gradient [message #161536 is a reply to message #161503] Mon, 19 November 2007 21:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Martin Tauber wrote:
> Hi Tomas,
>
> Hm, I'm actually traing to learn as much as possible from GMF, thats why
> I am following the newsgroup intensivly. So I thought that shapes with
> gradient would be a cute idea for my project ;-) Well but the bad news
> is, that I havn't done it yet ....
Ok. One of us is bound to figure it out sooner or later!

>
> About out discussion on org.eclipse.draw2d.Shape and
> org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure both implement the
> IFigure interface and I think this is key. I guess you are not using
> customizable figures so maybe hen the code generater just generates a
> Shape object.
I use Scalable Polygons with template points. This generates figures
which extends draw2d.Shape, this class has both methods (paint and
fill). I guess they do the same?
Reading on the GEF newsgroup, background patterns seems like the only
solution available (but even they seem have much trouble with that).

Regards,

Tomas Zijdemans


>
> Tomas Zijdemans wrote:
>> Martin Tauber wrote:
>>> Hi Tomas,
>>>
>>> (1)
>>> I think we are not talking about exactly the same thing. My Figures
>>> in GMF are children
>>> org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure, which does not
>>> have a method called fillShape. fillShape is a method of Shape as far
>>> as I understand. So the method that I am using is paintFigure.
>> I think we are using the same class (default gmf) fillShape and
>> paintFigure are both methods of Shape. So far I have only tried
>> fillShape (works great for rectangles but nothing else) - You got
>> gradient working on other figures than rectangles using paintFigure?
>> That would be great news!
>>> (2)
>>> As I understood the Pattern class it takes two colors to create the
>>> gradient. So why sould I then set the foreground and background class.
>> I have little experience with the Pattern class. I thought you were
>> using fillShape.
>>
>> Regards,
>>
>> Tomas Zijdemans
>>
>
>> Martin Tauber wrote:
>>> Hi Tomas,
>>>
>>> (1)
>>> I think we are not talking about exactly the same thing. My Figures
>>> in GMF are children
>>> org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure, which does not
>>> have a method called fillShape. fillShape is a method of Shape as far
>>> as I understand. So the method that I am using is paintFigure.
>> I think we are using the same class (default gmf) fillShape and
>> paintFigure are both methods of Shape. So far I have only tried
>> fillShape (works great for rectangles but nothing else) - You got
>> gradient working on other figures than rectangles using paintFigure?
>> That would be great news!
>>> (2)
>>> As I understood the Pattern class it takes two colors to create the
>>> gradient. So why sould I then set the foreground and background class.
>> I have little experience with the Pattern class. I thought you were
>> using fillShape.
>>
>> Regards,
>>
>> Tomas Zijdemans
>>
Re: Fill Gradient [message #161620 is a reply to message #161536] Tue, 20 November 2007 07:36 Go to previous message
Eclipse UserFriend
Originally posted by: martin.tauber.t-online.de

Hi Tomas,

if you find a solution, let me know.

Thanks
Martin

Tomas Zijdemans wrote:
> Martin Tauber wrote:
>> Hi Tomas,
>>
>> Hm, I'm actually traing to learn as much as possible from GMF, thats
>> why I am following the newsgroup intensivly. So I thought that shapes
>> with gradient would be a cute idea for my project ;-) Well but the bad
>> news is, that I havn't done it yet ....
> Ok. One of us is bound to figure it out sooner or later!
>
>>
>> About out discussion on org.eclipse.draw2d.Shape and
>> org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure both implement the
>> IFigure interface and I think this is key. I guess you are not using
>> customizable figures so maybe hen the code generater just generates a
>> Shape object.
> I use Scalable Polygons with template points. This generates figures
> which extends draw2d.Shape, this class has both methods (paint and
> fill). I guess they do the same?
> Reading on the GEF newsgroup, background patterns seems like the only
> solution available (but even they seem have much trouble with that).
>
> Regards,
>
> Tomas Zijdemans
>
>
>>
>> Tomas Zijdemans wrote:
>>> Martin Tauber wrote:
>>>> Hi Tomas,
>>>>
>>>> (1)
>>>> I think we are not talking about exactly the same thing. My Figures
>>>> in GMF are children
>>>> org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure, which does not
>>>> have a method called fillShape. fillShape is a method of Shape as
>>>> far as I understand. So the method that I am using is paintFigure.
>>> I think we are using the same class (default gmf) fillShape and
>>> paintFigure are both methods of Shape. So far I have only tried
>>> fillShape (works great for rectangles but nothing else) - You got
>>> gradient working on other figures than rectangles using paintFigure?
>>> That would be great news!
>>>> (2)
>>>> As I understood the Pattern class it takes two colors to create the
>>>> gradient. So why sould I then set the foreground and background class.
>>> I have little experience with the Pattern class. I thought you were
>>> using fillShape.
>>>
>>> Regards,
>>>
>>> Tomas Zijdemans
>>>
>>
>>> Martin Tauber wrote:
>>>> Hi Tomas,
>>>>
>>>> (1)
>>>> I think we are not talking about exactly the same thing. My Figures
>>>> in GMF are children
>>>> org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure, which does not
>>>> have a method called fillShape. fillShape is a method of Shape as
>>>> far as I understand. So the method that I am using is paintFigure.
>>> I think we are using the same class (default gmf) fillShape and
>>> paintFigure are both methods of Shape. So far I have only tried
>>> fillShape (works great for rectangles but nothing else) - You got
>>> gradient working on other figures than rectangles using paintFigure?
>>> That would be great news!
>>>> (2)
>>>> As I understood the Pattern class it takes two colors to create the
>>>> gradient. So why sould I then set the foreground and background class.
>>> I have little experience with the Pattern class. I thought you were
>>> using fillShape.
>>>
>>> Regards,
>>>
>>> Tomas Zijdemans
>>>
Previous Topic:Implementing a DEVS modeling plugin
Next Topic:BorderItemRectilinearRouter.
Goto Forum:
  


Current Time: Fri Apr 19 19:38:19 GMT 2024

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

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

Back to the top