Home » Eclipse Projects » GEF » Is it possible to make a Blinking Element?
Is it possible to make a Blinking Element? [message #124570] |
Fri, 26 March 2004 12:57  |
Eclipse User |
|
|
|
I want to make an element which blinks at every 2 seconds, and I have
developed a class - BlinkControler, which notifies the model when to
blink.
The model the calls firePropertyChange(...) and updates the figure. To
make
the delay of 2 seconds I make a new thread and use Thread.sleep(2000).
After
thah I call BlinkControler.listeners.firePropertyChange(...) which
notifies
the model. At least this is the idea.
My model is a listener in the BlinkControler class. BlinkControler
implements
Runnable and I use theads. But when the BlinkControler notifies the model
an
exception is thrown. Here is the information which appears in the console
view:
java.lang.NullPointerException
at
org.eclipse.draw2d.DeferredUpdateManager.queueWork(DeferredU pdateManager.java:146)
at
org.eclipse.draw2d.DeferredUpdateManager.addInvalidFigure(De ferredUpdateManager.java:96)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1210)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1212)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1212)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1212)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1212)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1212)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1212)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1212)
at
org.eclipse.geditor.editparts.ElementEditPart.propertyChange (ElementEditPart.java:39)
at
java.beans.PropertyChangeSupport.firePropertyChange(Property ChangeSupport.java:252)
at
org.eclipse.geditor.models.Element.firePropertyChange(Elemen t.java:32)
at
org.eclipse.geditor.models.BlinkingElement.propertyChange(Bl inkingElement.java:143)
at
java.beans.PropertyChangeSupport.firePropertyChange(Property ChangeSupport.java:252)
at
org.eclipse.geditor.models.BlinkControler.run(BlinkControler .java:42)
Could somebody help me?
Thank you.
|
|
| | | | |
Re: Is it possible to make a Blinking Element? [message #124775 is a reply to message #124763] |
Sun, 28 March 2004 16:25   |
Eclipse User |
|
|
|
Here is the code of my BlinkElementEditPart::propertyChange(...):
public void propertyChange(java.beans.PropertyChangeEvent change){
if ( change.getPropertyName().equals(BlinkElement.BLINK))
{
this.display.asyncExec(
new Runnable() {
public void run() {
refreshVisuals();
}
}
);
}
else
super.propertyChange(change);
}
Here is the code of refreshVisuals():
protected void refreshVisuals() {
getBlinkElementFigure().setCurrentColor(
getBlinkElementModel().getCurrentColor());
Point loc = getRelsaSubpart().getLocation();
Dimension size= getRelsaSubpart().getSize();
Rectangle r = new Rectangle(loc ,size);
((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(),
r);
};
My stucture is similar to the structure of the Logic example so here
RelsaSubpart is very similar to LogicSubpart(there aren`t any
differences).
The BlinkControler changes the currentColor in the BlinkElement. When the
BlinkElementEditPart refreshes it visuals, it sets the figure color. -
getBlinkElementFigure().setCurrentColor(...);
The problem is than BlinkElementFigure::paintGraphics(...) isn`t called.
Thank you.
kiko
Randy Hudson wrote:
> You'd have to tell us what refreshVisuals() does, and all of the code for
> any methods it calls which you wrote.
> "kiko" <kiril_mitov@abv.bg> wrote in message
> news:c4798d$a6d$1@eclipse.org...
> > Thank you David!
> > I did it as you said. But it does not work. The problem is that after I
> > call
> > this.display.asyncExec(
> >
> > new Runnable() { public void run() { refreshVisuals(); } }
> >
> > );
> >
> > the method MyFigure::paintFigure(Graphics g) isn`t called. So my figure
> > isn`t
> > repainted. Do you have any idea why MyFigure::paintFigure(...) isn`t
> > called ?
> >
> > kiko
> >
> >
> > David Lindeijer wrote:
> >
> > > I had the same problem, and found a solution you may find usefull.
> >
> > > The NullPointerException is caused within
> DeferredUpdateManager.queueWork
> > > because Display.getCurrent() returns null for the current UI display.
> This
> > > is probably because the BlinkControler.run thread you start is not a UI
> > > thread.
> > > Anyway, what I did was aquire a reference to the current Display some
> other
> > > way, and then used Randy Hudsons solution regarding thread safety.
> >
> > > The change in my model, which originated via rmi from some other remote
> > > process, eventually invokes a method called propertyChange on the
> model's
> > > EditPart. This pattern is copied from the GEF examples. First thing
this
> > > method does in call
> > > this.display = this.getRoot().getViewer().getControl().getDisplay();
> >
> > > aquiring a reference to its Display. Next, the Runnable is executed
> > > asynchronously.
> >
> > > this.display.asyncExec(
> >
> > > new Runnable() { public void run() { refreshVisuals(); } }
> >
> > > );
> >
> > > Hopes it works for you also. It would make the time I wasted figuring
> this
> > > out more worthwhile.
> >
> > > Cheers,
> >
> > > David.
> >
|
|
|
Re: Is it possible to make a Blinking Element? [message #125597 is a reply to message #124775] |
Fri, 02 April 2004 11:44   |
Eclipse User |
|
|
|
> The problem is than BlinkElementFigure::paintGraphics(...) isn`t called.
You mean BlinkElementFigure::paint(Graphics)? You probably only need to
override the paintFigure method, and not the paint method.
What does BlinkElementFigure.setCurrentColor(Color) do? Does it revalidate
the figure?
"kiko" <kiril_mitov@abv.bg> wrote in message
news:c47ft4$ga1$1@eclipse.org...
> Here is the code of my BlinkElementEditPart::propertyChange(...):
>
> public void propertyChange(java.beans.PropertyChangeEvent change){
> if ( change.getPropertyName().equals(BlinkElement.BLINK))
> {
> this.display.asyncExec(
> new Runnable() {
> public void run() {
> refreshVisuals();
> }
> }
> );
> }
> else
> super.propertyChange(change);
> }
>
>
> Here is the code of refreshVisuals():
>
> protected void refreshVisuals() {
> getBlinkElementFigure().setCurrentColor(
> getBlinkElementModel().getCurrentColor());
>
> Point loc = getRelsaSubpart().getLocation();
> Dimension size= getRelsaSubpart().getSize();
> Rectangle r = new Rectangle(loc ,size);
>
> ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(),
>
> r);
> };
>
> My stucture is similar to the structure of the Logic example so here
> RelsaSubpart is very similar to LogicSubpart(there aren`t any
> differences).
>
> The BlinkControler changes the currentColor in the BlinkElement. When the
> BlinkElementEditPart refreshes it visuals, it sets the figure color. -
> getBlinkElementFigure().setCurrentColor(...);
>
> The problem is than BlinkElementFigure::paintGraphics(...) isn`t called.
>
> Thank you.
>
> kiko
>
>
>
> Randy Hudson wrote:
>
> > You'd have to tell us what refreshVisuals() does, and all of the code
for
> > any methods it calls which you wrote.
>
> > "kiko" <kiril_mitov@abv.bg> wrote in message
> > news:c4798d$a6d$1@eclipse.org...
> > > Thank you David!
> > > I did it as you said. But it does not work. The problem is that after
I
> > > call
> > > this.display.asyncExec(
> > >
> > > new Runnable() { public void run() { refreshVisuals(); } }
> > >
> > > );
> > >
> > > the method MyFigure::paintFigure(Graphics g) isn`t called. So my
figure
> > > isn`t
> > > repainted. Do you have any idea why MyFigure::paintFigure(...) isn`t
> > > called ?
> > >
> > > kiko
> > >
> > >
> > > David Lindeijer wrote:
> > >
> > > > I had the same problem, and found a solution you may find usefull.
> > >
> > > > The NullPointerException is caused within
> > DeferredUpdateManager.queueWork
> > > > because Display.getCurrent() returns null for the current UI
display.
> > This
> > > > is probably because the BlinkControler.run thread you start is not a
UI
> > > > thread.
> > > > Anyway, what I did was aquire a reference to the current Display
some
> > other
> > > > way, and then used Randy Hudsons solution regarding thread safety.
> > >
> > > > The change in my model, which originated via rmi from some other
remote
> > > > process, eventually invokes a method called propertyChange on the
> > model's
> > > > EditPart. This pattern is copied from the GEF examples. First thing
> this
> > > > method does in call
> > > > this.display = this.getRoot().getViewer().getControl().getDisplay();
> > >
> > > > aquiring a reference to its Display. Next, the Runnable is executed
> > > > asynchronously.
> > >
> > > > this.display.asyncExec(
> > >
> > > > new Runnable() { public void run() { refreshVisuals(); } }
> > >
> > > > );
> > >
> > > > Hopes it works for you also. It would make the time I wasted
figuring
> > this
> > > > out more worthwhile.
> > >
> > > > Cheers,
> > >
> > > > David.
> > >
>
|
|
|
Re: Is it possible to make a Blinking Element? [message #125813 is a reply to message #125597] |
Mon, 05 April 2004 13:11   |
Eclipse User |
|
|
|
I think i fixed the problem. I don't know whether it is right but i call
revalidate() in the refreshVisual().
For now it works for me.
Thank you all for your help.
kiko
Pratik Shah wrote:
> > The problem is than BlinkElementFigure::paintGraphics(...) isn`t called.
> You mean BlinkElementFigure::paint(Graphics)? You probably only need to
> override the paintFigure method, and not the paint method.
> What does BlinkElementFigure.setCurrentColor(Color) do? Does it revalidate
> the figure?
> "kiko" <kiril_mitov@abv.bg> wrote in message
> news:c47ft4$ga1$1@eclipse.org...
> > Here is the code of my BlinkElementEditPart::propertyChange(...):
> >
> > public void propertyChange(java.beans.PropertyChangeEvent change){
> > if ( change.getPropertyName().equals(BlinkElement.BLINK))
> > {
> > this.display.asyncExec(
> > new Runnable() {
> > public void run() {
> > refreshVisuals();
> > }
> > }
> > );
> > }
> > else
> > super.propertyChange(change);
> > }
> >
> >
> > Here is the code of refreshVisuals():
> >
> > protected void refreshVisuals() {
> > getBlinkElementFigure().setCurrentColor(
> > getBlinkElementModel().getCurrentColor());
> >
> > Point loc = getRelsaSubpart().getLocation();
> > Dimension size= getRelsaSubpart().getSize();
> > Rectangle r = new Rectangle(loc ,size);
> >
> > ((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(),
> >
> > r);
> > };
> >
> > My stucture is similar to the structure of the Logic example so here
> > RelsaSubpart is very similar to LogicSubpart(there aren`t any
> > differences).
> >
> > The BlinkControler changes the currentColor in the BlinkElement. When the
> > BlinkElementEditPart refreshes it visuals, it sets the figure color. -
> > getBlinkElementFigure().setCurrentColor(...);
> >
> > The problem is than BlinkElementFigure::paintGraphics(...) isn`t called.
> >
> > Thank you.
> >
> > kiko
> >
> >
> >
> > Randy Hudson wrote:
> >
> > > You'd have to tell us what refreshVisuals() does, and all of the code
> for
> > > any methods it calls which you wrote.
> >
> > > "kiko" <kiril_mitov@abv.bg> wrote in message
> > > news:c4798d$a6d$1@eclipse.org...
> > > > Thank you David!
> > > > I did it as you said. But it does not work. The problem is that after
> I
> > > > call
> > > > this.display.asyncExec(
> > > >
> > > > new Runnable() { public void run() { refreshVisuals(); } }
> > > >
> > > > );
> > > >
> > > > the method MyFigure::paintFigure(Graphics g) isn`t called. So my
> figure
> > > > isn`t
> > > > repainted. Do you have any idea why MyFigure::paintFigure(...) isn`t
> > > > called ?
> > > >
> > > > kiko
> > > >
> > > >
> > > > David Lindeijer wrote:
> > > >
> > > > > I had the same problem, and found a solution you may find usefull.
> > > >
> > > > > The NullPointerException is caused within
> > > DeferredUpdateManager.queueWork
> > > > > because Display.getCurrent() returns null for the current UI
> display.
> > > This
> > > > > is probably because the BlinkControler.run thread you start is not
a
> UI
> > > > > thread.
> > > > > Anyway, what I did was aquire a reference to the current Display
> some
> > > other
> > > > > way, and then used Randy Hudsons solution regarding thread safety.
> > > >
> > > > > The change in my model, which originated via rmi from some other
> remote
> > > > > process, eventually invokes a method called propertyChange on the
> > > model's
> > > > > EditPart. This pattern is copied from the GEF examples. First thing
> > this
> > > > > method does in call
> > > > > this.display =
this.getRoot().getViewer().getControl().getDisplay();
> > > >
> > > > > aquiring a reference to its Display. Next, the Runnable is executed
> > > > > asynchronously.
> > > >
> > > > > this.display.asyncExec(
> > > >
> > > > > new Runnable() { public void run() { refreshVisuals(); } }
> > > >
> > > > > );
> > > >
> > > > > Hopes it works for you also. It would make the time I wasted
> figuring
> > > this
> > > > > out more worthwhile.
> > > >
> > > > > Cheers,
> > > >
> > > > > David.
> > > >
> >
|
|
|
Re: Is it possible to make a Blinking Element? [message #126153 is a reply to message #125813] |
Tue, 06 April 2004 10:47  |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
You shouldn't call revalidate() unless you want to layout. Calling
revalidate does not guarantee a repaint.
"kiko" <kiril_mitov@abv.bg> wrote in message
news:c4s3vf$7dt$1@eclipse.org...
> I think i fixed the problem. I don't know whether it is right but i call
> revalidate() in the refreshVisual().
> For now it works for me.
>
> Thank you all for your help.
>
> kiko
>
>
> Pratik Shah wrote:
>
> > > The problem is than BlinkElementFigure::paintGraphics(...) isn`t
called.
>
> > You mean BlinkElementFigure::paint(Graphics)? You probably only need to
> > override the paintFigure method, and not the paint method.
>
> > What does BlinkElementFigure.setCurrentColor(Color) do? Does it
revalidate
> > the figure?
>
> > "kiko" <kiril_mitov@abv.bg> wrote in message
> > news:c47ft4$ga1$1@eclipse.org...
> > > Here is the code of my BlinkElementEditPart::propertyChange(...):
> > >
> > > public void propertyChange(java.beans.PropertyChangeEvent change){
> > > if ( change.getPropertyName().equals(BlinkElement.BLINK))
> > > {
> > > this.display.asyncExec(
> > > new Runnable() {
> > > public void run() {
> > > refreshVisuals();
> > > }
> > > }
> > > );
> > > }
> > > else
> > > super.propertyChange(change);
> > > }
> > >
> > >
> > > Here is the code of refreshVisuals():
> > >
> > > protected void refreshVisuals() {
> > > getBlinkElementFigure().setCurrentColor(
> > > getBlinkElementModel().getCurrentColor());
> > >
> > > Point loc = getRelsaSubpart().getLocation();
> > > Dimension size= getRelsaSubpart().getSize();
> > > Rectangle r = new Rectangle(loc ,size);
> > >
> > > ((GraphicalEditPart) getParent()).setLayoutConstraint(this,
> getFigure(),
> > >
> > > r);
> > > };
> > >
> > > My stucture is similar to the structure of the Logic example so here
> > > RelsaSubpart is very similar to LogicSubpart(there aren`t any
> > > differences).
> > >
> > > The BlinkControler changes the currentColor in the BlinkElement. When
the
> > > BlinkElementEditPart refreshes it visuals, it sets the figure color. -
> > > getBlinkElementFigure().setCurrentColor(...);
> > >
> > > The problem is than BlinkElementFigure::paintGraphics(...) isn`t
called.
> > >
> > > Thank you.
> > >
> > > kiko
> > >
> > >
> > >
> > > Randy Hudson wrote:
> > >
> > > > You'd have to tell us what refreshVisuals() does, and all of the
code
> > for
> > > > any methods it calls which you wrote.
> > >
> > > > "kiko" <kiril_mitov@abv.bg> wrote in message
> > > > news:c4798d$a6d$1@eclipse.org...
> > > > > Thank you David!
> > > > > I did it as you said. But it does not work. The problem is that
after
> > I
> > > > > call
> > > > > this.display.asyncExec(
> > > > >
> > > > > new Runnable() { public void run() { refreshVisuals(); } }
> > > > >
> > > > > );
> > > > >
> > > > > the method MyFigure::paintFigure(Graphics g) isn`t called. So my
> > figure
> > > > > isn`t
> > > > > repainted. Do you have any idea why MyFigure::paintFigure(...)
isn`t
> > > > > called ?
> > > > >
> > > > > kiko
> > > > >
> > > > >
> > > > > David Lindeijer wrote:
> > > > >
> > > > > > I had the same problem, and found a solution you may find
usefull.
> > > > >
> > > > > > The NullPointerException is caused within
> > > > DeferredUpdateManager.queueWork
> > > > > > because Display.getCurrent() returns null for the current UI
> > display.
> > > > This
> > > > > > is probably because the BlinkControler.run thread you start is
not
> a
> > UI
> > > > > > thread.
> > > > > > Anyway, what I did was aquire a reference to the current Display
> > some
> > > > other
> > > > > > way, and then used Randy Hudsons solution regarding thread
safety.
> > > > >
> > > > > > The change in my model, which originated via rmi from some other
> > remote
> > > > > > process, eventually invokes a method called propertyChange on
the
> > > > model's
> > > > > > EditPart. This pattern is copied from the GEF examples. First
thing
> > > this
> > > > > > method does in call
> > > > > > this.display =
> this.getRoot().getViewer().getControl().getDisplay();
> > > > >
> > > > > > aquiring a reference to its Display. Next, the Runnable is
executed
> > > > > > asynchronously.
> > > > >
> > > > > > this.display.asyncExec(
> > > > >
> > > > > > new Runnable() { public void run() { refreshVisuals(); } }
> > > > >
> > > > > > );
> > > > >
> > > > > > Hopes it works for you also. It would make the time I wasted
> > figuring
> > > > this
> > > > > > out more worthwhile.
> > > > >
> > > > > > Cheers,
> > > > >
> > > > > > David.
> > > > >
> > >
>
|
|
|
Goto Forum:
Current Time: Sat Jun 07 10:10:23 EDT 2025
Powered by FUDForum. Page generated in 0.03674 seconds
|