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;
}
}
}
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));
}
}
});
}
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) {
}
});
}
Aggregations