📄 mediator.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.jmodel.controller;
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.xml.ModelLoader;
import jmt.gui.common.xml.XMLWriter;
import jmt.gui.exact.ExactModel;
import jmt.gui.exact.ExactWizard;
import jmt.gui.jmodel.DialogFactory;
import jmt.gui.jmodel.JGraphMod.*;
import jmt.gui.jmodel.controller.actions.*;
import jmt.gui.jmodel.definitions.JMODELModel;
import jmt.gui.jmodel.definitions.JmodelClassDefinition;
import jmt.gui.jmodel.definitions.JmodelStationDefinition;
import jmt.gui.jmodel.mainGui.MainWindow;
import jmt.gui.jmodel.panels.JModelProblemsWindow;
import jmt.gui.jmodel.panels.StationNamePanel;
import jmt.gui.jmodel.panels.jmodelClassesPanel;
import org.jgraph.JGraph;
import org.jgraph.graph.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.util.*;
import java.util.List;
/**
* This class mantains a reference to all the main copmponents of the Gui,
* in this way it's possible to divide the responsability of the actions &
* every object know only about of himself & the mediator.
* Other actions are made through the mediator without knowing who will actually
* do it.
*
* @author Federico Granata
* Date: 3-giu-2003
* Time: 16.54.45
* Heavily modified by Bertoli Marco 2-giu-2005
* Modified by Francesco D'Aquino
* Modyfied by Bertoli Marco to support JGraph 5.8 - 21/mar/2006
*/
public class Mediator implements GuiInterface {
// making it final allows the compiler to skip code generation when false
private GraphMouseListner mouseListner;
private AbstractJmtAction closeModel, newModel, openHelp, openModel,
saveModel, setConnect, actionCopy , actionCut, setOptions, actionPaste,
setSelect, actionDelete, simulate, solveAnalitic, solveApp,
editUserClasses, editMeasures, switchToExactSolver, exit,
// Bertoli Marco
editDefaults, saveModelAs, pauseSimulation, stopSimulation, editSimParams,
showResults, about, addBlockingRegion, takeScreenShot,
//end
// Conti Andrea
editUndo, editRedo;
//end
private JmtJGraph graph;
private MainWindow mainWindow;
protected Object[] cells;
protected Map cellsAttr;
public static boolean advanced;
private Cursor cursor;
private Cursor oldCursor;
// Bertoli Marco
private JMODELModel model;
private JFrame resultsWindow;
private JmtClipboard clipboard;
private DispatcherThread dispatcher = null; // To control simulation
private ModelLoader modelLoader = new ModelLoader(ModelLoader.JMODEL); // To Save / Load
// end
// Francesco D'Aquino
private ModelChecker mc;
private JModelProblemsWindow pw;
private PADispatcherThread batchThread;
private PAProgressWindow progressWindow;
private AbstractJmtAction editPAParams;
// end
public Mediator(final JmtJGraph graph, MainWindow mainWindow) {
this.mainWindow = mainWindow;
DialogFactory.setOwner(mainWindow);
this.graph = graph;
closeModel = new CloseModel(this);
newModel = new NewModel(this);
openHelp = new OpenHelp(this);
openModel = new OpenModel(this);
saveModel = new SaveModel(this);
setConnect = new SetConnectState(this);
actionCopy = new ActionCopy(this);
actionCut = new ActionCut(this);
setOptions = new SetOptions(this);
actionPaste = new ActionPaste(this);
setSelect = new SetSelectState(this);
actionDelete = new ActionDelete(this);
simulate = new Simulate(this);
solveAnalitic = new SolveAnalytic(this);
solveApp = new SolveApprox(this);
//Conti Andrea - undo
undoManager = new GraphUndoManager();
undoProxy = new UndoManagerProxy(undoManager);
editUndo = new ActionUndo(this, undoManager);
editRedo = new ActionRedo(this, undoManager);
// end
// Bertoli Marco
pauseSimulation = new PauseSimulation(this);
stopSimulation = new StopSimulation(this);
exit = new Exit(this);
clipboard = new JmtClipboard(this);
editDefaults = new EditDefaults(this);
saveModelAs = new SaveModelAs(this);
editSimParams = new EditSimParams(this);
editPAParams = new EditPAParams(this);
showResults = new ShowResults(this);
about = new About(this);
addBlockingRegion = new AddBlockingRegion(this);
takeScreenShot = new TakeScreenShot(this);
// end
//Conti Andrea
CellFactory.setMediator(this);
//end
// 28/07/03 - Massimo Cattai //////////////////////////////////////////
editUserClasses = new EditUserClasses(this);
editMeasures = new EditMeasures(this);
switchToExactSolver = new SwitchToExactSolver(this);
// 28/07/03 - end /////////////////////////////////////////////////////
}
public void setMouseListner(GraphMouseListner mouseListner) {
this.mouseListner = mouseListner;
}
private File openedArchive;
// Bertoli Marco
public AbstractJmtAction getEditUserClasses() {
return editUserClasses;
}
public AbstractJmtAction getExit() {
return exit;
}
public JmodelStationDefinition getStationDefinition() {
return model;
}
public JmodelClassDefinition getClassDefinition() {
return model;
}
public SimulationDefinition getSimulationDefinition() {
return model;
}
public BlockingRegionDefinition getBlockingRegionDefinition() {
return model;
}
public void enableAddBlockingRegion(boolean state) {
addBlockingRegion.setEnabled(state);
}
public AbstractJmtAction getEditDefaults() {
return editDefaults;
}
public AbstractJmtAction getAddBlockingRegion() {
return addBlockingRegion;
}
public AbstractJmtAction getSaveModelAs() {
return saveModelAs;
}
public AbstractJmtAction getPauseSimulation() {
return pauseSimulation;
}
public AbstractJmtAction getStopSimulation() {
return stopSimulation;
}
public AbstractJmtAction getEditSimParams() {
return editSimParams;
}
public AbstractJmtAction getEditPAParams() {
return editPAParams;
}
public AbstractJmtAction getShowResults() {
return showResults;
}
public AbstractJmtAction getAbout() {
return about;
}
//end
//Conti Andrea - undo
private GraphUndoManager undoManager;
private UndoManagerProxy undoProxy;
public void undo() {
undoManager.undo();
}
public void redo() {
undoManager.redo();
}
public void enableUndoAction(boolean state) {
editUndo.setEnabled(state);
}
public void enableRedoAction(boolean state) {
editRedo.setEnabled(state);
}
public AbstractJmtAction getUndoAction() {
return editUndo;
}
public AbstractJmtAction getRedoAction() {
return editRedo;
}
public GraphUndoManager getUndoManager() {
return undoManager;
}
public void setUndoManager(GraphUndoManager um) {
undoManager = um;
}
//end
public void setConnectState() {
setSelect.setEnabled(true);
//DEK (Federico Granata) 14-11-2003
oldCursor = cursor;
cursor = new Cursor(Cursor.CROSSHAIR_CURSOR);
setGraphCursor(cursor);
//end 14-11-2003
mouseListner.setConnectState();
}
public void setCopyState() {
setSelect.setEnabled(true);
// mouseListner.setCopyState();
}
public void setCutState() {
setSelect.setEnabled(true);
// mouseListner.setCutState();
}
public void setInsertState(String className) {
setSelect.setEnabled(true);
mouseListner.setInsertState(className);
}
public void setSelectState() {
setSelect.setEnabled(true);
mouseListner.setSelectState();
//DEK (Federico Granata)
// mainWindow.getAlbero().setSelectedButton(true);
}
public AbstractJmtAction getDeleteAction() {
return actionDelete;
}
public void activateSelect() {
mainWindow.getComponentBar().setSelect();
}
public void enableCutAction(boolean state) {
actionCut.setEnabled(state);
}
public void enablePasteAction(boolean state) {
actionPaste.setEnabled(state);
}
public void enableCopyAction(boolean state) {
actionCopy.setEnabled(state);
}
public void enableDeleteAction(boolean state) {
actionDelete.setEnabled(state);
}
public AbstractJmtAction getTakeScreenShot() {
return takeScreenShot;
}
public void setHandle(CellHandle handle) {
this.mouseListner.setHandle(handle);
}
public AbstractJmtAction getCloseModel() {
return closeModel;
}
public AbstractJmtAction getNewModel() {
return newModel;
}
public AbstractJmtAction getOpenHelp() {
return openHelp;
}
public AbstractJmtAction getOpenModel() {
return openModel;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -