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

📄 simulationpanel.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    protected void InitActions() {
        // Random seed
        randomSeed.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                if (randomSeed.isSelected()) {
                    simd.setUseRandomSeed(true);
                    seed.setEnabled(false);
                }
                else {
                    simd.setUseRandomSeed(false);
                    seed.setEnabled(true);
                }
            }
        });
        // Seed value
        seed.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                Object value = seed.getValue();
                if (value instanceof Long) {
                    Long l = (Long) value;
                    if (l.longValue() >= 0)
                        simd.setSimulationSeed(l);
                }
                else if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    if (i.intValue() >= 0)
                        simd.setSimulationSeed(new Long(i.intValue()));
                }
                seed.setValue(simd.getSimulationSeed());
            }
        });

        // Infinite duration
        infDuration.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                if (infDuration.isSelected()) {
                    simd.setMaximumDuration(new Double(-1));
                    duration.setEnabled(false);
                }
                else {
                    Object value = duration.getValue();
                    if (value instanceof Double)
                        simd.setMaximumDuration((Double) value);
                    else if (value instanceof Integer)
                        simd.setMaximumDuration(new Double(((Integer) value).intValue()));
                    duration.setEnabled(true);
                }
            }
        });

        if (animationEnabler != null) {
            animationEnabler.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (animationEnabler.isSelected()) {
                        simd.setAnimationEnabled(true);
                    }
                    else {
                        simd.setAnimationEnabled(false);
                    }
                }
            });
        }


        // Duration
        duration.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                Object value = duration.getValue();
                if (value instanceof Double) {
                    Double d = (Double) value;
                    if (d.doubleValue() >= MINIMUM_TIME)
                        simd.setMaximumDuration(d);
                }
                else if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    if (i.intValue() >= MINIMUM_TIME)
                        simd.setMaximumDuration(new Double(i.intValue()));
                }
                duration.setValue(simd.getMaximumDuration());
            }
        });

        // Maximum number of samples
        maxSamples.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                Object value = maxSamples.getValue();
                if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    if (i.intValue() >= 100000)
                        simd.setMaxSimulationSamples(i);
                }
                maxSamples.setValue(simd.getMaxSimulationSamples());
            }
        });

        //Polling interval
        polling.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                Object value = polling.getValue();
                if (value instanceof Double) {
                    Double d = (Double) value;
                    if (d.doubleValue() > 0)
                        simd.setPollingInterval(d.doubleValue());
                }
                else if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    if (i.intValue() > 0)
                        simd.setPollingInterval(i.doubleValue());
                }
                polling.setValue(new Double(simd.getPollingInterval()));
            }
        });
        
        // Disable statistic
        noStatistic.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                simd.setDisableStatistic(new Boolean(noStatistic.isSelected()));
            }
        });
    }

    /**
     * Inner class to specify preloading table
     */
    protected class PreloadingTable extends ExactTable {
        public PreloadingTable() {
            super(new PreloadTableModel());
            setDefaultEditor(Integer.class, new jmt.gui.exact.table.ExactCellEditor());
            autoResizeMode = AUTO_RESIZE_OFF;
            setDisplaysScrollLabels(true);

            setRowSelectionAllowed(false);
            setColumnSelectionAllowed(false);
            setClipboardTransferEnabled(false);
        }
    }

    /**
     * Model for Preload table
     * Rows represent classes, columns stations.
     */
    protected class PreloadTableModel extends ExactTableModel {
        public PreloadTableModel() {
            prototype = "Station10000";
            rowHeaderPrototype = "Class10000 (Ni = 100)";
        }

        public int getRowCount() {
            return cd.getClassKeys().size();
        }

        public int getColumnCount() {
            return sd.getStationKeysNoSourceSink().size();
        }


        public Class getColumnClass(int columnIndex){
            if(columnIndex >= 0) return Integer.class;
            else return super.getColumnClass(columnIndex);
        }

        public String getColumnName(int index) {
            if(index >= 0 && sd.getStationKeysNoSourceSink().size()>0) {
                return sd.getStationName(getStationKey(index));
            }
            else return "";
        }

        public Object getPrototype(int i){
            if(i==-1) return rowHeaderPrototype;
            else return prototype;
        }

        protected Object getValueAtImpl(int rowIndex, int columnIndex) {
            Object row = getClassKey(rowIndex),
                    col = getStationKey(columnIndex);
            return simd.getPreloadedJobs(col, row);
        }

        protected Object getRowName(int rowIndex) {
            String className =  cd.getClassName(getClassKey(rowIndex));
            Integer population = cd.getClassPopulation(getClassKey(rowIndex));
            if (cd.getClassType(getClassKey(rowIndex)) == CLASS_TYPE_OPEN)
                return className;
            else
                return className + " (Ni = "+population+")";
        }

        //returns search key of a station given its index in table
        private Object getStationKey(int index){
            return sd.getStationKeysNoSourceSink().get(index);
        }

        //returns search key of a class given its index in table
        private Object getClassKey(int index){
            return cd.getClassKeys().get(index);
        }

        public void setValueAt(Object value, int rowIndex, int columnIndex) {
            try {
                if(value instanceof Integer || value instanceof String){
                    int i;
                    if (value instanceof Integer)
                        i = ((Integer) value).intValue();
                    else
                        i = Integer.parseInt((String)value);

                    Object key = getClassKey(rowIndex);
                    int oldjobs = simd.getPreloadedJobs(getStationKey(columnIndex), key).intValue();
                    if (i >= 0) {
                        if (cd.getClassType(key) == CLASS_TYPE_OPEN)
                            simd.setPreloadedJobs(new Integer(i),
                                    getStationKey(columnIndex),
                                    key);
                        // If class is closed controls if unallocated jobs are enough to change this value
                        else if (i - oldjobs <= ((Integer)unallocated.get(key)).intValue()) {
                            simd.setPreloadedJobs(new Integer(i),
                                    getStationKey(columnIndex),
                                    key);
                            int newunallocated = ((Integer)unallocated.get(key)).intValue() - i + oldjobs;
                            unallocated.put(key, new Integer(newunallocated));
                        }
                    }
                }
            } catch (NumberFormatException e) {
                // Aborts modification if String is invalid
            }
        }

        public void clear(int row, int col) {
            int oldjobs = simd.getPreloadedJobs(getStationKey(col), getClassKey(row)).intValue();
            simd.setPreloadedJobs(new Integer(0),
                    getStationKey(col),
                    getClassKey(row));
            // If class is closed, put back oldjobs into unallocated data structure
            if (cd.getClassType(getClassKey(row)) == CLASS_TYPE_CLOSED) {
                int newunallocated = ((Integer)unallocated.get(getClassKey(row))).intValue() + oldjobs;
                unallocated.put(getClassKey(row), new Integer(newunallocated));
            }
        }

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
        }

    }

    /**
     * @return name to be displayed on the tab, when inserted in a wizard tabbed pane
     */
    public String getName(){
        return "Simulation";
    }

}

⌨️ 快捷键说明

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