⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genericpropertysheet.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ********************************************************************** *  *    Use, duplication, or disclosure by the Government is subject to *           restricted rights as set forth in the DFARS. *   *                         BBNT Solutions LLC *                             A Part of  *                  Verizon       *                          10 Moulton Street *                         Cambridge, MA 02138 *                          (617) 873-3000 * *    Copyright (C) 2002 by BBNT Solutions, LLC *                 All Rights Reserved. * ********************************************************************** */package com.bbn.openmap.tools.beanbox;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.lang.reflect.*;import javax.swing.*;/** * Displays the properties associated with a bean for editing. An * instance of this class is created by the * {@link com.bbn.openmap.tools.beanbox.BeanBox}to display the * properties of a bean that the user has clicked on the map. An * instance of GenericPropertySheet can also be used as a custom * editor component for a bean property that is itself a bean. */public class GenericPropertySheet extends JDialog implements        PropertyChangeListener {    /**     * contains a referrence to an internal panel that displays the     * bean's properties.     */    protected PropertySheetPanel panel;    /**     * If an instance of this class is used as a custom editor     * component of a bean's property that is itself a bean, this     * member contains a reference to the custom editor.     */    protected PropertyEditor editor;    /** the bean that this property sheet is associated with. */    protected Object targetBean;    /**     * A GenericPropertySheet can be optionally associated with a     * BeanBox.     */    protected BeanBox beanBox;    /**     * contains the rectangular bounds of this GenericPropertySheet.     */    protected Rectangle bounds;    /**     * contains the number of editors displayed in this     * GenericPropertySheet.     */    protected int numEditorsToDisplay;    /**     * Constructs a property sheet dialog.     *      * @param isModal whether the propertysheet should be displayed in     *        a modal dialog.     * @param title the title of this propertysheet.     */    public GenericPropertySheet(boolean isModal, String title) {        super((JFrame) null, title, isModal);    }    /**     * Constructs a property sheet dialog.     *      * @param target the bean associated with this property sheet.     * @param x the top-left x position of this property sheet.     * @param y the top-left y position of this property sheet.     * @param beanBox the beanBox that this propertysheet is     *        associated with. This param is usually non-null only if     *        this is a top-level property-sheet. When this param is     *        non-null, this propertysheet will inform the BeanBox     *        whenever a property on the bean changes by calling the     *        beanChanged method on BeanBox. Additionally the     *        propertysheet will call the editComplete method on the     *        BeanBox when the user closes the window.     */    public GenericPropertySheet(Object target, int x, int y, PropertyEditor pe,            BeanBox beanBox) {        this(false, target, new Rectangle(x, y, 100, 100), pe, beanBox);    }    /**     * Constructs a property sheet dialog.     *      * @param isModal whether to display the propertysheet as a modal     *        dialog.     * @param target the bean property that this class handles.     * @param bounds the boundaries to use     * @param pe the parent PropertyEditor of this sheet. An instance     *        of GenericPropertySheet is invoked from the     *        getCustomEditor method of pe. The parent editor can be     *        null, in which case this class behaves exactly as a     *        regular property sheet class.     * @param beanBox the beanBox that this propertysheet is     *        associated with. This param is usually non-null only if     *        this is a top-level property-sheet. When this param is     *        non-null, this propertysheet will inform the BeanBox     *        whenever a property on the bean changes by calling the     *        beanChanged method on BeanBox.     */    public GenericPropertySheet(boolean isModal, Object target,            Rectangle bounds, PropertyEditor pe, BeanBox beanBox) {        super((JFrame) null, "Properties - <initializing...>", isModal);        this.targetBean = target;        if (bounds == null)            this.bounds = new Rectangle(0, 0, 100, 100);        else {            this.bounds = new Rectangle();            this.bounds.x = bounds.x;            this.bounds.y = bounds.y;            this.bounds.width = (bounds.width > 0) ? bounds.width : 100;            this.bounds.height = (bounds.height > 0) ? bounds.height : 100;        }        this.editor = pe;        this.beanBox = beanBox;        init();        this.getContentPane().add(panel);    }    /**     * Initializes the background, bounds, title, panel and adds a     * window listener.     */    protected void init() {        setBackground(Color.lightGray);        setBounds(bounds.x, bounds.y, bounds.width, bounds.height);        initTitle();        initPanel();        addWindowListener();    }    /**     * Initializes the property sheet panel.     */    protected void initPanel() {        panel = new PropertySheetPanel(this);        if (targetBean != null)            panel.setTarget(targetBean);    }    /**     * Initializes the property sheet's title.     */    protected void initTitle() {        if (targetBean != null) {            Class beanClass = targetBean.getClass();            try {                BeanInfo bi = Introspector.getBeanInfo(beanClass);                String label = bi.getBeanDescriptor().getDisplayName();                setTitle(label + " Properties");            } catch (Exception ex) {                System.err.println("GenericPropertySheet: couldn't find BeanInfo for "                        + beanClass);                ex.printStackTrace();            }        }    }    /**     * adds a window listener to this property sheet. The     * windowClosing method calls the editComplete method on the     * BeanBox associated with this property sheet if there is one.     */    protected void addWindowListener() {        addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent evt) {                if (beanBox != null)                    beanBox.editComplete(targetBean);                setVisible(false);            }        });    }    /**     * Returns the JPanel object used to display all the editors in     * this property sheet.     */    protected PropertySheetPanel getPropertySheetPanel() {        return panel;    }    /**     * Sets the frame size in order to accomodate all property     * editors.     */    protected void setFrameSize() {        int approxControlBarWidth = 60;        int approxTitleBarHeight = 20;        int approxIconWidth = 20;        int approxFontWidth = 8;        int approxFontHeight = 17;        int approxTitleWidth = (getTitle() == null) ? approxControlBarWidth * 2                : (approxIconWidth + (getTitle().length() * approxFontWidth) + approxControlBarWidth);        int width = (approxTitleWidth > 220) ? approxTitleWidth : 220;        setSize(width, approxTitleBarHeight + numEditorsToDisplay                * approxFontHeight * 2);    }    /**     * Sets the number of editors to be displayed on this property     * sheet.     */    protected void setNumEditorsToDisplay(int numEditorsToDisplay) {        this.numEditorsToDisplay = numEditorsToDisplay;    }    /**     * Sets the bean associated with this property sheet. The property     * sheet will re-initialize to display the bean's properties when     * this method is called.     */    public void setTarget(Object bean) {        //System.out.println("Enter>        // GenericPropertySheet.setTarget()");        panel.setTarget(bean);        Class beanClass = bean.getClass();        try {            BeanInfo bi = Introspector.getBeanInfo(beanClass);            String label = bi.getBeanDescriptor().getDisplayName();            setTitle("Properties for " + label);        } catch (Exception ex) {            System.err.println("GenericPropertySheet: couldn't find BeanInfo for "                    + beanClass);            ex.printStackTrace();        }        setVisible(true);        targetBean = bean;        //System.out.println("Exit>        // GenericPropertySheet.setTarget()");    }//    private void setCustomizer(Customizer c) {//        panel.setCustomizer(c);//    }    /**     * Required by interface PropertyChangeListener. This method is     * called whenever one of the properties of the associated bean     * changes. If there is a PropertyEditor associated with this     * property sheet, this method will generate a call to the     * editor's setValue method. If there is a BeanBox associated with     * this property sheet, this method will generate a call to     * beanChanged method on the BeanBox.     */    public void propertyChange(PropertyChangeEvent evt) {        panel.wasModified(evt);        if (editor != null)            editor.setValue(targetBean);        if (beanBox != null)            beanBox.beanChanged(targetBean, evt.getPropertyName());    }}//*****************************************************************************/** * A utilty class used to display a bean's properties on a * GenericPropertySheet. */class PropertySheetPanel extends JPanel {    private GenericPropertySheet _frame;    // We need to cache the targets' wrapper so we can annoate it with    // information about what target properties have changed during    // design    // time.    private Object targetBean;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -