Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Regular commits. Done by Nikhil.
authorlingutln <lingutln@localhost>
Tue, 24 Jan 2012 22:14:41 +0000 (22:14 +0000)
committerlingutln <lingutln@localhost>
Tue, 24 Jan 2012 22:14:41 +0000 (22:14 +0000)
svn path=/; revision=275

Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java
Annotation/src/ie/dcu/swt/SwtUtils.java

index d91c1ebb93fc6201de59bb7949814ad93f3b6ef1..2bc5cb4990ebdc89097805fa4e4f67b7f70ec6ee 100644 (file)
@@ -48,10 +48,6 @@ public class SegmentationView extends Composite {
        // Left and right tool bar
        private final ToolBar bar1, bar2, bar3;
        
-       private final Button assign;
-       
-       //private final StyledText text;                
-       
        // Control to change brush size
        private final BrushControl brushControl;
        
@@ -75,6 +71,8 @@ public class SegmentationView extends Composite {
 
        public static Combo comboLabel;
        
+       private static Button assign;
+       
        // Current segmentation tool
        private Segmenter segmenter;
        
@@ -123,7 +121,6 @@ public class SegmentationView extends Composite {
                bar1 = new ToolBar(this, SWT.RIGHT | SWT.FLAT);
                bar2 = new ToolBar(this, SWT.RIGHT | SWT.FLAT);
                bar3 = new ToolBar(this, SWT.RIGHT | SWT.FLAT);
-               assign = new Button(bar3, SWT.PUSH);
                view = new AnnotatedImageControl(this, SWT.BORDER);
                brushControl = new BrushControl(getShell(), SWT.BORDER);
                eventHandler = new EventHandler();
@@ -212,39 +209,13 @@ public class SegmentationView extends Composite {
                SwtUtils.addLabel(bar3, getAction(Tool.SetLabel).getText());
                comboLabel = SwtUtils.addCombo(bar3, 150, SWT.SIMPLE);
                comboLabel.setToolTipText( getAction(Tool.SetLabel).getToolTipText());
-               comboLabel.addKeyListener(new KeyListener() {
-                       @Override
+               comboLabel.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent e) {
-                               ArrayList<String> listElements = new ArrayList<String>();
-                               //For the down arrow functionality
-                               if(e.keyCode == 16777218)
-                               {
-                                       comboLabel.setListVisible(true);
-                               }
-                               // If key pressed is only a number of charecter or space.
-                               else if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32)
-                               {
-                                       //For removing all previously assigned labels
-                                       comboLabel.remove(0,comboLabel.getItemCount()-1);
-                                       listElements = labels.getLabels(comboLabel.getText());
-                                       assign.setEnabled(!(comboLabel.getText().isEmpty()));
-                                       
-                               }
-                               for (int i=0; i<listElements.size();i++)
-                               {
-                                       comboLabel.add(listElements.get(i),i);
-                               }
-                       }
-                       @Override
-                       public void keyPressed(KeyEvent arg0) {
-                               // TODO Auto-generated method stub
+                               dropdownLabels(e);
                        }
                });
-               ToolItem item = new ToolItem(bar3, SWT.SEPARATOR);
-               assign.setText("Assign");
-               item.setWidth(50);
-               item.setControl(assign);
-               assign.addSelectionListener(new SelectionListener() {
+               assign = SwtUtils.addButton(bar3, 50, "Assign");
+               assign.addSelectionListener(new SelectionAdapter() {
         public void widgetSelected(SelectionEvent arg0) {
                if(view.getContext().isEnabled())
                {
@@ -257,18 +228,39 @@ public class SegmentationView extends Composite {
                                view.getContext().getEnabledMask().segmentName = comboLabel.getText();
                        }
                }
-               System.out.println("selected"+view.getContext().getEnabledMask().segmentName);
                execute(Tool.AssignButton, null);
                }
-               @Override
-               public void widgetDefaultSelected(SelectionEvent arg0) {
-                       // TODO Auto-generated method stub
-               }
                });
                bar3.pack();
        }
        
-       
+       /**
+        * For dropping down the labels on pressing the down arrow key just like "Google suggests" functionality.
+        * @param e
+        */
+       public void dropdownLabels(KeyEvent e)
+       {
+               ArrayList<String> listElements = new ArrayList<String>();
+               //For the down arrow functionality
+               if(e.keyCode == 16777218)
+               {
+                       comboLabel.setListVisible(true);
+               }
+               // If key pressed is only a number of charecter or space.
+               else if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32)
+               {
+                       //For removing all previously assigned labels
+                       comboLabel.remove(0,comboLabel.getItemCount()-1);
+                       listElements = labels.getLabels(comboLabel.getText());
+                       assign.setEnabled(!(comboLabel.getText().isEmpty()));
+                       
+               }
+               for (int i=0; i<listElements.size();i++)
+               {
+                       comboLabel.add(listElements.get(i),i);
+               }
+       }
+               
        private void layoutControls() {
                GridLayout layout = new GridLayout(3, false);
                layout.marginHeight = 1;
@@ -357,7 +349,6 @@ public class SegmentationView extends Composite {
                return segmenter;
        }
        
-       
        public void setContext(SegmentationContext ctx) {
                
                // context change handler handles initialization etc. 
index fd1d95e8949fcbe519bf893f0f56255405e2f54e..d9fe8ff5af3ae41bede16df5b10a887239e3a938 100644 (file)
@@ -602,6 +602,24 @@ public class SwtUtils {
                return combo;
        }
        
+       /**
+        * Add a button to the given ToolBar. 
+        * 
+        * @param bar
+        *            A ToolBar.
+        * @param width
+        *            The horizontal width to make the ToolBar.
+        * 
+        */
+       public static Button addButton(ToolBar bar, int width, String text) {
+               ToolItem item = new ToolItem(bar, SWT.SEPARATOR);
+               Button button = new Button(bar, SWT.PUSH);
+               button.setText(text);
+               item.setWidth(width);
+               item.setControl(button);
+               return button;
+       }
+       
        /**
         * Center the given shell on the Display.
         *