|
|
|
@ -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; |
|
|
|
@ -33,160 +31,147 @@ import java.io.Serializable;
|
|
|
|
|
*/ |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@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 boolean isEnabled() { |
|
|
|
|
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
boolean enable = true; |
|
|
|
|
if (template != null) { |
|
|
|
|
enable = super.isEnabled() && template.checkEnable(); |
|
|
|
|
} |
|
|
|
|
return enable; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|