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

📄 rectboundedshape.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
字号:
/* * RectBoundedShape.java * * Created on April 29, 2005, 4:48 PM */package flow.graph.gui.graph.item.unit;import java.awt.*;import java.awt.event.MouseEvent;/** * * @author hysun */public abstract class RectBoundedShape implements IShape {        protected Color color;        protected Stroke stroke;        protected int startX, startY, endX, endY;        protected RectBoundedShape(Color c, Stroke s, int x, int y) {        color = c;        stroke = s;        startX = endX = x;        startY = endY = y;    }        protected RectBoundedShape() {    }        public void processCursorEvent(MouseEvent e, int t) {        if (t != IShape.CURSOR_DRAGGED)            return;        int x = e.getX();        int y = e.getY();        if (e.isShiftDown()) {            regulateShape(x, y);        } else {            endX = x;            endY = y;        }    }        /**      * Regulate the bounding rectangle to a square with ending point      * coordinate derived from the specified x, y.     */    protected void regulateShape(int x, int y) {        int w = x - startX;        int h = y - startY;        int s = Math.min(Math.abs(w), Math.abs(h));        if (s == 0) {            endX = startX;            endY = startY;        } else {            endX = startX + s * (w / Math.abs(w));            endY = startY + s * (h / Math.abs(h));        }    }        public String getShapeData() {        int si = 0;        for (int i=0; i<DrawingBoard.STROKES.length; i++) {            if (stroke == DrawingBoard.STROKES[i]) {                si = i;                break;            }        }        StringBuffer buffer = new StringBuffer();        buffer.append(color.getRGB());        buffer.append(":");        buffer.append(si);        buffer.append(":");        buffer.append(startX);        buffer.append(":");        buffer.append(startY);        buffer.append(":");        buffer.append(endX);        buffer.append(":");        buffer.append(endY);        return buffer.toString();    }        public void setShapeData(String data) throws Exception {        String[] splits = data.split(":");        color = new Color(Integer.parseInt(splits[0]));        stroke = DrawingBoard.STROKES[Integer.parseInt(splits[1])];        startX = Integer.parseInt(splits[2]);        startY = Integer.parseInt(splits[3]);        endX = Integer.parseInt(splits[4]);        endY = Integer.parseInt(splits[5]);    }    }

⌨️ 快捷键说明

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