aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorkild U. Resheim2013-11-13 15:16:11 (EST)
committerTorkild U. Resheim2013-11-13 17:20:41 (EST)
commit530b86176c076bd419749b536d0c60ed5cfdeefc (patch)
treeebdbf519ce67b10b3b112afff8400b621c1c257f
parent63076d815fa02272b1968abd344cf4275df8f155 (diff)
downloadorg.eclipse.nebula-530b86176c076bd419749b536d0c60ed5cfdeefc.zip
org.eclipse.nebula-530b86176c076bd419749b536d0c60ed5cfdeefc.tar.gz
org.eclipse.nebula-530b86176c076bd419749b536d0c60ed5cfdeefc.tar.bz2
Bug 421670 - Add Cross and Circle annotation types to XYGraphrefs/changes/54/18354/3
Change-Id: I01b024ef3c9c8df4e25dc76baa3c05147c6ca69b Signed-off-by: Torkild U. Resheim <torkildr@gmail.com>
-rw-r--r--widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/Annotation.java303
-rw-r--r--widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/CircleAnnotation.java56
-rw-r--r--widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/CrossAnnotation.java67
3 files changed, 277 insertions, 149 deletions
diff --git a/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/Annotation.java b/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/Annotation.java
index 6887486..fb3c9d4 100644
--- a/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/Annotation.java
+++ b/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/Annotation.java
@@ -1,9 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2010 Oak Ridge National Laboratory.
+ * Copyright (c) 2010, 2013 Oak Ridge National Laboratory and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xihui Chen - initial API and implementation
+ * Torkild U. Resheim - Expose fields and methods for subclassing bug 421670
******************************************************************************/
package org.eclipse.nebula.visualization.xygraph.figures;
@@ -38,8 +42,9 @@ import org.eclipse.swt.graphics.RGB;
/**
* Annotation Figure. Annotation could be used to indicate the information for a particular
* point.
- * @author Xihui Chen
*
+ * @author Xihui Chen
+ * @author Torkild U. Resheim
*/
public class Annotation extends Figure implements IAxisListener, IDataProviderListener {
/** The way how the cursor line will be drawn. */
@@ -51,15 +56,15 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
NONE(0, "None"),
UP_DOWN(1, "Up&Down"),
LEFT_RIGHT(2, "Left&Right"),
- FOUR_DIRECTIONS(3, "Four Directions");
-
+ FOUR_DIRECTIONS(3, "Four Directions");
+
private CursorLineStyle(int index, String description) {
this.index = index;
this.description = description;
}
private int index;
private String description;
-
+
@Override
public String toString() {
return description;
@@ -70,41 +75,41 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
for(CursorLineStyle p : values())
sv[i++] = p.toString();
return sv;
- }
+ }
/**
* @return the index
*/
public int getIndex() {
return index;
}
-
-
- }
-
-
-
- private Axis xAxis;
- private Axis yAxis;
+
+
+ }
+
+
+
+ protected Axis xAxis;
+ protected Axis yAxis;
private String name;
private FontData fontData;
-
+
private CursorLineStyle cursorLineStyle = CursorLineStyle.NONE;
private Point currentPosition;
- private double xValue;
- private double yValue;
-
-
- private Trace trace;
- private ISample currentSnappedSample;
-
+ protected double xValue;
+ protected double yValue;
+
+
+ protected Trace trace;
+ protected ISample currentSnappedSample;
+
private boolean showName = true;
private boolean showSampleInfo = true;
private boolean showPosition = true;
-
+
private Color annotationColor = null;
private RGB annotationColorRGB = null;
-
+
private Label infoLabel;
//label's relative position to currentPosition
private double dx = 40;
@@ -113,31 +118,31 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
private double x0, y0;
private boolean knowX0Y0 = false;
private boolean infoLabelArmed = false;
-
+
private Pointer pointer;
-
+
private Polyline vLine, hLine;
-
+
private XYGraph xyGraph;
-
+
private final static int POINT_SIZE = 6;
private final static int CURSOR_LINE_LENGTH = 3;
private final static int ARROW_LINE_LENGTH = 12;
- private boolean pointerDragged;
-
+ protected boolean pointerDragged;
+
private List<IAnnotationListener> listeners;
-
+
/**Construct an annotation on a trace.
* @param name the name of the annotation.
* @param trace the trace which the annotation will snap to.
- */
+ */
public Annotation(String name, Trace trace) {
this(name, trace.getXAxis(), trace.getYAxis());
this.trace = trace;
trace.getDataProvider().addDataProviderListener(this);
}
-
+
/**Construct a free annotation.
* @param xAxis the xAxis of the annotation.
* @param yAxis the yAxis of the annotation.
@@ -147,29 +152,29 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
this.xAxis = xAxis;
this.yAxis = yAxis;
this.name = name;
- trace = null;
+ trace = null;
infoLabel = new Label();
infoLabel.setOpaque(false);
- infoLabel.setCursor(Cursors.SIZEALL);
+ infoLabel.setCursor(Cursors.SIZEALL);
add(infoLabel);
InfoLabelDragger infoLabelDragger = new InfoLabelDragger();
infoLabel.addMouseMotionListener(infoLabelDragger);
- infoLabel.addMouseListener(infoLabelDragger);
+ infoLabel.addMouseListener(infoLabelDragger);
pointer = new Pointer();
add(pointer);
- updateToDefaultPosition();
+ updateToDefaultPosition();
xAxis.addListener(this);
yAxis.addListener(this);
}
-
-
+
+
public synchronized void addAnnotationListener(IAnnotationListener listener){
if(listeners == null)
listeners = new CopyOnWriteArrayList<IAnnotationListener>();
listeners.add(listener);
}
-
+
private void fireAnnotationMoved(double oldX, double oldY, double newX, double newY){
if(listeners == null)
return;
@@ -177,15 +182,15 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
listener.annotationMoved(oldX, oldY, newX, newY);
}
}
-
+
@Override
public boolean containsPoint(int x, int y) {
-
+
return infoLabel.containsPoint(x, y) || pointer.containsPoint(x,y) ||
(vLine !=null?vLine.containsPoint(x, y):false)||
(hLine !=null?hLine.containsPoint(x, y):false);
}
-
+
@Override
protected void layout() {
super.layout();
@@ -193,11 +198,11 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
updateToDefaultPosition();
Dimension size = infoLabel.getPreferredSize();
updateX0Y0Fromdxdy(size);
- Rectangle infoBounds = new Rectangle((int) (currentPosition.x + x0 - size.width/2.0),
+ Rectangle infoBounds = new Rectangle((int) (currentPosition.x + x0 - size.width/2.0),
(int) (currentPosition.y +y0 - size.height/2.0), size.width, size.height);
-
- infoLabel.setBounds(infoBounds);
-
+
+ infoLabel.setBounds(infoBounds);
+
pointer.setBounds(new Rectangle(currentPosition.x - POINT_SIZE, currentPosition.y - POINT_SIZE,
2*POINT_SIZE, 2*POINT_SIZE));
// layout Cursor Line
@@ -220,18 +225,18 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
break;
}
}
-
+
@Override
protected void paintFigure(Graphics graphics) {
super.paintFigure(graphics);
if(trace != null && currentSnappedSample == null &&!pointerDragged)
updateToDefaultPosition();
-
+
if (Preferences.useAdvancedGraphics())
graphics.setAntialias(SWT.ON);
Color tempColor;
if(annotationColor == null){
- tempColor = yAxis.getForegroundColor();
+ tempColor = yAxis.getForegroundColor();
}else
tempColor = annotationColor;
infoLabel.setForegroundColor(tempColor);
@@ -240,8 +245,8 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
vLine.setForegroundColor(tempColor);
if(hLine != null)
hLine.setForegroundColor(tempColor);
- graphics.setForegroundColor(tempColor);
-
+ graphics.setForegroundColor(tempColor);
+
if(infoLabelArmed) //draw infoLabel Armed rect
graphics.drawRectangle(infoLabel.getBounds());
if (showName || showPosition || showSampleInfo) {
@@ -270,27 +275,27 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
switch (cursorLineStyle) {
case NONE:
//left
- graphics.drawLine(currentPosition.x - POINT_SIZE/2, currentPosition.y,
+ graphics.drawLine(currentPosition.x - POINT_SIZE/2, currentPosition.y,
currentPosition.x - POINT_SIZE/2 - CURSOR_LINE_LENGTH, currentPosition.y);
//right
- graphics.drawLine(currentPosition.x + POINT_SIZE/2, currentPosition.y,
+ graphics.drawLine(currentPosition.x + POINT_SIZE/2, currentPosition.y,
currentPosition.x + POINT_SIZE/2 + CURSOR_LINE_LENGTH, currentPosition.y);
//up
- graphics.drawLine(currentPosition.x , currentPosition.y - POINT_SIZE/2,
+ graphics.drawLine(currentPosition.x , currentPosition.y - POINT_SIZE/2,
currentPosition.x, currentPosition.y - POINT_SIZE/2 - CURSOR_LINE_LENGTH);
//down
- graphics.drawLine(currentPosition.x , currentPosition.y + POINT_SIZE/2,
- currentPosition.x, currentPosition.y + POINT_SIZE/2 + CURSOR_LINE_LENGTH);
- break;
+ graphics.drawLine(currentPosition.x , currentPosition.y + POINT_SIZE/2,
+ currentPosition.x, currentPosition.y + POINT_SIZE/2 + CURSOR_LINE_LENGTH);
+ break;
default:
break;
}
-
-
+
+
}
-
-
+
+
/**update (x0, y0) if it is unknown.
* @param size the label size
* @return
@@ -304,50 +309,50 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
//assume this is the intersection
y0 = dy-h/2.0;
x0 = (dx/dy)*y0;
- if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
+ if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
new Range(x0-w/2.0, x0 + w/2.0).inRange(dx))
return;
-
+
y0 = dy+h/2.0;
x0 = (dx/dy)*y0;
- if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
+ if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
new Range(x0-w/2.0, x0 + w/2.0).inRange(dx))
return;
}else{
-
+
}
if(dx!=0){
x0 = dx+w/2.0;
y0 = (dy/dx)*x0;
- if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
+ if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
new Range(y0-h/2.0, y0+h/2.0).inRange(dy))
return;
-
+
x0 = dx-w/2.0;
y0 = (dy/dx)*x0;
- if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
+ if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
new Range(y0-h/2.0, y0+h/2.0).inRange(dy))
return;
}
- }else
+ }else
return;
}
-
+
/**update (dx, dy) if (x0, y0) has been updated by dragging.
* @param size the label size
* @return
*/
- private void updatedxdyFromX0Y0() {
+ private void updatedxdyFromX0Y0() {
Dimension size = infoLabel.getPreferredSize();
int h = size.height;
int w = size.width;
if(y0 != 0){
dy = y0+h/2.0;
dx = x0*dy/y0;
- if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
+ if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
new Range(x0-w/2.0, x0 + w/2.0).inRange(dx))
return;
-
+
dy = y0-h/2.0;
dx = x0*dy/y0;
if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
@@ -359,24 +364,24 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
if(x0 != 0){
dx = x0-size.width/2.0;
dy = y0*dx/x0;
- if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
+ if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
new Range(y0-h/2.0, y0+h/2.0).inRange(dy))
return;
-
+
dx = x0+size.width/2.0;
dy = y0*dx/x0;
if(new Range(0, x0).inRange(dx) && new Range(0, y0).inRange(dy) &&
new Range(y0-h/2.0, y0+h/2.0).inRange(dy))
- return;
+ return;
}else
dx=0;
}
-
-
+
+
/**
* move the annotation to the center of the plot area or trace.
*/
- private void updateToDefaultPosition(){
+ protected void updateToDefaultPosition(){
double oldX = xValue;
double oldY = yValue;
if(trace != null && trace.getHotSampleList().size()>0){
@@ -399,8 +404,8 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
yValue = (yAxis.getRange().getLower() + yAxis.getRange().getUpper())/2;
currentPosition = new Point(xAxis.getValuePosition(xValue, false),
- yAxis.getValuePosition(yValue, false));
- }
+ yAxis.getValuePosition(yValue, false));
+ }
updateInfoLableText(true);
if(xValue != oldX || yValue != oldY)
revalidate();
@@ -420,34 +425,34 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
yValue = y;
currentPosition = new Point(xAxis.getValuePosition(xValue, false),
- yAxis.getValuePosition(yValue, false));
+ yAxis.getValuePosition(yValue, false));
updateInfoLableText(true);
revalidate();
if(oldX != xValue || oldY != yValue)
fireAnnotationMoved(oldX, oldY, xValue, yValue);
}
-
+
/**
- *
+ *
*/
private void updateInfoLableText(boolean updateX0Y0) {
- String info = "";
+ String info = "";
if(showName)
info = name;
if(showSampleInfo && currentSnappedSample != null && !currentSnappedSample.getInfo().equals(""))
info += "\n" + currentSnappedSample.getInfo();
if(showPosition)
- info += "\n" + "(" + xAxis.format(xValue) + ", " +
- (Double.isNaN(yValue) ? "NaN" : yAxis.format(yValue)) + ")";
+ info += "\n" + "(" + xAxis.format(xValue) + ", " +
+ (Double.isNaN(yValue) ? "NaN" : yAxis.format(yValue)) + ")";
infoLabel.setText(info);
- knowX0Y0 = !updateX0Y0;
+ knowX0Y0 = !updateX0Y0;
}
-
+
private void updateInfoLableText(){
updateInfoLableText(true);
}
-
-
+
+
/**
* @param axis the xAxis to set
*/
@@ -455,7 +460,7 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
if(this.xAxis == axis)
return;
xAxis = axis;
- updateToDefaultPosition();
+ updateToDefaultPosition();
revalidate();
repaint();
}
@@ -465,7 +470,7 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
public void setYAxis(Axis axis) {
if(this.yAxis == axis)
return;
- yAxis = axis;
+ yAxis = axis;
updateToDefaultPosition();
revalidate();
repaint();
@@ -477,15 +482,15 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
this.name = name;
updateInfoLableText();
}
-
-
-
-
+
+
+
+
@Override
public void setFont(Font f) {
// TODO Auto-generated method stub
super.setFont(f);
-
+
if(f != null)
this.fontData = getFont().getFontData()[0];
}
@@ -497,13 +502,13 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
/**
* @param trace the trace to set
*/
- public void setTrace(Trace trace) {
+ public void setTrace(Trace trace) {
if(this.trace == trace)
return;
this.xAxis = trace.getXAxis();
- this.yAxis = trace.getYAxis();
+ this.yAxis = trace.getYAxis();
if(!isFree() && this.trace != trace)
- this.trace.getDataProvider().removeDataProviderListener(this);
+ this.trace.getDataProvider().removeDataProviderListener(this);
if(isFree() || this.trace != trace){
this.trace = trace;
updateToDefaultPosition();
@@ -512,30 +517,30 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
trace.getDataProvider().addDataProviderListener(this);
repaint();
}
-
+
/**Make the annotation free.
- * @param xAxis
+ * @param xAxis
* @param yAxis
*/
- public void setFree(Axis xAxis, Axis yAxis){
- if(trace != null){
+ public void setFree(Axis xAxis, Axis yAxis){
+ if(trace != null){
trace.getDataProvider().removeDataProviderListener(this);
trace = null;
- updateToDefaultPosition();
- }
+ updateToDefaultPosition();
+ }
setXAxis(xAxis);
setYAxis(yAxis);
revalidate();
repaint();
}
-
+
/**
* @return true if the annotation is free.
*/
public boolean isFree(){
return trace == null;
}
-
+
/**
* @param showName the showName to set
*/
@@ -562,10 +567,10 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
*/
public void setAnnotationColor(Color annotationColor) {
this.annotationColor = annotationColor;
-
+
if(annotationColor != null)
this.annotationColorRGB = annotationColor.getRGB();
-
+
infoLabel.setForegroundColor(annotationColor);
pointer.setForegroundColor(annotationColor);
}
@@ -590,18 +595,18 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
vLine.addMouseListener(annotationDragger);
vLine.addMouseMotionListener(annotationDragger);
vLine.setTolerance(3);
- add(vLine, 0);
+ add(vLine, 0);
}
}
if(cursorLineStyle == CursorLineStyle.LEFT_RIGHT || cursorLineStyle == CursorLineStyle.FOUR_DIRECTIONS){
- if(hLine == null){
+ if(hLine == null){
hLine = new Polyline();
hLine.setCursor(Cursors.SIZENS);
AnnotationDragger annotationDragger = new AnnotationDragger(false, true);
hLine.addMouseListener(annotationDragger);
hLine.addMouseMotionListener(annotationDragger);
hLine.setTolerance(3);
- add(hLine,0);
+ add(hLine,0);
}
}
if(cursorLineStyle == CursorLineStyle.UP_DOWN){
@@ -617,8 +622,8 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
}
}
}
-
-
+
+
/**
* @param currentPosition the currentPosition to set
*/
@@ -629,7 +634,7 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
x0 +=deltaX;
y0 +=deltaY;
knowX0Y0 = true;
- updatedxdyFromX0Y0();
+ updatedxdyFromX0Y0();
}
this.currentPosition = currentPosition;
if(calcValueFromPosition){
@@ -641,16 +646,16 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
}
updateInfoLableText(keepLablePosition);
revalidate();
- repaint();
+ repaint();
}
-
+
public void setCurrentPosition(Point currentPosition, boolean keepLablePosition){
setCurrentPosition(currentPosition, keepLablePosition, true);
}
/**
* @param currentSnappedSample the currentSnappedSample to set
- * @param keepLabelPosition
+ * @param keepLabelPosition
*/
public void setCurrentSnappedSample(ISample currentSnappedSample, boolean keepLabelPosition) {
if(!trace.getHotSampleList().contains(currentSnappedSample))
@@ -670,8 +675,8 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
}
repaint();
}
-
-
+
+
public void axisRevalidated(Axis axis) {
currentPosition = new Point(xAxis.getValuePosition(xValue, false),
@@ -680,7 +685,7 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
if(getParent()!=null)
layout();
}
-
+
public void axisRangeChanged(Axis axis, Range old_range, Range new_range) {
//do nothing
}
@@ -692,22 +697,22 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
double oldX=xValue;
double oldY=yValue;
if (yValue != currentSnappedSample.getYValue())
- { // When waveform index is changed, Y value of the
+ { // When waveform index is changed, Y value of the
// snapped sample is also changed. In that case,
// the position of this annotation must be updated
// accordingly.
- yValue = currentSnappedSample.getYValue();
+ yValue = currentSnappedSample.getYValue();
}
if (xValue != currentSnappedSample.getXValue())
{
xValue = currentSnappedSample.getXValue();
}
currentPosition = new Point(xAxis.getValuePosition(xValue, false),
- yAxis.getValuePosition(yValue, false));
+ yAxis.getValuePosition(yValue, false));
fireAnnotationMoved(oldX, oldY, xValue, yValue);
- }
+ }
else if(trace.getHotSampleList().size() > 0){
- updateToDefaultPosition();
+ updateToDefaultPosition();
pointerDragged = false;
}
}
@@ -718,7 +723,7 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
public void setxyGraph(XYGraph xyGraph) {
this.xyGraph = xyGraph;
}
-
+
public void setdxdy(double dx, double dy){
this.dx = dx;
this.dy = dy;
@@ -758,7 +763,7 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
public double getYValue() {
return yValue;
}
-
+
/**
* @return the cursorLineStyle
*/
@@ -804,7 +809,7 @@ public class Annotation extends Figure implements IAxisListener, IDataProviderLi
class InfoLabelDragger extends MouseMotionListener.Stub implements MouseListener{
-
+
private MovingAnnotationLabelCommand command;
@Override
public void mouseDragged(MouseEvent me) {
@@ -818,7 +823,7 @@ class InfoLabelDragger extends MouseMotionListener.Stub implements MouseListener
}
public void mouseDoubleClicked(MouseEvent me) {}
-
+
public void mousePressed(MouseEvent me) {
command = new MovingAnnotationLabelCommand(Annotation.this);
command.setBeforeMovingDxDy(dx, dy);
@@ -827,7 +832,7 @@ class InfoLabelDragger extends MouseMotionListener.Stub implements MouseListener
Annotation.this.repaint();
me.consume(); //it must be consumed to make dragging smoothly.
}
-
+
public void mouseReleased(MouseEvent me) {
command.setAfterMovingDxDy(dx, dy);
xyGraph.getOperationsManager().addCommand(command);
@@ -836,17 +841,17 @@ class InfoLabelDragger extends MouseMotionListener.Stub implements MouseListener
Annotation.this.repaint();
me.consume();
}
-
+
}
private class AnnotationDragger extends MouseMotionListener.Stub implements MouseListener {
private MovingAnnotationCommand command;
-
+
private boolean horizontalMoveable;
private boolean verticalMoveable;
-
-
+
+
public AnnotationDragger(boolean horizontalMoveable, boolean verticalMoveable) {
this.horizontalMoveable = horizontalMoveable;
@@ -918,30 +923,30 @@ class InfoLabelDragger extends MouseMotionListener.Stub implements MouseListener
}
}
-
-class Pointer extends Figure{
-
+
+class Pointer extends Figure{
+
public Pointer() {
setCursor(Cursors.CROSS);
AnnotationDragger dragger = new AnnotationDragger(true, true);
addMouseMotionListener(dragger);
addMouseListener(dragger);
}
-
+
@Override
protected void paintClientArea(Graphics graphics) {
super.paintClientArea(graphics);
if (Preferences.useAdvancedGraphics())
graphics.setAntialias(SWT.ON);
- //draw X-cross point
- Rectangle clientArea = getClientArea().getCopy().shrink(POINT_SIZE/2, POINT_SIZE/2);
+ //draw X-cross point
+ Rectangle clientArea = getClientArea().getCopy().shrink(POINT_SIZE/2, POINT_SIZE/2);
graphics.drawLine(clientArea.x, clientArea.y,
clientArea.x + clientArea.width, clientArea.y + clientArea.height);
graphics.drawLine(clientArea.x + clientArea.width, clientArea.y,
clientArea.x, clientArea.y + clientArea.height);
-
+
}
-}
+}
public void axisForegroundColorChanged(Axis axis, Color oldColor,
Color newColor) {
@@ -949,16 +954,16 @@ public void axisForegroundColorChanged(Axis axis, Color oldColor,
}
public void axisTitleChanged(Axis axis, String oldTitle, String newTitle) {
-
+
}
public void axisAutoScaleChanged(Axis axis, boolean oldAutoScale,
boolean newAutoScale) {
-
+
}
public void axisLogScaleChanged(Axis axis, boolean old, boolean logScale) {
-
+
}
public RGB getAnnotationColorRGB() {
diff --git a/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/CircleAnnotation.java b/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/CircleAnnotation.java
new file mode 100644
index 0000000..dab2898
--- /dev/null
+++ b/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/CircleAnnotation.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2013 MARINTEK
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Torkild U. Resheim - Initial implementation
+ ******************************************************************************/
+package org.eclipse.nebula.visualization.xygraph.figures;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.nebula.visualization.xygraph.dataprovider.ISample;
+import org.eclipse.nebula.visualization.xygraph.figures.Annotation;
+import org.eclipse.nebula.visualization.xygraph.figures.Trace;
+import org.eclipse.nebula.visualization.xygraph.util.Preferences;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Variation of annotation that is represented as a circle with a diameter of
+ * eight pixels.
+ *
+ * @author Torkild U. Resheim
+ */
+public class CircleAnnotation extends Annotation {
+
+ private final static int CIRCLE_DIAMETER = 8;
+
+ public CircleAnnotation(String name, Trace trace) {
+ super(name, trace);
+ }
+
+ @Override
+ public void setCurrentSnappedSample(ISample currentSnappedSample, boolean keepLabelPosition) {
+ this.currentSnappedSample = currentSnappedSample;
+ repaint();
+ }
+
+ @Override
+ protected void paintFigure(Graphics graphics) {
+ if (trace != null && currentSnappedSample == null && !pointerDragged)
+ updateToDefaultPosition();
+
+ if (Preferences.useAdvancedGraphics())
+ graphics.setAntialias(SWT.ON);
+
+ graphics.setForegroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+ xValue = currentSnappedSample.getXValue();
+ yValue = currentSnappedSample.getYValue();
+ int x = xAxis.getValuePosition(xValue, false);
+ int y = yAxis.getValuePosition(yValue, false);
+ graphics.drawOval(x - (CIRCLE_DIAMETER / 2), y - (CIRCLE_DIAMETER / 2), CIRCLE_DIAMETER, CIRCLE_DIAMETER);
+ }
+} \ No newline at end of file
diff --git a/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/CrossAnnotation.java b/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/CrossAnnotation.java
new file mode 100644
index 0000000..812b7d5
--- /dev/null
+++ b/widgets/visualization/org.eclipse.nebula.visualization.xygraph/src/org/eclipse/nebula/visualization/xygraph/figures/CrossAnnotation.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2013 MARINTEK
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Torkild U. Resheim - Initial implementation
+ ******************************************************************************/
+package org.eclipse.nebula.visualization.xygraph.figures;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.nebula.visualization.xygraph.dataprovider.ISample;
+import org.eclipse.nebula.visualization.xygraph.figures.Annotation;
+import org.eclipse.nebula.visualization.xygraph.figures.Axis;
+import org.eclipse.nebula.visualization.xygraph.figures.Trace;
+import org.eclipse.nebula.visualization.xygraph.util.Preferences;
+import org.eclipse.swt.SWT;
+
+/**
+ * Variation of annotation that is represented as a cross with an arm length of
+ * five pixels.
+ *
+ * @author Torkild U. Resheim
+ */
+public class CrossAnnotation extends Annotation {
+
+ final static int CROSS_SIZE = 5;
+
+ public CrossAnnotation(String name, Trace trace) {
+ super(name, trace);
+ }
+
+ public CrossAnnotation(String name, Axis xAxis, Axis yAxis) {
+ super(name, xAxis, yAxis);
+ }
+
+ @Override
+ public void setCurrentSnappedSample(ISample currentSnappedSample, boolean keepLabelPosition) {
+ this.currentSnappedSample = currentSnappedSample;
+ repaint();
+ }
+
+ @Override
+ protected void paintFigure(Graphics graphics) {
+ if (trace != null && currentSnappedSample == null && !pointerDragged)
+ updateToDefaultPosition();
+
+ if (Preferences.useAdvancedGraphics())
+ graphics.setAntialias(SWT.ON);
+
+ graphics.setForegroundColor(getForegroundColor());
+ xValue = currentSnappedSample.getXValue();
+ yValue = currentSnappedSample.getYValue();
+ int x = xAxis.getValuePosition(xValue, false);
+ int y = yAxis.getValuePosition(yValue, false);
+ Point p = new Point();
+ p.setLocation(y, x);
+
+ graphics.drawLine(x - CROSS_SIZE, y - CROSS_SIZE, x + CROSS_SIZE, y + CROSS_SIZE);
+ graphics.drawLine(x - CROSS_SIZE, y + CROSS_SIZE, x + CROSS_SIZE, y - CROSS_SIZE);
+ graphics.drawLine(x, y + CROSS_SIZE, x, y - CROSS_SIZE);
+ graphics.drawLine(x - CROSS_SIZE, y, x + CROSS_SIZE, y);
+ }
+} \ No newline at end of file