Browse Source

KERNEL-8568 设计器编辑按钮的实现方案不好

research/11.0
hades 3 years ago
parent
commit
2c1c557b97
  1. 27
      designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java
  2. 24
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  3. 13
      designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java
  4. 12
      designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java
  5. 14
      designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java
  6. 7
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardAddButton.java
  7. 7
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java
  8. 14
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java
  9. 8
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java
  10. 10
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTitleLayout.java
  11. 10
      designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java
  12. 21
      designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java

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

@ -267,23 +267,24 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
return;
}
FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
isEditing = e.getButton() == MouseEvent.BUTTON1 &&
(e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR);
displayCoverPane(!isEditing);
selectionModel.selectACreatorAtMouseEvent(e);
editingMouseListener.refreshTopXCreator(isEditing);
startEditing(editingMouseListener, designer, isEditing);
}
@Override
protected void startEditing(EditingMouseListener editingMouseListener, FormDesigner designer, boolean editing) {
displayCoverPane(!editing);
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
selectionModel.reset();
selectionModel.selectACreator(this);
editingMouseListener.refreshTopXCreator(editing);
if (editingMouseListener.stopEditing()) {
if (this != (XCreator) designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
if (isEditing) {
EastRegionContainerPane.getInstance().switchTabTo(EastRegionContainerPane.KEY_WIDGET_SETTINGS);
}
editingMouseListener.startEditing(this, isEditing ? adapter.getDesignerEditor() : null, adapter);
if (isEditing) {
EastRegionContainerPane.getInstance().switchTabTo(EastRegionContainerPane.KEY_WIDGET_SETTINGS);
}
isEditing = editing;
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, isEditing ? adapter.getDesignerEditor() : null, adapter);
if (editing) {
EastRegionContainerPane.getInstance().switchTabTo(EastRegionContainerPane.KEY_WIDGET_SETTINGS);
}
}
}

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

@ -7,8 +7,6 @@ import com.fr.base.GraphHelper;
import com.fr.base.vcs.DesignerMode;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.UpdateAction;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.events.DesignerEditor;
import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.ui.SelectedPopupDialog;
@ -28,10 +26,12 @@ import com.fr.design.plugin.DesignerPluginContext;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Constants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JFrame;
@ -546,21 +546,31 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
* @param e 鼠标点击事件
*/
public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){
FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
if (e.getClickCount() <= 1) {
selectionModel.selectACreatorAtMouseEvent(e);
}
editingMouseListener.refreshTopXCreator();
}
if (editingMouseListener.stopEditing() && this != designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
/**
*
* 进入编辑模式
*/
public void startEditing() {
FormDesigner designer = WidgetPropertyPane.getInstance().getEditingFormDesigner();
MouseListener[] listeners = designer.getMouseListeners();
if (ArrayUtils.isNotEmpty(listeners) && listeners[0] instanceof EditingMouseListener) {
startEditing(((EditingMouseListener) listeners[0]), designer, true);
}
}
protected void startEditing(EditingMouseListener editingMouseListener, FormDesigner designer, boolean editing) {
// do nothing
// 子类按需实现
}
/**
* 删除相关组件
*

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

@ -319,12 +319,13 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
private void switchTab(MouseEvent e, EditingMouseListener editingMouseListener) {
FormDesigner designer = editingMouseListener.getDesigner();
if (e.getButton() == MouseEvent.BUTTON1 &&
(e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR)) {
FormElementCaseContainerProvider component = (FormElementCaseContainerProvider) designer.getComponentAt(e);
//切换设计器
designer.switchTab(component);
}
startEditing(editingMouseListener, designer, e.getButton() == MouseEvent.BUTTON1 &&
(e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR));
}
@Override
protected void startEditing(EditingMouseListener editingMouseListener, FormDesigner designer, boolean editing) {
designer.switchTab(this);
}
@Override

12
designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java

@ -4,9 +4,11 @@
package com.fr.design.designer.creator;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.form.layout.FRLayoutManager;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.widget.editors.PaddingMarginEditor;
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor;
@ -586,4 +588,14 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
public void setDragInAble(boolean dragInAble) {
this.dragInAble = dragInAble;
}
@Override
protected void startEditing(EditingMouseListener editingMouseListener, FormDesigner designer, boolean editing) {
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
selectionModel.reset();
selectionModel.selectACreator(this);
setEditable(editing);
editingMouseListener.refreshTopXCreator(editing);
designer.repaint();
}
}

14
designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java

@ -490,21 +490,9 @@ public class XWAbsoluteLayout extends XLayoutContainer {
return;
}
FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
boolean isEditing = isEditable() ||
e.getButton() == MouseEvent.BUTTON1 && (designer.getCursor().getType() == Cursor.HAND_CURSOR || e.getClickCount() == 2);
setEditable(isEditing);
selectionModel.selectACreatorAtMouseEvent(e);
designer.repaint();
editingMouseListener.refreshTopXCreator(isEditing);
if (editingMouseListener.stopEditing()) {
if (this != designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, isEditing ? adapter.getDesignerEditor() : null, adapter);
}
}
startEditing(editingMouseListener, designer, isEditing);
}
/**

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

@ -1,8 +1,6 @@
package com.fr.design.designer.creator.cardlayout;
import com.fr.base.BaseUtils;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.creator.XButton;
import com.fr.design.designer.creator.XLayoutContainer;
@ -101,11 +99,6 @@ public class XCardAddButton extends XButton {
addTab(index);
this.tagLayout.adjustComponentWidth();
if (editingMouseListener.stopEditing()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
}
FormHierarchyTreePane.getInstance().refreshRoot();
//将焦点切换到新增的tab对应的tabfitLayout上
showNewTab(editingMouseListener,index);

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

@ -6,8 +6,6 @@ package com.fr.design.designer.creator.cardlayout;
import com.fr.base.BaseUtils;
import com.fr.base.GraphHelper;
import com.fr.base.background.ColorBackground;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.creator.XButton;
import com.fr.design.designer.creator.XCreator;
@ -32,7 +30,6 @@ import com.fr.general.ComparatorUtils;
import com.fr.general.FRFont;
import com.fr.general.act.TitlePacker;
import com.fr.general.cardtag.TemplateStyle;
import com.fr.stable.ProductConstants;
import com.fr.stable.unit.PT;
import javax.swing.*;
@ -176,10 +173,6 @@ public class XCardSwitchButton extends XButton {
tabFitLayout.setxCardSwitchButton(xCardSwitchButton);
selectionModel.setSelectedCreator(tabFitLayout);
if (editingMouseListener.stopEditing()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
}
if(SwingUtilities.isRightMouseButton(e)){
showPopupMenu(editingMouseListener, e, index, maxIndex);
}

14
designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java

@ -377,21 +377,9 @@ public class XWCardMainBorderLayout extends XWBorderLayout {
return;
}
FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
boolean isEditing = e.getButton() == MouseEvent.BUTTON1 &&
(designer.getCursor().getType() == Cursor.HAND_CURSOR || e.getClickCount() == 2);
setEditable(isEditing);
selectionModel.selectACreatorAtMouseEvent(e);
editingMouseListener.refreshTopXCreator(isEditing);
designer.repaint();
if (editingMouseListener.stopEditing()) {
if (this != designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, isEditing ? adapter.getDesignerEditor() : null, adapter);
}
}
startEditing(editingMouseListener, designer, isEditing);
}
/**

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

@ -6,7 +6,6 @@ package com.fr.design.designer.creator.cardlayout;
import com.fr.base.GraphHelper;
import com.fr.base.ScreenResolution;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRWCardTagLayoutAdapter;
import com.fr.design.designer.beans.models.SelectionModel;
@ -242,19 +241,12 @@ public class XWCardTagLayout extends XWHorizontalBoxLayout {
*/
public void respondClick(EditingMouseListener editingMouseListener,
MouseEvent e) {
FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
if (e.getClickCount() <= 1) {
selectionModel.selectACreatorAtMouseEvent(e);
}
editingMouseListener.refreshTopXCreator();
if (editingMouseListener.stopEditing()) {
if (this != designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
}
}
}
@Override

10
designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTitleLayout.java

@ -3,8 +3,6 @@
*/
package com.fr.design.designer.creator.cardlayout;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
@ -198,20 +196,12 @@ public class XWCardTitleLayout extends XWBorderLayout {
*/
public void respondClick(EditingMouseListener editingMouseListener,
MouseEvent e) {
FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
if (e.getClickCount() <= 1) {
selectionModel.selectACreatorAtMouseEvent(e);
}
editingMouseListener.refreshTopXCreator();
if (editingMouseListener.stopEditing()) {
if (this != designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
}
}
}
@Override

10
designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java

@ -11,11 +11,9 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.VerticalFlowLayout;
import com.fr.design.mainframe.CoverReportPane;
import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormDesigner;
import com.fr.form.ui.Widget;
import com.fr.general.IOUtils;
import com.fr.stable.ArrayUtils;
import javax.swing.*;
import java.awt.*;
@ -23,7 +21,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
@ -72,13 +69,8 @@ public class PopupControlPanel extends JPanel {
editButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int x = rectangle.x + rectangle.width / 2;
int y = rectangle.y + rectangle.height / 2;
XCreator childCreator = PopupControlPanel.this.creator.getEditingChildCreator();
MouseListener[] listeners = designer.getMouseListeners();
if (ArrayUtils.isNotEmpty(listeners) && listeners[0] instanceof EditingMouseListener) {
childCreator.respondClick(((EditingMouseListener) listeners[0]), new MouseEvent(childCreator, MouseEvent.MOUSE_CLICKED, e.getWhen(), e.getModifiers(), x, y, 2, false));
}
childCreator.startEditing();
}
});
return editButton;

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

@ -13,11 +13,9 @@ import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.itree.UITreeUI;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import java.awt.Rectangle;
import java.awt.event.MouseListener;
import java.util.Stack;
import java.util.function.Consumer;
import javax.swing.BorderFactory;
@ -387,7 +385,7 @@ public class ComponentTree extends JTree {
@Override
public void accept(XCreator creator) {
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1 && !designer.isFormParaDesigner()) {
startEditing(creator, e);
startEditing(creator);
}
}
});
@ -455,18 +453,11 @@ public class ComponentTree extends JTree {
* 组件进入编辑状态
*
* @param comp
* @param e
*/
private void startEditing(XCreator comp, MouseEvent e) {
private void startEditing(XCreator comp) {
designer.getSelectionModel().selectACreator(comp);
Rectangle rectangle = getRelativeBounds(comp);
int x = rectangle.x + rectangle.width / 2;
int y = rectangle.y + rectangle.height / 2;
XCreator creator = comp.getEditingChildCreator();
MouseListener[] listeners = designer.getMouseListeners();
if (ArrayUtils.isNotEmpty(listeners) && listeners[0] instanceof EditingMouseListener) {
responseClickAll(creator, (EditingMouseListener) listeners[0], new MouseEvent(creator, MouseEvent.MOUSE_CLICKED, e.getWhen(), e.getModifiers(), x, y, e.getClickCount(), false));
}
responseEditing(creator);
// 放到事件尾部执行
SwingUtilities.invokeLater(new Runnable() {
@Override
@ -488,10 +479,8 @@ public class ComponentTree extends JTree {
*
*
* @param creator
* @param editingMouseListener
* @param mouseEvent
*/
public void responseClickAll(XCreator creator, EditingMouseListener editingMouseListener, MouseEvent mouseEvent) {
private void responseEditing(XCreator creator) {
Stack<XCreator> stack = new Stack<>();
stack.push(creator);
while (creator.getParent() instanceof XCreator) {
@ -499,7 +488,7 @@ public class ComponentTree extends JTree {
stack.push(creator);
}
while (!stack.isEmpty()) {
stack.pop().respondClick(editingMouseListener, mouseEvent);
stack.pop().startEditing();
}
}

Loading…
Cancel
Save