gidbcontroller.java
来自「world wind java sdk 源码」· Java 代码 · 共 541 行 · 第 1/2 页
JAVA
541 行
/*
Copyright (C) 2001, 2008 United States Government as represented by
the Administrator of the National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.applications.gio.gidb;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.applications.gio.GIDBCatalogPanel;
import gov.nasa.worldwind.applications.gio.catalogui.*;
import gov.nasa.worldwind.avlist.*;
import gov.nasa.worldwind.examples.ApplicationTemplate;
import gov.nasa.worldwind.examples.util.BrowserOpener;
import gov.nasa.worldwind.util.Logging;
import gov.nasa.worldwind.wms.*;
import javax.swing.*;
import java.beans.*;
import java.net.URL;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author dcollins
* @version $Id: GIDBController.java 9066 2009-02-27 16:42:58Z tgaskins $
*/
public class GIDBController implements PropertyChangeListener
{
private GIDBCatalogPanel gidbPanel;
private int threadPoolSize;
private ExecutorService executor;
private final AtomicInteger numResultActors = new AtomicInteger(0);
private final Map<Object, gov.nasa.worldwind.layers.Layer> wwLayerMap =
new HashMap<Object, gov.nasa.worldwind.layers.Layer>();
private static final int DEFAULT_THREAD_POOL_SIZE = 3;
public GIDBController(GIDBCatalogPanel gidbPanel)
{
if (gidbPanel == null)
{
String message = "nullValue.GIDBPanelIsNull";
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
this.gidbPanel = gidbPanel;
this.threadPoolSize = DEFAULT_THREAD_POOL_SIZE;
this.executor = Executors.newFixedThreadPool(this.threadPoolSize);
}
public int getThreadPoolSize()
{
return this.threadPoolSize;
}
public void setThreadPoolSize(int size)
{
if (this.executor != null)
{
this.executor.shutdown();
}
if (size < 1)
{
String message = Logging.getMessage("generic.ArgumentOutOfRange", "size=" + size);
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
this.threadPoolSize = size;
this.executor = Executors.newFixedThreadPool(this.threadPoolSize);
}
public void propertyChange(PropertyChangeEvent evt)
{
if (evt != null)
Logging.logger().fine(String.format("%s=%s", evt.getPropertyName(), evt.getNewValue()));
if (evt != null && evt.getPropertyName() != null)
{
if (evt.getPropertyName().equals(CatalogKey.ACTION_COMMAND_BROWSE))
{
Object value = evt.getNewValue();
if (value != null && value instanceof AVList)
{
onBrowse((AVList) value);
}
else if (value != null && value instanceof URL)
{
onBrowse(((URL) value).toExternalForm());
}
else if (value != null && value instanceof String)
{
onBrowse((String) value);
}
}
else if (evt.getPropertyName().equals(GIDBKey.ACTION_COMMAND_GET_SERVICE_CAPABILITIES))
{
Object value = evt.getNewValue();
if (value != null && value instanceof GIDBResultModel)
{
onGetServiceCapabilities((GIDBResultModel) evt.getNewValue());
}
}
else if (evt.getPropertyName().equals(GIDBKey.ACTION_COMMAND_LAYER_PRESSED))
{
Object source = evt.getSource();
Object value = evt.getNewValue();
if (source != null && source instanceof GIDBResultModel &&
value != null && value instanceof Layer)
{
onLayerPressed((GIDBResultModel) source, (Layer) value);
}
}
else if (evt.getPropertyName().equals(CatalogKey.ACTION_COMMAND_QUERY))
{
onGetServices();
}
}
}
protected void onBrowse(AVList params)
{
if (params != null)
{
String path = params.getStringValue(CatalogKey.URI);
if (path != null)
onDoOpenInBrowser(path);
}
}
protected void onBrowse(String path)
{
if (path != null)
{
onDoOpenInBrowser(path);
}
}
protected void onGetServices()
{
AVList queryParams = this.gidbPanel.getQueryModel();
if (queryParams != null)
{
queryParams = queryParams.copy();
GetServicesTask task = new GetServicesTask(queryParams, this);
this.executor.submit(task);
}
}
protected void onGetServiceCapabilities(GIDBResultModel resultModel)
{
GetServiceCapabilitiesTask task = new GetServiceCapabilitiesTask(resultModel, this);
this.executor.submit(task);
}
protected void onLayerPressed(GIDBResultModel resultModel, Layer layer)
{
UpdateLayerTask task = new UpdateLayerTask(resultModel, layer, this);
this.executor.submit(task);
}
private void onDoOpenInBrowser(String path)
{
if (path == null)
{
String message = "nullValue.PathIsNull";
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
// TODO: fixup path (if path is missing "http://", for example)
URL url = null;
try
{
url = new URL(path);
}
catch (Exception e)
{
String message = "gidb.InvalidPath";
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
}
try
{
if (url != null)
BrowserOpener.browse(url);
}
catch (Exception e)
{
String message = "gidb.CannotOpenBrowser";
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
}
}
protected void addResultActor()
{
this.numResultActors.incrementAndGet();
setResultsWaiting(true);
}
protected void removeResultActor()
{
int i = this.numResultActors.decrementAndGet();
if (i < 1)
setResultsWaiting(false);
}
private void setResultsWaiting(boolean waiting)
{
if (this.gidbPanel != null)
{
if (this.gidbPanel.getQueryPanel() != null)
this.gidbPanel.getQueryPanel().setEnabled(!waiting);
if (this.gidbPanel.getResultPanel() != null)
this.gidbPanel.getResultPanel().setWaiting(waiting);
}
}
private void setResultsStatusText(String text)
{
if (this.gidbPanel != null)
if (this.gidbPanel.getResultPanel() != null)
this.gidbPanel.getResultPanel().setStatusText(text);
}
private void setResultsStatusSearching()
{
setResultsStatusText("Searching...");
}
private void setResultsStatusFinished()
{
int numResults = 0;
if (this.gidbPanel != null)
if (this.gidbPanel.getResultModel() != null)
numResults = this.gidbPanel.getResultModel().size();
StringBuilder sb = new StringBuilder();
sb.append(numResults);
sb.append(" result");
if (numResults > 1)
sb.append("s");
sb.append(" returned");
setResultsStatusText(sb.toString());
}
private static class GetServicesTask implements Callable<Object>
{
private AVList params;
private GIDBController controller;
public GetServicesTask(AVList queryParams, GIDBController controller)
{
this.params = queryParams;
this.controller = controller;
}
public Object call() throws Exception
{
this.controller.doGetServices(this.params);
return null;
}
}
private void doGetServices(AVList queryParams)
{
if (queryParams == null)
{
String message = "nullValue.QueryParamsIsNull";
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?