📄 mediator.java
字号:
/**
* Stops current simulation, aborting all measures
*
* Author: Bertoli Marco
*/
public void stopSimulation() {
if(stopSimulation.isEnabled()) {
if (!model.isParametricAnalysisEnabled()) dispatcher.stopSimulation();
else {
batchThread.stopSimulation();
}
}
}
/**
* Pauses current simulation
*
* Author: Bertoli Marco
*
* Modified by Francesco D'Aquino
*/
public void pauseSimulation() {
if (model.isParametricAnalysisEnabled()) {
batchThread.pauseSimulation();
}
else dispatcher.pauseSimulation();
}
/**
* Changes simulation action status. This method is called by DispatcherThread.
* @param start state for start action
* @param pause state for pause action
* @param stop state for stop action
*/
public void changeSimActionsState(boolean start, boolean pause, boolean stop){
simulate.setEnabled(start);
stopSimulation.setEnabled(stop);
pauseSimulation.setEnabled(pause);
}
/////////////////////////////////////////////
// METHODS THAT MANAGE MEASURES
/**
* Launches the <code>Measure</code> editor.
* Author: Bertoli Marco
*/
public void editMeasures() {
DialogFactory.getDialog(new MeasurePanel(model, model, model), "Define performance indices");
}
/**
* @return A refernce to the action <code>EditMeasures</code>.
*/
public AbstractJmtAction getEditMeasures() {
return editMeasures;
}
/////////////////////////////////////////////
/**
* Checks if there's an old graph to save. This methods is called when creates/closes/opens a graph.
* @param msg The message to display.
* @return <code>true</code> - whether the user accepts to save the graph, or he cancels the current action.
*/
public boolean checkForSave(String msg) {
// Checks if there's an old graph to save
if (model != null && model.toBeSaved()) {
int resultValue = JOptionPane.showConfirmDialog(mainWindow,
msg,
"JMODEL - Warning",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (resultValue == JOptionPane.YES_OPTION) {
saveModel();
return false;
}
if (resultValue == JOptionPane.CANCEL_OPTION) {
return true;
}
}
return false;
}
/**
* @return A refernce to the action <code>SwitchToExactSolver</code>.
*/
public AbstractJmtAction getSwitchToWizard() {
return switchToExactSolver;
}
/**
* Disposes the main application.
*/
public void disposeApplication() {
mainWindow.dispose();
}
// 13/10/03 - end /////////////////////////////////////////////////////
public Cursor getOldCursor() {
return oldCursor;
}
public void setOldCursor(Cursor oldCursor) {
this.oldCursor = oldCursor;
}
public void setCursor(Cursor cursor) {
oldCursor = this.cursor;
this.cursor = cursor;
setGraphCursor(cursor);
}
// --- Bertoli Marco ---------------------
/**
* Sends an exit signal to main window
*/
public void exit() {
// Send a closing signat to main window.
mainWindow.dispatchEvent(new WindowEvent(mainWindow, WindowEvent.WINDOW_CLOSING));
}
/**
* Shows a DefaultEditor to edit Defaults parameters
*/
public void showDefaultsEditor() {
DefaultsEditor.getInstance(mainWindow, DefaultsEditor.JMODEL).show();
}
/**
* Used to reset mouseListener to default (to avoid File_Save / File_New
* operations while in inserting mode)
*/
public void resetMouseState() {
mouseListner.setDefaultState();
mainWindow.getComponentBar().unsetAll();
if (graph != null)
setGraphCursor(Cursor.getDefaultCursor());
}
/**
* Returns true iff specified cell is editable. This is used by <code>SelectState</code>
* to check if editor has to be showed upon double click event.
* @param cell specified cell
* @return true iff cell is editable
*/
public boolean isCellEditable(Object cell) {
return cell instanceof JmtCell || cell instanceof BlockingRegion;
}
/**
* Shows a panel with catched exception
* @param e exception to be shown
*/
public void handleException(Exception e){
e.printStackTrace();
showErrorMessage(e.getMessage());
}
/**
* Shows a panel with an error message
* @param message specified error message
*/
public synchronized void showErrorMessage(String message){
Component parent = mainWindow;
if (resultsWindow != null && resultsWindow.hasFocus())
parent = resultsWindow;
JOptionPane.showMessageDialog(parent, message,
"Error", JOptionPane.ERROR_MESSAGE);
}
/**
* Switch current model to JMVA exact solver
*/
public void toJMVA(){
mc = new ModelChecker(model,model,model, model,true);
pw = new JModelProblemsWindow(mainWindow,mc,this);
if (!mc.isEverythingOkToJMVA()) {
pw.show();
}
if ( mc.isEverythingOkToJMVA() || ((!mc.isEverythingOkToJMVA())&&(pw.continued()))){
if (checkForSave("<html>Save changes before switching?</html>")) return;
//try {
// New Converter by Bertoli Marco
ExactModel output = new ExactModel();
Vector res = ModelConverter.convertJSIMtoJMVA(model, output);
ExactWizard jmva = new ExactWizard(output);
// If problems are found, shows warnings
if (res.size() > 0)
new WarningWindow(res, jmva).show();
/* Old code to use XSLT transformer (really bugged and unfinished)
File xmlTempFile = File.createTempFile("~SIMtoMVA", ".xml");
xmlTempFile.deleteOnExit();
File destFile = File.createTempFile("~MVA", ".xml");
destFile.deleteOnExit();
InputStream stream = XSDSchemaLoader.loadSchemaAsStream(XSDSchemaLoader.JSIM_TO_JMVA);
if(stream==null){
System.out.println("stream is null");
return;
}
XMLWriter.writeXML(xmlTempFile, model);
InputStream is = new BufferedInputStream(stream);
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(is));
StreamSource ssrc = new StreamSource(xmlTempFile);
StreamResult srst = new StreamResult(destFile);
transformer.transform(ssrc, srst);
xmlTempFile.delete();
ExactModel xm = new ExactModel();
xm.loadDocument(new XMLUtils().loadXML(destFile));
new ExactWizard(xm);
}catch (Exception e) {
handleException(e);
}*/
}
}
/**
* Called when EditSimParams action is triggered
*/
public void editSimulationParameters() {
DialogFactory.getDialog(new SimulationPanel(model, model,model,this), "Define Simulation Parameters");
}
/**
* Called when EditPAParams action is triggered
*/
public void editPAParameters() {
DialogFactory.getDialog(new ParametricAnalysisPanel(model, model,model,this), "Define What-if analysis parameters");
}
/**
* Sets resultWindow to be shown. This method is used by pollerThread
* @param rsw window to be set as current ResultsWindow
*/
public void setResultsWindow(JFrame rsw) {
this.resultsWindow = rsw;
if (rsw instanceof ResultsWindow) {
// Sets action for toolbar buttons
((ResultsWindow)rsw).addButtonActions(simulate, pauseSimulation, stopSimulation);
}
else {
showResults.setEnabled(true);
}
// Adds a listener that will unselect Show results button upon results window closing
rsw.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
mainWindow.getResultsButton().setSelected(false);
}
});
}
/**
* Called when showResults action is triggered
* @param selected Tells if show results button is selected or not
*
* Modified by Francesco D'Aquino
*/
public synchronized void showResultsWindow(boolean selected) {
if (selected) {
if (resultsWindow != null)
resultsWindow.show();
}
else {
if (resultsWindow != null)
resultsWindow.hide();
}
}
/**
* Shows results window and forces show results button to be selected
*/
public void showResultsWindow() {
mainWindow.getResultsButton().setSelected(true);
showResultsWindow(true);
}
/**
* Returns current ResultsWindow
* @return current ResultsWindow or null if none was created
*/
public JFrame getResultsWindow() {
return resultsWindow;
}
/**
* Returns current PAProgressWindow
* @return current PAProgressWindow or null if none was created
*/
public PAProgressWindow getPAProgressWindow() {
return progressWindow;
}
/**
* Shows about window
*/
public void about() {
AboutDialogFactory.showJMODEL(mainWindow);
}
/**
* Tells if something is selected into graph window
* @return true if something is selected
*/
public boolean isSomethingSelected() {
return graph.getSelectionCell() != null;
}
/**
* Takes a screenshot of current jgraph. Shows a dialog to select image type and name
*/
public void takeScreenShot() {
graph.clearSelection();
graph.showScreenShotDialog();
}
// --- end Bertoli Marco ---------------------
// --------------------------------- Francesco D'Aquino -----------------------
/**
* Shows the panel to solve a problem
*/
public void showRelatedPanel(int problemType,int problemSubType, Object relatedStation, Object relatedClass) {
//if it is a no class error show the class panel
if ((problemSubType == ModelChecker.NO_CLASSES_ERROR) && (problemType == ModelChecker.ERROR_PROBLEM) ) {
DialogFactory.getDialog(new jmodelClassesPanel(model,model),"Manage User Classes");
model.manageJobs(); //a close class may be added
}
//if it is a no station error show an error message dialog
else if ((problemSubType == ModelChecker.NO_STATION_ERROR) && (problemType == ModelChecker.ERROR_PROBLEM)){
JOptionPane.showMessageDialog(null,"Please insert at least one server or delay before starting simulation.", "Error",JOptionPane.ERROR_MESSAGE);
}
else if ( (problemSubType == ModelChecker.SIMULATION_ERROR) && (problemType == ModelChecker.ERROR_PROBLEM)) {
DialogFactory.getDialog(new MeasurePanel(model,model,model),"Edit Performance Indices");
}
//if a measure is inconsistent (i.e have one or more 'null' field) show performance indices panel
else if ( (problemSubType == ModelChecker.INCONSISTENT_MEASURE_ERROR) && (problemType == ModelChecker.ERROR_PROBLEM)) {
DialogFactory.getDialog(new MeasurePanel(model,model,model),"Edit Performance Indices");
}
//if a measure was defined more than once ask to erase all redundant measure
else if ((problemSubType == ModelChecker.DUPLICATE_MEASURE_ERROR) && (problemType == ModelChecker.ERROR_PROBLEM)) {
int k = JOptionPane.showConfirmDialog(null,"Delete all redundant performance indices?\n","Redundant performance indices found",JOptionPane.ERROR_MESSAGE);
if (k == 0) {
mc.deleteRedundantMeasure();
}
}
//if it is a reference station error show the class panel
else if ((problemSubType == ModelChecker.REFERENCE_STATION_ERROR) && (problemType == ModelChecker.ERROR_PROBLEM)) {
DialogFactory.getDialog(new jmodelClassesPanel(model,model),"Manage User Classes");
model.manageJobs(); //a close class may be added
}
//if a source has been inserted in the model but no open classes defined show the class panel
else if ((problemSubType == ModelChecker.SOURCE_WITH_NO_OPEN_CLASSES_ERROR) && (problemType == ModelChecker.ERROR_PROBLEM)) DialogFactory.getDialog(new jmodelClassesPanel(model,model),"Manage User Classes");
//if there is a routing error show the station parameter panel
else if ((problemSubType == ModelChecker.ROUTING_ERROR) && (problemType == ModelChecker.ERROR_PROBLEM)) {
StationParameterPanel tempPanel = new StationParameterPanel(model,model,relatedStation);
String stationN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -