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

📄 paprogresswindow.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.parametric;

import jmt.gui.common.CommonConstants;
import jmt.gui.common.definitions.parametric.ParametricAnalysisDefinition;
import jmt.gui.common.resources.ImageLoader;
import jmt.gui.common.startScreen.sampleAnimation.SampleQNAnimation;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * <p>Title: Parametric Analysis Progress Window</p>
 * <p>Description: This window is shown during parametric analysis</p>
 *
 * @author Francesco D'Aquino
 *         Date: 4-gen-2006
 *         Time: 13.53.23
 */
public class PAProgressWindow extends JDialog {
    public static final String RUNNING_MESSAGE = "What-if analysis running, please wait...";
    public static final String ENUMERATION_MESSAGE = "Running simulation";
    public static final String PAUSE_MESSAGE = "Parametric analysis paused...";
    public static final String STOP_MESSAGE = "Parametric analysis stopped";
    //private final double SIMULATION_DURATION_INITIALIZATION = 0;
    private static final double HISTOGRAM_INTERVALS = 10;
    private JButton start, stop, pause;
    private JToolBar toolbar;
    private JProgressBar progressBar;
    private SampleQNAnimation animation;
    private JLabel mainLabel;
    private JLabel stepLabel;
    private JLabel elapsedTimeLabel;
    //private JLabel remainingTimeLabel;

    JLabel stoppedAnimation;

    private int numberOfSimulations;
    private int stepNumber;
    private JPanel globalPanel;
    private JPanel pivotPanel;
    private boolean stopped,paused;
    private String elapsedTimeString;
    private String remainingTimeString;

    private Timer timer;
    //private double MA_cumulativeTime;
    private double[] simulationTimes;
    private double globalCumulativeTime;
    private double globalMeanSimulationTime;
    private double lastSimulationFinishTime;
    private double globalStartTime;


    boolean wasPaused;
    double pauseTime;
    double resumeTime;


    private double elapsedTime;

    public PAProgressWindow (Frame owner,AbstractAction startAction, AbstractAction pauseAction, final AbstractAction stopAction, ParametricAnalysisDefinition pad) {
        super(owner);
        this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        numberOfSimulations = pad.getNumberOfSteps();
        stepNumber = 1;
        this.getContentPane().setLayout(new BorderLayout());
        this.setTitle("What-if analysis progress");
        int width = 500, height=390;

        globalCumulativeTime = 0;
        globalMeanSimulationTime = 0;


        // Centers this dialog on the screen
        Dimension scrDim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setBounds((scrDim.width-width)/2,(scrDim.height-height)/2,width,height);

        // Creates bottom toolbar
        toolbar = new JToolBar();
        toolbar.setFloatable(false);
        toolbar.setRollover(true);
        start = new JButton();
        toolbar.add(start);
        pause = new JButton();
        toolbar.add(pause);
        stop = new JButton();
        toolbar.add(stop);

        start.setAction(startAction);
        start.setText("");
        start.setIcon(ImageLoader.loadImage("Sim"));
        start.setFocusPainted(false);
        start.setContentAreaFilled(false);
        start.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        start.setRolloverIcon(ImageLoader.loadImage("SimRO"));
        start.setPressedIcon(ImageLoader.loadImage("SimP"));
        start.setVisible(true);

        pause.setAction(pauseAction);
        pause.setText("");
        pause.setIcon(ImageLoader.loadImage("Pause"));
        pause.setFocusPainted(false);
        pause.setContentAreaFilled(false);
        pause.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        pause.setRolloverIcon(ImageLoader.loadImage("PauseRO"));
        pause.setPressedIcon(ImageLoader.loadImage("PauseP"));
        pause.setVisible(true);

        stop.setAction(stopAction);
        stop.setText("");
        stop.setIcon(ImageLoader.loadImage("Stop"));
        stop.setFocusPainted(false);
        stop.setContentAreaFilled(false);
        stop.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        stop.setRolloverIcon(ImageLoader.loadImage("StopRO"));
        stop.setPressedIcon(ImageLoader.loadImage("StopP"));
        stop.setVisible(true);

        // Adds a progress bar
        progressBar = new JProgressBar();
        progressBar.setStringPainted(true);
        progressBar.setForeground(Color.BLUE);
        toolbar.add(progressBar);

        // Adds toolbar
        this.getContentPane().add(toolbar, BorderLayout.SOUTH);

        //Creates and adds the animation panel
        //animation = new SampleQNAnimation();
        //animation.start();
        pivotPanel = new JPanel (new GridBagLayout());
        //animation.setPreferredSize(new Dimension(200,120));
        //animation.setBackground(new Color(151,151,151));
        stoppedAnimation = new JLabel(ImageLoader.loadImage("emptyAnimation"));
        stoppedAnimation.setPreferredSize(new Dimension(200,120));
        pivotPanel.add(stoppedAnimation);

        //Creates and adds the description label
        JPanel mainLabelPanel = new JPanel();
        mainLabel = new JLabel(CommonConstants.HTML_START + CommonConstants.HTML_FONT_TITLE +
            RUNNING_MESSAGE + CommonConstants.HTML_FONT_TIT_END +
            CommonConstants.HTML_END);
        mainLabelPanel.add(mainLabel);



        elapsedTimeString = "00m : 00s";
        remainingTimeString = "-- : --";
        elapsedTimeLabel = new JLabel("Elapsed time: " + elapsedTimeString);
        JPanel elapsedTimeLabelPanel = new JPanel();
        elapsedTimeLabelPanel.add(elapsedTimeLabel);
        //remainingTimeLabel = new JLabel("Residual time: " + remainingTimeString);
        JPanel remainingTimeLabelPanel = new JPanel();
        //remainingTimeLabelPanel.add(remainingTimeLabel);
        remainingTimeLabelPanel.setBorder(new EmptyBorder(10,0,10,0));
        JPanel tempPanel = new JPanel(new BorderLayout());
        tempPanel.add(elapsedTimeLabel,BorderLayout.NORTH);
        //tempPanel.add(remainingTimeLabel,BorderLayout.SOUTH);
        JPanel timeLabelPanel = new JPanel();
        timeLabelPanel.add(tempPanel);
        timeLabelPanel.setBorder(new EmptyBorder(10,0,0,0));
        JPanel stepLabelPanel = new JPanel();
        stepLabel = new JLabel (CommonConstants.HTML_START + CommonConstants.HTML_FONT_NORM +
                                 ENUMERATION_MESSAGE + " " + stepNumber + " of " + this.numberOfSimulations + "..." +  CommonConstants.HTML_FONT_NOR_END + CommonConstants.HTML_END);
        stepLabelPanel.add(stepLabel);
        JPanel lowerLabelPanel = new JPanel(new BorderLayout());
        lowerLabelPanel.add(timeLabelPanel,BorderLayout.CENTER);
        lowerLabelPanel.add(stepLabelPanel,BorderLayout.SOUTH);



        mainLabelPanel.setBorder(new EmptyBorder(20,20,10,20));
        stepLabelPanel.setBorder(new EmptyBorder(20,20,20,20));
        JPanel upperPanel = new JPanel(new BorderLayout());
        upperPanel.add(mainLabelPanel,BorderLayout.CENTER);
        //upperPanel.add(timeLabelPanel,BorderLayout.SOUTH);
        globalPanel = new JPanel(new BorderLayout());
        globalPanel.add(upperPanel,BorderLayout.NORTH);
        globalPanel.add(pivotPanel,BorderLayout.CENTER);
        globalPanel.add(lowerLabelPanel,BorderLayout.SOUTH);
        this.getContentPane().add(globalPanel,BorderLayout.CENTER);
        this.setSize(width,height);

        this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                // If simulation is not terminated, avoid closing
                if (!stopped)
                    return;
                // TODO if stop action need an actionevent, modify this
                stopAction.actionPerformed(null);
                dispose();
            }
        });
        elapsedTime = 0;
    }

    public void initialize (int numberOfStep) {
        simulationTimes = new double[numberOfStep];
        this.numberOfSimulations = numberOfStep;
        progressBar.setMaximum(numberOfSimulations);
    }

    /**
     * Sets the running number of step
     * @param step the step to be run
     */
    public void setStepNumber(int step) {
        stepNumber = step;
        stepLabel.setText(CommonConstants.HTML_START + CommonConstants.HTML_FONT_NORM +
                                 ENUMERATION_MESSAGE + " " + stepNumber + " of " + this.numberOfSimulations + "..." +  CommonConstants.HTML_FONT_NOR_END + CommonConstants.HTML_END);
        progressBar.setValue(step-1);
        updateStatistics(step-1);
    }

    /**
     * Updates the showed elapsed time
     */
    public void updateTime() {
        elapsedTimeString = this.getTimeString((int)elapsedTime);
        elapsedTimeLabel.setText("Elapsed time: " + elapsedTimeString);
    }

    /**
     * This method updates all statistics related stuff. It contains a simple alghorithm to estimate residual execution time
     * @param lastSimulationCompletedIndex the index of the last finished simulation, beggining from 1.
     */
    private void updateStatistics(int lastSimulationCompletedIndex) {
        //it happens only at the beginning of simulation
        if (lastSimulationCompletedIndex == 0) return;

        // INITIALIZATIONS //

        //set the precision of residual time estimation
        double histogramIntervals = HISTOGRAM_INTERVALS;

⌨️ 快捷键说明

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