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

📄 exactwizard.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                button.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
                tb.add(button);
                help.addHelp(button, htext[j]);
            }
        }
        return tb;
    }


    //BEGIN Federico Dall'Orso 8/3/2005
    //NEW
    private JMenuBar makeMenubar(){

        JMenuBar jmb = new JMenuBar();

        //OLD
        /*
        JMenuItem[][] menuItems = {{new JMenuItem(FILE_NEW), new JMenuItem(FILE_OPEN), new JMenuItem(FILE_SAVE),null, new JMenuItem(FILE_EXIT)},
                                   {new JMenuItem(ACTION_FINISH), null, new JMenuItem(SWITCH_TO_SIMULATOR)} };
        String[] menuTitles = {"File", "Action"};
        */
        //NEW
        //@author Stefano Omini
        //added solve, help, about
        JMenuItem[][] menuItems = {{new JMenuItem(FILE_NEW), new JMenuItem(FILE_OPEN), new JMenuItem(FILE_SAVE),null, new JMenuItem(FILE_EXIT)},
                                   {new JMenuItem(ACTION_SOLVE),new JMenuItem(ACTION_RANDOMIZE_MODEL), null, new JMenuItem(SWITCH_TO_SIMULATOR),
                                    null, new JMenuItem(ACTION_NEXT), new JMenuItem(ACTION_PREV)},
                                   {new JMenuItem(HELP), null, new JMenuItem(ABOUT)} };
        String[] menuTitles = {"File", "Action", "Help"};
        char[] chars = {'F','A','e'};
        //end NEW

        for(int i=0; i<menuItems.length; i++){
            JMenu menu = new JMenu(menuTitles[i]);
            menu.setMnemonic(chars[i]);
            for(int j=0; j<menuItems[i].length; j++){
                if(menuItems[i][j]==null)menu.addSeparator();
                else menu.add(menuItems[i][j]);
            }
            jmb.add(menu);
        }
        return jmb;

    }
    //END Federico Dall'Orso 8/3/2005


    /**
     * @return the button panel
     */
    protected JComponent makeButtons() {
        help = new HoverHelp();
        helpLabel = help.getHelpLabel();

        helpLabel.setBorder(BorderFactory.createEtchedBorder());
        //helpLabel.setHorizontalAlignment(SwingConstants.CENTER);

        ACTION_FINISH.putValue(Action.NAME, "Solve");
        ACTION_CANCEL.putValue(Action.NAME, "Exit");

        JPanel buttons = new JPanel();

        JButton button_finish = new JButton(ACTION_FINISH);
        help.addHelp(button_finish, "Validates the system and starts the solver");
        JButton button_cancel = new JButton(ACTION_CANCEL);
        help.addHelp(button_cancel, "Exits the wizard discarding all changes");
        JButton button_next = new JButton(ACTION_NEXT);
        help.addHelp(button_next, "Moves on to the next step");
        JButton button_previous = new JButton(ACTION_PREV);
        help.addHelp(button_previous, "Goes back to the previous step");
        JButton button_help = new JButton(ACTION_HELP);
        help.addHelp(button_help, "Displays help for the current panel");
        buttons.add(button_previous);
        buttons.add(button_next);
        buttons.add(button_finish);
        buttons.add(button_cancel);
        buttons.add(button_help);


        JPanel labelbox = new JPanel();
        labelbox.setLayout(new BorderLayout());
        labelbox.add(Box.createVerticalStrut(20), BorderLayout.WEST);
        labelbox.add(helpLabel, BorderLayout.CENTER);

        Box buttonBox = Box.createVerticalBox();
        buttonBox.add(buttons);
        buttonBox.add(labelbox);
        return buttonBox;
    }

    //BEGIN Federico Dall'Orso 8/3/2005
    //NEW
    private void newModel(){
        currentPanel.lostFocus();
        if (checkForSave("<html>Save changes before creating a new model?</html>")) return;
        Rectangle bounds = this.getBounds();
        ExactWizard ew = new ExactWizard();
        ew.setBounds(bounds);
        ew.show();
        Manager.addJMTWindow(ew);
        this.hide();
        this.dispose();
        Manager.exit(this);
    }
    //END Federico Dall'Orso 8/3/2005

    /**
     * Shows a confirmation dialog to save before new model or exit operations
     * @param msg The message to display.
     * @return <code>true</code> - if the user select cancel button.
     */
    public boolean checkForSave(String msg) {
        // Checks if there's an old graph to save
        if (data != null && data.isChanged()) {
            int resultValue = JOptionPane.showConfirmDialog(this,
                    msg,
                    "JMVA - Warning",
                    JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE);
            if (resultValue == JOptionPane.YES_OPTION) {
                save();
                return false;
            }
            if (resultValue == JOptionPane.CANCEL_OPTION) {
                return true;
            }
        }
        return false;
    }
    /**
     * Saves current model
     * <br>Author: Bertoli Marco
     */
    private void save() {
        currentPanel.lostFocus();
        if (!checkFinish()) return; // panels with problems are expected to notify the user by themselves
        int retval = modelLoader.saveModel(data, this, null);
        switch (retval) {
            case ModelLoader.SUCCESS:
                data.resetChanged();
                break;
            case ModelLoader.FAILURE:
                JOptionPane.showMessageDialog(this, modelLoader.getFailureMotivation(), "Error", JOptionPane.ERROR_MESSAGE);
                break;
        }
    }

    /**
     * Opens a new model
     * <br>Author: Bertoli Marco
     */
    private void open() {
        currentPanel.lostFocus();
        if (checkForSave("<html>Save changes before opening a saved model?</html>")) return;
        ExactModel newdata = new ExactModel();
        int retval = modelLoader.loadModel(newdata, this);
        switch (retval) {
            case ModelLoader.SUCCESS:
            case ModelLoader.WARNING:
                data = newdata;
                currentPanel.gotFocus();
                // Shows right panels
                if (data.areVisitsSet()) {
                    removePanel(serviceDemandsPanel);
                    ((ForceUpdatablePanel)serviceTimesPanel).retrieveData();
                    ((ForceUpdatablePanel)visitsPanel).retrieveData();
                    addPanel(visitsPanel,2);
                    addPanel(serviceTimesPanel,2);
                }
                else {
                    removePanel(visitsPanel);
                    removePanel(serviceTimesPanel);
                    ((ForceUpdatablePanel)serviceDemandsPanel).retrieveData();
                    addPanel(serviceDemandsPanel,2);
                }
                tabbedPane.setSelectedIndex(0);
                break;
            case ModelLoader.FAILURE:
                JOptionPane.showMessageDialog(this, modelLoader.getFailureMotivation(), "Error", JOptionPane.ERROR_MESSAGE);
                break;

        }
        tempFile = modelLoader.getSelectedFile();
        if(data.hasResults()) this.createSolutionWindow();
        updatePanels();

        // Shows warnings if any
        if (retval == ModelLoader.WARNING) {
            new WarningWindow(modelLoader.getLastWarnings(), this).show();
        }
    }

    public ExactModel getData() {
        return data;
    }

    protected void finish() {
        //OLD
        //do not call this method!!! It's already called inside checkFinish() method.
        //currentPanel.lostFocus();

        solve();
    }

    protected void cancel() {
        if (currentPanel != null) currentPanel.lostFocus();
        if (checkForSave("<html>Save changes before closing?</html>")) return;
        super.cancel();
    }

    protected void switchToSimulator() {
        JSIMModel output = new JSIMModel();
        // New Converter by Bertoli Marco
        Vector res = ModelConverter.convertJMVAtoJSIM(data, output);
        JSIMMain jsim = new JSIMMain(output);
        jsim.show();
        // If problems are found, shows warnings
        if (res.size() > 0)
            new WarningWindow(res, jsim).show();

    }

    public HoverHelp getHelp() {
        return help;
    }

    /**switches service times and visits panels to service demands panel in order to change
     * data representation.*/
    public void switchFromSTVtoSD(){
        ((ForceUpdatablePanel)serviceTimesPanel).commitData();
        ((ForceUpdatablePanel)visitsPanel).retrieveData();
        ((ForceUpdatablePanel)visitsPanel).commitData();
        removePanel(serviceTimesPanel);
        removePanel(visitsPanel);
        ((ForceUpdatablePanel)serviceDemandsPanel).retrieveData();
        addPanel(serviceDemandsPanel,2);
    }

    /**switches service times and visits panels to service demands panel in order to change
     * data representation.*/
    public void switchFromSDtoSTV(){
        ((ForceUpdatablePanel)serviceDemandsPanel).commitData();
        removePanel(serviceDemandsPanel);
        ((ForceUpdatablePanel)serviceTimesPanel).retrieveData();
        ((ForceUpdatablePanel)visitsPanel).retrieveData();
        addPanel(visitsPanel,2);
        addPanel(serviceTimesPanel,2);
    }

    private void solve() {

        if (solver == null) solver = new SolverClient(this);

        ExactModel newdata = new ExactModel(data); // Yields the mean performance indices

        // Checks saturation
        int state = data.checkSaturation();
        switch (state) {
            case ExactModel.SATURATION:
                JOptionPane.showMessageDialog(this, "Error: input data will cause model saturation. Please adjust arrival rates or service demands.", "Input data error", JOptionPane.ERROR_MESSAGE);
                return;
            case ExactModel.SATURATION_WHATIF:
                JOptionPane.showMessageDialog(this, "Error: input data will cause model saturation during what-if analysis. Please adjust what-if analysis parameters.", "Input data error", JOptionPane.ERROR_MESSAGE);
                return;
        }

        try {
            //OLD
            /*
			solver.solve(newdata);
            */
            //NEW Dall'Orso
            tempFile = solver.solve(newdata);
            //OLD
        //NEW
        //@author Stefano Omini
        } catch (InputDataException rse) {
            JOptionPane.showMessageDialog(this, rse.getMessage(), "Input data error", JOptionPane.ERROR_MESSAGE);
            return;
        //end NEW
        } catch (SolverException e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Solver error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        this.data = newdata;
        if (data.hasResults())
            createSolutionWindow();
        updatePanels();
        currentPanel.gotFocus();
    }




    //NEW
    //@author Stefano Omini
    private void showHelp(ActionEvent event){
        /*
        try {
            ClassLoader cl = this.getClass().getClassLoader();

            //TODO: cerca nella cartella class... 

⌨️ 快捷键说明

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