From: lingutln Date: Mon, 26 Dec 2011 03:18:08 +0000 (+0000) Subject: Implemented functionality of toggling between Segmentation mode and labelling mode... X-Git-Url: http://gitweb.planteome.org/?a=commitdiff_plain;h=87a846b560ca952761cda8d996cdaca654b575cf;p=old-jaiswallab-svn%2F.git Implemented functionality of toggling between Segmentation mode and labelling mode. Done by Nikhil. svn path=/; revision=237 --- diff --git a/Annotation/library/commons-lang3-3.1.jar b/Annotation/library/commons-lang3-3.1.jar new file mode 100644 index 0000000..a85e539 Binary files /dev/null and b/Annotation/library/commons-lang3-3.1.jar differ diff --git a/Annotation/src/ie/dcu/apps/ist/controllers/AnnotationTool.java b/Annotation/src/ie/dcu/apps/ist/controllers/AnnotationTool.java index eb89bb0..e02fecf 100644 --- a/Annotation/src/ie/dcu/apps/ist/controllers/AnnotationTool.java +++ b/Annotation/src/ie/dcu/apps/ist/controllers/AnnotationTool.java @@ -38,7 +38,6 @@ public class AnnotationTool extends MouseMotionAdapter { this.current = null; this.lineWidth = 1; this.type = AnnotationType.Foreground; - attach(view); } @@ -48,9 +47,9 @@ public class AnnotationTool extends MouseMotionAdapter { * @param view */ public void attach(ImageControl view) { + detach(); - - if (view != null) { + if (view != null) { this.view = view; canvas = view.getCanvas(); canvas.addMouseListener(this); @@ -107,7 +106,7 @@ public class AnnotationTool extends MouseMotionAdapter { /** * @param type the annotation type to set */ - public void setType(AnnotationType type) { + public void setType(AnnotationType type, boolean isLabelling) { assert (type != null); this.type = type; } diff --git a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java index 56669a4..c13f1a9 100644 --- a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java +++ b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java @@ -68,6 +68,9 @@ public class SegmentationView extends Composite { // Auto segment on update flag private boolean auto = true; + + // Inorder to toggle between segmentation and Labelling mode. Initially under Segmentation Mode + private boolean labelMode = false; // Combo box housing the selectable views private Combo combo; @@ -154,7 +157,10 @@ public class SegmentationView extends Composite { private void addListeners() { brushControl.addSelectionListener(eventHandler); - view.addContextChangeListener(eventHandler); + if(!labelMode) + { + view.addContextChangeListener(eventHandler); + } view.addZoomListener(eventHandler); addDisposeListener(eventHandler); } @@ -201,11 +207,14 @@ public class SegmentationView extends Composite { */ private void createToolbar3() { SwtUtils.addLabel(bar3, getAction(Tool.SetLabel).getText()); - comboLabel = SwtUtils.addCombo(bar3, 130, SWT.SIMPLE); + comboLabel = SwtUtils.addCombo(bar3, 150, SWT.SIMPLE); comboLabel.setToolTipText( getAction(Tool.SetLabel).getToolTipText()); comboLabel.addKeyListener(new KeyListener() { @Override public void keyReleased(KeyEvent e) { + /* + * For the down arrow functionality + */ if(e.keyCode == 16777218) { comboLabel.setListVisible(true); @@ -342,8 +351,8 @@ public class SegmentationView extends Composite { } - public void setAnnotationType(AnnotationType type) { - view.setAnnotationType(type); + public void setAnnotationType(AnnotationType type, boolean isLabelling) { + view.setAnnotationType(type, isLabelling); } @@ -421,6 +430,26 @@ public class SegmentationView extends Composite { this.auto = checked; } + public void setLabellingMode(boolean checked) { + if (!this.labelMode && checked) { + // Toggling between Segmentation and labelling + Tool.Foreground.action.setEnabled(false); + Tool.Background.action.setEnabled(false); + setAnnotationType(AnnotationType.Background, true); + view.removeContextChangeListener(eventHandler); + if(!(view.getTool() == null)) + { + view.getTool().detach(); + } + } + else + { + view.addContextChangeListener(eventHandler); + view.getTool().attach(view.getImageControl()); + } + this.labelMode = checked; + updateToolStates(); + } public boolean isAutoApply() { return this.auto; @@ -689,6 +718,7 @@ public class SegmentationView extends Composite { switch (a) { case Foreground: case Background: + case OperatingMode: case AutoApply: return Action.AS_CHECK_BOX; case SetBrushSize: @@ -703,10 +733,13 @@ public class SegmentationView extends Composite { private void execute(Tool a, Event e) { switch (a) { case Foreground: - setAnnotationType(AnnotationType.Foreground); + setAnnotationType(AnnotationType.Foreground, false); break; case Background: - setAnnotationType(AnnotationType.Background); + setAnnotationType(AnnotationType.Background, false); + break; + case OperatingMode: + setLabellingMode(a.action.isChecked()); break; case ZoomIn: zoomIn(); @@ -769,17 +802,19 @@ public class SegmentationView extends Composite { assign.setEnabled(canZoomBestFit() & !(comboLabel.getText().isEmpty())); Tool.Foreground.action.setChecked(isAnnotatingForeground()); Tool.Background.action.setChecked(isAnnotatingBackground()); + Tool.OperatingMode.action.setChecked(labelMode); Tool.Clear.action.setEnabled(canClear()); Tool.AutoApply.action.setChecked(auto); Tool.SegmenterOptions.action.setEnabled(canShowOptions()); + Tool.Foreground.action.setEnabled(!labelMode && canZoomIn()); + Tool.Background.action.setEnabled(!labelMode && canZoomIn()); + Tool.OperatingMode.action.setEnabled(canZoomIn()); // Always enabled if view enabled Tool.SetBrushSize.action.setEnabled(true); Tool.SegmenterOptions.action.setEnabled(true); Tool.SetPainter.action.setEnabled(true); Tool.Repaint.action.setEnabled(true); - Tool.Foreground.action.setEnabled(true); - Tool.Background.action.setEnabled(true); Tool.AutoApply.action.setEnabled(true); } else { diff --git a/Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java b/Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java index ed1c4b1..f023313 100644 --- a/Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java +++ b/Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java @@ -72,10 +72,10 @@ public class AnnotatedImageControl extends Composite { // Detach old tool int lineWidth = 1; - if (tool != null) { - lineWidth = tool.getLineWidth(); - tool.detach(); - tool = null; + if (getTool() != null) { + lineWidth = getTool().getLineWidth(); + getTool().detach(); + setTool(null); } // Detach old annotation listener @@ -92,8 +92,8 @@ public class AnnotatedImageControl extends Composite { annotations.addAnnotationListener(listener); // Attach a new annotation tool - tool = new AnnotationTool(annotations, view); - tool.setLineWidth(lineWidth); + setTool(new AnnotationTool(annotations, view)); + getTool().setLineWidth(lineWidth); } // Create the initial image @@ -105,31 +105,31 @@ public class AnnotatedImageControl extends Composite { public int getLineWidth() { - if (tool != null) { - return tool.getLineWidth(); + if (getTool() != null) { + return getTool().getLineWidth(); } return 1; } public void setLineWidth(int width) { - if (tool != null) { - tool.setLineWidth(width); + if (getTool() != null) { + getTool().setLineWidth(width); } } public AnnotationType getAnnotationType() { - if (tool != null) { - return tool.getType(); + if (getTool() != null) { + return getTool().getType(); } return AnnotationType.Foreground; } - public void setAnnotationType(AnnotationType type) { - if (tool != null) { - tool.setType(type); + public void setAnnotationType(AnnotationType type, boolean isLabelling) { + if (getTool() != null) { + getTool().setType(type, isLabelling); } } @@ -351,6 +351,16 @@ public class AnnotatedImageControl extends Composite { } + public AnnotationTool getTool() { + return tool; + } + + + public void setTool(AnnotationTool tool) { + this.tool = tool; + } + + private final DisposeListener disposeListener = new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (cursor != null) {