public void paint(Graphics g, JComponent c) { //若是当前被设计的组件不为空,则画出该组件来 if ((selected_components != null) &&!selected_components.isEmpty()) {布局 //若是当前选中的组件不为空,则画出他们的resizing边框来 if (selection_bounds != null) {url //若是当前正在选择组件,画出选择框来 private void paintResizing(Graphics g, JComponent c) {设计 //当前这些选中的组件是不是能够resize的component //带有布局管理器的容器组件内的组件不该该能resizeablehtm //另外若是所选择的组件跨了几个容器,它们也不该该能resizeable for (Component comp : selected_components) { Rectangle bounds = getRelativeBounds(comp); g.setColor(SELECTION_COLOR); int x = bounds.x + LEFT_PAD; //画出被选择组件的高亮边框 g.drawRect(x, y, w, h); if (resizable) { //若是是resizable,要画出其拖拽点矩形 drawResizingThumbs(g, x, y, w, h); private void paintDesignedComponent(Graphics g, JComponent c) { //这儿和之前讲过的同样,再使用Renderer技术时,要保证渲染组件是非缓冲的 disableBuffer(component, dbcomponents); int width = component.getWidth(); //建立相对根组件的剪切窗口图形对象 //使用跟组件渲染 component.paint(clipg); int x = LEFT_PAD - BORDER_THICK; //画出外边框来 areaBorder.paintBorder(component, g, x, y, w, h); |
时间很少了,今天先写到这儿吧。明天再详细讲述如何给界面设计工具加上选择、键盘、编辑等功能。这儿有初步的代码下载。已经能进行组件选择、拖放、添加、删除、复制、粘贴等简单的编辑动做了。下面是个截图:
更新:
这两天作了进一步重构,添加了一些新的功能和注释。如今的设计界面工具能够进行布局管理,添加了添加提示、添加、删除、复制、剪切、粘帖、对齐等功能,把组件选择工具条作了修改,能够添加容器类等等。下面是几个截图: