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

📄 inspector.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        } else {            // otherwise, show them all, in alphabetical order            sortedKeys = sortKeys(keySet);        }        int num = sortedKeys.size();        editors = new Hashtable(num);        JButton doneButton = null, cancelButton = null;        JPanel component = new JPanel();        component.setLayout(new BorderLayout());        JPanel propertyPanel = new JPanel();        GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        c.insets = new Insets(2, 10, 2, 10);        propertyPanel.setLayout(gridbag);        int i = 0;        for (Iterator it = sortedKeys.iterator(); it.hasNext();) { // iterate            // properties            String prop = (String) it.next();            String marker = prop;            if (prefix != null && prop.startsWith(prefix)) {                marker = prop.substring(prefix.length() + 1);            }            if (marker.startsWith(".")) {                marker = marker.substring(1);            }            String editorMarker = marker                    + PropertyConsumer.ScopedEditorProperty;            String editorClass = info.getProperty(editorMarker);            if (editorClass == null) {                editorClass = defaultEditorClass;            }            // instantiate PropertyEditor            Class propertyEditorClass = null;            PropertyEditor editor = null;            try {                propertyEditorClass = Class.forName(editorClass);                editor = (PropertyEditor) propertyEditorClass.newInstance();                if (editor instanceof PropertyConsumer) {                    ((PropertyConsumer) editor).setProperties(marker, info);                }                editors.put(prop, editor);            } catch (Exception e) {                e.printStackTrace();                editorClass = null;            }            Component editorFace = null;            if (editor != null && editor.supportsCustomEditor()) {                editorFace = editor.getCustomEditor();            } else {                editorFace = new JLabel("Does not support custom editor");            }            if (editor != null) {                Object propVal = props.get(prop);                if (Debug.debugging("inspector")) {                    Debug.output("Inspector loading " + prop + "(" + propVal                            + ")");                }                editor.setValue(propVal);            }            // Customized labels for each property, instead of the            // abbreviated nature of the true property names.            String labelMarker = marker + PropertyConsumer.LabelEditorProperty;            String labelText = info.getProperty(labelMarker);            if (labelText == null) {                labelText = marker;            }            JLabel label = new JLabel(labelText + ":");            label.setHorizontalAlignment(SwingConstants.RIGHT);            c.gridx = 0;            c.gridy = i++;            c.weightx = 0;            c.fill = GridBagConstraints.NONE;            c.anchor = GridBagConstraints.EAST;            gridbag.setConstraints(label, c);            propertyPanel.add(label);            c.gridx = 1;            c.anchor = GridBagConstraints.WEST;            c.fill = GridBagConstraints.HORIZONTAL;            c.weightx = 1f;            gridbag.setConstraints(editorFace, c);            propertyPanel.add(editorFace);            String toolTip = (String) info.get(marker);            label.setToolTipText(toolTip == null ? "No further information available."                    : toolTip);        }        // create the palette's scroll pane        JScrollPane scrollPane = new JScrollPane(propertyPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);        //      scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);        scrollPane.setAlignmentY(Component.TOP_ALIGNMENT);        component.add(scrollPane, BorderLayout.CENTER);        JPanel buttons = new JPanel();        if (print) {            doneButton = new JButton("Print");            cancelButton = new JButton("Quit");        } else {            doneButton = new JButton("OK");            cancelButton = new JButton("Cancel");        }        doneButton.addActionListener(this);        doneButton.setActionCommand(doneCommand);        cancelButton.addActionListener(this);        cancelButton.setActionCommand(cancelCommand);        buttons.add(doneButton);        buttons.add(cancelButton);        component.add(buttons, BorderLayout.SOUTH);        component.validate();        return component;    }    /**     * Implement the ActionListener interface. The actions registering     * here should be generated by the two buttons in the Inspector     * GUI.     */    public void actionPerformed(ActionEvent e) {        final String actionCommand = e.getActionCommand();        String prefix = propertyConsumer.getPropertyPrefix();        if (actionCommand == doneCommand) {// confirmed            Properties props = collectProperties();            if (!print) {                windowSupport.killWindow();                propertyConsumer.setProperties(prefix, props);                if (actionListener != null) {                    actionListener.actionPerformed(e);                }            } else {                Collection keys = props.keySet();                Iterator it = keys.iterator();                while (it.hasNext()) {                    String next = (String) it.next();                    System.out.println(next + "=" + props.get(next));                }            }        } else if (actionCommand == cancelCommand) {// canceled            if (actionListener != null && actionListener != this) {                actionListener.actionPerformed(e);            }            propertyConsumer = null; // to be garb. coll'd            windowSupport.killWindow();            if (print) {                System.exit(0);            }        }    }    /** Extracts properties from textfield[]. */    public Properties collectProperties() {        Properties props = new Properties();        Iterator values = editors.keySet().iterator();        while (values.hasNext()) {            String key = (String) values.next();            PropertyEditor editor = (PropertyEditor) editors.get(key);            if (editor != null) {                String stuff = editor.getAsText();                // If it's not defined with text, don't put it in the                // properties. The layer should handle this and use                // its default settings.                if (!stuff.equals("")) {                    props.put(key, stuff);                }                if (editor instanceof PropertyConsumer) {                    ((PropertyConsumer) editor).getProperties(props);                }            }        }        return props;    }    public void setPrint(boolean p) {        print = p;    }    public boolean getPrint() {        return print;    }    public WindowSupport getWindowSupport() {        return windowSupport;    }    /** test cases. */    public static void main(String[] args) {        Debug.init();        String name = (args.length < 1) ? "com.bbn.openmap.layer.shape.ShapeLayer"                : args[0];        PropertyConsumer propertyconsumer = null;        try {            Class c = Class.forName(name);            propertyconsumer = (PropertyConsumer) c.newInstance();        } catch (Exception e) {            e.printStackTrace();            System.exit(1);        }        Properties props = new Properties(), info = new Properties();        System.out.println("Inspecting " + name);        String pp = name.substring(name.lastIndexOf(".") + 1);        propertyconsumer.setPropertyPrefix(pp.toLowerCase());        props = propertyconsumer.getProperties(props);        info = propertyconsumer.getPropertyInfo(info);        Inspector inspector = new Inspector();        inspector.setPrint(true);        inspector.addActionListener(inspector);        inspector.inspectPropertyConsumer(propertyconsumer);    }}

⌨️ 快捷键说明

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