⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layermanagerlayer.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            this.annotation.getAttributes().setHighlighted(false);
            ((Component)this.wwd).setCursor(Cursor.getDefaultCursor());
            this.update();
        }
    }

    protected void drag(SelectEvent event)
    {
        if (event.getEventAction().equals(SelectEvent.DRAG))
        {
            if ((this.isComponentDragEnabled() && this.selectedIndex == -1 && this.dragRefIndex == -1)
                || this.draggingComponent)
            {
                // Dragging the whole list
                if (!this.draggingComponent)
                {
                    this.dragRefCursorPoint = event.getMouseEvent().getPoint();
                    this.dragRefPoint = this.annotation.getScreenPoint();
                    this.draggingComponent = true;
                }
                Point cursorOffset = new Point(event.getMouseEvent().getPoint().x - this.dragRefCursorPoint.x,
                    event.getMouseEvent().getPoint().y - this.dragRefCursorPoint.y);
                Point targetPoint = new Point(this.dragRefPoint.x + cursorOffset.x,
                    this.dragRefPoint.y - cursorOffset.y);
                this.moveTo(targetPoint);
            }
            else if (this.isLayerDragEnabled())
            {
                // Dragging a layer inside the list
                if (!this.draggingLayer)
                {
                    this.dragRefIndex = this.selectedIndex;
                    this.draggingLayer = true;
                }
                if (this.selectedIndex != -1 && this.dragRefIndex != -1 && this.dragRefIndex != this.selectedIndex)
                {
                    // Move dragged layer
                    LayerList layers = this.wwd.getModel().getLayers();
                    int insertIndex = this.dragRefIndex > this.selectedIndex ?
                        this.selectedIndex : this.selectedIndex + 1;
                    int removeIndex = this.dragRefIndex > this.selectedIndex ?
                        this.dragRefIndex + 1 : this.dragRefIndex;
                    layers.add(insertIndex, layers.get(this.dragRefIndex));
                    layers.remove(removeIndex);
                    this.dragRefIndex = this.selectedIndex;
                }
            }
        }
        else if (event.getEventAction().equals(SelectEvent.DRAG_END))
        {
            this.draggingComponent = false;
            this.draggingLayer = false;
            this.dragRefIndex = -1;
        }
    }

    protected void moveTo(Point targetPoint)
    {
        Point refPoint = this.annotation.getScreenPoint();
        if (this.locationOffset == null)
            this.locationOffset = Vec4.ZERO;

        // Compute appropriate offset
        int x = (int)this.locationOffset.x - (refPoint.x - targetPoint.x);
        int y = (int)this.locationOffset.y - (refPoint.y - targetPoint.y);
        this.locationOffset = new Vec4(x, y, 0);

        // Compensate for rounding errors
        Point computedPoint = this.computeLocation(this.wwd.getView().getViewport());
        x += targetPoint.x - computedPoint.x;
        y += targetPoint.y - computedPoint.y;
        this.locationOffset = new Vec4(x, y, 0);
        
        if (this.snapToCorners)
            this.snapToCorners();
    }

    protected void snapToCorners()
    {
        // TODO: handle annotation scaling
        int width = (int)this.annotation.getAttributes().getSize().getWidth();
        int height = (int)this.annotation.getAttributes().getSize().getHeight();
        Rectangle viewport = this.wwd.getView().getViewport();
        Point refPoint = this.computeLocation(viewport);
        Point centerPoint = new Point(refPoint.x + width / 2, refPoint.y + height / 2);
        
        // Find closest corner position
        String newPos;
        if (centerPoint.x > viewport.width / 2)
            newPos = (centerPoint.y > viewport.height / 2) ? AVKey.NORTHEAST : AVKey.SOUTHEAST;
        else
            newPos = (centerPoint.y > viewport.height / 2) ? AVKey.NORTHWEST : AVKey.SOUTHWEST;

        // Adjust offset if position changed
        int x = 0, y = 0;
        if (newPos.equals(this.getPosition()))
        {
            x = (int) this.locationOffset.x;
            y = (int) this.locationOffset.y;
        }
        else
        {
            if (newPos.equals(AVKey.NORTHEAST))
            {
                x = refPoint.x -(viewport.width - width - this.borderWidth);
                y = refPoint.y - (viewport.height - height - this.borderWidth);
            }
            else if (newPos.equals(AVKey.SOUTHEAST))
            {
                x = refPoint.x -(viewport.width - width - this.borderWidth);
                y = refPoint.y - this.borderWidth;
            }
            if (newPos.equals(AVKey.NORTHWEST))
            {
                x = refPoint.x - this.borderWidth;
                y = refPoint.y -(viewport.height - height - this.borderWidth);
            }
            else if (newPos.equals(AVKey.SOUTHWEST))
            {
                x = refPoint.x - this.borderWidth;
                y = refPoint.y - this.borderWidth;
            }
        }

        // Snap to edges
        x = Math.abs(x) < 16 ? 0 : x;
        y = Math.abs(y) < 16 ? 0 : y;

        this.position = newPos;
        this.locationOffset = new Vec4(x, y, 0);
    }

    /**
     * Schedule the layer list for redrawing before the next render pass.
     */
    public void update()
    {
        this.update = true;
        this.wwd.redraw();
    }

    /**
     * Force the layer list to redraw itself from the current <code>Model</code> with the current
     * highlighted state and selected layer colors and opacity.
     *
     * @see #setMinOpacity, #setMaxOpacity
     * @see #setColor, #setHighlightColor
     */
    public void updateNow()
    {
        // Adjust annotation appearance to highlighted state
        this.highlight(this.annotation.getAttributes().isHighlighted());

        // Compose html text
        String text = this.makeAnnotationText(this.wwd.getModel().getLayers());
        this.annotation.setText(text);

        // Measure text and adjust annotation size/draw offset
        // TODO: handle annotation scaling
        String wrappedText = MultiLineTextRenderer.processLineBreaksHTML(text);
        Rectangle2D rect = this.mltr.getBoundsHTML(wrappedText, this.textRendererCache);
        Insets insets = this.annotation.getAttributes().getInsets();
        int width = (int)rect.getWidth() + insets.left + insets.right + 6;
        int height = (int)rect.getHeight() + insets.top + insets.bottom + 2;
        this.annotation.getAttributes().setSize(new Dimension(width, height));
        this.annotation.getAttributes().setDrawOffset(new Point(width / 2, 0));

        // Clear update flag
        this.update = false;
    }

    /**
     * Change the annotation appearance according to the given highlighted state.
     *
     * @param highlighted <ode>true</code> if the annotation should appear highlighted.
     */
    protected void highlight(boolean highlighted)
    {
        // Adjust border color and annotation opacity
        if (highlighted)
        {
            this.annotation.getAttributes().setBorderColor(this.highlightColor);
            this.annotation.getAttributes().setOpacity(this.maxOpacity);
        }
        else
        {
            this.annotation.getAttributes().setBorderColor(this.color);
            this.annotation.getAttributes().setOpacity(this.minOpacity);
        }
    }

    /**
     * Compose the annotation text from the given <code>LayerList</code>.
     *
     * @param layers the <code>LayerList</code> to draw names from.
     * @return the annotation text to be displayed.
     */
    protected String makeAnnotationText(LayerList layers)
    {
        // Compose html text
        StringBuilder text = new StringBuilder();
        Color color;
        int i = 0;
        for (Layer layer : layers)
        {
            if (!this.isMinimized() || layer == this)
            {
                color = (i == this.selectedIndex) ? this.highlightColor : this.color;
                color = (i == this.dragRefIndex) ? dragColor : color;
                text.append("<a href=\"");
                text.append(i);
                text.append("\"><font color=\"");
                text.append(encodeHTMLColor(color));
                text.append("\">");
                text.append((layer.isEnabled() ? layerEnabledSymbol : layerDisabledSymbol));
                text.append(" ");
                text.append((layer.isEnabled() ? "<b>" : "<i>"));
                text.append(layer.getName());
                text.append((layer.isEnabled() ? "</b>" : "</i>"));
                text .append("</a><br />");
            }
            i++;
        }
        return text.toString();
    }

    protected static String encodeHTMLColor(Color c)
    {
        return String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue());
    }

    public void render(DrawContext dc)
    {
        if (this.update)
            this.updateNow();

        this.annotation.setScreenPoint(computeLocation(dc.getView().getViewport()));
        super.render(dc);
    }

    /**
     * Compute the draw frame south-west corner screen location according to it's position - see
     * {@link #setPosition(String)}, location offset - see {@link #setLocationOffset(Vec4)}, or location center -
     * see {@link #setLocationCenter(Vec4)}, and border distance from the viewport edges - see
     * {@link #setBorderWidth(int)}.
     *
     * @param viewport the current <code>Viewport</code> rectangle.
     * @return the draw frame south-west corner screen location.
     */
    protected Point computeLocation(Rectangle viewport)
    {
        // TODO: handle annotation scaling
        int width = (int)this.annotation.getAttributes().getSize().getWidth();
        int height = (int)this.annotation.getAttributes().getSize().getHeight();

        int x;
        int y;

        if (this.locationCenter != null)
        {
            x = (int)this.locationCenter.x - width / 2;
            y = (int)this.locationCenter.y - height / 2;
        }
        else if (this.position.equals(AVKey.NORTHEAST))
        {
            x = (int)viewport.getWidth() - width - this.borderWidth;
            y = (int)viewport.getHeight() - height - this.borderWidth;
        }
        else if (this.position.equals(AVKey.SOUTHEAST))
        {
            x = (int)viewport.getWidth() - width - this.borderWidth;
            //noinspection SuspiciousNameCombination
            y = this.borderWidth;
        }
        else if (this.position.equals(AVKey.NORTHWEST))
        {
            x = this.borderWidth;
            y = (int)viewport.getHeight() - height - this.borderWidth;
        }
        else if (this.position.equals(AVKey.SOUTHWEST))
        {
            x = this.borderWidth;
            //noinspection SuspiciousNameCombination
            y = this.borderWidth;
        }
        else // use North East as default
        {
            x = (int)viewport.getWidth() - width - this.borderWidth;
            y = (int)viewport.getHeight() - height - this.borderWidth;
        }

        if (this.locationOffset != null)
        {
            x += this.locationOffset.x;
            y += this.locationOffset.y;
        }

        return new Point(x, y);
    }

    @Override
    public String toString()
    {
        return Logging.getMessage("layers.LayerManagerLayer.Name");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -