📄 jabawizard.java
字号:
buttons.add(button_cancel);
buttons.add(button_help);
JPanel labelbox = new JPanel();
labelbox.setLayout(new BorderLayout());
labelbox.add(Box.createVerticalStrut(20), BorderLayout.WEST);
labelbox.add(helpLabel, BorderLayout.CENTER);
Box buttonBox = Box.createVerticalBox();
buttonBox.add(buttons);
buttonBox.add(labelbox);
return buttonBox;
}
//BEGIN Federico Dall'Orso 8/3/2005
//NEW
private void newModel(){
currentPanel.lostFocus();
if (checkForSave("<html>Save changes before creating a new model?</html>")) return;
Rectangle bounds = this.getBounds();
JabaWizard ew = new JabaWizard();
ew.setBounds(bounds);
ew.show();
Manager.addJMTWindow(ew);
this.hide();
this.dispose();
Manager.exit(this);
}
//END Federico Dall'Orso 8/3/2005
/**
* Shows a confirmation dialog to save before new model or exit operations
* @param msg The message to display.
* @return <code>true</code> - if the user select cancel button.
*/
public boolean checkForSave(String msg) {
// Checks if there's an old graph to save
if (data != null && data.isChanged()) {
int resultValue = JOptionPane.showConfirmDialog(this,
msg,
"JABA - Warning",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (resultValue == JOptionPane.YES_OPTION) {
save();
return false;
}
if (resultValue == JOptionPane.CANCEL_OPTION) {
return true;
}
}
return false;
}
/**
* Saves current model
* <br>Author: Bertoli Marco
*/
private void save() {
currentPanel.lostFocus();
if (!checkFinish()) return; // panels with problems are expected to notify the user by themselves
int retval = modelLoader.saveModel(data, this, null);
switch (retval) {
case ModelLoader.SUCCESS:
data.resetChanged();
break;
case ModelLoader.FAILURE:
JOptionPane.showMessageDialog(this, modelLoader.getFailureMotivation(), "Error", JOptionPane.ERROR_MESSAGE);
break;
}
}
/**
* Opens a new model
* <br>Author: Bertoli Marco
*/
private void open() {
currentPanel.lostFocus();
if (checkForSave("<html>Save changes before opening a saved model?</html>")) return;
JabaModel newdata = new JabaModel();
int retval = modelLoader.loadModel(newdata, this);
switch (retval) {
case ModelLoader.SUCCESS:
case ModelLoader.WARNING:
data = newdata;
currentPanel.gotFocus();
// Shows right panels
if (data.areVisitsSet()) {
removePanel(serviceDemandsPanel);
((ForceUpdatablePanel)serviceTimesPanel).retrieveData();
((ForceUpdatablePanel)visitsPanel).retrieveData();
addPanel(visitsPanel,2);
addPanel(serviceTimesPanel,2);
}
else {
removePanel(visitsPanel);
removePanel(serviceTimesPanel);
((ForceUpdatablePanel)serviceDemandsPanel).retrieveData();
addPanel(serviceDemandsPanel,2);
}
tabbedPane.setSelectedIndex(0);
break;
case ModelLoader.FAILURE:
JOptionPane.showMessageDialog(this, modelLoader.getFailureMotivation(), "Error", JOptionPane.ERROR_MESSAGE);
break;
}
updatePanels();
// Shows warnings if any
if (retval == ModelLoader.WARNING) {
new WarningWindow(modelLoader.getLastWarnings(), this).show();
}
updatePanels();
}
public JabaModel getData() {
return data;
}
protected void finish() {
//OLD
//do not call this method!!! It's already called inside checkFinish() method.
//currentPanel.lostFocus();
solve();
}
protected void cancel() {
if (currentPanel != null) currentPanel.lostFocus();
if (checkForSave("<html>Save changes before closing?</html>")) return;
super.cancel();
}
protected void switchToSimulator() {
cancel();
new jmt.gui.jmodel.mainGui.MainWindow();
dispose();
}
public HoverHelp getHelp() {
return help;
}
/**switches service times and visits panels to service demands panel in order to change
* data representation.*/
public void switchFromSTVtoSD(){
((ForceUpdatablePanel)serviceTimesPanel).commitData();
((ForceUpdatablePanel)visitsPanel).retrieveData();
((ForceUpdatablePanel)visitsPanel).commitData();
removePanel(serviceTimesPanel);
removePanel(visitsPanel);
((ForceUpdatablePanel)serviceDemandsPanel).retrieveData();
addPanel(serviceDemandsPanel,2);
}
/**switches service times and visits panels to service demands panel in order to change
* data representation.*/
public void switchFromSDtoSTV(){
((ForceUpdatablePanel)serviceDemandsPanel).commitData();
removePanel(serviceDemandsPanel);
((ForceUpdatablePanel)serviceTimesPanel).retrieveData();
((ForceUpdatablePanel)visitsPanel).retrieveData();
addPanel(visitsPanel,2);
addPanel(serviceTimesPanel,2);
}
private void solve() {
//if (solver == null) solver = new SolverClient();
//NEW Zanzottera
if (jsolver == null) jsolver = new SolverDispatcher();
JabaModel newdata = new JabaModel(data); // Yields the mean performance indices
try {
//controllo che ci siano 2 o 3 classi
//NEW Zanzottera
newdata.setResults(jsolver.solve(newdata));
//end NEW
//@author Stefano Omini
} catch (InputDataException rse) {
JOptionPane.showMessageDialog(this, rse.getMessage(), "Input data error", JOptionPane.ERROR_MESSAGE);
return;
//end NEW
} catch (SolverException e) {
JOptionPane.showMessageDialog(this, e.getMessage(), "Solver error", JOptionPane.ERROR_MESSAGE);
return;
}
this.data = newdata;
// Zanzottera: i risultati vengono visualizzati all'interno della schermata principale
/*
//Dall'Orso
createSolutionWindow(newdata.getResults());
//END
*/
updatePanels();
currentPanel.gotFocus();
// Select graphical results panel (before select textual one to avoid a graphical glitch)
tabbedPane.setSelectedIndex(5);
tabbedPane.setSelectedIndex(4);
}
//NEW
//@author Stefano Omini
private void showHelp(ActionEvent event){
/*
try {
ClassLoader cl = this.getClass().getClassLoader();
//URL url = HelpSet.findHelpSet(cl, "help/mvaIt/MVA.hs");
URL url = HelpSet.findHelpSet(cl, "help/jmva_en/jmva_eng.hs");
//System.out.println(url.toString());
HelpSet hs = new HelpSet(cl, url);
HelpBroker hb = hs.createHelpBroker();
CSH.DisplayHelpFromSource display = new CSH.DisplayHelpFromSource(hb);
display.actionPerformed(event);
//} catch (HelpSetException e) {
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Sorry, jMVA help is not available", "Help not found", JOptionPane.ERROR_MESSAGE);
}
return;
*/
JHelp helpViewer;
try {
// Get the classloader of this class.
ClassLoader cl = this.getClass().getClassLoader();
// Use the findHelpSet method of HelpSet to create a URL referencing the helpset file.
URL url = HelpSet.findHelpSet(cl, "help/jABA_en/jaba_eng.hs");
// Create a new JHelp object with a new HelpSet.
helpViewer = new JHelp(new HelpSet(cl, url));
// Set the initial entry point in the table of contents.
//helpViewer.setCurrentID("");
} catch (Exception e) {
if (DEBUG)
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Sorry, jABA help is not available",
"Help not found", JOptionPane.ERROR_MESSAGE);
return;
}
// Create a new frame.
JFrame frame = new JFrame();
// Set it's size.
frame.setSize(650,510);
// Add the created helpViewer to it.
frame.getContentPane().add(helpViewer);
// Set a default close operation.
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// Make the frame visible.
frame.setVisible(true);
}
//end NEW
//NEW
//@author Bertoli Marco
private void showAbout(){
AboutDialogFactory.showJABA(this);
}
//end NEW
//NEW
//@author Stefano Omini
/**
* find the helpset file and create a HelpSet object
*/
public HelpSet getHelpSet(String helpsetfile) {
HelpSet hs = null;
ClassLoader cl = this.getClass().getClassLoader();
try {
URL hsURL = HelpSet.findHelpSet(cl, helpsetfile);
hs = new HelpSet(null, hsURL);
} catch(Exception ee) {
//System.out.println("HelpSet: "+ee.getMessage());
//System.out.println("HelpSet: "+ helpsetfile + " not found");
JOptionPane.showMessageDialog(this, ee.getMessage(), "Help not found", JOptionPane.ERROR_MESSAGE);
}
return hs;
}
//end NEW
//randomizes model data
private void randomizeModel(){
if (DEBUG)
System.out.println("Classes: "+data.getClasses()+"; Stations: "+data.getStations());
//first get infos about classes and station
for(int i=0; i<panels.size()&&i<2; i++){
Object o = panels.get(i);
if(o instanceof ForceUpdatablePanel){
((ForceUpdatablePanel)o).commitData();
}
}
//then randomize data
data.randomizeModelData();
//and then update all those data into panels
ForceUpdatablePanel[] fuPanes = {(ForceUpdatablePanel)serviceDemandsPanel,
(ForceUpdatablePanel)serviceTimesPanel,
(ForceUpdatablePanel)serviceDemandsPanel};
for(int i=0; i<fuPanes.length; i++){
fuPanes[i].retrieveData();
}
repaint();
}
//END
private void updatePanels() {
if (data == null) return;
//NEW
for(int i=0; i<panelCount; i++){
if(panels.get(i) instanceof WizardPanel){
((WizardPanel)(panels.get(i))).gotFocus();
}
}
//END
}
protected void updateActions() {
super.updateActions();
if (currentIndex < (panelCount - 1)) {
if (!tabbedPane.isEnabledAt(currentIndex + 1)) ACTION_NEXT.setEnabled(false);
}
if (currentIndex > 0) {
if (!tabbedPane.isEnabledAt(currentIndex - 1)) ACTION_PREV.setEnabled(false);
}
updatePanels();
}
// JABA MAIN
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new com.jgoodies.looks.plastic.Plastic3DLookAndFeel());
Locale.setDefault(Locale.ENGLISH);
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
new JabaWizard(new JabaModel());
}
/////// CLASSI PER LA VISUALIZZAZIONE GRAFICA //////////////////////////
//Pannello iniziale che conterr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -