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

📄 symbolchooser.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        + " user object with code |" + sp.getCode()                        + "| at code position "                        + sp.getCodePosition().startIndex);            }            if (sp.codeMatches(code)) {                return getNodeForCodeStartingAt(root, code);            } else {                return null;            }        }        protected DefaultMutableTreeNode getNodeForCodeStartingAt(                                                                  DefaultMutableTreeNode node,                                                                  String code) {            Enumeration enumeration = node.children();            while (enumeration.hasMoreElements()) {                DefaultMutableTreeNode kid = (DefaultMutableTreeNode) enumeration.nextElement();                SymbolPart ssp = (SymbolPart) kid.getUserObject();                try {                    if (code.charAt(ssp.getCodePosition().startIndex) == '-')                        return node;                    if (ssp.codeMatches(code)) {                        return getNodeForCodeStartingAt(kid, code);                    }                } catch (StringIndexOutOfBoundsException sioobe) {                } catch (NullPointerException npe) {                }            }            return node;        }        /**         * Given an text string, have the options available to the         * current SymbolTreeHolder reflect those updates.         *          * @param text         */        protected void updateOptionsForCode(String text) {            for (Iterator it = options.getOptions().iterator(); it.hasNext();) {                CodePosition cp = (CodePosition) it.next();                JComboBox jcb = (JComboBox) optionMenuHashtable.get(cp);                if (jcb != null) {                    int numComps = jcb.getItemCount();                    for (int i = 0; i < numComps; i++) {                        if (((CodePosition) jcb.getItemAt(i)).codeMatches(text)) {                            jcb.setSelectedIndex(i);                            break;                        }                    }                }            }        }        public void valueChanged(TreeSelectionEvent e) {            handleNodeSelection((DefaultMutableTreeNode) tree.getLastSelectedPathComponent());        }        public void updateInterfaceToLastSelectedNode() {            handleNodeSelection((DefaultMutableTreeNode) tree.getLastSelectedPathComponent());        }        public void handleNodeSelection(DefaultMutableTreeNode node) {            if (node == null) {                setCode("");                return;            }            Object nodeInfo = node.getUserObject();            if (nodeInfo instanceof SymbolPart) {                SymbolPart symbolPart = (SymbolPart) nodeInfo;                currentSymbol = node;                setCode(updateStringWithCurrentOptionChars(symbolPart.getSymbolCode()));                ImageIcon ii = library.getIcon(getCode(),                        new Dimension(DEFAULT_ICON_DIMENSION, DEFAULT_ICON_DIMENSION));                if (createImageFileButton != null) {                    createImageFileButton.setEnabled(ii != null);                }                if (ii == null) {                    ii = getNotFoundImageIcon();                }                setImageIcon(ii);            } else {                setCode("");                setImageIcon(getNotFoundImageIcon());                createImageFileButton.setEnabled(false);            }        }        public JPanel getOptionPanel() {            if (optionPanel == null) {                optionMenuHashtable = new Hashtable();                optionPanel = new JPanel();                GridBagLayout gridbag = new GridBagLayout();                GridBagConstraints c = new GridBagConstraints();                optionPanel.setLayout(gridbag);                if (options != null) {                    int i = 0;                    for (Iterator it = options.getOptions().iterator(); it.hasNext();) {                        CodePosition cp = (CodePosition) it.next();                        List lt = cp.getPositionChoices();                        if (lt != null) {                            JLabel label = new JLabel(cp.getPrettyName() + ": ");                            c.gridx = 0;                            c.gridy = i++;                            c.weightx = 0;                            c.fill = GridBagConstraints.NONE;                            c.anchor = GridBagConstraints.EAST;                            gridbag.setConstraints(label, c);                            optionPanel.add(label);                            JComboBox jcb = new JComboBox(lt.toArray());                            jcb.addActionListener(new ActionListener() {                                public void actionPerformed(ActionEvent ae) {                                    setPositionSetting((CodePosition) ((JComboBox) ae.getSource()).getSelectedItem());                                    updateInterfaceToLastSelectedNode();                                }                            });                            c.gridx = 1;                            c.anchor = GridBagConstraints.WEST;                            c.fill = GridBagConstraints.HORIZONTAL;                            c.weightx = 1f;                            gridbag.setConstraints(jcb, c);                            optionPanel.add(jcb);                            optionMenuHashtable.put(cp, jcb);                        }                    }                } else {                    optionPanel.add(new JLabel("No options available for these symbols."));                }            }            return optionPanel;        }        public void setPositionSetting(CodePosition cp) {            if (Debug.debugging("codeposition")) {                Debug.output("Setting " + cp.getPrettyName() + " ["                        + cp.getID() + "] at " + cp.getStartIndex() + ", "                        + cp.getEndIndex());            }            updateOptionChars(cp);            setCode(updateStringWithCurrentOptionChars(getCode()));        }        public void updateOptionChars(CodePosition cp) {            String cpString = cp.getID();            for (int i = 0; i < cpString.length(); i++) {                char curChar = cpString.charAt(i);                optionChars[cp.getStartIndex() + i] = new Character(curChar);            }        }        public String updateStringWithCurrentOptionChars(                                                         String currentSymbolCode) {            try {                StringBuffer buf = new StringBuffer(currentSymbolCode);                for (int i = 0; i < optionChars.length; i++) {                    Character c = optionChars[i];                    if (c != null) {                        buf.setCharAt(i, c.charValue());                    }                }                currentSymbolCode = buf.toString();            } catch (StringIndexOutOfBoundsException siobe) {            } catch (NullPointerException npe) {            }            return currentSymbolCode;        }        public String toString() {            return ((SymbolPart) getSource()).getCodePosition().getPrettyName();        }    }}/* * Class which builds a symbol chooser dialog consisting of a * SymbolChooser with "Ok", "Cancel", and "Reset" buttons. This class * is based on the contents of the JColorChooser components. */class SymbolChooserDialog extends JDialog {    private String initialCode;    private SymbolChooser chooserPane;    public SymbolChooserDialog(Component c, String title, boolean modal,            SymbolChooser chooserPane, ActionListener okListener,            ActionListener cancelListener) throws HeadlessException {        super(JOptionPane.getFrameForComponent(c), title, modal);        this.chooserPane = chooserPane;        String okString = UIManager.getString("ColorChooser.okText");        String cancelString = UIManager.getString("ColorChooser.cancelText");        String resetString = UIManager.getString("ColorChooser.resetText");        Container contentPane = getContentPane();        contentPane.setLayout(new BorderLayout());        contentPane.add(chooserPane, BorderLayout.CENTER);        /*         * Create Lower button panel         */        JPanel buttonPane = new JPanel();        buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));        JButton okButton = new JButton(okString);        getRootPane().setDefaultButton(okButton);        okButton.setActionCommand("OK");        if (okListener != null) {            okButton.addActionListener(okListener);        }        okButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                hide();            }        });        buttonPane.add(okButton);        JButton cancelButton = new JButton(cancelString);        cancelButton.setActionCommand("cancel");        if (cancelListener != null) {            cancelButton.addActionListener(cancelListener);        }        cancelButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                hide();            }        });        buttonPane.add(cancelButton);        JButton resetButton = new JButton(resetString);        resetButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                reset();            }        });        buttonPane.add(resetButton);        contentPane.add(buttonPane, BorderLayout.SOUTH);        applyComponentOrientation(((c == null) ? getRootPane() : c).getComponentOrientation());        pack();        setLocationRelativeTo(c);    }    public void show() {        initialCode = chooserPane.getCode();        super.show();    }    public void reset() {        chooserPane.setCode(initialCode);        chooserPane.handleManualNameFieldUpdate(initialCode);    }    static class Closer extends WindowAdapter implements Serializable {        public void windowClosing(WindowEvent e) {            Window w = e.getWindow();            w.hide();        }    }    static class DisposeOnClose extends ComponentAdapter implements            Serializable {        public void componentHidden(ComponentEvent e) {            Window w = (Window) e.getComponent();            w.dispose();        }    }}class SymbolTracker implements ActionListener, Serializable {    SymbolChooser chooser;    ImageIcon icon;    public SymbolTracker(SymbolChooser c) {        chooser = c;    }    public void actionPerformed(ActionEvent e) {        icon = chooser.library.getIcon(chooser.getCode(),                chooser.getDesiredIconDimension());    }    public ImageIcon getImageIcon() {        return icon;    }}

⌨️ 快捷键说明

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