📄 whatifpanel.java
字号:
updateType();
}
});
help.addHelp(type, "Select control parameter for what-if analysis. If no parameter is selected, analysis is disabled.");
paramPanel.add(type);
// Station name
stationLabel = new JLabel("Station :", JLabel.RIGHT);
paramPanel.add(stationLabel);
stationName = new JComboBox();
stationName.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
updateLabels(false);
}
});
help.addHelp(stationName, "Select at which station service demand should be modified.");
paramPanel.add(stationName);
// Class Name
classLabel = new JLabel("Class :", JLabel.RIGHT);
paramPanel.add(classLabel);
className = new JComboBox(new String[]{ALL_CLASSES});
className.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
updateLabels(false);
}
});
help.addHelp(className, "Select reference class for current analysis. All classes can be selected too.");
paramPanel.add(className);
// From field
fromLabel = new JLabel("From :", JLabel.RIGHT);
paramPanel.add(fromLabel);
from = new JTextField();
from.addKeyListener(listener);
from.addFocusListener(listener);
help.addHelp(from, "Initial value for what-if analysis. This is actual value.");
paramPanel.add(from);
// To field
toLabel = new JLabel("To :", JLabel.RIGHT);
paramPanel.add(toLabel);
to = new JTextField();
to.addKeyListener(listener);
to.addFocusListener(listener);
help.addHelp(to, "Specify final value for what-if analysis (default value is 200% of actual value)");
paramPanel.add(to);
// Iteration number field
iterationLabel = new JLabel("Steps (n. of executions) :", JLabel.RIGHT);
paramPanel.add(iterationLabel);
iterations = new JTextField();
iterations.addKeyListener(listener);
iterations.addFocusListener(listener);
help.addHelp(iterations, "Specify number of executions to be performed (default value is 11)");
paramPanel.add(iterations);
JPanel tmpPanel = new JPanel(new BorderLayout()); // Used to pack fields
tmpPanel.add(paramPanel, BorderLayout.NORTH);
add(tmpPanel, BorderLayout.CENTER);
// Adds class table
classTable = new ClassTable();
help.addHelp(classTable, "Classes characteristics. Values in red are currently selected for what-if analysis.");
tablePanel = new JPanel(new BorderLayout());
tablePanel.add(classTable);
tablePanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
tablePanel.setVisible(false);
add(tablePanel, BorderLayout.SOUTH);
}
/**
* This method is called each time what-if analysis type is changed
*/
private void updateType() {
String parameter = (String)type.getSelectedItem();
if (currentType != null && currentType.equalsIgnoreCase(parameter))
return;
// If an unavailable mode is selected, select previous one
if (currentType != null && !modes.contains(parameter)) {
type.setSelectedItem(currentType);
return;
}
// Stores old selected class
String selClassName = (String) className.getSelectedItem();
if (parameter == null || parameter.equals(NO_ANALYSIS)) {
description.setText(DESCRIPTION_WHATIF_NONE);
// Hide all components
stationLabel.setVisible(false);
stationName.setVisible(false);
classLabel.setVisible(false);
className.setVisible(false);
fromLabel.setVisible(false);
from.setVisible(false);
toLabel.setVisible(false);
to.setVisible(false);
iterationLabel.setVisible(false);
iterations.setVisible(false);
tablePanel.setVisible(false);
}
else {
// Shows nearly all components (except station)
stationLabel.setVisible(false);
stationName.setVisible(false);
classLabel.setVisible(true);
className.setVisible(true);
fromLabel.setVisible(true);
from.setVisible(true);
toLabel.setVisible(true);
to.setVisible(true);
iterationLabel.setVisible(true);
iterations.setVisible(true);
tablePanel.setVisible(true);
// Disables from field
from.setEnabled(false);
Iterator it;
// Default help for 'from' and 'to' values (only changes for population mix)
help.removeHelp(from);
help.addHelp(from, "Initial value for what-if analysis. This is actual value.");
help.removeHelp(to);
help.addHelp(to, "Specify final value for what-if analysis (default value is 200% of actual value)");
if (parameter.equals(WHAT_IF_ARRIVAL)) {
// Sets open classes for selection
className.removeAllItems();
it = openClassNames.keySet().iterator();
while(it.hasNext())
className.addItem(it.next());
// Removes 'ALL_CLASS' if only a single open class was found
if (openClassNames.size() == 2)
className.removeItem(ALL_CLASSES);
className.setSelectedItem(selClassName);
// Shows correct help on item
help.removeHelp(classTable);
help.addHelp(classTable, "Initial arrival rates. Values in red are currently selected for what-if analysis.");
}
else if (parameter.equals(WHAT_IF_CUSTOMERS)) {
// Sets closed class for selection
className.removeAllItems();
it = closedClassNames.keySet().iterator();
while(it.hasNext())
className.addItem(it.next());
// Removes 'ALL_CLASS' if only a single closed class was found
if (closedClassNames.size() == 2)
className.removeItem(ALL_CLASSES);
className.setSelectedItem(selClassName);
// Shows correct help on item
help.removeHelp(classTable);
help.addHelp(classTable, "Initial number of customers and population mix values (\u03b2i = Ni / N). Values in red are currently selected for what-if analysis.");
}
else if (parameter.equals(WHAT_IF_MIX)) {
// Enables 'from' field
from.setEnabled(true);
// Sets the two closed class for selection
className.removeAllItems();
it = closedClassNames.keySet().iterator();
while(it.hasNext())
className.addItem(it.next());
className.removeItem(ALL_CLASSES);
className.setSelectedItem(selClassName);
// Shows correct help on item
help.removeHelp(classTable);
help.addHelp(classTable, "Initial number of customers and population mix values (\u03b2i = Ni / N). Values in red are currently selected for what-if analysis.");
help.removeHelp(from);
help.addHelp(from, "Initial value corresponding to an integer, not null, number of customers.");
help.removeHelp(to);
help.addHelp(to, "Final value corresponding to an integer, not null, number of customers.");
}
else if (parameter.equals(WHAT_IF_DEMANDS)) {
stationLabel.setVisible(true);
stationName.setVisible(true);
// Sets all classes for selection
className.removeAllItems();
it = classNames.keySet().iterator();
while(it.hasNext())
className.addItem(it.next());
// Removes 'ALL_CLASS' if only a single class was found
if (classNames.size() == 2)
className.removeItem(ALL_CLASSES);
className.setSelectedItem(selClassName);
// Sets all non-ld stations for selection
stationName.removeAllItems();
it = stationNames.keySet().iterator();
while(it.hasNext())
stationName.addItem(it.next());
stationName.setSelectedIndex(0);
// Shows correct help on item
help.removeHelp(classTable);
help.addHelp(classTable, "Initial service demands. Values in red are currently selected for what-if analysis.");
}
updateLabels(true);
}
currentType = parameter;
}
/**
* This method is called each time selected class is changed
* @param changedType tells if type of what-if analysis was changed too.
*/
private void updateLabels(boolean changedType) {
String selType = (String)type.getSelectedItem();
if (changedType || (currentClass != null && className.getSelectedItem() != null)) {
if (className.getSelectedItem().equals(ALL_CLASSES)) {
fromLabel.setText(FROM_ALL);
toLabel.setText(TO_ALL);
values = new double[] {1.0, 2.0};
current = 1.0;
// Sets the correct description
if (selType.equals(WHAT_IF_ARRIVAL))
description.setText(DESCRIPTION_WHATIF_ARRIVAL_ALL);
else if (selType.equals(WHAT_IF_CUSTOMERS))
description.setText(DESCRIPTION_WHATIF_CUSTOMERS_ALL);
else if (selType.equals(WHAT_IF_DEMANDS))
description.setText(DESCRIPTION_WHATIF_DEMANDS_ALL);
}
else {
// Finds selected values
int selClass = ((Integer)classNames.get(className.getSelectedItem())).intValue();
int selStation;
Object st = stationName.getSelectedItem();
if (st != null)
selStation = ((Integer)stationNames.get(st)).intValue();
else
selStation = 0;
if (selType.equals(ExactModel.WHAT_IF_DEMANDS)) {
description.setText(DESCRIPTION_WHATIF_DEMANDS_ONE);
fromLabel.setText(FROM_DEMANDS);
toLabel.setText(TO_DEMANDS);
// Finds current service demand for selected station
current = data.getServiceTimes()[selStation][selClass][0] * data.getVisits()[selStation][selClass];
if (current <= 0)
current = 1.0;
values = new double[] {current, current*2};
}
else if (selType.equals(ExactModel.WHAT_IF_ARRIVAL)) {
description.setText(DESCRIPTION_WHATIF_ARRIVAL_ONE);
fromLabel.setText(FROM_ARRIVAL);
toLabel.setText(TO_ARRIVAL);
// Finds current arrival rate for selected class
current = data.getClassData()[selClass];
if (current <= 0)
current = 1.0;
values = new double[] {current, current*2};
}
else if (selType.equals(ExactModel.WHAT_IF_CUSTOMERS)) {
description.setText(DESCRIPTION_WHATIF_CUSTOMERS_ONE);
fromLabel.setText(FROM_CUSTOMERS);
toLabel.setText(TO_CUSTOMERS);
// Finds current number of customers for selected class
current = data.getClassData()[selClass];
if (current <= 0)
current = 1.0;
values = new double[] {current, current*2};
}
else if (selType.equals(ExactModel.WHAT_IF_MIX)) {
description.setText(DESCRIPTION_WHATIF_MIX);
fromLabel.setText(FROM_MIX);
toLabel.setText(TO_MIX);
values = new double[] {0.0, 1.0};
current = 0.0;
}
}
// Shows new values
setFromToIterations();
iterations.setText("11");
updateFields();
// Updates classTable
classTable.update();
}
currentClass = (String)className.getSelectedItem();
}
/**
* This function is called each time from, to or iterations field is changed.
*/
private void updateFields() {
String type = (String)this.type.getSelectedItem();
double from = current;
// From field is 'current' value if parsing fails.
try {
from = Double.parseDouble(this.from.getText());
if (from < 0)
from = 0.0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -