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 03-01-2012, 08:50 PM   #1
BraydenJames
Junior Member
 
Join Date: May 2010
Location: Layton, UT
Posts: 23
BraydenJames is on a distinguished road
Question Vertical Alignment on ScreenAnnotation

So I have a ScreenRelativeAnnotation object and for the project I need to set a certain size for it instead of just letting it wrap the text. Which works fine except for one thing, the text is no longer centered vertically, and I can't for the life of me figure out how to fix that?

Here's a simple example:

Code:
import gov.nasa.worldwind.BasicModel;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.layers.AnnotationLayer;
import gov.nasa.worldwind.render.ScreenRelativeAnnotation;

import java.awt.Dimension;

import javax.swing.JFrame;

public class RelativeAnnotationTest {

	public static void main(String[] args) {

		JFrame frame = new JFrame();

		WorldWindowGLCanvas worldWindow = new WorldWindowGLCanvas();
		worldWindow.setPreferredSize(new Dimension(600, 600));
		worldWindow.setModel(new BasicModel());

		AnnotationLayer annotationLayer = new AnnotationLayer();
		worldWindow.getModel().getLayers().add(annotationLayer);

		{
			ScreenRelativeAnnotation annotation = new ScreenRelativeAnnotation("Tall", 0, .5);
			annotation.getAttributes().setSize(new Dimension(100, 100));
			annotationLayer.addAnnotation(annotation);
		}

		{
			ScreenRelativeAnnotation annotation = new ScreenRelativeAnnotation("Normal", 1, .5);
			annotationLayer.addAnnotation(annotation);
		}

		frame.add(worldWindow);
		frame.pack();
		frame.setVisible(true);
	}

}
If you run it you can see how normally the annotation wraps the text so the text is centered (right side), but when I set a custom hard coded height (left side) the text is top aligned. Any help?
BraydenJames is offline   Reply With Quote
Old 03-01-2012, 11:06 PM   #2
BraydenJames
Junior Member
 
Join Date: May 2010
Location: Layton, UT
Posts: 23
BraydenJames is on a distinguished road
Default

Been digging through the source code of AbstractAnnotation and MultiLineTextRenderer and it's not looking good... I don't think there is anything that affects the y location where the text is being drawn. Bleh. Might have to add this myself! Still open to suggestions!
BraydenJames is offline   Reply With Quote
Old 03-02-2012, 05:21 PM   #3
BraydenJames
Junior Member
 
Join Date: May 2010
Location: Layton, UT
Posts: 23
BraydenJames is on a distinguished road
Default

Alright well for future reference in case anybody else runs into this, I ended up having to implement a vertical alignment myself in the AbstractAnnotation and MultiLineRenderer classes to get this to work. I'm using HTML for my text so I only implemented it in the drawHTML call, not the drawPlainText call. But yeah.
BraydenJames is offline   Reply With Quote
Old 03-02-2012, 08:54 PM   #4
heidtmare
Senior Member
 
heidtmare's Avatar
 
Join Date: Feb 2008
Location: Melbourne, FL, USA
Posts: 675
heidtmare is on a distinguished road
Default

not exactly answering your question, but here is an info box i implemented on a previous application.

PHP Code:
package REMOVED;

import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.layers.AnnotationLayer;
import gov.nasa.worldwind.render.AnnotationAttributes;
import gov.nasa.worldwind.render.DrawContext;
import gov.nasa.worldwind.render.ScreenAnnotation;
import java.awt.Color;
import java.awt.Insets;
import java.awt.Point;

/**
 *
 * @author heidtmare
 */
public class InformationBoxLayer extends AnnotationLayer {
    
    private final 
ScreenAnnotation sa;

    
/**
     *
     */
    
public InformationBoxLayer() {
        
setName("Information Box");
        
AnnotationAttributes attrs = new AnnotationAttributes();
        
attrs.setAdjustWidthToText(AVKey.SIZE_FIT_TEXT);
        
attrs.setBackgroundColor(new Color(0f0f0f.5f));
        
attrs.setBorderWidth(0);
        
attrs.setCornerRadius(0);
        
attrs.setInsets(new Insets(8888));
        
attrs.setTextAlign(AVKey.CENTER);
        
attrs.setTextColor(Color.WHITE);
        
        
sa = new ScreenAnnotation("", new Point(00), attrs);
        
this.addAnnotation(sa);
        
this.setPickEnabled(false);
    }

    
/**
     *
     * @param info
     */
    
public void setInformation(String info) {
        
sa.setText(info);
    }

    
/**
     * 
     * @param dc
     */
    
@Override
    
protected void doRender(DrawContext dc) {
        if (!
sa.getText().isEmpty()) {
            
Point centerScreenPoint dc.getViewportCenterScreenPoint();
            
sa.setScreenPoint(new Point(centerScreenPoint.x20));
            
super.doRender(dc);
        }
    }

__________________
Junior Member
 
Join Date: May 2010
Location: Layton, UT
Posts: 23
BraydenJames is on a distinguished road
Default

Quote:
Originally Posted by heidtmare View Post
not exactly answering your question, but here is an info box i implemented on a previous application.

PHP Code:
package REMOVED;

import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.layers.AnnotationLayer;
import gov.nasa.worldwind.render.AnnotationAttributes;
import gov.nasa.worldwind.render.DrawContext;
import gov.nasa.worldwind.render.ScreenAnnotation;
import java.awt.Color;
import java.awt.Insets;
import java.awt.Point;

/**
 *
 * @author heidtmare
 */
public class InformationBoxLayer extends AnnotationLayer {
    
    private final 
ScreenAnnotation sa;

    
/**
     *
     */
    
public InformationBoxLayer() {
        
setName("Information Box");
        
AnnotationAttributes attrs = new AnnotationAttributes();
        
attrs.setAdjustWidthToText(AVKey.SIZE_FIT_TEXT);
        
attrs.setBackgroundColor(new Color(0f0f0f.5f));
        
attrs.setBorderWidth(0);
        
attrs.setCornerRadius(0);
        
attrs.setInsets(new Insets(8888));
        
attrs.setTextAlign(AVKey.CENTER);
        
attrs.setTextColor(Color.WHITE);
        
        
sa = new ScreenAnnotation("", new Point(00), attrs);
        
this.addAnnotation(sa);
        
this.setPickEnabled(false);
    }

    
/**
     *
     * @param info
     */
    
public void setInformation(String info) {
        
sa.setText(info);
    }

    
/**
     * 
     * @param dc
     */
    
@Override
    
protected void doRender(DrawContext dc) {
        if (!
sa.getText().isEmpty()) {
            
Point centerScreenPoint dc.getViewportCenterScreenPoint();
            
sa.setScreenPoint(new Point(centerScreenPoint.x20));
            
super.doRender(dc);
        }
    }

My problem just arose from the fact that I had to do a hard coded height instead of just letting it wrap the text height wise (including your set insets). But I implemented it myself and it worked. Thank you though! Is there a way I could go about submitting my my change to the WorldWind source? I haven't contributed to an open source project before, so I'm not positive how to do it, but I can see how this change could be useful to others if I cleaned up the code a little and documented it.
BraydenJames is offline   Reply With Quote
Reply

Tags
alignment, screenrelativeannotation, vertical


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
Shape objects and vertical exaggeration Dario Saccavino Development Help 0 11-15-2011 03:29 PM
Problem picking terrain with vertical exaggeration set to 0 NathanKronenfeld Development Help 3 01-21-2011 04:50 PM
How to add Chinese annotation on ScreenAnnotation yedaya Development Help 2 03-07-2010 03:09 PM
KML AltitudeMode and Vertical Exaggeration question... James_In_Utah Developers' Corner 5 07-18-2008 09:20 PM
Vertical Exaggeration James_In_Utah Suggestion Box 16 05-13-2006 02:36 AM


All times are GMT +1. The time now is 08:03 PM.


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