📄 inspector.java
字号:
/* * File: Inspector.java * Date: Jul 2001 * Author: Kai Lessmann <klessman@intevation.de> * Copyright 2001 Intevation GmbH, Germany * * This file is Free Software to be included into OpenMap * under its Free Software license. * Permission is granted to use, modify and redistribute. * * Intevation hereby grants BBN a royalty free, worldwide right and license * to use, copy, distribute and make Derivative Works * of this Free Software created by Kai Lessmann * and sublicensing rights of any of the foregoing. * */package com.bbn.openmap.util.propertyEditor;import java.awt.BorderLayout;import java.awt.Component;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyEditor;import java.util.Collection;import java.util.Hashtable;import java.util.Iterator;import java.util.Properties;import java.util.Vector;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.ScrollPaneConstants;import javax.swing.SwingConstants;import com.bbn.openmap.PropertyConsumer;import com.bbn.openmap.gui.WindowSupport;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * Class to inspect a PropertyConsumer. Used by the LayerAddPanel * class to interactively configure a Layer object before it gets * added to the map. This class should suffice to "inspect" any * PropertyConsumer on a very basic level, handling is more convinient * if property editor classes are available. The behavior of the * Inspector is configured through properties; the propertiesInfo * object of a PropertyConsumer may contain a initPropertiesProperty * which determines which properties are to be shown and in which * order, in a space seperated list, i.e. * * <code> * initPropertiesProperty=class prettyName shapeFile * * </code> If this property is not defined, then all the properties * will be displayed, in alphabetical order. * * For each property there may be a editorProperty entry giving a * PropertyEditor class to instanciate as an editor for the property, * i.e. <code> * shapeFile.editor=com.bbn.openmap.util.propertyEditor.FilePropertyEditor * </code>. */public class Inspector implements ActionListener { /** A simple TextField as a String editor. */ protected final String defaultEditorClass = "com.bbn.openmap.util.propertyEditor.TextPropertyEditor"; /** * The PropertyConsumer being inspected. Set in * inspectPropertyConsumer. */ protected PropertyConsumer propertyConsumer = null; /** Handle to the GUI. Used for setVisible(true/false). */ protected WindowSupport windowSupport = null; /** Action command for the cancelButton. */ // public so it can be referenced from the actionListener public final static String cancelCommand = "cancelCommand"; /** The action command for the doneButton. */ // public so it can be referenced from the actionListener public final static String doneCommand = "doneCommand"; /** * Hashtable containing property names, and their editors. Used to * fetch user inputs for configuring a property consumer. */ protected Hashtable editors = null; /** * Handle to call back the object that invokes this Inspector. */ protected ActionListener actionListener = null; /** * Flag to print out the properties. Used when the Inspector is in * stand-alone mode, so that the properties are directed to * stdout. */ protected boolean print = false; /** * Set an Actionlistener for callbacks. Once a Layer object is * configured, ie the "Add" button has been clicked, an * ActionListener that invoked this Inspector can register here to * be notified. */ public void addActionListener(ActionListener al) { actionListener = al; } /** Does nothing. */ public Inspector() {} /** Sets the actionListener. */ public Inspector(ActionListener al) { actionListener = al; } /** * Inspect and configure a PropertyConsumer object. Main method of * this class. The argument PropertyConsumer is inspected through * the ProperyConsumer interface, the properties are displayed to * be edited. */ public void inspectPropertyConsumer(PropertyConsumer propertyConsumer) { String prefix = propertyConsumer.getPropertyPrefix(); // construct GUI if (windowSupport != null) { windowSupport.killWindow(); windowSupport = null; } JComponent comp = createPropertyGUI(propertyConsumer); windowSupport = new WindowSupport(comp, "Inspector - " + prefix); windowSupport.setMaxSize(-1, 500); windowSupport.displayInWindow(); } public Vector sortKeys(Collection keySet) { Vector vector = new Vector(keySet.size()); // OK, ok, this isn't the most efficient way to do this, but // it's simple. Shouldn't matter for what we are using it // for... Iterator it = keySet.iterator(); while (it.hasNext()) { String key = (String) it.next(); int size = vector.size(); for (int i = 0; i <= size; i++) { if (i == size) { // System.out.println("Adding " + key + " at " + // i); vector.add(key); break; } else { int compare = key.compareTo((String) vector.elementAt(i)); if (compare < 0) { // System.out.println(key + " goes before " + // vector.elementAt(i) + " at " + i); vector.add(i, key); break; } } } } return vector; } /** * Creates a JComponent with the properties to be changed. This * component is suitable for inclusion into a GUI. * * @param pc The property consumer to create a gui for. * @return JComponent, a panel holding the interface to set the * properties. */ public JComponent createPropertyGUI(PropertyConsumer pc) { // fill variables this.propertyConsumer = pc; Properties props = new Properties(); props = pc.getProperties(props); Properties info = new Properties(); info = pc.getPropertyInfo(info); String prefix = pc.getPropertyPrefix(); return createPropertyGUI(prefix, props, info); } /** * Creates a JComponent with the properties to be changed. This * component is suitable for inclusion into a GUI. Don't use this * method directly! Use the createPropertyGUI(PropertyConsumer) * instead. You will get a NullPointerException if you use this * method without setting the PropertyConsumer in the Inspector. * * @param prefix the property prefix for the property consumer. * Received from the PropertyConsumer.getPropertyPrefix() * method. Properties that start with this prefix will have * the prefix removed from the display, so the GUI will * only show the actual property name. * @param props the properties received from the * PropertyConsumer.getProperties() method. * @param info the properties received from the * PropertyConsumer.getPropertyInfo() method, containing * descriptions and any specific PropertyEditors that * should be used for a particular property named in the * PropertyConsumer.getProperties() properties. * @return JComponent, a panel holding the interface to set the * properties. */ public JComponent createPropertyGUI(String prefix, Properties props, Properties info) { if (Debug.debugging("inspectordetail")) { Debug.output("Inspector creating GUI for " + prefix + "\nPROPERTIES " + props + "\nPROP INFO " + info); } // collect the info needed... Collection keySet = props.keySet(); String propertyList = info.getProperty(PropertyConsumer.initPropertiesProperty); Vector sortedKeys; if (propertyList != null) { Vector propertiesToShow = PropUtils.parseSpacedMarkers(propertyList); for (int i = 0; i < propertiesToShow.size(); i++) { propertiesToShow.set(i, prefix + "." + propertiesToShow.get(i)); } sortedKeys = propertiesToShow;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -