Issue #429 fix minor issues with toolbar and updated eraser code

Former-commit-id: 27e850d203 [formerly 27e850d203 [formerly f6f3bcc2596735c8371256f4274c9b9e21445f1a]]
Former-commit-id: 236ae6f26c
Former-commit-id: 0a97f20f3a
This commit is contained in:
Matt Nash 2012-03-30 16:35:02 -05:00
parent cf2054fe6a
commit e7d6b86a2f
5 changed files with 267 additions and 157 deletions

View file

@ -41,6 +41,29 @@
class="com.raytheon.uf.viz.drawing.actions.RedoAddAction"
commandId="com.raytheon.uf.viz.drawing.redoadd">
</handler>
</extension>
<extension
point="org.eclipse.ui.contexts">
<context
description="Drawing Context"
id="com.raytheon.uf.viz.drawing.context"
name="Drawing Context">
</context>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="com.raytheon.uf.viz.drawing.undoadd"
contextId="com.raytheon.uf.viz.drawing.context"
schemeId="com.raytheon.viz.ui.awips.scheme"
sequence="M1+Z">
</key>
<key
commandId="com.raytheon.uf.viz.drawing.redoadd"
contextId="com.raytheon.uf.viz.drawing.context"
schemeId="com.raytheon.viz.ui.awips.scheme"
sequence="M1+Y">
</key>
</extension>
<!--extension
point="org.eclipse.ui.bindings">

View file

@ -29,7 +29,6 @@ import com.raytheon.uf.viz.core.rsc.IInputHandler;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.viz.ui.tools.AbstractModalTool;
/**
* Describes a basic drawing tool.
*

View file

@ -28,7 +28,6 @@ import java.util.Map;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.drawables.IWireframeShape;
@ -43,7 +42,9 @@ import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability;
import com.raytheon.viz.ui.cmenu.IContextMenuContributor;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString;
@ -69,12 +70,17 @@ public class DrawingLayer extends
protected IWireframeShape eraseWireframeShape;
// TODO take this out
private List<IWireframeShape> erasedShapes;
protected IGraphicsTarget target;
protected boolean needsRefresh = true;
protected boolean erase = false;
private PaintProperties paintProps = null;
private boolean needsRefresh = false;
public DrawingLayer(PathDrawingResourceData data, LoadProperties props) {
super(data, props);
}
@ -100,6 +106,8 @@ public class DrawingLayer extends
this.tempGeometries = new ArrayList<Geometry>();
this.wireframeShapes = new LinkedHashMap<Geometry, IWireframeShape>();
this.deletedShapes = new LinkedHashMap<Geometry, IWireframeShape>();
this.erasedShapes = new ArrayList<IWireframeShape>();
this.target = target;
getCapability(OutlineCapability.class);
@ -115,6 +123,7 @@ public class DrawingLayer extends
*/
protected void paintInternal(IGraphicsTarget target,
PaintProperties paintProps) throws VizException {
this.paintProps = paintProps;
if (tempWireframeShape == null || needsRefresh) {
tempWireframeShape = target.createWireframeShape(true,
getDescriptor());
@ -125,47 +134,87 @@ public class DrawingLayer extends
getDescriptor());
}
RGB rgb = getCapability(ColorableCapability.class).getColor();
OutlineCapability outline = getCapability(OutlineCapability.class);
ColorableCapability colorable = getCapability(ColorableCapability.class);
// remove after debugging
// MagnificationCapability magnification =
// getCapability(MagnificationCapability.class);
// for (Geometry ls : wireframeShapes.keySet()) {
// if (ls instanceof LineString) {
// LineString string = (LineString) ls;
// for (int i = 0; i < string.getNumPoints(); i++) {
// target.drawPoint(string.getPointN(i).getX(), string
// .getPointN(i).getY(), 0, colorable.getColor(),
// PointStyle.BOX, magnification.getMagnification()
// .floatValue());
// DrawableString dString = new DrawableString(string
// .getPointN(i).getCoordinate().toString(),
// colorable.getColor());
// dString.basics.x = string.getPointN(i).getX();
// dString.basics.y = string.getPointN(i).getY();
// target.drawStrings(dString);
// }
// }
// }
for (IWireframeShape sh : wireframeShapes.values()) {
target.drawWireframeShape(sh, colorable.getColor(),
(float) outline.getOutlineWidth());
(float) outline.getOutlineWidth(), outline.getLineStyle());
}
for (Geometry g : this.tempGeometries) {
drawTempLinePrimitive(g, target, rgb);
drawTempLinePrimitive(g, tempWireframeShape);
}
// if (erase) {
// target.drawWireframeShape(tempWireframeShape, new RGB(255, 0, 0),
// 1.0f);
// } else {
target.drawWireframeShape(tempWireframeShape, colorable.getColor(),
outline.getOutlineWidth(), outline.getLineStyle());
// target.drawWireframeShape(eraseWireframeShape, new RGB(255, 0, 0),
// 4.0f);
// }
}
private void drawTempLinePrimitive(Geometry shape, IGraphicsTarget target,
RGB color) throws VizException {
private void drawTempLinePrimitive(Geometry shape, IWireframeShape wShape) {
LineString line = (LineString) shape;
int pts = line.getNumPoints();
for (int i = 1; i < pts; i++) {
double[] p1 = this.descriptor
.worldToPixel(new double[] { line.getPointN(i - 1).getX(),
line.getPointN(i - 1).getY() });
double[] p2 = this.descriptor.worldToPixel(new double[] {
line.getPointN(i).getX(), line.getPointN(i).getY() });
double[] p1 = new double[] { line.getPointN(i - 1).getX(),
line.getPointN(i - 1).getY() };
double[] p2 = new double[] { line.getPointN(i).getX(),
line.getPointN(i).getY() };
double[][] coords = new double[2][2];
coords[0][0] = p1[0];
coords[0][1] = p1[1];
coords[1][0] = p2[0];
coords[1][1] = p2[1];
tempWireframeShape.addLineSegment(coords);
wShape.addLineSegment(coords);
}
}
/**
* Draw a line using pixel coordinates
* Convert from world to gl pixels
*
* @param line
* @param i
* @return
*/
public LineString convertPixels(LineString line) {
int pts = line.getNumPoints();
GeometryFactory factory = new GeometryFactory();
List<Coordinate> coords = new ArrayList<Coordinate>();
for (int i = 0; i < pts; i++) {
double[] point = this.descriptor.worldToPixel(new double[] {
line.getPointN(i).getX(), line.getPointN(i).getY() });
coords.add(new Coordinate(point[0], point[1]));
}
return factory.createLineString(coords.toArray(new Coordinate[0]));
}
/**
* Finalize a temporary line by putting it in the map of all the drawn
* shapes
*
* UUID is optional, and generally should be null
*
@ -173,74 +222,68 @@ public class DrawingLayer extends
* @param isFinal
* @param uuid
*/
public void addLine(LineString line, String uuid) {
public void finalizeLine(LineString line, String uuid) {
tempWireframeShape.compile();
wireframeShapes.put(line, tempWireframeShape);
}
public void addTempLine(LineString line) {
if (!erase) {
this.tempGeometries.add(line);
} else {
Map<Geometry, IWireframeShape> shapes = new HashMap<Geometry, IWireframeShape>();
shapes.putAll(wireframeShapes);
GeometryFactory factory = new GeometryFactory();
for (Geometry geom : shapes.keySet()) {
if (line.intersects(geom)) {
Point point = factory
.createPoint(line.getCoordinates()[line
.getNumPoints() - 1]);
Geometry intersection = point.buffer(1).intersection(geom);
Geometry finalGeom = geom.difference(intersection);
deletedShapes.put(geom, wireframeShapes.remove(geom));
public void addTempDrawLine(LineString line) {
this.tempGeometries.add(line);
}
if (finalGeom instanceof MultiLineString) {
MultiLineString mLineString = (MultiLineString) finalGeom;
for (int j = 0; j < mLineString.getNumGeometries(); j++) {
LineString lineString = (LineString) mLineString
.getGeometryN(j);
eraseWireframeShape = target.createWireframeShape(
true, descriptor);
int pts = lineString.getNumPoints();
for (int i = 1; i < pts; i++) {
double[] p1 = this.descriptor
.worldToPixel(new double[] {
lineString.getPointN(i - 1)
.getX(),
lineString.getPointN(i - 1)
.getY() });
double[] p2 = this.descriptor
.worldToPixel(new double[] {
lineString.getPointN(i).getX(),
lineString.getPointN(i).getY() });
double[][] coords = new double[2][2];
coords[0][0] = p1[0];
coords[0][1] = p1[1];
coords[1][0] = p2[0];
coords[1][1] = p2[1];
eraseWireframeShape.addLineSegment(coords);
// try {
// target.drawPoint(coords[0][0],
// coords[0][1], 0,
// new RGB(0, 0, 255),
// PointStyle.CIRCLE);
// } catch (VizException e) {
// e.printStackTrace();
// }
}
this.wireframeShapes.put(lineString,
eraseWireframeShape);
// try {
// target.drawWireframeShape(eraseWireframeShape,
// new RGB(0, 0, 255), 10.0f);
// } catch (VizException e) {
// e.printStackTrace();
// }
issueRefresh();
}
public void addTempEraseLine(LineString line) {
this.tempGeometries.add(line);
Map<Geometry, IWireframeShape> shapes = new HashMap<Geometry, IWireframeShape>();
shapes.putAll(wireframeShapes);
for (Geometry geom : shapes.keySet()) {
double extentPercentageX = paintProps.getView().getExtent()
.getWidth()
/ (double) paintProps.getCanvasBounds().width;
double cursorSize = 16;
double size = extentPercentageX * cursorSize;
if (line.buffer(size / 2).intersects(geom)) {
Geometry intersection = line.buffer(size / 2)
.intersection(geom);
Geometry finalGeom = geom.difference(intersection);
deletedShapes.put(geom, wireframeShapes.remove(geom));
Geometry lString = null;
// should be split into multiple pieces (half or more)
if (finalGeom instanceof MultiLineString) {
lString = (MultiLineString) finalGeom;
for (int j = 0; j < lString.getNumGeometries(); j++) {
LineString lineString = (LineString) lString
.getGeometryN(j);
eraseWireframeShape = target.createWireframeShape(true,
descriptor);
drawTempLinePrimitive(lineString, eraseWireframeShape);
this.wireframeShapes.put(lineString,
eraseWireframeShape);
erasedShapes.add(eraseWireframeShape);
}
}
if (finalGeom instanceof LineString) {
GeometryFactory factory = new GeometryFactory();
lString = (LineString) finalGeom;
Point point = factory
.createPoint(lString.getCoordinates()[0]);
intersection = point.buffer(size / 2).intersection(geom);
finalGeom = geom.difference(intersection);
eraseWireframeShape = target.createWireframeShape(true,
descriptor);
drawTempLinePrimitive(lString, eraseWireframeShape);
this.wireframeShapes.put(lString, eraseWireframeShape);
erasedShapes.add(eraseWireframeShape);
} else {
lString = (GeometryCollection) finalGeom;
// for (int j = 0; j < lString.getNumGeometries(); j++) {
// System.out.println(lString.getGeometryN(j).getClass());
// }
// System.out.println(finalGeom.getClass() + " has "
// + lString.getNumGeometries() + " geometries");
}
}
tempGeometries.clear();
}
}
@ -251,6 +294,7 @@ public class DrawingLayer extends
}
public void resetTemp() {
// this.tempWireframeShape.dispose();
this.tempGeometries.clear();
needsRefresh = true;
}
@ -268,12 +312,16 @@ public class DrawingLayer extends
for (IWireframeShape shape : this.deletedShapes.values()) {
shape.dispose();
}
this.tempWireframeShape.dispose();
this.eraseWireframeShape.dispose();
this.wireframeShapes.clear();
this.deletedShapes.clear();
}
/**
* Remove the last drawn shape
*/
public void undoAdd() {
if (!this.wireframeShapes.isEmpty()) {
Geometry geom = this.wireframeShapes.keySet().toArray(
@ -284,7 +332,7 @@ public class DrawingLayer extends
}
/**
* Add the ability to remove and redo
* Redraw the last deleted shape
*/
public void redoAdd() {
if (!deletedShapes.isEmpty()) {
@ -296,40 +344,18 @@ public class DrawingLayer extends
}
/**
* @return the wireframeShapes
*/
public IWireframeShape getTempWireframeShape() {
return tempWireframeShape;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.ui.cmenu.IContextMenuContributor#addContextMenuItems
* (org.eclipse.jface.action.IMenuManager, int, int)
* Add items to the right click menu, in this case just a button to launch
* the Drawing toolbar
*/
@Override
public void addContextMenuItems(IMenuManager menuManager, int x, int y) {
ResourcePair pair = new ResourcePair();
pair.setResource(this);
Action action = new Action("Draw Toolbar") {
Action action = new Action("Draw Toolbar...") {
public void run() {
PathToolbar.getToolbar().open();
};
};
// ClearDrawingAction cAction = new ClearDrawingAction();
// cAction.setSelectedRsc(pair);
// cAction.setImageDescriptor(ToolsUtils.getImageDescriptor("remove.gif"));
// UndoAddAction uAction = new UndoAddAction();
// uAction.setSelectedRsc(pair);
// uAction.setImageDescriptor(ToolsUtils.getImageDescriptor("undo.gif"));
// RedoAddAction rAction = new RedoAddAction();
// rAction.setSelectedRsc(pair);
// rAction.setImageDescriptor(ToolsUtils.getImageDescriptor("redo.gif"));
// menuManager.add(cAction);
// menuManager.add(uAction);
// menuManager.add(rAction);
menuManager.add(action);
}

View file

@ -19,14 +19,13 @@
**/
package com.raytheon.uf.viz.drawing;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@ -34,11 +33,15 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.ResourcePair;
import com.raytheon.uf.viz.core.icon.IconUtil;
import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.uf.viz.drawing.actions.ClearDrawingAction;
import com.raytheon.uf.viz.drawing.actions.EraseObjectsAction;
import com.raytheon.uf.viz.drawing.actions.RedoAddAction;
@ -72,15 +75,23 @@ public class PathToolbar extends CaveSWTDialog implements
private static PathToolbar toolbar;
private Map<AbstractEditor, ResourcePair> layers;
// private Map<AbstractEditor, ResourcePair> layers;
private ToolItem drawItem;
private ToolItem eraserItem;
private ToolItem undoItem;
private ToolItem redoItem;
private ToolItem clearItem;
private IContextActivation drawingContext;
public static PathToolbar getToolbar() {
if (toolbar == null) {
toolbar = new PathToolbar(Display.getCurrent().getActiveShell());
toolbar = new PathToolbar(new Shell(Display.getCurrent()));
}
return toolbar;
}
@ -91,7 +102,6 @@ public class PathToolbar extends CaveSWTDialog implements
*/
protected PathToolbar(Shell parentShell) {
super(parentShell, SWT.DIALOG_TRIM | CAVE.DO_NOT_BLOCK);
layers = new HashMap<AbstractEditor, ResourcePair>();
setText("Drawing");
}
@ -112,6 +122,18 @@ public class PathToolbar extends CaveSWTDialog implements
*/
@Override
protected void initializeComponents(Shell shell) {
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
PathToolbar.getToolbar().getShell().removeShellListener(this);
IContextService contextService = (IContextService) PlatformUI
.getWorkbench().getService(IContextService.class);
contextService.deactivateContext(drawingContext);
super.shellClosed(e);
}
});
Composite comp = new Composite(shell, SWT.NONE);
GridLayout layout = new GridLayout();
comp.setLayout(layout);
@ -141,10 +163,9 @@ public class PathToolbar extends CaveSWTDialog implements
.getActiveEditorAs(AbstractEditor.class);
IDescriptor desc = editor.getActiveDisplayPane()
.getDescriptor();
if (layers.containsKey(editor)) {
if (((DrawingLayer) layers.get(editor).getResource()).erase) {
((DrawingLayer) layers.get(editor).getResource())
.setErase(false);
for (ResourcePair pair : desc.getResourceList()) {
if (pair.getResource() instanceof DrawingLayer) {
((DrawingLayer) pair.getResource()).erase = false;
eraserItem.setSelection(false);
}
}
@ -153,49 +174,39 @@ public class PathToolbar extends CaveSWTDialog implements
// ((VizMultiPaneEditor) editor)
// .addSelectedPaneChangedListener(PathToolbar
// .getToolbar());
for (ResourcePair pair : desc.getResourceList()) {
if (pair.getResource() instanceof DrawingLayer) {
layers.put(editor, pair);
eraserItem.setEnabled(true);
// drawItem.setEnabled(false);
}
}
updateToolbar();
}
});
ToolItem undoItem = new ToolItem(toolbar, SWT.FLAT);
undoItem = new ToolItem(toolbar, SWT.FLAT);
undoItem.setText("Undo");
undoItem.setImage(IconUtil.getImageDescriptor(
Activator.getDefault().getBundle(), "undo.gif").createImage());
undoItem.setToolTipText("Ctrl+Z to Undo");
undoItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UndoAddAction action = new UndoAddAction();
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
if (layers.get(editor) != null) {
executeAction(action);
}
executeAction(action);
updateToolbar();
}
});
ToolItem redoItem = new ToolItem(toolbar, SWT.FLAT);
redoItem = new ToolItem(toolbar, SWT.FLAT);
redoItem.setText("Redo");
redoItem.setImage(IconUtil.getImageDescriptor(
Activator.getDefault().getBundle(), "redo.gif").createImage());
redoItem.setToolTipText("Ctrl+Y to Redo");
redoItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
RedoAddAction action = new RedoAddAction();
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
if (layers.get(editor) != null) {
executeAction(action);
}
executeAction(action);
updateToolbar();
}
});
ToolItem clearItem = new ToolItem(toolbar, SWT.FLAT);
clearItem = new ToolItem(toolbar, SWT.FLAT);
clearItem.setText("Clear");
clearItem
.setImage(IconUtil.getImageDescriptor(
@ -205,11 +216,8 @@ public class PathToolbar extends CaveSWTDialog implements
@Override
public void widgetSelected(SelectionEvent e) {
ClearDrawingAction action = new ClearDrawingAction();
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
if (layers.get(editor) != null) {
executeAction(action);
}
executeAction(action);
updateToolbar();
}
});
@ -219,18 +227,23 @@ public class PathToolbar extends CaveSWTDialog implements
.setImage(IconUtil.getImageDescriptor(
Activator.getDefault().getBundle(), "eraser.png")
.createImage());
eraserItem.setEnabled(false);
eraserItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EraseObjectsAction action = new EraseObjectsAction();
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
if (layers.get(editor) != null) {
executeAction(action);
}
executeAction(action);
}
});
updateToolbar();
}
@Override
protected void opened() {
IContextService contextService = (IContextService) PlatformUI
.getWorkbench().getService(IContextService.class);
drawingContext = contextService
.activateContext("com.raytheon.uf.viz.drawing.context");
super.opened();
}
private void executeAction(AbstractHandler action) {
@ -262,4 +275,41 @@ public class PathToolbar extends CaveSWTDialog implements
}
}
private void updateToolbar() {
if (true) {
return;
}
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
ResourceList list = editor.getActiveDisplayPane().getDescriptor()
.getResourceList();
for (ResourcePair pair : list) {
if (pair.getResource() instanceof DrawingLayer) {
DrawingLayer layer = (DrawingLayer) pair.getResource();
if (layer.getDeletedShapes().isEmpty()
&& layer.getWireframeShapes().isEmpty()) {
undoItem.setEnabled(false);
redoItem.setEnabled(false);
clearItem.setEnabled(false);
} else {
clearItem.setEnabled(true);
if (layer.getDeletedShapes().isEmpty()) {
undoItem.setEnabled(true);
redoItem.setEnabled(false);
} else {
undoItem.setEnabled(false);
redoItem.setEnabled(true);
}
if (layer.getWireframeShapes().isEmpty()) {
redoItem.setEnabled(true);
undoItem.setEnabled(false);
} else {
redoItem.setEnabled(false);
undoItem.setEnabled(true);
}
}
}
}
}
}

View file

@ -31,6 +31,7 @@ import org.eclipse.swt.widgets.Display;
import com.raytheon.uf.viz.core.icon.IconUtil;
import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
import com.raytheon.uf.viz.core.rsc.IInputHandler;
import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability;
import com.raytheon.uf.viz.drawing.AbstractDrawingTool;
import com.raytheon.uf.viz.drawing.Activator;
import com.raytheon.uf.viz.drawing.PathDrawingResourceData;
@ -83,7 +84,9 @@ public class PathDrawingTool extends AbstractDrawingTool {
*/
@Override
public boolean handleMouseDown(int anX, int aY, int button) {
if (button != 1)
if (button != 1
|| !theDrawingLayer.getCapability(EditableCapability.class)
.isEditable())
return false;
Cursor cursor = null;
@ -120,7 +123,9 @@ public class PathDrawingTool extends AbstractDrawingTool {
*/
@Override
public boolean handleMouseDownMove(int x, int y, int button) {
if (button != 1)
if (button != 1
|| !theDrawingLayer.getCapability(EditableCapability.class)
.isEditable())
return false;
Coordinate p1 = editor.translateClick(theLastMouseX, theLastMouseY);
Coordinate p2 = editor.translateClick(x, y);
@ -133,8 +138,12 @@ public class PathDrawingTool extends AbstractDrawingTool {
GeometryFactory gf = new GeometryFactory();
LineString ls = gf.createLineString(new Coordinate[] { p1, p2 });
theDrawingLayer.addTempLine(ls);
ls = theDrawingLayer.convertPixels(ls);
if (theDrawingLayer.isErase()) {
theDrawingLayer.addTempEraseLine(ls);
} else {
theDrawingLayer.addTempDrawLine(ls);
}
theLastMouseX = x;
theLastMouseY = y;
editor.refresh();
@ -149,25 +158,28 @@ public class PathDrawingTool extends AbstractDrawingTool {
*/
@Override
public boolean handleMouseUp(int anX, int aY, int button) {
if (button != 1
|| !theDrawingLayer.getCapability(EditableCapability.class)
.isEditable()) {
return false;
}
// change the cursor back on up
Cursor cursor = new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW);
Display.getCurrent().getActiveShell().setCursor(cursor);
cursor.dispose();
if (button != 1) {
return false;
}
theDrawingLayer.resetTemp();
Coordinate[] coords = (Coordinate[]) pathList
.toArray(new Coordinate[pathList.size()]);
GeometryFactory gf = new GeometryFactory();
if (coords.length > 1) {
LineString ls = gf.createLineString(coords);
ls = theDrawingLayer.convertPixels(ls);
if (!theDrawingLayer.isErase()) {
theDrawingLayer.addLine(ls, null);
theDrawingLayer.finalizeLine(ls, null);
}
}
editor.refresh();
return true;
}
}