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

📄 simulationpanel.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**    
  * Copyright (C) 2006, Laboratorio di Valutazione delle Prestazioni - Politecnico di Milano

  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.

  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.

  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
  
package jmt.gui.common.panels;

import jmt.gui.common.CommonConstants;
import jmt.gui.common.definitions.ClassDefinition;
import jmt.gui.common.definitions.GuiInterface;
import jmt.gui.common.definitions.SimulationDefinition;
import jmt.gui.common.definitions.StationDefinition;
import jmt.gui.common.layouts.SpringUtilities;
import jmt.gui.exact.table.ExactTable;
import jmt.gui.exact.table.ExactTableModel;
import jmt.gui.wizard.WizardPanel;

import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.util.HashMap;

/**
 * <p>Title: Simulation & Preloading panel</p>
 * <p>Description: A panel in which simulation parameters and queue preloading can be specified</p>
 * 
 * @author Bertoli Marco
 *         Date: 16-set-2005
 *         Time: 14.01.02
 *
 * Modified by Francesco D'Aquino 11/11/2005
 */
public class SimulationPanel  extends WizardPanel implements CommonConstants {
    protected static final int BORDERSIZE = 20;
    protected static final long MINIMUM_TIME = 5; // Minimum simulation duration
    protected ClassDefinition cd;
    protected StationDefinition sd;
    protected SimulationDefinition simd;
    protected HashMap unallocated;

    // Simulation parameters
    protected JCheckBox randomSeed, infDuration, noStatistic;
    protected JSpinner seed, duration, polling, maxSamples;
    protected  JTable preloadTable;

    //Francesco D'Aquino
    protected JCheckBox animationEnabler;
    private GuiInterface gui;
    // end Francesco D'Aquino

    /**
     * Builds a new simulation panel
     * @param cd a ClassDefinition data structure
     * @param sd a StationDefinition data structure
     * @param simd a SimulationDefinition data structure
     */
    public SimulationPanel(ClassDefinition cd, StationDefinition sd, SimulationDefinition simd, GuiInterface gui) {
        setData(cd, sd, simd);
        //Francesco D'Aquino
        this.gui = gui;
        InitGUI(this.gui);
        // end Francesco D'Aquino
        InitActions();
    }

    /**
     * Initialize internal data structures
     * @param cd a ClassDefinition data structure
     * @param sd a StationDefinition data structure
     * @param simd a SimulationDefinition data structure
     */
    public void setData(ClassDefinition cd, StationDefinition sd, SimulationDefinition simd) {
        this.cd = cd;
        this.sd = sd;
        this.simd = simd;
        refreshDataStructures();
    }

    /**
     * Refresh internal data structures. This method is separate from setData as have to
     * be called in JSIM at every gotFocus event (or internal data structures will
     * not be up-to-date)
     */
    protected void refreshDataStructures() {
        // Creates an hashmap with unallocated jobs for every class closed class
        unallocated = new HashMap();
        for (int i=0; i<cd.getClassKeys().size(); i++) {
            Object key = cd.getClassKeys().get(i);
            if (cd.getClassType(key) == CLASS_TYPE_CLOSED)
                unallocated.put(key, new Integer(
                    cd.getClassPopulation(key).intValue() - simd.getPreloadedJobsNumber(key).intValue()
                ));
        }
    }

    /**
     * called by the Wizard when the panel becomes active
     */
    public void gotFocus() {
        refreshDataStructures();
        this.removeAll();
        InitGUI(gui);
        InitActions();
    }

    /**
     * called by the Wizard before when switching to another panel
     */
    public void lostFocus() {
        // Aborts editing of table
        TableCellEditor editor = preloadTable.getCellEditor();
        if (editor != null)
            editor.stopCellEditing();
        simd.manageJobs();
    }

    /**
     * Sets the tab to be shown
     * @param tabNumber the index of the tab to be shown
     */
    /*public void setSelectedTab(int tabNumber) {
        tabbedPane.setSelectedIndex(tabNumber);    
    }*/

    /**
     * Initialize all GUI related stuff
     *
     * Modified by Francesco D'Aquino.
     * The old version was InitGUI(). The gui parameter is used to insert or not the
     * JCheckBox used to enable queue animation.
     */
    protected void InitGUI(GuiInterface gui) {
        // ------------ Francesco D'Aquino  ------------------------------------
        //tabbedPane = new JTabbedPane();
        // ----------- end Francesco D'Aquino ----------------------------------

        // Adds margins and a central main panel
        this.setLayout(new BorderLayout());
        this.add(Box.createVerticalStrut(BORDERSIZE), BorderLayout.NORTH);
        this.add(Box.createVerticalStrut(BORDERSIZE), BorderLayout.SOUTH);
        this.add(Box.createHorizontalStrut(BORDERSIZE), BorderLayout.WEST);
        this.add(Box.createHorizontalStrut(BORDERSIZE), BorderLayout.EAST);
        JPanel mainpanel = new JPanel(new BorderLayout());
        this.add(mainpanel, BorderLayout.CENTER);

        JPanel upperPanel = new JPanel(new BorderLayout());
        JLabel descrLabel = new JLabel(SIMULATION_DESCRIPTION);
        descrLabel.setVerticalAlignment(JLabel.NORTH);
        upperPanel.add(descrLabel, BorderLayout.WEST);
        upperPanel.add(Box.createVerticalStrut(BORDERSIZE / 2), BorderLayout.SOUTH);
        mainpanel.add(upperPanel, BorderLayout.NORTH);


        // Adds preloading table
        preloadTable = new PreloadingTable();
        WarningScrollTable preloadPanel = new WarningScrollTable(preloadTable,
                WARNING_CLASS_STATION);
        //tabbedPane.addTab("Initial state",preloadPanel);
        //ParametricAnalysisPanel parametricAnalysisPanel = new ParametricAnalysisPanel();
        //tabbedPane.addTab("Parametric analysis options",parametricAnalysisPanel);
        //mainpanel.add(tabbedPane, BorderLayout.CENTER);
        mainpanel.add(preloadPanel,BorderLayout.CENTER);

        // Adds simulation parameters
        JPanel simPanel = new JPanel(new SpringLayout());
        JLabel label;
        // Simulation seed
        label = new JLabel("Simulation random seed: ");
        simPanel.add(label);
        seed = new JSpinner();
        seed.setValue(simd.getSimulationSeed());
        label.setLabelFor(seed);
        simPanel.add(seed);
        randomSeed = new JCheckBox("random");
        if (simd.getUseRandomSeed()) {
            randomSeed.setSelected(true);
            seed.setEnabled(false);
            randomSeed.setToolTipText("Uses a random seed to initialize the random number generator");
        }
        simPanel.add(randomSeed);
        // Maximum duration
        label = new JLabel("Maximum duration (sec): ");
        simPanel.add(label);
        duration = new JSpinner(new SpinnerNumberModel(1,.1,Integer.MAX_VALUE, 1));
        duration.setValue(simd.getMaximumDuration());
        label.setLabelFor(duration);
        simPanel.add(duration);
        infDuration = new JCheckBox("infinite");
        infDuration.setToolTipText("Disables the automatic timer used to stop simulation");
        if (simd.getMaximumDuration().longValue() == -1) {
            infDuration.setSelected(true);
            duration.setValue(new Double(600));
            duration.setEnabled(false);
        }
        simPanel.add(infDuration);

        // Maximum number of samples
        label = new JLabel("Maximum number of samples: ");
        simPanel.add(label);
        maxSamples = new JSpinner(new SpinnerNumberModel(500000,100000,Integer.MAX_VALUE, 50000));
        maxSamples.setValue(simd.getMaxSimulationSamples());
        label.setLabelFor(maxSamples);
        simPanel.add(maxSamples);
        // Adds disable statistic checkbox
        noStatistic = new JCheckBox("no automatic stop");
        noStatistic.setToolTipText("Disable confidence interval/maximum relative error as simulation stopping criteria");
        noStatistic.setSelected(simd.getDisableStatistic().booleanValue());
        simPanel.add(noStatistic);

        //Francesco D'Aquino
        if (gui.isAnimationDisplayable()) {
            animationEnabler = new JCheckBox("animation");
            animationEnabler.setToolTipText("Shows queue animation during simulation");
            if (simd.isAnimationEnabled()) animationEnabler.setSelected(true);
        }
        // end Francesco D'Aquino


        // Maximum duration
        label = new JLabel("Animation update interval (sec): ");
        simPanel.add(label);
        polling = new JSpinner(new SpinnerNumberModel(1,.1,Integer.MAX_VALUE, 1));
        polling.setValue(new Double(simd.getPollingInterval()));
        label.setLabelFor(polling);
        simPanel.add(polling);

        if (gui.isAnimationDisplayable()) 
            simPanel.add(animationEnabler);
        // Adds an empty panel not to spoil layout
        else simPanel.add(new JPanel());


        SpringUtilities.makeCompactGrid(simPanel,
                                            4, 3, //rows, cols
                                            16, 6, //initX, initY
                                            6, 6);//xPad, yPad
        upperPanel.add(simPanel, BorderLayout.CENTER);
    }

    /**
     * Inits all action listeners related to GUI object
     */

⌨️ 快捷键说明

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