|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.fr.design.mainframe; |
|
|
|
|
|
|
|
|
|
import com.fine.theme.utils.FineClientProperties; |
|
|
|
|
import com.fr.base.vcs.DesignerMode; |
|
|
|
|
import com.fr.design.designer.creator.XCreator; |
|
|
|
|
import com.fr.design.designer.creator.XCreatorUtils; |
|
|
|
@ -7,12 +8,9 @@ import com.fr.design.file.HistoryTemplateListCache;
|
|
|
|
|
import com.fr.design.form.util.FormDesignerUtils; |
|
|
|
|
import com.fr.design.gui.core.WidgetOption; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.gui.ibutton.UIForbiddenButtonUI; |
|
|
|
|
import com.fr.form.ui.Widget; |
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.plaf.ButtonUI; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.datatransfer.DataFlavor; |
|
|
|
|
import java.awt.datatransfer.Transferable; |
|
|
|
|
import java.awt.datatransfer.UnsupportedFlavorException; |
|
|
|
@ -21,172 +19,178 @@ import java.awt.dnd.DragGestureEvent;
|
|
|
|
|
import java.awt.dnd.DragGestureListener; |
|
|
|
|
import java.awt.dnd.DragSource; |
|
|
|
|
import java.awt.dnd.DragSourceAdapter; |
|
|
|
|
import java.awt.dnd.DragSourceDragEvent; |
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
import java.awt.event.MouseListener; |
|
|
|
|
import java.awt.event.MouseMotionListener; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.Serializable; |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
*august: 控件按钮 |
|
|
|
|
/** |
|
|
|
|
* 控件按钮 |
|
|
|
|
* |
|
|
|
|
* @author august |
|
|
|
|
* @since 7.0 |
|
|
|
|
* Created on 2008 |
|
|
|
|
*/ |
|
|
|
|
public class ToolBarButton extends UIButton implements MouseListener, MouseMotionListener, Serializable { |
|
|
|
|
|
|
|
|
|
private WidgetOption no; |
|
|
|
|
private MouseEvent lastPressEvent; |
|
|
|
|
|
|
|
|
|
public ToolBarButton(WidgetOption no) { |
|
|
|
|
super(no.optionIcon()); |
|
|
|
|
this.no = no; |
|
|
|
|
this.addMouseListener(this); |
|
|
|
|
this.addMouseMotionListener(this); |
|
|
|
|
this.setToolTipText(no.optionName()); |
|
|
|
|
this.setBorder(null); |
|
|
|
|
this.setOpaque(false); |
|
|
|
|
this.setRequestFocusEnabled(false); |
|
|
|
|
this.set4ToolbarButton(); |
|
|
|
|
// FormEditor那边用的DND的复杂方式 这边还必须也用,不然就方便多了
|
|
|
|
|
new DragAndDropDragGestureListener(this, DnDConstants.ACTION_COPY_OR_MOVE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Dimension getPreferredSize() { |
|
|
|
|
return new Dimension(super.getPreferredSize().width, 20); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public WidgetOption getNameOption() { |
|
|
|
|
return this.no; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setNameOption(WidgetOption no) { |
|
|
|
|
this.no = no; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
|
|
if (e.getClickCount() >= 2) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
|
lastPressEvent = e; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseDragged(MouseEvent e) { |
|
|
|
|
if (!isEnabled()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (DesignerMode.isAuthorityEditing()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (lastPressEvent == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
getModel().setPressed(false); |
|
|
|
|
getModel().setSelected(false); |
|
|
|
|
getModel().setRollover(false); |
|
|
|
|
|
|
|
|
|
Object source = e.getSource(); |
|
|
|
|
Widget creatorSource = null; |
|
|
|
|
if (source instanceof ToolBarButton) { |
|
|
|
|
ToolBarButton no = (ToolBarButton) e.getSource(); |
|
|
|
|
if (no == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
creatorSource = no.getNameOption().createWidget(); |
|
|
|
|
} |
|
|
|
|
if (creatorSource != null) { |
|
|
|
|
XCreator xCreator = XCreatorUtils.createThemedXCreator(creatorSource); |
|
|
|
|
WidgetToolBarPane.getTarget().startDraggingNewWidget(xCreator, lastPressEvent, e); |
|
|
|
|
FormDesignerUtils.addWidgetProcessInfo(xCreator.toData()); |
|
|
|
|
lastPressEvent = null; |
|
|
|
|
this.setBorder(null); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseMoved(MouseEvent e) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class DragAndDropDragGestureListener extends DragSourceAdapter implements DragGestureListener { |
|
|
|
|
private DragSource source; |
|
|
|
|
|
|
|
|
|
public DragAndDropDragGestureListener(ToolBarButton tt, int actions) { |
|
|
|
|
source = new DragSource(); |
|
|
|
|
source.createDefaultDragGestureRecognizer(tt, actions, this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void dragGestureRecognized(DragGestureEvent dge) { |
|
|
|
|
ToolBarButton toolBarButton = (ToolBarButton) dge.getComponent(); |
|
|
|
|
if (toolBarButton != null) { |
|
|
|
|
Widget widget = toolBarButton.getNameOption().createWidget(); |
|
|
|
|
DragAndDropTransferable dragAndDropTransferable = new DragAndDropTransferable(widget); |
|
|
|
|
dge.startDrag(DragSource.DefaultCopyDrop, dragAndDropTransferable, this); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void dragEnter(DragSourceDragEvent dragSourceDragEvent) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class DragAndDropTransferable implements Transferable { |
|
|
|
|
private Widget widget; |
|
|
|
|
|
|
|
|
|
public DragAndDropTransferable(Widget widget) { |
|
|
|
|
this.widget = widget; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DataFlavor[] flavors = {new DataFlavor(Widget.class, "Widget")}; |
|
|
|
|
|
|
|
|
|
public DataFlavor[] getTransferDataFlavors() { |
|
|
|
|
return flavors; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isDataFlavorSupported(DataFlavor flavor) { |
|
|
|
|
for (DataFlavor df : flavors) { |
|
|
|
|
if (ComparatorUtils.equals(df, flavor)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException { |
|
|
|
|
return widget; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseEntered(MouseEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ButtonUI getUI() { |
|
|
|
|
return new UIForbiddenButtonUI(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean isEnabled() { |
|
|
|
|
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
boolean enable = true; |
|
|
|
|
if (template != null) { |
|
|
|
|
enable = super.isEnabled() && template.checkEnable(); |
|
|
|
|
} |
|
|
|
|
return enable; |
|
|
|
|
} |
|
|
|
|
private WidgetOption no; |
|
|
|
|
private MouseEvent lastPressEvent; |
|
|
|
|
|
|
|
|
|
public ToolBarButton(WidgetOption no) { |
|
|
|
|
super(no.optionIcon()); |
|
|
|
|
this.no = no; |
|
|
|
|
this.addMouseListener(this); |
|
|
|
|
this.addMouseMotionListener(this); |
|
|
|
|
this.setToolTipText(no.optionName()); |
|
|
|
|
this.setRequestFocusEnabled(false); |
|
|
|
|
putClientProperty(FineClientProperties.BUTTON_TYPE, FineClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON); |
|
|
|
|
// FormEditor那边用的DND的复杂方式 这边还必须也用,不然就方便多了
|
|
|
|
|
new DragAndDropDragGestureListener(this, DnDConstants.ACTION_COPY_OR_MOVE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取控件配置 |
|
|
|
|
* |
|
|
|
|
* @return 控件配置 |
|
|
|
|
*/ |
|
|
|
|
public WidgetOption getNameOption() { |
|
|
|
|
return this.no; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置控件配置 |
|
|
|
|
* |
|
|
|
|
* @param no 控件配置 |
|
|
|
|
*/ |
|
|
|
|
public void setNameOption(WidgetOption no) { |
|
|
|
|
this.no = no; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
|
lastPressEvent = e; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseDragged(MouseEvent e) { |
|
|
|
|
if (!isEnabled()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (DesignerMode.isAuthorityEditing()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (lastPressEvent == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
getModel().setPressed(false); |
|
|
|
|
getModel().setSelected(false); |
|
|
|
|
getModel().setRollover(false); |
|
|
|
|
|
|
|
|
|
Object source = e.getSource(); |
|
|
|
|
Widget creatorSource = null; |
|
|
|
|
if (source instanceof ToolBarButton) { |
|
|
|
|
ToolBarButton no = (ToolBarButton) e.getSource(); |
|
|
|
|
if (no == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
creatorSource = no.getNameOption().createWidget(); |
|
|
|
|
} |
|
|
|
|
if (creatorSource != null) { |
|
|
|
|
XCreator xCreator = XCreatorUtils.createThemedXCreator(creatorSource); |
|
|
|
|
WidgetToolBarPane.getTarget().startDraggingNewWidget(xCreator, lastPressEvent, e); |
|
|
|
|
FormDesignerUtils.addWidgetProcessInfo(xCreator.toData()); |
|
|
|
|
lastPressEvent = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseMoved(MouseEvent e) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 拖放拖动手势侦听器 |
|
|
|
|
*/ |
|
|
|
|
public static class DragAndDropDragGestureListener extends DragSourceAdapter implements DragGestureListener { |
|
|
|
|
private DragSource source; |
|
|
|
|
|
|
|
|
|
public DragAndDropDragGestureListener(ToolBarButton tt, int actions) { |
|
|
|
|
source = new DragSource(); |
|
|
|
|
source.createDefaultDragGestureRecognizer(tt, actions, this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void dragGestureRecognized(DragGestureEvent dge) { |
|
|
|
|
ToolBarButton toolBarButton = (ToolBarButton) dge.getComponent(); |
|
|
|
|
if (toolBarButton != null) { |
|
|
|
|
Widget widget = toolBarButton.getNameOption().createWidget(); |
|
|
|
|
DragAndDropTransferable dragAndDropTransferable = new DragAndDropTransferable(widget); |
|
|
|
|
dge.startDrag(DragSource.DefaultCopyDrop, dragAndDropTransferable, this); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 拖放转换器 |
|
|
|
|
*/ |
|
|
|
|
public static class DragAndDropTransferable implements Transferable { |
|
|
|
|
private Widget widget; |
|
|
|
|
|
|
|
|
|
public DragAndDropTransferable(Widget widget) { |
|
|
|
|
this.widget = widget; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DataFlavor[] flavors = {new DataFlavor(Widget.class, "Widget")}; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public DataFlavor[] getTransferDataFlavors() { |
|
|
|
|
return flavors; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean isDataFlavorSupported(DataFlavor flavor) { |
|
|
|
|
for (DataFlavor df : flavors) { |
|
|
|
|
if (ComparatorUtils.equals(df, flavor)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException { |
|
|
|
|
return widget; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseEntered(MouseEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean isEnabled() { |
|
|
|
|
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
boolean enable = true; |
|
|
|
|
if (template != null) { |
|
|
|
|
enable = super.isEnabled() && template.checkEnable(); |
|
|
|
|
} |
|
|
|
|
return enable; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|