World Wind Forums

Go Back   World Wind Forums > WorldWind JAVA forums > Development Help

Development Help Help for building applications or diagnosing problems with WWJ

Reply
 
Thread Tools Display Modes
Old 06-20-2012, 02:12 PM   #1
Anthra
Junior Member
 
Join Date: Jun 2011
Location: Liège, Belgium
Posts: 18
Anthra is on a distinguished road
Default Simple text layer with ScreenAnnotation

Hi,

I'm encoutering some issue when I try to do a simple text layer for providing shortcuts to user.

I'm not able to switch visibility between two annotation using their visible attribute. When I do setCollapsed with false, the two annotations are visible.

Here is the code of my layer:

Code:
public class HelpLayer extends RenderableLayer{

    private Color color = Color.white;

    private String collapsedText = "Press 'h' to show keyboard shortcuts";
    private String expandedText  = "Press 'h' to hide keyboard shortcuts\nexpanded";

    ScreenAnnotation collapsedAnnotation;
    ScreenAnnotation expandedAnnotation;

    private boolean collapsed = true;

    public HelpLayer() {
        this.collapsedAnnotation = new ScreenAnnotation(collapsedText, new Point(50, 50));
        AnnotationAttributes annotationAttributes = new AnnotationAttributes();
        annotationAttributes.setTextColor(this.color);
        annotationAttributes.setImageSource(null);
        annotationAttributes.setFrameShape(AVKey.SHAPE_NONE);
        annotationAttributes.setAdjustWidthToText(AVKey.SIZE_FIT_TEXT);
        this.collapsedAnnotation.setAttributes(annotationAttributes);
        this.addRenderable(this.collapsedAnnotation);

        this.expandedAnnotation = new ScreenAnnotation(expandedText, new Point(50, 50));
        annotationAttributes = new AnnotationAttributes();
        annotationAttributes.setTextColor(this.color);
        annotationAttributes.setImageSource(null);
        annotationAttributes.setFrameShape(AVKey.SHAPE_NONE);
        annotationAttributes.setAdjustWidthToText(AVKey.SIZE_FIT_TEXT);
        this.expandedAnnotation.setAttributes(annotationAttributes);
        this.addRenderable(this.expandedAnnotation);

        update();
    }

    private synchronized void update()
    {
        collapsedAnnotation.getAttributes().setVisible(collapsed);
        expandedAnnotation.getAttributes().setVisible(!collapsed);
    }

    /**
     * @return the collapsed
     */
    public boolean isCollapsed() {
        return collapsed;
    }

    /**
     * @param collapsed the collapsed to set
     */
    public void setCollapsed(boolean collapsed) {
        this.collapsed = collapsed;
        update();
    }

}
Thanks in advance for all the help you could provide.
Anthra is offline   Reply With Quote
Old 06-20-2012, 02:58 PM   #2
BuM
Member
 
Join Date: Jan 2012
Posts: 94
BuM is on a distinguished road
Question redrawNow() needed

Hi there,

I tried your class and never experience both ScreenAnnotations at the same time.

However, often changing the Annotation has no visible effect at all, so I needed to add a redrawNow() (redraw() might work, too) to see the change immediately. Maybe this will solve your problem, too? Here are my changes:

Code:
public class HelpLayer extends RenderableLayer{

    private WorldWindow wwd;
	
    private Color color = Color.white;

    private String collapsedText = "Press 'h' to show keyboard shortcuts";
    private String expandedText  = "Press 'h' to hide keyboard shortcuts\nexpanded";

    ScreenAnnotation collapsedAnnotation;
    ScreenAnnotation expandedAnnotation;

    private boolean collapsed = true;

    public HelpLayer(WorldWindow wwd) {
    	this.wwd = wwd;
    	
        this.collapsedAnnotation = new ScreenAnnotation(collapsedText, new Point(50, 50));
        AnnotationAttributes annotationAttributes = new AnnotationAttributes();
        annotationAttributes.setTextColor(this.color);
        annotationAttributes.setImageSource(null);
        annotationAttributes.setFrameShape(AVKey.SHAPE_NONE);
        annotationAttributes.setAdjustWidthToText(AVKey.SIZE_FIT_TEXT);
        this.collapsedAnnotation.setAttributes(annotationAttributes);
        this.addRenderable(this.collapsedAnnotation);

        this.expandedAnnotation = new ScreenAnnotation(expandedText, new Point(50, 50));
        annotationAttributes = new AnnotationAttributes();
        annotationAttributes.setTextColor(this.color);
        annotationAttributes.setImageSource(null);
        annotationAttributes.setFrameShape(AVKey.SHAPE_NONE);
        annotationAttributes.setAdjustWidthToText(AVKey.SIZE_FIT_TEXT);
        this.expandedAnnotation.setAttributes(annotationAttributes);
        this.addRenderable(this.expandedAnnotation);

        update();
    }

    private synchronized void update()
    {
        collapsedAnnotation.getAttributes().setVisible(collapsed);
        expandedAnnotation.getAttributes().setVisible(!collapsed);
        wwd.redrawNow();
    }

    /**
     * @return the collapsed
     */
    public boolean isCollapsed() {
        return collapsed;
    }

    /**
     * @param collapsed the collapsed to set
     */
    public void setCollapsed(boolean collapsed) {
        this.collapsed = collapsed;
        update();
    }

}
BuM is offline   Reply With Quote
Old 06-20-2012, 03:32 PM   #3
Anthra
Junior Member
 
Join Date: Jun 2011
Location: Liège, Belgium
Posts: 18
Anthra is on a distinguished road
Default

It works! Thx a lot.
Anthra is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GetCurrentPosition question... ruso Development Help 19 08-24-2011 04:07 PM
Problems displaying a layer from cache jpralle Development Help 0 11-02-2010 01:27 PM
Plugin: My favorite Icons - Add Icons/Favorite canosso Add-ons & Scripts 26 03-02-2010 03:06 AM
WW1.3.2-Plugin: Layer Edit canosso Add-ons & Scripts 21 02-27-2010 04:37 AM
Simple scalebar layer patmurris Development Help 4 12-20-2008 07:00 AM


All times are GMT +1. The time now is 07:58 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.