📄 exactwizard.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.exact;
import jmt.common.exception.InputDataException;
import jmt.common.exception.SolverException;
import jmt.gui.common.definitions.ModelConverter;
import jmt.gui.common.panels.AboutDialogFactory;
import jmt.gui.common.panels.WarningWindow;
import jmt.gui.common.resources.ImageLoader;
import jmt.gui.common.xml.ModelLoader;
import jmt.gui.common.Manager;
import jmt.gui.exact.link.SolverClient;
import jmt.gui.exact.panels.*;
import jmt.gui.help.HoverHelp;
import jmt.gui.jsim.JSIMMain;
import jmt.gui.jsim.definitions.JSIMModel;
import jmt.gui.wizard.Wizard;
import jmt.gui.wizard.WizardPanel;
import javax.help.HelpSet;
import javax.help.JHelp;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
import java.net.URL;
import java.util.Vector;
import java.util.Locale;
/**
* This is the object you use to define your system structure and parameters
* @author alyf (Andrea Conti)
* @version Date: 11-set-2003 Time: 14.47.11
*
* Modified by Bertoli Marco 01-mar-2006 (added model conversion and solved bug
* with stored visits)
*
*/
public class ExactWizard extends Wizard {
private final static boolean DEBUG = false;
private ExactModel data;
private JLabel helpLabel;
private HoverHelp help;
private SolverClient solver;
// New Bertoli Marco
private ModelLoader modelLoader = new ModelLoader(ModelLoader.JMVA);
// End
//NEW Dall'Orso
//A link to the last modified model's temporary file - used to display synopsis
private File tempFile=null;
//END
//keep a reference to these three components to enable switching
private WizardPanel serviceTimesPanel, serviceDemandsPanel, visitsPanel;
private AbstractAction FILE_SAVE = new AbstractAction("Save...") {
{
putValue(Action.SHORT_DESCRIPTION, "Save 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) {
save();
}
};
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) {
open();
}
};
private AbstractAction FILE_NEW = new AbstractAction("New...") {
{
putValue(Action.SHORT_DESCRIPTION, "Create 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) {
newModel();
}
};
private AbstractAction FILE_EXIT = new AbstractAction("Exit") {
{
putValue(Action.SHORT_DESCRIPTION, "Exits Application");
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 SWITCH_TO_SIMULATOR = new AbstractAction("Import in JSIM...") {
{
putValue(Action.SHORT_DESCRIPTION, "Import current model into JSIM...");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("toJSIM"));
putValue(Action.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_G,
ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_G));
}
public void actionPerformed(ActionEvent e) {
switchToSimulator();
}
};
private AbstractAction ACTION_RANDOMIZE_MODEL = new AbstractAction("Randomize") {
{
putValue(Action.SHORT_DESCRIPTION, "Random generation of service demands");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("dice"));
putValue(Action.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_R,
ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R));
}
public void actionPerformed(ActionEvent e) {
randomizeModel();
}
};
//NEW
//@author Stefano Omini
private AbstractAction HELP = new AbstractAction("jMVA help") {
{
putValue(Action.SHORT_DESCRIPTION, "Show jMVA 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(e);
}
};
//end NEW
//NEW
//@author Stefano Omini
private AbstractAction ABOUT = new AbstractAction("About jMVA...") {
{
putValue(Action.SHORT_DESCRIPTION, "About jMVA");
/*
putValue(Action.SMALL_ICON, ImageLoader.loadImage("helpIcon"));
putValue(Action.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_H,
ActionEvent.ALT_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_H));
*/
}
public void actionPerformed(ActionEvent e) {
showAbout();
}
};
//end NEW
//NEW
//@author Stefano Omini
private AbstractAction ACTION_SOLVE = new AbstractAction("Solve") {
{
putValue(Action.SHORT_DESCRIPTION, "Solve model");
putValue(Action.SMALL_ICON, ImageLoader.loadImage("Sim"));
putValue(Action.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_L,
ActionEvent.CTRL_MASK));
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_L));
}
public void actionPerformed(ActionEvent e) {
if(checkFinish())
finish();
}
};
//end NEW
public ExactWizard() {
this(new ExactModel());
}
public ExactWizard(ExactModel data) {
super("JMVA - PFQN exact solver");
//setResizable(false);
setSize(640, 480);
centerOnScreen(this);
setIconImage(ImageLoader.loadImageAwt("JMVAIcon"));
this.data = data;
data.resetChanged();
//BEGIN Federico Dall'Orso 8/3/2005
//OLD
/*
getContentPane().add(makeToolbar(), BorderLayout.NORTH);
*/
//NEW
JPanel first = new JPanel(new GridLayout(2,1));
first.add(makeMenubar());
first.add(makeToolbar());
getContentPane().add(first, BorderLayout.NORTH);
//END Federico Dall'Orso 8/3/2005
addPanel(new ClassesPanel(this));
addPanel(new StationsPanel(this));
serviceTimesPanel = new ServiceTimesPanel(this);
visitsPanel = new VisitsPanel(this);
serviceDemandsPanel = new ServiceDemandsPanel(this);
if (data.areVisitsSet()) {
addPanel(serviceTimesPanel);
addPanel(visitsPanel);
}
else
addPanel(serviceDemandsPanel);
addPanel(new WhatIfPanel(this));
addPanel(new DescriptionPanel(this));
show();
}
/**
* @return the toolbar for the exact wizard. Shamelessly uses icon from the main jmt frame
*/
protected JToolBar makeToolbar() {
JToolBar tb = new JToolBar();
tb.setRollover(true);
tb.setOrientation(SwingConstants.HORIZONTAL);
tb.setFloatable(false);
//null values add a gap between toolbar icons
Action[] actions = {FILE_NEW,FILE_OPEN, FILE_SAVE,null, ACTION_FINISH,
SWITCH_TO_SIMULATOR, ACTION_RANDOMIZE_MODEL,null, HELP};
String[] icons = {"New","Open", "Save", "Sim", "toJSIM", "dice", "Help"};
String[] htext = {"Creates a new model","Opens a saved model", "Saves the current model",
"Solves the current model", "Import current model to JSIM to solve it with the simulator", "Randomize model data", "Show help"};
JButton button;
tb.setBorderPainted(true);
//i index scans actions' array which includes null values, while j scans other arrays.
//so j must be decremented when a null value is found in action array.
for (int i = 0, j=0; i < actions.length; i++,j++) {
if(actions[i]==null){
j--;
tb.addSeparator(new Dimension(20,2));
}else{
button = new JButton(actions[i]);
button.setText("");
button.setIcon(ImageLoader.loadImage(icons[j]));
button.setRolloverIcon(ImageLoader.loadImage(icons[j] + "RO"));
button.setPressedIcon(ImageLoader.loadImage(icons[j] + "P"));
button.setFocusPainted(false);
button.setContentAreaFilled(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -