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

📄 simparambool.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.component;

import janetsim.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SimParamBool extends SimParameter implements ItemListener,java.io.Serializable {
  private boolean value;
  private boolean isEditable;
  private transient JCheckBox jcomp=null;
  
  public SimParamBool(String aName,SimComponent comp,long creationTick,boolean isLoggable,
                        boolean editable,boolean val) {
    super(aName,comp,creationTick,isLoggable);
    value=val;
    isEditable=editable;
  }

////////////// possible overrides //////////////////////////

  public boolean getValue() {
    return value;
  }

  public void setValue(boolean val) {
    value = val;
    if(jcomp!=null) scheduleUpdate();
  }

  //helper for thread safe GUI update
  private void scheduleUpdate() {
    Runnable r=new Runnable() {
      public void run() {
        jcomp.setSelected(value);
      }
    };
    SwingUtilities.invokeLater(r);
  }

  //helper setValue() with auto-update given current tick and a minimum
  //interval between updates (interval must be >0 to have effect)
  public void setValue(boolean val,long tick,long interval) {
    setValue(val);
    if(interval>0 && (tick-getLastUpdateTick() >= interval)) update(tick);
  }

  public boolean globalSetValue(String val) {
    if(!isEditable) return false;

    if(val.equals("true") || val.equals("t") || val.equals("1")) setValue(true);
    else if(val.equals("false") || val.equals("f") || val.equals("0")) setValue(false);
    else return false;

    return true;
  }

  protected void doMeter(long tick) {
    theMeter.add(tick,(value?1.0:0));
  }

  public String getString() {
    return String.valueOf(value);
  }

  public JComponent getJComponent() {
    if(jcomp==null) {
      jcomp=new JCheckBox("",value);
      jcomp.setBorder(BorderFactory.createCompoundBorder(
              BorderFactory.createLineBorder(Color.black),
              BorderFactory.createEmptyBorder(0,5,0,5)));
      jcomp.setEnabled(isEditable);
      if(isEditable)
        jcomp.addItemListener(this);
    }
    return jcomp;
  }

  public void itemStateChanged(ItemEvent e) {
    if(e.getStateChange()==ItemEvent.SELECTED) value = true;
    else value = false;
  }
}

⌨️ 快捷键说明

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