📄 simguicontrol.java
字号:
/*
* @(#)SimGuiControl.java ver 1.2 6/20/2005
*
* Copyright 2005 Weishuai Yang (wyang@cs.binghamton.edu).
* All rights reserved.
*
*/
package gps.gui;
import gps.Simulator;
import gps.network.graph.Graph;
import gps.network.graph.GraphException;
import gps.util.MyFileChooser;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
* Control object of M/V/C, all the global commands are directed to this object
*
*
* @author Weishuai Yang
* @version 1.2, 6/20/2005
*/
public class SimGuiControl {
/**
* reference to gui
*/
private SimGui mSimGui;
/**
* reference to graph
*/
private Graph mGraph=null;
/**
* reference to graph panel
*/
private GraphPanel mGraphPanel=null;
/**
* reference to control panel
*/
private ControlPanel mControlPanel=null;
/**
* file chooser
*/
private MyFileChooser fileChooser = new MyFileChooser();
/**
* constructs new control object with gui reference
* @param sg reference to SimGui
*/
public SimGuiControl(SimGui sg){
mSimGui=sg;
}
/**
* set graph panel
* @param g reference to graph panel
*/
public void setGraphPanel(JPanel g){
mGraphPanel=(GraphPanel)g;
}
/**
* set control panel
* @param i reference to control panel
*/
public void setControlPanel(JPanel i){
mControlPanel=(ControlPanel)i;
}
/**
* get graph panel
* @return graph panel object
*/
public GraphPanel getGraphPanel(){
return mGraphPanel;
}
/**
* get control panel
* @return control panel object
*/
public ControlPanel getControlPanel(){
return mControlPanel;
}
/**
* get gui
* @return gui object
*/
public SimGui getSimGui(){
return mSimGui;
}
/**
* opens configuration file
*/
public void openConf(){
mControlPanel.actionPerformed(new ActionEvent(this,0,"Load"));
}
/**
* saves configuration file
*/
public void saveConf(){
mControlPanel.actionPerformed(new ActionEvent(this,0,"Save"));
}
/**
* loads initial value to gui
*/
public void loadInit(){
String path=Simulator.getInstance().getProperties().getProperty("GraphFile");
if((path!=null)&&(path.length()!=0))
openGraph(path);
mControlPanel.loadInit();
}
/**
* opens graph file through gui
*/
public void openGraph(){
fileChooser.setFileFilter( MyFileChooser.graphFilter );
int res = fileChooser.showOpenDialog( mSimGui );
if ( res==JFileChooser.CANCEL_OPTION )
return;
File file = fileChooser.getSelectedFile();
openGraph(file.getAbsolutePath());
}
/**
* opens graph file
* @param filepath path to the graph file
*/
public boolean openGraph(String filepath){
try {
mGraph=Graph.fromALTFile(filepath);
}
catch ( GraphException e ) {
JOptionPane.showMessageDialog(mSimGui.getFrame(),"File format error!", "Error!", JOptionPane.ERROR_MESSAGE);
mControlPanel.loadFailed();
return false;
}
catch ( Exception e ) {
e.printStackTrace();
mControlPanel.loadFailed();
return false;
}
mGraph.setGraphFile(filepath);
mGraphPanel.setGraph(mGraph);
mGraphPanel.repaint();
mSimGui.setStatusBar("Simulation Graph Loaded. ");
mControlPanel.loadSuccess();
return true;
}
/**
* opens resume file, not implemented yet
*/
public void openResume(){
/*
fileChooser.setFileFilter( fileChooser.resumeFilter );
int res = fileChooser.showOpenDialog( mSimGui );
if ( res==JFileChooser.CANCEL_OPTION ) return;
File file = fileChooser.getSelectedFile();
try {
//AltFileProcessor.readFile( file, mSimGui );
//drawPanel.repaint();
}
catch ( Exception e ) {
e.printStackTrace();
}
*/
}
/**
* run simulation
*/
public void run(){
mControlPanel.actionPerformed(new ActionEvent(this,0,"Run"));
}
/**
* pause simulation
*/
public void stop(){
mControlPanel.actionPerformed(new ActionEvent(this,0,"Pause"));
}
/**
* resume simulation
*/
public void resume(){
mControlPanel.actionPerformed(new ActionEvent(this,0,"Resume"));
}
/**
* terminate simulation
*/
public void terminate(){
mControlPanel.actionPerformed(new ActionEvent(this,0,"Stop"));
}
/**
* quit simulator
*/
public void quit(){
Simulator.getInstance().stopIt();
mSimGui.quit();
}
/**
* setting options
*/
public void options(){ }
/**
* simulator information
*/
public void about(){
JOptionPane.showMessageDialog(getSimGui().getFrame(),
"General P2P Simulator\nVersion "+getVersion()+"\nWeishuai Yang (wyang@cs.binghamton.edu)\nCopyright 2005 All rights reserved",
"About", JOptionPane.INFORMATION_MESSAGE);
}
/**
* reset progress bar
*/
public void resetProgress(){
mSimGui.resetProgress();
}
/**
* gets simulator version
*
* @return version
*/
public double getVersion(){
return 1.1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -