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

📄 viewlimits.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                box.add(hbox);                label = new JLabel("<html><b>Pitch Limits</b></html>");                label.setAlignmentX(Component.LEFT_ALIGNMENT);                box.add(label);                hbox = Box.createHorizontalBox();                hbox.setAlignmentX(Component.LEFT_ALIGNMENT);                hbox.add(new JLabel("Min/Max"));                hbox.add(this.minPitch);                hbox.add(this.maxPitch);                box.add(hbox);                label = new JLabel("<html><b>Zoom Limits</b></html>");                label.setAlignmentX(Component.LEFT_ALIGNMENT);                box.add(label);                hbox = Box.createHorizontalBox();                hbox.setAlignmentX(Component.LEFT_ALIGNMENT);                hbox.add(new JLabel("Min/Max"));                hbox.add(this.minZoom);                hbox.add(this.maxZoom);                box.add(hbox);                controlPanel.add(box, BorderLayout.NORTH);            }            this.getLayerPanel().add(controlPanel, BorderLayout.SOUTH);            JMenuBar menuBar = new JMenuBar();            {                JMenu menu = new JMenu("File");                JMenuItem item = new JMenuItem("Open");                item.setActionCommand(LOAD);                item.addActionListener(this.controller);                menu.add(item);                item = new JMenuItem("Save");                item.setActionCommand(SAVE);                item.addActionListener(this.controller);                menu.add(item);                menuBar.add(menu);            }            this.setJMenuBar(menuBar);        }        protected JSpinner createDoubleSpinner(final String actionCommand, double initialValue, double min, double max)        {            final JSpinner spinner  = new JSpinner(new SpinnerNumberModel(                initialValue, min, max, 0.01));            spinner.addChangeListener(new ChangeListener()            {                public void stateChanged(ChangeEvent changeEvent)                {                    ActionEvent actionEvent = new ActionEvent(spinner, 0, actionCommand);                    actionPerformed(actionEvent);                }            });            Dimension preferredSize = spinner.getPreferredSize();            preferredSize.width = 70;            spinner.setPreferredSize(preferredSize);                        return spinner;        }        protected JSpinner createAngleSpinner(final String actionCommand, Angle initialValue, Angle min, Angle max)        {            return createDoubleSpinner(actionCommand, initialValue.degrees, min.degrees, max.degrees);        }    }    public static class Controller implements ActionListener    {        protected AppFrame appFrame;        protected SurfaceSector surfaceSector;        protected RenderableLayer layer;        protected static final Sector DEFAULT_SECTOR_LIMITS = Sector.fromDegrees(40, 50, -130, -120);        public Controller(AppFrame appFrame)        {            this.appFrame = appFrame;            this.surfaceSector = new SurfaceSector();            this.surfaceSector.getAttributes().setInteriorMaterial(Material.WHITE);            this.surfaceSector.getAttributes().setOutlineMaterial(Material.GREEN);            this.surfaceSector.getAttributes().setInteriorOpacity(0.1);            this.surfaceSector.getAttributes().setOutlineOpacity(0.7);            this.surfaceSector.getAttributes().setOutlineWidth(3);            this.layer = new SurfaceShapeLayer();            this.layer.setPickEnabled(false);            this.layer.addRenderable(this.surfaceSector);            insertBeforePlacenames(this.appFrame.getWwd(), this.layer);            OrbitView view = this.getOrbitView();            if (view != null)            {                OrbitViewLimits limits = view.getOrbitViewLimits();                if (limits != null)                {                    Globe globe = this.appFrame.getWwd().getModel().getGlobe();                    double maxZoom = 3 * globe.getRadius();                    limits.setCenterLocationLimits(DEFAULT_SECTOR_LIMITS);                    limits.setZoomLimits(0, maxZoom);                    BasicOrbitViewLimits.applyLimits(view, limits);                }            }        }        @SuppressWarnings({"StringEquality"})        public void actionPerformed(ActionEvent actionEvent)        {            if (actionEvent == null)            {                return;            }            String actionCommand = actionEvent.getActionCommand();            if (actionCommand == null)            {                return;            }            if (actionCommand == SECTOR_LIMITS_CHANGED                || actionCommand == HEADING_LIMITS_CHANGED                || actionCommand == PITCH_LIMITS_CHANGED                || actionCommand == ZOOM_LIMITS_CHANGED)            {                this.updateViewLimits();            }            else if (actionCommand == LOAD)            {                this.loadObjects();            }            else if (actionCommand == SAVE)            {                this.saveObjects();            }        }        public void updateViewLimits()        {            OrbitView view = this.getOrbitView();            if (view == null)                return;            OrbitViewLimits limits = view.getOrbitViewLimits();            if (limits == null)                return;            Sector sector = this.appFrame.getSectorLimits();            if (sector != null)                limits.setCenterLocationLimits(sector);            Angle[] angles = this.appFrame.getHeadingLimits();            if (angles != null)                limits.setHeadingLimits(angles[0], angles[1]);            angles = this.appFrame.getPitchLimits();            if (angles != null)                limits.setPitchLimits(angles[0], angles[1]);            double[] values = this.appFrame.getZoomLimits();            if (values != null)                limits.setZoomLimits(values[0], values[1]);            BasicOrbitViewLimits.applyLimits(view, limits);            this.updateRenderables();        }        public void saveObjects()        {            JFileChooser fc = new JFileChooser();            fc.setCurrentDirectory(new File(Configuration.getUserHomeDirectory()));            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);            fc.setMultiSelectionEnabled(false);            int status = fc.showSaveDialog(this.appFrame);            if (status != JFileChooser.APPROVE_OPTION)                return;            File file = fc.getSelectedFile();            if (file == null)                return;            View view = this.appFrame.getWwd().getView();            String xmlString = view.getRestorableState();            WWIO.writeTextFile(xmlString, file);        }        public void loadObjects()        {            JFileChooser fc = new JFileChooser();            fc.setCurrentDirectory(new File(Configuration.getUserHomeDirectory()));            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);            fc.setMultiSelectionEnabled(false);            int status = fc.showOpenDialog(this.appFrame);            if (status != JFileChooser.APPROVE_OPTION)                return;            File file = fc.getSelectedFile();            if (file == null)                return;            View view = this.appFrame.getWwd().getView();            String xmlString = WWIO.readTextFile(file);            view.restoreState(xmlString);            if (view instanceof OrbitView)            {                OrbitView orbitView = (OrbitView) view;                BasicOrbitViewLimits.applyLimits(orbitView, orbitView.getOrbitViewLimits());            }            this.appFrame.updateComponents();        }        public OrbitView getOrbitView()        {            View view = this.appFrame.getWwd().getView();            return (view != null && view instanceof OrbitView) ? (OrbitView) view : null;        }        public void updateRenderables()        {            View view = this.appFrame.getWwd().getView();            if (view == null || !(view instanceof OrbitView))            {                return;            }            OrbitView orbitView = (OrbitView) view;            OrbitViewLimits limits = orbitView.getOrbitViewLimits();            this.surfaceSector.setSector(limits.getCenterLocationLimits());            this.appFrame.getWwd().redraw();                    }    }    public static void main(String[] args)    {        ApplicationTemplate.start("View Limits", AppFrame.class);    }}

⌨️ 快捷键说明

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