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

📄 jtransition.java

📁 Rakiura JFern是一个非常轻型的带有模拟器的Petri网络框架
💻 JAVA
字号:
// This is copyrighted source file, part of Rakiura JFern package.// See the file LICENSE for copyright information and the terms and conditions// for copying, distributing and modifications of Rakiura JFern package.// Copyright (C) 1999-2002 by Mariusz Nowostawski and others  [http://www.rakiura.org]package org.rakiura.cpn.gui;/**/import java.awt.Point;import java.util.Random;import org.rakiura.cpn.Transition;import org.rakiura.cpn.event.TransitionEvent;import org.rakiura.cpn.event.TransitionFinishedEvent;import org.rakiura.cpn.event.TransitionListener;import org.rakiura.cpn.event.TransitionStartedEvent;import org.rakiura.cpn.event.TransitionStateChangedEvent;import org.rakiura.draw.figure.GroupFigure;import org.rakiura.draw.figure.RectangleFigure;import org.rakiura.draw.figure.TextFigure;/** * Represents the graphical transition view. * *<br><br> * JTransition.java<br> * Created: Mon Apr 15 14:36:07 2002<br> * *@author  <a href="mariusz@rakiura.org">Mariusz Nowostawski</a> *@version $Revision: 1.7 $ $Date: 2002/05/30 03:42:17 $ *@since 2.0 */public class JTransition extends GroupFigure implements TransitionListener {  /**/  private static Random random = new Random(System.currentTimeMillis());  /**/  private Transition transition;  /**/  private RectangleFigure rectangle;  final private long DELAY = 1;  /**   * Creates a new <code>JTransition</code> instance.   * @param aTransition a <code>Transition</code> value   */  public JTransition(final Transition aTransition) {    this.rectangle = new RectangleFigure(new Point(8, 15), new Point(50, 30));    this.rectangle.setFillColor(java.awt.Color.yellow);    this.add(this.rectangle);    final TextFigure name = new TextFigure(aTransition.getName(), false);    this.add(name);    moveBy(random.nextInt(350), random.nextInt(300));    this.transition = aTransition;    this.transition.addTransitionListener(this);  }  /**   * Returns the gui rectangle handle.   *@return the rectangle figure.   */  public RectangleFigure getRectangle() {    return this.rectangle;  }  /**   * Event notification. This method throws runtime exception.   * @param anEvent a <code>TransitionEvent</code> value   */  public void notify(final TransitionEvent anEvent) {    throw new RuntimeException("Unknown event type: " + anEvent.getClass() + " " + anEvent);  }  /**   * Event notification. This method makes the transition green.   * @param anEvent a <code>TransitionStartedEvent</code> value   */  public void notify(final TransitionStartedEvent anEvent) {    this.rectangle.setFillColor(java.awt.Color.green);    this.rectangle.changed();    changed();    try {      Thread.sleep(DELAY);    } catch (InterruptedException e) {}  }  /**   * Event notification. This method makes the transition yellow again.   * @param anEvent a <code>TransitionFinishedEvent</code> value   */  public void notify(final TransitionFinishedEvent anEvent) {    this.rectangle.setFillColor(java.awt.Color.yellow);    changed();    try {      Thread.sleep(DELAY);    } catch (InterruptedException e) {}  }  /**   * Event notification. This method makes the transition yellow again.   * @param anEvent a <code>TransitionStateChangedEvent</code> value   */  public void notify(final TransitionStateChangedEvent anEvent) {    if (anEvent.getTransition().isEnabled())      this.rectangle.setFillColor(java.awt.Color.white);    else      this.rectangle.setFillColor(java.awt.Color.yellow);  }} // JTransition//////////////////// end of file ////////////////////

⌨️ 快捷键说明

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