📄 numberofcustomerspanel.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.gui.common.panels.parametric;
import jmt.gui.common.definitions.parametric.NumberOfCustomerParametricAnalysis;
import jmt.gui.common.definitions.parametric.ParametricAnalysis;
import jmt.gui.common.definitions.ClassDefinition;
import jmt.gui.common.definitions.StationDefinition;
import jmt.gui.common.definitions.SimulationDefinition;
import jmt.gui.common.definitions.GuiInterface;
import jmt.gui.exact.table.ExactTable;
import jmt.gui.exact.table.ExactTableModel;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.border.TitledBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.util.Vector;
import java.text.DecimalFormat;
/**
* <p>Title: NumberOfCustomersPanel</p>
* <p>Description: this is the panel for the parametric analysis where the
* global number of customers is changed. It contains a nested class <code>PopulationVectorTable</code>
* used to show the population composition</p>
*
* @author Francesco D'Aquino
* Date: 9-mar-2006
* Time: 16.17.48
*/
public class NumberOfCustomersPanel extends ParameterOptionPanel {
private JRadioButton allClass;
private JRadioButton singleClass;
private JLabel fromLabel;
private JTextField from;
private JLabel toLabel;
private JSpinner to;
private JLabel stepsLabel;
private JSpinner steps;
private JLabel classChooserLabel;
private JComboBox classChooser;
private JScrollPane scroll;
private JTextArea description;
private JScrollPane descrPane;
private TitledBorder descriptionTitle;
private String DESCRIPTION_SINGLE;
private TablePanel tablePanel;
private JPanel globalEditPanel;
private NumberOfCustomerParametricAnalysis NCPA;
private GuiInterface gui;
public NumberOfCustomersPanel(NumberOfCustomerParametricAnalysis ncpa, ClassDefinition classDef, StationDefinition stationDef, SimulationDefinition simDef, GuiInterface guiInterface) {
super();
super.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
super.setDividerSize(3);
DESCRIPTION = "Repeat the simulation with different number of jobs in each iteration, " +
"starting from the current number of jobs in the close class.\n\n" +
"The proportion of the number of jobs in the different " +
"classes will be kept constant, so the number of steps that can be practically executed " +
"may be very small (since only integer values are allowed).";
DESCRIPTION_SINGLE = "Repeat the simulation with different number of jobs in each iteration, " +
"starting from the current number of jobs in the closed class, and increasing the number of jobs of" +
" selected class only.\n\n";
NCPA = ncpa;
cd = classDef;
sd = stationDef;
simd = simDef;
gui = guiInterface;
initialize();
}
public void initialize() {
JPanel radioButtonsPanel = new JPanel(new GridLayout(2,1));
allClass = new JRadioButton("Increase number of job of all closed classes");
allClass.setToolTipText("Increase population of all close classes");
singleClass = new JRadioButton("Increase number of job of one closed class");
singleClass.setToolTipText("Increase only population of one class");
ButtonGroup group = new ButtonGroup();
group.add(allClass);
group.add(singleClass);
radioButtonsPanel.add(allClass);
radioButtonsPanel.add(singleClass);
radioButtonsPanel.setBorder(new EmptyBorder(5,20,0,20));
if (cd.getClosedClassKeys().size() == 1) allClass.setEnabled(false);
JPanel edit = new JPanel(new GridLayout(4,1,0,5));
classChooserLabel = new JLabel("Class: ");
classChooser = new JComboBox();
classChooser.setToolTipText("Choose the class whose number of jobs will be incremented");
SpinnerNumberModel toModel;
int minTo;
if (NCPA.isSingleClass()) {
Vector classes = cd.getClosedClassKeys();
String[] classNames = new String[classes.size()];
for (int i=0; i<classes.size(); i++) classNames[i] = cd.getClassName(classes.get(i));
classChooser.removeAllItems();
for (int i=0;i<classNames.length;i++) classChooser.addItem(classNames[i]);
classChooser.setEnabled(true);
classChooser.setSelectedItem(cd.getClassName(NCPA.getReferenceClass()));
singleClass.setSelected(true);
allClass.setSelected(false);
//set the minimum final value
minTo = cd.getTotalCloseClassPopulation() + 1;
}
else {
classChooser.removeAllItems();
classChooser.addItem("All closed classes");
classChooser.setEnabled(false);
singleClass.setSelected(false);
allClass.setSelected(true);
// set the minimum final value.
if (cd.getClosedClassKeys().size() > 1) minTo = cd.getTotalCloseClassPopulation()*2 + 1;
else minTo = cd.getTotalCloseClassPopulation() + 1;
}
fromLabel = new JLabel("From N: ");
from = new JTextField();
from.setEnabled(false);
from.setText(Integer.toString((int)NCPA.getInitialValue()));
from.setBorder(new TitledBorder(""));
from.setBackground(Color.WHITE);
from.setAlignmentX(JTextField.EAST);
from.setToolTipText("To change number of jobs double click here");
toLabel = new JLabel("To N: ");
toModel = new SpinnerNumberModel((int)NCPA.getFinalValue(),minTo,Integer.MAX_VALUE,1);
to = new JSpinner(toModel);
to.setToolTipText("Set the final number of jobs");
stepsLabel = new JLabel("Steps (n. of exec.): ");
int maximumSteps = NCPA.searchForAvaibleSteps();
if (maximumSteps > ParametricAnalysis.MAX_STEP_NUMBER) maximumSteps = ParametricAnalysis.MAX_STEP_NUMBER;
steps = new JSpinner(new SpinnerNumberModel(NCPA.getNumberOfSteps(),2,maximumSteps,1));
steps.setToolTipText("Set the number of steps to be performed");
edit.add(fromLabel);
edit.add(from);
edit.add(toLabel);
edit.add(to);
edit.add(stepsLabel);
edit.add(steps);
edit.add(classChooserLabel);
edit.add(classChooser);
edit.setPreferredSize(new Dimension(130,88));
JPanel editLables = new JPanel (new GridLayout(4,1,0,5));
editLables.add(fromLabel);
editLables.add(toLabel);
editLables.add(stepsLabel);
editLables.add(classChooserLabel);
editLables.setPreferredSize(new Dimension(100,88));
JPanel editPanel = new JPanel();
editPanel.add(editLables);
editPanel.add(edit);
editPanel.setBorder(new EmptyBorder(10,0,0,10));
//Create values table and add to JScrollPane
tablePanel = new TablePanel();
//tablePanel.setBorder(new EmptyBorder(15,0,0,0));
globalEditPanel = new JPanel(new BorderLayout());
globalEditPanel.add(tablePanel,BorderLayout.CENTER);
globalEditPanel.add(editPanel,BorderLayout.NORTH);
JPanel cont = new JPanel(new BorderLayout());
cont.add(radioButtonsPanel,BorderLayout.NORTH);
cont.add(globalEditPanel,BorderLayout.CENTER);
scroll = new JScrollPane(cont);
title = new TitledBorder("Type of population growth");
scroll.setBorder(title);
description = new JTextArea();
if (NCPA.isSingleClass()) description.setText(DESCRIPTION_SINGLE);
else description.setText(DESCRIPTION);
description.setOpaque(false);
description.setEditable(false);
description.setLineWrap(true);
description.setWrapStyleWord(true);
descrPane = new JScrollPane(description);
descriptionTitle = new TitledBorder(new EtchedBorder(), "Description");
descrPane.setBorder(descriptionTitle);
descrPane.setMinimumSize(new Dimension(80,0));
scroll.setMinimumSize(new Dimension(360,0));
setLeftComponent(scroll);
setRightComponent(descrPane);
setListeners();
this.setBorder(new EmptyBorder(5,0,5,0));
}
/*private String getTextForPop() {
String text = "<html>";
text += cd.getTotalCloseClassPopulation() + " (";
Vector classes = cd.getClosedClassKeys();
for (int i=0; i<classes.size(); i++) {
Object thisClass = classes.get(i);
int n = cd.getClassPopulation(classes.get(i)).intValue();
if ((NCPA.isSingleClass()) && (thisClass == NCPA.getReferenceClass())) {
text += "<font color=\"blue\">" + n + "</font>";
}
else {
text += n;
}
if (i != classes.size()-1) text+=",";
}
text += ")</html>";
return text;
}*/
public void setEnabled(boolean enabled) {
if (cd.getClosedClassKeys().size() == 1) allClass.setEnabled(false);
else allClass.setEnabled(enabled);
singleClass.setEnabled(enabled);
fromLabel.setEnabled(enabled);
from.setEnabled(false);
toLabel.setEnabled(enabled);
to.setEnabled(enabled);
stepsLabel.setEnabled(enabled);
steps.setEnabled(enabled);
classChooserLabel.setEnabled(enabled);
description.setEnabled(enabled);
if (!enabled) {
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
descrPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
}
else {
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
descrPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
}
if (!enabled) classChooser.setEnabled(enabled);
else if (singleClass.isSelected()) classChooser.setEnabled(enabled);
if (!enabled) {
title.setTitleColor(Color.LIGHT_GRAY);
descriptionTitle.setTitleColor(Color.LIGHT_GRAY);
globalEditPanel.remove(tablePanel);
globalEditPanel.doLayout();
globalEditPanel.validate();
}
else {
title.setTitleColor(DEFAULT_TITLE_COLOR);
descriptionTitle.setTitleColor(DEFAULT_TITLE_COLOR);
tablePanel = new TablePanel();
//tablePanel.setBorder(new EmptyBorder(15,0,0,0));
globalEditPanel.add(tablePanel,BorderLayout.CENTER);
globalEditPanel.doLayout();
globalEditPanel.validate();
}
}
private void setListeners() {
from.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
gui.showClassPanel();
}
}
});
singleClass.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
NCPA.setSingleClass(true);
classChooser.setEnabled(true);
ItemListener listener = classChooser.getItemListeners()[0];
classChooser.removeItemListener(listener);
classChooser.removeAllItems();
Vector classes = cd.getClosedClassKeys();
String[] classNames = new String[classes.size()];
for (int i=0; i<classes.size(); i++) classNames[i] = cd.getClassName(classes.get(i));
for (int i=0;i<classNames.length;i++) classChooser.addItem(classNames[i]);
classChooser.addItemListener(listener);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -