/*
* Copyright (C) 2011-2014 GeoForge Project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.geoforge.worldwind.awt.annotation;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.geom.Position;
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;
import java.beans.PropertyChangeListener;
import java.util.Observer;
import org.geoforge.java.awt.font.GfrUtilFont;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
/**
*
* @author bantchao
*
* !!!!!!!!! SHOULD REWRITE ALL THESE SCREEN_ANNOTATION
*
*
*/
abstract public class GfrScreenAnnotationDimAbs extends ScreenAnnotation implements
IGfrHandlerLifeCycleObject,
Observer
{
protected String _strId_ = null;
protected String _strSuffixText = null; // nil value NOT allowed;
protected GfrScreenAnnotationDimAbs(
PropertyChangeListener lstShouldRedraw,
String strId,
String strLabel,
String strKindShape,
String strSuffixText)
{
super(strLabel + "\n" + strSuffixText, new Point());
this._strId_ = strId;
this._strSuffixText = strSuffixText;
super.setPickEnabled(false);
_setAttributesThis_(strKindShape);
if (lstShouldRedraw != null)
super.addPropertyChangeListener(lstShouldRedraw);
}
private void _setAttributesThis_(String strKindShape)
{
AnnotationAttributes attrs = new AnnotationAttributes();
attrs.setAdjustWidthToText(AVKey.SIZE_FIT_TEXT);
attrs.setFrameShape(strKindShape);
attrs.setDrawOffset(new Point(0, 20)); // coz of tbrl with SurfaceCircle, tempo code
attrs.setLeaderGapWidth(5);
attrs.setTextColor(Color.BLACK);
attrs.setBackgroundColor(new Color(1f, 1f, 1f, 0.8f));
attrs.setCornerRadius(5);
attrs.setBorderColor(new Color(0xababab));
attrs.setFont(GfrUtilFont.s_get());
attrs.setTextAlign(AVKey.CENTER);
attrs.setInsets(new Insets(5, 5, 5, 5));
attrs.setCornerRadius(0);
super.setAttributes(attrs);
}
/*
* fixing up drawing of "shape==none"
*/
@Override
protected void drawText(DrawContext dc, int width, int height, double opacity, Position pickPosition)
{
AnnotationAttributes attrs = super.getAttributes();
String str = attrs.getFrameShape();
if (str.compareTo(AVKey.SHAPE_NONE) == 0)
return;
super.drawText(dc, width, height, opacity, pickPosition);
}
@Override
public boolean init()
{
return true;
}
@Override
public void destroy()
{
}
}