📄 layermanagerlayer.java
字号:
/*
Copyright (C) 2001, 2009 United States Government
as represented by the Administrator of the
National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.examples.util;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.event.*;
import gov.nasa.worldwind.geom.Vec4;
import gov.nasa.worldwind.layers.*;
import gov.nasa.worldwind.pick.PickedObject;
import gov.nasa.worldwind.render.*;
import gov.nasa.worldwind.util.Logging;
import java.awt.*;
import java.awt.geom.*;
/**
* Displays the layer list in a viewport corner.
*
* @author Patrick Murris
* @version $Id: LayerManagerLayer.java 10567 2009-04-28 00:37:05Z patrickmurris $
*/
public class LayerManagerLayer extends RenderableLayer implements SelectListener
{
protected WorldWindow wwd;
protected TextRendererCache textRendererCache = new TextRendererCache();
protected MultiLineTextRenderer mltr;
protected boolean update = true;
private ScreenAnnotation annotation;
private int selectedIndex = -1;
private Color color = Color.decode("#b0b0b0");
private Color highlightColor = Color.decode("#ffffff");
private double minOpacity = .6;
private double maxOpacity = 1;
private char layerEnabledSymbol = '\u25a0';
private char layerDisabledSymbol = '\u25a1';
private Font font = new Font("SansSerif", Font.PLAIN, 14);
private boolean minimized = false;
private int borderWidth = 20; // TODO: make configurable
private String position = AVKey.SOUTHWEST; // TODO: make configurable
private Vec4 locationCenter = null;
private Vec4 locationOffset = null;
// Dragging
private boolean componentDragEnabled = true;
private boolean layerDragEnabled = true;
private boolean snapToCorners = true;
protected boolean draggingComponent = false;
protected boolean draggingLayer = false;
protected Point dragRefCursorPoint;
protected Point dragRefPoint;
protected int dragRefIndex = -1;
protected Color dragColor = Color.RED;
public LayerManagerLayer(WorldWindow wwd)
{
if (wwd == null)
{
String msg = Logging.getMessage("nullValue.WorldWindow");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
this.wwd = wwd;
this.initialize();
}
protected void initialize()
{
// Set up screen annotation that will display the layer list
this.annotation = new ScreenAnnotation("", new Point(0, 0));
this.annotation.getAttributes().setCornerRadius(0);
this.annotation.getAttributes().setAdjustWidthToText(Annotation.SIZE_FIXED);
this.annotation.getAttributes().setFont(this.font);
this.annotation.getAttributes().setHighlightScale(1);
this.annotation.getAttributes().setTextColor(Color.WHITE);
this.annotation.getAttributes().setBackgroundColor(new Color(0f, 0f, 0f, .5f));
this.annotation.getAttributes().setInsets(new Insets(6, 6, 6, 6));
this.annotation.getAttributes().setBorderWidth(1);
this.addRenderable(this.annotation);
// Set up multiline text renderer used to measure html text bounds
this.mltr = new MultiLineTextRenderer(this.font);
this.mltr.setLineSpacing(-2);
// Listen to world window for select event
this.wwd.addSelectListener(this);
}
/**
* Get the <code>ScreenAnnotation</code> used to display the layer list.
*
* @return the <code>ScreenAnnotation</code> used to display the layer list.
*/
public ScreenAnnotation getAnnotation()
{
return this.annotation;
}
/**
* Set the <code>ScreenAnnotation</code> used to display the layer list.
*
* @param annotation the <code>ScreenAnnotation</code> used to display the layer list.
*/
public void setAnnotation(ScreenAnnotation annotation)
{
if (annotation == null)
{
String msg = Logging.getMessage("nullValue.AnnotationIsNull");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
this.annotation = annotation;
}
public void setEnabled(boolean enabled)
{
this.setMinimized(!enabled);
}
public boolean isEnabled()
{
return !this.isMinimized();
}
/**
* Get the <code>Font</code> used to draw the layer list text.
*
* @return the <code>Font</code> used to draw the layer list text.
*/
public Font getFont()
{
return this.font;
}
/**
* Set the <code>Font</code> used to draw the layer list text.
*
* @param font the <code>Font</code> used to draw the layer list text.
*/
public void setFont(Font font)
{
if (font == null)
{
String message = Logging.getMessage("nullValue.FontIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (!this.font.equals(font))
{
this.font = font;
this.mltr = new MultiLineTextRenderer(font);
this.annotation.getAttributes().setFont(font);
this.update();
}
}
/**
* Get the <code>Color</code> used to draw the layer names and the frame border when they are not highlighted.
*
* @return the <code>Color</code> used to draw the layer names and the frame border when they are not highlighted.
*/
public Color getColor()
{
return this.color;
}
/**
* Set the <code>Color</code> used to draw the layer names and the frame border when they are not highlighted.
*
* @param color the <code>Color</code> used to draw the layer names and the frame border when they are
* not highlighted.
*/
public void setColor(Color color)
{
if (color == null)
{
String msg = Logging.getMessage("nullValue.ColorIsNull");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
this.color = color;
this.update();
}
/**
* Get the <code>Color</code> used to draw the layer names and the frame border when they are highlighted.
*
* @return the <code>Color</code> used to draw the layer names and the frame border when they are highlighted.
*/
public Color getHighlightColor()
{
return this.highlightColor;
}
/**
* Set the <code>Color</code> used to draw the layer names and the frame border when they are highlighted.
*
* @param color the <code>Color</code> used to draw the layer names and the frame border when they are
* highlighted.
*/
public void setHighlightColor(Color color)
{
if (color == null)
{
String msg = Logging.getMessage("nullValue.ColorIsNull");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
this.highlightColor = color;
this.update();
}
/**
* Get the opacity applied to the layer list when the cursor is outside it's frame.
*
* @return the opacity applied to the layer list when the cursor is outside it's frame.
*/
public double getMinOpacity()
{
return this.minOpacity;
}
/**
* Set the opacity applied to the layer list when the cursor is outside it's frame - zero to one,
* one is fully opaque.
*
* @param opacity the opacity applied to the layer list when the cursor is outside it's frame.
*/
public void setMinOpacity(double opacity)
{
this.minOpacity = opacity;
this.update();
}
/**
* Get the opacity applied to the layer list when the cursor is inside it's frame.
*
* @return the opacity applied to the layer list when the cursor is inside it's frame.
*/
public double getMaxOpacity()
{
return this.maxOpacity;
}
/**
* Set the opacity applied to the layer list when the cursor is inside it's frame - zero to one,
* one is fully opaque.
*
* @param opacity the opacity applied to the layer list when the cursor is inside it's frame.
*/
public void setMaxOpacity(double opacity)
{
this.maxOpacity = opacity;
this.update();
}
/**
* Get the character used to denote an enabled layer.
*
* @return the character used to denote an enabled layer.
*/
public char getLayerEnabledSymbol()
{
return this.layerEnabledSymbol;
}
/**
* Set the character used to denote an enabled layer.
*
* @param c the character used to denote an enabled layer.
*/
public void setLayerEnabledSymbol(char c)
{
this.layerEnabledSymbol = c;
this.update();
}
/**
* Get the character used to denote a disabled layer.
*
* @return the character used to denote a disabled layer.
*/
public char getLayerDisabledSymbol()
{
return this.layerDisabledSymbol;
}
/**
* Set the character used to denote a disabled layer.
*
* @param c the character used to denote a disabled layer.
*/
public void setLayerDisabledSymbol(char c)
{
this.layerDisabledSymbol = c;
this.update();
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -