📄 jplace.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.Place;import org.rakiura.cpn.Multiset;import org.rakiura.cpn.event.PlaceListener;import org.rakiura.cpn.event.PlaceEvent;import org.rakiura.cpn.event.TokensAddedEvent;import org.rakiura.cpn.event.TokensRemovedEvent;import org.rakiura.draw.figure.EllipseFigure;import org.rakiura.draw.figure.TextFigure;import org.rakiura.draw.figure.GroupFigure;/** * Represents graphical place view. * *<br><br> * JPlace.java<br> * Created: Mon Apr 15 14:27:20 2002<br> * *@author <a href="mariusz@rakiura.org">Mariusz Nowostawski</a> *@version $Revision: 1.6 $ $Date: 2002/05/30 03:42:17 $ *@since 2.0 */public class JPlace extends GroupFigure implements PlaceListener { /**/ private static Random random = new Random(System.currentTimeMillis()); /**/ private Place place; /**/ private EllipseFigure circle; /**/ private TextFigure name; /**/ private TextFigure tokensText; /**/ private TextFigure count; /** * Creates a new <code>JPlace</code> instance. * @param aPlace a <code>Place</code> value */ public JPlace(final Place aPlace) { this.circle = new EllipseFigure(new Point(20, 15), new Point(40, 35)); this.circle.setFillColor(java.awt.Color.yellow); this.count = new TextFigure("" + aPlace.getTokens().size(), false); this.count.moveBy(26, 17); this.tokensText = new TextFigure("", false); this.tokensText.moveBy(26, 21); updateTokensText(aPlace.getTokens()); this.name = new TextFigure("" + aPlace.getName(), false); this.name.moveBy(10, 0); this.add(this.circle); this.add(this.name); this.add(this.count); this.add(this.tokensText); moveBy(random.nextInt(350), random.nextInt(300)); this.place = aPlace; this.place.addPlaceListener(this); } /** * Returns the circular figure representing this place. * @return an <code>EllipseFigure</code> value */ public EllipseFigure getCircle() { return this.circle; } /** * Event notification. This method makes the token green * for a moment, and updates the tokens count. * @param anEvent a <code>PlaceEvent</code> value */ public void notify(final PlaceEvent anEvent) { this.count.setText("" + anEvent.getPlace().getTokens().size()); updateTokensText(anEvent.getPlace().getTokens()); this.circle.setFillColor(java.awt.Color.green); changed(); try { Thread.sleep(1000); } catch (InterruptedException e) {} this.circle.setFillColor(java.awt.Color.yellow); changed(); } public void notify(final TokensAddedEvent anEvent) { notify((PlaceEvent) anEvent); } public void notify(final TokensRemovedEvent anEvent) { notify((PlaceEvent) anEvent); } void updateTokensText(Multiset m) { final Object[] o = m.toArray(); String text = ""; for (int i = 0; i < o.length; i++) { text += o[i].toString() + "\n"; } this.tokensText.setText(text); }} // JPlace//////////////////// end of file ////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -