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

📄 jmacroeditor.java

📁 拥有图形界面的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * JMacroEditor.java * * Created on 20 agosto 2002, 12.37 */package org.joone.edit;import org.joone.net.*;import org.joone.util.*;import org.joone.log.*;import org.joone.edit.jedit.*;import org.joone.edit.jedit.tokenmarker.*;import org.joone.script.*;import java.io.*;import java.util.*;import java.awt.*;import javax.swing.*;import javax.swing.filechooser.FileFilter;import CH.ifa.draw.util.*;import CH.ifa.draw.framework.*;/** * A text editor to edit and run BeanShell/ Groovy scripts * @author  PMLMAPA * @author  yccheok */public class JMacroEditor extends javax.swing.JFrame {    /**     * Logger     * */    private static final ILogger log = LoggerFactory.getLogger(JMacroEditor.class);        private JEditTextArea ta;    private NeuralNet neuralNet;    private char[] m_buf;    private String m_dir;    private String[] FileExtension = { "bsh", "groovy" };    private String FileDescription = "BeanShell scripts (.bsh) | Groovy scripts (.groovy)";    private String fileName = null;    private String actualMacro = null;    private javax.swing.DefaultListModel list;    /** Creates new form TestJEdit */    public JMacroEditor(NeuralNet nnet) {        initComponents();        setNeuralNet(nnet);        ta = new JEditTextArea();        ta.addFocusListener(new java.awt.event.FocusAdapter() {            public void focusLost(java.awt.event.FocusEvent evt) {                taFocusLost(evt);            }        });                ta.setTokenMarker(new JavaTokenMarker());        jSplitPane1.setRightComponent(ta);        Iconkit kit = Iconkit.instance();        if (kit == null)            throw new HJDError("Iconkit instance isn't set");        final Image img = kit.loadImageResource(JoonEdit.DIAGRAM_IMAGES + "JooneIcon.gif");        this.setIconImage(img);        fillList();        enableMacroMenuItem.setSelected(getNeuralNet().isScriptingEnabled());        if (getNeuralNet().getMacroPlugin() instanceof MacroPlugin)            beanShellMenuItem.setSelected(true);        else            groovyMenuItem.setSelected(true);        pack();    }        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    private void initComponents() {//GEN-BEGIN:initComponents        buttonGroup1 = new javax.swing.ButtonGroup();        jSplitPane1 = new javax.swing.JSplitPane();        jList1 = new javax.swing.JList();        menuBar = new javax.swing.JMenuBar();        fileMenu = new javax.swing.JMenu();        importMenuItem = new javax.swing.JMenuItem();        saveAsMenuItem = new javax.swing.JMenuItem();        jSeparator1 = new javax.swing.JSeparator();        exitMenuItem = new javax.swing.JMenuItem();        editMenu = new javax.swing.JMenu();        cutMenuItem = new javax.swing.JMenuItem();        copyMenuItem = new javax.swing.JMenuItem();        pasteMenuItem = new javax.swing.JMenuItem();        jSeparator4 = new javax.swing.JSeparator();        selectAllMenuItem = new javax.swing.JMenuItem();        macroMenu = new javax.swing.JMenu();        enableMacroMenuItem = new javax.swing.JCheckBoxMenuItem();        jSeparator3 = new javax.swing.JSeparator();        addMenuItem = new javax.swing.JMenuItem();        removeMenuItem = new javax.swing.JMenuItem();        renameMenuItem = new javax.swing.JMenuItem();        jSeparator2 = new javax.swing.JSeparator();        runMenuItem = new javax.swing.JMenuItem();        setRateMenuItem = new javax.swing.JMenuItem();        jSeparator5 = new javax.swing.JSeparator();        jMenuLanguage = new javax.swing.JMenu();        beanShellMenuItem = new javax.swing.JRadioButtonMenuItem();        groovyMenuItem = new javax.swing.JRadioButtonMenuItem();        setTitle("JavaScript Macro Editor");        addWindowListener(new java.awt.event.WindowAdapter() {            public void windowClosing(java.awt.event.WindowEvent evt) {                exitForm(evt);            }        });        jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {                jList1ValueChanged(evt);            }        });        jSplitPane1.setLeftComponent(jList1);        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);        fileMenu.setText("File");        importMenuItem.setText("Import Macro...");        importMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                importMenuItemActionPerformed(evt);            }        });        fileMenu.add(importMenuItem);        saveAsMenuItem.setText("Save Macro As ...");        saveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                saveAsMenuItemActionPerformed(evt);            }        });        fileMenu.add(saveAsMenuItem);        fileMenu.add(jSeparator1);        exitMenuItem.setMnemonic('x');        exitMenuItem.setText("Close");        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                exitMenuItemActionPerformed(evt);            }        });        fileMenu.add(exitMenuItem);        menuBar.add(fileMenu);        editMenu.setText("Edit");        cutMenuItem.setText("Cut");        cutMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                cutMenuItemActionPerformed(evt);            }        });        editMenu.add(cutMenuItem);        copyMenuItem.setText("Copy");        copyMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                copyMenuItemActionPerformed(evt);            }        });        editMenu.add(copyMenuItem);        pasteMenuItem.setText("Paste");        pasteMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                pasteMenuItemActionPerformed(evt);            }        });        editMenu.add(pasteMenuItem);        editMenu.add(jSeparator4);        selectAllMenuItem.setText("Select All");        selectAllMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                selectAllMenuItemActionPerformed(evt);            }        });        editMenu.add(selectAllMenuItem);        menuBar.add(editMenu);        macroMenu.setText("Macro");        macroMenu.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                macroMenuActionPerformed(evt);            }        });        enableMacroMenuItem.setText("Enable Scripting");        enableMacroMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                enableMacroMenuItemActionPerformed(evt);            }        });        macroMenu.add(enableMacroMenuItem);        macroMenu.add(jSeparator3);        addMenuItem.setText("Add...");        addMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                addMenuItemActionPerformed(evt);            }        });        macroMenu.add(addMenuItem);        removeMenuItem.setText("Remove");        removeMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                removeMenuItemActionPerformed(evt);            }        });        macroMenu.add(removeMenuItem);        renameMenuItem.setText("Rename");        renameMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                renameMenuItemActionPerformed(evt);            }        });        macroMenu.add(renameMenuItem);        macroMenu.add(jSeparator2);        runMenuItem.setText("Run");        runMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                runMenuItemActionPerformed(evt);            }        });        macroMenu.add(runMenuItem);        setRateMenuItem.setText("set Rate...");        setRateMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                setRateMenuItemActionPerformed(evt);            }        });        macroMenu.add(setRateMenuItem);        macroMenu.add(jSeparator5);        jMenuLanguage.setText("Language");        buttonGroup1.add(beanShellMenuItem);        beanShellMenuItem.setSelected(true);        beanShellMenuItem.setText("BeanShell");        beanShellMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                beanShellMenuItemActionPerformed(evt);            }        });        jMenuLanguage.add(beanShellMenuItem);        buttonGroup1.add(groovyMenuItem);        groovyMenuItem.setText("Groovy");        groovyMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                groovyMenuItemActionPerformed(evt);            }        });        jMenuLanguage.add(groovyMenuItem);        macroMenu.add(jMenuLanguage);        menuBar.add(macroMenu);        setJMenuBar(menuBar);        pack();    }//GEN-END:initComponents        private void groovyMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groovyMenuItemActionPerformed        GroovyMacroPlugin newMacroPlugin = new GroovyMacroPlugin();        setNewMacroPlugin(newMacroPlugin);    }//GEN-LAST:event_groovyMenuItemActionPerformed        private void beanShellMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_beanShellMenuItemActionPerformed        MacroPlugin newMacroPlugin = new MacroPlugin();        setNewMacroPlugin(newMacroPlugin);    }//GEN-LAST:event_beanShellMenuItemActionPerformed        private void setNewMacroPlugin(MacroInterface newMacroPlugin) {        MacroInterface oldMacroPlugin = getNeuralNet().getMacroPlugin();        newMacroPlugin.setMacroManager(oldMacroPlugin.getMacroManager());        getNeuralNet().setMacroPlugin(newMacroPlugin);    }        private void taFocusLost(java.awt.event.FocusEvent evt) {        // Ensure the latest edited macro take effect immediately        // just after the user changes focus from text editing field        // to other components.        saveMacro();    }        private void setRateMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setRateMenuItemActionPerformed        // Add your handling code here:        int newRate;        int oldRate = ((MonitorPlugin)getNeuralNet().getMacroPlugin()).getRate();        String s_newRate = this.showInputDialog("Set Rate", "Insert the new rate's value:", Integer.toString(oldRate));        if (s_newRate != null) {            try {                newRate = Integer.parseInt(s_newRate);            } catch (NumberFormatException nfe) {                // If the input value is invalid (not numeric) the rate is unchanged                newRate = oldRate;            }            // The rate can't be negative            if (newRate < 0)                newRate = newRate * -1;            ((MonitorPlugin)getNeuralNet().getMacroPlugin()).setRate(newRate);        }            }//GEN-LAST:event_setRateMenuItemActionPerformed        private void renameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_renameMenuItemActionPerformed        // Add your handling code here:        String newName = getNewName("Rename a macro", "Insert the new name of the Macro:", actualMacro);        if (newName != null) {            getNeuralNet().getMacroPlugin().getMacroManager().renameMacro(actualMacro, newName);            actualMacro = newName;            list.setElementAt(newName, jList1.getSelectedIndex());        }    }//GEN-LAST:event_renameMenuItemActionPerformed        private void beanShellRadioButtonMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_beanShellRadioButtonMenuItemActionPerformed        // TODO: remove this method    }//GEN-LAST:event_beanShellRadioButtonMenuItemActionPerformed        private void groovyRadioButtonMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groovyRadioButtonMenuItemActionPerformed        // TODO: remove this method    }//GEN-LAST:event_groovyRadioButtonMenuItemActionPerformed        private void removeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeMenuItemActionPerformed        // Add your handling code here:        int n = JOptionPane.showConfirmDialog(this,                "OK to remove '" + actualMacro +"' ?",                "Macro Editor",                JOptionPane.YES_NO_OPTION);

⌨️ 快捷键说明

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