📄 simobject.java
字号:
// $Id: SimObject.java,v 1.2.8.3 2003/08/26 09:08:11 cssharp Exp $/* tab:2 * * * "Copyright (c) 2000 and The Regents of the University * of California. All rights reserved. * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose, without fee, and without written * agreement is hereby granted, provided that the above copyright * notice and the following two paragraphs appear in all copies of * this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Authors: Nelson Lee * Date: December 09, 2002 * Desc: Template object for AdvSim * *//** * @author Nelson Lee */package net.tinyos.sim;import net.tinyos.sim.event.*;import java.awt.*;import java.awt.event.*;import java.util.Hashtable;public abstract class SimObject implements SimConst { protected Hashtable attrs = new Hashtable(); protected SimObjectPopupMenu popup; protected MotePanel motePanel; protected SimEventBus eventBus; protected SimState simState; protected boolean visible = true; protected int objectSize; private boolean selected = false; public SimObject(TinyViz tv, int objectSize, SimObjectPopupMenu popup) { this.objectSize = objectSize; this.popup = popup; this.motePanel = tv.getMotePanel(); this.eventBus = tv.getEventBus(); this.simState = tv.getSimState(); simState.addSimObject(this); } public void activatePopupMenu(MouseEvent e) { popup.setSimObjectSelected(this); motePanel.refresh(popup, e); } public void addAttribute(Attribute a) { synchronized (simState) { attrs.put(a.getClass().getName(), a); } } public void addAttribute(String name, Attribute a) { synchronized (simState) { attrs.put(name, a); } } public Attribute getAttribute(String name) { synchronized (simState) { return (Attribute)attrs.get(name); } } public void removeAttribute(String name) { synchronized (simState) { attrs.remove(name); } } public boolean isSelected() { synchronized (simState) { return selected; } } public void setSelected() { synchronized (simState) { selected = true; } } public void setUnselected() { synchronized (simState) { selected = false; } } public boolean isVisible() { synchronized (simState) { return visible; } } public void setVisible() { synchronized (simState) { visible = true; } } public void setNotVisible() { synchronized (simState) { visible = false; } } public int getObjectSize() { // Kind of overkill with the synchronization, b/c there are no functions // for changing objectSize synchronized (simState) { return objectSize; } } // function used by MouseHandler to determine if an object has been selected by clicking public abstract boolean pointInSimObjectSpace(int windowX, int windowY, CoordinateTransformer cT); // function used by MouseHandler when object is selected and has been dragged a certain distance (dx, dy) public abstract void moveSimObject(int dx, int dy, CoordinateTransformer cT); // this method is used by MouseHandler to determine if someone's been selected by pressing and dragging public abstract boolean simObjectInQuad(double x1, double y1, double x2, double y2, CoordinateTransformer cT); public abstract void addCoordinateChangedEvent();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -