airspacebuilder.java

来自「world wind java sdk 源码」· Java 代码 · 共 1,830 行 · 第 1/5 页

JAVA
1,830
字号
                            {                                setAirspaces(airspaces);                                setEnabled(true);                                getApp().setCursor(null);                                getApp().getWwd().redraw();                            }                        });                    }                }            });            this.setEnabled(false);            getApp().setCursor(new Cursor(Cursor.WAIT_CURSOR));            t.start();        }        protected void saveToFile()        {            if (this.fileChooser == null)            {                this.fileChooser = new JFileChooser();                this.fileChooser.setCurrentDirectory(new File(Configuration.getUserHomeDirectory()));            }            this.fileChooser.setDialogTitle("Choose Directory to Place Airspaces");            this.fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);            this.fileChooser.setMultiSelectionEnabled(false);            int status = this.fileChooser.showSaveDialog(null);            if (status != JFileChooser.APPROVE_OPTION)                return;            final File dir = this.fileChooser.getSelectedFile();            if (dir == null)                return;            if (dir.exists())            {                try                {                    WWIO.deleteDirectory(dir);                }                catch (Exception e)                {                    e.printStackTrace();                }            }            if (!dir.exists())            {                //noinspection ResultOfMethodCallIgnored                dir.mkdirs();            }            final Iterable<AirspaceEntry> entries = this.getModel().getEntries();            Thread t = new Thread(new Runnable()            {                public void run()                {                    try                    {                        java.text.DecimalFormat f = new java.text.DecimalFormat("####");                        f.setMinimumIntegerDigits(4);                        int counter = 0;                        for (AirspaceEntry entry : entries)                        {                            Airspace a = entry.getAirspace();                            AirspaceAttributes currentAttribs = a.getAttributes();                            a.setAttributes(entry.getAttributes());                                                        String xmlString = a.getRestorableState();                            if (xmlString != null)                            {                                try                                {                                    PrintWriter of = new PrintWriter(new File(dir,                                        a.getClass().getName() + "-" + entry.getName() + "-" + f.format(counter++) + ".xml"));                                    of.write(xmlString);                                    of.flush();                                    of.close();                                }                                catch (Exception e)                                {                                    e.printStackTrace();                                }                            }                            a.setAttributes(currentAttribs);                        }                    }                    finally                    {                        SwingUtilities.invokeLater(new Runnable()                        {                            public void run()                            {                                setEnabled(true);                                getApp().setCursor(null);                                getApp().getWwd().redraw();                            }                        });                    }                }            });            this.setEnabled(false);            getApp().setCursor(new Cursor(Cursor.WAIT_CURSOR));            t.start();        }        private void setAirspaces(Iterable<? extends Airspace> airspaces)        {            ArrayList<AirspaceEntry> entryList = new ArrayList<AirspaceEntry>(this.getModel().getEntries());            this.removeEntries(entryList);            for (Airspace airspace : airspaces)            {                airspace.setAttributes(getDefaultAttributes());                AirspaceEntry entry = new AirspaceEntry(airspace, getEditorFor(airspace));                this.addEntry(entry);            }        }        private String getFileName(String s)        {            int index = s.lastIndexOf("/");            if (index == -1)                index = s.lastIndexOf("\\");            if (index != -1 && index < s.length())                return s.substring(index + 1, s.length());            return s;        }    }    //**************************************************************//    //********************  Main  **********************************//    //**************************************************************//    //protected static class ToolTip implements Renderable    //{    //    private String text;    //    private Point point;    //    private ScreenAnnotation annotation;    //    //    private static final Font toolTipFont = UIManager.getFont("ToolTip.font");    //    private static final Color toolTipFg = UIManager.getColor("ToolTip.foreground");    //    private static final Color toolTipBg = UIManager.getColor("ToolTip.background");    //    private static final Border toolTipBorder = UIManager.getBorder("ToolTip.border");    //    //    public ToolTip(String text, Point point, double opacity)    //    {    //        this.text = text;    //        this.point = point;    //        this.annotation = this.createAnnotation(text, point);    //        this.annotation.getAttributes().setOpacity(opacity);    //    }    //    //    public String getText()    //    {    //        return this.text;    //    }    //    //    public Point getPoint()    //    {    //        return this.point;    //    }    //    //    public void render(DrawContext dc)    //    {    //        this.annotation.render(dc);    //    }    //    //    protected ScreenAnnotation createAnnotation(String text, Point point)    //    {    //        AnnotationAttributes attributes = new AnnotationAttributes();    //        attributes.setFont(toolTipFont);    //        attributes.setTextColor(toolTipFg);    //        attributes.setBorderColor(toolTipFg);    //        attributes.setBackgroundColor(toolTipBg);    //        attributes.setBorderWidth(1.0);    //        attributes.setCornerRadius(0);    //        attributes.setInsets(toolTipBorder.getBorderInsets(null));    //        attributes.setEffect(MultiLineTextRenderer.EFFECT_NONE);    //        attributes.setAntiAliasHint(Annotation.ANTIALIAS_DONT_CARE);    //        attributes.setAdjustWidthToText(Annotation.SIZE_FIT_TEXT);    //        attributes.setSize(new Dimension(300, 0));    //    //        ScreenAnnotation sa = new ScreenAnnotation(text, point, attributes);    //        sa.setAlwaysOnTop(true);    //    //        return sa;    //    }    //}    protected static class AppFrame extends ApplicationTemplate.AppFrame    {        // Airspace layer and editor UI components.        private AirspaceLayer airspaceLayer;        private AirspaceBuilderModel builderModel;        private AirspaceBuilderPanel builderView;        private AirspaceBuilderController builderController;        // Tool tip layer.        //private ToolTip toolTip;        //private RenderableLayer toolTipLayer;        public AppFrame()        {            this.airspaceLayer = new AirspaceLayer();            this.airspaceLayer.setName(AIRSPACE_LAYER_NAME);            insertBeforePlacenames(this.getWwd(), this.airspaceLayer);            this.getLayerPanel().update(this.getWwd());            this.builderController = new AirspaceBuilderController(this);            this.builderModel = new AirspaceBuilderModel();            this.builderView = new AirspaceBuilderPanel(this.builderModel, this.builderController);            this.getContentPane().add(this.builderView, BorderLayout.SOUTH);            this.builderController.setModel(this.builderModel);            this.builderController.setView(this.builderView);            this.builderController.setResizeNewShapesToViewport(true);            //this.toolTipLayer = new RenderableLayer();            //this.toolTipLayer.setPickEnabled(false); // Don't want to pick the tool tip            //insertBeforeCompass(this.getWwd(), this.toolTipLayer);            makeMenuBar(this, this.builderController);        }        public AirspaceBuilderPanel getAirspaceBuilderPanel()        {            return this.builderView;        }        public AirspaceLayer getAirspaceLayer()        {            return this.airspaceLayer;        }        //public ToolTip getWorldWindToolTip()        //{        //    return this.toolTip;        //}        //        //public void setWorldWindToolTip(ToolTip toolTip)        //{        //    this.toolTip = toolTip;        //    this.toolTipLayer.removeAllRenderables();        //    if (this.toolTip != null)        //        this.toolTipLayer.addRenderable(this.toolTip);        //}        public static void makeMenuBar(JFrame frame, final AirspaceBuilderController controller)        {            JMenuBar menuBar = new JMenuBar();            final JCheckBoxMenuItem resizeNewShapesItem;            final JCheckBoxMenuItem enableEditItem;            JMenu menu = new JMenu("File");            {                JMenuItem item = new JMenuItem("Open...");                item.setAccelerator(KeyStroke.getKeyStroke(                    KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));                item.setActionCommand(OPEN);                item.addActionListener(controller);                menu.add(item);                item = new JMenuItem("Open URL...");                item.setActionCommand(OPEN_URL);                item.addActionListener(controller);                menu.add(item);                item = new JMenuItem("Save...");                item.setAccelerator(KeyStroke.getKeyStroke(                    KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));                item.setActionCommand(SAVE);                item.addActionListener(controller);                menu.add(item);                menu.addSeparator();                item = new JMenuItem("Load Demo Shapes");                item.setActionCommand(OPEN_DEMO_AIRSPACES);                item.addActionListener(controller);                menu.add(item);            }            menuBar.add(menu);            menu = new JMenu("Shape");            {                JMenu subMenu = new JMenu("New");                for (final AirspaceFactory factory : defaultAirspaceFactories)                {                    JMenuItem item = new JMenuItem(factory.toString());                    item.addActionListener(new ActionListener()                    {                        public void actionPerformed(ActionEvent e)                        {                            controller.createNewEntry(factory);                        }                    });                    subMenu.add(item);                }                menu.add(subMenu);                resizeNewShapesItem = new JCheckBoxMenuItem("Fit new shapes to viewport");                resizeNewShapesItem.setActionCommand(SIZE_NEW_SHAPES_TO_VIEWPORT);                resizeNewShapesItem.addActionListener(controller);                resizeNewShapesItem.setState(controller.isResizeNewShapesToViewport());                menu.add(resizeNewShapesItem);                enableEditItem = new JCheckBoxMenuItem("Enable shape editing");                enableEditItem.setActionCommand(ENABLE_EDIT);                enableEditItem.addActionListener(controller);                enableEditItem.setState(controller.isEnableEdit());                menu.add(enableEditItem);            }            menuBar.add(menu);            menu = new JMenu("Selection");            {                //JMenuItem item = new JMenuItem("Zoom To Selection");                //item.setActionCommand(ZOOM_TO_SELECTED);                //item.addActionListener(controller);                //menu.add(item);                JMenuItem item = new JMenuItem("Deselect");                item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));                item.setActionCommand(CLEAR_SELECTION);                item.addActionListener(controller);                menu.add(item);                item = new JMenuItem("Delete");                item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));                item.setActionCommand(REMOVE_SELECTED);                item.addActionListener(controller);                menu.add(item);            }            menuBar.add(menu);            frame.setJMenuBar(menuBar);            controller.addPropertyChangeListener(new PropertyChangeListener()            {                public void propertyChange(PropertyChangeEvent e)                {                    //noinspection StringEquality                    if (e.getPropertyName() == SIZE_NEW_SHAPES_TO_VIEWPORT)                    {                        resizeNewShapesItem.setSelected(controller.isResizeNewShapesToViewport());                    }                    else //noinspection StringEquality                        if (e.getPropertyName() == ENABLE_EDIT)                    {                        enableEditItem.setSelected(controller.isEnableEdit());                    }                }            });        }    }        public static void main(String[] args)    {        ApplicationTemplate.start("Airspace Builder", AppFrame.class);    }}

⌨️ 快捷键说明

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