📄 subsystemmaker.java
字号:
package com.zcsoft.stock;/** * <p>Title: 串口通信</p> * <p>Description: 串口通信实验</p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: Zhicheng Software&Service Co. Ltd.</p> * @author unascribed * @version 1.0 */import com.zcsoft.image.ImageMaker;import java.net.URL;import java.util.*;import java.util.List;import java.awt.*;import java.beans.*;import javax.swing.*;/** 包含设备的子系统绘制器 */public class SubSystemMaker extends ImageMaker implements PropertyChangeListener{ List deviceMakers = new ArrayList(); private boolean underMinimumMode = true; private Dimension minimumSize = new Dimension(); private Point minimumLocation; private Point normalLocation = new Point(); private Dimension normalSize;// private Dimension minimumSize; public SubSystemMaker(URL backGroundImage) { super(backGroundImage); this.setXTranslatable(true); this.setYTranslatable(true); } /** * 添加属于该子系统的设备。设备的绘制位置原点为该子系统的所在矩形区域的左上角。 * @param dm */ public void addDeviceMakers(DeviceMaker dm) { this.deviceMakers.add(dm); } public void doubleClick(Point location) { this.setUnderMinimumMode( !this.underMinimumMode ); } /** * 在超类实现的基础上,绘制上面的设备。 */ protected void paint(Graphics2D g2, int width, int height) { if (this.underMinimumMode) { return; } super.paint(g2, width, height); List deviceMakers = this.deviceMakers; Rectangle clipBounds = g2.getClipBounds(); DeviceMaker one; for (int i = deviceMakers.size() - 1; i >= 0 ; i--) { one = (DeviceMaker)deviceMakers.get(i); if (one.intersects(clipBounds)) { one.paint(g2); } } } /** * 系统中某设备属性发生改变后,重新绘制该设备 * 此时需要完成相对坐标的转换。 * @param evt */ public void propertyChange(PropertyChangeEvent evt) { JComponent owner = this.getOwner(); if (owner != null) { Device source = (Device)evt.getSource(); Rectangle bounds = null; List deviceMakers = this.deviceMakers; for (int i = 0; i < deviceMakers.size(); i++) { DeviceMaker one = (DeviceMaker)deviceMakers.get(i); if (source.equals(one.getDevice())) { bounds = one.getRange(); break; } } if (bounds == null) // Should never happen { return; } if (evt.getPropertyName().equals("location")) { Point old = (Point)evt.getOldValue(); bounds = bounds.union(new Rectangle(old.x, old.y, bounds.width, bounds.height)); } RepaintManager.currentManager(owner).addDirtyRegion(owner , bounds.x + this.range.x, bounds.y + this.range.y , bounds.width, bounds.height); } } public void setNormalLocation(Point loc) { this.normalLocation.setLocation( loc ); } public void setMinimumSize(Dimension size) { this.minimumSize.setSize( size ); } public void setUnderMinimumMode(boolean yes) { if (this.underMinimumMode == yes) { return; } this.underMinimumMode = yes; Rectangle oldBounds = this.getRange(); if (yes) { this.normalLocation = this.getLocation(); this.setLocation(this.minimumLocation); this.setSize(this.minimumSize); } else//retreive to normal size { this.minimumLocation = this.getLocation(); this.setLocation(this.normalLocation); if (normalSize == null) { Image bgImage = this.getImage(); if (bgImage == null) { this.loadImage(); bgImage = this.getImage(); } if (bgImage != null) { normalSize = new Dimension(bgImage.getWidth(null), bgImage.getHeight(null)); } } this.setSize(normalSize); } this.getOwner().repaint(oldBounds); this.getOwner().repaint(this.range); } public boolean isUnderMinimumMode() { return underMinimumMode; } public Point getNormalLocation() { return normalLocation; } public Dimension getMinimumSize() { return minimumSize; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -