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

📄 mainwindow.java

📁 UML设计测试工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            });        setBounds(10,20, 900, 700);        // initialize application state to current system        sessionChanged();    }    /**     * Returns the selected view of all internal views. If none is     * selected null is returned.     */    public View getSelectedView() {        if ( fDesk.getSelectedFrame() != null ) {            return ((ViewFrame) fDesk.getSelectedFrame()).getView();            }        return null;    }        /**     * Returns the model browser instance.     */    public ModelBrowser getModelBrowser() {        return fModelBrowser;    }        private void close() {        setVisible(false);        dispose();        Shell.getInstance( fSession ).exit();    }    /**     * Returns the instance of MainWindow.     */    public static MainWindow instance() {        return fInstance;    }    /**     * Returns the page format for printing.     */    public PageFormat pageFormat() {        if (fPageFormat == null ) {            // initialize with defaults            PrinterJob job = PrinterJob.getPrinterJob();            fPageFormat = job.defaultPage();            Paper p = fPageFormat.getPaper();            p.setSize(Options.PRINT_PAGEFORMAT_WIDTH,                       Options.PRINT_PAGEFORMAT_HEIGHT);            fPageFormat.setPaper(p);            if (Options.PRINT_PAGEFORMAT_ORIENTATION.equals("portrait") )                fPageFormat.setOrientation(PageFormat.PORTRAIT);            else if (Options.PRINT_PAGEFORMAT_ORIENTATION.equals("landscape") )                fPageFormat.setOrientation(PageFormat.LANDSCAPE);            else if (Options.PRINT_PAGEFORMAT_ORIENTATION.equals("seascape") )                fPageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);        }        return fPageFormat;    }    public StatusBar statusBar() {        return fStatusBar;    }    LogPanel logPanel() {        return fLogPanel;    }    public PrintWriter logWriter() {        return fLogWriter;    }    private void checkStructure() {        //fLogWriter.println("Checking structure...");        boolean ok = fSession.system().state().checkStructure(fLogWriter);        fLogWriter.println("checking structure, " +                           (( ok ) ? "ok." : "found errors."));        fLogWriter.flush();    }    public void stateChanged(StateChangeEvent e) {        if (e.structureHasChanged() && fCbMenuItemCheckStructure.isSelected() )            checkStructure();        fActionFileSaveScript.setEnabled(fSession.system().numExecutedCmds() > 0);    }    private int fViewFrameX = 0;    private int fViewFrameY = 0;    /**     * Adds a new view (internal frame) to the desktop.     */    private void addNewViewFrame(ViewFrame f) {        f.setBounds(fViewFrameX, fViewFrameY, 300, 200);        fDesk.add(f, JDesktopPane.DEFAULT_LAYER);        fDesk.moveToFront(f);        // position for next frame         if (fViewFrameX < 200 ) {            fViewFrameX += 20;            fViewFrameY += 20;        } else {            fViewFrameX = 0;            fViewFrameY = 0;        }        // enable print button when a printable view is activated        final boolean isPrintable = f.isPrintable();        f.addInternalFrameListener(new InternalFrameAdapter() {                public void internalFrameActivated(InternalFrameEvent ev) {                    // jdk1.3: JInternalFrame jif = ev.getInternalFrame();                    JInternalFrame jif = (JInternalFrame) ev.getSource();                    fActionFilePrint.setEnabled(isPrintable);                }                public void internalFrameDeactivated(InternalFrameEvent ev) {                    fActionFilePrint.setEnabled(false);                }            });        f.setVisible(true);    }        /**      * Set application state for new system. The system parameter may     * be null.     */    void sessionChanged() {        boolean on = fSession.hasSystem();        fActionStateCreateObject.setEnabled(on);        fActionStateEvalOCL.setEnabled(on);        fActionStateCheckStructure.setEnabled(on);        fActionViewCreateObjectCount.setEnabled(on);        fActionViewCreateObjectCount.setEnabled(on);        fActionViewCreateLinkCount.setEnabled(on);        fActionViewCreateClassDiagram.setEnabled(on);        fActionViewCreateObjectDiagram.setEnabled(on);        fActionViewCreateClassInvariant.setEnabled(on);        fActionViewCreateStateEvolution.setEnabled(on);        fActionViewCreateObjectProperties.setEnabled(on);        fActionViewCreateClassExtent.setEnabled(on);        fActionViewCreateSequenceDiagram.setEnabled(on);        fActionViewCreateCallStack.setEnabled(on);        fActionViewCreateCommandList.setEnabled(on);        fActionViewClassDiagram.setEnabled(on);        disableUndo();        closeAllViews();        if (on ) {            MSystem system = fSession.system();            fModelBrowser.setModel(system.model());            system.addChangeListener(this);            setTitle("USE: " + system.model().filename());        } else {            fModelBrowser.setModel(null);            //fSession.system().removeChangeListener(this);            fActionFileSaveScript.setEnabled(false);            setTitle("USE");        }    }    /**     * Closes all views.     */    void closeAllViews() {        // How many frames do we have?        JInternalFrame[] allframes = fDesk.getAllFrames();        int count = allframes.length;        for (int i = 0; i < count; i++) {            ViewFrame f = (ViewFrame) allframes[i];            fDesk.getDesktopManager().closeFrame(f);        }        // reset start position for new frames        fViewFrameX = 0;        fViewFrameY = 0;    }    /**      * Enables the undo command.      */    void enableUndo(String name) {        fActionEditUndo.setEnabled(true);        // change text of menu item, leave toolbar button untouched        String s = "Undo: " + name;        //FIXME: apparently enableUndo is sometimes called before GUI setup        if (fMenuItemEditUndo != null) {            fMenuItemEditUndo.setText(s);        }        if (fBtnEditUndo != null) {            fBtnEditUndo.setToolTipText(s);        }    }    /**      * Disables the undo command.      */    void disableUndo() {        fActionEditUndo.setEnabled(false);        // change text of menu item, leave toolbar button untouched        fMenuItemEditUndo.setText("Undo");        fBtnEditUndo.setToolTipText(DEFAULT_UNDO_TEXT);    }    /**      * Shows the log panel.     */    void showLogPanel() {        double loc = fTopSplitPane.getDividerLocation();        // if divider is at bottom move it to top so that the log is visible        if (loc / (fTopSplitPane.getHeight() - fTopSplitPane.getDividerSize()) > 0.95 )            fTopSplitPane.setDividerLocation(0.75);    }    /**     * Creates a new object. Keeps track of undo information and     * handles errors on the GUI level.     */    public void createObject(String clsName, java.util.List names) {        // System.err.println("Creating " + name + " : " + cls.name());        // setup command for object creation        MClass cls = fSession.system().model().getClass(clsName);        if (cls == null ) {            JOptionPane.showMessageDialog(this, "No class named `" + clsName +                                           "' defined in model.", "Error",                                          JOptionPane.ERROR_MESSAGE);        } else {            MSystem system = fSession.system();            MCmdCreateObjects cmd = new MCmdCreateObjects(system.state(),                                                           names,                                                           TypeFactory.mkObjectType(cls));            try {                system.executeCmd(cmd);                if (cmd.canUndo() )                     enableUndo(cmd.name());                StringBuffer msg = new StringBuffer();                for (Iterator it = names.iterator(); it.hasNext();) {                    String name = (String) it.next();                    msg.append(name);                    if (it.hasNext())                        msg.append(", ");                }                USEWriter.getInstance().protocol("[GUI] create " + msg + ":" + clsName);            } catch (MSystemException ex) {                JOptionPane.showMessageDialog(this, ex.getMessage(), "Error",                                              JOptionPane.ERROR_MESSAGE);                // Log.error(ex.getMessage());            }        }    }    /**     * Applies changes by setting new attribute values. Entries may be     * arbitrary OCL expressions.      */    public void execCmd(String line) {        Log.trace(this, "line = " + line);            // exit if no changes        if (line == null )            return;        MSystem system = fSession.system();        java.util.List cmdList =             USECompiler.compileCmdList(system.model(), system.state(),                                       new StringReader(line), "<input>",                                       fLogWriter);            // compile errors?        if (cmdList == null ) {            JOptionPane.showMessageDialog(this,                                           "One of the values you entered contains an error. " +                                          Options.LINE_SEPARATOR +                                           "See the Log for more information.", "Error",                                          JOptionPane.ERROR_MESSAGE);            return;        }        Iterator it = cmdList.iterator();        while (it.hasNext() ) {            MCmd cmd = (MCmd) it.next();            Log.trace(this, "--- Executing command: " + cmd);            try {                system.executeCmd(cmd);                USEWriter.getInstance().protocol("[GUI] " + line);                if (cmd.canUndo() )                     enableUndo(cmd.name());            } catch (MSystemException ex) {                JOptionPane.showMessageDialog(this, ex.getMessage(), "Error",                                              JOptionPane.ERROR_MESSAGE);            }        }    }    // Actions    private ActionFileOpenSpec fActionFileOpenSpec =         new ActionFileOpenSpec();    private ActionFileSaveScript fActionFileSaveScript =         new ActionFileSaveScript();    private ActionFileSaveProtocol fActionFileSaveProtocol =        new ActionFileSaveProtocol();    private ActionFilePrinterSetup fActionFilePrinterSetup =         new ActionFilePrinterSetup();    private ActionFilePrint fActionFilePrint =         new ActionFilePrint();    private ActionFileExit fActionFileExit =         new ActionFileExit();    private ActionEditUndo fActionEditUndo =         new ActionEditUndo();    private ActionStateCreateObject fActionStateCreateObject =         new ActionStateCreateObject();    private ActionStateEvalOCL fActionStateEvalOCL =         new ActionStateEvalOCL();    private ActionStateCheckStructure fActionStateCheckStructure =         new ActionStateCheckStructure();    private ActionStateReset fActionStateReset =         new ActionStateReset();    private ActionViewCreateObjectCount fActionViewCreateObjectCount =         new ActionViewCreateObjectCount();    private ActionViewCreateLinkCount fActionViewCreateLinkCount =         new ActionViewCreateLinkCount();    private ActionViewCreateClassDiagram fActionViewCreateClassDiagram =         new ActionViewCreateClassDiagram();    private ActionViewCreateObjectDiagram fActionViewCreateObjectDiagram =         new ActionViewCreateObjectDiagram();    private ActionViewCreateClassInvariant fActionViewCreateClassInvariant =         new ActionViewCreateClassInvariant();//    private ActionViewCreateStateTreeView fActionViewCreateStateTree = //        new ActionViewCreateStateTreeView();    private ActionViewCreateStateEvolution fActionViewCreateStateEvolution =         new ActionViewCreateStateEvolution();    private ActionViewCreateObjectProperties fActionViewCreateObjectProperties =         new ActionViewCreateObjectProperties();    private ActionViewCreateClassExtent fActionViewCreateClassExtent =         new ActionViewCreateClassExtent();    private ActionViewCreateSequenceDiagram fActionViewCreateSequenceDiagram =         new ActionViewCreateSequenceDiagram();    private ActionViewCreateCallStack fActionViewCreateCallStack =         new ActionViewCreateCallStack();    private ActionViewCreateCommandList fActionViewCreateCommandList =         new ActionViewCreateCommandList();    private ActionViewClassDiagram fActionViewClassDiagram =         new ActionViewClassDiagram();    private ActionViewTile fActionViewTile =         new ActionViewTile();    private ActionViewCloseAll fActionViewCloseAll =         new ActionViewCloseAll();

⌨️ 快捷键说明

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