Search in sources :

Example 16 with MouseEvent

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

the class ExtendedGraphViewer method showGrid.

/**
 * Show/hide grid
 *
 * @param show
 */
public void showGrid(boolean show) {
    if (show) {
        if (gridFigure == null) {
            gridFigure = new GridFigure();
            backgroundLayer.add(gridFigure, null, 1);
            gridFigure.setSize(graph.getZestRootLayer().getSize());
            gridFigure.addMouseListener(new MouseListener() {

                @Override
                public void mousePressed(MouseEvent me) {
                    setSelection(null);
                }

                @Override
                public void mouseReleased(MouseEvent me) {
                }

                @Override
                public void mouseDoubleClicked(MouseEvent me) {
                }
            });
        }
    } else {
        if (gridFigure != null) {
            backgroundLayer.remove(gridFigure);
            gridFigure = null;
        }
    }
}
Also used : MouseListener(org.eclipse.draw2d.MouseListener) MouseEvent(org.eclipse.draw2d.MouseEvent)

Example 17 with MouseEvent

use of org.eclipse.draw2d.MouseEvent 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 18 with MouseEvent

use of org.eclipse.draw2d.MouseEvent 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)18 MouseListener (org.eclipse.draw2d.MouseListener)15 MouseMotionListener (org.eclipse.draw2d.MouseMotionListener)9 Label (org.eclipse.draw2d.Label)6 Figure (org.eclipse.draw2d.Figure)4 IFigure (org.eclipse.draw2d.IFigure)3 ColumnSash (org.talend.designer.gefabstractmap.figures.table.ColumnSash)3 TableColumn (org.talend.designer.gefabstractmap.figures.table.TableColumn)3 CompoundBorder (org.eclipse.draw2d.CompoundBorder)2 Graphics (org.eclipse.draw2d.Graphics)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Point (org.eclipse.draw2d.geometry.Point)2 ALogger (de.fhg.igd.slf4jplus.ALogger)1 ALoggerFactory (de.fhg.igd.slf4jplus.ALoggerFactory)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 ResolvedTask (eu.esdihumboldt.hale.common.tasks.ResolvedTask)1 TaskService (eu.esdihumboldt.hale.common.tasks.TaskService)1 HaleUI (eu.esdihumboldt.hale.ui.HaleUI)1 CommonSharedImages (eu.esdihumboldt.hale.ui.common.CommonSharedImages)1 CellFigure (eu.esdihumboldt.hale.ui.common.graph.figures.CellFigure)1