sar2.java

来自「world wind java sdk 源码」· Java 代码 · 共 990 行 · 第 1/3 页

JAVA
990
字号
        }        catch (IOException e)        {            e.printStackTrace();        }        if (track == null)            return;        if (name == null)            name = urlString;        track.setFile(null);        track.setName(name);        trackController.addTrack(track);        track.markDirty();    }    private static URL makeURL(String urlString)    {        URL url = null;        try        {            if (urlString != null)                url = new URL(urlString);        }        catch (MalformedURLException e)        {            url = null;        }        return url;    }    private int removeTrack(SARTrack track, boolean forceSavePrompt)    {        if (track == null)            return OK;        int status = OK;        if (track.isDirty() || forceSavePrompt)        {            int option = SaveTrackDialog.showSaveChangesPrompt(this, null, null, track);            // Show a save track dialog that will            // always prompt the user to choose a location.            if (option == JOptionPane.YES_OPTION)                status = saveTrack(track, true);            else if (option == JOptionPane.CANCEL_OPTION)                status = CANCELLED;        }        if (status != OK)            return status;        try        {            track.firePropertyChange(TrackController.TRACK_REMOVE, null, track);            this.trackController.refreshCurrentTrack();            this.annotationSupport.removeAnnotationsForTrack(track);            this.wwd.redraw();        }        catch (Exception e)        {            e.printStackTrace();            return ERROR;        }        return OK;    }    private int removeAllTracks(boolean forceSavePrompt)    {        int status = OK;        for (SARTrack track : getTracksPanel().getAllTracks())        {            status |= removeTrack(track, forceSavePrompt);            if ((status & CANCELLED) != 0)                return status;        }        return status;    }    private int saveTrack(SARTrack track, boolean forceSavePrompt)    {        return saveTrack(            track,            null,  // Use track's file, or prompt user.            0,     // Use track's format.            true,  // Save annotations            forceSavePrompt);    }    private int saveTrack(SARTrack track, File file, int format, boolean saveAnnotations, boolean forceSavePrompt)    {        if (track == null)            return OK;        if (file == null)            file = track.getFile();        if (format == 0)            format = track.getFormat();        // Show the "Overwrite?" dialog if:        // * The current track has a source file.        // * AND The caller has specified not to show the save dialog.        //if (file != null && !forceSavePrompt)        //{        //    int result = SaveTrackDialog.showOverwritePrompt(this, null, null, JOptionPane.YES_NO_CANCEL_OPTION, file);        //    if (result == JOptionPane.CANCEL_OPTION)        //        return CANCELLED;        //    else if (result == JOptionPane.NO_OPTION)        //        forceSavePrompt = true;        //}        // Show the "Save As..." dialog if either:        // * The current track has no source file.        // * The caller has specified that the user should prompted to select a file,        if (file == null || forceSavePrompt)        {            int result = showSaveDialog(track);            if (result == SaveTrackDialog.CANCEL_OPTION)                return CANCELLED;            else if (result == SaveTrackDialog.ERROR_OPTION)                return ERROR;            file = this.saveTrackDialog.getSelectedFile();            format = this.saveTrackDialog.getFileFormat();            saveAnnotations = this.saveTrackDialog.isSaveAnnotations();        }        try        {            // Get the file's last modified time,            // or zero if the file does not exist.            long time = file.exists() ? file.lastModified() : 0;            SARTrack.toFile(track, file.getPath(), format);            if (saveAnnotations)            {                String annotationFilePath = getAnnotationsPath(file.getPath());                                this.annotationSupport.writeAnnotations(annotationFilePath, track);            }            // If the track was saved sucessfully (it exists and            // is newer than is was before the save operation),            // then adopt the properties of the new            // file and format, and clear the track's dirty bit.            if (file.exists() && time <= file.lastModified())            {                track.setFile(file);                track.setFormat(format);                track.setName(file.getName());                track.clearDirtyBit();            }        }        catch (Exception e)        {            e.printStackTrace();            return ERROR;        }        return OK;    }    private int showSaveDialog(SARTrack track)    {        if (this.saveTrackDialog == null)            this.saveTrackDialog = new SaveTrackDialog();        this.saveTrackDialog.setDialogTitle(track);        this.saveTrackDialog.setFileFormat(track);        this.saveTrackDialog.setSelectedFile(track);        return this.saveTrackDialog.showSaveDialog(this);    }    private void bulkDownload()    {        if (this.bulkDownloadFrame == null)        {            this.bulkDownloadFrame = new BulkDownloadFrame(this.wwd);            this.bulkDownloadFrame.setLocation(new Point(this.getLocationOnScreen().x + 100,                this.getLocationOnScreen().y + 100));        }        this.bulkDownloadFrame.setVisible(true);    }    private SARAnnotation getCurrentAnnotation()    {        return this.annotationSupport.getCurrent();    }    private void newAnnotation()    {        newAnnotation(null, getCurrentTrack());    }    private void newAnnotation(String text, SARTrack track)    {        this.annotationSupport.addNew(text, track);        this.wwd.redraw();    }    private void removeAnnotation(SARAnnotation annotation)    {        if (annotation != null)        {            this.annotationSupport.remove(annotation);        }        this.wwd.redraw();    }    private void setAnnotationsEnabled(boolean show)    {        this.annotationSupport.setEnabled(show);        this.wwd.redraw();    }    private void showHelp()    {        try        {            if (this.helpFrame == null)                this.helpFrame = new HelpFrame();            this.helpFrame.setVisible(true);        }        catch (IOException e1)        {            System.err.println("Unable to open Help window");            e1.printStackTrace();        }    }    public void showAbout()    {        SARAboutDialog dialog = new SARAboutDialog();        dialog.showDialog(this);    }    public boolean exit()    {        int status = removeAllTracks(false);        if ((status & CANCELLED) != 0)            return false;        dispose();        System.exit(0);        return true;    }    private String getAnnotationsPath(String trackFilePath)    {        return (trackFilePath != null) ? trackFilePath + ".sta" : null;    }    private void initComponents()    {        //======== this ========        setTitle("World Wind Search and Rescue");        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);        addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent event) {                exit();            }            public void windowClosed(WindowEvent event) {                exit();            }        });        Container contentPane = getContentPane();        contentPane.setLayout(new BorderLayout());        controlPanel = new ControlPanel();        contentPane.add(controlPanel, BorderLayout.WEST);        //---- WWPanel ----        wwPanel = new WWPanel();        wwPanel.setPreferredSize(new Dimension(1000, 800));        contentPane.add(wwPanel, BorderLayout.CENTER);        //======== MenuBar ========        JMenuBar menuBar = new JMenuBar();        {            JMenu fileMenu = new JMenu();            //======== "File" ========        	{        		fileMenu.setText("File");        		fileMenu.setMnemonic('F');                //---- "New Track" ----        		JMenuItem newTrack = new JMenuItem();                newTrack.setText("New Track...");                newTrack.setMnemonic('N');                newTrack.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));                newTrack.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        newTrack(null);                    }                });                fileMenu.add(newTrack);                //---- "Open Track File" ----        		JMenuItem openTrackFile = new JMenuItem();                openTrackFile.setText("Open Track File...");                openTrackFile.setMnemonic('O');                openTrackFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));                openTrackFile.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        newTrackFromFile(null, null);                    }                });                fileMenu.add(openTrackFile);        		//---- "Open Track URL..." ----                JMenuItem openTrackURL = new JMenuItem();                openTrackURL.setText("Open Track URL...");                openTrackURL.setMnemonic('U');                openTrackURL.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U,                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));                openTrackURL.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        newTrackFromURL(null, null);                    }                });                fileMenu.add(openTrackURL);        		//---- "Close Track" ----                JMenuItem removeTrack = new JMenuItem();                removeTrack.setText("Close Track");

⌨️ 快捷键说明

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