servicedetailsdialog.java
来自「world wind java sdk 源码」· Java 代码 · 共 566 行 · 第 1/2 页
JAVA
566 行
/*Copyright (C) 2001, 2008 United States Government as represented bythe Administrator of the National Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.applications.gio.esg;import gov.nasa.worldwind.applications.gio.catalogui.CatalogKey;import gov.nasa.worldwind.applications.gio.catalogui.SwingUtils;import gov.nasa.worldwind.applications.gio.ebrim.Address;import gov.nasa.worldwind.applications.gio.ebrim.EmailAddress;import gov.nasa.worldwind.applications.gio.ebrim.PersonName;import gov.nasa.worldwind.applications.gio.ebrim.TelephoneNumber;import gov.nasa.worldwind.avlist.AVList;import gov.nasa.worldwind.util.Logging;import gov.nasa.worldwind.util.WWIO;import javax.swing.*;import javax.swing.event.HyperlinkEvent;import javax.swing.event.HyperlinkListener;import java.awt.*;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.net.URL;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Map;import java.util.Set;/** * @author dcollins * @version $Id: ServiceDetailsDialog.java 5517 2008-07-15 23:36:34Z dcollins $ */public class ServiceDetailsDialog extends JDialog{ private String contentPath; private String contentType; private String contentText; private AVList contentParams; private JPanel panel; private JEditorPane editorPane; private JScrollPane scrollPane; @SuppressWarnings({"FieldCanBeLocal"}) private HyperlinkListener hyperlinkListener; private int maxHeight; private int maxWidth; private static final int DEFAULT_MAX_HEIGHT = 600; private static final int DEFAULT_MAX_WIDTH = Short.MAX_VALUE; protected ServiceDetailsDialog() { makeComponents(); layoutComponents(); } public static void showDialog(String contentPath, String contentType, AVList contentParams, boolean alwaysOnTop) { if (contentPath == null) { String message = "nullValue.ContentPathIsNull"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (contentType == null) { String message = "nullValue.ContentTypeIsNull"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (contentParams == null) { String message = "nullValue.ContentParamsIsNull"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } ServiceDetailsDialog dialog = new ServiceDetailsDialog(); dialog.setContentPath(contentPath); dialog.setContentType(contentType); dialog.setContentParams(contentParams); dialog.setAlwaysOnTop(alwaysOnTop); dialog.doUpdate(); Dimension size = dialog.getEditorPane().getPreferredSize(); int hPadding = 16; // TODO: properly configure preferred size of editor int width = Math.min(dialog.maxWidth, size.width + hPadding); int height = Math.min(dialog.maxHeight, size.height); dialog.getEditorPane().setPreferredSize(new Dimension(width, height)); dialog.pack(); SwingUtils.centerWindowInDesktop(dialog); dialog.setVisible(true); } public String getContentPath() { return this.contentPath; } public void setContentPath(String contentPath) { if (contentPath == null) { String message = "nullValue.ContentPathIsNull"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.contentPath = contentPath; this.contentText = null; } public String getContentType() { return this.contentType; } public void setContentType(String contentType) { if (contentType == null) { String message = "nullValue.ContentTypeIsNull"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.contentType = contentType; this.contentText = null; } public AVList getContentParams() { return this.contentParams; } public void setContentParams(AVList contentParams) { if (contentParams == null) { String message = "nullValue.ContentParamsIsNull"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.contentParams = contentParams; } protected JEditorPane getEditorPane() { return this.editorPane; } protected JScrollPane getScrollPane() { return this.scrollPane; } protected void doUpdate() { AVList params = initContentParams(this.contentParams); String type = this.contentType; if (type == null) type = "text/plain"; String text = null; if (this.contentText == null) this.contentText = loadContent(); if (this.contentText != null) text = replaceContentParams(this.contentText, params); this.editorPane.setContentType(type); this.editorPane.setText(text); } protected void onHyperlinkPressed(URL url) { if (url != null) { if (this.contentParams != null) { this.contentParams.firePropertyChange(CatalogKey.ACTION_COMMAND_BROWSE, null, url); } } } protected void onHyperlinkPressed(String propertyName) { if (propertyName != null) { if (this.contentParams != null) { Object o = this.contentParams.getValue(propertyName); if (o != null) { if (o instanceof Object[]) { for (Object v : (Object[]) o) if (v != null) this.contentParams.firePropertyChange(CatalogKey.ACTION_COMMAND_BROWSE, null, v); } else { this.contentParams.firePropertyChange(CatalogKey.ACTION_COMMAND_BROWSE, null, o); } } } } } protected String loadContent() { StringBuilder sb = null; try { Object o = WWIO.getFileOrResourceAsStream(this.contentPath, getClass()); if (o != null) { if (o instanceof Exception) { throw (Exception) o; } else if (o instanceof InputStream) { sb = new StringBuilder(); InputStream is = (InputStream) o; BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; while ((line = br.readLine()) != null) { sb.append(line); } } } } catch (Exception e) { String message = "esg.ExceptionWhileLoadingContent"; Logging.logger().log(java.util.logging.Level.SEVERE, message, e); } return sb != null ? sb.toString() : null; } protected AVList initContentParams(AVList params) { if (params != null) { params = params.copy(); if (params.getValue(CatalogKey.ABSTRACT) == null) params.setValue(CatalogKey.ABSTRACT, "None"); if (params.getValue(CatalogKey.CONTACT_ADDRESS) == null) params.setValue(CatalogKey.CONTACT_ADDRESS, "None"); if (params.getValue(CatalogKey.CONTACT_ADDRESS_TYPE) == null) params.setValue(CatalogKey.CONTACT_ADDRESS_TYPE, "None"); if (params.getValue(CatalogKey.CONTACT_NAME) == null) params.setValue(CatalogKey.CONTACT_NAME, "None"); if (params.getValue(CatalogKey.CONTACT_TELEPHONE_NUMBER) == null) params.setValue(CatalogKey.CONTACT_TELEPHONE_NUMBER, "None"); if (params.getValue(CatalogKey.CONTACT_EMAIL_ADDRESSS) == null) params.setValue(CatalogKey.CONTACT_EMAIL_ADDRESSS, "None"); if (params.getValue(CatalogKey.CONTENT_START_DATE) == null) params.setValue(CatalogKey.CONTENT_START_DATE, "None"); if (params.getValue(CatalogKey.CONTENT_END_DATE) == null) params.setValue(CatalogKey.CONTENT_END_DATE, "None"); if (params.getValue(CatalogKey.DESCRIPTION) == null) params.setValue(CatalogKey.DESCRIPTION, "None"); if (params.getValue(CatalogKey.HARVEST_DATE) == null) params.setValue(CatalogKey.HARVEST_DATE, "None"); if (params.getValue(CatalogKey.HARVEST_TYPE) == null) params.setValue(CatalogKey.HARVEST_TYPE, "None"); if (params.getValue(CatalogKey.ID) == null) params.setValue(CatalogKey.ID, "None"); if (params.getValue(CatalogKey.KEYWORDS) == null) params.setValue(CatalogKey.KEYWORDS, "None"); if (params.getValue(CatalogKey.MODIFICATION_DATE) == null) params.setValue(CatalogKey.MODIFICATION_DATE, ""); if (params.getValue(CatalogKey.MAX_LATITUDE) == null) params.setValue(CatalogKey.MAX_LATITUDE, "None"); if (params.getValue(CatalogKey.MAX_LONGITUDE) == null) params.setValue(CatalogKey.MAX_LONGITUDE, "None"); if (params.getValue(CatalogKey.MIN_LATITUDE) == null) params.setValue(CatalogKey.MIN_LATITUDE, "None");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?