From ca1b0d60890ecbd0690ab35dfb42c44d01662bcf Mon Sep 17 00:00:00 2001 From: lingutln Date: Fri, 30 Dec 2011 23:01:28 +0000 Subject: [PATCH] Popup dialog functionality. Done by Nikhil. svn path=/; revision=245 --- .../apps/ist/dialogs/PopUpLabelDialog.java | 50 ++++++++-- .../src/ie/dcu/apps/ist/labelling/Labels.java | 63 ++++++++++++ .../dcu/apps/ist/views/SegmentationView.java | 95 +++++-------------- 3 files changed, 130 insertions(+), 78 deletions(-) create mode 100644 Annotation/src/ie/dcu/apps/ist/labelling/Labels.java diff --git a/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java b/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java index 0e7d3b9..bc4e60c 100644 --- a/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java +++ b/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java @@ -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 listElements = new ArrayList(); + //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 containing each Label item + * + */ + public ArrayList getLabels(String content) { + ArrayList labels = new ArrayList(); + // 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= 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 getLabels(String content) { - ArrayList labels = new ArrayList(); - 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