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

📄 jsimmain.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            //ActionMenu
            {ACTION_NEXT, ACTION_PREV, null,
             ACTION_SWITCH_JMVA},
            //Simulation Menu
            {SIM_START, SIM_PAUSE, SIM_STOP, SHOW_RESULTS},
            //Options menu
            {OPTIONS_DEFAULTS},
            //Help Menu
            {HELP_SHOWHELP, null, HELP_CREDITS}
        };
        String[] menuNames = new String[]{"File", "Action", "Simulation", "Define", "?"};
        char[] mnemChars = new char[]{'f','a','s','d','?'};
        for(int i=0; i<menus.length; i++){
            //initialize menu
            JMenu menu = new JMenu(menuNames[i]);
            menu.setMnemonic(mnemChars[i]);
            for(int j=0; j<menus[i].length;j++){
                if(menus[i][j]!=null){
                    menu.add(new JMenuItem(menus[i][j]));
                }else menu.addSeparator();
            }
            menuBar.add(menu);
        }
        return menuBar;
    }


    public CommonModel getModel() {
        return model;
    }

    /**
     * Sets resultWindow to be shown. This method is used by pollerThread
     * @param rsw window to be set as current ResultsWindow
     */
    public void setResultsWindow(JFrame rsw) {
        this.resultsWindow = rsw;
        if (rsw instanceof ResultsWindow) {
            // Sets action for toolbar buttons
            ((ResultsWindow)rsw).addButtonActions(SIM_START, SIM_PAUSE, SIM_STOP);
        }
        else {
            resultsButton.setEnabled(true);
        }
        // Adds a listener that will unselect Show results button upon results window closing
        rsw.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                resultsButton.setSelected(false);
            }
        });
    }

    /**
     * Called when showResults action is triggered
     * @param selected Tells if show results button is selected or not
     */
    public void showResultsWindow(boolean selected) {
        if (selected) {
            if (resultsWindow != null)
                resultsWindow.show();
        }
        else {
            if (resultsWindow != null)
                resultsWindow.hide();
        }
    }

    /**
     * Shows results window and forces show results button to be selected
     */
    public void showResultsWindow() {
        resultsButton.setSelected(true);
        showResultsWindow(true);
    }



    // ------------------------------ Francesco D'Aquino ---------------------------------------

    /**
     * Shows the panel to solve a problem
     */
    public void showRelatedPanel(int problemType,int problemSubType, Object relatedStation, Object relatedClass) {
        // if it's a no class error show the class panel
        if ((problemType == ModelChecker.ERROR_PROBLEM) && (problemSubType == ModelChecker.NO_CLASSES_ERROR)) {
            tabbedPane.setSelectedIndex(0);
        }
        // if it's a no station error show the station panel
        else if ((problemType == ModelChecker.ERROR_PROBLEM) && (problemSubType == ModelChecker.NO_STATION_ERROR)) {
            tabbedPane.setSelectedIndex(1);
        }
        // if it's a link error show the link panel
        else if ((problemType == ModelChecker.ERROR_PROBLEM) && (problemSubType == ModelChecker.STATION_LINK_ERROR)) {
            tabbedPane.setSelectedIndex(2);
        }
        //if it's an allForwardSinkError show the link panel
        else if ((problemType == ModelChecker.ERROR_PROBLEM) && (problemSubType == ModelChecker.ALL_FORWARD_STATION_ARE_SINK_ERROR)) {
            tabbedPane.setSelectedIndex(2);
        }
        // if it's a routing error show the link panel
        else if ((problemType == ModelChecker.ERROR_PROBLEM) && (problemSubType == ModelChecker.ROUTING_ERROR)) {
            AllStationsParametersPanel temp = (AllStationsParametersPanel)tabbedPane.getComponent(3);
            //set temp to show routing section panel
            temp.showStationParameterPanel(relatedStation,relatedClass,2);
            tabbedPane.setSelectedIndex(3);
        }
        //if no measure have been defined show the measure panel
        else if ((problemType == ModelChecker.ERROR_PROBLEM) && (problemSubType == ModelChecker.SIMULATION_ERROR)) {
            tabbedPane.setSelectedIndex(4);
        }
        //if a measure is inconsistent (i.e have one or more 'null' field) show performance indices panel
        else if ( (problemType == ModelChecker.ERROR_PROBLEM) && (problemSubType == ModelChecker.INCONSISTENT_MEASURE_ERROR) ) {
            tabbedPane.setSelectedIndex(4);
        }
        //if a measure was defined more than once ask to delete the redundant measure
        else if ((problemSubType == ModelChecker.DUPLICATE_MEASURE_ERROR) && (problemType == ModelChecker.ERROR_PROBLEM)) {
            int k = JOptionPane.showConfirmDialog(null,"Delete all redundant performance indices?\n","Redundant performance indices found",JOptionPane.ERROR_MESSAGE);
            if (k == 0) {
                mc.deleteRedundantMeasure();
            }
        }
        //if it is a reference station error show the reference station panel
        else if ((problemType == ModelChecker.ERROR_PROBLEM) && (problemSubType == ModelChecker.REFERENCE_STATION_ERROR)) {
            tabbedPane.setSelectedIndex(5);
        }
        else if ((problemType == ModelChecker.ERROR_PROBLEM) && (problemSubType == ModelChecker.JOIN_WITHOUT_FORK_ERROR)) {
            JOptionPane.showMessageDialog(this,"One or more join found but no fork. Please, remove al join or add a fork");
            tabbedPane.setSelectedIndex(1);
        }

        //used only in JMVA conversion
        else if ((problemSubType == ModelChecker.BCMP_DIFFERENT_QUEUEING_STRATEGIES_WARNING) && (problemType == ModelChecker.WARNING_PROBLEM)) {
            String name = getModel().getStationName(relatedStation);
            int k = JOptionPane.showConfirmDialog(null,"According to BCMP theorem hypothesis each station must have the same queue\nstrategy for each class, but different per class queue strategy were found at " + name + ".\nDo you want to edit "+ name+" queue strategy?\n\n","Mixed queue strategy found",JOptionPane.WARNING_MESSAGE);
            if (k==0) {
                AllStationsParametersPanel temp = (AllStationsParametersPanel)tabbedPane.getComponent(3);
                //set the station parameter panel to show the queue section
                temp.showStationParameterPanel(relatedStation,null,0);
                tabbedPane.setSelectedIndex(3);
            }
        }
        //used only in JMVA conversion
        else if ((problemSubType == ModelChecker.BCMP_FCFS_DIFFERENT_SERVICE_TYPES_WARNING) && (problemType == ModelChecker.WARNING_PROBLEM)) {
            String name = getModel().getStationName(relatedStation);
            int k = JOptionPane.showConfirmDialog(null,"According to BCMP theorem hypothesis, a FCFS server must have the same service times for each class,\nbut at "+name+" the service strategy is mixed, i.e. both load dependent and independent were found.\nDo you want to edit " +name+ " service parameters?\n\n","Mixed service strategies found",JOptionPane.WARNING_MESSAGE);
            if (k==0) {
                AllStationsParametersPanel temp = (AllStationsParametersPanel)tabbedPane.getComponent(3);
                //set the station parameter panel to show the service section
                temp.showStationParameterPanel(relatedStation,null,1);
                tabbedPane.setSelectedIndex(3);
            }
        }
        //used only in JMVA conversion
        else if ((problemSubType == ModelChecker.BCMP_FCFS_EXPONENTIAL_WARNING) && (problemType == ModelChecker.WARNING_PROBLEM)) {
            String name = getModel().getStationName(relatedStation);
            int k = JOptionPane.showConfirmDialog(null,"According to BCMP theorem hypothesis, in a FCFS server all the service time distribution\nmust be exponential, but at "+name+" at least one non exponential distribution was found.\nDo you want to edit " +name+ " service parameters?\n\n","Non exponential distribution in FCFS server",JOptionPane.WARNING_MESSAGE);
            if (k==0) {
                AllStationsParametersPanel temp = (AllStationsParametersPanel)tabbedPane.getComponent(3);
                //set the station parameter panel to show the service section
                temp.showStationParameterPanel(relatedStation,null,1);
                tabbedPane.setSelectedIndex(3);
            }
        }
        //used only in JMVA conversion
        else if ((problemSubType == ModelChecker.BCMP_FCFS_DIFFERENT_SERVICE_TIMES_WARNING) && (problemType == ModelChecker.WARNING_PROBLEM)) {
            String name = getModel().getStationName(relatedStation);
            int k = JOptionPane.showConfirmDialog(null,"According to BCMP theorem hypothesis, in a FCFS server all the per class service time mean values\nmust be the same. If the service strategies are load dependent the mean value in each range\nhas to be the same for each class.\nDo you want to edit " +name+ " service parameters?\n\n","Non exponential distribution in FCFS server",JOptionPane.WARNING_MESSAGE);
            if (k==0) {
                AllStationsParametersPanel temp = (AllStationsParametersPanel)tabbedPane.getComponent(3);
                //set the station parameter panel to show the queue section
                temp.showStationParameterPanel(relatedStation,null,1);
                tabbedPane.setSelectedIndex(3);
            }
        }
        //used only in JMVA conversion
        else if ((problemType == ModelChecker.WARNING_PROBLEM) && (problemSubType == ModelChecker.BCMP_NON_STATE_INDEPENDENT_ROUTING_WARNING)) {
            int k = JOptionPane.showConfirmDialog(null,"Convert all non state independent routing strategies to Random Routing?\n\nAccording to the BCMP theorem the routing probabilities must be independent from the state of the model.\nChoosing ok all non state independent routing strategies inside a station will be converted to Random Routing.\nDo you want to convert all non state independent routing strategies to Random Routing?\n\n","BCMP hypothesis not verified",JOptionPane.ERROR_MESSAGE);
            if (k == 0) mc.setAllStateDependentRoutingStrategyToRandomRouting();
        }

        //if it is a no backward link warning show the link panel
        else if ((problemType == ModelChecker.WARNING_PROBLEM) && (problemSubType == ModelChecker.NO_BACKWARD_LINK_WARNING)) {
            tabbedPane.setSelectedIndex(2);
        }
        else if ( (problemType == ModelChecker.WARNING_PROBLEM) && (problemSubType == ModelChecker.PARAMETRIC_ANALYSIS_MODEL_MODIFIED_WARNING) ) {
            String message = "Check parametric analysis model?\n\nThe parametric analysis model previously defined had become inconsistent with the \nsimulation model. It will be automatically modified when simulation will be started.\nDo you want to autocorrect and check parametric analysis panel?\n\n";
            int k = JOptionPane.showConfirmDialog(null,message,"Inconsistent parametric analysis model",JOptionPane.WARNING_MESSAGE);
            if (k==0) {
                model.getParametricAnalysisModel().checkCorrectness(true);
                tabbedPane.setSelectedIndex(8);
                SimulationPanel simPanel = (SimulationPanel)tabbedPane.getComponentAt(6);
                //model.getParametricAnalysisModel().setModified(true);
            }
        }
        else if ((problemSubType == ModelChecker.PARAMETRIC_ANALYSIS_NO_MORE_AVAIBLE_WARNING) && (problemType == ModelChecker.WARNING_PROBLEM)) {
            String message = "Parametric analysis was set, but no parametric analysis is now avaible,\nsince the simulation model was changed. It is only possible to execute normal simulation.\nDo you wish to continue anyway?\n\n";
            int k = JOptionPane.showConfirmDialog(null,message,"Parametric analysis not avaible",JOptionPane.WARNING_MESSAGE);
            if (k == 0) {
                model.setParametricAnalysisEnabled(false);
                model.setParametricAnalysisModel(null);
            }
        }
        else if ((problemSubType == ModelChecker.FORK_WITHOUT_JOIN_WARNING) && (problemType == ModelChecker.WARNING_PROBLEM)) {
            JOptionPane.showMessageDialog(this,"A fork was found but no join. Please check the topology");
        }
        else if ((problemSubType == ModelChecker.EMPTY_BLOCKING_REGION)) {
            int k = JOptionPane.showConfirmDialog(null,"Delete empty finite capacity regions?\n","Empty finite capacity regions found",JOptionPane.ERROR_MESSAGE);
            if (k == 0) {
                mc.deleteEmptyBlockingRegions();
            }
        }
        else if (problemSubType == ModelChecker.PRELOADING_WITH_BLOCKING) {
            tabbedPane.setSelectedIndex(7);
        }
    }

    /**
     * Shows the class panel
     */
    public void showClassPanel() {
        tabbedPane.setSelectedIndex(0);
    }

    /**
     * Sets the Parametric Analysis Results Window
     *
     * @param parw the Parametric Analysis Results Window to be set
     */
    /*public void setPAResultsWindow(PAResultsWindow parw) {
        parametricResultsWindow = parw;
        parw.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                resultsButton.setSelected(false);
            }
        });
    }*/

    /**
     * Sets the availability of results in case of parametric analysis
     *
     * @param avaible true if they are avaible
     */
    /*public void setPAResultsAvaible(boolean avaible) {
        resultsButton.setEnabled(avaible);
    }*/

    /**
     * Used to discover if the instance can display simulation animation
     *
     * @return true if the instance can display simulation animation
     */
    public boolean isAnimationDisplayable() {
        return false;
    }

    //-------------------------------------- end Francesco D'Aquino --------------------------------

    /**
     * Shows a panel with catched exception
     * @param e exception to be shown
     */
    public void handleException(Exception e){
        showErrorMessage(e.getMessage());
    }

    /**
     * Shows a panel with an error message
     * @param message specified error message
     */
    public void showErrorMessage(String message){
        JOptionPane.showMessageDialog(this, message,
                "Error", JOptionPane.ERROR_MESSAGE);
    }

    /**
     * Checks if there's an old graph to save. This methods is called when creates/closes/opens a graph.
     * @param msg The message to display.
     * @return <code>true</code> - whether the user accepts to save the graph, or he cancels the current action.
     */
    public boolean checkForSave(String msg) {
        // Checks if there's an old graph to save
        if (model != null && model.toBeSaved()) {
            int resultValue = JOptionPane.showConfirmDialog(this,
                    msg,
                    "JSIM - Warning",
                    JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE);
            if (resultValue == JOptionPane.YES_OPTION) {
                saveFile();
                return false;
            }
            if (resultValue == JOptionPane.CANCEL_OPTION) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args){
        try {
            UIManager.setLookAndFeel(new com.jgoodies.looks.plastic.Plastic3DLookAndFeel());

        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        Locale.setDefault(Locale.ENGLISH);
        new JSIMMain().show();
    }

    /**
     * Overrides default Solve button pression...
     * @see Wizard
     */
    protected void finish() {
        SIM_START.actionPerformed(null);
    }

}

⌨️ 快捷键说明

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