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