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

📄 graticuleattributespanel.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    onLabelFontChanged(event);                }            });            this.labelFontStyle.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent event) {                    onLabelFontChanged(event);                }            });            this.labelFontSize.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent event) {                    onLabelFontChanged(event);                }            });        }    }    private void layoutComponents()    {        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));        //---------- Line Properties ----------//        {            this.linePanel.setLayout(new BoxLayout(this.linePanel, BoxLayout.PAGE_AXIS));            this.linePanel.setBorder(new CompoundBorder(new TitledBorder("Graticule"), new EmptyBorder(10, 10, 10, 10)));            //this.lineEnabled.setAlignmentX(Component.LEFT_ALIGNMENT);            //this.linePanel.add(this.lineEnabled);            //this.linePanel.add(Box.createVerticalStrut(10));            this.lineColorPanel.setAlignmentX(Component.LEFT_ALIGNMENT);            this.linePanel.add(this.lineColorPanel);            this.linePanel.add(Box.createVerticalStrut(10));            Box hbox = Box.createHorizontalBox();            hbox.setAlignmentX(Component.LEFT_ALIGNMENT);            hbox.add(this.lineWidthSlider);            hbox.add(this.lineWidthSpinner);            hbox.add(Box.createHorizontalGlue());            this.linePanel.add(hbox);            this.linePanel.add(Box.createVerticalStrut(10));            this.lineStyle.setAlignmentX(Component.LEFT_ALIGNMENT);            this.linePanel.add(this.lineStyle);        }        this.linePanel.setAlignmentX(Component.LEFT_ALIGNMENT);        add(this.linePanel);        add(Box.createVerticalStrut(20));        //---------- Label Properties ----------//        {            this.labelPanel.setLayout(new BoxLayout(this.labelPanel, BoxLayout.PAGE_AXIS));            this.labelPanel.setBorder(new CompoundBorder(new TitledBorder("Labels"), new EmptyBorder(10, 10, 10, 10)));            this.labelEnabled.setAlignmentX(Component.LEFT_ALIGNMENT);            this.labelPanel.add(this.labelEnabled);            this.labelPanel.add(Box.createVerticalStrut(10));            this.labelColorPanel.setAlignmentX(Component.LEFT_ALIGNMENT);            this.labelPanel.add(this.labelColorPanel);            this.labelPanel.add(Box.createVerticalStrut(10));            Box hbox = Box.createHorizontalBox();            hbox.setAlignmentX(Component.LEFT_ALIGNMENT);            hbox.add(this.labelFontName);            hbox.add(this.labelFontStyle);            hbox.add(this.labelFontSize);            this.labelPanel.add(hbox);        }        this.labelPanel.setAlignmentX(Component.LEFT_ALIGNMENT);        add(this.labelPanel);        add(Box.createVerticalGlue());    }    private static String getLineStyleLabel(String lineStyle)    {        String labelText = null;        if (MGRSGraticuleLayer.LINE_STYLE_SOLID.equals(lineStyle))            labelText = "Solid";        else if (MGRSGraticuleLayer.LINE_STYLE_DASHED.equals(lineStyle))            labelText = "Dashed";        else if (MGRSGraticuleLayer.LINE_STYLE_DOTTED.equals(lineStyle))            labelText = "Dotted";        return labelText;    }    private static class LineStyleRenderer implements ListCellRenderer    {        private ListCellRenderer delegate;        public LineStyleRenderer(ListCellRenderer delegate)        {            this.delegate = delegate;        }        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {            Component c = this.delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);            if (c != null && c instanceof JLabel)            {                JLabel label = (JLabel) c;                if (value != null && value instanceof String)                {                    String lineStyle = (String) value;                    String labelText = getLineStyleLabel(lineStyle);                    label.setText(labelText);                }            }            return c;        }    }    private static class ColorPanel extends JPanel    {        private JLabel colorLabel;        private JButton colorButton;        private JColorChooser colorChooser;        private JDialog colorChooserDialog;        private JSlider opacitySlider;        private Color lastSelectedColor = null;        private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);        public ColorPanel()        {            makeComponents();            layoutComponents();        }        public void addColorChangeListener(PropertyChangeListener propertyChangeListener)        {            this.changeSupport.addPropertyChangeListener(propertyChangeListener);        }        public void removeColorChangeListener(PropertyChangeListener propertyChangeListener)        {            this.changeSupport.removePropertyChangeListener(propertyChangeListener);        }        public void fireColorChanged()        {            this.changeSupport.firePropertyChange("color", null, makeColorFromControls());        }        public Color getColor()        {            return makeColorFromControls();        }        public void setColor(Color color)        {            if (color == null)            {                String message = Logging.getMessage("nullValue.ColorIsNull");                Logging.logger().severe(message);                throw new IllegalArgumentException(message);            }            setColorControls(color);        }        private Color makeColorFromControls()        {            Color rgb = this.colorChooser.getColor();            int a = this.opacitySlider.getValue();            return new Color(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), a);        }        private void setColorControls(Color color)        {            if (color == null)            {                String message = Logging.getMessage("nullValue.ColorIsNull");                Logging.logger().severe(message);                throw new IllegalArgumentException(message);            }            this.colorChooser.setColor(color);            this.opacitySlider.setValue(color.getAlpha());            setColorLabel(color);        }        private void onColorPressed()        {            this.lastSelectedColor = makeColorFromControls();            this.colorChooserDialog.setVisible(true);        }        private void onColorChooserOk(ActionEvent event)        {            if (event != null)            {                this.lastSelectedColor = null;                Color color = makeColorFromControls();                setColorLabel(color);                if (color != null)                {                    fireColorChanged();                }            }        }        private void onColorChooserCancel(ActionEvent event)        {            if (event != null)            {                Color color = this.lastSelectedColor;                if (color != null)                {                    setColorControls(color);                    fireColorChanged();                }            }        }        private void onColorChooserChanged(ChangeEvent event)        {            if (event != null)            {                Color color = makeColorFromControls();                setColorLabel(color);                if (color != null)                {                    fireColorChanged();                }            }        }        private void onOpacityChanged(ChangeEvent event)        {            if (event != null)            {                Color color = makeColorFromControls();                setColorLabel(color);                if (color != null)                {                    fireColorChanged();                }            }        }        private void makeComponents()        {            this.colorLabel = new JLabel(makeImageIcon(60, 16));            this.colorButton = new JButton("Choose...");            this.colorChooser = new JColorChooser();            // Replace the color "preview panel" with an empty panel.            // We will be previewing color changes in the WorldWindow.            this.colorChooser.setPreviewPanel(new JPanel());            this.opacitySlider = new JSlider(                1,    // min                255); // max            this.colorChooserDialog = JColorChooser.createDialog(this, "Choose Graticule Color", true, this.colorChooser,                new ActionListener() {                    public void actionPerformed(ActionEvent event) {                        onColorChooserOk(event);                    }                },                new ActionListener() {                    public void actionPerformed(ActionEvent event) {                        onColorChooserCancel(event);                    }                });            this.colorLabel.addMouseListener(new MouseAdapter() {                public void mouseClicked(MouseEvent event) {                    onColorPressed();                }            });            this.colorButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent event) {                    onColorPressed();                }            });            this.colorChooser.getSelectionModel().addChangeListener(new ChangeListener() {                public void stateChanged(ChangeEvent event) {                    onColorChooserChanged(event);                }            });            this.opacitySlider.addChangeListener(new ChangeListener() {                public void stateChanged(ChangeEvent event) {                    onOpacityChanged(event);                }            });        }        private void setColorLabel(Color color)        {            if (color != null                && this.colorLabel != null                && this.colorLabel.getIcon() != null                && this.colorLabel.getIcon() instanceof ImageIcon)            {                ImageIcon icon = (ImageIcon) this.colorLabel.getIcon();                if (icon.getImage() != null)                {                    // We only want to represent the RGB color components                    // on this label.                    Color rgb = new Color(color.getRGB());                    fillImage(icon.getImage(), rgb);                    this.colorLabel.repaint();                }            }        }        private void layoutComponents()        {            setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));            Box hbox = Box.createHorizontalBox();            hbox.setAlignmentX(Component.LEFT_ALIGNMENT);            this.colorLabel.setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));            hbox.add(this.colorLabel);            hbox.add(Box.createHorizontalStrut(5));            hbox.add(this.colorButton);            add(hbox);            add(Box.createVerticalStrut(10));            this.opacitySlider.setAlignmentX(Component.LEFT_ALIGNMENT);            add(this.opacitySlider);        }    }    private static ImageIcon makeImageIcon(int width, int height)    {        ImageIcon icon = null;        try        {            BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);            icon = new ImageIcon(bi);        }        catch (Exception e)        {            String message = "Exception while creating icon";            Logging.logger().log(java.util.logging.Level.SEVERE, message, e);        }        return icon;    }    private static void fillImage(Image image, Color color)    {        try        {            Graphics g = image.getGraphics();            g.setColor(color);            g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));        }        catch (Exception e)        {            String message = "Exception while drawing to image";            Logging.logger().log(java.util.logging.Level.SEVERE, message, e);        }    }}

⌨️ 快捷键说明

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