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

📄 simcomponent.java

📁 一个小型网络仿真器的实现
💻 JAVA
字号:
/*
   JaNetSim  ---  Java Network Simulator
   -------------------------------------

   This software was developed at the Network Research Lab, Faculty of
   Computer Science and Information Technology (FCSIT), University of Malaya.
   This software may be used and distributed freely. FCSIT assumes no responsibility
   whatsoever for its use by other parties, and makes no guarantees, expressed or
   implied, about its quality, reliability, or any other characteristic.

   We would appreciate acknowledgement if the software is used.

   FCSIT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
   DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
   FROM THE USE OF THIS SOFTWARE.
*/

package janetsim;

import java.awt.*;

public class SimComponent implements java.io.Serializable,SimListener {
  private String name;
  private String compClass; //component class
  private java.util.List params;
  private java.util.List neighbors;
  protected transient Sim theSim=null;

//for GUI purpose
  protected transient Image image=null;
  private int x,y; //center of the image in SimPanel
  private boolean selected=false;

  //constructor
  public SimComponent(String aName,String aClass,Sim aSim,int locx,int locy) {
    name = aName;
    compClass = aClass;
    theSim = aSim;
    x = locx;
    y = locy;

    neighbors = new java.util.ArrayList();
    params = new java.util.ArrayList();
  }

//////////////////// property methods ///////////////////////

  public final void setSim(Sim aSim) {
    theSim = aSim;
  }
  public final Sim getSim() {
    return theSim;
  }
  public final String getName() {
    return name;
  }
  public final String getCompClass() {
    return compClass;
  }
  public final int getX() {
    return x;
  }
  public final int getY() {
    return y;
  }
  public final void setLocation(int locx,int locy) {
    x = locx;
    y = locy;
  }
  public final boolean isSelected() {
    return selected;
  }
  public final void setSelected(boolean sel) {
    selected = sel;
  }
  public final SimParameter [] getParameters() {
    return (SimParameter[])params.toArray(new SimParameter[0]);
  }
  public final void addParameter(SimParameter parm) {
    params.add(parm);
    theSim.notifyParamsChange(this);
  }
  public final void addParameters(java.util.List parms) {
    params.addAll(parms);
    theSim.notifyParamsChange(this);
  }
  public final void removeParameter(SimParameter parm) {
    params.remove(parm);
    theSim.notifyParamsChange(this);
  }
  public final void removeParameters(java.util.List parms) {
    params.removeAll(parms);
    theSim.notifyParamsChange(this);
  }

/////////////////// connection methods ///////////////////////

  public final void addNeighbor(SimComponent comp) {
    neighbors.add(comp);
    neighborAdded(comp);
  }
  public final void removeNeighbor(SimComponent comp) {
    if(neighbors.contains(comp)) {
      neighbors.remove(comp);
      neighborRemoved(comp);
    }
  }
  public final void removeNeighbors(java.util.List comps) {
    for(int i=0;i<comps.size();i++) {
      SimComponent comp=(SimComponent)comps.get(i);
      removeNeighbor(comp);
    }
  }
  public final SimComponent[] getNeighbors() {
    return (SimComponent[])neighbors.toArray(new SimComponent[0]);
  }
  public final int neighborCount() {
    return neighbors.size();
  }
  public final SimComponent neighbor(int i) {
    return (SimComponent)neighbors.get(i);
  }


///////////////////////// overridables ////////////////////////////////////

  public boolean isConnectable(SimComponent comp) {
    if(comp==this) return false;
    if(neighbors.contains(comp)) return false;
    return true;
  }
  protected void neighborAdded(SimComponent comp) {
  }
  protected void neighborRemoved(SimComponent comp) {
  }

///////////////////// GUI Helpers ///////////////////

  public Image getImage(Component refcomp) {
    if(image==null) {
    //prepare the default image (name in a box)
      image=refcomp.createImage(theSim.DEFAULT_COMP_WIDTH,theSim.DEFAULT_COMP_HEIGHT);
      Graphics g=image.getGraphics();
      g.setColor(Color.blue);
      g.fill3DRect(0,0,theSim.DEFAULT_COMP_WIDTH,theSim.DEFAULT_COMP_HEIGHT,true);
    }
    return image;
  }
  public Image setImage(Image anImage,Component refcomp) {
    Image oldimage=getImage(refcomp);
    image = anImage;
    return oldimage;
  }
  public boolean isTagged(int level) { //"tagging" support
    return false;
  }

////////////////////// SimCommand support ///////////////////////////////

  public SimCommand querySimCommand(int selectedCount) {
    return null;
  }

////////////////////////////////////////////////////////////////////////

//component info
  public Object compInfo(int infoid,SimComponent source,Object params) {
    return null;
  }

//copy operation
  public void copy(SimComponent comp) {
  }

//batch job support
  public void preprocess(int jobindex) {
  }
  public void postprocess(int jobindex) {
  }

//actions
  public void reset() {
  }
  public void start() {
  }
  public void pause() {
  }
  public void resume() {
  }

//action (SimListener method)
  public void action(SimEvent e) {
  }
}

⌨️ 快捷键说明

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