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

📄 annotations.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    }
                    // Highlight on rollover
                    else if (event.getEventAction().equals(SelectEvent.ROLLOVER) && !this.dragger.isDragging())
                    {
                        AppFrame.this.highlight(event.getTopObject());
                    }
                    // Have drag events drag the selected object.
                    else if (event.getEventAction().equals(SelectEvent.DRAG_END)
                            || event.getEventAction().equals(SelectEvent.DRAG))
                    {
                        if (event.hasObjects())
                        {
                            // If selected annotation delegate dragging computations to a dragger.
                            if(event.getTopObject() == AppFrame.this.currentAnnotation)
                                this.dragger.selected(event);
                        }

                        // We missed any roll-over events while dragging, so highlight any under the cursor now,
                        // or de-highlight the dragged shape if it's no longer under the cursor.
                        if (event.getEventAction().equals(SelectEvent.DRAG_END))
                        {
                            PickedObjectList pol = getWwd().getObjectsAtCurrentPosition();
                            if (pol != null)
                            {
                                AppFrame.this.highlight(pol.getTopObject());
                                AppFrame.this.getWwd().repaint();
                            }
                        }
                    }

                }
            });
        }

        private void highlight(Object o)
        {
            // Manage highlighting of Annotations.
            if (this.lastPickedObject == o)
                return; // same thing selected

            // Turn off highlight if on.
            if (this.lastPickedObject != null) // && this.lastPickedObject != this.currentAnnotation)
            {
                this.lastPickedObject.getAttributes().setHighlighted(false);
                this.lastPickedObject = null;
            }

            // Turn on highlight if object selected.
            if (o != null && o instanceof Annotation)
            {
                this.lastPickedObject = (Annotation) o;
                this.lastPickedObject.getAttributes().setHighlighted(true);
            }
        }

        public GlobeAnnotation makeTopImageBottomTextAnnotation(BufferedImage image, String text, Position position)
        {
            int width = image.getWidth();
            int height = image.getHeight();
            // Check for alpha channel in image
            if (image.getTransparency() == BufferedImage.OPAQUE)
            {
                // Copy the image into a buffered image with an alpha channel.
                // That ensures the annotation background color will not be covered with black
                BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                newImage.getGraphics().drawImage(image, 0, 0, null);
                image = newImage;
            }
            // Create annotation
            GlobeAnnotation ga = new GlobeAnnotation(text, position);
            int inset = 10; // pixels
            ga.getAttributes().setInsets(new Insets(height + inset * 2, inset, inset, inset));
            ga.getAttributes().setImageSource(image);
            ga.getAttributes().setImageOffset(new Point(inset, inset));
            ga.getAttributes().setImageRepeat(Annotation.IMAGE_REPEAT_NONE);
            ga.getAttributes().setImageOpacity(1);
            ga.getAttributes().setSize(new Dimension(width + inset * 2, 0));
            ga.getAttributes().setAdjustWidthToText(Annotation.SIZE_FIXED);
            ga.getAttributes().setBackgroundColor(Color.WHITE);
            ga.getAttributes().setTextColor(Color.BLACK);
            ga.getAttributes().setBorderColor(Color.BLACK);
            return ga;
        }


        // -- Control panel ---------------------------------------------------------------

        private JPanel makeControlPanel()
        {

            //-- Annotation text area. ----------------------------------------------
            this.inputTextArea = new JTextArea();
            this.inputTextArea.setFont(new Font("Sans_Serif", Font.PLAIN, 16));
            this.inputTextArea.setLineWrap(true);
            this.inputTextArea.setWrapStyleWord(true);
            JScrollPane textScrollPane = new JScrollPane(this.inputTextArea);
            textScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            textScrollPane.setPreferredSize(new Dimension(200, 100));
            textScrollPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));

            //-- Width panel --------------------------------------------------------
            JPanel sizePanel = new JPanel(new GridLayout(0, 1, 0, 0));
            sizePanel.setBorder(
                    new CompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), new TitledBorder("Width and Height")));
            this.widthSlider = new JSlider(JSlider.HORIZONTAL, 0, 800, 160);
            this.widthSlider.setMajorTickSpacing(100);
            this.widthSlider.setMinorTickSpacing(10);
            //this.widthSlider.setPaintTicks(true);
            this.widthSlider.setPaintLabels(true);
            this.widthSlider.setToolTipText("Preferred annotation width");
            this.widthSlider.addChangeListener(new ChangeListener()
            {
                public void stateChanged(ChangeEvent event)
                {
                    JSlider s = (JSlider)event.getSource();
                    if (currentAnnotation != null)
                    {
                        updateAnnotation();
                    }
                }

            });
            sizePanel.add(this.widthSlider);
            this.heightSlider = new JSlider(JSlider.HORIZONTAL, 0, 800, 0);
            this.heightSlider.setMajorTickSpacing(100);
            this.heightSlider.setMinorTickSpacing(10);
            //this.widthSlider.setPaintTicks(true);
            this.heightSlider.setPaintLabels(true);
            this.heightSlider.setToolTipText("Preferred annotation height, zero = no limit");
            this.heightSlider.addChangeListener(new ChangeListener()
            {
                public void stateChanged(ChangeEvent event)
                {
                    JSlider s = (JSlider)event.getSource();
                    if (currentAnnotation != null)
                    {
                        updateAnnotation();
                    }
                }

            });
            sizePanel.add(this.heightSlider);

            //-- Corner radius panel ----------------------------------------------------
            JPanel cornerRadiusPanel = new JPanel();
            cornerRadiusPanel.setLayout(new BoxLayout(cornerRadiusPanel, BoxLayout.X_AXIS));
            cornerRadiusPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
            cornerRadiusPanel.add(new JLabel("Corner radius:"));
            cornerRadiusPanel.add(Box.createRigidArea(new Dimension(10, 0)));
            this.cornerRadiusSlider = new JSlider(JSlider.HORIZONTAL, 0, 50, 10);
            this.cornerRadiusSlider.setMajorTickSpacing(10);
            this.cornerRadiusSlider.setMinorTickSpacing(1);
            //this.cornerRadiusSlider.setPaintTicks(true);
            this.cornerRadiusSlider.setPaintLabels(true);
            this.cornerRadiusSlider.setToolTipText("Rounded corners radius");
            this.cornerRadiusSlider.addChangeListener(new ChangeListener()
            {
                public void stateChanged(ChangeEvent event)
                {
                    if (currentAnnotation != null)
                    {
                        updateAnnotation();
                    }
                }

            });
            cornerRadiusPanel.add(this.cornerRadiusSlider);

            //-- Insets panel ----------------------------------------------------
            JPanel insetsPanel = new JPanel();
            insetsPanel.setLayout(new BoxLayout(insetsPanel, BoxLayout.X_AXIS));
            insetsPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
            insetsPanel.add(new JLabel("Insets:"));
            insetsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
            this.insetsTop = new JSpinner();
            this.insetsTop.addChangeListener(new ChangeListener()
            {
                public void stateChanged(ChangeEvent event)
                {
                    if (currentAnnotation != null)
                    {
                        updateAnnotation();
                    }
                }

            });
            this.insetsRight = new JSpinner();
            this.insetsRight.addChangeListener(new ChangeListener()
            {
                public void stateChanged(ChangeEvent event)
                {
                    if (currentAnnotation != null)
                    {
                        updateAnnotation();
                    }
                }

            });
            this.insetsBottom = new JSpinner();
            this.insetsBottom.addChangeListener(new ChangeListener()
            {
                public void stateChanged(ChangeEvent event)
                {
                    if (currentAnnotation != null)
                    {
                        updateAnnotation();
                    }
                }

            });
            this.insetsLeft = new JSpinner();
            this.insetsLeft.addChangeListener(new ChangeListener()
            {
                public void stateChanged(ChangeEvent event)
                {
                    if (currentAnnotation != null)
                    {
                        updateAnnotation();
                    }
                }

            });
            insetsPanel.add(this.insetsTop);
            insetsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
            insetsPanel.add(this.insetsRight);
            insetsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
            insetsPanel.add(this.insetsBottom);
            insetsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
            insetsPanel.add(this.insetsLeft);


            //-- Border width panel ----------------------------------------------------
            JPanel borderWidthPanel = new JPanel();
            borderWidthPanel.setLayout(new BoxLayout(borderWidthPanel, BoxLayout.X_AXIS));
            borderWidthPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
            borderWidthPanel.add(new JLabel("Border width:"));
            borderWidthPanel.add(Box.createRigidArea(new Dimension(10, 0)));
            this.borderWidthSlider = new JSlider(JSlider.HORIZONTAL, 0, 50, 10);
            this.borderWidthSlider.setMajorTickSpacing(10);
            this.borderWidthSlider.setMinorTickSpacing(1);
            //this.borderWidthSlider.setPaintTicks(true);
            this.borderWidthSlider.setPaintLabels(true);
            this.borderWidthSlider.setToolTipText("Border width 1/10th");
            this.borderWidthSlider.addChangeListener(new ChangeListener()
            {

⌨️ 快捷键说明

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