📄 mmqueues.java
字号:
/**
* 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.jmarkov;
import com.jgoodies.looks.Options;
import jmt.gui.common.panels.AboutDialogFactory;
import jmt.gui.common.Manager;
import jmt.jmarkov.Graphics.*;
import jmt.jmarkov.Graphics.constants.DrawBig;
import jmt.jmarkov.Graphics.constants.DrawConstrains;
import jmt.jmarkov.Graphics.constants.DrawNormal;
import jmt.jmarkov.Graphics.constants.DrawSmall;
import jmt.jmarkov.Queues.*;
import jmt.jmarkov.Queues.Exceptions.NonErgodicException;
import jmt.jmarkov.utils.Formatter;
import javax.help.HelpSet;
import javax.help.JHelp;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;
import java.util.Dictionary;
import java.util.Enumeration;
public class MMQueues extends JFrame implements Runnable {
//NEW
//@author Stefano Omini
// introduced DEBUG var to skip System.out.println() calls in final release
private static final boolean DEBUG = false;
//end NEW
private JLabel accelerationL;
private BoundedRangeModel brm;
private TitledBorder tb;
private boolean nonErgodic;
private Dimension initSize = new Dimension(800, 600);
private double U; //Utilizzo [%]
private double Q; //Numero medio di jobs
private int buffer;
private double timemultiplier = 1.0;
private JPanel sPanel;
private JPanel lambdaPanel;
private JSlider sS;
private JSlider lambdaS;
private double sMultiplier = 1;
private boolean paused = false;
private JButton pauseB;
private QueueDrawer queueDrawer;
private StatiDrawer statiDrawer;
private JobsDrawer jobsDrawer;
private JEditorPane helpEP;
private JComboBox topicCB;
private JPanel helpP;
private JTabbedPane outputTabP;
private JScrollPane txtScroll;
private TANotifier outputTA;
private Notifier[] tan = new Notifier[4];
public JButton stopB;
private JPanel buttonsP;
private JButton playB;
private JTextField utilizationT;
private JTextField mediaJobsT;
private JPanel resultsP;
private JPanel SimulationValuesP;
public JFrame mf;
private JPanel outputP;
private JPanel parametersP;
private JPanel simulationP;
private JSlider buffS = new JSlider();
private JPanel buffPanel = new JPanel();
private JPanel accelerationP = new JPanel();
private JPanel jobsP = new JPanel();
private JSlider accelerationS = new JSlider();
private MMQueues mmqueue;
//Label & Label strings
private JLabel
sL,
lambdaL,
mediaJobsL,
utilizationL,
buffL,
thrL,
responseL;
private String
sStrS = "Avg. Service Time (S): ",
sStrE = " s",
//OLD
//lambdaStrS = "Avg. Arrival Time (l): ",
//NEW
//@author Stefano Omini
//lambda is an arrival RATE, not an arrival TIME !
lambdaStrS = "Avg. Arrival Rate (l): ",
//end NEW
lambdaStrE = " job/s",
nStrS = "Avg. Queue Lenght (Q): ",
nStrE = " jobs",
uStrS = "Avg. Utilization (U): ",
uStrE = "",
bufStrS = "Buffer Size: ",
bufStrE = " jobs",
thrStrS = "Avg. Throughput: ",
thrStrE = " job/s",
respStrS = "Avg. Response Time (R): ",
respStrE = " s";
//Settings
private Color emptyC = Color.WHITE,
probC = Color.GREEN,
queueC = Color.BLUE,
animC = Color.RED;
private boolean gradientF = false;
private DrawConstrains dCst = new DrawNormal();
private int BUFF_I = 16,
LAMBDA_I = 20,
S_I = 190;
//menu
private JMenuBar menuB;
//help
private JMenu helpMenu;
private JMenuItem helpMenuItem;
//queue
private JMenu queueMenu;
private JRadioButtonMenuItem MM1Item, MM1dItem, gradientItem;
private JMenuItem exitMenuItem;
//settings
private JMenu settingsMenu;
//colors
private JMenu colorsMenu;
private JMenuItem queueColorItem;
private JMenuItem queueFillColorItem;
private JMenuItem statusColorItem;
private JMenuItem statusFillColorItem;
//size
private JMenu sizeMenu;
private JMenuItem drawSmallItem;
private JMenuItem drawNormalItem;
private JMenuItem drawBigItem;
//l&f
private JMenu plafMenu;
private static String[] plafURIA = {"com.jgoodies.looks.plastic.Plastic3DLookAndFeel",
"com.digitprop.tonic.TonicLookAndFeel",
"com.incors.plaf.kunststoff.KunststoffLookAndFeel",
"com.jgoodies.looks.plastic.PlasticXPLookAndFeel",
"com.oyoaha.swing.plaf.oyoaha.OyoahaLookAndFeel",
"com.shfarr.ui.plaf.fh.FhLookAndFeel",
"com.stefankrause.xplookandfeel.XPLookAndFeel",
"net.beeger.squareness.SquarenessLookAndFeel",
"net.sourceforge.mlf.metouia.MetouiaLookAndFeel"};
private static String[] plafName = {"Plastic",
"Tonic",
"Kunststoff",
"PlasticXP",
"Oyoaha",
"FH",
"XP",
"Squareness",
"Metouia"};
private JMenuItem[] plafItem = new JMenuItem[plafName.length];
private int plafcounter = 0;
//Queues data:
MM1Logic ql = new MM1Logic(0.0,0.0);
QueueStack qs;
Thread at, pt, qD, sD, jD, logT, mft;
Arrivals arrival;
Processor cpu;
public MMQueues() {
mf = this;
mmqueue = this;
initGUI();
}
protected void initGUI() {
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
this.setLocation((screenSize.width - initSize.width)/2, (screenSize.height - initSize.height)/2);
try {
// Simulation data panel
simulationP = new JPanel();
SimulationValuesP = new JPanel();
parametersP = new JPanel();
lambdaPanel = new JPanel();
lambdaL = new JLabel();
lambdaS = new JSlider();
sPanel = new JPanel();
sS = new JSlider();
resultsP = new JPanel();
mediaJobsL = new JLabel();
mediaJobsT = new JTextField();
utilizationL = new JLabel();
utilizationT = new JTextField();
mediaJobsL = new JLabel();
thrL = new JLabel();
responseL = new JLabel();
// simulation output panels
outputP = new JPanel();
outputTabP = new JTabbedPane();
txtScroll = new JScrollPane();
outputTA = new TANotifier();
//logD = new LogDrawer();
statiDrawer = new StatiDrawer(ql);
queueDrawer = new QueueDrawer(ql);
jobsDrawer = new JobsDrawer();
// acceleration
accelerationP.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 0;
accelerationP.setBorder(addTitle("Simulation time", dCst.getSmallGUIFont()));
accelerationL = new JLabel("Time x0.0");
accelerationL.setFont(dCst.getNormalGUIFont());
accelerationL.setHorizontalAlignment(JLabel.CENTER);
accelerationP.add(accelerationL,gbc);
accelerationS.setValue(50);
accelerationS.setMaximum(100);
accelerationS.setMinimum(1);
accelerationS.setMajorTickSpacing(50);
accelerationS.setMinorTickSpacing(1);
accelerationS.setSnapToTicks(true);
accelerationS.setPaintTicks(true);
accelerationS.setPaintLabels(true);
Dictionary ad = accelerationS.getLabelTable();
Enumeration k = ad.keys();
ad.put(new Integer(1), new JLabel("real time"));
ad.put(new Integer(51), new JLabel("faster"));
ad.put(new Integer(100), new JLabel("fastest"));
accelerationS.setLabelTable(ad);
gbc.gridy = 1;
gbc.weightx = 1;
accelerationP.add(accelerationS,gbc);
accelerationS.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
ql.setTimeMultiplier(accelerationS.getValue());
accelerationL.setText("Time x" + Formatter.formatNumber(ql.getTimeMultiplier(), 2));
}
});
ql.setTimeMultiplier(accelerationS.getValue());
accelerationL.setText("Time x" + Formatter.formatNumber(ql.getTimeMultiplier(), 2));
// jobs panel
jobsP.setBorder(addTitle("Jobs", dCst.getSmallGUIFont()));
jobsP.setLayout(new GridLayout(1,1));
jobsP.add(jobsDrawer);
// buttons
buttonsP = new JPanel();
playB = new JButton();
stopB = new JButton();
pauseB = new JButton();
//Adding to main frame
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
this.getContentPane().setLayout(new BorderLayout());
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
/**
* Invoked when a window has been closed.
*/
public void windowClosed(WindowEvent e) {
Manager.exit(MMQueues.this);
}
});
//OLD
//this.setTitle("MMQueues");
//NEW
//@author Stefano Omini
this.setTitle("jMCH - Markov Chain");
this.setIconImage(jmt.gui.common.resources.ImageLoader.loadImage("JMCHIcon").getImage());
//end NEW
this.setSize(new java.awt.Dimension(initSize.width, initSize.height));
simulationP.setLayout(new GridBagLayout());
this.getContentPane().add(simulationP,BorderLayout.CENTER);
parametersP.setLayout(new GridBagLayout());
parametersP.setBorder(addTitle("Simulation Parameters", dCst.getSmallGUIFont()));
c.weightx = 1;
c.weighty = 0;
c.gridx = 0;
c.gridy = 0;
simulationP.add(parametersP, c);
// lambda
lambdaPanel.setLayout(new GridLayout(2,1));
c.weightx = 0.5;
parametersP.add(lambdaPanel,c);
lambdaL.setAlignmentX(JLabel.CENTER);
lambdaPanel.add(lambdaL);
lambdaS.setMaximum(300);
lambdaS.setMinimum(0);
lambdaS.setMajorTickSpacing(50);
lambdaS.setMinorTickSpacing(1);
lambdaS.setPaintLabels(true);
lambdaS.setSnapToTicks(true);
lambdaPanel.add(lambdaS);
lambdaL.setFont(dCst.getNormalGUIFont());
lambdaS.setValue(LAMBDA_I);
setLambdaSlider();
lambdaS.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
lambdaSStateChanged(evt);
}
});
lambdaS.repaint();
// S slider
sPanel.setLayout(new GridLayout(2,1));
c.gridx = 1;
parametersP.add(sPanel,c);
sL = new JLabel();
sL.setAlignmentX(JLabel.CENTER);
sPanel.add(sL);
sS.setMaximum(200);
sS.setMinimum(0);
sS.setMajorTickSpacing(50);
sS.setMinorTickSpacing(1);
sS.setPaintLabels(true);
sL.setFont(dCst.getNormalGUIFont());
/*Dictionary d = sS.getLabelTable();
for(int i = 0; i < 6; i++){
d.put(new Integer(i * 50), new JLabel("" + i * 0.5));
}
sS.setLabelTable(d);
sL.setFont(dCst.getNormalGUIFont());
sL.setText(sStrS + Formatter.formatNumber(sS.getValue() * 0.005 * sMultiplier,2) + sStrE);*/
sPanel.add(sS);
sS.setValue(S_I);
setSSlider();
sS.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
sSStateChanged(evt);
}
});
// queueBuffer slider
buffPanel.setLayout(new GridLayout(2,1));
c.gridx = 2;
buffPanel.setVisible(false);
parametersP.add(buffPanel,c);
buffL = new JLabel();
buffL.setAlignmentX(JLabel.CENTER);
buffL.setFont(dCst.getNormalGUIFont());
buffPanel.add(buffL);
buffS.setValue(BUFF_I);
buffS.setMaximum(20);
buffS.setMinimum(0);
buffS.setMajorTickSpacing(5);
buffS.setMinorTickSpacing(1);
buffS.setPaintLabels(true);
buffS.setPaintTicks(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -