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

📄 defaultseditor.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

        // Distribution
        addInputDistribution("Distribution (open classes)", "classDistribution", class_panel);
        classpanelnum++;

        SpringUtilities.makeCompactGrid(class_panel,
                                            classpanelnum, 2, //rows, cols
                                            6, 6, //initX, initY
                                            6, 6);//xPad, yPad
        param_panel.add(class_panel);


        // Station Parameters
        JPanel station_panel = new JPanel(new SpringLayout());
        int stationpanelnum = 0; // Counts all inserted elements
        station_panel.setBorder(new TitledBorder(new EtchedBorder(), "Station parameters"));

        // Name (JSIM only)
        if (target == JSIM) {
            addInputString("Name", "stationName", station_panel);
            stationpanelnum++;
        }

        // Station type (JSIM only)
        if (target == JSIM) {
            tmpMap = new TreeMap();
            tmpMap.put(Defaults.STATION_TYPE_SERVER, Defaults.STATION_TYPE_SERVER);
            tmpMap.put(Defaults.STATION_TYPE_DELAY, Defaults.STATION_TYPE_DELAY);
            tmpMap.put(Defaults.STATION_TYPE_ROUTER, Defaults.STATION_TYPE_ROUTER);
            tmpMap.put(Defaults.STATION_TYPE_FORK, Defaults.STATION_TYPE_FORK);
            tmpMap.put(Defaults.STATION_TYPE_JOIN, Defaults.STATION_TYPE_JOIN);
            addInputCombo("Type", "stationType", station_panel, tmpMap);
            stationpanelnum++;
        }

        // Queue Capacity
        addInputInfSpinner("Queue Capacity","stationCapacity", station_panel, 0, -1);
        stationpanelnum++;

        // Number of Servers
        addInputSpinner("Number of Servers","stationServers", station_panel, 1);
        stationpanelnum++;

        // Queue Strategy
        addInputQueueStrategy("Queue Strategy", "stationQueueStrategy", station_panel);
        stationpanelnum++;

        // Service strategy
        addInputDistribution("Service Strategy", "stationServiceStrategy", station_panel);
        stationpanelnum++;

        // Delay service strategy
        addInputDistribution("Delay Service Strategy", "stationDelayServiceStrategy", station_panel);
        stationpanelnum++;

        // Routing strategy
        addInputRouting("Routing Strategy", "stationRoutingStrategy", station_panel);
        stationpanelnum++;
        
        // Drop rule
        addInputDropRule("Drop Rule", "dropRule", station_panel);
        stationpanelnum++;

        // Fork Blocking
        addInputInfSpinner("Fork Blocking","forkBlock", station_panel, 1, -1);
        stationpanelnum++;

        // Number of jobs created for each fork link
        addInputSpinner("Fork tasks per link", "forkJobsPerLink", station_panel, 1);
        stationpanelnum++;

        SpringUtilities.makeCompactGrid(station_panel,
                                            stationpanelnum, 2, //rows, cols
                                            6, 6, //initX, initY
                                            6, 6);//xPad, yPad
        param_panel.add(station_panel);

        // Simulation Parameters
        JPanel sim_panel = new JPanel(new SpringLayout());
        int simpanelnum = 0; // Counts all inserted elements
        sim_panel.setBorder(new TitledBorder(new EtchedBorder(), "Simulation parameters"));

        // Measure Alpha
        addInput01Spinner("Measure Confidence Interval (0-1)","measureAlpha", sim_panel);
        simpanelnum++;

        // Measure Precision
        addInput01Spinner("Measure Max Relative Error (0-1)","measurePrecision", sim_panel);
        simpanelnum++;

        // Simulation Seed
        addInputSpinner("Simulation random seed","simulationSeed", sim_panel,1);
        simpanelnum++;

        // Maximum duration
        addInputInfSpinner("Maximum duration (sec)","simulationMaxDuration", sim_panel, MINIMUM_TIME, -1);
        simpanelnum++;

        // Maximum duration
        addInputSpinner("Maximum number of samples","maxSimulationSamples", sim_panel, 100000);
        simpanelnum++;

        //Polling interval
        simpanelnum++;
        addInputSpinner("Animation update interval (sec)","simulationPolling", sim_panel,1);

        // Francesco D'Aquino
        // Animation enabled/disabled
        simpanelnum++;
        this.addInputAnimationSpinner("Number of classes in queue animations","isWithAnimation","representableClasses",sim_panel,1,10);
        // end Francesco D'Aquino

        SpringUtilities.makeCompactGrid(sim_panel,
                                            simpanelnum, 2, //rows, cols
                                            6, 6, //initX, initY
                                            6, 6);//xPad, yPad


        param_panel.add(sim_panel);

        // Blocking region parameters
        JPanel block_panel = new JPanel(new SpringLayout());
        int blockpanelnum = 0; // Counts all inserted elements
        block_panel.setBorder(new TitledBorder(new EtchedBorder(), "Finite Capacity Region Parameters"));

        // Blocking Region name
        addInputString("Name", "blockingRegionName", block_panel);
        blockpanelnum++;

        // Region Capacity
        addInputInfSpinner("Global Region Capacity","blockingMaxJobs", block_panel, 1, -1);
        blockpanelnum++;

        // Region Capacity per Class
        addInputInfSpinner("Region Capacity per Class","blockingMaxJobsPerClass", block_panel, 1, -1);
        blockpanelnum++;

        // Drop rule
        addBooleanComboBox("Drop", "blockingDropPerClass", block_panel);
        blockpanelnum++;

        SpringUtilities.makeCompactGrid(block_panel,
                                            blockpanelnum, 2, //rows, cols
                                            6, 6, //initX, initY
                                            6, 6);//xPad, yPad
        param_panel.add(block_panel);
    }

    /**
     * Adds an input field to insert a String
     * @param text text to be shown on a label
     * @param property property to be changed in Defaults
     * @param cont container where input field must be added
     */
    protected void addInputString(String text, String property, Container cont) {
        JLabel label = new JLabel(text+":");
        JTextField field = new JTextField(10);
        field.setName(property);
        label.setLabelFor(field);
        field.setText(Defaults.get(property));
        // Sets maximum size to minimal one, otherwise springLayout will stretch this
        field.setMaximumSize(new Dimension(field.getMaximumSize().width,
                field.getMinimumSize().height));
        field.addKeyListener(stringListener);
        field.addFocusListener(stringListener);
        registeredStringListener.add(field);
        cont.add(label);
        cont.add(field);
    }

    /**
     * Adds an input field to select from a ComboBox
     * @param text text to be shown on a label
     * @param property property to be changed in Defaults
     * @param cont container where input field must be added
     * @param values Map with internal value <-> showed value relations
     */
    protected void addInputCombo(String text, final String property, Container cont, final Map values) {
        JLabel label = new JLabel(text+":");
        JComboBox combo = new JComboBox(values.values().toArray());
        combo.setName(property);
        label.setLabelFor(combo);
        combo.setSelectedItem(values.get(Defaults.get(property)));
        // Sets maximum size to minimal one, otherwise springLayout will stretch this
        combo.setMaximumSize(new Dimension(combo.getMaximumSize().width,
                combo.getMinimumSize().height));
        combo.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                // As Map does not allows reverse mapping, scans the entire keyset to
                // find the key corresponding to a given object
                Object[] keys = values.keySet().toArray();
                for (int i =0; i<keys.length; i++)
                    if (values.get(keys[i]) == e.getItem()) {
                        Defaults.set(property, (String) keys[i]);
                    }
            }
        });
        cont.add(label);
        cont.add(combo);
    }

    /**
     * Adds an input field to chose a number from a Spinner
     * @param text text to be shown on a label
     * @param property property to be changed in Defaults
     * @param cont container where input field must be added
     * @param minvalue minimum value allowed for this property
     */
    protected void addInputSpinner(String text, final String property, Container cont, final int minvalue) {
        JLabel label;
        label = new JLabel(text+":");
        final JSpinner spinner = new JSpinner();
        label.setLabelFor(spinner);
        spinner.setValue(Defaults.getAsInteger(property));
        // Sets maximum size to minimal one, otherwise springLayout will stretch this
        spinner.setMaximumSize(new Dimension(spinner.getMaximumSize().width,
                spinner.getMinimumSize().height));
        spinner.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                //stop editing text inside spinner
                try{
                    spinner.commitEdit();
                }catch(ParseException pe){
                    //if string does not represent a number, return
                    return;
                }
                //new number of classes
                int x = minvalue;
                try{
                    x = ((Integer)spinner.getValue()).intValue();
                }catch(NumberFormatException nfe){
                    //null
                }catch(ClassCastException cce){
                    //null
                }
                if (x < minvalue)
                    x = minvalue;
                spinner.setValue(new Integer(x));
                Defaults.set(property, Integer.toString(x));
            }
        });
        cont.add(label);
        cont.add(spinner);
    }

    /**
     * Adds an input field to chose a number from a Spinner. Number is between 0 and 1
     * @param text text to be shown on a label
     * @param property property to be changed in Defaults
     * @param cont container where input field must be added
     */
    protected void addInput01Spinner(String text, final String property, Container cont) {
        JLabel label;
        label = new JLabel(text+":");
        final JSpinner spinner = new JSpinner();
        spinner.setModel(new SpinnerNumberModel(0.0, 0.0, 1.0, 0.01));
        label.setLabelFor(spinner);
        spinner.setValue(Defaults.getAsDouble(property));
        // Sets maximum size to minimal one, otherwise springLayout will stretch this
        spinner.setMaximumSize(new Dimension(spinner.getMaximumSize().width,
                spinner.getMinimumSize().height));
        spinner.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                //stop editing text inside spinner
                try{
                    spinner.commitEdit();
                }catch(ParseException pe){
                    //if string does not represent a number, return
                    return;
                }
                //new number of classes

⌨️ 快捷键说明

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