Search in sources :

Example 6 with MouseMotionListener

use of org.eclipse.draw2d.MouseMotionListener in project netxms by netxms.

the class ObjectFloorPlan method createResizeHandle.

/**
 * Create resize handle
 */
private void createResizeHandle(int pos) {
    final Figure handle = new Figure();
    add(handle);
    Dimension size = getSize();
    handle.setSize(8, 8);
    switch(pos) {
        case TOP_LEFT:
            handle.setLocation(new Point(-1, -1));
            handle.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZENWSE));
            break;
        case TOP_RIGHT:
            handle.setLocation(new Point(size.width - 7, -1));
            handle.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZENESW));
            break;
        case BOTTOM_LEFT:
            handle.setLocation(new Point(-1, size.height - 7));
            handle.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZENESW));
            break;
        case BOTTOM_RIGHT:
            handle.setLocation(new Point(size.width - 7, size.height - 7));
            handle.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZENWSE));
            break;
    }
    handle.addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent me) {
            if (resize) {
                resize = false;
                Dimension size = getSize();
                element.setSize(size.width, size.height);
            }
        }

        @Override
        public void mousePressed(MouseEvent me) {
            if (me.button == 1) {
                resize = true;
                lastX = me.x;
                lastY = me.y;
                me.consume();
            }
        }

        @Override
        public void mouseDoubleClicked(MouseEvent me) {
        }
    });
    handle.addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseMoved(MouseEvent me) {
        }

        @Override
        public void mouseHover(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseDragged(MouseEvent me) {
            if (resize) {
                Dimension size = getSize();
                int dx = me.x - lastX;
                int dy = me.y - lastY;
                if ((dx < 0) && (size.width <= 40))
                    dx = 0;
                if ((dy < 0) && (size.height <= 20))
                    dy = 0;
                size.width += dx;
                size.height += dy;
                setSize(size);
                Point p = handle.getLocation();
                p.performTranslate(dx, dy);
                handle.setLocation(p);
                lastX = me.x;
                lastY = me.y;
                me.consume();
                Dimension d = label.getPreferredSize();
                p = getLocation();
                label.setLocation(new Point(p.x + size.width / 2 - d.width / 2, p.y + size.height / 2 - d.height / 2));
            }
        }
    });
}
Also used : MouseListener(org.eclipse.draw2d.MouseListener) MouseEvent(org.eclipse.draw2d.MouseEvent) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) MouseMotionListener(org.eclipse.draw2d.MouseMotionListener) Figure(org.eclipse.draw2d.Figure)

Example 7 with MouseMotionListener

use of org.eclipse.draw2d.MouseMotionListener in project InformationSystem by ObeoNetwork.

the class TreeMapper method drawMapping.

/**
 * @param leftItem
 * @param rightItem
 */
private void drawMapping(final M mapping) {
    LinkFigure previousFigure = mappingsToFigures.get(mapping);
    if (previousFigure != null) {
        previousFigure.deleteFromParent();
        mappingsToFigures.remove(mapping);
        figuresToMappings.remove(previousFigure);
    }
    boolean leftItemVisible = true;
    TreeItem leftTreeItem = (TreeItem) leftTreeViewer.testFindItem(semanticSupport.resolveLeftItem(mapping));
    TreeItem lastVisibleLeftTreeItem = leftTreeItem;
    if (leftTreeItem != null) {
        while (leftTreeItem.getParentItem() != null) {
            if (!leftTreeItem.getParentItem().getExpanded()) {
                lastVisibleLeftTreeItem = leftTreeItem.getParentItem();
                leftItemVisible = false;
            }
            leftTreeItem = leftTreeItem.getParentItem();
        }
    }
    boolean rightItemVisible = true;
    TreeItem rightTreeItem = (TreeItem) rightTreeViewer.testFindItem(semanticSupport.resolveRightItem(mapping));
    TreeItem lastVisibleRightTreeItem = rightTreeItem;
    if (rightTreeItem != null) {
        while (rightTreeItem.getParentItem() != null) {
            if (!rightTreeItem.getParentItem().getExpanded()) {
                lastVisibleRightTreeItem = rightTreeItem.getParentItem();
                rightItemVisible = false;
            }
            rightTreeItem = rightTreeItem.getParentItem();
        }
    }
    if (lastVisibleLeftTreeItem == null || lastVisibleRightTreeItem == null) {
        return;
    }
    final LinkFigure arrowFigure = new LinkFigure(linkRootFigure);
    // store it
    figuresToMappings.put(arrowFigure, mapping);
    mappingsToFigures.put(mapping, arrowFigure);
    arrowFigure.setLeftPoint(0, lastVisibleLeftTreeItem.getBounds().y + lastVisibleLeftTreeItem.getBounds().height / 2);
    arrowFigure.setLeftMappingVisible(leftItemVisible);
    arrowFigure.setRightPoint(linkRootFigure.getBounds().width, lastVisibleRightTreeItem.getBounds().y + rightTreeItem.getBounds().height / 2);
    arrowFigure.setRightMappingVisible(rightItemVisible);
    arrowFigure.setLineWidth(uiConfig.getDefaultArrowWidth());
    arrowFigure.seLineColor(uiConfig.getDefaultMappingColor());
    arrowFigure.addMouseListener(new MouseListener() {

        public void mousePressed(MouseEvent me) {
            boolean addToSelection = ((me.getState() & SWT.CONTROL) > 0);
            fireMappingSelection(mapping, arrowFigure, addToSelection);
        }

        public void mouseReleased(MouseEvent me) {
        }

        public void mouseDoubleClicked(MouseEvent me) {
        // if (arrowFigure.)
        }
    });
    arrowFigure.addMouseMotionListener(new MouseMotionListener() {

        public void mouseDragged(MouseEvent me) {
        }

        public void mouseEntered(MouseEvent me) {
            fireMouseEntered(mapping, arrowFigure);
        }

        public void mouseExited(MouseEvent me) {
            fireMouseExited(mapping, arrowFigure);
        }

        public void mouseHover(MouseEvent me) {
        }

        public void mouseMoved(MouseEvent me) {
        }
    });
}
Also used : MouseListener(org.eclipse.draw2d.MouseListener) MouseEvent(org.eclipse.draw2d.MouseEvent) TreeItem(org.eclipse.swt.widgets.TreeItem) LinkFigure(org.eclipse.nebula.treemapper.internal.LinkFigure) MouseMotionListener(org.eclipse.draw2d.MouseMotionListener)

Aggregations

MouseEvent (org.eclipse.draw2d.MouseEvent)7 MouseMotionListener (org.eclipse.draw2d.MouseMotionListener)7 MouseListener (org.eclipse.draw2d.MouseListener)4 Figure (org.eclipse.draw2d.Figure)2 IFigure (org.eclipse.draw2d.IFigure)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Point (org.eclipse.draw2d.geometry.Point)2 EObject (org.eclipse.emf.ecore.EObject)1 NodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure)1 Node (org.eclipse.gmf.runtime.notation.Node)1 LinkFigure (org.eclipse.nebula.treemapper.internal.LinkFigure)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 BusinessItemNameFigure (org.talend.designer.business.diagram.custom.figures.BusinessItemNameFigure)1 BusinessItemShapeFigure (org.talend.designer.business.diagram.custom.figures.BusinessItemShapeFigure)1 BusinessItem (org.talend.designer.business.model.business.BusinessItem)1