Hello!

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

Note that updates take place every 10 minutes, commits may not be seen immediately.
Popup dialog functionality. Done by Nikhil.
authorlingutln <lingutln@localhost>
Fri, 30 Dec 2011 23:01:28 +0000 (23:01 +0000)
committerlingutln <lingutln@localhost>
Fri, 30 Dec 2011 23:01:28 +0000 (23:01 +0000)
svn path=/; revision=245

Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java
Annotation/src/ie/dcu/apps/ist/labelling/Labels.java [new file with mode: 0644]
Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java

index 0e7d3b9e46cf2d67ce841011e61fcfd1ab6cbe91..bc4e60c2ea5155dc474a2ac5d0725997cab62462 100644 (file)
@@ -1,12 +1,16 @@
 package ie.dcu.apps.ist.dialogs;
 
+import java.util.ArrayList;
+
 import ie.dcu.swt.SwtUtils;
+import ie.dcu.apps.ist.labelling.*;
 import ie.dcu.swt.layout.LayoutFactory;
 
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
@@ -19,12 +23,16 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 
 public class PopUpLabelDialog extends Dialog {
-
+       
+       private Labels labels = new Labels();
+       
        public class Result {
-               public final String image;
+               public final String curator;
+               public final String comboText;
                
                Result() {
-                       image = imageText.getText().trim();
+                       curator = curatorText.getText().trim();
+                       comboText = labelCombo.getText();
                }
        };
        
@@ -39,8 +47,7 @@ public class PopUpLabelDialog extends Dialog {
        
        // Widgets
        private Combo labelCombo;
-       private Text curator;
-       private Text imageText;
+       private Text curatorText;
        
        // Dialog buttons
        private Button cancelButton;
@@ -94,10 +101,38 @@ public class PopUpLabelDialog extends Dialog {
                // Form content
                label(widgets, "Annotate");
                labelCombo = combo(widgets);
+               labelCombo.addKeyListener(new KeyListener() {
+                       @Override
+                       public void keyReleased(KeyEvent e) {
+                               ArrayList<String> listElements = new ArrayList<String>();
+                               //For the down arrow functionality
+                               if(e.keyCode == 16777218)
+                               {
+                                       labelCombo.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
+                                       labelCombo.remove(0,labelCombo.getItemCount()-1);
+                                       listElements = labels.getLabels(labelCombo.getText());
+                               }
+                               for (int i=0; i<listElements.size();i++)
+                               {
+                                       labelCombo.add(listElements.get(i),i);
+                               }
+                       }
+
+                       @Override
+                       public void keyPressed(KeyEvent arg0) {
+                               // TODO Auto-generated method stub
+                               
+                       }
+               });
                spacer(widgets);
                
                label(widgets, "Curator");
-               curator = text(widgets,"Enter your name");
+               curatorText = text(widgets,"Enter your name");
                spacer(widgets);
                hline(widgets);
                
@@ -186,4 +221,5 @@ public class PopUpLabelDialog extends Dialog {
        private GridData layout4() {
                return new GridData(SWT.RIGHT, SWT.BOTTOM, false, false);
        }
+       
 }
diff --git a/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java b/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java
new file mode 100644 (file)
index 0000000..ce6cd69
--- /dev/null
@@ -0,0 +1,63 @@
+package ie.dcu.apps.ist.labelling;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+
+import org.apache.commons.lang3.StringEscapeUtils;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+public class Labels
+{
+       /**
+        * Function for getting the Labels through web service
+        * 
+        * @param
+        * The user entered text in the html element
+        * @return 
+        * ArrayList<String> containing each Label item
+        * 
+        */
+       public ArrayList<String> getLabels(String content) {
+               ArrayList<String> labels = new ArrayList<String>();
+               // temporary variable for storing each list element in the loop
+               String listElement;
+               try
+           {
+                       String encodedContent = URLEncoder.encode(content.toString(),"UTF-8");
+                       URL url = new URL("http://palea.cgrb.oregonstate.edu/services/PO_web_service.php?request_type=term_search&search_value="+encodedContent+"&inc_synonyms&branch_filter=plant_anatomy&max=20");
+                       HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+                       BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+                       // if the response from Web service is 'OK'
+                       if(connection.getResponseCode() == 200)
+               {
+                       String inputLine;
+                       JSONObject object = null;
+                       while ((inputLine = in.readLine()) != null) 
+                       {
+                               object = new JSONObject(inputLine);
+                       }
+                       JSONArray array = new JSONArray(object.getString("PO_term_search_response"));
+                       for(int i=0; i<array.length();i++)
+                       {
+                               listElement = (array.getJSONObject(i).getString("match")+" {"+array.getJSONObject(i).getString("accession_id")+"}");
+                               labels.add(i,StringEscapeUtils.unescapeHtml4(listElement));
+                       }
+                       in.close();
+               }
+               else
+               {
+                       System.out.println("Response error");
+               }
+           }
+           catch(Exception ex)
+           {
+           }
+           return labels;
+       }
+       
+}
\ No newline at end of file
index 5594e8925a426fe4b0f6b52ebd4b623497d81815..da23470258a7d9455aae8c0c112a729764425a66 100644 (file)
@@ -3,8 +3,8 @@ package ie.dcu.apps.ist.views;
 
 import ie.dcu.apps.ist.PainterRegistry;
 import ie.dcu.apps.ist.event.*;
-import ie.dcu.apps.ist.export.imagemap.Exporter;
 import ie.dcu.apps.ist.widgets.*;
+import ie.dcu.apps.ist.labelling.*;
 import ie.dcu.segment.*;
 import ie.dcu.segment.annotate.*;
 import ie.dcu.segment.options.SegmenterOptionDialog;
@@ -18,11 +18,6 @@ import java.net.*;
 import java.util.ArrayList;
 import java.util.Properties;
 import java.util.logging.*;
-import java.awt.image.BufferedImage;
-import java.io.*;
-
-import org.json.*;
-import org.apache.commons.lang3.StringEscapeUtils;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.*;
@@ -92,6 +87,9 @@ public class SegmentationView extends Composite {
        // Flag to indicate that the runnable context blocks when fork is true
        private boolean blocksOnFork;
        
+       // For getting the Labels through Webservice
+       private Labels labels;
+       
        
        public enum Tool {
                Foreground,
@@ -130,6 +128,7 @@ public class SegmentationView extends Composite {
                brushControl = new BrushControl(getShell(), SWT.BORDER);
                eventHandler = new EventHandler();
                segmenterProxy = new RobustSegmenterProxy();
+               labels = new Labels();
                
                init();
        }
@@ -224,14 +223,12 @@ public class SegmentationView extends Composite {
                                {
                                        comboLabel.setListVisible(true);
                                }
-                               else if (!(e.keyCode == 13))
+                               // 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)
                                {
-                                       if(listElements != null)
-                                       {
-                                               listElements = null;
-                                       }
-                                       comboLabel.setListVisible(false);
-                                       listElements = getLabels(comboLabel.getText());
+                                       //For removing all previously assigned labels
+                                       comboLabel.remove(0,comboLabel.getItemCount()-1);
+                                       listElements = labels.getLabels(comboLabel.getText());
                                        assign.setEnabled(!(comboLabel.getText().isEmpty()));
                                        
                                }
@@ -862,51 +859,10 @@ public class SegmentationView extends Composite {
                setPainter(painter);
        }
        
-       private ArrayList<String> getLabels(String content) {
-               ArrayList<String> labels = new ArrayList<String>();
-               try
-           {
-                       comboLabel.remove(0,comboLabel.getItemCount()-1);
-                       String encodedContent = URLEncoder.encode(content.toString(),"UTF-8");
-                       URL url = new URL("http://palea.cgrb.oregonstate.edu/services/PO_web_service.php?request_type=term_search&search_value="+encodedContent+"&inc_synonyms&branch_filter=plant_anatomy&max=20");
-                       HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-                       BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
-                       /*
-                        * if the response is 'OK'
-                        */
-               if(connection.getResponseCode() == 200)
-               {
-                       String inputLine;
-                       JSONObject object = null;
-                       while ((inputLine = in.readLine()) != null) 
-                       {
-                               object = new JSONObject(inputLine);
-                       }
-                       JSONArray array = new JSONArray(object.getString("PO_term_search_response"));
-                       String listElement;
-                       for(int i=0; i<array.length();i++)
-                       {
-                               listElement = (array.getJSONObject(i).getString("match")+" {"+array.getJSONObject(i).getString("accession_id")+"}");
-                               labels.add(i,StringEscapeUtils.unescapeHtml4(listElement));
-                       }
-                       in.close();
-               }
-               else
-               {
-                       System.out.println("Response error");
-               }
-           }
-           catch(Exception ex)
-           {
-           }
-           return labels;
-       }
-       
        private void apply() {
                performSegmentation(null, view.getContext());
        }
 
-
        private void showBrushControl(Event e) {
                brushControl.showBelow(bar1, (ToolItem) e.widget);
        }
@@ -1069,28 +1025,25 @@ public class SegmentationView extends Composite {
                        PopUpLabelDialog dialog = new PopUpLabelDialog(getShell());
                        PopUpLabelDialog.Result result = dialog.open();
                        if (result != null) {
-                               
-                               // Grab image and mask
-                               SegmentationContext ctx = view.getContext();
-                               SegmentationMask mask = ctx.getMask();
-                               BufferedImage image = ImageConverter.convert(ctx.getImageData());
-                               
-                               // Setup exporter
-                               Exporter exporter = new Exporter(image, mask);
-                               exporter.setImageFile(result.image);
-                               String label = SegmentationView.comboLabel.getText();
-                       if(label.indexOf('{') != -1)
+                               String lab = null;
+                               if(result.comboText.indexOf('{') != -1)
+                       {
+                                       lab = result.comboText.substring(0,comboLabel.getText().indexOf('{')-1);
+                       }
+                       else
                        {
-                               label = label.substring(0,label.indexOf('{')-1);
+                               lab = result.comboText;
                        }
-                       exporter.setTitle(label);
+                       System.out.println("selected"+lab);
+                               comboLabel.setText(result.comboText);
+                               execute(Tool.AssignButton, null);
                        }
                }
-               public void mouseDown(MouseEvent e) {
-                       
+               public void mouseDown(MouseEvent e) 
+               {
                }
-               public void mouseDoubleClick(MouseEvent e) {
-                       
+               public void mouseDoubleClick(MouseEvent e) 
+               {
                }
                
        };