[udig-devel] Problem with my MapGraphic implementation. Please Help

Ingmar Eveslage eveslage at gmail.com
Fri Oct 12 09:04:34 PDT 2007


Thank you for the example. It help very much. Everything looks fine now.


Jesse Eichar wrote:
> 
> Ok I have an example for you.  It is online at:
> 
> http://svn.geotools.org/udig/branches/1.1.x/udig/tutorials/ 
> net.refractions.udig.code.examples/src/net/refractions/udig/code/ 
> examples/AnimationMapGraphic.java
> 
> Hope this helps,
> 
> Jesse
> 
> On Oct 11, 2007, at 2:51 PM, Ingmar Eveslage wrote:
> 
>>
>> Thank you for your hint. But i have some problems with using the  
>> IAnimation
>> interface.
>>
>> I implemented the interface with a simple implementation
>>
>> package es.visualizer;
>> import org.eclipse.core.runtime.IProgressMonitor;
>>
>> import net.refractions.udig.project.IMap;
>> import net.refractions.udig.project.command.Command;
>> import net.refractions.udig.project.internal.Map;
>> import net.refractions.udig.project.render.displayAdapter.IMapDisplay;
>> import net.refractions.udig.project.ui.IAnimation;
>> import net.refractions.udig.ui.graphics.ViewportGraphics;
>>
>> public class AnimationImpl implements IAnimation {
>>
>> 	int counter = 1;
>> 	Map map = null;
>> 	boolean valid = true;
>> 	MapGraphic myMapGrahpic = null;
>> 	
>> 	void setMapGraphic(MapGraphic myMapGrahpic) {
>> 		this.myMapGraphic = myMapGraphic;
>> 	}
>>
>> 	@Override
>> 	public short getFrameInterval() {
>> 		return 100;
>> 	}
>>
>> 	@Override
>> 	public boolean hasNext() {
>> 		if (counter < 1000) {
>> 			counter++;
>> 			return true;
>> 		}
>> 		return false;
>> 	}
>>
>> 	@Override
>> 	public void nextFrame() {
>> 		// here i update the data for the mapgraphic layer on the map
>>
>> 	}
>>
>> 	@Override
>> 	public void run(IProgressMonitor monitor) throws Exception {
>> 		// dont know what i have to do here
>>
>> 	}
>>
>> 	@Override
>> 	public void dispose() {
>> 		// TODO Auto-generated method stub
>>
>> 	}
>>
>> 	@Override
>> 	public Rectangle getValidArea() {
>> 		return null;
>> 	}
>>
>> 	@Override
>> 	public boolean isValid() {
>> 		return valid;
>> 	}
>>
>> 	@Override
>> 	public void setGraphics(ViewportGraphics graphics, IMapDisplay  
>> display) {
>> 		// dont know what i have to do here
>>
>> 	}
>>
>> 	@Override
>> 	public void setValid(boolean valid) {
>> 		this.valid = valid;
>> 	}
>>
>> 	@Override
>> 	public Map getMap() {
>> 		return map;
>> 	}
>>
>> 	@Override
>> 	public void setMap(IMap map) {
>> 		this.map = (Map) map;
>> 	}
>>
>> 	@Override
>> 	public Command copy() {
>> 		// TODO Auto-generated method stub
>> 		return null;
>> 	}
>>
>> 	@Override
>> 	public String getName() {
>> 		// TODO Auto-generated method stub
>> 		return null;
>> 	}
>> }
>>
>>
>> ---------
>>
>> when i push a button in my view (i already implemented) i start the
>> AnimationUpdater:
>>
>> 		AnimationImpl ai = new AnimationImpl();
>> 		ai.setMapGraphic(myMapGraphic);
>> 		AnimationUpdater au = new AnimationUpdater((ViewportPane)
>> ApplicationGIS.getActiveMap().getRenderManager().getMapDisplay(),  
>> (short)
>> 100);
>> 		au.getAnimations().add(ai);
>> 		au.run();
>>
>> I think this could work, but i get an exception:
>>
>> java.lang.NullPointerException
>> 	at
>> net.refractions.udig.project.ui.AnimationUpdater$RunUpdaters.run 
>> (AnimationUpdater.java:130)
>> 	at org.eclipse.swt.widgets.Display.runTimers(Display.java:3436)
>> 	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2932)
>> 	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java: 
>> 2389)
>> 	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
>> 	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
>> 	at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
>> 	at
>> org.eclipse.core.databinding.observable.Realm.runWithDefault 
>> (Realm.java:289)
>> 	at
>> org.eclipse.ui.internal.Workbench.createAndRunWorkbench 
>> (Workbench.java:461)
>> 	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java: 
>> 149)
>> 	at
>> net.refractions.udig.internal.ui.UDIGApplication.run 
>> (UDIGApplication.java:41)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke 
>> (NativeMethodAccessorImpl.java:39)
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke 
>> (DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:589)
>> 	at
>> org.eclipse.equinox.internal.app.EclipseAppContainer.callMethod 
>> (EclipseAppContainer.java:572)
>> 	at
>> org.eclipse.equinox.internal.app.EclipseAppHandle.run 
>> (EclipseAppHandle.java:171)
>> 	at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplic 
>> ation(EclipseAppLauncher.java:106)
>> 	at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start 
>> (EclipseAppLauncher.java:76)
>> 	at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run 
>> (EclipseStarter.java:363)
>> 	at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run 
>> (EclipseStarter.java:176)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke 
>> (NativeMethodAccessorImpl.java:39)
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke 
>> (DelegatingMethodAccessorImpl.java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:589)
>> 	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:508)
>> 	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
>> 	at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
>> 	at org.eclipse.equinox.launcher.Main.main(Main.java:1148)
>>
>> what did i wrong? perhaps you can provide me a little working  
>> example for
>> me.
>>
>> Thanks forward.
>>
>> Ingmar
>>
>> Jesse Eichar wrote:
>>>
>>> Hi.
>>>
>>> It sounds to me like since you want actual animation you may want to
>>> use an animation instead.  For now the API is rather poor.  I plan on
>>> integrating the timing framework later on.  But for now look into
>>> IAnimation and AnimationUpdater to run the animation.
>>>
>>> The problem with using an animation is that it something must start
>>> it.  I'd suggest that when your map graphic is called to render it
>>> starts the animation (if it is not already running).  Draw commands
>>> (and IAnimations) are drawn on the Acetate layer and are removed
>>> during certain rendering actions, such as a zoom in.  Because of this
>>> you may find that you have to put a timestamp on you animation to
>>> make sure that it keeps running and isn't disposed of.
>>>
>>> I'm not sure this email completely makes sense.  Please let me know
>>> if you have a question.
>>>
>>> Jesse
>>>
>>> On Oct 8, 2007, at 8:57 AM, Ingmar Eveslage wrote:
>>>
>>>>
>>>> Hello,
>>>>
>>>> I have a problem with the plugin I developed. I implemented a
>>>> MapGraphic
>>>> Extension which draw rectangles on a given position on the map.
>>>> I also implemented a thread which modifies the data that is drawn
>>>> and then
>>>> calls the Layer.refresh(Envelope) function to draw the MapGraphic
>>>> again with
>>>> the updated data. Then the thread takes a short break, modifies the
>>>> data
>>>> again and refreshes the layer again, and so on.
>>>>
>>>> The MapGrahpics implementation uses double buffering and draws the
>>>> hidden
>>>> painted picture (a java.awt.image.BufferedImage) in the last line
>>>> of the
>>>> override draw(MapGraphicContext context) function.
>>>>
>>>> All works fine, but because the MapGraphic.draw function takes some
>>>> time (i
>>>> paint many rectangles, and sometime circles) it has not finished
>>>> before the
>>>> "updating-thread" calls Layer.refresh again. if this happens the
>>>> MapGraphics
>>>> layer gets totally blank. As i said: only if the Layer.refresh  
>>>> call is
>>>> before the MapGrahics.draw function finishes its last redraw.
>>>>
>>>> This is very distracting, because the MapGraphic layer with all my
>>>> rectangles and circles begin to flicker and sometimes when there
>>>> are many
>>>> updates the MapGraphic layer gets deleted short after its ready with
>>>> painting.
>>>>
>>>> I hope someone can help me. I tried to find a way to suspend the
>>>> updating
>>>> thread until the MapGraphic layer completed the draw method, but i
>>>> didn't
>>>> find the right api call. after hours of debugging i could not even
>>>> find the
>>>> place where the layer gets blank.
>>>>
>>>> So please help me.
>>>>
>>>> Thanks forward
>>>> 	Ingmar
>>>>
>>>> For info:
>>>>
>>>> I use Eclipse 3.2 and the uDig SDK 1.1RC11 on a Intel Mac.
>>>> -- 
>>>> View this message in context: http://www.nabble.com/Problem-with-my-
>>>> MapGraphic-implementation.-Please-Help-tf4588290.html#a13096935
>>>> Sent from the udig-devel mailing list archive at Nabble.com.
>>>>
>>>> _______________________________________________
>>>> User-friendly Desktop Internet GIS (uDig)
>>>> http://udig.refractions.net
>>>> http://lists.refractions.net/mailman/listinfo/udig-devel
>>>
>>> _______________________________________________
>>> User-friendly Desktop Internet GIS (uDig)
>>> http://udig.refractions.net
>>> http://lists.refractions.net/mailman/listinfo/udig-devel
>>>
>>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/Problem-with-my- 
>> MapGraphic-implementation.-Please-Help-tf4588290.html#a13165456
>> Sent from the udig-devel mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> User-friendly Desktop Internet GIS (uDig)
>> http://udig.refractions.net
>> http://lists.refractions.net/mailman/listinfo/udig-devel
> 
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-with-my-MapGraphic-implementation.-Please-Help-tf4588290.html#a13177023
Sent from the udig-devel mailing list archive at Nabble.com.



More information about the udig-devel mailing list