Browse Source

REPORT-36985 代码提交 组件树删除优化和选择组件时让其浮于顶层

research/11.0
Yuan.Wang 4 years ago
parent
commit
72f8c306b7
  1. 2
      designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java
  2. 15
      designer-form/src/main/java/com/fr/design/designer/creator/XButton.java
  3. 8
      designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java
  4. 33
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  5. 7
      designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java
  6. 39
      designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java
  7. 1
      designer-form/src/main/java/com/fr/design/mainframe/CoverPane.java
  8. 11
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  9. 21
      designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/BasicTopXCreator.java
  10. 8
      designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreator.java
  11. 9
      designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreators.java

2
designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java

@ -84,7 +84,6 @@ public class SelectionModel {
selection.reset();
} else {
//按下Ctrl或者shift键时鼠标可以进行多选,两次点击同一控件就取消选中
//XCreator comp = designer.getComponentAt(e);
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout();
if (topLayout != null && !topLayout.isEditable()) {
comp = topLayout;
@ -98,7 +97,6 @@ public class SelectionModel {
comp = designer.getComponentAt(e);
}
// 获取e所在的组件
//XCreator comp = designer.getComponentAt(e);
selectACreator(comp);
}

15
designer-form/src/main/java/com/fr/design/designer/creator/XButton.java

@ -309,19 +309,4 @@ public class XButton extends XWidgetCreator {
}
}
/* @Override
public BasicTopCreator getTopXCreator(){
return new BasicTopXCreator(this) {
@Override
protected void initEditor() {
XButton(XButton.this.toData(),this.getSize()
}
}
//return new XButton((Button)this.toData(),this.getSize());
}*/
}

8
designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java

@ -366,20 +366,20 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
return new TopXChart(this);
}
private class TopXChart extends TopXCreator{
private class TopXChart extends TopXCreator {
private final DesignerEditor designerEditor;
public TopXChart(XCreator creator) {
super(creator);
designerEditor = creator.getDesignerEditor();
Rectangle bounds=getBounds();
Rectangle bounds = getBounds();
designerEditor.getEditorTarget().setBounds(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2);
}
/**
* 更新designerEditor的大小
* */
protected void resetSize(Rectangle bounds){
*/
protected void resetSize(Rectangle bounds) {
super.resetSize(bounds);
designerEditor.getEditorTarget().setBounds(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2);
}

33
designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java

@ -25,12 +25,12 @@ import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.stable.Constants;
import com.fr.stable.CoreGraphHelper;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.third.javax.annotation.Nullable;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.BorderLayout;
import java.awt.Color;
@ -39,6 +39,7 @@ import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.List;
@ -540,6 +541,8 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
selectionModel.selectACreatorAtMouseEvent(e);
}
editingMouseListener.refreshTopXCreator();
if (editingMouseListener.stopEditing() && this != designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
@ -807,8 +810,30 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
/**
* 获得该组件的顶层显示组件
*/
@Nullable
public BasicTopXCreator getTopXCreator() {
return null;
return new BasicTopXCreator(this){
@Override
protected void addComponent() {
BufferedImage image=getImage();
Icon icon = new ImageIcon(image);
JLabel jLabel = new JLabel(icon,JLabel.CENTER);
jLabel.setSize(getSize());
this.add(jLabel);
}
};
}
/**
* 获得组件的图像
* */
public BufferedImage getImage() {
BufferedImage image = CoreGraphHelper.createBufferedImage(getWidth(), getHeight());
Graphics g = image.createGraphics();
this.paint(g);
return image;
}
}

7
designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java

@ -384,11 +384,8 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
public TopXElementCase(XCreator creator) {
super(creator);
if (creator instanceof XElementCase) {
XElementCase elementCase = (XElementCase) creator;
imageLabel = elementCase.initImageBackground();
add(imageLabel);
}
imageLabel = initImageBackground();
add(imageLabel);
}
}

39
designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java

@ -236,12 +236,9 @@ public class ComponentTree extends JTree {
repaint();
}
public void expandTree() {
TreePath[] paths = getSelectedTreePath();
if (paths.length > 0) {
expandPath(getSelectedTreePath()[0]);
}
}
/**
* 获得树的展开路径
* */
public void getExpandNodes(List<TreePath> searchList) {
getExpandNodes((XLayoutContainer)designer.getTopContainer(),searchList);
}
@ -256,6 +253,10 @@ public class ComponentTree extends JTree {
}
}
}
/**
* 将树按照展开路径进行展开
* */
public void expandNodes(List<TreePath> list){
for(TreePath treePath:list) {
if (treePath.getLastPathComponent() instanceof XLayoutContainer) {
@ -267,32 +268,6 @@ public class ComponentTree extends JTree {
}
}
}
/* private void expandNode(JTree myTree, DefaultMutableTreeNode currNode, List<Object> list){
if(currNode.getParent()==null){
list.remove(0);
}
if(list.size()<=0) return;
int childCount = currNode.getChildCount();
String strNode = vNode.elementAt(0).toString();
DefaultMutableTreeNode child = null;
boolean flag=false;
for(int i=0; i<childCount; i++){
child = (DefaultMutableTreeNode)currNode.getChildAt(i);
if(strNode.equals(child.toString())){
flag=true;
break;
}
}
if(child != null&&flag){
vNode.removeElementAt(0);
if(vNode.size()>0){
expandNode(myTree,child, vNode);
}else{
myTree.expandPath(new TreePath(child.getPath()));
}
}
}*/
private TreePath buildTreePath(Component comp) {
ArrayList<Component> path = new ArrayList<Component>();

1
designer-form/src/main/java/com/fr/design/mainframe/CoverPane.java

@ -94,7 +94,6 @@ public class CoverPane extends JComponent {
int preferWidth = editButton.getPreferredSize().width;
int preferHeight = editButton.getPreferredSize().height;
editButton.setBounds((width - preferWidth) / 2, (height - preferHeight) / 2, preferWidth, preferHeight);
System.out.println(width+"---"+height);
}
@Override

11
designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

@ -846,12 +846,13 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
y -= creator.getY();
Rectangle rect = ComponentUtils.computeVisibleRect(creator);
// 判断是否处于交叉区域
if (isIntersectArea(x, y, rect)) {
if (creator instanceof XWTitleLayout) {
return creator.getEditingChildCreator();
}
return creator;
if (!isIntersectArea(x, y, rect)) {
continue;
}
if (creator instanceof XWTitleLayout) {
return creator.getEditingChildCreator();
}
return creator;
}
return null;
}

21
designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/BasicTopXCreator.java

@ -5,10 +5,12 @@ import com.fr.design.mainframe.CoverReportPane;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.utils.ComponentUtils;
import com.fr.stable.CoreGraphHelper;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
/**
* @Author: Yuan.Wang
@ -18,8 +20,6 @@ public class BasicTopXCreator extends JComponent {
private FormDesigner designer;
private XCreator creator;
private JComponent editor;
public BasicTopXCreator(XCreator creator) {
this.designer = WidgetPropertyPane.getInstance().getEditingFormDesigner();
this.creator = creator;
@ -30,11 +30,8 @@ public class BasicTopXCreator extends JComponent {
setOpaque(false);
setBackground(null);
setLayout(null);
setBounds(calculateBounds(creator));
initEditor();
if(editor!=null) {
add(editor);
}
setBounds(calculateBounds());
addComponent();
}
@ -43,7 +40,7 @@ public class BasicTopXCreator extends JComponent {
//do nothing
}
protected void initEditor() {
protected void addComponent() {
}
@ -51,7 +48,7 @@ public class BasicTopXCreator extends JComponent {
* 重新设置组件大小
* */
public void resizeTopXCreator() {
Rectangle bounds=calculateBounds(creator);
Rectangle bounds=calculateBounds();
setBounds(bounds);
resetSize(bounds);
}
@ -61,7 +58,7 @@ public class BasicTopXCreator extends JComponent {
/**
* 计算显示大小
* */
private Rectangle calculateBounds(XCreator xCreator) {
private Rectangle calculateBounds() {
Rectangle rect = ComponentUtils.getRelativeBounds(creator);
Rectangle bounds = new Rectangle(0, 0, creator.getWidth(), creator.getHeight());
bounds.x += (rect.x - designer.getHorizontalScaleValue());
@ -69,4 +66,8 @@ public class BasicTopXCreator extends JComponent {
return bounds;
}
@Override
public void paint(Graphics g) {
super.paint(g);
}
}

8
designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreator.java

@ -34,10 +34,16 @@ public class TopXCreator extends BasicTopXCreator {
coverPanel.setSize(getSize());
}
public void setCoverPaneVisible(boolean visible) {
/**
* 设置是否显示蒙层
* */
public void displayCoverPane(boolean visible) {
coverPanel.setVisible(visible);
}
/**
* 依据鼠标事件和visible设置是否显示蒙层
* */
public void displayCoverPane(MouseEvent event, boolean visible) {
if (!visible) {
setVisible(false);

9
designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreators.java

@ -1,5 +1,7 @@
package com.fr.design.mainframe.widget.topxcreator;
import com.fr.design.designer.beans.events.DesignerEditListener;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.mainframe.FormDesigner;
@ -29,6 +31,11 @@ public class TopXCreators extends JComponent {
setVisible(false);
setBackground(null);
setOpaque(false);
designer.addDesignerEditListener(e -> {
if (e.getCreatorEventID() == DesignerEvent.CREATOR_EDITED) {
refresh();
}
});
}
/**
@ -52,7 +59,7 @@ public class TopXCreators extends JComponent {
for (int i = 0, count = getComponentCount(); i < count; i++) {
if (getComponent(i) instanceof TopXCreator) {
TopXCreator xCreator = (TopXCreator) getComponent(i);
xCreator.setCoverPaneVisible(aFlag);
xCreator.displayCoverPane(aFlag);
}
}
repaint();

Loading…
Cancel
Save