📄 jsimmain.java
字号:
if (progressWindow != null) {
progressWindow.stopAnimation();
progressWindow.dispose();
}
model.resetSaveState();
}
private void setPanelsData(CommonModel simModel){
model = simModel;
classes.setData(model);
stations.setData(model, model);
connections.setData(model);
parameters.setData(model, model);
measures.setData(model, model, model);
rspl.setData(model,model, model);
simulation.setData(model, model, model);
parametricAnalysis.setData(model,model,model);
blocking.setData(model, model, model);
}
/**
* Saves current model
* <br>Author: Bertoli Marco
*/
private void saveFile(){
if (currentFile == null) {
saveFileAs();
return;
}
int status = modelLoader.saveModel(model, this, currentFile);
if (status == ModelLoader.FAILURE)
showErrorMessage(modelLoader.getFailureMotivation());
setTitle(WINDOW_TITLE+" - "+currentFile.getName());
model.resetSaveState();
}
/**
* Saves current model with a new name
* <br>Author: Bertoli Marco
*/
private void saveFileAs() {
int status = modelLoader.saveModel(model, this, null);
if (status == ModelLoader.FAILURE)
showErrorMessage(modelLoader.getFailureMotivation());
else if (status == ModelLoader.SUCCESS) {
currentFile = modelLoader.getSelectedFile();
setTitle(WINDOW_TITLE+" - "+currentFile.getName());
model.resetSaveState();
}
}
/**
* Exits from JSIM
*/
public void cancel(){
if (checkForSave("<html>Save changes before closing?</html>")) return;
Dimension d = getSize();
Defaults.set("JSIMWindowWidth", String.valueOf(d.width));
Defaults.set("JSIMWindowHeight", String.valueOf(d.height));
Defaults.save();
// Stops simulation if active
if (SIM_STOP.isEnabled())
stopSimulation();
// Disposes resultswindow and this
if (resultsWindow != null)
resultsWindow.dispose();
if (progressWindow != null) {
progressWindow.stopAnimation();
progressWindow.dispose();
}
super.cancel();
}
private void toJMVA(){
mc = new ModelChecker(model,model,model, model,true);
//pw.setToJMVAConversion(true);
pw.setModelChecker(mc);
pw.updateProblemsShown(false);
if (!mc.isEverythingOkToJMVA()) {
pw.show();
}
else {
pw.setVisible(false);
launchToJMVA();
}
}
public void launchToJMVA() {
// 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();
}
private void randomizeModel(){
}
private void startSimulation(){
//if simulation is not in pause state
if(!SIM_STOP.isEnabled()){
// Asks for confirmation before overwriting previous simulation data
if (model.containsSimulationResults()) {
// Find frame to show confirm dialog
Component parent = this;
if (resultsWindow != null && resultsWindow.isFocused())
parent = resultsWindow;
int resultValue = JOptionPane.showConfirmDialog(parent,
"This operation will overwrite old simulation results."+
"Continue anyway?",
"JMT - Warning",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (resultValue == JOptionPane.NO_OPTION) {
return;
}
}
// Correct eventual problems on preloading for closed classes
model.manageJobs();
// Removes previous ResultsWindow
if (resultsWindow != null) {
resultsWindow.dispose();
SHOW_RESULTS.setEnabled(false);
}
mc = new ModelChecker(model,model,model, model,false);
pw.setModelChecker(mc);
//pw.setToJMVAConversion(false);
pw.updateProblemsShown(false);
if (!mc.isEverythingOkNormal()) {
WindowListener wl = pw.getWindowListeners()[0];
pw.show();
}
else {
pw.setVisible(false);
launchSimulation();
}
}else{
if (!model.isParametricAnalysisEnabled()) dispatcher.restartSimulation();
else batchThread.restartSimulation();
}
}
public void launchSimulation() {
if (!model.isParametricAnalysisEnabled()) {
try {
File temp = File.createTempFile("~JModelSimulation",".xml");
temp.deleteOnExit();
XMLWriter.writeXML(temp, model);
// Creates results data structure
model.setSimulationResults(new ResultsModel(model.getPollingInterval()));
SHOW_RESULTS.setEnabled(true);
dispatcher = new DispatcherThread(this, model,
(ResultsModel)model.getSimulationResults());
dispatcher.startSimulation(temp);
}
catch (Exception e) {
handleException(e);
}
}
else {
SHOW_RESULTS.setEnabled(false);
// Removes previous ResultsWindow
//if (parametricResultsWindow != null) {
// parametricResultsWindow.dispose();
//}
if (progressWindow == null) {
progressWindow = new PAProgressWindow(this,SIM_START,SIM_PAUSE,SIM_STOP,model.getParametricAnalysisModel());
}
batchThread = new PADispatcherThread(this,model,progressWindow);
changeSimActionsState(false, true, true);
progressWindow.initialize(model.getParametricAnalysisModel().getNumberOfSteps());
progressWindow.start();
progressWindow.show();
batchThread.start();
}
}
private void pauseSimulation(){
if (model.isParametricAnalysisEnabled()) {
batchThread.pauseSimulation();
}
else dispatcher.pauseSimulation();
}
private void stopSimulation(){
if (!model.isParametricAnalysisEnabled()) dispatcher.stopSimulation();
else batchThread.stopSimulation();
}
public void changeSimActionsState(boolean start, boolean pause, boolean stop){
SIM_START.setEnabled(start);
SIM_STOP.setEnabled(stop);
SIM_PAUSE.setEnabled(pause);
}
private void showHelp(){}
/**
* Shows JSIM Credits
* <br>Author: Bertoli Marco
*/
private void showCredits(){
AboutDialogFactory.showJSIM(this);
}
public JSIMMain(){
this(null);
}
public JSIMMain(CommonModel model){
super();
Defaults.reload();
if(model == null) this.model = new JSIMModel();
else this.model = model;
model = this.model;
setSize(Defaults.getAsInteger("JSIMWindowWidth").intValue(),
Defaults.getAsInteger("JSIMWindowHeight").intValue());
setTitle(WINDOW_TITLE);
setIconImage(ImageLoader.loadImageAwt("JSIMIcon"));
centerOnScreen(this);
classes = new ClassesPanel(model);
stations = new StationsPanel(model, model);
connections = new ConnectionsPanel(model);
parameters = new AllStationsParametersPanel(model, model);
measures = new MeasurePanel(model, model, model);
rspl = new RSPLPanel(model, model, model);
simulation = new SimulationPanel(model, model, model,this);
parametricAnalysis = new ParametricAnalysisPanel(model,model,model,this);
blocking = new AllBlockingRegionsPanel(model, model, model);
initComponents();
mc = new ModelChecker(model,model,model, model,false);
pw = new JSimProblemsWindow(mc,this);
}
private void initComponents(){
JPanel menus = new JPanel(new BorderLayout());
menus.add(createMenuBar(), BorderLayout.NORTH);
menus.add(createToolBar(), BorderLayout.SOUTH);
getContentPane().add(menus, BorderLayout.NORTH);
//add panels
WizardPanel[] panels = new WizardPanel[]{
classes, stations, connections, parameters, measures, rspl, blocking, simulation, parametricAnalysis
};
for(int i=0; i<panels.length; i++){
addPanel(panels[i]);
}
}
private JToolBar createToolBar(){
JToolBar toolbar = new JToolBar();
toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
toolbar.setFloatable(false);
toolbar.setBorderPainted(false);
toolbar.setOrientation(JToolBar.HORIZONTAL);
toolbar.setRollover(true);
Action[] items = new Action[]{
FILE_NEW, FILE_OPEN, FILE_SAVE, null,
ACTION_SWITCH_JMVA, null,
SIM_START, SIM_PAUSE, SIM_STOP, SHOW_RESULTS,null,
OPTIONS_DEFAULTS, null, HELP_SHOWHELP
};
String[] iconNames = new String[]{
"New", "Open", "Save", "toJMVA",
"Sim", "Pause", "Stop", "Results", "Options", "Help"
};
for(int i=0, j=0; i<items.length; i++, j++){
// Tis is a particularcase as it's a toggle button
if (items[i] == SHOW_RESULTS) {
resultsButton = new JToggleButton(items[i]);
resultsButton.setText("");
resultsButton.setRolloverEnabled(true);
resultsButton.setBorderPainted(false);
resultsButton.setFocusPainted(false);
resultsButton.setContentAreaFilled(false);
resultsButton.setPressedIcon(ImageLoader.loadImage(iconNames[j]+"P"));
resultsButton.setRolloverIcon(ImageLoader.loadImage(iconNames[j]+"RO"));
resultsButton.setSelectedIcon(ImageLoader.loadImage(iconNames[j]+"S"));
resultsButton.setBorder(new EmptyBorder(0,0,0,0));
resultsButton.setMaximumSize(getMinimumSize());
toolbar.add(resultsButton);
}
else if(items[i] != null){
JButton button = new JButton(items[i]);
button.setText("");
button.setRolloverEnabled(true);
button.setBorderPainted(false);
button.setFocusPainted(false);
button.setContentAreaFilled(false);
button.setPressedIcon(ImageLoader.loadImage(iconNames[j]+"P"));
button.setRolloverIcon(ImageLoader.loadImage(iconNames[j]+"RO"));
button.setBorder(new EmptyBorder(0,0,0,0));
button.setMaximumSize(getMinimumSize());
toolbar.add(button);
}else{
toolbar.addSeparator();
j--;
}
}
return toolbar;
}
private JMenuBar createMenuBar(){
JMenuBar menuBar = new JMenuBar();
Action[][] menus = new Action[][]{
//File menu
{FILE_NEW, FILE_SAVE, FILE_SAVEAS, FILE_OPEN, null, FILE_EXIT},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -