📄 viewlimits.java
字号:
/* Copyright (C) 2001, 2009 United States Government as represented bythe Administrator of the National Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.examples;import gov.nasa.worldwind.*;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.globes.Globe;import gov.nasa.worldwind.layers.*;import gov.nasa.worldwind.render.*;import gov.nasa.worldwind.util.*;import gov.nasa.worldwind.view.*;import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;import java.io.File;/** * @author dcollins * @version $Id: ViewLimits.java 10301 2009-04-17 20:21:46Z dcollins $ */public class ViewLimits extends ApplicationTemplate{ protected static final String SECTOR_LIMITS_CHANGED = "SectorLimitsChanged"; protected static final String HEADING_LIMITS_CHANGED = "HeadingLimitsChanged"; protected static final String PITCH_LIMITS_CHANGED = "PitchLimitsChanged"; protected static final String ZOOM_LIMITS_CHANGED = "ZoomLimitsChanged"; protected static final String SAVE = "Save"; protected static final String LOAD = "Load"; public static class AppFrame extends ApplicationTemplate.AppFrame implements ActionListener { private Controller controller; // UI components. private JSpinner minLatitude; private JSpinner maxLatitude; private JSpinner minLongitude; private JSpinner maxLongitude; private JSpinner minHeading; private JSpinner maxHeading; private JSpinner minPitch; private JSpinner maxPitch; private JSpinner minZoom; private JSpinner maxZoom; private boolean ignoreComponentEvents = false; public AppFrame() { this.controller = new Controller(this); this.initComponents(); this.updateComponents(); } public Sector getSectorLimits() { return Sector.fromDegrees( (Double) this.minLatitude.getValue(), (Double) this.maxLatitude.getValue(), (Double) this.minLongitude.getValue(), (Double) this.maxLongitude.getValue()); } public void setSectorLimits(Sector sector) { if (sector == null) { String message = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.ignoreComponentEvents = true; try { this.minLatitude.setValue(sector.getMinLatitude().degrees); this.maxLatitude.setValue(sector.getMaxLatitude().degrees); this.minLongitude.setValue(sector.getMinLongitude().degrees); this.maxLongitude.setValue(sector.getMaxLongitude().degrees); } finally { this.ignoreComponentEvents = false; } } public Angle[] getHeadingLimits() { return new Angle[] { Angle.fromDegrees((Double) this.minHeading.getValue()), Angle.fromDegrees((Double) this.maxHeading.getValue()) }; } public void setHeadingLimits(Angle min, Angle max) { if (min == null || max == null) { String message = Logging.getMessage("nullValue.MinOrMaxAngleIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.ignoreComponentEvents = true; try { this.minHeading.setValue(min.degrees); this.maxHeading.setValue(max.degrees); } finally { this.ignoreComponentEvents = false; } } public Angle[] getPitchLimits() { return new Angle[] { Angle.fromDegrees((Double) this.minPitch.getValue()), Angle.fromDegrees((Double) this.maxPitch.getValue()) }; } public void setPitchLimits(Angle min, Angle max) { if (min == null || max == null) { String message = Logging.getMessage("nullValue.MinOrMaxAngleIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.ignoreComponentEvents = true; try { this.minPitch.setValue(min.degrees); this.maxPitch.setValue(max.degrees); } finally { this.ignoreComponentEvents = false; } } public double[] getZoomLimits() { return new double[] { (Double) this.minZoom.getValue(), (Double) this.maxZoom.getValue() }; } public void setZoomLimits(double min, double max) { try { this.minZoom.setValue(min); this.maxZoom.setValue(max); } finally { this.ignoreComponentEvents = false; } } public void actionPerformed(ActionEvent actionEvent) { if (this.ignoreComponentEvents) return; if (this.controller != null) { this.controller.actionPerformed(actionEvent); } } public void updateComponents() { OrbitView view = this.controller.getOrbitView(); if (view == null) return; OrbitViewLimits limits = view.getOrbitViewLimits(); if (limits == null) return; Sector sector = limits.getCenterLocationLimits(); if (sector != null) this.setSectorLimits(sector); Angle[] angles = limits.getHeadingLimits(); if (angles != null) this.setHeadingLimits(angles[0], angles[1]); angles = limits.getPitchLimits(); if (angles != null) this.setPitchLimits(angles[0], angles[1]); double[] values = limits.getZoomLimits(); if (values != null) this.setZoomLimits(values[0], values[1]); } protected void initComponents() { this.minLatitude = this.createAngleSpinner(SECTOR_LIMITS_CHANGED, Angle.NEG90, Angle.NEG90, Angle.POS90); this.maxLatitude = this.createAngleSpinner(SECTOR_LIMITS_CHANGED, Angle.POS90, Angle.NEG90, Angle.POS90); this.minLongitude = this.createAngleSpinner(SECTOR_LIMITS_CHANGED, Angle.NEG180, Angle.NEG180, Angle.POS180); this.maxLongitude = this.createAngleSpinner(SECTOR_LIMITS_CHANGED, Angle.POS180, Angle.NEG180, Angle.POS180); this.minHeading = this.createAngleSpinner(HEADING_LIMITS_CHANGED, Angle.NEG180, Angle.NEG180, Angle.POS180); this.maxHeading = this.createAngleSpinner(HEADING_LIMITS_CHANGED, Angle.POS180, Angle.NEG180, Angle.POS180); this.minPitch = this.createAngleSpinner(PITCH_LIMITS_CHANGED, Angle.NEG180, Angle.NEG180, Angle.POS180); this.maxPitch = this.createAngleSpinner(PITCH_LIMITS_CHANGED, Angle.POS180, Angle.NEG180, Angle.POS180); this.minZoom = this.createDoubleSpinner(ZOOM_LIMITS_CHANGED, 0, 0, Double.MAX_VALUE); this.maxZoom = this.createDoubleSpinner(ZOOM_LIMITS_CHANGED, Double.MAX_VALUE, 0, Double.MAX_VALUE); JPanel controlPanel = new JPanel(new BorderLayout(0, 0)); // hgap, vgap { controlPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 20, 0)); // top, left, bottom, right Box box = Box.createVerticalBox(); JLabel label = new JLabel("<html><b>Sector Limits</b></html>"); label.setAlignmentX(Component.LEFT_ALIGNMENT); box.add(label); Box hbox = Box.createHorizontalBox(); hbox.setAlignmentX(Component.LEFT_ALIGNMENT); hbox.add(new JLabel("Lat Min/Max")); hbox.add(this.minLatitude); hbox.add(this.maxLatitude); box.add(hbox); hbox = Box.createHorizontalBox(); hbox.setAlignmentX(Component.LEFT_ALIGNMENT); hbox.add(new JLabel("Lon Min/Max")); hbox.add(this.minLongitude); hbox.add(this.maxLongitude); box.add(hbox); label = new JLabel("<html><b>Heading 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.minHeading); hbox.add(this.maxHeading);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -