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

📄 resultswindow.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.definitions.AbortMeasure;
import jmt.gui.common.definitions.MeasureDefinition;
import jmt.gui.common.definitions.ResultsConstants;
import jmt.gui.common.layouts.SpringUtilities;
import jmt.gui.common.resources.ImageLoader;
import jmt.gui.common.util.FastGraph;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.util.Vector;

/**
 * <p>Title: Results Window</p>
 * <p>Description: Window to show simulation results.</p>
 * 
 * @author Bertoli Marco
 *         Date: 22-set-2005
 *         Time: 15.10.52
 */
public class ResultsWindow extends JFrame implements ResultsConstants{
    private MeasureDefinition results;
    private AbortMeasure abort;
    private JButton start, stop, pause;
    private JProgressBar progressBar;
    // Used to format numbers
    private static DecimalFormat decimalFormatExp = new DecimalFormat("0.000E0");
    private static DecimalFormat decimalFormatNorm = new DecimalFormat("#0.0000");


    /**
     * Creates a new ResultsWindow
     * @param results results data structure
     */
    public ResultsWindow(MeasureDefinition results) {
        this.results = results;
        initGUI();
    }
    /**
     * Creates a new ResultsWindow
     * @param results results data structure
     * @param abort object used to implement abort button action
     */
    public ResultsWindow(MeasureDefinition results, AbortMeasure abort) {
        this.results = results;
        this.abort = abort;
        initGUI();
    }

    /**
     * Initialize allgui related stuff
     */
    private void initGUI() {
        // Sets default title, close operation and dimensions
        this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
        this.setTitle("Simulation Results...");
        this.setIconImage(ImageLoader.loadImage("Results").getImage());
        int width = 800, height=500;

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

        // Creates all tabs
        JTabbedPane mainPanel = new JTabbedPane();
        this.getContentPane().setLayout(new BorderLayout());
        this.getContentPane().add(mainPanel, BorderLayout.CENTER);
        addTabPane(mainPanel, "Queue Length", DESCRIPTION_QUEUELENGTHS, results.getQueueLengthMeasures());
        addTabPane(mainPanel, "Queue Time", DESCRIPTION_QUEUETIMES, results.getQueueTimeMeasures());
        addTabPane(mainPanel, "Residence Time", DESCRIPTION_RESIDENCETIMES, results.getResidenceTimeMeasures());
        addTabPane(mainPanel, "Response Time", DESCRIPTION_RESPONSETIMES, results.getResponseTimeMeasures());
        addTabPane(mainPanel, "Utilization", DESCRIPTION_UTILIZATIONS, results.getUtilizationMeasures());
        addTabPane(mainPanel, "Throughput", DESCRIPTION_THROUGHPUTS, results.getThroughputMeasures());
        addTabPane(mainPanel, "System Response Time", DESCRIPTION_SYSTEMRESPONSETIMES, results.getSystemResponseTimeMeasures());
        addTabPane(mainPanel, "System Throughput", DESCRIPTION_SYSTEMTHROUGHPUTS, results.getSystemThroughputMeasures());
        addTabPane(mainPanel, "Customer Number", DESCRIPTION_CUSTOMERNUMBERS, results.getCustomerNumberMeasures());

        // Creates bottom toolbar
        JToolBar toolbar = new JToolBar();
        toolbar.setFloatable(false);
        toolbar.setRollover(true);
        start = new JButton();
        toolbar.add(start);
        start.setVisible(false);
        pause = new JButton();
        toolbar.add(pause);
        pause.setVisible(false);
        stop = new JButton();
        toolbar.add(stop);
        stop.setVisible(false);
        // Adds a progress bar
        progressBar = new JProgressBar();
        progressBar.setStringPainted(true);
        progressBar.setForeground(Color.BLUE);
        setProgressBar(results.getProgressTime());
        toolbar.add(progressBar);
        // Add close window button
        JButton close = new JButton();
        close.setIcon(ImageLoader.loadImage("Close"));
        close.setFocusPainted(false);
        close.setContentAreaFilled(false);
        close.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        close.setRolloverIcon(ImageLoader.loadImage("CloseRO"));
        close.setPressedIcon(ImageLoader.loadImage("CloseP"));
        close.setVisible(true);
        close.setToolTipText("Closes this window");
        close.addActionListener(new ActionListener() {
            // Fires a window closing event
            public void actionPerformed(ActionEvent e) {
                ResultsWindow.this.dispatchEvent(
                        new WindowEvent(ResultsWindow.this, WindowEvent.WINDOW_CLOSING));
            }
        });

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

        // Adds listener for progressBar
        results.setProgressTimeListener(new MeasureDefinition.ProgressTimeListener () {
            public void timeChanged(double time) {
                setProgressBar(time);
            }
        });


    }

    /**
     * Sets progress bar to specified value
     * @param percent value. Must be between 0 included and 1 included
     */
    private void setProgressBar(double percent) {
        int progress = (int)Math.round(percent * 100);
        progressBar.setValue(progress);
        if (progress < 100)
            progressBar.setString(progress+"% of simulation performed...");
        else
            progressBar.setString("Simulation Complete");
    }

    /**
     * Sets action for toolbar buttons and displays them
     * @param startAction action associated with start simulation button
     * @param pauseAction action associated with pause simulation button
     * @param stopAction action associated with stop simulation button
     */
    public void addButtonActions(AbstractAction startAction, AbstractAction pauseAction, AbstractAction stopAction) {
        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);
    }

    /**
     * Creates a new tabbed pane that shows specified measures and adds it to
     * specified JTabPane. If measures indexes vector is null or empty no panel is added.
     * @param parent panel where newly created tab should be added
     * @param name name of the panel to be added
     * @param description description to be shown into the panel
     * @param indexes array with all measures indexes to be shown in this panel
     */
    private void addTabPane(JTabbedPane parent, String name, String description,int []indexes) {
        // If no measure are present, don't add corresponding tab
        if (indexes != null && indexes.length > 0) {
            JPanel tabPanel = new JPanel(new BorderLayout());
            // Adds margins
            tabPanel.add(Box.createVerticalStrut(BORDERSIZE), BorderLayout.NORTH);
            tabPanel.add(Box.createVerticalStrut(BORDERSIZE), BorderLayout.SOUTH);
            tabPanel.add(Box.createHorizontalStrut(BORDERSIZE), BorderLayout.WEST);
            tabPanel.add(Box.createHorizontalStrut(BORDERSIZE), BorderLayout.EAST);
            JPanel mainpanel = new JPanel(new BorderLayout());
            tabPanel.add(mainpanel, BorderLayout.CENTER);
            // Adds tab description
            JPanel upperPanel = new JPanel(new BorderLayout());
            JLabel descrLabel = new JLabel(description);
            upperPanel.add(descrLabel, BorderLayout.NORTH);
            upperPanel.add(Box.createVerticalStrut(BORDERSIZE / 2), BorderLayout.SOUTH);
            mainpanel.add(upperPanel, BorderLayout.NORTH);
            // Adds panel with measures
            JPanel scroll = new JPanel(new GridLayout(indexes.length, 1,1,1));
            // Adds all measures to this panel
            for (int i=0; i<indexes.length; i++)
                scroll.add(new MeasurePanel(results, indexes[i]));
            mainpanel.add(new JScrollPane(scroll), BorderLayout.CENTER);

            // Adds tab to parent tabbed pane
            parent.addTab(name, tabPanel);
        }
    }

    /**
     * Helper method used to convert a double into a String avoiding too many decimals
     * @param d number to be converted
     * @return string rappresentation of input number
     */
    protected static String doubleToString(double d) {
        double abs = (d >= 0)? d : -d;
        if (abs == 0)
            return "0.0";
        else if (abs > 1e4 || abs < 1e-2)
            return decimalFormatExp.format(d);
        else
            return decimalFormatNorm.format(d);
    }

    /**
     * Inner class to create a panel that holds a specified measure
     */
    protected class MeasurePanel extends JPanel{
        protected MeasureDefinition md;
        protected int measureIndex;
        protected JLabel icon;
        protected Vector values;

⌨️ 快捷键说明

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