forked from fanruan/design
Yuan.Wang
4 years ago
21 changed files with 499 additions and 9 deletions
@ -0,0 +1,72 @@
|
||||
package com.fr.design.mainframe.widget.topxcreator; |
||||
|
||||
import com.fr.design.designer.creator.XCreator; |
||||
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 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; |
||||
|
||||
private JComponent editor; |
||||
|
||||
public BasicTopXCreator(XCreator creator) { |
||||
this.designer = WidgetPropertyPane.getInstance().getEditingFormDesigner(); |
||||
this.creator = creator; |
||||
init(); |
||||
} |
||||
|
||||
private void init() { |
||||
setOpaque(false); |
||||
setBackground(null); |
||||
setLayout(null); |
||||
setBounds(calculateBounds(creator)); |
||||
initEditor(); |
||||
if(editor!=null) { |
||||
add(editor); |
||||
} |
||||
} |
||||
|
||||
|
||||
//子类可能会重写该方法
|
||||
protected void resetSize(Rectangle bounds) { |
||||
//do nothing
|
||||
} |
||||
|
||||
protected void initEditor() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 重新设置组件大小 |
||||
* */ |
||||
public void resizeTopXCreator() { |
||||
Rectangle bounds=calculateBounds(creator); |
||||
setBounds(bounds); |
||||
resetSize(bounds); |
||||
} |
||||
|
||||
public void displayCoverPane(MouseEvent e, boolean visible) {} |
||||
|
||||
/** |
||||
* 计算显示大小 |
||||
* */ |
||||
private Rectangle calculateBounds(XCreator xCreator) { |
||||
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; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,54 @@
|
||||
package com.fr.design.mainframe.widget.topxcreator; |
||||
|
||||
import com.fr.design.designer.creator.XCreator; |
||||
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 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 setCoverPaneVisible(boolean visible) { |
||||
coverPanel.setVisible(visible); |
||||
} |
||||
|
||||
public void displayCoverPane(MouseEvent event, boolean visible) { |
||||
if (!visible) { |
||||
setVisible(false); |
||||
return; |
||||
} |
||||
Rectangle rect = getBounds(); |
||||
if (rect.contains(event.getX(), event.getY())) { |
||||
coverPanel.setVisible(true); |
||||
} else { |
||||
coverPanel.setVisible(false); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,95 @@
|
||||
package com.fr.design.mainframe.widget.topxcreator; |
||||
|
||||
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); |
||||
} |
||||
|
||||
/** |
||||
* 选中的组件有变化时刷新 |
||||
*/ |
||||
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.setCoverPaneVisible(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