📄 installeddata.java
字号:
for (ElevationModel model : modelList) { Object o = model.getValue(DATA_SOURCE_DESCRIPTOR); if (o != null && o instanceof DataDescriptor) { DataDescriptor d = (DataDescriptor) o; // If the layer references an installed DataDesriptor, then we can eliminate it from the list // of new DataDescriptors. if (installedDescriptors.contains(d)) installedDescriptors.remove(d); // If the layer references a DataDescriptor that is no longer installed, // then remove that layer. //else // uninstalledModels.add(model); } } // Remove layers for uninstalled DataDescriptors. //for (ElevationModel model : uninstalledModels) // compoundModel.removeElevationModel(model); // Add layers for installedDataDescriptors. for (DataDescriptor d : installedDescriptors) this.createElevationModelForDescriptor(d, compoundModel); } private void createLayerForDescriptor(DataDescriptor descriptor) { if (AVKey.TILED_IMAGERY.equals(descriptor.getType())) { TiledImageLayer layer = new BasicTiledImageLayer(descriptor); layer.setNetworkRetrievalEnabled(false); layer.setValue(DATA_SOURCE_DESCRIPTOR, descriptor); if (descriptor.getName() != null) layer.setName(descriptor.getName()); ApplicationTemplate.insertBeforePlacenames(this.appFrame.getWwd(), layer); } } private void createElevationModelForDescriptor(DataDescriptor descriptor, CompoundElevationModel compoundModel) { if (AVKey.TILED_ELEVATIONS.equals(descriptor.getType())) { double HEIGHT_OF_MT_EVEREST = 8850d; // meters double DEPTH_OF_MARIANAS_TRENCH = -11000d; // meters descriptor.setValue(AVKey.ELEVATION_MAX, HEIGHT_OF_MT_EVEREST); descriptor.setValue(AVKey.ELEVATION_MIN, DEPTH_OF_MARIANAS_TRENCH); ElevationModel model = new BasicElevationModel(descriptor); model.setNetworkRetrievalEnabled(false); model.setValue(DATA_SOURCE_DESCRIPTOR, descriptor); compoundModel.addElevationModel(model); } } } public static class Installer extends WWObjectImpl { // UI components. private Controller controller; private ProgressMonitor installProgressMonitor; // Installation components. private DataStoreProducer producer; private AVList parameters; private DataSource[] dataSources; private String installLocation; public Installer(Controller controller, DataStoreProducer producer, AVList parameters, DataSource[] dataSources, String installLocation) { this.controller = controller; this.producer = producer; this.parameters = parameters; this.dataSources = dataSources; this.installLocation = installLocation; } public void propertyChange(final PropertyChangeEvent evt) { if (evt == null) return; if (AVKey.PROGRESS.equalsIgnoreCase(evt.getPropertyName())) { SwingUtilities.invokeLater(new Runnable() { public void run() { Installer.this.updateInstallProgress(evt.getNewValue()); } }); } } public void install() throws Exception { SwingUtilities.invokeLater(new Runnable() { public void run() { Installer.this.beginInstall(); } }); try { this.parameters.setValue(AVKey.FILE_STORE_LOCATION, this.installLocation); this.producer.setStoreParameters(this.parameters); this.producer.removeAllDataSources(); this.producer.offerAllDataSources(java.util.Arrays.asList(this.dataSources)); producer.startProduction(); } finally { SwingUtilities.invokeLater(new Runnable() { public void run() { Installer.this.endInstall(); } }); } } public void installInNonUIThread(final Runnable onFinished) { Thread thread = new Thread(new Runnable() { public void run() { try { Installer.this.install(); } catch (Exception e) { String message = "Controller.ExceptionWhileInstalling"; Logging.logger().log(java.util.logging.Level.SEVERE, message, e); JOptionPane.showMessageDialog(Installer.this.controller.getAppFrame(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } if (onFinished != null) SwingUtilities.invokeLater(onFinished); } }); thread.start(); } private void beginInstall() { this.producer.addPropertyChangeListener(this); this.controller.getAppFrame().getInstalledDataPanel().getInstallButton().setEnabled(false); this.controller.getAppFrame().getInstalledDataPanel().getUninstallButton().setEnabled(false); this.controller.getAppFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } private void endInstall() { this.producer.removePropertyChangeListener(this); if (this.installProgressMonitor != null) this.installProgressMonitor.close(); this.installProgressMonitor = null; this.controller.getAppFrame().getInstalledDataPanel().getInstallButton().setEnabled(true); this.controller.getAppFrame().getInstalledDataPanel().getUninstallButton().setEnabled(true); this.controller.getAppFrame().setCursor(Cursor.getDefaultCursor()); this.controller.getAppFrame().getController().refreshInstalled(); } private void updateInstallProgress(Object newValue) { if (this.installProgressMonitor == null) { String message = "Installing..."; this.installProgressMonitor = new ProgressMonitor(this.controller.getAppFrame(), message, null, 0, 100); this.installProgressMonitor.setMillisToDecideToPopup(100); this.installProgressMonitor.setMillisToPopup(0); } if (newValue != null && newValue instanceof Number) { double progress = ((Number) newValue).doubleValue(); if (progress < 1.0) { int percentComplete = (int) (100 * progress); String note = String.format("%s %02d%%", this.parameters.getStringValue(AVKey.DATASET_NAME), percentComplete); this.installProgressMonitor.setNote(note); this.installProgressMonitor.setProgress(percentComplete); } else { this.installProgressMonitor.close(); this.installProgressMonitor = null; } } } } public static class Uninstaller extends WWObjectImpl { private Controller controller; private Iterable<DataDescriptor> descriptors; public Uninstaller(Controller controller, Iterable<DataDescriptor> descriptors) { this.controller = controller; this.descriptors = descriptors; } public void uninstall() { SwingUtilities.invokeLater(new Runnable() { public void run() { Uninstaller.this.beginUninstall(); } }); for (DataDescriptor descriptor : descriptors) this.uninstall(descriptor); SwingUtilities.invokeLater(new Runnable() { public void run() { Uninstaller.this.endUninstall(); } }); } public void uninstallInNonUIThread() { Thread thread = new Thread(new Runnable() { public void run() { Uninstaller.this.uninstall(); } }); thread.start(); } private void uninstall(DataDescriptor descriptor) { java.io.File storeLocation = descriptor.getFileStoreLocation(); String storePath = descriptor.getFileStorePath(); java.io.File installLocation = new java.io.File(storeLocation, storePath); try { WWIO.deleteDirectory(installLocation); } catch (java.io.IOException e) { String message = "Controller.ExceptionWhileUninstalling"; Logging.logger().log(java.util.logging.Level.SEVERE, message, e); JOptionPane.showMessageDialog(this.controller.getAppFrame(), "Error during uninstallation", "Error", JOptionPane.ERROR_MESSAGE); } } private void beginUninstall() { this.controller.getAppFrame().getInstalledDataPanel().getInstallButton().setEnabled(false); this.controller.getAppFrame().getInstalledDataPanel().getUninstallButton().setEnabled(false); this.controller.getAppFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } private void endUninstall() { this.controller.getAppFrame().getInstalledDataPanel().getInstallButton().setEnabled(true); this.controller.getAppFrame().getInstalledDataPanel().getUninstallButton().setEnabled(true); this.controller.getAppFrame().setCursor(Cursor.getDefaultCursor()); this.controller.getAppFrame().getController().refreshInstalled(); } } public static void main(String[] args) { ApplicationTemplate.start("World Wind Installed Data", AppFrame.class); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -