📄 jsimmain.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.jsim;
import jmt.gui.common.Defaults;
import jmt.gui.common.controller.DispatcherThread;
import jmt.gui.common.controller.ModelChecker;
import jmt.gui.common.controller.PADispatcherThread;
import jmt.gui.common.definitions.*;
import jmt.gui.common.editors.DefaultsEditor;
import jmt.gui.common.panels.*;
import jmt.gui.common.panels.parametric.PAProgressWindow;
import jmt.gui.common.panels.parametric.PAResultsWindow;
import jmt.gui.common.panels.parametric.ParametricAnalysisPanel;
import jmt.gui.common.resources.ImageLoader;
import jmt.gui.common.xml.ModelLoader;
import jmt.gui.common.xml.XMLWriter;
import jmt.gui.exact.ExactModel;
import jmt.gui.exact.ExactWizard;
import jmt.gui.jsim.definitions.JSIMModel;
import jmt.gui.jsim.panels.*;
import jmt.gui.wizard.Wizard;
import jmt.gui.wizard.WizardPanel;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.Locale;
import java.util.Vector;
/**
* Created by IntelliJ IDEA.
* User: orsotronIII
* Date: 18-lug-2005
* Time: 8.59.44
* Modified by Bertoli Marco
*
* Modified by Francesco D'Aquino
*/
public class JSIMMain extends Wizard implements GuiInterface{
private static final String WINDOW_TITLE = "JSIMwiz - Queue Network Models Simulator";
private CommonModel model = new JSIMModel();
private File currentFile = null;
private JFrame resultsWindow;
private JToggleButton resultsButton;
private DispatcherThread dispatcher;
private ModelLoader modelLoader = new ModelLoader(ModelLoader.JSIM);
private ClassesPanel classes;
private StationsPanel stations;
private ConnectionsPanel connections;
private AllStationsParametersPanel parameters;
private MeasurePanel measures;
private RSPLPanel rspl;
private SimulationPanel simulation;
private AllBlockingRegionsPanel blocking;
//Francesco D'Aquino
private ModelChecker mc;
private JSimProblemsWindow pw;
private PADispatcherThread batchThread;
private PAProgressWindow progressWindow;
private ParametricAnalysisPanel parametricAnalysis;
// end
private AbstractAction FILE_NEW = new AbstractAction("New"){
{
putValue(Action.SHORT_DESCRIPTION, "New Model");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("New"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_N));
}
public void actionPerformed(ActionEvent e) {
newFile();
}
};
private AbstractAction FILE_OPEN = new AbstractAction("Open"){
{
putValue(Action.SHORT_DESCRIPTION, "Open Saved Model");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Open"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
}
public void actionPerformed(ActionEvent e) {
openFile();
}
};
private AbstractAction FILE_SAVE = new AbstractAction("Save"){
{
putValue(Action.SHORT_DESCRIPTION, "Save this model");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Save"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
}
public void actionPerformed(ActionEvent e) {
saveFile();
}
};
private AbstractAction FILE_SAVEAS = new AbstractAction("Save as"){
{
putValue(Action.SHORT_DESCRIPTION, "Save this model as ");
}
public void actionPerformed(ActionEvent e) {
saveFileAs();
}
};
private AbstractAction FILE_EXIT = new AbstractAction("Quit"){
{
putValue(Action.SHORT_DESCRIPTION, "Exit JSIM");
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_Q));
}
public void actionPerformed(ActionEvent e) {
cancel();
}
};
private AbstractAction ACTION_SWITCH_JMVA = new AbstractAction("Export to JMVA..."){
{
putValue(Action.SHORT_DESCRIPTION, "Export current model to JMVA...");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("toJMVA"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_W));
}
public void actionPerformed(ActionEvent e) {
toJMVA();
}
};
private AbstractAction ACTION_RAND = new AbstractAction("Randomize"){
{
putValue(Action.SHORT_DESCRIPTION, "Generate Randomized Model");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Dice"));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R));
}
public void actionPerformed(ActionEvent e) {
randomizeModel();
}
};
private AbstractAction SIM_START = new AbstractAction("Start Simulation"){
{
putValue(Action.SHORT_DESCRIPTION, "Start Simulation");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Sim"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_M));
}
public void actionPerformed(ActionEvent e) {
startSimulation();
}
};
private AbstractAction SIM_PAUSE = new AbstractAction("Pause"){
{
putValue(Action.SHORT_DESCRIPTION, "Pause Simulation");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Pause"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
//start disabled
setEnabled(false);
}
public void actionPerformed(ActionEvent e) {
pauseSimulation();
}
};
private AbstractAction SIM_STOP = new AbstractAction("Stop"){
{
putValue(Action.SHORT_DESCRIPTION, "Stop Simulation");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Stop"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_T));
//start disabled
setEnabled(false);
}
public void actionPerformed(ActionEvent e) {
stopSimulation();
}
};
private AbstractAction OPTIONS_DEFAULTS = new AbstractAction("Default parameters..."){
{
putValue(Action.SHORT_DESCRIPTION, "Define default value of model's parameters");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Options"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_D));
}
public void actionPerformed(ActionEvent e) {
showOptions();
}
};
private AbstractAction HELP_SHOWHELP = new AbstractAction("Help"){
{
putValue(Action.SHORT_DESCRIPTION, "Show Help");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Help"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_H));
}
public void actionPerformed(ActionEvent e) {
showHelp();
}
};
private AbstractAction HELP_CREDITS = new AbstractAction("About JSIMwiz"){
{
putValue(Action.SHORT_DESCRIPTION, "Credits");
}
public void actionPerformed(ActionEvent e) {
showCredits();
}
};
public AbstractAction SHOW_RESULTS = new AbstractAction("Results"){
{
putValue(Action.SHORT_DESCRIPTION, "Show simulation results");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Results"));
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R));
//start disabled
setEnabled(false);
}
public void actionPerformed(ActionEvent e) {
//if (resultsWindow == null)
// return;
if (e.getSource() instanceof JToggleButton)
showResultsWindow(((JToggleButton)e.getSource()).isSelected());
else
showResultsWindow();
}
};
private void showOptions() {
JFrame jf = new JFrame("Defaults Editor");
jf.setIconImage(getIconImage());
jf.setSize(getSize());
new DefaultsEditor(jf, DefaultsEditor.JSIM).show();
}
/**
* Open a stored model from a file
* <br>Author: Bertoli Marco
*/
private void openFile(){
if (checkForSave("<html>Save changes before opening a saved model?</html>")) return;
JSIMModel tmpmodel = new JSIMModel();
int state = modelLoader.loadModel(tmpmodel, this);
if (state == ModelLoader.SUCCESS || state == ModelLoader.WARNING) {
currentFile = modelLoader.getSelectedFile();
// At this point loading was successful, so substitutes old model with loaded one
model = tmpmodel;
// Clears old resultsWindow
if (resultsWindow != null)
resultsWindow.dispose();
// Clears parametric window too...
if (progressWindow != null) {
progressWindow.stopAnimation();
progressWindow.dispose();
}
SHOW_RESULTS.setEnabled(false);
resultsButton.setSelected(false);
setPanelsData(model);
setTitle(WINDOW_TITLE+" - "+currentFile.getName());
// If simulation results are present, adds a Result Window
if (model.containsSimulationResults()) {
if (model.isParametricAnalysisEnabled()) {
this.setResultsWindow(new PAResultsWindow(model.getParametricAnalysisModel(),(PAResultsModel)model.getSimulationResults()));
SHOW_RESULTS.setEnabled(true);
}
else {
this.setResultsWindow(new ResultsWindow(model.getSimulationResults()));
SHOW_RESULTS.setEnabled(true);
}
}
model.resetSaveState();
System.gc();
}
else if (state == ModelLoader.FAILURE)
showErrorMessage(modelLoader.getFailureMotivation());
// Shows warnings if any
if (state == ModelLoader.WARNING) {
new WarningWindow(modelLoader.getLastWarnings(), this).show();
}
}
private void newFile(){
if (checkForSave("<html>Save changes before creating a new model?</html>")) return;
setPanelsData(new JSIMModel());
currentFile = null;
setTitle(WINDOW_TITLE);
// Disposes results (if any)
if (resultsWindow != null)
resultsWindow.dispose();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -