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

📄 swinggui.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    public void closeEditor(File file) {
        int index = this.editorFiles.indexOf(file);
        if (this.editorFiles.size() == 1) {
            this.splitter2.setBottomComponent(null);
        }
        this.editors.removeTabAt(index);
        this.editorFiles.remove(index);
    }

    
    /**
     * 
     * @param file
     */
    public void openFileInEditor(File file) {
        try {
            this.editFile(file);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    
    /**
     * 
     * @param e
     */
    void jMenuItem1_actionPerformed(ActionEvent e) 
    {
        this.close();
    }

    
    /**
     * Called on FILE/NEW
     * @param e The action event
     */
    void jMenuItem2_actionPerformed(ActionEvent e) 
    {
        // Check if the main window is empty
        int x = this.answer.getText().length();
        if (x > 2) {
            // No
            // Do you want save it?
            jMenuItem5_actionPerformed(e);
        }
        this.setTitle(this.appTitle);
        KeyHandler kh = (KeyHandler) (this.answer.getKeyListeners()[0]);
        CommandHistoryManager.getDefaultInstance().clearCurrentSession();
        this.answer.setText("> ");
    }


    /**
     * Called on FILE/OPEN
     * @param e The action event
     */
    void jMenuItem3_actionPerformed(ActionEvent e) 
    {
        int val = jFileChooser1.showOpenDialog(this);
        if (val == JFileChooser.APPROVE_OPTION) 
        {
            loadWorkspace(jFileChooser1.getSelectedFile());
        }
    }


    /**
     * Called on FILE/SAVE
     * @param e The action event
     */
    void jMenuItem4_actionPerformed(ActionEvent e) 
    {
        // Check if we have already opened a file
        if (this.getTitle().length() < this.appTitle.length()) 
        {
            // Yes
            String fileName = this.getTitle().substring(this.appTitle.length());
            saveWorkspace(new File(fileName));
        } 
        else 
        {
            jMenuItem5_actionPerformed(e);
        }
    }



    /**
     * Called on FILE/SAVE AS..
     * @param e The action event
     */
    void jMenuItem5_actionPerformed(ActionEvent e) 
    {
        int val = jFileChooser1.showSaveDialog(this);
        if (val == JFileChooser.APPROVE_OPTION) 
        {
            File f = jFileChooser1.getSelectedFile();
            if (!f.getName().endsWith(".msw")) 
            {
                f = new File(f.getAbsolutePath() + ".msw");
            }
            saveWorkspace(f);
        }
    }


    /**
     * 
     * @param e
     */
    void jMenuItem6_actionPerformed(ActionEvent e) {
        new About();
    }


    /**
     * 
     * @param e
     */
    void jMenuItem7_actionPerformed(ActionEvent e) {
        new ReleaseNotes();
    }


    /**
     * 
     * @param e
     */
    void jMenuItem8_actionPerformed(ActionEvent e) {
        String s = answer.getcurrentWord();
        HTMLRenderDialog hrd = new HTMLRenderDialog(SwingGUI.runningReference, "Function reference: " + s, false);
        try {
            hrd.setPage("file:///" + new File("").getCanonicalPath() + "\\handbook\\function_" + s + ".html");
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }


    /**
     * 
     * @param e
     */
    void jMenuItem9_actionPerformed(ActionEvent e) {
        HTMLRenderDialog hrd = new HTMLRenderDialog(SwingGUI.runningReference, "JMathLib Documentation", false);
        try {
            hrd.setPage("file:///" + new File("").getCanonicalPath() + "\\handbook\\index.html");
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }


    /**
     * 
     * @param e
     */
    void jMenuItem10_actionPerformed(ActionEvent e) {
        // Edit - Cut
        // Let's "cut" the text to the System Clipboard
        Robot r = null;
        try {
            r = new Robot();
        } catch (AWTException awtex) {
            awtex.printStackTrace();
        }
        r.keyPress(KeyEvent.VK_CONTROL);
        r.keyPress(KeyEvent.VK_X);
        r.keyRelease(KeyEvent.VK_X);
        r.keyRelease(KeyEvent.VK_CONTROL);
    }


    /**
     * 
     * @param e
     */
    void jMenuItem11_actionPerformed(ActionEvent e) {
        // Edit - Copy
        // Let's "copy" the text to the System Clipboard
        Robot r = null;
        try {
            r = new Robot();
        } catch (AWTException awtex) {
            awtex.printStackTrace();
        }
        r.keyPress(KeyEvent.VK_CONTROL);
        r.keyPress(KeyEvent.VK_C);
        r.keyRelease(KeyEvent.VK_C);
        r.keyRelease(KeyEvent.VK_CONTROL);
    }


    /**
     * 
     * @param e
     */
    void jMenuItem12_actionPerformed(ActionEvent e) {
        // Edit - Paste
        // Let's paste the content System Clipboard (if possible)
        Robot r = null;
        try {
            r = new Robot();
        } catch (AWTException awtex) {
            awtex.printStackTrace();
        }
        r.keyPress(KeyEvent.VK_CONTROL);
        r.keyPress(KeyEvent.VK_V);
        r.keyRelease(KeyEvent.VK_V);
        r.keyRelease(KeyEvent.VK_CONTROL);
    }


    /**
     * 
     * @param e
     */
    void jMenuItem13_actionPerformed(ActionEvent e) {
        // Edit - Select All
        // Let's select all the text
        Robot r = null;
        try {
            r = new Robot();
        } catch (AWTException awtex) {
            awtex.printStackTrace();
        }
        r.keyPress(KeyEvent.VK_CONTROL);
        r.keyPress(KeyEvent.VK_A);
        r.keyRelease(KeyEvent.VK_A);
        r.keyRelease(KeyEvent.VK_CONTROL);
    }


    /**
     * 
     * @param e
     */
    void jMenuItem14_actionPerformed(ActionEvent e) {
        // File - Update Manager
        // First of all, let's save the workspace
        jMenuItem5_actionPerformed(e);
        new UpdateManager();
    }

    
    /**
     * 
     * @param e
     */
    void jMenuItem15_actionPerformed(ActionEvent e) {
        SearchPathSelection.showPathSelectionDialog(this);
    }
    
    
    /**
     * 
     * @param e
     */
    void jMenuItem16_actionPerformed(ActionEvent e) {
        ApplicationConfiguration.getInstance().showConfigurationDialog(this);
    }

    
    /**
     * 
     */
    static void loadProperties() {
        try {
            InputStream s = SwingGUI.class.getClassLoader().getResourceAsStream(DEAFULT_PROPERTIES);
            System.getProperties().load(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * Load the specified workspace file.
     *
     * All the main window text and the command history is overwritten.
     * See release notes - General notes - GN0009
     * @param f File to load
     */
    void loadWorkspace(File f) {
        try {
            FileReader fr = new FileReader(f);
            this.setTitle(appTitle + " - " + f.getAbsolutePath());
            String s = this.statusBar.getText();
            this.statusBar.setText("Reading file...");
            this.answer.setText("");

            // Command History Vector
            char c = (char) fr.read();
            while (fr.ready()) {
                String line = "";
                // Read a line
                while (c != '\r' && c != '\n' && fr.ready()) {
                    line += c;
                    c = (char) fr.read();
                }
                // Skip new-lines (MAC, DOS or UNIX styles supported)
                char c2 = 0;
                while (c != c2 && fr.ready() && (c == '\n' || c == '\r')) {
                    c2 = c;
                    c = (char) fr.read();
                }
                // Test if it's a command
                if (line.startsWith("> ") && line.length() > 2) {
                    // Yes, it's a command
                    CommandHistoryManager.getDefaultInstance().addCommand(line.substring(2));
                }
                // Append the line to the main window
                if (fr.ready()) {
                    line += '\n';
                } else {
                    line += c;
                }
                this.answer.append(line);
            }

            // It's safer to uncomment the next line only when saving files
            // with unfinished operations (no prompt is shown)
            //// answer.append('\n' + "> ");
            answer.setCaretPosition(answer.getText().length());
            this.statusBar.setText(s);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }


    /**
     * 
     * @param args
     */
    public static void main(String[] args) {
        if (getJavaRuntimeVersion().compareTo("1.4") < 0) {
            System.err.println("WARNING: Required java runtime " + "version 1.4.0-b92 or later. " + "System reported: " + System.getProperty("java.runtime.version"));
        }
        // See GN0013.
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        new SwingGUI(args);
    }


    /**
     * 
     * @param f
     */
    void saveWorkspace(File f) {
        try {
            FileWriter fw = new FileWriter(f);
            this.setTitle(appTitle + " - " + f.getAbsolutePath());
            String s = this.statusBar.getText();
            this.statusBar.setText("Writing file...");
            this.answer.write(fw);
            this.statusBar.setText(s);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }


    /**
     * 
     * @param e
     */
    void this_windowClosing(WindowEvent e) {
        this.close();
    }
}

⌨️ 快捷键说明

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