⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protocolpanel.java

📁 p2p仿真
💻 JAVA
字号:
/*
 * @(#)ProtocolPanel.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.event.SimEventScheduler;
import gps.network.Topology;
import gps.network.graph.Graph;
import gps.protocol.Document;
import gps.protocol.Protocol;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Properties;

import javax.swing.JOptionPane;
import javax.swing.JPanel;


/**
 * the panel for protocol parameters
 *
 * @author  Weishuai Yang
 * @version 1.2,  6/20/2005
 */

public abstract class ProtocolPanel extends JPanel implements ActionListener {

	/**
	 * singleton reference to topology
	 */
	protected static Topology mTopology=Topology.getInstance();
	/**
	 * singleton reference to event scheduler
	 */
	protected static SimEventScheduler mScheduler=SimEventScheduler.getInstance();
	/**
	 * singleton reference to simulator object
	 */
    protected static Simulator mSim = Simulator.getInstance();
    
	/**
	 * protocol object
	 */
    protected Protocol mProtocol = null;
	/**
	 * protocol properties
	 */
    protected Properties mProtocolProperties = null;

	/**
	 * reference to control panel
	 */
    protected ControlPanel mParent=null;
	/**
	 * protocol index, used to distinugish the protocol to be simulated
	 */
    protected int mProtocolIndex=0;

	/**
	 * constructs protocol panel
	 * @param p parent control panel
	 */

    public ProtocolPanel(ControlPanel p) {
        mParent = p;
        mSim.setPP(this);
        //mProtocolProperties=Config.getProperties();
    }


	/**
	 * put information in panel into protocol properties
	 */
    public void apply() {
        
        updateProtocolProperties();

        Graph g = mParent.getSimGuiControl().getGraphPanel().getGraph();
        if (g == null) {
            JOptionPane.showMessageDialog(mParent.getSimGuiControl().getSimGui().getFrame(), 
                    "Before applying parameters, please load graph file first!",
                    "Error!", JOptionPane.ERROR_MESSAGE);
            return;
        }        
		
		//reset();
        //mParent.getSimGuiControl().getGraphPanel().repaint();
    }


	/**
	 * resets protocol and simulator
	 */
	 
    public void reset(){
    	
    	mTopology.reset();

        mScheduler.reset();

        mProtocol.reset();

        Document.reset();

        mSim.reset();
    }
    
	/**
	 * to be called after simulation finished
	 */
    public void finishRun() {
        mParent.finishedRun();
    }


	/**
	 * gets graph object in graph panel
	 * @return graph object
	 */
    public Graph getGraph() {
        return mParent.getSimGuiControl().getGraphPanel().getGraph();
    }
    
	/**
	 * gets control object in GUI
	 * @return SimGuiControl object
	 */
    public SimGuiControl getSimGuiControl() {
        return mParent.getSimGuiControl();
    }

	/**
	 * Button handler - start
	 */
    public void start() {
    	mSim.GUIinit();
		Protocol p=getProtocol();
		p.setSimulatorProperties(mSim.getProperties());
      	mSim.confProtocol(p);
        mSim.GUIstart();

    }
    
	/**
	 * Button handler - resume
	 */
    public void resume() {
        mSim.resumeIt();
    }

	/**
	 * Button handler - pause
	 */
    public void pause() {
        mSim.pauseIt();
    }
	/**
	 * Button handler - stop
	 */
    public void stop() {
        mSim.stopIt();
    }

    
    /**
     * updates current running progress
     * @param a current value
     * @param b maximum possible value, 0 if not known
     */
    public void runProgress(int a, int b) {
        mParent.runProgress(a, b);
    }
    
    /**
     * make components in this panel
     */
    public void makeShape(){
        setBorder(new javax.swing.border.TitledBorder("Procotol Properties:"));
    }

    /**
     * abstract function actionPerformed
     */
    abstract public void actionPerformed(ActionEvent e);
    /**
     * abstract function setInitialValue
     */
    abstract public void setInitialValue();
    /**
     * abstract function loadConfig, loads configuration file
     */
    abstract public void loadConfig(File f);
    /**
     * abstract function loadSuccess, called after load success
     */
    abstract public void loadSuccess();
    /**
     * abstract function getProtocol, gets protocol to be simulated
     */
	abstract public Protocol getProtocol();
    /**
     * abstract function updateProtocolProperties
     */
    abstract public void updateProtocolProperties();



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -