|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
package com.fr.design.mainframe; |
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
import com.fr.design.beans.location.MoveUtils; |
|
|
|
|
import com.fr.design.designer.beans.AdapterBus; |
|
|
|
|
import com.fr.design.designer.beans.ComponentAdapter; |
|
|
|
|
import com.fr.design.designer.beans.events.DesignerEditor; |
|
|
|
@ -31,7 +30,6 @@ import java.awt.event.MouseEvent;
|
|
|
|
|
*/ |
|
|
|
|
public class EditingMouseListener extends MouseInputAdapter { |
|
|
|
|
|
|
|
|
|
private static final int INDEX = 0; |
|
|
|
|
private FormDesigner designer; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -56,6 +54,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
* 选择模型,存储当前选择的组件和剪切板 |
|
|
|
|
*/ |
|
|
|
|
private SelectionModel selectionModel; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取选择模型 |
|
|
|
|
* |
|
|
|
@ -65,10 +64,10 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
return selectionModel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private XCreator last_creator; |
|
|
|
|
private XCreator lastXCreator; |
|
|
|
|
private MouseEvent lastPressEvent; |
|
|
|
|
private DesignerEditor<? extends JComponent> current_editor; |
|
|
|
|
private XCreator current_creator; |
|
|
|
|
private DesignerEditor<? extends JComponent> currentEditor; |
|
|
|
|
private XCreator currentXCreator; |
|
|
|
|
|
|
|
|
|
//备份开始拖动的位置和大小
|
|
|
|
|
private Rectangle dragBackupBounds; |
|
|
|
@ -113,11 +112,11 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
|
|
|
|
|
private void promptWidgetForbidEnter(int x, int y, XLayoutContainer container) { |
|
|
|
|
container.setBorder(BorderFactory.createLineBorder(Color.RED, Constants.LINE_MEDIUM)); |
|
|
|
|
int screen_X = (int)designer.getArea().getLocationOnScreen().getX(); |
|
|
|
|
int screen_Y = (int)designer.getArea().getLocationOnScreen().getY(); |
|
|
|
|
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(screen_X + x + GAP, screen_Y + y + GAP); |
|
|
|
|
promptWindow.setLocation(screenX + x + GAP, screenY + y + GAP); |
|
|
|
|
promptWindow.setVisible(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -129,6 +128,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 按下 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
@ -139,9 +139,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
// 获取焦点,以便获取热键
|
|
|
|
|
designer.requestFocus(); |
|
|
|
|
} |
|
|
|
|
if (e.isPopupTrigger()) { |
|
|
|
|
// 为触发上下文菜单预留
|
|
|
|
|
} else if (e.getButton() == MouseEvent.BUTTON1) { |
|
|
|
|
if (e.getButton() == MouseEvent.BUTTON1) { |
|
|
|
|
|
|
|
|
|
Direction dir = selectionModel.getDirectionAt(e); |
|
|
|
|
if (!BaseUtils.isAuthorityEditing()) { |
|
|
|
@ -157,7 +155,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
designer.getArea().getHorizontalValue() + e.getX(), |
|
|
|
|
designer.getArea().getVerticalValue() + e.getY())) { |
|
|
|
|
lastPressEvent = e; |
|
|
|
|
last_creator = selectionModel.getSelection().getSelectedCreator(); |
|
|
|
|
lastXCreator = selectionModel.getSelection().getSelectedCreator(); |
|
|
|
|
} else { |
|
|
|
|
stateModel.startSelecting(e); |
|
|
|
|
} |
|
|
|
@ -170,6 +168,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 释放 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
@ -192,7 +191,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
lastPressEvent = null; |
|
|
|
|
last_creator = null; |
|
|
|
|
lastXCreator = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void mouseDraggingRelease(MouseEvent e) { |
|
|
|
@ -202,7 +201,6 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
XCreator selectionXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); |
|
|
|
|
if (selectionXCreator != null) { |
|
|
|
|
selectionXCreator.setBounds(dragBackupBounds.x, dragBackupBounds.y, dragBackupBounds.width, dragBackupBounds.height); |
|
|
|
|
// MoveUtils.hideForbidWindow();
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
dragBackupBounds = null; |
|
|
|
@ -231,17 +229,14 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 激活上下文菜单,待完善 |
|
|
|
|
* TODO 激活上下文菜单,待完善 |
|
|
|
|
* 6.56暂时不支持右键 bugid 8777 |
|
|
|
|
*/ |
|
|
|
|
private void trigger_popup(MouseEvent e) { |
|
|
|
|
|
|
|
|
|
private void triggerPopup(MouseEvent e) { |
|
|
|
|
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
|
|
|
|
|
|
|
|
|
if (creator == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JPopupMenu popupMenu = null; |
|
|
|
|
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, creator); |
|
|
|
|
popupMenu = adapter.getContextPopupMenu(e); |
|
|
|
@ -255,6 +250,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 移动 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void mouseMoved(MouseEvent e) { |
|
|
|
@ -409,6 +405,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 拖拽 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void mouseDragged(MouseEvent e) { |
|
|
|
@ -446,13 +443,13 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
// 如果是拖拽选择区域状态,则更新选择区域
|
|
|
|
|
stateModel.changeSelection(e); |
|
|
|
|
} else { |
|
|
|
|
if ((lastPressEvent == null) || (last_creator == null)) { |
|
|
|
|
if ((lastPressEvent == null) || (lastXCreator == null)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (e.getPoint().distance(lastPressEvent.getPoint()) > minDragSize) { |
|
|
|
|
//参数面板和自适应布局不支持拖拽
|
|
|
|
|
if (last_creator.isSupportDrag()){ |
|
|
|
|
designer.startDraggingComponent(last_creator, lastPressEvent, e.getX(), e.getY()); |
|
|
|
|
if (lastXCreator.isSupportDrag()) { |
|
|
|
|
designer.startDraggingComponent(lastXCreator, lastPressEvent, e.getX(), e.getY()); |
|
|
|
|
} |
|
|
|
|
e.consume(); |
|
|
|
|
lastPressEvent = null; |
|
|
|
@ -483,7 +480,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isCreatorInLayout(XCreator creator, XCreator layout) { |
|
|
|
|
if (creator == layout){ |
|
|
|
|
if (creator.equals(layout)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
if (layout.getParent() != null) { |
|
|
|
@ -495,7 +492,8 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
private XCreator processTopLayoutMouseClick(XCreator creator) { |
|
|
|
|
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(creator).getTopLayout(); |
|
|
|
|
if (topLayout != null) { |
|
|
|
|
if (clickTopLayout != null && clickTopLayout != topLayout && !isCreatorInLayout(clickTopLayout, topLayout)){ |
|
|
|
|
if (clickTopLayout != null && !clickTopLayout.equals(topLayout) && !isCreatorInLayout(clickTopLayout, |
|
|
|
|
topLayout)) { |
|
|
|
|
clickTopLayout.setEditable(false); |
|
|
|
|
setTopLayoutUnEditable(clickTopLayout, topLayout); |
|
|
|
|
} |
|
|
|
@ -503,8 +501,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
if (!topLayout.isEditable()) { |
|
|
|
|
creator = topLayout; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
} else { |
|
|
|
|
if (clickTopLayout != null) { |
|
|
|
|
clickTopLayout.setEditable(false); |
|
|
|
|
setTopLayoutUnEditable(clickTopLayout, null); |
|
|
|
@ -513,8 +510,10 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
|
|
|
|
|
return creator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 点击 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
|
@ -534,9 +533,9 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 离开 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
|
@ -551,6 +550,7 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 开始编辑 |
|
|
|
|
* |
|
|
|
|
* @param creator 容器 |
|
|
|
|
* @param designerEditor 设计器 |
|
|
|
|
* @param adapter 适配器 |
|
|
|
@ -558,8 +558,8 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
public void startEditing(XCreator creator, DesignerEditor<? extends JComponent> designerEditor, ComponentAdapter adapter) { |
|
|
|
|
if (designerEditor != null) { |
|
|
|
|
Rectangle rect = ComponentUtils.getRelativeBounds(creator); |
|
|
|
|
current_editor = designerEditor; |
|
|
|
|
current_creator = creator; |
|
|
|
|
currentEditor = designerEditor; |
|
|
|
|
currentXCreator = creator; |
|
|
|
|
Rectangle bounds = new Rectangle(1, 1, creator.getWidth() - 2, creator.getHeight() - 2); |
|
|
|
|
bounds.x += (rect.x - designer.getArea().getHorizontalValue()); |
|
|
|
|
bounds.y += (rect.y - designer.getArea().getVerticalValue()); |
|
|
|
@ -574,22 +574,23 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 停止编辑 |
|
|
|
|
* |
|
|
|
|
* @return 是否编辑成功 |
|
|
|
|
*/ |
|
|
|
|
public boolean stopEditing() { |
|
|
|
|
if (current_editor != null) { |
|
|
|
|
designer.remove(current_editor.getEditorTarget()); |
|
|
|
|
current_editor.fireEditStoped(); |
|
|
|
|
if (currentEditor != null) { |
|
|
|
|
designer.remove(currentEditor.getEditorTarget()); |
|
|
|
|
currentEditor.fireEditStoped(); |
|
|
|
|
|
|
|
|
|
Container container = current_creator.getParent(); |
|
|
|
|
Container container = currentXCreator.getParent(); |
|
|
|
|
|
|
|
|
|
if (container != null) { |
|
|
|
|
LayoutUtils.layoutRootContainer(container); |
|
|
|
|
} |
|
|
|
|
designer.invalidate(); |
|
|
|
|
designer.repaint(); |
|
|
|
|
current_creator = null; |
|
|
|
|
current_editor = null; |
|
|
|
|
currentXCreator = null; |
|
|
|
|
currentEditor = null; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
@ -599,22 +600,22 @@ public class EditingMouseListener extends MouseInputAdapter {
|
|
|
|
|
* 重置编辑控件大小 |
|
|
|
|
*/ |
|
|
|
|
public void resetEditorComponentBounds() { |
|
|
|
|
if (current_editor == null) { |
|
|
|
|
if (currentEditor == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (current_creator.getParent() == null) { |
|
|
|
|
if (currentXCreator.getParent() == null) { |
|
|
|
|
stopEditing(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Rectangle rect = ComponentUtils.getRelativeBounds(current_creator); |
|
|
|
|
Rectangle bounds = new Rectangle(1, 1, current_creator.getWidth() - 2, current_creator.getHeight() - 2); |
|
|
|
|
Rectangle rect = ComponentUtils.getRelativeBounds(currentXCreator); |
|
|
|
|
Rectangle bounds = new Rectangle(1, 1, currentXCreator.getWidth() - 2, currentXCreator.getHeight() - 2); |
|
|
|
|
bounds.x += (rect.x - designer.getArea().getHorizontalValue()); |
|
|
|
|
bounds.y += (rect.y - designer.getArea().getVerticalValue()); |
|
|
|
|
if (current_creator instanceof XEditorHolder) { |
|
|
|
|
ToolTipEditor.getInstance().resetBounds((XEditorHolder) current_creator, bounds, current_editor.getEditorTarget().getBounds()); |
|
|
|
|
if (currentXCreator instanceof XEditorHolder) { |
|
|
|
|
ToolTipEditor.getInstance().resetBounds((XEditorHolder) currentXCreator, bounds, currentEditor.getEditorTarget().getBounds()); |
|
|
|
|
} |
|
|
|
|
current_editor.getEditorTarget().setBounds(bounds); |
|
|
|
|
currentEditor.getEditorTarget().setBounds(bounds); |
|
|
|
|
} |
|
|
|
|
} |