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

📄 mainwindow.java

📁 UML设计测试工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    private ActionHelpAbout fActionHelpAbout =         new ActionHelpAbout();        /**     * Opens and compiles a specification file.     */    private class ActionFileOpenSpec extends AbstractAction {        private JFileChooser fChooser;        ActionFileOpenSpec() {            super("Open specification...", new ImageIcon(Options.iconDir + "Open.gif"));        }        public void actionPerformed(ActionEvent e) {            String path;            // reuse chooser if possible            if (fChooser == null ) {                path = System.getProperty("user.dir");                fChooser = new JFileChooser(path);                ExtFileFilter filter = new ExtFileFilter("use", "USE specifications");                fChooser.addChoosableFileFilter(filter);                fChooser.setDialogTitle("Open specification");            }            int returnVal = fChooser.showOpenDialog(MainWindow.this);             if (returnVal != JFileChooser.APPROVE_OPTION )                return;            path = fChooser.getCurrentDirectory().toString();            File f = new File(path, fChooser.getSelectedFile().getName());             Log.verbose("File " + f);            fLogPanel.clear();            showLogPanel();            compile(f);        }        private void compile(final File f) {            fLogWriter.println("compiling specification " + f.getName() + "...");            MModel model = null;            MSystem system = null;            Reader r = null;            try {                r = new BufferedReader(new FileReader(f));                model = USECompiler.compileSpecification(                                                         r, f.getName(),                                                         fLogWriter,                                                         new ModelFactory());                fLogWriter.println("done.");                if (model != null ) {                    fLogWriter.println(model.getStats());                    // create system                    system = new MSystem(model);                }            } catch (FileNotFoundException ex) {                Log.error("File `" + f.getName() + "' not found.");            } finally {                if (r != null )                    try { r.close(); } catch (IOException ex) {                        // ignored                    }            }             // set new system (may be null if compilation failed)            final MSystem system2 = system; // need final variable for Runnable            SwingUtilities.invokeLater(new Runnable() {                    public void run() {                        fSession.setSystem(system2);                    }});        }    }    /**     * Saves commands executed so far to a script file.     */    private class ActionFileSaveScript extends AbstractAction {        private JFileChooser fChooser;        ActionFileSaveScript() {            super("Save script...", new ImageIcon(Options.iconDir + "Save.gif"));        }        public void actionPerformed(ActionEvent e) {            String path;            // reuse chooser if possible            if (fChooser == null ) {                path = System.getProperty("user.dir");                fChooser = new JFileChooser(path);                ExtFileFilter filter = new ExtFileFilter("cmd", "USE scripts");                fChooser.addChoosableFileFilter(filter);                fChooser.setDialogTitle("Save script");            }            int returnVal = fChooser.showSaveDialog(MainWindow.this);             if (returnVal != JFileChooser.APPROVE_OPTION )                return;            path = fChooser.getCurrentDirectory().toString();            File f = new File(path, fChooser.getSelectedFile().getName());             Log.verbose("File " + f);            if (f.exists() ) {                int n = JOptionPane.showConfirmDialog(MainWindow.this,                                                      "Overwrite existing file " + f + "?",                                                      "Please confirm",                                                      JOptionPane.YES_NO_CANCEL_OPTION);                if (n != JOptionPane.YES_OPTION )                    return;            }            // write script file            PrintWriter out = null;            try {                out = new PrintWriter(new BufferedWriter(new FileWriter(f)));                out.println("-- Script generated by USE " +                            Options.RELEASE_VERSION);                out.println();                fSession.system().writeUSEcmds(out);                fLogWriter.println("Wrote script " + f);            } catch (IOException ex) {                JOptionPane.showMessageDialog(MainWindow.this,                                               ex.getMessage(), "Error",                                              JOptionPane.ERROR_MESSAGE);            } finally {                if (out != null )                    out.close();            }        }    }    private class ActionFileSaveProtocol extends AbstractAction {        private JFileChooser fChooser;                ActionFileSaveProtocol() {            super("Save Protocol...", new ImageIcon(Options.iconDir + "Save.gif"));        }                public void actionPerformed(ActionEvent e) {            String path;            // reuse chooser if possible            if (fChooser == null ) {                path = System.getProperty("user.dir");                fChooser = new JFileChooser(path);                ExtFileFilter filter = new ExtFileFilter("protocol", "USE protocols");                fChooser.addChoosableFileFilter(filter);                fChooser.setDialogTitle("Save protocol");            }            int returnVal = fChooser.showSaveDialog(MainWindow.this);             if (returnVal != JFileChooser.APPROVE_OPTION )                return;            path = fChooser.getCurrentDirectory().toString();            File f = new File(path, fChooser.getSelectedFile().getName());             Log.verbose("File " + f);            if (f.exists() ) {                int n = JOptionPane.showConfirmDialog(MainWindow.this,                                                      "Overwrite existing file " + f + "?",                                                      "Please confirm",                                                      JOptionPane.YES_NO_CANCEL_OPTION);                if (n != JOptionPane.YES_OPTION )                    return;            }                        try {                //OldUSEWriter.getInstance().writeProtocolFile( f );                FileWriter fw = new FileWriter(f);                USEWriter.getInstance().writeProtocolFile(fw);                fw.flush();            } catch (IOException e1) {                // TODO Auto-generated catch block                e1.printStackTrace();            }        }            }        /**     * Setup printer.     */    private class ActionFilePrinterSetup extends AbstractAction {        ActionFilePrinterSetup() {            super("Printer Setup...");        }        public void actionPerformed(ActionEvent e) {            PrinterJob job = PrinterJob.getPrinterJob();            // initialize page format if necessary            pageFormat();            // show dialog            fPageFormat = job.pageDialog(fPageFormat);        }    }    /**     * Print view.     */    private class ActionFilePrint extends AbstractAction {        ActionFilePrint() {            super("Print diagram...",                   new ImageIcon(Options.iconDir + "Print.gif"));            this.setEnabled(false);        }        public void actionPerformed(ActionEvent e) {            ViewFrame vf = null;            // jdk1.3: vf = (ViewFrame) fDesk.getSelectedFrame();            JInternalFrame[] frames = fDesk.getAllFrames();            for (int i = 0; i < frames.length; i++)                if (frames[i].isSelected() )                    vf = (ViewFrame) frames[i];            if (vf != null && vf.isPrintable() )                vf.print(pageFormat());        }    }    /**     * Exit application.     */    private class ActionFileExit extends AbstractAction {        ActionFileExit() {            super("Exit");        }        public void actionPerformed(ActionEvent e) {            close();        }    }    /**     * Undoes the last state manipulation command.     */    class ActionEditUndo extends AbstractAction {        ActionEditUndo() {            super("Undo", new ImageIcon(Options.iconDir + "Undo.gif"));            this.setEnabled(false);        }        public void actionPerformed(ActionEvent e) {            try {                fSession.system().undoCmd();                String name = fSession.system().nextUndoableCmdName();                if (name != null )                    enableUndo(name);                else                     disableUndo();            } catch (MSystemException ex) {                JOptionPane.showMessageDialog(MainWindow.this,                                               ex.getMessage(), "Error",                                              JOptionPane.ERROR_MESSAGE);            }        }    }    /**     * Opens a dialog for creating objects.     */    private class ActionStateCreateObject extends AbstractAction {        ActionStateCreateObject() {            super("Create object...");        }        public void actionPerformed(ActionEvent e) {            CreateObjectDialog dlg =                 new CreateObjectDialog(fSession.system(), MainWindow.this);            dlg.setVisible(true);        }    }    /**     * Opens a dialog for evaluating OCL expressions.     */    private class ActionStateEvalOCL extends AbstractAction {        ActionStateEvalOCL() {            super("Evaluate OCL expression...",                   new ImageIcon(Options.iconDir + "OCL.gif"));        }        public void actionPerformed(ActionEvent e) {            EvalOCLDialog dlg = new EvalOCLDialog(fSession.system(),MainWindow.this);            dlg.setVisible(true);        }    }    /**     * Checks structure of system state.     */    private class ActionStateCheckStructure extends AbstractAction {        ActionStateCheckStructure() {            super("Check structure now");        }        public void actionPerformed(ActionEvent e) {            checkStructure();        }    }    /**     * Resets the system to its initial empty state.     */    private class ActionStateReset extends AbstractAction {        ActionStateReset() {            super("Reset");        }        public void actionPerformed(ActionEvent e) {            int n = JOptionPane.showConfirmDialog(MainWindow.this,                                                  "Reset system to its initial state and delete all objects and links?",                                                  "Please confirm",                                                  JOptionPane.YES_NO_CANCEL_OPTION);            if (n == JOptionPane.YES_OPTION )                fSession.reset();        }    }    /**     * Creates a new object count view.     */    private class ActionViewCreateObjectCount extends AbstractAction {        ActionViewCreateObjectCount() {            super("Object count",                  new ImageIcon(Options.iconDir + "ObjectCountView.gif"));        }        public void actionPerformed(ActionEvent e) {            ObjectCountView ov = new ObjectCountView(fSession.system());            ViewFrame f = new ViewFrame("Object count", ov, "ObjectCountView.gif");            JComponent c = (JComponent) f.getContentPane();            c.setLayout(new BorderLayout());            c.add(new JScrollPane(ov), BorderLayout.CENTER);            addNewViewFrame(f);        }    }    /**     * Creates a new link count view.     */    private class ActionViewCreateLinkCount extends AbstractAction {        ActionViewCreateLinkCount() {            super("Link count",                  new ImageIcon(Options.iconDir + "LinkCountView.gif"));        }        public void actionPerformed(ActionEvent e) {            LinkCountView lv = new LinkCountView(fSession.system());            ViewFrame f = new ViewFrame("Link count", lv, "LinkCountView.gif");            JComponent c = (JComponent) f.getContentPane();            c.setLayout(new BorderLayout());            c.add(new JScrollPane(lv), BorderLayout.CENTER);            addNewViewFrame(f);        }    }

⌨️ 快捷键说明

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