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

📄 symbolchooser.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/tools/symbology/milStd2525/SymbolChooser.java,v $// $RCSfile: SymbolChooser.java,v $// $Revision: 1.4.2.8 $// $Date: 2005/08/11 21:03:16 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.tools.symbology.milStd2525;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Graphics;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.HeadlessException;import java.awt.Insets;import java.awt.Window;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.image.BufferedImage;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.Serializable;import java.util.Enumeration;import java.util.Hashtable;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.JTree;import javax.swing.UIManager;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.TreePath;import javax.swing.tree.TreeSelectionModel;import com.bbn.openmap.event.ListenerSupport;import com.bbn.openmap.gui.DimensionQueryPanel;import com.bbn.openmap.image.AcmeGifFormatter;import com.bbn.openmap.image.BufferedImageHelper;import com.bbn.openmap.image.ImageFormatter;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.omGraphics.DrawingAttributes;import com.bbn.openmap.util.ArgParser;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.FileUtils;import com.bbn.openmap.util.PaletteHelper;/** * The SymbolChooser is a GUI symbol builder. It can be used in * stand-alone mode to create image files, or be integrated into a * java application to create ImageIcons. * <P> * To bring up this chooser, run this class as a standalone * application, or call showDialog(..) */public class SymbolChooser extends JPanel implements ActionListener {    public final static String CREATE_IMAGE_CMD = "CREATE_IMAGE_CMD";    public final static String NAMEFIELD_CMD = "NAMEFIELD_CMD";    public final static String EMPTY_FEATURE_LIST = null;    public final static int DEFAULT_ICON_DIMENSION = 100;    public final static String EMPTY_CODE = "---------------";    protected static ImageIcon DEFAULT_SYMBOL_IMAGE;    protected DrawingAttributes drawingAttributes = new DrawingAttributes();    protected ImageIcon symbolImage;    protected DefaultMutableTreeNode currentSymbol = null;    protected SymbolTreeHolder currentSymbolTreeHolder;    protected SymbolReferenceLibrary library;    protected List trees;    protected DimensionQueryPanel dqp;    protected JButton clearFeaturesButton;    protected JButton createImageFileButton;    protected JTextField nameField;    protected JLabel symbolImageLabel;    protected JScrollPane treeView;    protected JPanel optionPanel;    protected Dimension iconDimension;    protected boolean allowCreateImage = true;    public SymbolChooser(SymbolReferenceLibrary srl) {        library = srl;        try {            trees = createNodes(srl);        } catch (FormatException fe) {            Debug.output("SymbolChooser(): Caught FormatException reading data: "                    + fe.getMessage());        }        init(srl, trees);    }    /**     * Update the GUI with the contents of the provided     * SymbolTreeHolder, reflecting a new set of symbols.     *      * @param sth     */    public void setSelectedTreeHolder(SymbolTreeHolder sth) {        treeView.setViewportView(sth.getTree());        optionPanel.removeAll();        optionPanel.add(sth.getOptionPanel());        sth.handleNodeSelection((DefaultMutableTreeNode) sth.tree.getLastSelectedPathComponent());        revalidate();    }    /**     * Convenience function to get a standard blank image for those     * SymbolParts that are not found by the SymbolImageMaker.     *      * @return DEFAULT_SYMBOL_IMAGE     */    public static ImageIcon getNotFoundImageIcon() {        if (DEFAULT_SYMBOL_IMAGE == null) {            BufferedImage bi = new BufferedImage(DEFAULT_ICON_DIMENSION, DEFAULT_ICON_DIMENSION, BufferedImage.TYPE_INT_RGB);            Graphics g = bi.getGraphics();            g.setColor(Color.LIGHT_GRAY);            g.fillRect(0, 0, DEFAULT_ICON_DIMENSION, DEFAULT_ICON_DIMENSION);            DEFAULT_SYMBOL_IMAGE = new ImageIcon(bi);        }        return DEFAULT_SYMBOL_IMAGE;    }    /**     * Create the GUI based on the contents of the     * SymbolReferenceLibrary and the SymbolPartTrees created from the     * options.     *      * @param srl     * @param trees     */    protected void init(SymbolReferenceLibrary srl, List trees) {        /////////////////////        // Create the tree window by creating the scroll pane and add        // the tree to it.        GridBagLayout outergridbag = new GridBagLayout();        GridBagConstraints outerc = new GridBagConstraints();        JPanel setChoicePanel = new JPanel();        JLabel setChoiceLabel = new JLabel("Symbol Set:");        JComboBox setChoices = new JComboBox(trees.toArray());        setChoices.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                JComboBox jcb = (JComboBox) e.getSource();                setSelectedTreeHolder((SymbolTreeHolder) jcb.getSelectedItem());            }        });        currentSymbolTreeHolder = (SymbolTreeHolder) setChoices.getSelectedItem();        setChoicePanel.add(setChoiceLabel);        setChoicePanel.add(setChoices);        treeView = new JScrollPane(currentSymbolTreeHolder.getTree());        setLayout(outergridbag);        outerc.fill = GridBagConstraints.BOTH;        outerc.gridwidth = GridBagConstraints.REMAINDER;        outerc.weighty = 0.0;        outerc.insets = new Insets(5, 10, 5, 10);        outergridbag.setConstraints(setChoicePanel, outerc);        add(setChoicePanel);        outerc.weightx = 1.0;        outerc.weighty = 1.0;        outerc.gridwidth = GridBagConstraints.RELATIVE;        outergridbag.setConstraints(treeView, outerc);        add(treeView);        // Add the symbol preview area to the right of the tree        JPanel symbolPanel = PaletteHelper.createVerticalPanel(" Current Symbol ");        setImageIcon(getNotFoundImageIcon());        symbolPanel.add(symbolImageLabel);        outerc.weightx = 0.0;        outerc.gridwidth = GridBagConstraints.REMAINDER;        outergridbag.setConstraints(symbolPanel, outerc);        dqp = new DimensionQueryPanel(getDesiredIconDimension());        dqp.addActionListener(this);        outergridbag.setConstraints(dqp, outerc);        symbolPanel.add(dqp);        add(symbolPanel);        /////////////////////        optionPanel = PaletteHelper.createVerticalPanel(" Symbol Attributes ");        optionPanel.add(((SymbolTreeHolder) setChoices.getSelectedItem()).getOptionPanel());        outergridbag.setConstraints(optionPanel, outerc);        add(optionPanel);        /////////////////////        // gridbag2 is for the name panel and the recent symbols.        GridBagLayout gridbag2 = new GridBagLayout();        GridBagConstraints c2 = new GridBagConstraints();        JPanel namePanel = new JPanel();        namePanel.setLayout(gridbag2);        c2.weightx = 0;        c2.anchor = GridBagConstraints.WEST;        JLabel nameLabel = new JLabel("Symbol Code: ");        gridbag2.setConstraints(nameLabel, c2);        namePanel.add(nameLabel);        c2.fill = GridBagConstraints.HORIZONTAL;        c2.weightx = 1.0;        if (nameField == null) {            nameField = new JTextField(EMPTY_CODE);        }        nameField.addActionListener(this);        nameField.setActionCommand(NAMEFIELD_CMD);        gridbag2.setConstraints(nameField, c2);        namePanel.add(nameField);        createImageFileButton = new JButton("Create Image File");        createImageFileButton.addActionListener(this);        createImageFileButton.setActionCommand(CREATE_IMAGE_CMD);        createImageFileButton.setEnabled(false);        createImageFileButton.setVisible(allowCreateImage);        c2.weightx = 0.0;        gridbag2.setConstraints(createImageFileButton, c2);        namePanel.add(createImageFileButton);        outerc.weighty = 0.0;        outerc.gridwidth = GridBagConstraints.REMAINDER;        outergridbag.setConstraints(namePanel, outerc);        add(namePanel);        /////////////////////        // Just call this to make sure that the stuff in the name        // field matches the selected JTree        setSelectedTreeHolder(currentSymbolTreeHolder);    }    public void actionPerformed(ActionEvent ae) {        String command = ae.getActionCommand();        if (command == CREATE_IMAGE_CMD && library != null && nameField != null) {            Dimension d = getDesiredIconDimension();            ImageIcon ii = library.getIcon(getCode(), d);            if (ii == null) {                createImageFileButton.setEnabled(false);                return;            }            try {                BufferedImage bi = BufferedImageHelper.getBufferedImage(ii.getImage(),                        0,                        0,                        (int) d.getWidth(),                        (int) d.getHeight(),                        BufferedImage.TYPE_INT_ARGB);                ImageFormatter formatter = new AcmeGifFormatter();                byte[] imageBytes = formatter.formatImage(bi);                String newFileName = FileUtils.getFilePathToSaveFromUser("Create File To Save");                if (newFileName != null) {                    FileOutputStream fos = new FileOutputStream(newFileName);                    fos.write(imageBytes);                    fos.flush();                    fos.close();                }            } catch (InterruptedException e) {                e.printStackTrace();            } catch (FileNotFoundException e) {                e.printStackTrace();            } catch (IOException e) {                e.printStackTrace();

⌨️ 快捷键说明

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