|
|
|
@ -1,14 +1,15 @@
|
|
|
|
|
package com.fr.design.mainframe; |
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
import com.fr.base.vcs.DesignerMode; |
|
|
|
|
import com.fr.common.inputevent.InputEventBaseOnOS; |
|
|
|
|
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.events.DesignerEditor; |
|
|
|
|
import com.fr.design.designer.beans.events.DesignerEvent; |
|
|
|
|
import com.fr.design.designer.beans.location.Direction; |
|
|
|
|
import com.fr.design.designer.beans.location.Location; |
|
|
|
|
import com.fr.design.designer.beans.models.DraggingModel; |
|
|
|
|
import com.fr.design.designer.beans.models.SelectionModel; |
|
|
|
|
import com.fr.design.designer.beans.models.StateModel; |
|
|
|
|
import com.fr.design.designer.creator.XBorderStyleWidgetCreator; |
|
|
|
@ -25,25 +26,18 @@ import com.fr.design.designer.creator.cardlayout.XCardAddButton;
|
|
|
|
|
import com.fr.design.designer.creator.cardlayout.XCardSwitchButton; |
|
|
|
|
import com.fr.design.designer.creator.cardlayout.XWCardLayout; |
|
|
|
|
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; |
|
|
|
|
import com.fr.design.form.util.XCreatorConstants; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.gui.imenu.UIPopupMenu; |
|
|
|
|
import com.fr.design.gui.xpane.ToolTipEditor; |
|
|
|
|
import com.fr.design.icon.IconPathConstants; |
|
|
|
|
import com.fr.design.utils.ComponentUtils; |
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
import com.fr.design.utils.gui.LayoutUtils; |
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
|
import com.fr.stable.Constants; |
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
|
import javax.swing.JComponent; |
|
|
|
|
import javax.swing.JPopupMenu; |
|
|
|
|
import javax.swing.JWindow; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import javax.swing.event.MouseInputAdapter; |
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.awt.Container; |
|
|
|
|
import java.awt.Cursor; |
|
|
|
|
import java.awt.Insets; |
|
|
|
@ -95,9 +89,6 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
private DesignerEditor<? extends JComponent> currentEditor; |
|
|
|
|
private XCreator currentXCreator; |
|
|
|
|
|
|
|
|
|
//备份开始拖动的位置和大小
|
|
|
|
|
private Rectangle dragBackupBounds; |
|
|
|
|
|
|
|
|
|
private int pressX; |
|
|
|
|
private int pressY; |
|
|
|
|
|
|
|
|
@ -121,40 +112,12 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
private XElementCase xElementCase; |
|
|
|
|
private XChartEditor xChartEditor; |
|
|
|
|
|
|
|
|
|
private JWindow promptWindow = new JWindow(); |
|
|
|
|
|
|
|
|
|
public EditingMouseListener(FormDesigner designer) { |
|
|
|
|
this.designer = designer; |
|
|
|
|
stateModel = designer.getStateModel(); |
|
|
|
|
selectionModel = designer.getSelectionModel(); |
|
|
|
|
UIButton promptButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Forbid_Drag_Into_Adapt_Pane"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); |
|
|
|
|
this.promptWindow.add(promptButton); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void promptUser(int x, int y, XLayoutContainer container) { |
|
|
|
|
if (!selectionModel.getSelection().getSelectedCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)) { |
|
|
|
|
promptWidgetForbidEnter(x, y, container); |
|
|
|
|
} else { |
|
|
|
|
cancelPromptWidgetForbidEnter(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void promptWidgetForbidEnter(int x, int y, XLayoutContainer container) { |
|
|
|
|
container.setBorder(BorderFactory.createLineBorder(Color.RED, Constants.LINE_MEDIUM)); |
|
|
|
|
int screenX = (int) designer.getArea().getLocationOnScreen().getX(); |
|
|
|
|
int screenY = (int) designer.getArea().getLocationOnScreen().getY(); |
|
|
|
|
this.promptWindow.setSize(promptWindow.getPreferredSize()); |
|
|
|
|
this.promptWindow.setPreferredSize(promptWindow.getPreferredSize()); |
|
|
|
|
promptWindow.setLocation(screenX + x + GAP, screenY + y + GAP); |
|
|
|
|
promptWindow.setVisible(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void cancelPromptWidgetForbidEnter() { |
|
|
|
|
designer.getRootComponent().setBorder(BorderFactory.createLineBorder(XCreatorConstants.LAYOUT_SEP_COLOR, Constants.LINE_THIN)); |
|
|
|
|
promptWindow.setVisible(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 按下 |
|
|
|
|
* |
|
|
|
@ -181,9 +144,6 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (dir == Location.outer) { |
|
|
|
|
if (designer.isDrawLineMode()) { |
|
|
|
|
designer.updateDrawLineMode(e); |
|
|
|
|
} else { |
|
|
|
|
if (selectionModel.hasSelectionComponent() |
|
|
|
|
&& selectionModel.getSelection().getRelativeBounds().contains( |
|
|
|
|
designer.getHorizontalScaleValue() + e.getX(), |
|
|
|
@ -193,7 +153,6 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
} else { |
|
|
|
|
stateModel.startSelecting(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
stateModel.startResizing(e); |
|
|
|
|
} |
|
|
|
@ -258,13 +217,6 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
private void mouseDraggingRelease(MouseEvent e) { |
|
|
|
|
// 当前鼠标所在的组件
|
|
|
|
|
XCreator hoveredComponent = designer.getComponentAt(e.getX(), e.getY()); |
|
|
|
|
if (designer.isWidgetsIntersect() && dragBackupBounds != null && hoveredComponent != null) { |
|
|
|
|
XCreator selectionXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); |
|
|
|
|
if (selectionXCreator != null) { |
|
|
|
|
selectionXCreator.setBounds(dragBackupBounds.x, dragBackupBounds.y, dragBackupBounds.width, dragBackupBounds.height); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
dragBackupBounds = null; |
|
|
|
|
// 拉伸时鼠标拖动过快,导致所在组件获取会为空
|
|
|
|
|
if (hoveredComponent == null && e.getY() < 0) { |
|
|
|
|
// bug63538
|
|
|
|
@ -285,7 +237,6 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
selectionModel.deleteSelection(); |
|
|
|
|
designer.setPainter(null); |
|
|
|
|
} |
|
|
|
|
cancelPromptWidgetForbidEnter(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -499,61 +450,56 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
if (DesignerMode.isAuthorityEditing()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
boolean shiftSelecting = e.isShiftDown(); |
|
|
|
|
boolean ctrlSelecting = InputEventBaseOnOS.isControlDown(e); |
|
|
|
|
int currentCursorType = this.designer.getCursor().getType(); |
|
|
|
|
boolean shiftResizing = e.isShiftDown() && ( Cursor.SW_RESIZE_CURSOR <= currentCursorType && currentCursorType <= Cursor.E_RESIZE_CURSOR); |
|
|
|
|
|
|
|
|
|
if ((shiftSelecting || ctrlSelecting) && !shiftResizing && !stateModel.isSelecting()) { |
|
|
|
|
stateModel.startSelecting(e); |
|
|
|
|
} |
|
|
|
|
// 如果当前是左键拖拽状态,拖拽组件
|
|
|
|
|
if (stateModel.dragable()) { |
|
|
|
|
if (SwingUtilities.isRightMouseButton(e)) { |
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
|
stateModel.dragging(e); |
|
|
|
|
// 获取e所在的焦点组件
|
|
|
|
|
XCreator hotspot = designer.getComponentAt(e.getX(), e.getY()); |
|
|
|
|
if (dragBackupBounds == null) { |
|
|
|
|
XCreator selectingXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); |
|
|
|
|
if (selectingXCreator != null) { |
|
|
|
|
dragBackupBounds = new Rectangle(selectingXCreator.getX(), selectingXCreator.getY(), selectingXCreator.getWidth(), selectingXCreator.getHeight()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isMultiKeySelectingDrag(e)) { |
|
|
|
|
stateModel.startSelecting(e); |
|
|
|
|
} |
|
|
|
|
// 拉伸时鼠标拖动过快,导致所在组件获取会为空
|
|
|
|
|
if (hotspot == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 获取焦点组件所在的焦点容器
|
|
|
|
|
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hotspot); |
|
|
|
|
//提示组件是否可以拖入
|
|
|
|
|
promptUser(e.getX(), e.getY(), container); |
|
|
|
|
} |
|
|
|
|
} else if (designer.isDrawLineMode()) { |
|
|
|
|
if (stateModel.prepareForDrawLining()) { |
|
|
|
|
stateModel.drawLine(e); |
|
|
|
|
} |
|
|
|
|
} else if (stateModel.isSelecting() && (selectionModel.getHotspotBounds() != null)) { |
|
|
|
|
// 如果是拖拽选择区域状态,则更新选择区域
|
|
|
|
|
|
|
|
|
|
if (isSelectionDrag()) { |
|
|
|
|
stateModel.changeSelection(e); |
|
|
|
|
} else { |
|
|
|
|
if ((lastPressEvent == null) || (lastXCreator == null)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (e.getPoint().distance(lastPressEvent.getPoint()) > minDragSize) { |
|
|
|
|
//参数面板和自适应布局不支持拖拽
|
|
|
|
|
if (lastXCreator.isSupportDrag()) { |
|
|
|
|
designer.startDraggingComponent(lastXCreator, lastPressEvent, e.getX(), e.getY()); |
|
|
|
|
} |
|
|
|
|
e.consume(); |
|
|
|
|
lastPressEvent = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
System.out.println("===set==="); |
|
|
|
|
designer.setDraggingModel(new DraggingModel() |
|
|
|
|
.designer(designer) |
|
|
|
|
.creator(lastXCreator) |
|
|
|
|
.lastPressEvent(lastPressEvent) |
|
|
|
|
.dragEvent(e)); |
|
|
|
|
XLayoutContainer container = designer.getDraggingHotspotLayout(); |
|
|
|
|
LayoutAdapter adapter = container.getLayoutAdapter(); |
|
|
|
|
adapter.dragging(designer.getDraggingModel()); |
|
|
|
|
|
|
|
|
|
e.translatePoint(oldX - e.getX(), oldY - e.getY()); |
|
|
|
|
designer.repaint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 当前拖拽是否是正在shift或者control拖拽一个选择框 |
|
|
|
|
* @param e |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private boolean isMultiKeySelectingDrag(MouseEvent e) { |
|
|
|
|
boolean shiftSelecting = e.isShiftDown(); |
|
|
|
|
boolean ctrlSelecting = InputEventBaseOnOS.isControlDown(e); |
|
|
|
|
int currentCursorType = this.designer.getCursor().getType(); |
|
|
|
|
boolean shiftResizing = e.isShiftDown() && ( Cursor.SW_RESIZE_CURSOR <= currentCursorType && currentCursorType <= Cursor.E_RESIZE_CURSOR); |
|
|
|
|
return (shiftSelecting || ctrlSelecting) && !shiftResizing && !stateModel.isSelecting(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 是否正在拖拽选择框 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private boolean isSelectionDrag() { |
|
|
|
|
return stateModel.isSelecting() && selectionModel.getHotspotBounds() != null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//当前编辑的组件是在布局中,鼠标点击布局外部,需要一次性将布局及其父布局都置为不可编辑
|
|
|
|
|
private void setTopLayoutUnEditable(XLayoutContainer clickedTopLayout, XLayoutContainer clickingTopLayout) { |
|
|
|
|
//双击的前后点击click为相同对象,过滤掉
|
|
|
|
@ -718,7 +664,6 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
if (designer.getCursor().getType() != Cursor.DEFAULT_CURSOR && !(e.isShiftDown() || InputEventBaseOnOS.isControlDown(e))) { |
|
|
|
|
designer.setCursor(Cursor.getDefaultCursor()); |
|
|
|
|
} |
|
|
|
|
cancelPromptWidgetForbidEnter(); |
|
|
|
|
e.translatePoint(oldX - e.getX(), oldY - e.getY()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|