Browse Source
Merge in DESIGN/design from ~YUAN.WANG/design:feature/10.0 to feature/10.0 * commit '48d6dc686ca358efd0892b6a6125a05860e847a1': REPORT-36985 改了一点代码 REPORT-36985 删除无用依赖,格式化 REPORT-36985 删除无用依赖,格式化 REPORT-36985 删除无用依赖 REPORT-36985 代码提交 组件树删除优化和选择组件时让其浮于顶层 REPORT-36985 代码提交 组件树删除优化和选择组件时让其浮于顶层research/11.0
Yuan.Wang
4 years ago
21 changed files with 482 additions and 10 deletions
@ -0,0 +1,70 @@
|
||||
package com.fr.design.mainframe.widget.topxcreator; |
||||
|
||||
import com.fr.design.designer.creator.XCreator; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
import com.fr.design.mainframe.WidgetPropertyPane; |
||||
import com.fr.design.utils.ComponentUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
/** |
||||
* @Author: Yuan.Wang |
||||
* @Date: 2020/8/31 |
||||
*/ |
||||
public class BasicTopXCreator extends JComponent { |
||||
private FormDesigner designer; |
||||
private XCreator creator; |
||||
|
||||
public BasicTopXCreator(XCreator creator) { |
||||
this.designer = WidgetPropertyPane.getInstance().getEditingFormDesigner(); |
||||
this.creator = creator; |
||||
init(); |
||||
} |
||||
|
||||
private void init() { |
||||
setOpaque(false); |
||||
setBackground(null); |
||||
setLayout(null); |
||||
setBounds(calculateBounds()); |
||||
addComponent(); |
||||
} |
||||
|
||||
|
||||
//子类可能会重写该方法
|
||||
protected void resetSize(Rectangle bounds) { |
||||
//do nothing
|
||||
} |
||||
|
||||
protected void addComponent() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 重新设置组件大小 |
||||
* */ |
||||
public void resizeTopXCreator() { |
||||
Rectangle bounds=calculateBounds(); |
||||
setBounds(bounds); |
||||
resetSize(bounds); |
||||
} |
||||
|
||||
public void displayCoverPane(MouseEvent e, boolean visible) {} |
||||
|
||||
/** |
||||
* 计算显示大小 |
||||
* */ |
||||
private Rectangle calculateBounds() { |
||||
Rectangle rect = ComponentUtils.getRelativeBounds(creator); |
||||
Rectangle bounds = new Rectangle(0, 0, creator.getWidth(), creator.getHeight()); |
||||
bounds.x += (rect.x - designer.getHorizontalScaleValue()); |
||||
bounds.y += (rect.y - designer.getVerticalScaleValue()); |
||||
return bounds; |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g) { |
||||
super.paint(g); |
||||
} |
||||
} |
@ -0,0 +1,49 @@
|
||||
package com.fr.design.mainframe.widget.topxcreator; |
||||
|
||||
import com.fr.design.designer.creator.XCreator; |
||||
import com.fr.design.mainframe.CoverReportPane; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
/** |
||||
* @Author: Yuan.Wang |
||||
* @Date: 2020/8/26 |
||||
*/ |
||||
public class TopXCreator extends BasicTopXCreator { |
||||
|
||||
private final CoverReportPane coverPanel; |
||||
|
||||
public TopXCreator(XCreator creator) { |
||||
super(creator); |
||||
coverPanel = new CoverReportPane(); |
||||
init(); |
||||
} |
||||
|
||||
private void init() { |
||||
coverPanel.setSize(getSize()); |
||||
coverPanel.setVisible(false); |
||||
add(coverPanel); |
||||
} |
||||
|
||||
|
||||
protected void resetSize(Rectangle bounds) { |
||||
coverPanel.setSize(getSize()); |
||||
} |
||||
|
||||
/** |
||||
* 设置是否显示蒙层 |
||||
* */ |
||||
public void displayCoverPane(boolean visible) { |
||||
coverPanel.setVisible(visible); |
||||
} |
||||
|
||||
/** |
||||
* 依据鼠标事件和visible设置是否显示蒙层 |
||||
* */ |
||||
public void displayCoverPane(MouseEvent event, boolean visible) { |
||||
boolean isVisible = visible && getBounds().contains(event.getX(), event.getY()); |
||||
coverPanel.setVisible(isVisible); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,101 @@
|
||||
package com.fr.design.mainframe.widget.topxcreator; |
||||
|
||||
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; |
||||
|
||||
import java.awt.event.MouseEvent; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
|
||||
/** |
||||
* 需要显示顶层的组件层 |
||||
* |
||||
* @Author: Yuan.Wang |
||||
* @Date: 2020/8/25 |
||||
*/ |
||||
public class TopXCreators extends JComponent { |
||||
final private FormDesigner designer; |
||||
|
||||
public TopXCreators(FormDesigner designer) { |
||||
this.designer = designer; |
||||
init(); |
||||
} |
||||
|
||||
private void init() { |
||||
setLayout(null); |
||||
setVisible(false); |
||||
setBackground(null); |
||||
setOpaque(false); |
||||
designer.addDesignerEditListener(e -> { |
||||
if (e.getCreatorEventID() == DesignerEvent.CREATOR_EDITED) { |
||||
refresh(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 选中的组件有变化时刷新 |
||||
*/ |
||||
public void refresh() { |
||||
removeAll(); |
||||
addXCreators(); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g) { |
||||
setSize(designer.getSize()); |
||||
resizeTopXCreators(); |
||||
super.paint(g); |
||||
} |
||||
|
||||
@Override |
||||
public void setVisible(boolean aFlag) { |
||||
super.setVisible(aFlag); |
||||
for (int i = 0, count = getComponentCount(); i < count; i++) { |
||||
if (getComponent(i) instanceof TopXCreator) { |
||||
TopXCreator xCreator = (TopXCreator) getComponent(i); |
||||
xCreator.displayCoverPane(aFlag); |
||||
} |
||||
} |
||||
repaint(); |
||||
} |
||||
|
||||
/** |
||||
* 依据MouseEvent坐标来设置是否显示蒙层 |
||||
*/ |
||||
public void displayCoverPane(MouseEvent e) { |
||||
for (int i = 0, count = getComponentCount(); i < count; i++) { |
||||
BasicTopXCreator xCreator = (BasicTopXCreator) getComponent(i); |
||||
xCreator.displayCoverPane(e, isVisible()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 加入被选择的组件 |
||||
*/ |
||||
private void addXCreators() { |
||||
SelectionModel selectionModel = designer.getSelectionModel(); |
||||
XCreator[] xCreators = selectionModel.getSelection().getSelectedCreators(); |
||||
for (XCreator creator : xCreators) { |
||||
BasicTopXCreator topXCreator = creator.getTopXCreator(); |
||||
if (topXCreator != null) { |
||||
add(topXCreator); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 更新顶层组件的位置和大小 |
||||
*/ |
||||
private void resizeTopXCreators() { |
||||
for (int i = 0, count = getComponentCount(); i < count; i++) { |
||||
BasicTopXCreator topXCreator = (BasicTopXCreator) getComponent(i); |
||||
topXCreator.resizeTopXCreator(); |
||||
} |
||||
repaint(); |
||||
} |
||||
} |
Loading…
Reference in new issue