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;
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();
}
};
// Widgets
private Combo labelCombo;
- private Text curator;
- private Text imageText;
+ private Text curatorText;
// Dialog buttons
private Button cancelButton;
// 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);
private GridData layout4() {
return new GridData(SWT.RIGHT, SWT.BOTTOM, false, false);
}
+
}
--- /dev/null
+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
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;
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.*;
// 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,
brushControl = new BrushControl(getShell(), SWT.BORDER);
eventHandler = new EventHandler();
segmenterProxy = new RobustSegmenterProxy();
+ labels = new Labels();
init();
}
{
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()));
}
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);
}
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)
+ {
}
};